Skip to content

Commit

Permalink
Added sharedPreference for authorName
Browse files Browse the repository at this point in the history
  • Loading branch information
WirelessAlien committed Aug 22, 2023
1 parent 949e0aa commit 1eedf85
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class VerseDetailActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)

val sharedPreferences = getSharedPreferences("theme_prefs", Context.MODE_PRIVATE)
val sharedPref = getSharedPreferences("author_prefs", Context.MODE_PRIVATE)

when (sharedPreferences.getString("chosenTheme", "default")) {
"black" -> setTheme(R.style.AppTheme_Black)
Expand Down Expand Up @@ -105,9 +106,17 @@ class VerseDetailActivity : AppCompatActivity() {
authorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
authorSpinner.adapter = authorAdapter

val savedAuthor = sharedPref.getString("selectedAuthor", "")
val savedAuthorPosition = allAuthors.indexOf(savedAuthor)

if (savedAuthorPosition != -1) {
authorSpinner.setSelection(savedAuthorPosition)
}

authorSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
selectedAuthor = allAuthors[position]
sharedPref.edit().putString("selectedAuthor", selectedAuthor).apply()

updateTranslationList()
}
Expand Down

0 comments on commit 1eedf85

Please sign in to comment.