Created
June 1, 2020 09:34
-
-
Save yoesuv/5832d549f66abe185706fa9dfd5767e2 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
class LanguageActivity : BaseActivity() { | |
private lateinit var toolbar: MaterialToolbar | |
private lateinit var radioEnglish: MaterialRadioButton | |
private lateinit var radioIndonesia: MaterialRadioButton | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
toolbar = findViewById(R.id.toolbarMain) | |
radioEnglish = findViewById(R.id.radioEnglish) | |
radioIndonesia = findViewById(R.id.radioIndonesia) | |
setSupportActionBar(toolbar) | |
supportActionBar?.setDisplayShowTitleEnabled(false) | |
radioEnglish.setOnClickListener { | |
LanguagePreferences.appLanguage = Language.EN.name | |
restartApp() | |
} | |
radioIndonesia.setOnClickListener { | |
LanguagePreferences.appLanguage = Language.IN.name | |
restartApp() | |
} | |
setupSelected() | |
} | |
private fun setupSelected() { | |
if(LanguagePreferences.appLanguage == Language.EN.name) { | |
radioEnglish.isChecked = true | |
} else { | |
radioIndonesia.isChecked = true | |
} | |
} | |
private fun restartApp() { | |
val intent = baseContext.packageManager.getLaunchIntentForPackage(baseContext.packageName) | |
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) | |
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) | |
intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | |
startActivity(intent) | |
finish() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment