Skip to content

Commit

Permalink
TipsFragment: Migrate to Jetpack Navigation (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdricChan03 committed Jun 21, 2024
1 parent 762ca71 commit f3815c8
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import com.edricchan.studybuddy.BuildConfig
import com.edricchan.studybuddy.R
import com.edricchan.studybuddy.constants.Constants
import com.edricchan.studybuddy.databinding.FragTipsBinding
import com.edricchan.studybuddy.exts.androidx.fragment.startActivity
import com.edricchan.studybuddy.exts.androidx.preference.defaultSharedPreferences
import com.edricchan.studybuddy.exts.androidx.viewbinding.viewInflateBinding
import com.edricchan.studybuddy.ui.modules.debug.DebugActivity
import com.edricchan.studybuddy.ui.modules.settings.SettingsActivity
import com.edricchan.studybuddy.navigation.compat.navigateToDebug
import com.edricchan.studybuddy.navigation.compat.navigateToSettings
import com.edricchan.studybuddy.utils.web.launchUri

class TipsFragment : Fragment() {
private var preferences: SharedPreferences? = null

private lateinit var navController: NavController

private val binding by viewInflateBinding(FragTipsBinding::inflate)

private val menuProvider = object : MenuProvider {
Expand All @@ -41,12 +44,12 @@ class TipsFragment : Fragment() {

override fun onMenuItemSelected(item: MenuItem) = when (item.itemId) {
R.id.action_debug -> {
startActivity<DebugActivity>()
navController.navigateToDebug()
true
}

R.id.action_settings -> {
startActivity<SettingsActivity>()
navController.navigateToSettings()
true
}

Expand All @@ -58,6 +61,8 @@ class TipsFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
preferences = requireContext().defaultSharedPreferences

navController = findNavController()
activity?.addMenuProvider(menuProvider)
}

Expand Down

0 comments on commit f3815c8

Please sign in to comment.