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))
}
}
+8 -8
View File
@@ -14,9 +14,9 @@
<string name="enable_course_notifications_title">Enable course notifications</string>
<string name="enable_course_notifications_desc">This does not affect broadcasts</string>
<string name="personalise">Personalise</string>
<string name="personalise">Personalize</string>
<string name="misc">Miscellaneous</string>
<string name="default_plan_title">Set personalised plan as default</string>
<string name="default_plan_title">Set personalized plan as default</string>
<string name="default_plan_desc">Defaults to general plan otherwise</string>
<string name="visit_website_title">Visit the school\'s website</string>
<string name="visit_website_desc">In case you need to</string>
@@ -39,7 +39,7 @@
<string name="greeting_title">Enable greeting</string>
<string name="greeting_desc">If you want me to be nice :)</string>
<string name="licences_title">Licences</string>
<string name="licences_title">Licenses</string>
<string name="licences_desc">What went into making this app</string>
<string name="version">Version Number</string>
@@ -53,7 +53,7 @@
<string name="grade_help_dialog_title">How to enter your grade</string>
<string name="grade_help_dialog_text">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.</string>
<string name="courses_help_dialog_title">How to enter your courses</string>
<string name="courses_help_dialog_text">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.</string>
<string name="courses_help_dialog_text">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.</string>
<string name="experimental_menu_dialog_title">Testing Menu</string>
<string name="statistics_dialog_title">Statistics Menu</string>
<string name="experimental_menu_dialog_text">This menu is intended for testing only.</string>
@@ -61,8 +61,8 @@
<string name="invalid_code">Invalid code</string>
<string name="no_personal_substitutions">No substitutions for you</string>
<string name="customise_colours_title">Customise colours</string>
<string name="customise_colours_desc">Customise every subject individually</string>
<string name="customise_colours_title">Customize colors</string>
<string name="customise_colours_desc">Customize every subject individually</string>
<string name="course_deu">German (+ as a second language)</string>
<string name="course_mat">Mathematics</string>
@@ -126,7 +126,7 @@
<item>Hi %s!</item>
</string-array>
<string name="pick_ringtone_title">Customise notification ringtone</string>
<string name="pick_ringtone_title">Customize notification ringtone</string>
<string name="pick_ringtone_desc">Currently: %s</string>
<string name="pick_ringtone_dialog_title">Pick a notification ringtone</string>
<string name="pick_ringtone_desc_o">Redirects to device settings</string>
@@ -172,7 +172,7 @@
</string-array>
<string name="ordering_system_hint">Ordering system</string>
<string name="ordering_systems_dialog_title">Information on ordering systems</string>
<string name="ordering_systems_dialog_text">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.</string>
<string name="ordering_systems_dialog_text">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.</string>
<string name="error_please_try_again">An error occurred, please try again</string>
<string name="thanks_for_using">Thanks for using the app!</string>
<string name="congratulations_for_nothing">Congratulations! You have achieved nothing.</string>