Unified app translation with iOS version, added "Follow system" theming option to API 28

This commit is contained in:
Deniz Düzgören
2019-10-15 09:50:00 +02:00
parent 3b239fc22d
commit b332381342
5 changed files with 31 additions and 29 deletions
@@ -70,7 +70,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
else -> { // launch the app
if (!prefs.getBoolean("colourTransferred", false)) {
HelperFunctions.transferOldColourIntsToString(prefs)
HelperFunctions.transferOldColourIntsToString(prefs, context)
edit.putBoolean("colourTransferred", true).apply()
}
@@ -43,10 +43,6 @@ internal object HelperFunctions {
"Theatre", "Geography", "History", "Politics", "Philosophy", "Religion", "Maths", "Biology", "Chemistry",
"Physics", "CompSci", "PhysEd", "GLL", "WAT", "Forder", "WP")
val colourNames = arrayOf("default", "red", "orange", "yellow", "green", "teal", "cyan", "blue", "purple", "pink",
"brown", "grey", "salmon", "tangerine", "banana", "flora", "spindrift", "sky", "orchid",
"lavender", "carnation", "brown2", "pureWhite", "pureBlack")
/**
* A lower-cased list of all phrases used to describe that a course has been cancelled. Expand
* this if necessary. No further code changes required if this is expanded
@@ -84,8 +80,16 @@ internal object HelperFunctions {
const val notificationChannelId = "general"
fun getColourArray(c: Context): Array<Colour> {
val titles = c.resources.getStringArray(R.array.colour_names)
/**
* This function returns an array that contains all data relevant to tinting individual entries
* on the substitution plan
*
* @param context a context reference to resolve the R.array reference
*
* @return the array of type Colour
*/
fun getColourArray(context: Context): Array<Colour> {
val titles = context.resources.getStringArray(R.array.colour_names)
return arrayOf(
Colour(titles[0], "default", 0, 0),
Colour(titles[1], "red", 0, R.color.bgRed),
@@ -216,13 +220,13 @@ internal object HelperFunctions {
*
* @param prefs a reference to the app's SharedPreferences
*/
fun transferOldColourIntsToString(prefs: SharedPreferences) {
fun transferOldColourIntsToString(prefs: SharedPreferences, context: Context) {
var colour = ""
val edit = prefs.edit()
for (course in languageIndependentCourses) {
for (i in colourIntegers.indices) {
if (prefs.getInt("bg$course", 0) == colourIntegers[i]) {
colour = colourNames[i]
colour = getColourArray(context)[i].titleNoLang
break
}
colour = ""
@@ -1,11 +1,9 @@
package com.denizd.substitutionplan.data
import android.graphics.Bitmap
import android.util.Log
import android.webkit.CookieManager
import android.webkit.WebView
import android.webkit.WebViewClient
import java.lang.IllegalStateException
/**
* Class that extends WebViewClient to provide a function that checks the website's cookies to
@@ -155,7 +155,7 @@ internal class SettingsFragment : Fragment(), View.OnClickListener, View.OnLongC
})
// Set spinners (+ listeners)
val darkModeList = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
val darkModeList = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
R.array.themes_pre_q
} else {
R.array.themes
@@ -178,7 +178,7 @@ internal class SettingsFragment : Fragment(), View.OnClickListener, View.OnLongC
window?.navigationBarColor = ContextCompat.getColor(mContext, R.color.colorBackground)
}
}
2 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) // only accessible on API 29+
2 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) // only accessible on API 28+
else -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
@@ -415,7 +415,7 @@ internal class SettingsFragment : Fragment(), View.OnClickListener, View.OnLongC
)
dialogButton.setOnClickListener {
when (dialogEditText.text.toString()) {
"_STATISTICS" -> {
"_statistics" -> {
val alertDialogDev = AlertDialog.Builder(mContext)
val devDialogView = View.inflate(mContext, R.layout.diagnostics_dialog, null)
val devDialogText = devDialogView.findViewById<TextView>(R.id.dialogtext)
@@ -438,20 +438,20 @@ internal class SettingsFragment : Fragment(), View.OnClickListener, View.OnLongC
alertDialogDev.setView(devDialogView)
alertDialogDev.show()
}
"_LOGIN" -> {
"_login" -> {
prefs.edit().putBoolean("successful_login", false).apply()
makeToast("Login flag cleared")
}
"_FIRSTTIME" -> {
"_firsttime" -> {
prefs.edit().putBoolean("firstTime", true).apply()
makeToast("First time flag cleared")
}
"_TESTURLS" -> {
"_testurls" -> {
val currentTest = !prefs.getBoolean("testUrls", false)
prefs.edit().putBoolean("testUrls", currentTest).apply()
makeToast("Test URLs set to $currentTest")
}
"_DEVCHANNEL" -> {
"_devchannel" -> {
val subbed = if (prefs.getBoolean("subscribedToFBDebugChannel", false)) {
unsubscribeFromTopic(Topic.DEVELOPMENT)
"Unsubscribed from"
@@ -462,7 +462,7 @@ internal class SettingsFragment : Fragment(), View.OnClickListener, View.OnLongC
prefs.edit().putBoolean("subscribedToFBDebugChannel", !prefs.getBoolean("subscribedToFBDebugChannel", false)).apply()
makeToast("$subbed Firebase development channel")
}
"_IOSCHANNEL" -> {
"_ioschannel" -> {
val subbed = if (prefs.getBoolean("subscribedToiOSChannel", false)) {
unsubscribeFromTopic(Topic.IOS)
"Unsubscribed from"
@@ -473,8 +473,8 @@ internal class SettingsFragment : Fragment(), View.OnClickListener, View.OnLongC
prefs.edit().putBoolean("subscribedToiOSChannel", !prefs.getBoolean("subscribedToiOSChannel", false)).apply()
makeToast("$subbed iOS channel")
}
"_WRITE" -> HelperFunctions.writePrefsToXml(prefs, mContext, activity!!)
"_READ" -> HelperFunctions.readPrefsFromXml(prefs, mContext, activity!!)
"_write" -> HelperFunctions.writePrefsToXml(prefs, mContext, activity!!)
"_read" -> HelperFunctions.readPrefsFromXml(prefs, mContext, activity!!)
else -> makeToast(getString(R.string.invalid_code))
}
}