use KAE synthetic binding for layouts in SettingsFragment
continuous-integration/drone/push Build is passing Details

* closes #7
This commit is contained in:
Jannik 2020-09-02 15:36:03 +02:00
parent a3102bc3f2
commit 390728bfb7
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
8 changed files with 52 additions and 85 deletions

View File

@ -48,8 +48,6 @@ import org.mosad.seil0.projectlaogai.controller.NFCMensaCard
import org.mosad.seil0.projectlaogai.controller.cache.CacheController
import org.mosad.seil0.projectlaogai.controller.preferences.EncryptedPreferences
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.cColorAccent
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.cColorPrimary
import org.mosad.seil0.projectlaogai.fragments.*
import org.mosad.seil0.projectlaogai.util.NotificationUtils
import kotlin.system.measureTimeMillis
@ -200,9 +198,9 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
Aesthetic.config {
colorPrimary(cColorPrimary)
colorPrimaryDark(cColorPrimary)
colorAccent(cColorAccent)
colorPrimary(Preferences.colorPrimary)
colorPrimaryDark(Preferences.colorPrimary)
colorAccent(Preferences.colorAccent)
navigationViewMode(NavigationViewMode.SELECTED_ACCENT)
apply()
}

View File

@ -34,7 +34,6 @@ import kotlinx.coroutines.*
import org.mosad.seil0.projectlaogai.controller.QISPOSParser
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences
import org.mosad.seil0.projectlaogai.controller.TCoRAPIController
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.cCourse
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.coursesCacheTime
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.gradesCacheTime
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.mensaCacheTime
@ -78,8 +77,8 @@ class CacheController(cont: Context) {
GlobalScope.launch(Dispatchers.Default) {
val threads = listOf(
updateTimetable(cCourse.courseName, 0, context),
updateTimetable(cCourse.courseName, 1, context)
updateTimetable(Preferences.course.courseName, 0, context),
updateTimetable(Preferences.course.courseName, 1, context)
)
threads.joinAll()
}
@ -87,7 +86,7 @@ class CacheController(cont: Context) {
updateCourseList(context)
readStartCache(cCourse.courseName) // initially read values from cache
readStartCache(Preferences.course.courseName) // initially read values from cache
// check if an update is necessary, not blocking
if (currentTime - coursesCacheTime > 86400)

View File

@ -25,7 +25,7 @@ package org.mosad.seil0.projectlaogai.controller.cache
import android.content.Context
import kotlinx.coroutines.Job
import org.mosad.seil0.projectlaogai.controller.TCoRAPIController
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.cCourse
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences
import org.mosad.seil0.projectlaogai.util.Lesson
import org.mosad.seil0.projectlaogai.util.TimetableWeek
@ -49,8 +49,8 @@ object TimetableController {
*/
fun update(context: Context): List<Job> {
return listOf(
CacheController.updateTimetable(cCourse.courseName, 0, context),
CacheController.updateTimetable(cCourse.courseName, 1, context),
CacheController.updateTimetable(Preferences.course.courseName, 0, context),
CacheController.updateTimetable(Preferences.course.courseName, 1, context),
CacheController.updateAdditionalLessons(context)
)
}

View File

@ -37,14 +37,14 @@ object Preferences {
var mensaCacheTime: Long = 0
var timetableCacheTime: Long = 0
var gradesCacheTime: Long = 0
var cColorPrimary: Int = Color.parseColor("#009688")
var cColorAccent: Int = Color.parseColor("#0096ff")
var colorPrimary: Int = Color.parseColor("#009688")
var colorAccent: Int = Color.parseColor("#0096ff")
var gradesSyncInterval = 0
var cCourse = Course(
var course = Course(
"https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0",
"AI3"
)
var cShowBuffet = true
var showBuffet = true
var oGiants = false
// TODO move!
@ -92,7 +92,7 @@ object Preferences {
apply()
}
cCourse = course
this.course = course
}
/**
@ -111,7 +111,7 @@ object Preferences {
apply()
}
cColorPrimary = colorPrimary
this.colorPrimary = colorPrimary
}
/**
@ -130,7 +130,7 @@ object Preferences {
apply()
}
cColorAccent = colorAccent
this.colorAccent = colorAccent
}
fun saveGradesSync(context: Context, interval: Int) {
@ -165,7 +165,7 @@ object Preferences {
apply()
}
cShowBuffet = showBuffet
this.showBuffet = showBuffet
}
/**
@ -192,19 +192,17 @@ object Preferences {
)
// load saved course
cCourse = Course(
sharedPref.getString(context.getString(R.string.save_key_courseTTLink),
"https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0"
)!!,
course = Course(
sharedPref.getString(context.getString(R.string.save_key_courseTTLink),"https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0")!!,
sharedPref.getString(context.getString(R.string.save_key_course), "AI3")!!
)
// load saved colors
cColorPrimary = sharedPref.getInt(
context.getString(R.string.save_key_colorPrimary), cColorPrimary
colorPrimary = sharedPref.getInt(
context.getString(R.string.save_key_colorPrimary), colorPrimary
)
cColorAccent = sharedPref.getInt(
context.getString(R.string.save_key_colorAccent), cColorAccent
colorAccent = sharedPref.getInt(
context.getString(R.string.save_key_colorAccent), colorAccent
)
// load grades sync interval
@ -213,7 +211,7 @@ object Preferences {
)
// load showBuffet
cShowBuffet = sharedPref.getBoolean(
showBuffet = sharedPref.getBoolean(
context.getString(R.string.save_key_showBuffet), true
)
}

View File

@ -36,7 +36,6 @@ import org.mosad.seil0.projectlaogai.R
import org.mosad.seil0.projectlaogai.controller.cache.CacheController
import org.mosad.seil0.projectlaogai.controller.cache.CacheController.Companion.mensaMenu
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.cShowBuffet
import org.mosad.seil0.projectlaogai.uicomponents.DayCardView
import org.mosad.seil0.projectlaogai.uicomponents.MealLinearLayout
import org.mosad.seil0.projectlaogai.uicomponents.TextViewInfo
@ -97,7 +96,7 @@ class MensaFragment : Fragment() {
val mealLayout = MealLinearLayout(context)
mealLayout.setMeal(meal)
if(meal.heading != "Buffet" || cShowBuffet) {
if(meal.heading != "Buffet" || Preferences.showBuffet) {
dayCardView.getLinLayoutDay().addView(mealLayout)
helpMeal = mealLayout
}

View File

@ -28,9 +28,7 @@ import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.widget.SwitchCompat
import androidx.fragment.app.Fragment
import com.afollestad.aesthetic.Aesthetic
import com.afollestad.materialdialogs.MaterialDialog
@ -53,10 +51,6 @@ import org.mosad.seil0.projectlaogai.controller.cache.CacheController.Companion.
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences
import org.mosad.seil0.projectlaogai.controller.cache.TimetableController
import org.mosad.seil0.projectlaogai.controller.preferences.EncryptedPreferences
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.cColorAccent
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.cColorPrimary
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.cCourse
import org.mosad.seil0.projectlaogai.controller.preferences.Preferences.cShowBuffet
import org.mosad.seil0.projectlaogai.uicomponents.dialogs.LoginDialog
import org.mosad.seil0.projectlaogai.util.DataTypes
import java.util.*
@ -67,16 +61,6 @@ import java.util.*
*/
class SettingsFragment : Fragment() {
private lateinit var linLayoutUser: LinearLayout
private lateinit var linLayoutCourse: LinearLayout
private lateinit var linLayoutManageLessons: LinearLayout
private lateinit var linLayoutAbout: LinearLayout
private lateinit var linLayoutLicence: LinearLayout
private lateinit var linLayoutTheme: LinearLayout
private lateinit var linLayoutPrimaryColor: LinearLayout
private lateinit var linLayoutAccentColor: LinearLayout
private lateinit var linLayoutGradesSync: LinearLayout
private lateinit var switchBuffet: SwitchCompat
private lateinit var txtViewCourse: TextView
private var selectedTheme = DataTypes.Theme.Light
@ -91,17 +75,6 @@ class SettingsFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
linLayoutUser = view.findViewById(R.id.linLayout_User)
linLayoutCourse = view.findViewById(R.id.linLayout_Course)
linLayoutManageLessons = view.findViewById(R.id.linLayout_ManageLessons)
linLayoutAbout = view.findViewById(R.id.linLayout_About)
linLayoutLicence = view.findViewById(R.id.linLayout_Licence)
linLayoutTheme = view.findViewById(R.id.linLayout_Theme)
linLayoutPrimaryColor = view.findViewById(R.id.linLayout_PrimaryColor)
linLayoutAccentColor = view.findViewById(R.id.linLayout_AccentColor)
linLayoutGradesSync = view.findViewById(R.id.linLayout_GradesSync)
switchBuffet = view.findViewById(R.id.switch_buffet)
// if we call txtView_Course via KAE view binding it'll result in a NPE in the onDismissed call
txtViewCourse = view.findViewById(R.id.txtView_Course)
@ -109,14 +82,14 @@ class SettingsFragment : Fragment() {
txtView_User.text = EncryptedPreferences.email.ifEmpty { resources.getString(R.string.sample_user) }
txtView_Course.text = cCourse.courseName
txtView_Course.text = Preferences.course.courseName
txtView_AboutDesc.text = resources.getString(R.string.about_version, BuildConfig.VERSION_NAME, getString(R.string.build_time))
txtView_GradesSyncDesc.text = if (Preferences.gradesSyncInterval == 0) {
resources.getString(R.string.grades_sync_desc_never)
} else {
resources.getString(R.string.grades_sync_desc, Preferences.gradesSyncInterval)
}
switch_buffet.isChecked = cShowBuffet // init switch
switch_buffet.isChecked = Preferences.showBuffet // init switch
val outValue = TypedValue()
activity!!.theme.resolveAttribute(R.attr.themeName, outValue, true)
@ -144,7 +117,7 @@ class SettingsFragment : Fragment() {
* initialize some actions for SettingsFragment elements
*/
private fun initActions() {
linLayoutUser.setOnClickListener {
linLayout_User.setOnClickListener {
// open a new dialog
LoginDialog(context!!)
.positiveButton {
@ -156,20 +129,20 @@ class SettingsFragment : Fragment() {
}
}
linLayoutUser.setOnLongClickListener {
linLayout_User.setOnLongClickListener {
Preferences.oGiants = true // enable easter egg
return@setOnLongClickListener true
}
linLayoutCourse.setOnClickListener {
linLayout_Course.setOnClickListener {
selectCourse(context!!).show {
onDismiss {
txtViewCourse.text = cCourse.courseName // update txtView after the dialog is dismissed
txtViewCourse.text = Preferences.course.courseName // update txtView after the dialog is dismissed
}
}
}
linLayoutManageLessons.setOnClickListener {
linLayout_ManageLessons.setOnClickListener {
val lessons = ArrayList<String>()
TimetableController.subjectMap.forEach { pair ->
pair.value.forEach {
@ -181,8 +154,8 @@ class SettingsFragment : Fragment() {
title(R.string.manage_lessons)
positiveButton(R.string.delete)
negativeButton(R.string.cancel)
getActionButton(WhichButton.POSITIVE).updateTextColor(cColorAccent)
getActionButton(WhichButton.NEGATIVE).updateTextColor(cColorAccent)
getActionButton(WhichButton.POSITIVE).updateTextColor(Preferences.colorAccent)
getActionButton(WhichButton.NEGATIVE).updateTextColor(Preferences.colorAccent)
listItemsMultiChoice(items = lessons) { _, _, items ->
items.forEach {
@ -193,7 +166,7 @@ class SettingsFragment : Fragment() {
}
}
linLayoutAbout.setOnClickListener {
linLayout_About.setOnClickListener {
// open a new info dialog
MaterialDialog(context!!)
.title(R.string.about_dialog_heading)
@ -201,7 +174,7 @@ class SettingsFragment : Fragment() {
.show()
}
linLayoutLicence.setOnClickListener {
linLayout_Licence.setOnClickListener {
// do the theme magic, as the lib's theme support is broken
val outValue = TypedValue()
context!!.theme.resolveAttribute(R.attr.themeName, outValue, true)
@ -227,7 +200,7 @@ class SettingsFragment : Fragment() {
.show()
}
linLayoutTheme.setOnClickListener {
linLayout_Theme.setOnClickListener {
val themes = listOf(
resources.getString(R.string.themeLight),
resources.getString(R.string.themeDark),
@ -250,10 +223,10 @@ class SettingsFragment : Fragment() {
}
}
linLayoutPrimaryColor.setOnClickListener {
linLayout_PrimaryColor.setOnClickListener {
// open a new color chooser dialog
MaterialDialog(context!!)
.colorChooser(DataTypes().primaryColors, allowCustomArgb = true, initialSelection = cColorPrimary) { _, color ->
.colorChooser(DataTypes().primaryColors, allowCustomArgb = true, initialSelection = Preferences.colorPrimary) { _, color ->
view_PrimaryColor.setBackgroundColor(color)
Aesthetic.config {
colorPrimary(color)
@ -265,15 +238,15 @@ class SettingsFragment : Fragment() {
.show {
title(R.string.primary_color)
positiveButton(R.string.select)
getActionButton(WhichButton.POSITIVE).updateTextColor(cColorAccent)
getActionButton(WhichButton.POSITIVE).updateTextColor(Preferences.colorAccent)
}
}
linLayoutAccentColor.setOnClickListener {
linLayout_AccentColor.setOnClickListener {
// open a new color chooser dialog
MaterialDialog(context!!)
.colorChooser(DataTypes().accentColors, allowCustomArgb = true, initialSelection = cColorAccent) { _, color ->
.colorChooser(DataTypes().accentColors, allowCustomArgb = true, initialSelection = Preferences.colorAccent) { _, color ->
view_AccentColor.setBackgroundColor(color)
Aesthetic.config {
colorAccent(color)
@ -285,11 +258,11 @@ class SettingsFragment : Fragment() {
.show{
title(R.string.accent_color)
positiveButton(R.string.select)
getActionButton(WhichButton.POSITIVE).updateTextColor(cColorAccent)
getActionButton(WhichButton.POSITIVE).updateTextColor(Preferences.colorAccent)
}
}
linLayoutGradesSync.setOnClickListener {
linLayout_GradesSync.setOnClickListener {
val items = resources.getStringArray(R.array.syncInterval).toList()
val initial = when (Preferences.gradesSyncInterval) {
1 -> 1
@ -321,8 +294,8 @@ class SettingsFragment : Fragment() {
}.show()
}
switchBuffet.setOnClickListener {
Preferences.saveShowBuffet(context!!, switchBuffet.isChecked)
switch_buffet.setOnClickListener {
Preferences.saveShowBuffet(context!!, switch_buffet.isChecked)
}
}
@ -348,8 +321,8 @@ class SettingsFragment : Fragment() {
// update current & next weeks timetable
val threads = listOf(
CacheController.updateTimetable(cCourse.courseName, 0, context),
CacheController.updateTimetable(cCourse.courseName, 1, context)
CacheController.updateTimetable(Preferences.course.courseName, 0, context),
CacheController.updateTimetable(Preferences.course.courseName, 1, context)
)
threads.joinAll() // blocking since we want the new data

View File

@ -71,8 +71,8 @@ class AddSubjectDialog(val context: Context) {
spinnerSubjects = dialog.getCustomView().findViewById(R.id.spinner_Lessons)
// fix not working accent color
dialog.getActionButton(WhichButton.POSITIVE).updateTextColor(Preferences.cColorAccent)
dialog.getActionButton(WhichButton.NEGATIVE).updateTextColor(Preferences.cColorAccent)
dialog.getActionButton(WhichButton.POSITIVE).updateTextColor(Preferences.colorAccent)
dialog.getActionButton(WhichButton.NEGATIVE).updateTextColor(Preferences.colorAccent)
initSpinners()
}

View File

@ -56,8 +56,8 @@ class LoginDialog(val context: Context) {
editTextPassword = dialog.getCustomView().findViewById(R.id.editText_password)
// fix not working accent color
dialog.getActionButton(WhichButton.POSITIVE).updateTextColor(Preferences.cColorAccent)
dialog.getActionButton(WhichButton.NEGATIVE).updateTextColor(Preferences.cColorAccent)
dialog.getActionButton(WhichButton.POSITIVE).updateTextColor(Preferences.colorAccent)
dialog.getActionButton(WhichButton.NEGATIVE).updateTextColor(Preferences.colorAccent)
}
fun positiveButton(func: LoginDialog.() -> Unit): LoginDialog = apply {