Archived
Changed card tinting method to use strings rather than raw integers to prevent mix-up of colours on app update; added migration strategy to convert old raw integer colours into string values
This commit is contained in:
@@ -19,6 +19,7 @@ import com.google.android.material.card.MaterialCardView
|
||||
class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapter<CardAdapter.CardViewHolder>() {
|
||||
|
||||
private var colour = 0
|
||||
private var colourString = ""
|
||||
private var colorCheck = ""
|
||||
|
||||
class CardViewHolder (view: View) : RecyclerView.ViewHolder(view), View.OnClickListener {
|
||||
@@ -83,46 +84,47 @@ class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapter<CardAd
|
||||
if (!psa) {
|
||||
try {
|
||||
colorCheck = holder.mCourse.text.toString().toLowerCase().substring(0, 3)
|
||||
colour = when (colorCheck) {
|
||||
"deu", "dep", "daz", "fda" -> prefs.getInt("bgGerman", 0)
|
||||
"mat", "map" -> prefs.getInt("bgMaths", 0)
|
||||
"eng", "enp", "ena" -> prefs.getInt("bgEnglish", 0)
|
||||
"spo", "spp", "spth" -> prefs.getInt("bgPhysEd", 0)
|
||||
"pol", "pop" -> prefs.getInt("bgPolitics", 0)
|
||||
"dar", "dap" -> prefs.getInt("bgTheatre", 0)
|
||||
"phy", "php" -> prefs.getInt("bgPhysics", 0)
|
||||
"bio", "bip", "nw1", "nw2", "nw3", "nw4" -> prefs.getInt("bgBiology", 0)
|
||||
"che", "chp" -> prefs.getInt("bgChemistry", 0)
|
||||
"phi", "psp" -> prefs.getInt("bgPhilosophy", 0)
|
||||
"laa", "laf", "lat" -> prefs.getInt("bgLatin", 0)
|
||||
"spa", "spf" -> prefs.getInt("bgSpanish", 0)
|
||||
"fra", "frf", "frz" -> prefs.getInt("bgFrench", 0)
|
||||
"inf" -> prefs.getInt("bgCompsci", 0)
|
||||
"ges" -> prefs.getInt("bgHistory", 0)
|
||||
"rel" -> prefs.getInt("bgReligion", 0)
|
||||
"geg" -> prefs.getInt("bgGeography", 0)
|
||||
"kun" -> prefs.getInt("bgArts", 0)
|
||||
"mus" -> prefs.getInt("bgMusic", 0)
|
||||
"tue" -> prefs.getInt("bgTurkish", 0)
|
||||
"chi" -> prefs.getInt("bgChinese", 0)
|
||||
"gll" -> prefs.getInt("bgGLL", 0)
|
||||
"wat" -> prefs.getInt("bgWAT", 0)
|
||||
"för" -> prefs.getInt("bgForder", 0)
|
||||
"met", "wpb" -> prefs.getInt("bgWP", 0)
|
||||
else -> 0
|
||||
colourString = when (colorCheck) {
|
||||
"deu", "dep", "daz", "fda" -> prefs.getString("cardGerman", "") ?: ""
|
||||
"mat", "map" -> prefs.getString("cardMaths", "") ?: ""
|
||||
"eng", "enp", "ena" -> prefs.getString("cardEnglish", "") ?: ""
|
||||
"spo", "spp", "spth" -> prefs.getString("cardPhysEd", "") ?: ""
|
||||
"pol", "pop" -> prefs.getString("cardPolitics", "") ?: ""
|
||||
"dar", "dap" -> prefs.getString("cardTheatre", "") ?: ""
|
||||
"phy", "php" -> prefs.getString("cardPhysics", "") ?: ""
|
||||
"bio", "bip", "nw1", "nw2", "nw3", "nw4" -> prefs.getString("cardBiology", "") ?: ""
|
||||
"che", "chp" -> prefs.getString("cardChemistry", "") ?: ""
|
||||
"phi", "psp" -> prefs.getString("cardPhilosophy", "") ?: ""
|
||||
"laa", "laf", "lat" -> prefs.getString("cardLatin", "") ?: ""
|
||||
"spa", "spf" -> prefs.getString("cardSpanish", "") ?: ""
|
||||
"fra", "frf", "frz" -> prefs.getString("cardFrench", "") ?: ""
|
||||
"inf" -> prefs.getString("cardCompsci", "") ?: ""
|
||||
"ges" -> prefs.getString("cardHistory", "") ?: ""
|
||||
"rel" -> prefs.getString("cardReligion", "") ?: ""
|
||||
"geg" -> prefs.getString("cardGeography", "") ?: ""
|
||||
"kun" -> prefs.getString("cardArts", "") ?: ""
|
||||
"mus" -> prefs.getString("cardMusic", "") ?: ""
|
||||
"tue" -> prefs.getString("cardTurkish", "") ?: ""
|
||||
"chi" -> prefs.getString("cardChinese", "") ?: ""
|
||||
"gll" -> prefs.getString("cardGLL", "") ?: ""
|
||||
"wat" -> prefs.getString("cardWAT", "") ?: ""
|
||||
"för" -> prefs.getString("cardForder", "") ?: ""
|
||||
"met", "wpb" -> prefs.getString("cardWP", "") ?: ""
|
||||
else -> ""
|
||||
}
|
||||
} catch (e: StringIndexOutOfBoundsException) {
|
||||
try {
|
||||
colorCheck = holder.mCourse.text.toString().toLowerCase().substring(0, 2)
|
||||
colour = when (colorCheck) {
|
||||
"nw" -> prefs.getInt("bgBiology", 0)
|
||||
"wp" -> prefs.getInt("bgWP", 0)
|
||||
else -> 0
|
||||
colourString = when (colorCheck) {
|
||||
"nw" -> prefs.getString("cardBiology", "") ?: ""
|
||||
"wp" -> prefs.getString("cardWP", "") ?: ""
|
||||
else -> ""
|
||||
}
|
||||
} catch (e2: StringIndexOutOfBoundsException) {
|
||||
colour = 0
|
||||
colourString = ""
|
||||
}
|
||||
}
|
||||
colour = MiscData.getColourForString(colourString)
|
||||
if (colour != 0) {
|
||||
holder.mCard.setCardBackgroundColor(ContextCompat.getColor(holder.mCourse.context, colour))
|
||||
} else {
|
||||
|
||||
@@ -46,7 +46,8 @@ class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
}
|
||||
else -> {
|
||||
window.navigationBarColor = ContextCompat.getColor(this, R.color.colorBackground)
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
||||
window.statusBarColor = ContextCompat.getColor(this, R.color.colorBackground)
|
||||
// window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +90,7 @@ class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
.putBoolean("greeting", findViewById<CheckBox>(R.id.cbGreetings).isChecked)
|
||||
.putBoolean("defaultPersonalised", pers.isChecked)
|
||||
.putBoolean("firstTime", false)
|
||||
.putBoolean("colourTransferred", true)
|
||||
.apply()
|
||||
|
||||
val cLayout = findViewById<CoordinatorLayout>(R.id.coordinatorLayout)
|
||||
|
||||
@@ -43,6 +43,11 @@ class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
startActivity(firstTime)
|
||||
finish()
|
||||
} else {
|
||||
if (!prefs.getBoolean("colourTransferred", false)) {
|
||||
MiscData.transferOldColourIntsToString(prefs)
|
||||
edit.putBoolean("colourTransferred", true).apply()
|
||||
}
|
||||
|
||||
edit.putInt("launchDev", prefs.getInt("launchDev", 0) + 1)
|
||||
edit.apply()
|
||||
|
||||
|
||||
@@ -1,9 +1,40 @@
|
||||
package com.denizd.substitutionplan
|
||||
|
||||
import android.content.SharedPreferences
|
||||
|
||||
object MiscData {
|
||||
|
||||
fun emoji(unicode: Int): String { return String(Character.toChars(unicode)) }
|
||||
|
||||
fun getColourForString(name: String): Int {
|
||||
return when(name) {
|
||||
"red" -> R.color.bgRed
|
||||
"orange" -> R.color.bgOrange
|
||||
"yellow" -> R.color.bgYellow
|
||||
"green" -> R.color.bgGreen
|
||||
"teal" -> R.color.bgTeal
|
||||
"cyan" -> R.color.bgCyan
|
||||
"blue" -> R.color.bgBlue
|
||||
"purple" -> R.color.bgPurple
|
||||
"pink" -> R.color.bgPink
|
||||
"brown" -> R.color.bgBrown
|
||||
"grey" -> R.color.bgGrey
|
||||
"pureWhite" -> R.color.bgPureWhite
|
||||
"salmon" -> R.color.bgSalmon
|
||||
"tangerine" -> R.color.bgTangerine
|
||||
"banana" -> R.color.bgBanana
|
||||
"flora" -> R.color.bgFlora
|
||||
"spindrift" -> R.color.bgSpindrift
|
||||
"sky" -> R.color.bgSky
|
||||
"orchid" -> R.color.bgOrchid
|
||||
"lavender" -> R.color.bgLavender
|
||||
"carnation" -> R.color.bgCarnation
|
||||
"brown2" -> R.color.bgBrown2
|
||||
"pureBlack" -> R.color.bgPureBlack
|
||||
else -> R.color.colorBackgroundLight
|
||||
}
|
||||
}
|
||||
|
||||
fun getIcon(course: String): Int {
|
||||
return with (course.toLowerCase()) {
|
||||
when {
|
||||
@@ -36,4 +67,30 @@ object MiscData {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun transferOldColourIntsToString(prefs: SharedPreferences) {
|
||||
val colourIntegers = intArrayOf(0, R.color.bgRed, R.color.bgOrange, R.color.bgYellow, R.color.bgGreen,
|
||||
R.color.bgTeal, R.color.bgCyan, R.color.bgBlue, R.color.bgPurple, R.color.bgPink, R.color.bgBrown, R.color.bgGrey,
|
||||
R.color.bgPureWhite, R.color.bgSalmon, R.color.bgTangerine, R.color.bgBanana, R.color.bgFlora, R.color.bgSpindrift,
|
||||
R.color.bgSky, R.color.bgOrchid, R.color.bgLavender, R.color.bgCarnation, R.color.bgBrown2, R.color.bgPureBlack)
|
||||
val colourStrings = arrayOf("default", "red", "orange", "yellow", "green", "teal", "cyan", "blue", "purple", "pink",
|
||||
"brown", "grey", "pureWhite", "salmon", "tangerine", "banana", "flora", "spindrift", "sky", "orchid",
|
||||
"lavender", "carnation", "brown2", "pureBlack")
|
||||
val courses = arrayOf("German", "English", "French", "Spanish", "Latin", "Turkish", "Chinese", "Arts", "Music",
|
||||
"Theatre", "Geography", "History", "Politics", "Philosophy", "Religion", "Maths", "Biology", "Chemistry",
|
||||
"Physics", "CompSci", "PhysEd", "GLL", "WAT", "Forder", "WP")
|
||||
var colour = ""
|
||||
val edit = prefs.edit()
|
||||
for (course in courses) {
|
||||
for (i in 0 until colourIntegers.size) {
|
||||
if (prefs.getInt("bg$course", 0) == colourIntegers[i]) {
|
||||
colour = colourStrings[i]
|
||||
break
|
||||
}
|
||||
colour = ""
|
||||
}
|
||||
edit.putString("card$course", colour)
|
||||
}
|
||||
edit.apply()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
val coursesIcons = intArrayOf(R.drawable.ic_german, R.drawable.ic_english, R.drawable.ic_french, R.drawable.ic_spanish, R.drawable.ic_latin, R.drawable.ic_turkish, R.drawable.ic_chinese, R.drawable.ic_arts, R.drawable.ic_music, R.drawable.ic_drama, R.drawable.ic_geography, R.drawable.ic_history, R.drawable.ic_politics, R.drawable.ic_philosophy, R.drawable.ic_religion, R.drawable.ic_maths, R.drawable.ic_biology, R.drawable.ic_chemistry, R.drawable.ic_physics, R.drawable.ic_compsci, R.drawable.ic_pe, R.drawable.ic_gll, R.drawable.ic_wat, R.drawable.ic_help, R.drawable.ic_pencil)
|
||||
|
||||
for (i in 0 until coursesNoLang.size) {
|
||||
colours.add(Colour(courses[i], coursesNoLang[i], coursesIcons[i], prefs.getInt("bg${coursesNoLang[i]}", 0)))
|
||||
colours.add(Colour(courses[i], coursesNoLang[i], coursesIcons[i], MiscData.getColourForString(prefs.getString("card${coursesNoLang[i]}", "") ?: "")))
|
||||
}
|
||||
return colours
|
||||
}
|
||||
@@ -317,14 +317,14 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
picker.findViewById(R.id.lavender), picker.findViewById(R.id.carnation), picker.findViewById(R.id.brown2),
|
||||
picker.findViewById(R.id.pureBlack))
|
||||
|
||||
val colours = intArrayOf(0, R.color.bgRed, R.color.bgOrange, R.color.bgYellow, R.color.bgGreen,
|
||||
R.color.bgTeal, R.color.bgCyan, R.color.bgBlue, R.color.bgPurple, R.color.bgPink, R.color.bgBrown, R.color.bgGrey,
|
||||
R.color.bgPureWhite, R.color.bgSalmon, R.color.bgTangerine, R.color.bgBanana, R.color.bgFlora, R.color.bgSpindrift,
|
||||
R.color.bgSky, R.color.bgOrchid, R.color.bgLavender, R.color.bgCarnation, R.color.bgBrown2, R.color.bgPureBlack)
|
||||
val colours = arrayOf("default", "red", "orange", "yellow", "green", "teal", "cyan", "blue", "purple", "pink",
|
||||
"brown", "grey", "pureWhite", "salmon", "tangerine", "banana", "flora", "spindrift", "sky", "orchid",
|
||||
"lavender", "carnation", "brown2", "pureBlack")
|
||||
|
||||
for (i2 in 0 until buttons.size) {
|
||||
buttons[i2].setOnClickListener {
|
||||
prefs.edit().putInt("bg$titleNoLang", colours[i2]).apply()
|
||||
// prefs.edit().putInt("bg$titleNoLang", colourIntegers[i2]).apply()
|
||||
prefs.edit().putString("card$titleNoLang", colours[i2]).apply()
|
||||
val recyclerViewState = colourRecycler.layoutManager?.onSaveInstanceState()
|
||||
colourRecycler.adapter = ColourAdapter(getColourList(), this)
|
||||
colourRecycler.layoutManager?.onRestoreInstanceState(recyclerViewState)
|
||||
|
||||
Reference in New Issue
Block a user