Created
November 13, 2020 19:17
-
-
Save ahmed-shehataa/ebff2a176c940000ac701f945ed88e2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle | |
import android.view.View | |
import androidx.preference.Preference | |
import androidx.preference.PreferenceFragmentCompat | |
import com.ashehata.linky.R | |
import com.ashehata.base.externals.hideIcon | |
import com.ashehata.linky.main.MainActivity | |
import com.ashehata.base.externals.restartActivity | |
class SettingsFragment : PreferenceFragmentCompat() { | |
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | |
setPreferencesFromResource(R.xml.fragment_settings, null) | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
initUi() | |
handleChangeLang() | |
handleChangeTheme() | |
} | |
private fun handleChangeTheme() { | |
findPreference<Preference>(getString(R.string.key_dark_theme))?.setOnPreferenceChangeListener { _, _ -> | |
// Restart activity | |
activity?.recreate() | |
return@setOnPreferenceChangeListener true | |
} | |
} | |
private fun handleChangeLang() { | |
findPreference<Preference>(getString(R.string.key_language))?.setOnPreferenceChangeListener { _, _ -> | |
// Restart application | |
activity?.restartActivity(MainActivity::class.java) | |
return@setOnPreferenceChangeListener true | |
} | |
} | |
private fun initUi() { | |
//findPreference<Preference>("user")?.hideIcon() | |
findPreference<Preference>("app")?.hideIcon() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment