Archived
Refactored some resources, centralised Firebase topics by creating an emun 'Topic'
This commit is contained in:
@@ -57,27 +57,29 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context) as SharedPreferences
|
||||
val edit = prefs.edit()
|
||||
val fab = findViewById<ExtendedFloatingActionButton>(R.id.efab)
|
||||
val start = Intent(this, Main::class.java)
|
||||
val name = findViewById<TextInputEditText>(R.id.txtName)
|
||||
val grade = findViewById<TextInputEditText>(R.id.txtClasses)
|
||||
val courses = findViewById<TextInputEditText>(R.id.txtCourses)
|
||||
val notif = findViewById<CheckBox>(R.id.cbNotif)
|
||||
val dark = findViewById<CheckBox>(R.id.cbDark)
|
||||
val pers = findViewById<CheckBox>(R.id.cbPersonalised)
|
||||
val helpClasses = findViewById<ImageButton>(R.id.chipHelpClasses)
|
||||
val helpCourses = findViewById<ImageButton>(R.id.chipHelpCourses)
|
||||
val greeting = findViewById<CheckBox>(R.id.cbGreetings)
|
||||
val mainActivity = Intent(this, Main::class.java)
|
||||
val nameEditText = findViewById<TextInputEditText>(R.id.txtName)
|
||||
val gradeEditText = findViewById<TextInputEditText>(R.id.txtClasses)
|
||||
val courseEditText = findViewById<TextInputEditText>(R.id.txtCourses)
|
||||
val helpGradeButton = findViewById<ImageButton>(R.id.chipHelpClasses)
|
||||
val helpCoursesButton = findViewById<ImageButton>(R.id.chipHelpCourses)
|
||||
val greetingCheckBox = findViewById<CheckBox>(R.id.cbGreetings)
|
||||
val notificationCheckBox = findViewById<CheckBox>(R.id.cbNotif)
|
||||
val darkModeCheckBox = findViewById<CheckBox>(R.id.cbDark)
|
||||
val personalPlanCheckBox = findViewById<CheckBox>(R.id.cbPersonalised)
|
||||
|
||||
notificationCheckBox.isChecked = true
|
||||
|
||||
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(
|
||||
R.string.enterGradeHelp
|
||||
))
|
||||
}
|
||||
helpCourses.setOnClickListener {
|
||||
helpCoursesButton.setOnClickListener {
|
||||
createDialog(getString(R.string.enterCoursesHelpTitle), getString(
|
||||
R.string.enterCoursesHelp
|
||||
))
|
||||
@@ -89,22 +91,22 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
fab.isClickable = false
|
||||
|
||||
edit.putString("firstTimeDev", Calendar.getInstance().time.toString())
|
||||
.putString("username", name.text.toString())
|
||||
.putString("classes", grade.text.toString())
|
||||
.putString("courses", courses.text.toString())
|
||||
.putString("username", nameEditText.text.toString())
|
||||
.putString("classes", gradeEditText.text.toString())
|
||||
.putString("courses", courseEditText.text.toString())
|
||||
val themeInt = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
|
||||
2
|
||||
} else {
|
||||
if (dark.isChecked) {
|
||||
if (darkModeCheckBox.isChecked) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
edit.putInt("themeInt", themeInt)
|
||||
edit.putBoolean("notif", notif.isChecked)
|
||||
.putBoolean("greeting", greeting.isChecked)
|
||||
.putBoolean("defaultPersonalised", pers.isChecked)
|
||||
edit.putBoolean("notif", notificationCheckBox.isChecked)
|
||||
.putBoolean("greeting", greetingCheckBox.isChecked)
|
||||
.putBoolean("defaultPersonalised", personalPlanCheckBox.isChecked)
|
||||
.putBoolean("firstTime", false)
|
||||
.putBoolean("colourTransferred", true)
|
||||
.apply()
|
||||
@@ -147,17 +149,15 @@ internal class FirstTime : AppCompatActivity(R.layout.activity_first_time) {
|
||||
}
|
||||
}, 1000)
|
||||
handler.postDelayed({
|
||||
startActivity(start)
|
||||
startActivity(mainActivity)
|
||||
finish()
|
||||
}, 2000)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createDialog(title: String, text: String) {
|
||||
val alertDialog = AlertDialog.Builder(context,
|
||||
R.style.AlertDialog
|
||||
)
|
||||
val dialogView = LayoutInflater.from(context).inflate(R.layout.simple_dialog, null)
|
||||
val alertDialog = AlertDialog.Builder(context, R.style.AlertDialog)
|
||||
val dialogView = View.inflate(context, R.layout.simple_dialog, null)
|
||||
val dialogTitle = dialogView.findViewById<TextView>(R.id.textviewtitle)
|
||||
val dialogText = dialogView.findViewById<TextView>(R.id.dialogtext)
|
||||
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()) {
|
||||
getGreetingString()
|
||||
} else {
|
||||
// textViewGreeting.visibility = View.GONE
|
||||
""
|
||||
}
|
||||
|
||||
@@ -213,7 +212,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
|
||||
private fun openInfoDialog() {
|
||||
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(
|
||||
R.string.information
|
||||
)
|
||||
@@ -242,7 +241,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
return if (prefs.getBoolean("greeting", true)) {
|
||||
getString(R.string.yourPlan)
|
||||
} 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)) {
|
||||
"$user${getString(R.string.noSPlan)}"
|
||||
} else {
|
||||
|
||||
@@ -231,7 +231,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
val notification = NotificationCompat.Builder(context, HelperFunctions.notificationChannelId)
|
||||
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
|
||||
.setCustomContentView(notificationLayout)
|
||||
.setSmallIcon(R.drawable.ic_avh)
|
||||
.setSmallIcon(R.drawable.ic_avhlogo)
|
||||
.setContentIntent(openAppPending)
|
||||
.setAutoCancel(true)
|
||||
.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) {
|
||||
|
||||
private val repository: FoodRepository =
|
||||
FoodRepository(application)
|
||||
private val repository: FoodRepository = FoodRepository(application)
|
||||
val allFoods: LiveData<List<Food>>?
|
||||
private val app = application
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ import com.denizd.substitutionplan.models.Subst
|
||||
|
||||
internal class SubstViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
private val repository: SubstRepository =
|
||||
SubstRepository(application)
|
||||
private val repository: SubstRepository = SubstRepository(application)
|
||||
val allSubst: LiveData<List<Subst>>?
|
||||
private val app = application
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.denizd.substitutionplan.*
|
||||
import com.denizd.substitutionplan.adapters.FoodAdapter
|
||||
import com.denizd.substitutionplan.database.FoodViewModel
|
||||
import com.denizd.substitutionplan.models.Food
|
||||
import com.denizd.substitutionplan.data.DataFetcher
|
||||
|
||||
internal class FoodFragment : Fragment(R.layout.food_layout) {
|
||||
|
||||
|
||||
@@ -12,19 +12,19 @@ internal class PersonalPlanFragment : PlanFragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
smileydown = view.findViewById(R.id.smileydown)
|
||||
smileydowntext = view.findViewById(R.id.smileydowntext)
|
||||
linearsmiley = view.findViewById(R.id.linearsmiley)
|
||||
personalPlanEmptyEmoticon = view.findViewById(R.id.smileydown)
|
||||
personalPlanEmptyText = view.findViewById(R.id.smileydowntext)
|
||||
personalPlanEmptyLayout = view.findViewById(R.id.linearsmiley)
|
||||
|
||||
val coursePreference = prefs.getString("courses", "") ?: ""
|
||||
val classPreference = prefs.getString("classes", "") ?: ""
|
||||
|
||||
substViewModel.allSubst?.observe(this, Observer<List<Subst>> { substitutions ->
|
||||
planCardList.clear()
|
||||
smileydown.visibility = View.GONE
|
||||
smileydowntext.visibility = View.GONE
|
||||
linearsmiley.visibility = View.GONE
|
||||
persPlanEmpty = true
|
||||
personalPlanEmptyEmoticon.visibility = View.GONE
|
||||
personalPlanEmptyText.visibility = View.GONE
|
||||
personalPlanEmptyLayout.visibility = View.GONE
|
||||
isPersonalPlanEmpty = true
|
||||
recyclerView.visibility = View.VISIBLE
|
||||
|
||||
substitutions.filter { substItem ->
|
||||
@@ -37,16 +37,16 @@ internal class PersonalPlanFragment : PlanFragment() {
|
||||
}.forEach { 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()
|
||||
mAdapter.setSubst(planCardList)
|
||||
|
||||
handler.postDelayed({
|
||||
if (persPlanEmpty) {
|
||||
smileydown.visibility = View.VISIBLE
|
||||
smileydowntext.visibility = View.VISIBLE
|
||||
linearsmiley.visibility = View.VISIBLE
|
||||
linearsmiley.scheduleLayoutAnimation()
|
||||
if (isPersonalPlanEmpty) {
|
||||
personalPlanEmptyEmoticon.visibility = View.VISIBLE
|
||||
personalPlanEmptyText.visibility = View.VISIBLE
|
||||
personalPlanEmptyLayout.visibility = View.VISIBLE
|
||||
personalPlanEmptyLayout.scheduleLayoutAnimation()
|
||||
}
|
||||
}, 64)
|
||||
})
|
||||
|
||||
@@ -18,7 +18,6 @@ import com.denizd.substitutionplan.*
|
||||
import com.denizd.substitutionplan.adapters.CardAdapter
|
||||
import com.denizd.substitutionplan.database.SubstViewModel
|
||||
import com.denizd.substitutionplan.models.Subst
|
||||
import com.denizd.substitutionplan.data.DataFetcher
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
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
|
||||
lateinit var prefs: SharedPreferences
|
||||
|
||||
lateinit var smileydown: TextView
|
||||
lateinit var smileydowntext: TextView
|
||||
lateinit var linearsmiley: LinearLayout
|
||||
var persPlanEmpty: Boolean = true
|
||||
lateinit var personalPlanEmptyEmoticon: TextView
|
||||
lateinit var personalPlanEmptyText: TextView
|
||||
lateinit var personalPlanEmptyLayout: LinearLayout
|
||||
var isPersonalPlanEmpty: Boolean = true
|
||||
val handler = Handler()
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
|
||||
@@ -14,7 +14,6 @@ import android.preference.PreferenceManager
|
||||
import android.provider.Settings
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import android.widget.*
|
||||
@@ -30,6 +29,7 @@ import com.denizd.substitutionplan.adapters.ColourAdapter
|
||||
import com.denizd.substitutionplan.adapters.RingtoneAdapter
|
||||
import com.denizd.substitutionplan.data.DataFetcher
|
||||
import com.denizd.substitutionplan.data.HelperFunctions
|
||||
import com.denizd.substitutionplan.data.Topic
|
||||
import com.denizd.substitutionplan.models.Colour
|
||||
import com.denizd.substitutionplan.models.Ringtone
|
||||
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 prefs: SharedPreferences
|
||||
private lateinit var edit: SharedPreferences.Editor
|
||||
private val builder = CustomTabsIntent.Builder()
|
||||
private val customTabsIntent = builder.build() as CustomTabsIntent
|
||||
private var cs: Int = 7
|
||||
@@ -58,50 +57,47 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
|
||||
super.onAttach(context)
|
||||
mContext = context
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(mContext)
|
||||
edit = prefs.edit()
|
||||
|
||||
window = activity?.window
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val txtName = view.findViewById<TextInputEditText>(R.id.txtName)
|
||||
val txtClasses = view.findViewById<TextInputEditText>(R.id.txtClasses)
|
||||
val txtCourses = view.findViewById<TextInputEditText>(R.id.txtCourses)
|
||||
val nameEditText = view.findViewById<TextInputEditText>(R.id.txtName)
|
||||
val gradeEditText = view.findViewById<TextInputEditText>(R.id.txtClasses)
|
||||
val courseEditText = view.findViewById<TextInputEditText>(R.id.txtCourses)
|
||||
|
||||
val switchDisableGreeting = view.findViewById<Switch>(R.id.switchDisableGreeting)
|
||||
// val switchDark = view.findViewById<Switch>(R.id.switchDark)
|
||||
val switchNotifications = view.findViewById<Switch>(R.id.switchNotifications)
|
||||
val switchDefaultPlan = view.findViewById<Switch>(R.id.switchDefaultPlan)
|
||||
val switchAutoRefresh = view.findViewById<Switch>(R.id.switchAutoRefresh)
|
||||
val versionNumber = view.findViewById<TextView>(R.id.txtVersionTwo)
|
||||
val helpCourses = view.findViewById<ImageButton>(R.id.chipHelpCourses)
|
||||
val helpClasses = view.findViewById<ImageButton>(R.id.chipHelpClasses)
|
||||
val btnCustomiseColours = view.findViewById<LinearLayout>(R.id.btnCustomiseColours)
|
||||
val btnVersion = view.findViewById<LinearLayout>(R.id.btnVersion)
|
||||
val greetingSwitch = view.findViewById<Switch>(R.id.switchDisableGreeting)
|
||||
val notificationSwitch = view.findViewById<Switch>(R.id.switchNotifications)
|
||||
val defaultPlanSwitch = view.findViewById<Switch>(R.id.switchDefaultPlan)
|
||||
val autoRefreshSwitch = view.findViewById<Switch>(R.id.switchAutoRefresh)
|
||||
val versionNumberText = view.findViewById<TextView>(R.id.txtVersionTwo)
|
||||
val helpGradeButton = view.findViewById<ImageButton>(R.id.chipHelpClasses)
|
||||
val helpCoursesButton = view.findViewById<ImageButton>(R.id.chipHelpCourses)
|
||||
val colourCustomisationButton = view.findViewById<LinearLayout>(R.id.btnCustomiseColours)
|
||||
val versionButton = view.findViewById<LinearLayout>(R.id.btnVersion)
|
||||
currentRingtone = view.findViewById(R.id.txtCustomiseRingtone2)
|
||||
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)
|
||||
switchNotifications.setOnCheckedChangeListener(this)
|
||||
switchDefaultPlan.setOnCheckedChangeListener(this)
|
||||
switchAutoRefresh.setOnCheckedChangeListener(this)
|
||||
helpCourses.setOnClickListener(this)
|
||||
helpClasses.setOnClickListener(this)
|
||||
btnCustomiseColours.setOnClickListener(this)
|
||||
notificationSwitch.setOnCheckedChangeListener(this)
|
||||
defaultPlanSwitch.setOnCheckedChangeListener(this)
|
||||
autoRefreshSwitch.setOnCheckedChangeListener(this)
|
||||
helpCoursesButton.setOnClickListener(this)
|
||||
helpGradeButton.setOnClickListener(this)
|
||||
colourCustomisationButton.setOnClickListener(this)
|
||||
view.findViewById<LinearLayout>(R.id.btnNoNotif).setOnClickListener(this)
|
||||
view.findViewById<LinearLayout>(R.id.btnCustomiseRingtone).setOnClickListener(this)
|
||||
view.findViewById<LinearLayout>(R.id.btnWebsite).setOnClickListener(this)
|
||||
view.findViewById<LinearLayout>(R.id.btnLicences).setOnClickListener(this)
|
||||
view.findViewById<LinearLayout>(R.id.btnTerms).setOnClickListener(this)
|
||||
view.findViewById<LinearLayout>(R.id.btnPrivacyP).setOnClickListener(this)
|
||||
btnVersion.setOnClickListener(this)
|
||||
btnForceRefresh.setOnClickListener(this)
|
||||
btnForceRefresh.setOnLongClickListener {
|
||||
edit.putString("timeNew", "").putString("newFoodTime", "").apply()
|
||||
versionButton.setOnClickListener(this)
|
||||
forceRefreshButton.setOnClickListener(this)
|
||||
forceRefreshButton.setOnLongClickListener {
|
||||
prefs.edit().putString("timeNew", "").putString("newFoodTime", "").apply()
|
||||
makeToast(mContext.getString(R.string.forcedRefreshTimes))
|
||||
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.setOnItemClickListener { _, _, position, _ ->
|
||||
edit.putInt("themeInt", position).apply()
|
||||
prefs.edit().putInt("themeInt", position).apply()
|
||||
|
||||
val bottomNav = view.rootView.findViewById<BottomNavigationView>(R.id.bottom_nav)
|
||||
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)
|
||||
switchDefaultPlan.isChecked = prefs.getBoolean("defaultPersonalised", false)
|
||||
switchAutoRefresh.isChecked = prefs.getBoolean("autoRefresh", false)
|
||||
notificationSwitch.isChecked = prefs.getBoolean("notif", false)
|
||||
defaultPlanSwitch.isChecked = prefs.getBoolean("defaultPersonalised", false)
|
||||
autoRefreshSwitch.isChecked = prefs.getBoolean("autoRefresh", false)
|
||||
|
||||
versionNumber.text = BuildConfig.VERSION_NAME
|
||||
versionNumberText.text = BuildConfig.VERSION_NAME
|
||||
|
||||
txtName.setText(prefs.getString("username", ""))
|
||||
txtName.addTextChangedListener(object: TextWatcher {
|
||||
nameEditText.setText(prefs.getString("username", ""))
|
||||
nameEditText.addTextChangedListener(object: TextWatcher {
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: 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", ""))
|
||||
txtClasses.addTextChangedListener(object: TextWatcher {
|
||||
gradeEditText.setText(prefs.getString("classes", ""))
|
||||
gradeEditText.addTextChangedListener(object: TextWatcher {
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: 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", ""))
|
||||
txtCourses.addTextChangedListener(object: TextWatcher {
|
||||
courseEditText.setText(prefs.getString("courses", ""))
|
||||
courseEditText.addTextChangedListener(object: TextWatcher {
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: 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))
|
||||
debugMenu()
|
||||
}
|
||||
@@ -282,31 +278,29 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
|
||||
).execute()
|
||||
}
|
||||
}
|
||||
edit.apply()
|
||||
}
|
||||
|
||||
override fun onCheckedChanged(v: CompoundButton?, isChecked: Boolean) {
|
||||
if (v?.isPressed == true) {
|
||||
when (v.id) {
|
||||
R.id.switchDisableGreeting -> {
|
||||
edit.putBoolean("greeting", isChecked)
|
||||
prefs.edit().putBoolean("greeting", isChecked).apply()
|
||||
}
|
||||
R.id.switchNotifications -> {
|
||||
edit.putBoolean("notif", isChecked)
|
||||
prefs.edit().putBoolean("notif", isChecked).apply()
|
||||
if (isChecked) {
|
||||
subToTopic("android")
|
||||
subscribeToTopic(Topic.ANDROID)
|
||||
} else {
|
||||
unsubFromTopic("android")
|
||||
unsubscribeFromTopic(Topic.ANDROID)
|
||||
}
|
||||
}
|
||||
R.id.switchDefaultPlan -> {
|
||||
edit.putBoolean("defaultPersonalised", isChecked)
|
||||
prefs.edit().putBoolean("defaultPersonalised", isChecked).apply()
|
||||
}
|
||||
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,
|
||||
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.dialogtext).text = text
|
||||
alertDialog.setView(dialogView).show()
|
||||
@@ -323,7 +317,7 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
|
||||
private fun createColourDialog() {
|
||||
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)
|
||||
titleText.text = getString(R.string.customiseColoursTitle)
|
||||
colourRecycler = dialogView.findViewById(R.id.recyclerView)
|
||||
@@ -390,7 +384,7 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
|
||||
} else {
|
||||
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)
|
||||
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) {
|
||||
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 pickerLayout = pickerDialogView.findViewById<LinearLayout>(R.id.empty_linearlayout)
|
||||
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)
|
||||
colourPickerBuilder.setView(pickerDialogView)
|
||||
val colourPickerDialog: AlertDialog = colourPickerBuilder.create()
|
||||
@@ -472,7 +466,6 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
|
||||
|
||||
for (i2 in buttons.indices) {
|
||||
picker.findViewById<MaterialButton>(buttons[i2]).setOnClickListener {
|
||||
// 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)
|
||||
@@ -484,10 +477,8 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
|
||||
}
|
||||
|
||||
private fun debugMenu(): Boolean {
|
||||
val alertDialog = AlertDialog.Builder(mContext,
|
||||
R.style.AlertDialog
|
||||
)
|
||||
val dialogView = LayoutInflater.from(mContext).inflate(R.layout.edittext_dialog, null)
|
||||
val alertDialog = AlertDialog.Builder(mContext, R.style.AlertDialog)
|
||||
val dialogView = View.inflate(mContext, R.layout.edittext_dialog, null)
|
||||
val dialogEditText = dialogView.findViewById<EditText>(R.id.dialog_edittext)
|
||||
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()) {
|
||||
"_DIAGNOSTICS" -> {
|
||||
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 resetLaunchBtn = devDialogView.findViewById<Button>(R.id.btnResetLaunch)
|
||||
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(
|
||||
R.string.diagnosticsMenu
|
||||
)
|
||||
devDialogText.text = getDiagnosticsText(prefs)
|
||||
devDialogText.text = getDiagnosticsText()
|
||||
|
||||
resetLaunchBtn.setOnClickListener {
|
||||
edit.putInt("launchDev", 0).apply()
|
||||
devDialogText.text = getDiagnosticsText(prefs)
|
||||
prefs.edit().putInt("launchDev", 0).apply()
|
||||
devDialogText.text = getDiagnosticsText()
|
||||
}
|
||||
|
||||
resetNotificationBtn.setOnClickListener {
|
||||
edit.putInt("pingFB", 0).apply()
|
||||
devDialogText.text = getDiagnosticsText(prefs)
|
||||
prefs.edit().putInt("pingFB", 0).apply()
|
||||
devDialogText.text = getDiagnosticsText()
|
||||
}
|
||||
|
||||
alertDialogDev.setView(devDialogView)
|
||||
@@ -534,34 +525,34 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
|
||||
}
|
||||
}
|
||||
"_FIRSTTIME" -> {
|
||||
edit.putBoolean("firstTime", true).apply()
|
||||
prefs.edit().putBoolean("firstTime", true).apply()
|
||||
makeToast("First time flag cleared")
|
||||
}
|
||||
"_TESTURLS" -> {
|
||||
val currentTest = !prefs.getBoolean("testUrls", false)
|
||||
edit.putBoolean("testUrls", currentTest).apply()
|
||||
prefs.edit().putBoolean("testUrls", currentTest).apply()
|
||||
makeToast("Test URLs set to $currentTest")
|
||||
}
|
||||
"_DEVCHANNEL" -> {
|
||||
val subbed = if (prefs.getBoolean("subscribedToFBDebugChannel", false)) {
|
||||
unsubFromTopic("debug")
|
||||
unsubscribeFromTopic(Topic.DEVELOPMENT)
|
||||
"Unsubscribed from"
|
||||
} else {
|
||||
subToTopic("debug")
|
||||
subscribeToTopic(Topic.DEVELOPMENT)
|
||||
"Subscribed to"
|
||||
}
|
||||
edit.putBoolean("subscribedToFBDebugChannel", !prefs.getBoolean("subscribedToFBDebugChannel", false)).apply()
|
||||
prefs.edit().putBoolean("subscribedToFBDebugChannel", !prefs.getBoolean("subscribedToFBDebugChannel", false)).apply()
|
||||
makeToast("$subbed Firebase development channel")
|
||||
}
|
||||
"_IOSCHANNEL" -> {
|
||||
val subbed = if (prefs.getBoolean("subscribedToiOSChannel", false)) {
|
||||
unsubFromTopic("ios")
|
||||
unsubscribeFromTopic(Topic.IOS)
|
||||
"Unsubscribed from"
|
||||
} else {
|
||||
subToTopic("ios")
|
||||
subscribeToTopic(Topic.IOS)
|
||||
"Subscribed to"
|
||||
}
|
||||
edit.putBoolean("subscribedToiOSChannel", !prefs.getBoolean("subscribedToiOSChannel", false)).apply()
|
||||
prefs.edit().putBoolean("subscribedToiOSChannel", !prefs.getBoolean("subscribedToiOSChannel", false)).apply()
|
||||
makeToast("$subbed iOS channel")
|
||||
}
|
||||
"_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()
|
||||
}
|
||||
|
||||
private fun getDiagnosticsText(prefs: SharedPreferences): String {
|
||||
private fun getDiagnosticsText(): String {
|
||||
return "First Launch: ${prefs.getString("firstTimeDev", "")}" +
|
||||
"\n\nApp launched: ${prefs.getInt("launchDev", 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\nAndroid Version: ${Build.VERSION.RELEASE}" +
|
||||
"\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)}"
|
||||
}
|
||||
|
||||
private fun subToTopic(topic: String) = FirebaseMessaging.getInstance().subscribeToTopic("substitutions-$topic")
|
||||
private fun unsubFromTopic(topic: String) = FirebaseMessaging.getInstance().unsubscribeFromTopic("substitutions-$topic")
|
||||
private fun subscribeToTopic(topic: Topic) = FirebaseMessaging.getInstance().subscribeToTopic(topic.tag)
|
||||
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.JobService
|
||||
import android.preference.PreferenceManager
|
||||
import com.denizd.substitutionplan.data.Topic
|
||||
import com.google.firebase.FirebaseApp
|
||||
import com.google.firebase.messaging.FirebaseMessaging
|
||||
|
||||
@@ -23,33 +24,29 @@ internal class FBPingService : JobService() {
|
||||
|
||||
private fun doBackgroundWork(params: JobParameters) {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
||||
FirebaseApp.initializeApp(context)
|
||||
|
||||
FirebaseMessaging.getInstance().apply {
|
||||
|
||||
if (prefs.getBoolean("notif", true)) {
|
||||
subscribeToTopic("substitutions-android")
|
||||
subscribeToTopic(Topic.ANDROID.tag)
|
||||
} else {
|
||||
unsubscribeFromTopic("substitutions-android")
|
||||
unsubscribeFromTopic(Topic.ANDROID.tag)
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("subscribedToFBDebugChannel", false)) {
|
||||
subscribeToTopic("substitutions-debug")
|
||||
subscribeToTopic(Topic.DEVELOPMENT.tag)
|
||||
} else {
|
||||
unsubscribeFromTopic("substitutions-debug")
|
||||
unsubscribeFromTopic(Topic.DEVELOPMENT.tag)
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("subscribedToiOSChannel", false)) {
|
||||
subscribeToTopic("substitutions-ios")
|
||||
subscribeToTopic(Topic.IOS.tag)
|
||||
} 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()
|
||||
|
||||
}
|
||||
jobFinished(params, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user