SignInActivity.kt 4.26 KB
package com.example.vip

import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.viewpager.widget.ViewPager
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_signin.*

class SignInActivity : AppCompatActivity() {

    internal lateinit var viewpager : ViewPager
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_signin)

        testingButton.setOnClickListener {
            var intent = Intent(this, PushingTestActivity::class.java)
            startActivity(intent)
        }

        val policyFieldList = ArrayList<PolicyFieldItem>()

        policyFieldList.add(
            PolicyFieldItem(
                ContextCompat.getDrawable(this, R.drawable.image01)!!,
                getString(R.string.title01)
            )
        )
        policyFieldList.add(
            PolicyFieldItem(
                ContextCompat.getDrawable(this, R.drawable.image02)!!,
                getString(R.string.title02)
            )
        )
        policyFieldList.add(
            PolicyFieldItem(
                ContextCompat.getDrawable(this, R.drawable.image03)!!,
                getString(R.string.title03)
            )
        )
        policyFieldList.add(
            PolicyFieldItem(
                ContextCompat.getDrawable(this, R.drawable.image04)!!,
                getString(R.string.title04)
            )
        )
        policyFieldList.add(
            PolicyFieldItem(
                ContextCompat.getDrawable(this, R.drawable.image05)!!,
                getString(R.string.title05)
            )
        )
        policyFieldList.add(
            PolicyFieldItem(
                ContextCompat.getDrawable(this, R.drawable.image06)!!,
                getString(R.string.title06)
            )
        )
        policyFieldList.add(
            PolicyFieldItem(
                ContextCompat.getDrawable(this, R.drawable.image07)!!,
                getString(R.string.title07)
            )
        )
        policyFieldList.add(
            PolicyFieldItem(
                ContextCompat.getDrawable(this, R.drawable.image08)!!,
                getString(R.string.title08)
            )
        )
        policyFieldList.add(
            PolicyFieldItem(
                ContextCompat.getDrawable(this, R.drawable.image09)!!,
                getString(R.string.title09)
            )
        )
        policyFieldList.add(
            PolicyFieldItem(
                ContextCompat.getDrawable(this, R.drawable.image10)!!,
                getString(R.string.title10)
            )
        )

        val adapter = PolicyFieldAdapter(policyFieldList)
        policyFieldRecyclerView.adapter = adapter

        viewpager = findViewById(R.id.viewpager) as ViewPager
        val viewpageradapter = ViewPagerAdapter(this)
        viewpager.adapter = viewpageradapter

        // 1. 툴바 사용 설정
        setSupportActionBar(toolbar)

        // 2. 툴바 왼쪽 버튼 설정
        supportActionBar!!.setDisplayHomeAsUpEnabled(true) // 왼쪽 버튼 사용 여부 true
        supportActionBar!!.setHomeAsUpIndicator(R.drawable.return_page) // 왼쪽 버튼 아이콘 설정
        supportActionBar!!.setDisplayShowTitleEnabled(false) // 타이틀 안보이게 하기
    }
    // 3.툴바 메뉴 버튼을 설정
    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.main_menu, menu) // main_menu 메뉴를 toolbar 메뉴 버튼으로 설정
        return true
    }

    // 4.툴바 메뉴 버튼이 클릭 됐을 때 콜백
    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
    // 클릭된 메뉴 아이템의 아이디 마다 when 구절로 클릭시 동작을 설정한다.
        when(item!!.itemId){
            android.R.id.home->{ // 메뉴 버튼
                Snackbar.make(toolbar,"Menu pressed",Snackbar.LENGTH_SHORT).show()
            }
            R.id.menu_search->{ // 검색 버튼
                Snackbar.make(toolbar,"Search menu pressed",Snackbar.LENGTH_SHORT).show()
            }
        }
        return super.onOptionsItemSelected(item)
    }

}