From b332381342288a6ced7eecc42d0294b3a8725e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deniz=20D=C3=BCzg=C3=B6ren?= Date: Tue, 15 Oct 2019 09:50:00 +0200 Subject: [PATCH] Unified app translation with iOS version, added "Follow system" theming option to API 28 --- .../substitutionplan/activities/Main.kt | 2 +- .../substitutionplan/data/HelperFunctions.kt | 20 +++++++++++-------- .../data/LoginWebViewClient.kt | 2 -- .../fragments/SettingsFragment.kt | 20 +++++++++---------- app/src/main/res/values/strings.xml | 16 +++++++-------- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/denizd/substitutionplan/activities/Main.kt b/app/src/main/java/com/denizd/substitutionplan/activities/Main.kt index 9fbcd3a..b7ccbbf 100644 --- a/app/src/main/java/com/denizd/substitutionplan/activities/Main.kt +++ b/app/src/main/java/com/denizd/substitutionplan/activities/Main.kt @@ -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() } diff --git a/app/src/main/java/com/denizd/substitutionplan/data/HelperFunctions.kt b/app/src/main/java/com/denizd/substitutionplan/data/HelperFunctions.kt index f3675da..4ed6f34 100644 --- a/app/src/main/java/com/denizd/substitutionplan/data/HelperFunctions.kt +++ b/app/src/main/java/com/denizd/substitutionplan/data/HelperFunctions.kt @@ -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 { - 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 { + 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 = "" diff --git a/app/src/main/java/com/denizd/substitutionplan/data/LoginWebViewClient.kt b/app/src/main/java/com/denizd/substitutionplan/data/LoginWebViewClient.kt index bc980af..a11f3f3 100644 --- a/app/src/main/java/com/denizd/substitutionplan/data/LoginWebViewClient.kt +++ b/app/src/main/java/com/denizd/substitutionplan/data/LoginWebViewClient.kt @@ -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 diff --git a/app/src/main/java/com/denizd/substitutionplan/fragments/SettingsFragment.kt b/app/src/main/java/com/denizd/substitutionplan/fragments/SettingsFragment.kt index 5d604d5..23ceace 100644 --- a/app/src/main/java/com/denizd/substitutionplan/fragments/SettingsFragment.kt +++ b/app/src/main/java/com/denizd/substitutionplan/fragments/SettingsFragment.kt @@ -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(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)) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 415aa21..47c28f0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,9 +14,9 @@ Enable course notifications This does not affect broadcasts - Personalise + Personalize Miscellaneous - Set personalised plan as default + Set personalized plan as default Defaults to general plan otherwise Visit the school\'s website In case you need to @@ -39,7 +39,7 @@ Enable greeting If you want me to be nice :) - Licences + Licenses What went into making this app Version Number @@ -53,7 +53,7 @@ How to enter your grade Enter your current grade to have it appear in your personal plan and be notified about any information.\n\nNote:\n\nIn junior phase, put the number and letter together, as in \"5a\".\n\nIn E-Phase, separate them by a space, as in \"18 a\".\n\nIn Q1/Q2, only put in the number, as in \"17\".\n\nEntering multiple grades is not recommended. How to enter your courses - You need to enter the course abbreviation for every course you want in your personal plan and want to be notified about. You can find them on your time table.\n\nHere\'s a few examples:\n\nMathematics in 5th grade (juniors) would be MAT.\n\nAdvanced English in E-Phase (seniors) for the English profile may be ENP1.\n\nBasic Biology in Q1 could be bio1.\n\nIn most cases, entering courses while in junior phase is redundant.\nSeparate multiple courses by spaces, commas are optional.\nCapitalisation is required. + You need to enter the course abbreviation for every course you want in your personal plan and want to be notified about. You can find them on your time table.\n\nHere\'s a few examples:\n\nMathematics in 5th grade (juniors) would be MAT.\n\nAdvanced English in E-Phase (seniors) for the English profile may be ENP1.\n\nBasic Biology in Q1 could be bio1.\n\nIn most cases, entering courses while in junior phase is redundant.\nSeparate multiple courses by spaces, commas are optional.\nCapitalization is required. Testing Menu Statistics Menu This menu is intended for testing only. @@ -61,8 +61,8 @@ Invalid code No substitutions for you - Customise colours - Customise every subject individually + Customize colors + Customize every subject individually German (+ as a second language) Mathematics @@ -126,7 +126,7 @@ Hi %s! - Customise notification ringtone + Customize notification ringtone Currently: %s Pick a notification ringtone Redirects to device settings @@ -172,7 +172,7 @@ Ordering system Information on ordering systems - You may pick between two ordering systems that dictate the order in which the items on the substitution plan will appear in.\n\nThe default \'app-specific\' is an algorithm implemented in this app that provides a consistently-sorted substitution plan ordered just like the substitution plan on the website used to; sorted by classes, then by time.\n\n\'Website original\' offers the items on the substitution plan just like they\'re presented on the school website, but since these are not guaranteed to be consistent, \'app-specific\' is picked by default. + You may pick between two ordering systems that decide the order in which the items on the substitution plan will appear in.\n\nThe default \'app-specific\' is an algorithm implemented in this app that provides a consistently-sorted substitution plan ordered just like the substitution plan on the website used to; sorted by classes, then by time.\n\n\'Website original\' offers the items on the substitution plan just like they\'re presented on the school website, but since these are not guaranteed to be consistent, \'app-specific\' is picked by default. An error occurred, please try again Thanks for using the app! Congratulations! You have achieved nothing.