Skip to content

29th-WE-SOPT-Android-Part/Android-Kangmin

Repository files navigation

Android-Kangmin

github_이강민_ver1-2

Seminar 7

실행화면

과제 완료 : Level 1-1 & Level 1-2 & Level 1-3 & Level 2-1 & Level 2-2

Level 1-1

nav_boarding.xml

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/nav_boarding"
    app:startDestination="@id/boardingFragment1">

    <fragment
        android:id="@+id/boardingFragment1"
        android:name="org.sopt.soptandroidseminar.view.fragment.BoardingFragment1"
        android:label="첫번째 화면"
        tools:layout="@layout/fragment_boarding1">
        <action
            android:id="@+id/action_boardingFragment1_to_boardingFragment2"
            app:destination="@+id/boardingFragment2" />
    </fragment>
    <fragment
        android:id="@+id/boardingFragment2"
        android:name="org.sopt.soptandroidseminar.view.fragment.BoardingFragment2"
        android:label="두번째 화면"
        tools:layout="@layout/fragment_boarding2">
        <action
            android:id="@+id/action_boardingFragment2_to_boardingFragment3"
            app:destination="@+id/boardingFragment3"
            app:popUpTo="@id/boardingFragment1"
            app:popUpToInclusive="false"/>
    </fragment>
    <fragment
        android:id="@+id/boardingFragment3"
        android:name="org.sopt.soptandroidseminar.view.fragment.BoardingFragment3"
        android:label="세번째 화면"
        tools:layout="@layout/fragment_boarding3" />
</navigation>

네이게이션을 이용한 온보딩 완료

Level 1-2

SOPTSharedPreferences.kt

object SOPTSharedPreferences {
    private const val STORAGE_KEY = "USER_AUTH"
    private const val AUTO_LOGIN = "AUTO_LOGIN"

    fun getAutoLogin(context: Context) : Boolean {
        val preferences = context.getSharedPreferences(STORAGE_KEY, Context.MODE_PRIVATE)
        return preferences.getBoolean(AUTO_LOGIN, false)
    }
    fun setAutoLogin(context: Context, value: Boolean) {
        val preferences = context.getSharedPreferences(STORAGE_KEY, Context.MODE_PRIVATE)
        preferences.edit()
            .putBoolean(AUTO_LOGIN, value)
            .apply()
    }

    fun setLogout(context: Context) {
        val preferences = context.getSharedPreferences(STORAGE_KEY, Context.MODE_PRIVATE)
        preferences.edit()
            .remove(AUTO_LOGIN)
            .clear()
            .apply()
    }
}

object를 이용한 SharedPreferences 사용 & 자동 로그인 구현

Level 1-3

스크린샷 2021-12-17 오후 9 52 00

adapter, util, api ,view로 크게 나누어서 폴더링

Level 2-1

nav_boarding.xml

        <action
            android:id="@+id/action_boardingFragment2_to_boardingFragment3"
            app:destination="@+id/boardingFragment3"
            app:popUpTo="@id/boardingFragment1"
            app:popUpToInclusive="false"/>

popUpTo와 popUpToInclusive를 사용하여 BackStack 관리

Level 2-2

BoardingActivity.kt

class BoardingActivity: AppCompatActivity() {
    private lateinit var binding: ActivityBoardingBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityBoardingBinding.inflate(layoutInflater)
        setContentView(binding.root)

        initToolbar()
    }

    private fun initToolbar() {
        val navHostFragment =
            supportFragmentManager.findFragmentById(R.id.container_boarding) as NavHostFragment
        val navController = navHostFragment.navController
        setSupportActionBar(binding.toolbar)
        NavigationUI.setupActionBarWithNavController(this,navController)
        val appBarConfiguration = AppBarConfiguration(navController.graph)
        binding.toolbar.setupWithNavController(navController, appBarConfiguration)
    }

    override fun onSupportNavigateUp() = findNavController(R.id.container_boarding).navigateUp()
}

navigation의 label과 Toolbar를 연동하여 title의 내용을 구현했습니다.

  • 배운 내용 : navigation을 활용한 온보딩에 대해 배울 수 있었습니다.

2022년 2월 리팩토링

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages