Refactored some resources, centralised Firebase topics by creating an emun 'Topic'

This commit is contained in:
Deniz Düzgören
2019-09-19 07:33:16 +02:00
parent 1414cdbb38
commit 8aec4ec4cd
15 changed files with 142 additions and 150 deletions
+3 -3
View File
@@ -10,8 +10,8 @@ android {
applicationId "com.denizd.substitutionplan" applicationId "com.denizd.substitutionplan"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 28 targetSdkVersion 28
versionCode 36 versionCode 37
versionName "2.2.13" versionName "2.2.14"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
@@ -32,7 +32,7 @@ dependencies {
implementation 'com.google.android.material:material:1.1.0-alpha10' implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'com.android.support:customtabs:28.0.0' implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.google.firebase:firebase-core:17.1.0' implementation 'com.google.firebase:firebase-core:17.2.0'
implementation 'com.google.firebase:firebase-messaging:20.0.0' implementation 'com.google.firebase:firebase-messaging:20.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
+1 -1
View File
@@ -11,7 +11,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application <application
android:allowBackup="true" android:allowBackup="false"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/appName" android:label="@string/appName"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
@@ -57,27 +57,29 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
prefs = PreferenceManager.getDefaultSharedPreferences(context) as SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context) as SharedPreferences
val edit = prefs.edit() val edit = prefs.edit()
val fab = findViewById<ExtendedFloatingActionButton>(R.id.efab) val fab = findViewById<ExtendedFloatingActionButton>(R.id.efab)
val start = Intent(this, Main::class.java) val mainActivity = Intent(this, Main::class.java)
val name = findViewById<TextInputEditText>(R.id.txtName) val nameEditText = findViewById<TextInputEditText>(R.id.txtName)
val grade = findViewById<TextInputEditText>(R.id.txtClasses) val gradeEditText = findViewById<TextInputEditText>(R.id.txtClasses)
val courses = findViewById<TextInputEditText>(R.id.txtCourses) val courseEditText = findViewById<TextInputEditText>(R.id.txtCourses)
val notif = findViewById<CheckBox>(R.id.cbNotif) val helpGradeButton = findViewById<ImageButton>(R.id.chipHelpClasses)
val dark = findViewById<CheckBox>(R.id.cbDark) val helpCoursesButton = findViewById<ImageButton>(R.id.chipHelpCourses)
val pers = findViewById<CheckBox>(R.id.cbPersonalised) val greetingCheckBox = findViewById<CheckBox>(R.id.cbGreetings)
val helpClasses = findViewById<ImageButton>(R.id.chipHelpClasses) val notificationCheckBox = findViewById<CheckBox>(R.id.cbNotif)
val helpCourses = findViewById<ImageButton>(R.id.chipHelpCourses) val darkModeCheckBox = findViewById<CheckBox>(R.id.cbDark)
val greeting = findViewById<CheckBox>(R.id.cbGreetings) val personalPlanCheckBox = findViewById<CheckBox>(R.id.cbPersonalised)
notificationCheckBox.isChecked = true
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
dark.visibility = View.GONE darkModeCheckBox.visibility = View.GONE
} }
helpClasses.setOnClickListener { helpGradeButton.setOnClickListener {
createDialog(getString(R.string.enterGradeHelpTitle), getString( createDialog(getString(R.string.enterGradeHelpTitle), getString(
R.string.enterGradeHelp R.string.enterGradeHelp
)) ))
} }
helpCourses.setOnClickListener { helpCoursesButton.setOnClickListener {
createDialog(getString(R.string.enterCoursesHelpTitle), getString( createDialog(getString(R.string.enterCoursesHelpTitle), getString(
R.string.enterCoursesHelp R.string.enterCoursesHelp
)) ))
@@ -89,22 +91,22 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
fab.isClickable = false fab.isClickable = false
edit.putString("firstTimeDev", Calendar.getInstance().time.toString()) edit.putString("firstTimeDev", Calendar.getInstance().time.toString())
.putString("username", name.text.toString()) .putString("username", nameEditText.text.toString())
.putString("classes", grade.text.toString()) .putString("classes", gradeEditText.text.toString())
.putString("courses", courses.text.toString()) .putString("courses", courseEditText.text.toString())
val themeInt = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { val themeInt = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
2 2
} else { } else {
if (dark.isChecked) { if (darkModeCheckBox.isChecked) {
1 1
} else { } else {
0 0
} }
} }
edit.putInt("themeInt", themeInt) edit.putInt("themeInt", themeInt)
edit.putBoolean("notif", notif.isChecked) edit.putBoolean("notif", notificationCheckBox.isChecked)
.putBoolean("greeting", greeting.isChecked) .putBoolean("greeting", greetingCheckBox.isChecked)
.putBoolean("defaultPersonalised", pers.isChecked) .putBoolean("defaultPersonalised", personalPlanCheckBox.isChecked)
.putBoolean("firstTime", false) .putBoolean("firstTime", false)
.putBoolean("colourTransferred", true) .putBoolean("colourTransferred", true)
.apply() .apply()
@@ -147,17 +149,15 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
} }
}, 1000) }, 1000)
handler.postDelayed({ handler.postDelayed({
startActivity(start) startActivity(mainActivity)
finish() finish()
}, 2000) }, 2000)
} }
} }
private fun createDialog(title: String, text: String) { private fun createDialog(title: String, text: String) {
val alertDialog = AlertDialog.Builder(context, val alertDialog = AlertDialog.Builder(context, R.style.AlertDialog)
R.style.AlertDialog val dialogView = View.inflate(context, R.layout.simple_dialog, null)
)
val dialogView = LayoutInflater.from(context).inflate(R.layout.simple_dialog, null)
val dialogTitle = dialogView.findViewById<TextView>(R.id.textviewtitle) val dialogTitle = dialogView.findViewById<TextView>(R.id.textviewtitle)
val dialogText = dialogView.findViewById<TextView>(R.id.dialogtext) val dialogText = dialogView.findViewById<TextView>(R.id.dialogtext)
dialogTitle.text = title dialogTitle.text = title
@@ -109,7 +109,6 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
textViewGreeting.text = if (prefs.getBoolean("greeting", true) && (prefs.getString("username", "") ?: "").isNotEmpty()) { textViewGreeting.text = if (prefs.getBoolean("greeting", true) && (prefs.getString("username", "") ?: "").isNotEmpty()) {
getGreetingString() getGreetingString()
} else { } else {
// textViewGreeting.visibility = View.GONE
"" ""
} }
@@ -213,7 +212,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
private fun openInfoDialog() { private fun openInfoDialog() {
val dialog = AlertDialog.Builder(context) val dialog = AlertDialog.Builder(context)
val dialogView = LayoutInflater.from(context).inflate(R.layout.simple_dialog, null) val dialogView = View.inflate(context, R.layout.simple_dialog, null)
dialogView.findViewById<TextView>(R.id.textviewtitle).text = getString( dialogView.findViewById<TextView>(R.id.textviewtitle).text = getString(
R.string.information R.string.information
) )
@@ -242,7 +241,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
return if (prefs.getBoolean("greeting", true)) { return if (prefs.getBoolean("greeting", true)) {
getString(R.string.yourPlan) getString(R.string.yourPlan)
} else { } else {
val user = (prefs.getString("username", "") ?: "").toString() val user = prefs.getString("username", "") ?: ""
if (user.endsWith("s", true) || user.endsWith("x", true) || user.endsWith("z", true)) { if (user.endsWith("s", true) || user.endsWith("x", true) || user.endsWith("z", true)) {
"$user${getString(R.string.noSPlan)}" "$user${getString(R.string.noSPlan)}"
} else { } else {
@@ -231,7 +231,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
val notification = NotificationCompat.Builder(context, HelperFunctions.notificationChannelId) val notification = NotificationCompat.Builder(context, HelperFunctions.notificationChannelId)
.setStyle(NotificationCompat.DecoratedCustomViewStyle()) .setStyle(NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout) .setCustomContentView(notificationLayout)
.setSmallIcon(R.drawable.ic_avh) .setSmallIcon(R.drawable.ic_avhlogo)
.setContentIntent(openAppPending) .setContentIntent(openAppPending)
.setAutoCancel(true) .setAutoCancel(true)
.setColor(ContextCompat.getColor(context, R.color.colorAccent)) .setColor(ContextCompat.getColor(context, R.color.colorAccent))
@@ -0,0 +1,8 @@
package com.denizd.substitutionplan.data
internal enum class Topic(val tag: String) {
ANDROID("substitutions-android"),
BROADCAST("substitutions-broadcast"),
IOS("substitutions-ios"),
DEVELOPMENT("substitutions-debug")
}
@@ -10,8 +10,7 @@ import com.denizd.substitutionplan.models.Food
internal class FoodViewModel(application: Application) : AndroidViewModel(application) { internal class FoodViewModel(application: Application) : AndroidViewModel(application) {
private val repository: FoodRepository = private val repository: FoodRepository = FoodRepository(application)
FoodRepository(application)
val allFoods: LiveData<List<Food>>? val allFoods: LiveData<List<Food>>?
private val app = application private val app = application
@@ -10,8 +10,7 @@ import com.denizd.substitutionplan.models.Subst
internal class SubstViewModel(application: Application) : AndroidViewModel(application) { internal class SubstViewModel(application: Application) : AndroidViewModel(application) {
private val repository: SubstRepository = private val repository: SubstRepository = SubstRepository(application)
SubstRepository(application)
val allSubst: LiveData<List<Subst>>? val allSubst: LiveData<List<Subst>>?
private val app = application private val app = application
@@ -15,7 +15,6 @@ import com.denizd.substitutionplan.*
import com.denizd.substitutionplan.adapters.FoodAdapter import com.denizd.substitutionplan.adapters.FoodAdapter
import com.denizd.substitutionplan.database.FoodViewModel import com.denizd.substitutionplan.database.FoodViewModel
import com.denizd.substitutionplan.models.Food import com.denizd.substitutionplan.models.Food
import com.denizd.substitutionplan.data.DataFetcher
internal class FoodFragment : Fragment(R.layout.food_layout) { internal class FoodFragment : Fragment(R.layout.food_layout) {
@@ -12,19 +12,19 @@ internal class PersonalPlanFragment : PlanFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
smileydown = view.findViewById(R.id.smileydown) personalPlanEmptyEmoticon = view.findViewById(R.id.smileydown)
smileydowntext = view.findViewById(R.id.smileydowntext) personalPlanEmptyText = view.findViewById(R.id.smileydowntext)
linearsmiley = view.findViewById(R.id.linearsmiley) personalPlanEmptyLayout = view.findViewById(R.id.linearsmiley)
val coursePreference = prefs.getString("courses", "") ?: "" val coursePreference = prefs.getString("courses", "") ?: ""
val classPreference = prefs.getString("classes", "") ?: "" val classPreference = prefs.getString("classes", "") ?: ""
substViewModel.allSubst?.observe(this, Observer<List<Subst>> { substitutions -> substViewModel.allSubst?.observe(this, Observer<List<Subst>> { substitutions ->
planCardList.clear() planCardList.clear()
smileydown.visibility = View.GONE personalPlanEmptyEmoticon.visibility = View.GONE
smileydowntext.visibility = View.GONE personalPlanEmptyText.visibility = View.GONE
linearsmiley.visibility = View.GONE personalPlanEmptyLayout.visibility = View.GONE
persPlanEmpty = true isPersonalPlanEmpty = true
recyclerView.visibility = View.VISIBLE recyclerView.visibility = View.VISIBLE
substitutions.filter { substItem -> substitutions.filter { substItem ->
@@ -37,16 +37,16 @@ internal class PersonalPlanFragment : PlanFragment() {
}.forEach { substItem -> }.forEach { substItem ->
planCardList.add(substItem) planCardList.add(substItem)
} }
persPlanEmpty = (planCardList.size == 1 && planCardList[0].date.substring(0, 3) == "psa") || planCardList.isEmpty() isPersonalPlanEmpty = (planCardList.size == 1 && planCardList[0].date.substring(0, 3) == "psa") || planCardList.isEmpty()
recyclerView.scheduleLayoutAnimation() recyclerView.scheduleLayoutAnimation()
mAdapter.setSubst(planCardList) mAdapter.setSubst(planCardList)
handler.postDelayed({ handler.postDelayed({
if (persPlanEmpty) { if (isPersonalPlanEmpty) {
smileydown.visibility = View.VISIBLE personalPlanEmptyEmoticon.visibility = View.VISIBLE
smileydowntext.visibility = View.VISIBLE personalPlanEmptyText.visibility = View.VISIBLE
linearsmiley.visibility = View.VISIBLE personalPlanEmptyLayout.visibility = View.VISIBLE
linearsmiley.scheduleLayoutAnimation() personalPlanEmptyLayout.scheduleLayoutAnimation()
} }
}, 64) }, 64)
}) })
@@ -18,7 +18,6 @@ import com.denizd.substitutionplan.*
import com.denizd.substitutionplan.adapters.CardAdapter import com.denizd.substitutionplan.adapters.CardAdapter
import com.denizd.substitutionplan.database.SubstViewModel import com.denizd.substitutionplan.database.SubstViewModel
import com.denizd.substitutionplan.models.Subst import com.denizd.substitutionplan.models.Subst
import com.denizd.substitutionplan.data.DataFetcher
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
internal open class PlanFragment : Fragment(R.layout.plan) { internal open class PlanFragment : Fragment(R.layout.plan) {
@@ -29,10 +28,10 @@ internal open class PlanFragment : Fragment(R.layout.plan) {
private lateinit var mContext: Context private lateinit var mContext: Context
lateinit var prefs: SharedPreferences lateinit var prefs: SharedPreferences
lateinit var smileydown: TextView lateinit var personalPlanEmptyEmoticon: TextView
lateinit var smileydowntext: TextView lateinit var personalPlanEmptyText: TextView
lateinit var linearsmiley: LinearLayout lateinit var personalPlanEmptyLayout: LinearLayout
var persPlanEmpty: Boolean = true var isPersonalPlanEmpty: Boolean = true
val handler = Handler() val handler = Handler()
override fun onAttach(context: Context) { override fun onAttach(context: Context) {
@@ -14,7 +14,6 @@ import android.preference.PreferenceManager
import android.provider.Settings import android.provider.Settings
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.Window import android.view.Window
import android.widget.* import android.widget.*
@@ -30,6 +29,7 @@ import com.denizd.substitutionplan.adapters.ColourAdapter
import com.denizd.substitutionplan.adapters.RingtoneAdapter import com.denizd.substitutionplan.adapters.RingtoneAdapter
import com.denizd.substitutionplan.data.DataFetcher import com.denizd.substitutionplan.data.DataFetcher
import com.denizd.substitutionplan.data.HelperFunctions import com.denizd.substitutionplan.data.HelperFunctions
import com.denizd.substitutionplan.data.Topic
import com.denizd.substitutionplan.models.Colour import com.denizd.substitutionplan.models.Colour
import com.denizd.substitutionplan.models.Ringtone import com.denizd.substitutionplan.models.Ringtone
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
@@ -45,7 +45,6 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
private lateinit var mContext: Context private lateinit var mContext: Context
private lateinit var prefs: SharedPreferences private lateinit var prefs: SharedPreferences
private lateinit var edit: SharedPreferences.Editor
private val builder = CustomTabsIntent.Builder() private val builder = CustomTabsIntent.Builder()
private val customTabsIntent = builder.build() as CustomTabsIntent private val customTabsIntent = builder.build() as CustomTabsIntent
private var cs: Int = 7 private var cs: Int = 7
@@ -58,50 +57,47 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
super.onAttach(context) super.onAttach(context)
mContext = context mContext = context
prefs = PreferenceManager.getDefaultSharedPreferences(mContext) prefs = PreferenceManager.getDefaultSharedPreferences(mContext)
edit = prefs.edit()
window = activity?.window window = activity?.window
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val txtName = view.findViewById<TextInputEditText>(R.id.txtName) val nameEditText = view.findViewById<TextInputEditText>(R.id.txtName)
val txtClasses = view.findViewById<TextInputEditText>(R.id.txtClasses) val gradeEditText = view.findViewById<TextInputEditText>(R.id.txtClasses)
val txtCourses = view.findViewById<TextInputEditText>(R.id.txtCourses) val courseEditText = view.findViewById<TextInputEditText>(R.id.txtCourses)
val switchDisableGreeting = view.findViewById<Switch>(R.id.switchDisableGreeting) val greetingSwitch = view.findViewById<Switch>(R.id.switchDisableGreeting)
// val switchDark = view.findViewById<Switch>(R.id.switchDark) val notificationSwitch = view.findViewById<Switch>(R.id.switchNotifications)
val switchNotifications = view.findViewById<Switch>(R.id.switchNotifications) val defaultPlanSwitch = view.findViewById<Switch>(R.id.switchDefaultPlan)
val switchDefaultPlan = view.findViewById<Switch>(R.id.switchDefaultPlan) val autoRefreshSwitch = view.findViewById<Switch>(R.id.switchAutoRefresh)
val switchAutoRefresh = view.findViewById<Switch>(R.id.switchAutoRefresh) val versionNumberText = view.findViewById<TextView>(R.id.txtVersionTwo)
val versionNumber = view.findViewById<TextView>(R.id.txtVersionTwo) val helpGradeButton = view.findViewById<ImageButton>(R.id.chipHelpClasses)
val helpCourses = view.findViewById<ImageButton>(R.id.chipHelpCourses) val helpCoursesButton = view.findViewById<ImageButton>(R.id.chipHelpCourses)
val helpClasses = view.findViewById<ImageButton>(R.id.chipHelpClasses) val colourCustomisationButton = view.findViewById<LinearLayout>(R.id.btnCustomiseColours)
val btnCustomiseColours = view.findViewById<LinearLayout>(R.id.btnCustomiseColours) val versionButton = view.findViewById<LinearLayout>(R.id.btnVersion)
val btnVersion = view.findViewById<LinearLayout>(R.id.btnVersion)
currentRingtone = view.findViewById(R.id.txtCustomiseRingtone2) currentRingtone = view.findViewById(R.id.txtCustomiseRingtone2)
setRingtoneText() setRingtoneText()
val btnForceRefresh = view.findViewById<LinearLayout>(R.id.btnForceRefresh) val forceRefreshButton = view.findViewById<LinearLayout>(R.id.btnForceRefresh)
switchDisableGreeting.setOnCheckedChangeListener(this) greetingSwitch.setOnCheckedChangeListener(this)
// switchDark.setOnCheckedChangeListener(this) // switchDark.setOnCheckedChangeListener(this)
switchNotifications.setOnCheckedChangeListener(this) notificationSwitch.setOnCheckedChangeListener(this)
switchDefaultPlan.setOnCheckedChangeListener(this) defaultPlanSwitch.setOnCheckedChangeListener(this)
switchAutoRefresh.setOnCheckedChangeListener(this) autoRefreshSwitch.setOnCheckedChangeListener(this)
helpCourses.setOnClickListener(this) helpCoursesButton.setOnClickListener(this)
helpClasses.setOnClickListener(this) helpGradeButton.setOnClickListener(this)
btnCustomiseColours.setOnClickListener(this) colourCustomisationButton.setOnClickListener(this)
view.findViewById<LinearLayout>(R.id.btnNoNotif).setOnClickListener(this) view.findViewById<LinearLayout>(R.id.btnNoNotif).setOnClickListener(this)
view.findViewById<LinearLayout>(R.id.btnCustomiseRingtone).setOnClickListener(this) view.findViewById<LinearLayout>(R.id.btnCustomiseRingtone).setOnClickListener(this)
view.findViewById<LinearLayout>(R.id.btnWebsite).setOnClickListener(this) view.findViewById<LinearLayout>(R.id.btnWebsite).setOnClickListener(this)
view.findViewById<LinearLayout>(R.id.btnLicences).setOnClickListener(this) view.findViewById<LinearLayout>(R.id.btnLicences).setOnClickListener(this)
view.findViewById<LinearLayout>(R.id.btnTerms).setOnClickListener(this) view.findViewById<LinearLayout>(R.id.btnTerms).setOnClickListener(this)
view.findViewById<LinearLayout>(R.id.btnPrivacyP).setOnClickListener(this) view.findViewById<LinearLayout>(R.id.btnPrivacyP).setOnClickListener(this)
btnVersion.setOnClickListener(this) versionButton.setOnClickListener(this)
btnForceRefresh.setOnClickListener(this) forceRefreshButton.setOnClickListener(this)
btnForceRefresh.setOnLongClickListener { forceRefreshButton.setOnLongClickListener {
edit.putString("timeNew", "").putString("newFoodTime", "").apply() prefs.edit().putString("timeNew", "").putString("newFoodTime", "").apply()
makeToast(mContext.getString(R.string.forcedRefreshTimes)) makeToast(mContext.getString(R.string.forcedRefreshTimes))
true true
} }
@@ -124,7 +120,7 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
darkModeDropDown.setText(darkModeDropDown.adapter.getItem(prefs.getInt("themeInt", 0)).toString(), false) darkModeDropDown.setText(darkModeDropDown.adapter.getItem(prefs.getInt("themeInt", 0)).toString(), false)
darkModeDropDown.setOnItemClickListener { _, _, position, _ -> darkModeDropDown.setOnItemClickListener { _, _, position, _ ->
edit.putInt("themeInt", position).apply() prefs.edit().putInt("themeInt", position).apply()
val bottomNav = view.rootView.findViewById<BottomNavigationView>(R.id.bottom_nav) val bottomNav = view.rootView.findViewById<BottomNavigationView>(R.id.bottom_nav)
when (position) { when (position) {
@@ -153,42 +149,42 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
} }
} }
switchDisableGreeting.isChecked = prefs.getBoolean("greeting", true) greetingSwitch.isChecked = prefs.getBoolean("greeting", true)
switchNotifications.isChecked = prefs.getBoolean("notif", false) notificationSwitch.isChecked = prefs.getBoolean("notif", false)
switchDefaultPlan.isChecked = prefs.getBoolean("defaultPersonalised", false) defaultPlanSwitch.isChecked = prefs.getBoolean("defaultPersonalised", false)
switchAutoRefresh.isChecked = prefs.getBoolean("autoRefresh", false) autoRefreshSwitch.isChecked = prefs.getBoolean("autoRefresh", false)
versionNumber.text = BuildConfig.VERSION_NAME versionNumberText.text = BuildConfig.VERSION_NAME
txtName.setText(prefs.getString("username", "")) nameEditText.setText(prefs.getString("username", ""))
txtName.addTextChangedListener(object: TextWatcher { nameEditText.addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(s: Editable) {} override fun afterTextChanged(s: Editable) {}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
edit.putString("username", txtName.text.toString().trim()).apply() prefs.edit().putString("username", nameEditText.text.toString().trim()).apply()
} }
}) })
txtClasses.setText(prefs.getString("classes", "")) gradeEditText.setText(prefs.getString("classes", ""))
txtClasses.addTextChangedListener(object: TextWatcher { gradeEditText.addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(s: Editable) {} override fun afterTextChanged(s: Editable) {}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
edit.putString("classes", txtClasses.text.toString()).apply() prefs.edit().putString("classes", gradeEditText.text.toString()).apply()
} }
}) })
txtCourses.setText(prefs.getString("courses", "")) courseEditText.setText(prefs.getString("courses", ""))
txtCourses.addTextChangedListener(object: TextWatcher { courseEditText.addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(s: Editable) {} override fun afterTextChanged(s: Editable) {}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
edit.putString("courses", txtCourses.text.toString()).apply() prefs.edit().putString("courses", courseEditText.text.toString()).apply()
} }
}) })
btnVersion.setOnLongClickListener { versionButton.setOnLongClickListener {
makeToast(getString(R.string.madeBy)) makeToast(getString(R.string.madeBy))
debugMenu() debugMenu()
} }
@@ -282,31 +278,29 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
).execute() ).execute()
} }
} }
edit.apply()
} }
override fun onCheckedChanged(v: CompoundButton?, isChecked: Boolean) { override fun onCheckedChanged(v: CompoundButton?, isChecked: Boolean) {
if (v?.isPressed == true) { if (v?.isPressed == true) {
when (v.id) { when (v.id) {
R.id.switchDisableGreeting -> { R.id.switchDisableGreeting -> {
edit.putBoolean("greeting", isChecked) prefs.edit().putBoolean("greeting", isChecked).apply()
} }
R.id.switchNotifications -> { R.id.switchNotifications -> {
edit.putBoolean("notif", isChecked) prefs.edit().putBoolean("notif", isChecked).apply()
if (isChecked) { if (isChecked) {
subToTopic("android") subscribeToTopic(Topic.ANDROID)
} else { } else {
unsubFromTopic("android") unsubscribeFromTopic(Topic.ANDROID)
} }
} }
R.id.switchDefaultPlan -> { R.id.switchDefaultPlan -> {
edit.putBoolean("defaultPersonalised", isChecked) prefs.edit().putBoolean("defaultPersonalised", isChecked).apply()
} }
R.id.switchAutoRefresh -> { R.id.switchAutoRefresh -> {
edit.putBoolean("autoRefresh", isChecked) prefs.edit().putBoolean("autoRefresh", isChecked).apply()
} }
} }
edit.apply()
} }
} }
@@ -314,7 +308,7 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
val alertDialog = AlertDialog.Builder(mContext, val alertDialog = AlertDialog.Builder(mContext,
R.style.AlertDialog R.style.AlertDialog
) )
val dialogView = LayoutInflater.from(mContext).inflate(R.layout.simple_dialog, null) val dialogView = View.inflate(mContext, R.layout.simple_dialog, null)
dialogView.findViewById<TextView>(R.id.textviewtitle).text = title dialogView.findViewById<TextView>(R.id.textviewtitle).text = title
dialogView.findViewById<TextView>(R.id.dialogtext).text = text dialogView.findViewById<TextView>(R.id.dialogtext).text = text
alertDialog.setView(dialogView).show() alertDialog.setView(dialogView).show()
@@ -323,7 +317,7 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
private fun createColourDialog() { private fun createColourDialog() {
val colourCustomiserBuilder = AlertDialog.Builder(mContext, R.style.AlertDialog) val colourCustomiserBuilder = AlertDialog.Builder(mContext, R.style.AlertDialog)
val dialogView = LayoutInflater.from(mContext).inflate(R.layout.recycler_dialog, null) val dialogView = View.inflate(mContext, R.layout.recycler_dialog, null)
val titleText = dialogView.findViewById<TextView>(R.id.empty_textviewtitle) val titleText = dialogView.findViewById<TextView>(R.id.empty_textviewtitle)
titleText.text = getString(R.string.customiseColoursTitle) titleText.text = getString(R.string.customiseColoursTitle)
colourRecycler = dialogView.findViewById(R.id.recyclerView) colourRecycler = dialogView.findViewById(R.id.recyclerView)
@@ -390,7 +384,7 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
} else { } else {
val ringtoneCustomiserBuilder = AlertDialog.Builder(mContext, R.style.AlertDialog) val ringtoneCustomiserBuilder = AlertDialog.Builder(mContext, R.style.AlertDialog)
val dialogView = LayoutInflater.from(mContext).inflate(R.layout.recycler_dialog, null) val dialogView = View.inflate(mContext, R.layout.recycler_dialog, null)
val titleText = dialogView.findViewById<TextView>(R.id.empty_textviewtitle) val titleText = dialogView.findViewById<TextView>(R.id.empty_textviewtitle)
titleText.text = getString(R.string.pickRingtone) titleText.text = getString(R.string.pickRingtone)
@@ -454,12 +448,12 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
override fun onClick(position: Int, title: String, titleNoLang: String) { override fun onClick(position: Int, title: String, titleNoLang: String) {
val colourPickerBuilder = AlertDialog.Builder(mContext, R.style.AlertDialog) val colourPickerBuilder = AlertDialog.Builder(mContext, R.style.AlertDialog)
val pickerDialogView = LayoutInflater.from(mContext).inflate(R.layout.empty_dialog, null) val pickerDialogView = View.inflate(mContext, R.layout.empty_dialog, null)
val pickerTitleText = pickerDialogView.findViewById<TextView>(R.id.empty_textviewtitle) val pickerTitleText = pickerDialogView.findViewById<TextView>(R.id.empty_textviewtitle)
val pickerLayout = pickerDialogView.findViewById<LinearLayout>(R.id.empty_linearlayout) val pickerLayout = pickerDialogView.findViewById<LinearLayout>(R.id.empty_linearlayout)
pickerTitleText.text = title pickerTitleText.text = title
val picker = LayoutInflater.from(mContext).inflate(R.layout.bg_colour_picker, null) val picker = View.inflate(mContext, R.layout.bg_colour_picker, null)
pickerLayout.addView(picker) pickerLayout.addView(picker)
colourPickerBuilder.setView(pickerDialogView) colourPickerBuilder.setView(pickerDialogView)
val colourPickerDialog: AlertDialog = colourPickerBuilder.create() val colourPickerDialog: AlertDialog = colourPickerBuilder.create()
@@ -472,7 +466,6 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
for (i2 in buttons.indices) { for (i2 in buttons.indices) {
picker.findViewById<MaterialButton>(buttons[i2]).setOnClickListener { picker.findViewById<MaterialButton>(buttons[i2]).setOnClickListener {
// prefs.edit().putInt("bg$titleNoLang", colourIntegers[i2]).apply()
prefs.edit().putString("card$titleNoLang", colours[i2]).apply() prefs.edit().putString("card$titleNoLang", colours[i2]).apply()
val recyclerViewState = colourRecycler.layoutManager?.onSaveInstanceState() val recyclerViewState = colourRecycler.layoutManager?.onSaveInstanceState()
colourRecycler.adapter = ColourAdapter(getColourList(), this) colourRecycler.adapter = ColourAdapter(getColourList(), this)
@@ -484,10 +477,8 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
} }
private fun debugMenu(): Boolean { private fun debugMenu(): Boolean {
val alertDialog = AlertDialog.Builder(mContext, val alertDialog = AlertDialog.Builder(mContext, R.style.AlertDialog)
R.style.AlertDialog val dialogView = View.inflate(mContext, R.layout.edittext_dialog, null)
)
val dialogView = LayoutInflater.from(mContext).inflate(R.layout.edittext_dialog, null)
val dialogEditText = dialogView.findViewById<EditText>(R.id.dialog_edittext) val dialogEditText = dialogView.findViewById<EditText>(R.id.dialog_edittext)
val dialogButton = dialogView.findViewById<Button>(R.id.dialog_button) val dialogButton = dialogView.findViewById<Button>(R.id.dialog_button)
@@ -501,7 +492,7 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
when (dialogEditText.text.toString()) { when (dialogEditText.text.toString()) {
"_DIAGNOSTICS" -> { "_DIAGNOSTICS" -> {
val alertDialogDev = AlertDialog.Builder(mContext, R.style.AlertDialog) val alertDialogDev = AlertDialog.Builder(mContext, R.style.AlertDialog)
val devDialogView = LayoutInflater.from(mContext).inflate(R.layout.diagnostics_dialog, null) val devDialogView = View.inflate(mContext, R.layout.diagnostics_dialog, null)
val devDialogText = devDialogView.findViewById<TextView>(R.id.dialogtext) val devDialogText = devDialogView.findViewById<TextView>(R.id.dialogtext)
val resetLaunchBtn = devDialogView.findViewById<Button>(R.id.btnResetLaunch) val resetLaunchBtn = devDialogView.findViewById<Button>(R.id.btnResetLaunch)
val resetNotificationBtn = devDialogView.findViewById<Button>(R.id.btnResetNotif) val resetNotificationBtn = devDialogView.findViewById<Button>(R.id.btnResetNotif)
@@ -509,16 +500,16 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
devDialogView.findViewById<TextView>(R.id.textviewtitle).text = getString( devDialogView.findViewById<TextView>(R.id.textviewtitle).text = getString(
R.string.diagnosticsMenu R.string.diagnosticsMenu
) )
devDialogText.text = getDiagnosticsText(prefs) devDialogText.text = getDiagnosticsText()
resetLaunchBtn.setOnClickListener { resetLaunchBtn.setOnClickListener {
edit.putInt("launchDev", 0).apply() prefs.edit().putInt("launchDev", 0).apply()
devDialogText.text = getDiagnosticsText(prefs) devDialogText.text = getDiagnosticsText()
} }
resetNotificationBtn.setOnClickListener { resetNotificationBtn.setOnClickListener {
edit.putInt("pingFB", 0).apply() prefs.edit().putInt("pingFB", 0).apply()
devDialogText.text = getDiagnosticsText(prefs) devDialogText.text = getDiagnosticsText()
} }
alertDialogDev.setView(devDialogView) alertDialogDev.setView(devDialogView)
@@ -534,34 +525,34 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
} }
} }
"_FIRSTTIME" -> { "_FIRSTTIME" -> {
edit.putBoolean("firstTime", true).apply() prefs.edit().putBoolean("firstTime", true).apply()
makeToast("First time flag cleared") makeToast("First time flag cleared")
} }
"_TESTURLS" -> { "_TESTURLS" -> {
val currentTest = !prefs.getBoolean("testUrls", false) val currentTest = !prefs.getBoolean("testUrls", false)
edit.putBoolean("testUrls", currentTest).apply() prefs.edit().putBoolean("testUrls", currentTest).apply()
makeToast("Test URLs set to $currentTest") makeToast("Test URLs set to $currentTest")
} }
"_DEVCHANNEL" -> { "_DEVCHANNEL" -> {
val subbed = if (prefs.getBoolean("subscribedToFBDebugChannel", false)) { val subbed = if (prefs.getBoolean("subscribedToFBDebugChannel", false)) {
unsubFromTopic("debug") unsubscribeFromTopic(Topic.DEVELOPMENT)
"Unsubscribed from" "Unsubscribed from"
} else { } else {
subToTopic("debug") subscribeToTopic(Topic.DEVELOPMENT)
"Subscribed to" "Subscribed to"
} }
edit.putBoolean("subscribedToFBDebugChannel", !prefs.getBoolean("subscribedToFBDebugChannel", false)).apply() prefs.edit().putBoolean("subscribedToFBDebugChannel", !prefs.getBoolean("subscribedToFBDebugChannel", false)).apply()
makeToast("$subbed Firebase development channel") makeToast("$subbed Firebase development channel")
} }
"_IOSCHANNEL" -> { "_IOSCHANNEL" -> {
val subbed = if (prefs.getBoolean("subscribedToiOSChannel", false)) { val subbed = if (prefs.getBoolean("subscribedToiOSChannel", false)) {
unsubFromTopic("ios") unsubscribeFromTopic(Topic.IOS)
"Unsubscribed from" "Unsubscribed from"
} else { } else {
subToTopic("ios") subscribeToTopic(Topic.IOS)
"Subscribed to" "Subscribed to"
} }
edit.putBoolean("subscribedToiOSChannel", !prefs.getBoolean("subscribedToiOSChannel", false)).apply() prefs.edit().putBoolean("subscribedToiOSChannel", !prefs.getBoolean("subscribedToiOSChannel", false)).apply()
makeToast("$subbed iOS channel") makeToast("$subbed iOS channel")
} }
"_WRITE" -> HelperFunctions.writePrefsToXml(prefs, mContext, activity!!) "_WRITE" -> HelperFunctions.writePrefsToXml(prefs, mContext, activity!!)
@@ -578,7 +569,7 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
Toast.makeText(mContext, text, Toast.LENGTH_LONG).show() Toast.makeText(mContext, text, Toast.LENGTH_LONG).show()
} }
private fun getDiagnosticsText(prefs: SharedPreferences): String { private fun getDiagnosticsText(): String {
return "First Launch: ${prefs.getString("firstTimeDev", "")}" + return "First Launch: ${prefs.getString("firstTimeDev", "")}" +
"\n\nApp launched: ${prefs.getInt("launchDev", 0)}" + "\n\nApp launched: ${prefs.getInt("launchDev", 0)}" +
"\n\nFirebase ping service fired: ${prefs.getInt("pingFB", 0)}" + "\n\nFirebase ping service fired: ${prefs.getInt("pingFB", 0)}" +
@@ -586,9 +577,10 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
"\n\nDevice Model: ${Build.MODEL}" + "\n\nDevice Model: ${Build.MODEL}" +
"\n\nAndroid Version: ${Build.VERSION.RELEASE}" + "\n\nAndroid Version: ${Build.VERSION.RELEASE}" +
"\n\nSubscribed to notification channel: ${prefs.getBoolean("notif", false)}" + "\n\nSubscribed to notification channel: ${prefs.getBoolean("notif", false)}" +
"\n\nSubscribed to iOS channel: ${prefs.getBoolean("subscribedToiOSChannel", false)}" +
"\n\nSubscribed to dev channel: ${prefs.getBoolean("subscribedToFBDebugChannel", false)}" "\n\nSubscribed to dev channel: ${prefs.getBoolean("subscribedToFBDebugChannel", false)}"
} }
private fun subToTopic(topic: String) = FirebaseMessaging.getInstance().subscribeToTopic("substitutions-$topic") private fun subscribeToTopic(topic: Topic) = FirebaseMessaging.getInstance().subscribeToTopic(topic.tag)
private fun unsubFromTopic(topic: String) = FirebaseMessaging.getInstance().unsubscribeFromTopic("substitutions-$topic") private fun unsubscribeFromTopic(topic: Topic) = FirebaseMessaging.getInstance().unsubscribeFromTopic(topic.tag)
} }
@@ -3,6 +3,7 @@ package com.denizd.substitutionplan.services
import android.app.job.JobParameters import android.app.job.JobParameters
import android.app.job.JobService import android.app.job.JobService
import android.preference.PreferenceManager import android.preference.PreferenceManager
import com.denizd.substitutionplan.data.Topic
import com.google.firebase.FirebaseApp import com.google.firebase.FirebaseApp
import com.google.firebase.messaging.FirebaseMessaging import com.google.firebase.messaging.FirebaseMessaging
@@ -23,33 +24,29 @@ internal class FBPingService : JobService() {
private fun doBackgroundWork(params: JobParameters) { private fun doBackgroundWork(params: JobParameters) {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) val prefs = PreferenceManager.getDefaultSharedPreferences(context)
FirebaseApp.initializeApp(context) FirebaseApp.initializeApp(context)
FirebaseMessaging.getInstance().apply { FirebaseMessaging.getInstance().apply {
if (prefs.getBoolean("notif", true)) { if (prefs.getBoolean("notif", true)) {
subscribeToTopic("substitutions-android") subscribeToTopic(Topic.ANDROID.tag)
} else { } else {
unsubscribeFromTopic("substitutions-android") unsubscribeFromTopic(Topic.ANDROID.tag)
} }
if (prefs.getBoolean("subscribedToFBDebugChannel", false)) { if (prefs.getBoolean("subscribedToFBDebugChannel", false)) {
subscribeToTopic("substitutions-debug") subscribeToTopic(Topic.DEVELOPMENT.tag)
} else { } else {
unsubscribeFromTopic("substitutions-debug") unsubscribeFromTopic(Topic.DEVELOPMENT.tag)
} }
if (prefs.getBoolean("subscribedToiOSChannel", false)) { if (prefs.getBoolean("subscribedToiOSChannel", false)) {
subscribeToTopic("substitutions-ios") subscribeToTopic(Topic.IOS.tag)
} else { } else {
unsubscribeFromTopic("substitutions-ios") unsubscribeFromTopic(Topic.IOS.tag)
} }
subscribeToTopic("substitutions-broadcast") subscribeToTopic(Topic.BROADCAST.tag)
prefs.edit().putInt("pingFB", prefs.getInt("pingFB", 0) + 1).apply() prefs.edit().putInt("pingFB", prefs.getInt("pingFB", 0) + 1).apply()
} }
jobFinished(params, false) jobFinished(params, false)
} }
+1 -1
View File
@@ -127,7 +127,7 @@
<string name="success">Erfolg</string> <string name="success">Erfolg</string>
<string name="notReceivingNotifications1">Benachrichtigungen kommen nicht an?</string> <string name="notReceivingNotifications1">Benachrichtigungen kommen nicht an?</string>
<string name="notReceivingNotifications2">Klick hier um zu sehen, warum</string> <string name="notReceivingNotifications2">Klick hier um zu sehen, warum</string>
<string name="notReceivingNotificationsHelp">Bemerke, dass diese Tipps insbesondere auf Huawei/Honor-Geräten nicht funktionieren könnten. Du kannst sie trotzdem ausprobieren.\n\nAkkusparfunktionen können dazu führen, dass Benachrichtigungen nicht ankommen. Versuche, Akkusparmodi auf deren Standardeinstellung zu setzen.\n\nEinige Geräte beschränken Apps im Hintergrund. Suche in deinen Geräteeinstellungen unter Apps die Vertretungsplan-App und schaue dann nach einer Einstellung namens \"Hintergrund-Services beschränken\" (oder ähnlich) und stelle sicher, dass diese ausgestellt ist.\n\nBei Schwierigkeiten kann ich auch gerne helfen.</string> <string name="notReceivingNotificationsHelp">Bemerke, dass diese Tipps insbesondere auf einigen Geräten chinesischer Hersteller nicht funktionieren könnten. Du kannst sie trotzdem ausprobieren.\n\nAkkusparfunktionen können dazu führen, dass Benachrichtigungen nicht ankommen. Versuche, Akkusparmodi auf deren Standardeinstellung zu setzen.\n\nEinige Geräte beschränken Apps im Hintergrund. Suche in deinen Geräteeinstellungen unter Apps die Vertretungsplan-App und schaue dann nach einer Einstellung namens \"Hintergrund-Services beschränken\" (oder ähnlich) und stelle sicher, dass diese ausgestellt ist.\n\nBei Schwierigkeiten kann ich auch gerne helfen.</string>
<string name="appTheme">App-Design</string> <string name="appTheme">App-Design</string>
<string-array name="themes"> <string-array name="themes">
<item>Hell</item> <item>Hell</item>
+1 -1
View File
@@ -140,7 +140,7 @@
<string name="success">Success</string> <string name="success">Success</string>
<string name="notReceivingNotifications1">Not receiving notifications?</string> <string name="notReceivingNotifications1">Not receiving notifications?</string>
<string name="notReceivingNotifications2">Click to see why</string> <string name="notReceivingNotifications2">Click to see why</string>
<string name="notReceivingNotificationsHelp">Note: on Huawei/Honor devices, there may not be a solution to this problem. You\'re welcome to try the tips provided.\n\nBattery saver functions often cause notifications to be delayed or not be received at all. Try setting any battery saving options to their default setting.\n\nSome devices restrict background usage of apps. Please go to your device app settings, select the app and check for a toggle named \"Restrict background usage\" (or similar) and verify that the setting is turned off.\n\nYou\'re also welcome to ask me for help.</string> <string name="notReceivingNotificationsHelp">Note: on some Chinese-branded devices, there may not be a solution to this problem. You\'re welcome to try the tips provided.\n\nBattery saver functions often cause notifications to be delayed or not be received at all. Try setting any battery saving options to their default setting.\n\nSome devices restrict background usage of apps. Please go to your device app settings, select the app and check for a toggle named \"Restrict background usage\" (or similar) and verify that the setting is turned off.\n\nYou\'re also welcome to ask me for help.</string>
<string name="appTheme">App theme</string> <string name="appTheme">App theme</string>
<string-array name="themes"> <string-array name="themes">
<item>Light</item> <item>Light</item>