From ac8ce4cdc419a40a20d62aa1a45ca818dd450859 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 00:42:26 +0200 Subject: [PATCH 01/40] Init commit --- .../component/ui/news/TopNewsStore.kt | 3 ++ .../ui/onboarding/LoginPromptCard.kt | 11 ++++-- .../component/ui/overview/CardManager.kt | 39 +++++++++++++++++-- .../component/ui/overview/CardsRepository.kt | 11 ++++-- .../ui/overview/MainActivityViewModel.kt | 13 ++++++- .../component/ui/overview/MainFragment.kt | 1 + .../component/ui/overview/card/Card.kt | 29 +++++++++----- 7 files changed, 86 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsStore.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsStore.kt index 54cc9fd27f..e70706c322 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsStore.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsStore.kt @@ -62,6 +62,9 @@ class RealTopNewsStore @Inject constructor( } val displayUntil = sharedPrefs.getString(Const.NEWS_ALERT_SHOW_UNTIL, "")!! + if(displayUntil.isEmpty()){ + return null + } val until: DateTime? = DateTimeUtils.parseIsoDateWithMillis(displayUntil) if (until == null || until.isBeforeNow) { return null diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt index 166ccd1c6f..50f02742b4 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt @@ -19,14 +19,19 @@ import de.tum.`in`.tumcampusapp.utils.Utils */ class LoginPromptCard(context: Context) : Card(CardManager.CARD_LOGIN, context, "card_login") { + private val SHOW_LOGIN = "show_login" + public override fun discard(editor: SharedPreferences.Editor) { - Utils.setSetting(context, CardManager.SHOW_LOGIN, false) + //Utils.setSetting(context, CardManager.SHOW_LOGIN, false) + editor.putBoolean(SHOW_LOGIN, false) } override fun shouldShow(prefs: SharedPreferences): Boolean { // show on top as long as user hasn't swiped it away and isn't connected to TUMonline - return Utils.getSettingBool(context, CardManager.SHOW_LOGIN, true) && - Utils.getSetting(context, Const.LRZ_ID, "").isEmpty() + //return Utils.getSettingBool(context, CardManager.SHOW_LOGIN, true) && + // Utils.getSetting(context, Const.LRZ_ID, "").isEmpty() + return prefs.getBoolean(SHOW_LOGIN, true) && + prefs.getString(Const.LRZ_ID, "").isNullOrEmpty() } override fun getId(): Int { diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt index ec8f401567..09bd73cdad 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt @@ -7,6 +7,7 @@ import de.tum.`in`.tumcampusapp.database.TcaDb import de.tum.`in`.tumcampusapp.utils.Const.CARD_POSITION_PREFERENCE_SUFFIX import de.tum.`in`.tumcampusapp.utils.Const.DISCARD_SETTINGS_START import de.tum.`in`.tumcampusapp.utils.Utils +import org.jetbrains.anko.defaultSharedPreferences /** * Card manager, manages inserting, dismissing, updating and displaying of cards @@ -14,12 +15,31 @@ import de.tum.`in`.tumcampusapp.utils.Utils object CardManager { const val SHOW_SUPPORT = "show_support" - const val SHOW_LOGIN = "show_login" const val SHOW_TOP_NEWS = "show_top_news" /** * Card typ constants */ + enum class CardTypes(val id: Int) { + CAFETERIA(R.layout.card_cafeteria_menu), + TUITION_FEE(R.layout.card_tuition_fees), + NEXT_LECTURE(R.layout.card_next_lecture_item), + RESTORE(R.layout.card_restore), + NO_INTERNET(R.layout.card_no_internet), + MVV(R.layout.card_mvv), + NEWS(R.layout.card_news_item), + NEWS_FILM(R.layout.card_news_film_item), + EDUROAM(R.layout.card_eduroam), + CHAT(R.layout.card_chat_messages), + SUPPORT(R.layout.card_support), + LOGIN(R.layout.card_login_prompt), + EDUROAM_FIX(R.layout.card_eduroam_fix), + TOP_NEWS(R.layout.card_top_news), + EVENT(R.layout.card_events_item), + UPDATE_NOTE(R.layout.card_update_note) + + } + const val CARD_CAFETERIA = R.layout.card_cafeteria_menu const val CARD_TUITION_FEE = R.layout.card_tuition_fees const val CARD_NEXT_LECTURE = R.layout.card_next_lecture_item @@ -41,14 +61,25 @@ object CardManager { * Resets dismiss settings for all cards */ fun restoreCards(context: Context) { - context.getSharedPreferences(DISCARD_SETTINGS_START, 0) + CardTypes.values().forEach { + context.getSharedPreferences("CardPref" + it.id.toString(), Context.MODE_PRIVATE) .edit() + // wipe completly .clear() + //.putBoolean("shouldShow", true) .apply() + } + + println("HierHier" + "restored") + + context.getSharedPreferences(DISCARD_SETTINGS_START, 0) + .edit() + .clear() + .apply() TcaDb.getInstance(context) - .newsDao() - .restoreAllNews() + .newsDao() + .restoreAllNews() Utils.setSetting(context, SHOW_TOP_NEWS, true) restoreCardPositions(context) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardsRepository.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardsRepository.kt index fe72505677..31309b8415 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardsRepository.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardsRepository.kt @@ -20,6 +20,9 @@ import de.tum.`in`.tumcampusapp.component.ui.ticket.EventCardsProvider import de.tum.`in`.tumcampusapp.component.ui.transportation.TransportController import de.tum.`in`.tumcampusapp.component.ui.updatenote.UpdateNoteCard import de.tum.`in`.tumcampusapp.utils.Utils +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import org.jetbrains.anko.doAsync import javax.inject.Inject @@ -30,6 +33,8 @@ class CardsRepository @Inject constructor( private var cards = MutableLiveData>() + private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO + /** * Starts refresh of [Card]s and returns the corresponding [LiveData] * through which the result can be received. @@ -37,15 +42,15 @@ class CardsRepository @Inject constructor( * @return The [LiveData] of [Card]s */ fun getCards(): LiveData> { - refreshCards(CacheControl.USE_CACHE) + //refreshCards(CacheControl.USE_CACHE) return cards } /** * Refreshes the [LiveData] of [Card]s and updates its value. */ - fun refreshCards(cacheControl: CacheControl) { - doAsync { + suspend fun refreshCards(cacheControl: CacheControl) { + withContext(ioDispatcher) { val results = getCardsNow(cacheControl) cards.postValue(results) } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainActivityViewModel.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainActivityViewModel.kt index 380f4adfbb..9c44df4d97 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainActivityViewModel.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainActivityViewModel.kt @@ -2,8 +2,10 @@ package de.tum.`in`.tumcampusapp.component.ui.overview import androidx.lifecycle.LiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import de.tum.`in`.tumcampusapp.api.tumonline.CacheControl import de.tum.`in`.tumcampusapp.component.ui.overview.card.Card +import kotlinx.coroutines.launch import javax.inject.Inject class MainActivityViewModel @Inject constructor( @@ -11,9 +13,16 @@ class MainActivityViewModel @Inject constructor( ) : ViewModel() { val cards: LiveData> - get() = cardsRepo.getCards() + get() { + viewModelScope.launch { + cardsRepo.refreshCards(CacheControl.USE_CACHE) + } + return cardsRepo.getCards() + } fun refreshCards() { - cardsRepo.refreshCards(CacheControl.BYPASS_CACHE) + viewModelScope.launch { + cardsRepo.refreshCards(CacheControl.BYPASS_CACHE) + } } } \ No newline at end of file diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt index d6f3d3f63e..7ab9193794 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt @@ -126,6 +126,7 @@ class MainFragment : BaseFragment( swipeRefreshLayout.isRefreshing = true onRefresh() downloadNewsAlert() + println("Refresh finished") } private fun onNewCardsAvailable(cards: List) { diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt index 18dfdc1bd8..9d17196aef 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt @@ -10,6 +10,7 @@ import de.tum.`in`.tumcampusapp.component.other.navigation.NavDestination import de.tum.`in`.tumcampusapp.utils.Const.CARD_POSITION_PREFERENCE_SUFFIX import de.tum.`in`.tumcampusapp.utils.Const.DISCARD_SETTINGS_START import de.tum.`in`.tumcampusapp.utils.Utils +import org.jetbrains.anko.defaultSharedPreferences /** * Base class for all cards @@ -24,7 +25,9 @@ abstract class Card( ) : Comparable { // Settings for showing this card on start page or as notification - private var showStart = Utils.getSettingBool(context, settingsPrefix + "_start", true) + //private var showStart = Utils.getSettingBool(context, settingsPrefix + "_start", true) + private val cardSharedPreferences = context.getSharedPreferences("CardPref$cardType", Context.MODE_PRIVATE) + private val shouldShowPrefName = "shouldShow" open fun getId(): Int { return 0 @@ -70,8 +73,8 @@ abstract class Card( * Should be called after the user has dismissed the card */ fun discard() { - val prefs = context.getSharedPreferences(DISCARD_SETTINGS_START, 0) - val editor = prefs.edit() + //val prefs = context.getSharedPreferences(DISCARD_SETTINGS_START, 0) + val editor = cardSharedPreferences.edit() discard(editor) editor.apply() } @@ -82,17 +85,20 @@ abstract class Card( * @return The Card to be displayed or null */ open fun getIfShowOnStart(): Card? { - if (showStart) { - val prefs = context.getSharedPreferences(DISCARD_SETTINGS_START, 0) - if (shouldShow(prefs)) { + println("ShownOnStart " + context.resources.getResourceEntryName(cardType) + cardSharedPreferences.getBoolean("shouldShow", true)) + if (cardSharedPreferences.getBoolean(shouldShowPrefName, true)) { + //val prefs = context.getSharedPreferences(DISCARD_SETTINGS_START, 0) + if (shouldShow(cardSharedPreferences)) { return this } + println("ShownOnStart2 " + context.resources.getResourceEntryName(cardType) + shouldShow(cardSharedPreferences)) + } return null } /** - * Determines if the card should be shown. Decision is based on the given SharedPreferences. + * Determines if the card should be shown at the card level. Decision is based on the given SharedPreferences. * This method should be overridden in most cases. * * @return returns true if the card should be shown @@ -106,12 +112,17 @@ abstract class Card( * reactivated manually by the user */ open fun hideAlways() { - val prefs = PreferenceManager.getDefaultSharedPreferences(context) + cardSharedPreferences + .edit() + .putBoolean(shouldShowPrefName, false) + .apply() + Utils.log("Hiding card: $cardType") + /*val prefs = PreferenceManager.getDefaultSharedPreferences(context) val e = prefs.edit() e.putBoolean(settingsPrefix + "_start", false) e.putBoolean(settingsPrefix + "_phone", false) e.apply() - Utils.log("Hiding card: $settingsPrefix") + Utils.log("Hiding card: $settingsPrefix")*/ } override fun compareTo(other: Card): Int { From 7ca734906dcb90e898ea5737b221f817927a80fa Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:35:30 +0200 Subject: [PATCH 02/40] CardType as Enum and alyways hide to default prefs --- .../component/ui/overview/card/Card.kt | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt index 9d17196aef..94fd1bb6b6 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt @@ -3,12 +3,11 @@ package de.tum.`in`.tumcampusapp.component.ui.overview.card import android.content.Context import android.content.SharedPreferences import android.content.SharedPreferences.Editor -import android.preference.PreferenceManager import androidx.recyclerview.widget.DiffUtil import de.tum.`in`.tumcampusapp.R import de.tum.`in`.tumcampusapp.component.other.navigation.NavDestination +import de.tum.`in`.tumcampusapp.component.ui.overview.CardManager import de.tum.`in`.tumcampusapp.utils.Const.CARD_POSITION_PREFERENCE_SUFFIX -import de.tum.`in`.tumcampusapp.utils.Const.DISCARD_SETTINGS_START import de.tum.`in`.tumcampusapp.utils.Utils import org.jetbrains.anko.defaultSharedPreferences @@ -19,14 +18,14 @@ import org.jetbrains.anko.defaultSharedPreferences * @param settingsPrefix Preference key prefix used for all preferences belonging to that card */ abstract class Card( - val cardType: Int, + val cardType: CardManager.CardTypes, protected var context: Context, val settingsPrefix: String = "" ) : Comparable { // Settings for showing this card on start page or as notification //private var showStart = Utils.getSettingBool(context, settingsPrefix + "_start", true) - private val cardSharedPreferences = context.getSharedPreferences("CardPref$cardType", Context.MODE_PRIVATE) + private val cardSharedPreferences: SharedPreferences = context.getSharedPreferences("CardPref$cardType", Context.MODE_PRIVATE) private val shouldShowPrefName = "shouldShow" open fun getId(): Int { @@ -85,14 +84,10 @@ abstract class Card( * @return The Card to be displayed or null */ open fun getIfShowOnStart(): Card? { - println("ShownOnStart " + context.resources.getResourceEntryName(cardType) + cardSharedPreferences.getBoolean("shouldShow", true)) - if (cardSharedPreferences.getBoolean(shouldShowPrefName, true)) { - //val prefs = context.getSharedPreferences(DISCARD_SETTINGS_START, 0) + if (context.defaultSharedPreferences.getBoolean("$cardType$shouldShowPrefName", true)) { if (shouldShow(cardSharedPreferences)) { return this } - println("ShownOnStart2 " + context.resources.getResourceEntryName(cardType) + shouldShow(cardSharedPreferences)) - } return null } @@ -112,17 +107,11 @@ abstract class Card( * reactivated manually by the user */ open fun hideAlways() { - cardSharedPreferences + context.defaultSharedPreferences .edit() - .putBoolean(shouldShowPrefName, false) + .putBoolean("$cardType$shouldShowPrefName", false) .apply() Utils.log("Hiding card: $cardType") - /*val prefs = PreferenceManager.getDefaultSharedPreferences(context) - val e = prefs.edit() - e.putBoolean(settingsPrefix + "_start", false) - e.putBoolean(settingsPrefix + "_phone", false) - e.apply() - Utils.log("Hiding card: $settingsPrefix")*/ } override fun compareTo(other: Card): Int { From bced1dca65d258ad054dad2dbe72ba50aa41a1f7 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:37:01 +0200 Subject: [PATCH 03/40] Adopted to CardType enum --- .../in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt index 4575948940..7d886dd402 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt @@ -22,7 +22,7 @@ import java.util.* /** * Card that shows the cafeteria menu */ -class CafeteriaMenuCard(context: Context, private val cafeteria: CafeteriaWithMenus) : Card(CardManager.CARD_CAFETERIA, context, "card_cafeteria") { +class CafeteriaMenuCard(context: Context, private val cafeteria: CafeteriaWithMenus) : Card(CardManager.CardTypes.CAFETERIA, context, "card_cafeteria") { override val optionsMenuResId: Int get() = R.menu.card_popup_menu From b5ca54c59d1b3d849b57ca6c344c2c790e5d2124 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:37:31 +0200 Subject: [PATCH 04/40] Adopted to CardType enum --- .../tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt index 7d886dd402..f8d0035505 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt @@ -22,7 +22,8 @@ import java.util.* /** * Card that shows the cafeteria menu */ -class CafeteriaMenuCard(context: Context, private val cafeteria: CafeteriaWithMenus) : Card(CardManager.CardTypes.CAFETERIA, context, "card_cafeteria") { +class CafeteriaMenuCard(context: Context, private val cafeteria: CafeteriaWithMenus) : + Card(CardManager.CardTypes.CAFETERIA, context, "card_cafeteria") { override val optionsMenuResId: Int get() = R.menu.card_popup_menu From aebe7826f5b2cb862566a6123f57afe8d386ab3c Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:38:24 +0200 Subject: [PATCH 05/40] Adopted to CardType enum and CardSharedPreferences --- .../component/ui/eduroam/EduroamCard.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt index 323eeea2a5..661a7aefcb 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt @@ -7,7 +7,6 @@ import android.content.Intent import android.content.SharedPreferences import android.content.pm.PackageManager.PERMISSION_GRANTED import android.net.wifi.WifiManager -import android.preference.PreferenceManager import android.view.LayoutInflater import android.view.ViewGroup import androidx.core.content.ContextCompat.checkSelfPermission @@ -24,7 +23,7 @@ import org.jetbrains.anko.wifiManager /** * Card that can start [SetupEduroamActivity] */ -class EduroamCard(context: Context) : Card(CardManager.CARD_EDUROAM, context, "card_eduroam") { +class EduroamCard(context: Context) : Card(CardManager.CardTypes.EDUROAM, context, "card_eduroam") { override val optionsMenuResId: Int get() = R.menu.card_popup_menu @@ -39,7 +38,10 @@ class EduroamCard(context: Context) : Card(CardManager.CARD_EDUROAM, context, "c override fun shouldShow(prefs: SharedPreferences): Boolean { // Check if WiFi is turned on at all, as we cannot say if it was configured if it is off val wifiManager = context.wifiManager - return (wifiManager.isWifiEnabled && EduroamController.getEduroamConfig(context) == null && eduroamAvailable(wifiManager)) + return (wifiManager.isWifiEnabled + && EduroamController.getEduroamConfig(context) == null + && eduroamAvailable(wifiManager) + && prefs.getBoolean("card_eduroam_start", true)) } private fun eduroamAvailable(wifi: WifiManager): Boolean { @@ -54,9 +56,8 @@ class EduroamCard(context: Context) : Card(CardManager.CARD_EDUROAM, context, "c } override fun discard(editor: SharedPreferences.Editor) { - val prefs = PreferenceManager.getDefaultSharedPreferences(context) - prefs.edit().putBoolean("card_eduroam_start", false) - .apply() + editor.putBoolean("card_eduroam_start", false) + .apply() } override fun getId(): Int { From a14c91a382503a44259a2a264fccd94aac4dcc98 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:39:04 +0200 Subject: [PATCH 06/40] Adopted to CardType enum and CardSharedPreferences --- .../in/tumcampusapp/component/ui/eduroam/EduroamFixCard.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamFixCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamFixCard.kt index fda4e65343..ca6b7cdbe8 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamFixCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamFixCard.kt @@ -26,7 +26,7 @@ import java.util.regex.Pattern class EduroamFixCard( context: Context -) : Card(CardManager.CARD_EDUROAM_FIX, context, "card_eduroam_fix_start") { +) : Card(CardManager.CardTypes.EDUROAM_FIX, context, "card_eduroam_fix_start") { private val errors: MutableList = ArrayList() private lateinit var eduroam: WifiConfiguration @@ -72,11 +72,11 @@ class EduroamFixCard( // Check if wifi is turned on at all, as we cannot say if it was configured if its off return if (!context.wifiManager.isWifiEnabled) { false - } else !isConfigValid() + } else !isConfigValid() && prefs.getBoolean("card_eduroam_fix_start", true) } override fun discard(editor: SharedPreferences.Editor) { - context.defaultSharedPreferences.edit().putBoolean("card_eduroam_fix_start", false).apply() + editor.putBoolean("card_eduroam_fix_start", false) } override fun getId(): Int { From 4ebf4135fc368c7e6a5cb78a1339e95d24cd8acc Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:39:24 +0200 Subject: [PATCH 07/40] Adopted to CardType enum --- .../de/tum/in/tumcampusapp/component/ui/ticket/EventCard.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/EventCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/EventCard.kt index b6af0bdb61..43fc171bf0 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/EventCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/EventCard.kt @@ -21,7 +21,7 @@ import de.tum.`in`.tumcampusapp.component.ui.tufilm.KinoActivity import de.tum.`in`.tumcampusapp.database.TcaDb import de.tum.`in`.tumcampusapp.utils.Const -class EventCard(context: Context) : Card(CardManager.CARD_EVENT, context, "card_event") { +class EventCard(context: Context) : Card(CardManager.CardTypes.EVENT, context, "card_event") { var event: Event? = null From d9a8787c23843b3927fac2fbd8ba3c9930c1abe5 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:39:40 +0200 Subject: [PATCH 08/40] Adopted to CardType enum --- .../java/de/tum/in/tumcampusapp/component/ui/tufilm/FilmCard.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/tufilm/FilmCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/tufilm/FilmCard.kt index 85fdc219f3..4e287fb57f 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/tufilm/FilmCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/tufilm/FilmCard.kt @@ -13,7 +13,7 @@ import de.tum.`in`.tumcampusapp.utils.DateTimeUtils class FilmCard( context: Context, news: News -) : NewsCard(context, news, CardManager.CARD_NEWS_FILM) { +) : NewsCard(context, news, CardManager.CardTypes.NEWS_FILM) { override fun getNavigationDestination(): NavDestination { val args = Bundle() args.putString(Const.KINO_DATE, DateTimeUtils.getDateTimeString(date)) From bb415b8a048425476159f9179c2652335d6d06e3 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:40:03 +0200 Subject: [PATCH 09/40] Adopted to CardType enum --- .../tumcampusapp/component/ui/onboarding/LoginPromptCard.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt index 50f02742b4..a5d6caf51d 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt @@ -11,25 +11,21 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.CardManager import de.tum.`in`.tumcampusapp.component.ui.overview.card.Card import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder import de.tum.`in`.tumcampusapp.utils.Const -import de.tum.`in`.tumcampusapp.utils.Utils /** * Card that prompts the user to login to TUMonline since we don't show the wizard after the first launch anymore. * It will be shown until it is swiped away for the first time. */ -class LoginPromptCard(context: Context) : Card(CardManager.CARD_LOGIN, context, "card_login") { +class LoginPromptCard(context: Context) : Card(CardManager.CardTypes.LOGIN, context, "card_login") { private val SHOW_LOGIN = "show_login" public override fun discard(editor: SharedPreferences.Editor) { - //Utils.setSetting(context, CardManager.SHOW_LOGIN, false) editor.putBoolean(SHOW_LOGIN, false) } override fun shouldShow(prefs: SharedPreferences): Boolean { // show on top as long as user hasn't swiped it away and isn't connected to TUMonline - //return Utils.getSettingBool(context, CardManager.SHOW_LOGIN, true) && - // Utils.getSetting(context, Const.LRZ_ID, "").isEmpty() return prefs.getBoolean(SHOW_LOGIN, true) && prefs.getString(Const.LRZ_ID, "").isNullOrEmpty() } From 00414eaefb648668437a58256afa44c012539319 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:40:19 +0200 Subject: [PATCH 10/40] Adopted to CardType enum --- .../in/tumcampusapp/component/ui/transportation/MVVCard.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/transportation/MVVCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/transportation/MVVCard.kt index bb5d975eaa..ba2292c2ab 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/transportation/MVVCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/transportation/MVVCard.kt @@ -10,7 +10,7 @@ import androidx.recyclerview.widget.RecyclerView import de.tum.`in`.tumcampusapp.R import de.tum.`in`.tumcampusapp.component.other.navigation.NavDestination import de.tum.`in`.tumcampusapp.component.ui.overview.CardInteractionListener -import de.tum.`in`.tumcampusapp.component.ui.overview.CardManager.CARD_MVV +import de.tum.`in`.tumcampusapp.component.ui.overview.CardManager import de.tum.`in`.tumcampusapp.component.ui.overview.card.Card import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder import de.tum.`in`.tumcampusapp.component.ui.transportation.model.efa.Departure @@ -19,7 +19,7 @@ import de.tum.`in`.tumcampusapp.component.ui.transportation.model.efa.StationRes /** * Card that shows MVV departure times */ -class MVVCard(context: Context, val station: StationResult, val departures: List) : Card(CARD_MVV, context, "card_mvv") { +class MVVCard(context: Context, val station: StationResult, val departures: List) : Card(CardManager.CardTypes.MVV, context, "card_mvv") { override val optionsMenuResId: Int get() = R.menu.card_popup_menu From 345e4b97d5bb71851347c575cd0f2751d5699205 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:40:28 +0200 Subject: [PATCH 11/40] Adopted to CardType enum --- .../java/de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt index 971010ec2a..97de298aee 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt @@ -20,7 +20,7 @@ import org.joda.time.DateTime open class NewsCard @JvmOverloads constructor( context: Context, val news: News, - type: Int = CardManager.CARD_NEWS + type: CardManager.CardTypes = CardManager.CardTypes.NEWS ) : Card(type, context, "card_news") { override val optionsMenuResId: Int From 8e91ec667ab2cf1682f9ae6b4dc351b936271a51 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:40:39 +0200 Subject: [PATCH 12/40] Adopted to CardType enum --- .../in/tumcampusapp/component/tumui/calendar/NextLectureCard.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/NextLectureCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/NextLectureCard.kt index dd4278e6b3..d155524dc8 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/NextLectureCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/NextLectureCard.kt @@ -14,7 +14,7 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder import org.joda.time.DateTime import java.util.* -class NextLectureCard(context: Context) : Card(CardManager.CARD_NEXT_LECTURE, context, "card_next_lecture") { +class NextLectureCard(context: Context) : Card(CardManager.CardTypes.NEXT_LECTURE, context, "card_next_lecture") { private val calendarController: CalendarController = CalendarController(context) From a5622ed72b1e1438f56f67e56cb023da8a8bcc41 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:40:49 +0200 Subject: [PATCH 13/40] Adopted to CardType enum --- .../tum/in/tumcampusapp/component/ui/overview/NoInternetCard.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/NoInternetCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/NoInternetCard.kt index 8d5e8bba98..4297b5561f 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/NoInternetCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/NoInternetCard.kt @@ -17,7 +17,7 @@ import org.joda.time.DateTime /** * Card that informs that no internet connection is available */ -class NoInternetCard(context: Context) : StickyCard(CardManager.CARD_NO_INTERNET, context) { +class NoInternetCard(context: Context) : StickyCard(CardManager.CardTypes.NO_INTERNET, context) { override fun updateViewHolder(viewHolder: RecyclerView.ViewHolder) { super.updateViewHolder(viewHolder) From b5eb589db8dc116ada508cea422ee82e147f62e5 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:41:24 +0200 Subject: [PATCH 14/40] Adopted to CardType enum --- .../de/tum/in/tumcampusapp/component/ui/overview/RestoreCard.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/RestoreCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/RestoreCard.kt index 27f35ac011..fe4bad34fb 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/RestoreCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/RestoreCard.kt @@ -12,7 +12,7 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.card.StickyCard /** * Card that allows the user to reset the dismiss state of all cards */ -class RestoreCard(context: Context) : StickyCard(CardManager.CARD_RESTORE, context) { +class RestoreCard(context: Context) : StickyCard(CardManager.CardTypes.RESTORE, context) { /** * Override getPositionByDate, we want the RestoreCard to be the last card. From 45cfd353c7e928f354a345283fada848bef75cad Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:41:50 +0200 Subject: [PATCH 15/40] Adopted to CardType enum --- .../in/tumcampusapp/component/ui/overview/card/StickyCard.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/StickyCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/StickyCard.kt index 1e810a10ba..30f4103a78 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/StickyCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/StickyCard.kt @@ -2,8 +2,9 @@ package de.tum.`in`.tumcampusapp.component.ui.overview.card import android.content.Context import android.content.SharedPreferences +import de.tum.`in`.tumcampusapp.component.ui.overview.CardManager -abstract class StickyCard(cardType: Int, context: Context) : Card(cardType, context) { +abstract class StickyCard(cardType: CardManager.CardTypes, context: Context) : Card(cardType, context) { override val isDismissible: Boolean get() = false From e1b7deec840549a3138df322dc3e7f3a69a7bd09 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:42:39 +0200 Subject: [PATCH 16/40] Adopted to CardType enum and CardSharedPreferences --- .../component/ui/overview/SupportCard.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/SupportCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/SupportCard.kt index ed6dab8eba..8034088903 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/SupportCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/SupportCard.kt @@ -12,19 +12,21 @@ import android.view.ViewGroup import de.tum.`in`.tumcampusapp.R import de.tum.`in`.tumcampusapp.component.ui.overview.card.Card import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder -import de.tum.`in`.tumcampusapp.utils.Utils /** * Card that describes how to dismiss a card */ -class SupportCard(context: Context) : Card(CardManager.CARD_SUPPORT, context, "") { +class SupportCard(context: Context) : Card(CardManager.CardTypes.SUPPORT, context, "") { + + private val SHOW_SUPPORT = "show_support" public override fun discard(editor: Editor) { - Utils.setSetting(context, CardManager.SHOW_SUPPORT, false) + editor.putBoolean(SHOW_SUPPORT, false) } - override fun shouldShow(prefs: SharedPreferences) = - Utils.getSettingBool(context, CardManager.SHOW_SUPPORT, true) + override fun shouldShow(prefs: SharedPreferences): Boolean { + return prefs.getBoolean(SHOW_SUPPORT, true) + } override fun getId() = 0 @@ -34,14 +36,18 @@ class SupportCard(context: Context) : Card(CardManager.CARD_SUPPORT, context, "" val view = LayoutInflater.from(parent.context).inflate(R.layout.card_support, parent, false) view.findViewById(R.id.facebook_button).setOnClickListener { v -> val browserIntent = Intent(Intent.ACTION_VIEW) - browserIntent.data = Uri.parse(view.context - .getString(R.string.facebook_link)) + browserIntent.data = Uri.parse( + view.context + .getString(R.string.facebook_link) + ) v.context.startActivity(browserIntent) } view.findViewById(R.id.github_button).setOnClickListener { v -> val browserIntent = Intent(Intent.ACTION_VIEW) - browserIntent.data = Uri.parse(view.context - .getString(R.string.github_link)) + browserIntent.data = Uri.parse( + view.context + .getString(R.string.github_link) + ) v.context.startActivity(browserIntent) } view.findViewById(R.id.email_button).setOnClickListener { v -> From 7a44d95ae5c83e63c804c450c700c804b054da26 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:42:56 +0200 Subject: [PATCH 17/40] Adopted to CardType enum --- .../de/tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt index 3a578688ff..1fe579c823 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt @@ -24,7 +24,7 @@ import org.jetbrains.anko.defaultSharedPreferences /** * Shows important news */ -class TopNewsCard(context: Context) : Card(CardManager.CARD_TOP_NEWS, context, "top_news") { +class TopNewsCard(context: Context) : Card(CardManager.CardTypes.TOP_NEWS, context, "top_news") { private lateinit var imageView: ImageView private lateinit var progress: ProgressBar private val topNewsStore: TopNewsStore From 1d3c745769100d5f238a1ccda45193edc7eeb242 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:43:37 +0200 Subject: [PATCH 18/40] Adopted to CardType enum and CardSharedPreferences --- .../tumcampusapp/component/ui/updatenote/UpdateNoteCard.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/updatenote/UpdateNoteCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/updatenote/UpdateNoteCard.kt index e3dcbd41ef..5671e776ae 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/updatenote/UpdateNoteCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/updatenote/UpdateNoteCard.kt @@ -16,7 +16,7 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder import de.tum.`in`.tumcampusapp.utils.Const import de.tum.`in`.tumcampusapp.utils.Utils -class UpdateNoteCard(context: Context) : Card(CardManager.CARD_UPDATE_NOTE, context, "update_note") { +class UpdateNoteCard(context: Context) : Card(CardManager.CardTypes.UPDATE_NOTE, context, "update_note") { override fun updateViewHolder(viewHolder: RecyclerView.ViewHolder) { super.updateViewHolder(viewHolder) @@ -26,12 +26,12 @@ class UpdateNoteCard(context: Context) : Card(CardManager.CARD_UPDATE_NOTE, cont } override fun shouldShow(prefs: SharedPreferences): Boolean { - return Utils.getSettingBool(context, Const.SHOW_UPDATE_NOTE, false) && + return prefs.getBoolean(Const.SHOW_UPDATE_NOTE, false) && Utils.getSetting(context, Const.UPDATE_MESSAGE, "").isNotEmpty() } override fun discard(editor: SharedPreferences.Editor) { - Utils.setSetting(context, Const.SHOW_UPDATE_NOTE, false) + editor.putBoolean(Const.SHOW_UPDATE_NOTE, false) } companion object { From fc69a3097eb1a9524825119e491826e2ac1b914f Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:43:50 +0200 Subject: [PATCH 19/40] Adopted to CardType enum --- .../tumcampusapp/component/tumui/tutionfees/TuitionFeesCard.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/tutionfees/TuitionFeesCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/tutionfees/TuitionFeesCard.kt index 36e9b6d765..893ede9cbc 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/tutionfees/TuitionFeesCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/tutionfees/TuitionFeesCard.kt @@ -24,7 +24,7 @@ import org.joda.time.format.DateTimeFormat class TuitionFeesCard( context: Context, private val tuition: Tuition -) : Card(CardManager.CARD_TUITION_FEE, context, "card_tuition_fee") { +) : Card(CardManager.CardTypes.TUITION_FEE, context, "card_tuition_fee") { override val optionsMenuResId: Int get() = R.menu.card_popup_menu From 4495bc5ef66f2d4eea4ef5fdcca33e0b20a3faa0 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:44:12 +0200 Subject: [PATCH 20/40] Adopted to CardType enum --- .../component/ui/overview/CardAdapter.kt | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardAdapter.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardAdapter.kt index 1925b9ef94..bd464da562 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardAdapter.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardAdapter.kt @@ -27,20 +27,20 @@ class CardAdapter(private val interactionListener: CardInteractionListener) : Re override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): CardViewHolder { when (viewType) { - CardManager.CARD_CAFETERIA -> return CafeteriaMenuCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_TUITION_FEE -> return TuitionFeesCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_NEXT_LECTURE -> return NextLectureCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_RESTORE -> return RestoreCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_NO_INTERNET -> return NoInternetCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_MVV -> return MVVCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_NEWS, CardManager.CARD_NEWS_FILM -> return NewsCard.inflateViewHolder(viewGroup, viewType, interactionListener) - CardManager.CARD_EDUROAM -> return EduroamCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_EDUROAM_FIX -> return EduroamFixCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_SUPPORT -> return SupportCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_LOGIN -> return LoginPromptCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_TOP_NEWS -> return TopNewsCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_EVENT -> return EventCard.inflateViewHolder(viewGroup, interactionListener) - CardManager.CARD_UPDATE_NOTE -> return UpdateNoteCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.CAFETERIA.id -> return CafeteriaMenuCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.TUITION_FEE.id -> return TuitionFeesCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.NEXT_LECTURE.id -> return NextLectureCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.RESTORE.id -> return RestoreCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.NO_INTERNET.id -> return NoInternetCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.MVV.id -> return MVVCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.NEWS.id, CardManager.CardTypes.NEWS_FILM.id -> return NewsCard.inflateViewHolder(viewGroup, viewType, interactionListener) + CardManager.CardTypes.EDUROAM.id -> return EduroamCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.EDUROAM_FIX.id -> return EduroamFixCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.SUPPORT.id -> return SupportCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.LOGIN.id -> return LoginPromptCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.TOP_NEWS.id -> return TopNewsCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.EVENT.id -> return EventCard.inflateViewHolder(viewGroup, interactionListener) + CardManager.CardTypes.UPDATE_NOTE.id -> return UpdateNoteCard.inflateViewHolder(viewGroup, interactionListener) else -> throw UnsupportedOperationException() } } @@ -51,11 +51,11 @@ class CardAdapter(private val interactionListener: CardInteractionListener) : Re card.updateViewHolder(viewHolder) } - override fun getItemViewType(position: Int) = mItems[position].cardType + override fun getItemViewType(position: Int) = mItems[position].cardType.id override fun getItemId(position: Int): Long { val card = mItems[position] - return (card.cardType + (card.getId() shl 4)).toLong() + return (card.cardType.id + (card.getId() shl 4)).toLong() } override fun getItemCount() = mItems.size From b489de01edfff7888d9c20d8b21eda73c5c92e75 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:45:45 +0200 Subject: [PATCH 21/40] Adopted to CardType enum --- .../component/ui/overview/CardManager.kt | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt index 09bd73cdad..501162dce4 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt @@ -5,16 +5,13 @@ import android.preference.PreferenceManager import de.tum.`in`.tumcampusapp.R import de.tum.`in`.tumcampusapp.database.TcaDb import de.tum.`in`.tumcampusapp.utils.Const.CARD_POSITION_PREFERENCE_SUFFIX -import de.tum.`in`.tumcampusapp.utils.Const.DISCARD_SETTINGS_START import de.tum.`in`.tumcampusapp.utils.Utils -import org.jetbrains.anko.defaultSharedPreferences /** * Card manager, manages inserting, dismissing, updating and displaying of cards */ object CardManager { - const val SHOW_SUPPORT = "show_support" const val SHOW_TOP_NEWS = "show_top_news" /** @@ -40,43 +37,17 @@ object CardManager { } - const val CARD_CAFETERIA = R.layout.card_cafeteria_menu - const val CARD_TUITION_FEE = R.layout.card_tuition_fees - const val CARD_NEXT_LECTURE = R.layout.card_next_lecture_item - const val CARD_RESTORE = R.layout.card_restore - const val CARD_NO_INTERNET = R.layout.card_no_internet - const val CARD_MVV = R.layout.card_mvv - const val CARD_NEWS = R.layout.card_news_item - const val CARD_NEWS_FILM = R.layout.card_news_film_item - const val CARD_EDUROAM = R.layout.card_eduroam - const val CARD_CHAT = R.layout.card_chat_messages - const val CARD_SUPPORT = R.layout.card_support - const val CARD_LOGIN = R.layout.card_login_prompt - const val CARD_EDUROAM_FIX = R.layout.card_eduroam_fix - const val CARD_TOP_NEWS = R.layout.card_top_news - const val CARD_EVENT = R.layout.card_events_item - const val CARD_UPDATE_NOTE = R.layout.card_update_note - /** * Resets dismiss settings for all cards */ fun restoreCards(context: Context) { CardTypes.values().forEach { - context.getSharedPreferences("CardPref" + it.id.toString(), Context.MODE_PRIVATE) + context.getSharedPreferences("CardPref$it", Context.MODE_PRIVATE) .edit() - // wipe completly .clear() - //.putBoolean("shouldShow", true) .apply() } - println("HierHier" + "restored") - - context.getSharedPreferences(DISCARD_SETTINGS_START, 0) - .edit() - .clear() - .apply() - TcaDb.getInstance(context) .newsDao() .restoreAllNews() From 596884fe11cbddfe26c28195baed85cfb0e825b4 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 02:46:30 +0200 Subject: [PATCH 22/40] Replaced deprecated PreferenceManager --- .../tum/in/tumcampusapp/component/ui/overview/CardManager.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt index 501162dce4..c350669fab 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt @@ -1,11 +1,11 @@ package de.tum.`in`.tumcampusapp.component.ui.overview import android.content.Context -import android.preference.PreferenceManager import de.tum.`in`.tumcampusapp.R import de.tum.`in`.tumcampusapp.database.TcaDb import de.tum.`in`.tumcampusapp.utils.Const.CARD_POSITION_PREFERENCE_SUFFIX import de.tum.`in`.tumcampusapp.utils.Utils +import org.jetbrains.anko.defaultSharedPreferences /** * Card manager, manages inserting, dismissing, updating and displaying of cards @@ -57,7 +57,7 @@ object CardManager { } private fun restoreCardPositions(context: Context) { - val preferences = PreferenceManager.getDefaultSharedPreferences(context) + val preferences = context.defaultSharedPreferences val editor = preferences.edit() for (s in preferences.all.keys) { From fa90129b76e0dd2c27dd871e0f444e6b17b54bf8 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 15:03:24 +0200 Subject: [PATCH 23/40] Removed unnecessary apply --- .../de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt index 661a7aefcb..630daffc74 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt @@ -57,7 +57,6 @@ class EduroamCard(context: Context) : Card(CardManager.CardTypes.EDUROAM, contex override fun discard(editor: SharedPreferences.Editor) { editor.putBoolean("card_eduroam_start", false) - .apply() } override fun getId(): Int { From 3282293fc5f7d975d5fe4da408db8bffbadb14fc Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 15:15:50 +0200 Subject: [PATCH 24/40] Added paths to shared prefs and updated settings To include support card --- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/strings.xml | 19 +++++++++++++++++++ app/src/main/res/xml/settings.xml | 22 +++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 741091953d..0ddbdc85e4 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -339,6 +339,7 @@ Zeigt die Abfahrtszeiten der öffentlich Verkehrmittel an Zeigt Informationen zur nächsten Vorlesung an Erinnert dich, wenn du die Studiengebühren zahlen musst + Unterstütze uns durch Feedback oder teilen der App Schlägt ausgewählte News vor Benachrichtigt dich über neue Nachrichten Karte anpassen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4d4f81e842..c5b21e68f1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -333,6 +333,24 @@ You have to reregister until %s! Undo + + CafeteriaCardShown + TuitionFeeCardShown + NextLectureCardShown + RestoreCardShown + NoInternetCardShown + MVVCardShown + NewsCardShown + NewsFilmCardShown + EduroamCardShown + ChatCardShown + SupportCardShown + LoginCardShown + EduroamFixCardShown + TopNewsCardShown + EventCardShown + UpdateNoteCardShown + Swipe left or right to hide a card. If you want to hide a card permanently or you want to be notified if a new card is available open card-settings by long pressing on a card @@ -390,6 +408,7 @@ Shows you the departure times of public transport Shows information about your next lecture Reminds you when you have to pay your fees + Support us by giving feedback or sharing the app Advertises selected news Notifies you about new messages Chat diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index f13bee9e31..b586b467d3 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -231,6 +231,24 @@ + + + + + + + + + + + + Date: Wed, 5 Jul 2023 15:16:56 +0200 Subject: [PATCH 25/40] Adopted pref key ifShown stored in strings --- .../component/ui/overview/CardManager.kt | 35 +++++++++---------- .../component/ui/overview/card/Card.kt | 15 ++++---- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt index c350669fab..ed6e6e7b05 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardManager.kt @@ -17,24 +17,23 @@ object CardManager { /** * Card typ constants */ - enum class CardTypes(val id: Int) { - CAFETERIA(R.layout.card_cafeteria_menu), - TUITION_FEE(R.layout.card_tuition_fees), - NEXT_LECTURE(R.layout.card_next_lecture_item), - RESTORE(R.layout.card_restore), - NO_INTERNET(R.layout.card_no_internet), - MVV(R.layout.card_mvv), - NEWS(R.layout.card_news_item), - NEWS_FILM(R.layout.card_news_film_item), - EDUROAM(R.layout.card_eduroam), - CHAT(R.layout.card_chat_messages), - SUPPORT(R.layout.card_support), - LOGIN(R.layout.card_login_prompt), - EDUROAM_FIX(R.layout.card_eduroam_fix), - TOP_NEWS(R.layout.card_top_news), - EVENT(R.layout.card_events_item), - UPDATE_NOTE(R.layout.card_update_note) - + enum class CardTypes(val id: Int, val showCardPreferenceStringRes: Int) { + CAFETERIA(R.layout.card_cafeteria_menu, R.string.cafeteria_default_sharedpref_shown), + TUITION_FEE(R.layout.card_tuition_fees, R.string.tuition_fee_default_sharedpref_shown), + NEXT_LECTURE(R.layout.card_next_lecture_item, R.string.next_lecture_default_sharedpref_shown), + RESTORE(R.layout.card_restore, R.string.restore_default_sharedpref_shown), + NO_INTERNET(R.layout.card_no_internet, R.string.no_internet_default_sharedpref_shown), + MVV(R.layout.card_mvv, R.string.mvv_default_sharedpref_shown), + NEWS(R.layout.card_news_item, R.string.news_default_sharedpref_shown), + NEWS_FILM(R.layout.card_news_film_item, R.string.news_film_default_sharedpref_shown), + EDUROAM(R.layout.card_eduroam, R.string.eduroam_default_sharedpref_shown), + CHAT(R.layout.card_chat_messages, R.string.chat_default_sharedpref_shown), + SUPPORT(R.layout.card_support, R.string.support_default_sharedpref_shown), + LOGIN(R.layout.card_login_prompt, R.string.login_default_sharedpref_shown), + EDUROAM_FIX(R.layout.card_eduroam_fix, R.string.eduroam_fix_default_sharedpref_shown), + TOP_NEWS(R.layout.card_top_news, R.string.top_news_default_sharedpref_shown), + EVENT(R.layout.card_events_item, R.string.event_default_sharedpref_shown), + UPDATE_NOTE(R.layout.card_update_note, R.string.update_note_default_sharedpref_shown) } /** diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt index 94fd1bb6b6..4b44a291a9 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt @@ -23,10 +23,8 @@ abstract class Card( val settingsPrefix: String = "" ) : Comparable { - // Settings for showing this card on start page or as notification - //private var showStart = Utils.getSettingBool(context, settingsPrefix + "_start", true) - private val cardSharedPreferences: SharedPreferences = context.getSharedPreferences("CardPref$cardType", Context.MODE_PRIVATE) - private val shouldShowPrefName = "shouldShow" + // stores information for dismiss + private val dismissCardSharedPreferences: SharedPreferences = context.getSharedPreferences("CardPref$cardType", Context.MODE_PRIVATE) open fun getId(): Int { return 0 @@ -73,7 +71,7 @@ abstract class Card( */ fun discard() { //val prefs = context.getSharedPreferences(DISCARD_SETTINGS_START, 0) - val editor = cardSharedPreferences.edit() + val editor = dismissCardSharedPreferences.edit() discard(editor) editor.apply() } @@ -84,8 +82,8 @@ abstract class Card( * @return The Card to be displayed or null */ open fun getIfShowOnStart(): Card? { - if (context.defaultSharedPreferences.getBoolean("$cardType$shouldShowPrefName", true)) { - if (shouldShow(cardSharedPreferences)) { + if (context.defaultSharedPreferences.getBoolean(context.getString(cardType.showCardPreferenceStringRes), true)) { + if (shouldShow(dismissCardSharedPreferences)) { return this } } @@ -109,9 +107,10 @@ abstract class Card( open fun hideAlways() { context.defaultSharedPreferences .edit() - .putBoolean("$cardType$shouldShowPrefName", false) + .putBoolean(context.getString(cardType.showCardPreferenceStringRes), false) .apply() Utils.log("Hiding card: $cardType") + println() } override fun compareTo(other: Card): Int { From 684b4dc9af34bb2039ed5ef8cdefa071a70bf088 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 5 Jul 2023 16:22:58 +0200 Subject: [PATCH 26/40] Adopted existing settings to new shared pref model --- app/src/main/res/values-de/strings.xml | 5 +++++ app/src/main/res/values/strings.xml | 5 +++++ app/src/main/res/xml/settings.xml | 22 ++++++++++++++++------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0ddbdc85e4..135eb4418f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -347,6 +347,11 @@ Um Benachrichtigungen auf dem Telefon zu erhalten muss Wearable aktiviert sein Anzeige + + Startseite News + Startpage Top-News + Startpage Film-News + Öffnet Schließt Geschlossen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c5b21e68f1..bb7243dddc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -417,6 +417,11 @@ To receive notifications on your phone you have to enable Wearable Display + + Startpage news + Startpage top-news + Startpage film-news + Opens Closes Closed diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index b586b467d3..6144a5f550 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -47,7 +47,7 @@ @@ -196,7 +196,7 @@ + android:key="@string/news_default_sharedpref_shown" + android:title="@string/startpage_news" /> + + + + Date: Wed, 5 Jul 2023 20:10:14 +0200 Subject: [PATCH 27/40] Added previously ignored cards to settings --- app/src/main/res/drawable/ic_celebration.xml | 21 ++++++ app/src/main/res/drawable/ic_download.xml | 5 ++ app/src/main/res/drawable/ic_live_help.xml | 5 ++ app/src/main/res/drawable/ic_person_24.xml | 9 +++ app/src/main/res/values-de/strings.xml | 4 ++ app/src/main/res/values/strings.xml | 4 ++ app/src/main/res/xml/settings.xml | 76 +++++++++++++++++++- 7 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_celebration.xml create mode 100644 app/src/main/res/drawable/ic_download.xml create mode 100644 app/src/main/res/drawable/ic_live_help.xml create mode 100644 app/src/main/res/drawable/ic_person_24.xml diff --git a/app/src/main/res/drawable/ic_celebration.xml b/app/src/main/res/drawable/ic_celebration.xml new file mode 100644 index 0000000000..10ceb08299 --- /dev/null +++ b/app/src/main/res/drawable/ic_celebration.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_download.xml b/app/src/main/res/drawable/ic_download.xml new file mode 100644 index 0000000000..c7a77ca853 --- /dev/null +++ b/app/src/main/res/drawable/ic_download.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_live_help.xml b/app/src/main/res/drawable/ic_live_help.xml new file mode 100644 index 0000000000..ac8620024a --- /dev/null +++ b/app/src/main/res/drawable/ic_live_help.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_person_24.xml b/app/src/main/res/drawable/ic_person_24.xml new file mode 100644 index 0000000000..68ec21feb7 --- /dev/null +++ b/app/src/main/res/drawable/ic_person_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 135eb4418f..5516faabc8 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -340,8 +340,12 @@ Zeigt Informationen zur nächsten Vorlesung an Erinnert dich, wenn du die Studiengebühren zahlen musst Unterstütze uns durch Feedback oder teilen der App + Zeigt an wenn keine Internetverbindung vorhanden ist + Erlaubt dir dich mit TUMOnline zu verbinden Schlägt ausgewählte News vor Benachrichtigt dich über neue Nachrichten + Zeigt anstehenden Events an + Gibt eine Übersicht über neue Features Karte anpassen Karte immer ausblenden Um Benachrichtigungen auf dem Telefon zu erhalten muss Wearable aktiviert sein diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bb7243dddc..59e294e49b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -409,8 +409,12 @@ Shows information about your next lecture Reminds you when you have to pay your fees Support us by giving feedback or sharing the app + Shows when there is no internet connection + Allows you to connect to TUMOnline Advertises selected news Notifies you about new messages + Shows upcoming events + Provides an overview about new features Chat Open card settings Always hide card diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 6144a5f550..77308f2bf1 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -234,7 +234,7 @@ @@ -362,6 +362,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From ccadf28f335db34c51acdee9a9553b63451a33f7 Mon Sep 17 00:00:00 2001 From: Franz Date: Thu, 6 Jul 2023 04:48:36 +0200 Subject: [PATCH 28/40] Removed unused settings prefix --- .../component/tumui/calendar/NextLectureCard.kt | 2 +- .../component/tumui/tutionfees/TuitionFeesCard.kt | 2 +- .../component/ui/cafeteria/CafeteriaMenuCard.kt | 2 +- .../in/tumcampusapp/component/ui/eduroam/EduroamCard.kt | 2 +- .../tumcampusapp/component/ui/eduroam/EduroamFixCard.kt | 3 +-- .../de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt | 2 +- .../tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt | 2 +- .../component/ui/onboarding/LoginPromptCard.kt | 2 +- .../tumcampusapp/component/ui/overview/CardsRepository.kt | 2 -- .../in/tumcampusapp/component/ui/overview/SupportCard.kt | 8 ++++---- .../in/tumcampusapp/component/ui/overview/card/Card.kt | 2 -- .../tum/in/tumcampusapp/component/ui/ticket/EventCard.kt | 2 +- .../tumcampusapp/component/ui/transportation/MVVCard.kt | 2 +- .../component/ui/updatenote/UpdateNoteCard.kt | 2 +- 14 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/NextLectureCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/NextLectureCard.kt index d155524dc8..124022451d 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/NextLectureCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/NextLectureCard.kt @@ -14,7 +14,7 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder import org.joda.time.DateTime import java.util.* -class NextLectureCard(context: Context) : Card(CardManager.CardTypes.NEXT_LECTURE, context, "card_next_lecture") { +class NextLectureCard(context: Context) : Card(CardManager.CardTypes.NEXT_LECTURE, context) { private val calendarController: CalendarController = CalendarController(context) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/tutionfees/TuitionFeesCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/tutionfees/TuitionFeesCard.kt index 893ede9cbc..37f265846c 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/tutionfees/TuitionFeesCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/tutionfees/TuitionFeesCard.kt @@ -24,7 +24,7 @@ import org.joda.time.format.DateTimeFormat class TuitionFeesCard( context: Context, private val tuition: Tuition -) : Card(CardManager.CardTypes.TUITION_FEE, context, "card_tuition_fee") { +) : Card(CardManager.CardTypes.TUITION_FEE, context) { override val optionsMenuResId: Int get() = R.menu.card_popup_menu diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt index f8d0035505..877585df98 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt @@ -23,7 +23,7 @@ import java.util.* * Card that shows the cafeteria menu */ class CafeteriaMenuCard(context: Context, private val cafeteria: CafeteriaWithMenus) : - Card(CardManager.CardTypes.CAFETERIA, context, "card_cafeteria") { + Card(CardManager.CardTypes.CAFETERIA, context) { override val optionsMenuResId: Int get() = R.menu.card_popup_menu diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt index 630daffc74..f42560f9c3 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt @@ -23,7 +23,7 @@ import org.jetbrains.anko.wifiManager /** * Card that can start [SetupEduroamActivity] */ -class EduroamCard(context: Context) : Card(CardManager.CardTypes.EDUROAM, context, "card_eduroam") { +class EduroamCard(context: Context) : Card(CardManager.CardTypes.EDUROAM, context) { override val optionsMenuResId: Int get() = R.menu.card_popup_menu diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamFixCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamFixCard.kt index ca6b7cdbe8..eb65f4b50d 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamFixCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamFixCard.kt @@ -19,14 +19,13 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.card.Card import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder import de.tum.`in`.tumcampusapp.utils.Const import de.tum.`in`.tumcampusapp.utils.Utils -import org.jetbrains.anko.defaultSharedPreferences import org.jetbrains.anko.wifiManager import java.util.* import java.util.regex.Pattern class EduroamFixCard( context: Context -) : Card(CardManager.CardTypes.EDUROAM_FIX, context, "card_eduroam_fix_start") { +) : Card(CardManager.CardTypes.EDUROAM_FIX, context) { private val errors: MutableList = ArrayList() private lateinit var eduroam: WifiConfiguration diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt index 97de298aee..08418cc0b6 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt @@ -21,7 +21,7 @@ open class NewsCard @JvmOverloads constructor( context: Context, val news: News, type: CardManager.CardTypes = CardManager.CardTypes.NEWS -) : Card(type, context, "card_news") { +) : Card(type, context) { override val optionsMenuResId: Int get() = R.menu.card_popup_menu diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt index 1fe579c823..f362671924 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt @@ -24,7 +24,7 @@ import org.jetbrains.anko.defaultSharedPreferences /** * Shows important news */ -class TopNewsCard(context: Context) : Card(CardManager.CardTypes.TOP_NEWS, context, "top_news") { +class TopNewsCard(context: Context) : Card(CardManager.CardTypes.TOP_NEWS, context) { private lateinit var imageView: ImageView private lateinit var progress: ProgressBar private val topNewsStore: TopNewsStore diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt index a5d6caf51d..d766f9854d 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt @@ -16,7 +16,7 @@ import de.tum.`in`.tumcampusapp.utils.Const * Card that prompts the user to login to TUMonline since we don't show the wizard after the first launch anymore. * It will be shown until it is swiped away for the first time. */ -class LoginPromptCard(context: Context) : Card(CardManager.CardTypes.LOGIN, context, "card_login") { +class LoginPromptCard(context: Context) : Card(CardManager.CardTypes.LOGIN, context) { private val SHOW_LOGIN = "show_login" diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardsRepository.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardsRepository.kt index 31309b8415..ed1e32c157 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardsRepository.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/CardsRepository.kt @@ -23,7 +23,6 @@ import de.tum.`in`.tumcampusapp.utils.Utils import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import org.jetbrains.anko.doAsync import javax.inject.Inject class CardsRepository @Inject constructor( @@ -42,7 +41,6 @@ class CardsRepository @Inject constructor( * @return The [LiveData] of [Card]s */ fun getCards(): LiveData> { - //refreshCards(CacheControl.USE_CACHE) return cards } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/SupportCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/SupportCard.kt index 8034088903..09d819d12a 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/SupportCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/SupportCard.kt @@ -16,16 +16,16 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder /** * Card that describes how to dismiss a card */ -class SupportCard(context: Context) : Card(CardManager.CardTypes.SUPPORT, context, "") { +class SupportCard(context: Context) : Card(CardManager.CardTypes.SUPPORT, context) { - private val SHOW_SUPPORT = "show_support" + private val showSupport = "show_support" public override fun discard(editor: Editor) { - editor.putBoolean(SHOW_SUPPORT, false) + editor.putBoolean(showSupport, false) } override fun shouldShow(prefs: SharedPreferences): Boolean { - return prefs.getBoolean(SHOW_SUPPORT, true) + return prefs.getBoolean(showSupport, true) } override fun getId() = 0 diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt index 4b44a291a9..5bfd6ae69a 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt @@ -15,12 +15,10 @@ import org.jetbrains.anko.defaultSharedPreferences * Base class for all cards * @param cardType Individual integer for each card type * @param context Android Context - * @param settingsPrefix Preference key prefix used for all preferences belonging to that card */ abstract class Card( val cardType: CardManager.CardTypes, protected var context: Context, - val settingsPrefix: String = "" ) : Comparable { // stores information for dismiss diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/EventCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/EventCard.kt index 43fc171bf0..fbbf06dd32 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/EventCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/EventCard.kt @@ -21,7 +21,7 @@ import de.tum.`in`.tumcampusapp.component.ui.tufilm.KinoActivity import de.tum.`in`.tumcampusapp.database.TcaDb import de.tum.`in`.tumcampusapp.utils.Const -class EventCard(context: Context) : Card(CardManager.CardTypes.EVENT, context, "card_event") { +class EventCard(context: Context) : Card(CardManager.CardTypes.EVENT, context) { var event: Event? = null diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/transportation/MVVCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/transportation/MVVCard.kt index ba2292c2ab..bbc40fd344 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/transportation/MVVCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/transportation/MVVCard.kt @@ -19,7 +19,7 @@ import de.tum.`in`.tumcampusapp.component.ui.transportation.model.efa.StationRes /** * Card that shows MVV departure times */ -class MVVCard(context: Context, val station: StationResult, val departures: List) : Card(CardManager.CardTypes.MVV, context, "card_mvv") { +class MVVCard(context: Context, val station: StationResult, val departures: List) : Card(CardManager.CardTypes.MVV, context) { override val optionsMenuResId: Int get() = R.menu.card_popup_menu diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/updatenote/UpdateNoteCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/updatenote/UpdateNoteCard.kt index 5671e776ae..1755b56719 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/updatenote/UpdateNoteCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/updatenote/UpdateNoteCard.kt @@ -16,7 +16,7 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder import de.tum.`in`.tumcampusapp.utils.Const import de.tum.`in`.tumcampusapp.utils.Utils -class UpdateNoteCard(context: Context) : Card(CardManager.CardTypes.UPDATE_NOTE, context, "update_note") { +class UpdateNoteCard(context: Context) : Card(CardManager.CardTypes.UPDATE_NOTE, context) { override fun updateViewHolder(viewHolder: RecyclerView.ViewHolder) { super.updateViewHolder(viewHolder) From 3d096abad78c7a0fd548fd010a571d09de472dca Mon Sep 17 00:00:00 2001 From: Franz Date: Thu, 6 Jul 2023 05:27:54 +0200 Subject: [PATCH 29/40] Made card settings reachable from main screen --- .../other/settings/SettingsFragment.kt | 7 ++++++ .../ui/overview/card/CardViewHolder.kt | 3 ++- app/src/main/res/xml/settings.xml | 22 +++++++++---------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/other/settings/SettingsFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/other/settings/SettingsFragment.kt index 3a87df7738..930974da8a 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/other/settings/SettingsFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/other/settings/SettingsFragment.kt @@ -29,6 +29,7 @@ import de.tum.`in`.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocal import de.tum.`in`.tumcampusapp.component.ui.eduroam.SetupEduroamActivity import de.tum.`in`.tumcampusapp.component.ui.news.NewsController import de.tum.`in`.tumcampusapp.component.ui.onboarding.StartupActivity +import de.tum.`in`.tumcampusapp.component.ui.overview.CardManager import de.tum.`in`.tumcampusapp.database.TcaDb import de.tum.`in`.tumcampusapp.di.injector import de.tum.`in`.tumcampusapp.service.SilenceWorker @@ -219,6 +220,12 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic if (key == "language_preference" && activity != null) { (activity as SettingsActivity).restartApp() } + // restart app after visibility of card changed + val cardTypesPrefNames = CardManager.CardTypes.values().map { context?.getString(it.showCardPreferenceStringRes) } + // restart when visibility changed + if (key in cardTypesPrefNames){ + (activity as SettingsActivity).restartApp() + } } private fun initCafeteriaCardSelections() { diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/CardViewHolder.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/CardViewHolder.kt index 7492d6de53..e5a58a890d 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/CardViewHolder.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/CardViewHolder.kt @@ -54,7 +54,8 @@ open class CardViewHolder @JvmOverloads constructor( } private fun openCardSettings() { - val key = currentCard?.settingsPrefix ?: return + val resId = currentCard?.cardType?.showCardPreferenceStringRes ?: return + val key = context.getString(resId) val intent = SettingsActivity.newIntent(context, key) context.startActivity(intent) } diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 77308f2bf1..905ba50332 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -39,7 +39,7 @@ @@ -145,7 +145,7 @@ @@ -188,7 +188,7 @@ @@ -211,7 +211,7 @@ @@ -234,7 +234,7 @@ @@ -252,7 +252,7 @@ @@ -334,7 +334,7 @@ @@ -365,7 +365,7 @@ @@ -383,7 +383,7 @@ @@ -401,7 +401,7 @@ @@ -419,7 +419,7 @@ From 38eacda765f21cbd347eb111bc51a72cbe5f8348 Mon Sep 17 00:00:00 2001 From: Franz Date: Thu, 6 Jul 2023 05:49:27 +0200 Subject: [PATCH 30/40] Removed println --- .../de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt index 5bfd6ae69a..b0f3f60b4c 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt @@ -108,7 +108,6 @@ abstract class Card( .putBoolean(context.getString(cardType.showCardPreferenceStringRes), false) .apply() Utils.log("Hiding card: $cardType") - println() } override fun compareTo(other: Card): Int { From ce29bab93c53fd16e28840df3f8d1373c54c2917 Mon Sep 17 00:00:00 2001 From: Franz Date: Thu, 6 Jul 2023 06:32:34 +0200 Subject: [PATCH 31/40] Fixed formatting --- .../other/settings/SettingsFragment.kt | 33 ++++++++++--------- .../component/ui/eduroam/EduroamCard.kt | 8 ++--- .../component/ui/news/TopNewsStore.kt | 2 +- .../component/ui/overview/card/Card.kt | 6 ++-- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/other/settings/SettingsFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/other/settings/SettingsFragment.kt index 930974da8a..e1863232e0 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/other/settings/SettingsFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/other/settings/SettingsFragment.kt @@ -47,7 +47,7 @@ import java.util.concurrent.ExecutionException import javax.inject.Inject class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClickListener, - SharedPreferences.OnSharedPreferenceChangeListener { + SharedPreferences.OnSharedPreferenceChangeListener { private val compositeDisposable = CompositeDisposable() @@ -92,6 +92,7 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic setSummary("silent_mode_set_to") setSummary("background_mode_set_to") } + "card_cafeteria" -> { setSummary("card_cafeteria_default_G") setSummary("card_cafeteria_default_K") @@ -99,11 +100,13 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic setSummary("card_role") initCafeteriaCardSelections() } + "card_mvv" -> { setSummary("card_stations_default_G") setSummary("card_stations_default_C") setSummary("card_stations_default_K") } + "card_eduroam" -> { findPreference(SETUP_EDUROAM).onPreferenceClickListener = this } @@ -140,11 +143,11 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic url: String ) { compositeDisposable += Single - .fromCallable { Picasso.get().load(url).get() } - .subscribeOn(Schedulers.io()) - .map { BitmapDrawable(resources, it) } - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(preference::setIcon, Utils::log) + .fromCallable { Picasso.get().load(url).get() } + .subscribeOn(Schedulers.io()) + .map { BitmapDrawable(resources, it) } + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(preference::setIcon, Utils::log) } /** @@ -223,16 +226,16 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic // restart app after visibility of card changed val cardTypesPrefNames = CardManager.CardTypes.values().map { context?.getString(it.showCardPreferenceStringRes) } // restart when visibility changed - if (key in cardTypesPrefNames){ + if (key in cardTypesPrefNames) { (activity as SettingsActivity).restartApp() } } private fun initCafeteriaCardSelections() { val cafeterias = cafeteriaLocalRepository - .getAllCafeterias() - .blockingFirst() - .sortedBy { it.name } + .getAllCafeterias() + .blockingFirst() + .sortedBy { it.name } val cafeteriaByLocationName = getString(R.string.settings_cafeteria_depending_on_location) val cafeteriaNames = listOf(cafeteriaByLocationName) + cafeterias.map { it.name } @@ -267,11 +270,11 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic preference.setSummary(R.string.settings_no_location_selected) } else { preference.summary = values - .map { preference.findIndexOfValue(it) } - .map { preference.entries[it] } - .map { it.toString() } - .sorted() - .joinToString(", ") + .map { preference.findIndexOfValue(it) } + .map { preference.entries[it] } + .map { it.toString() } + .sorted() + .joinToString(", ") } } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt index f42560f9c3..75ed6fbcc3 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt @@ -38,10 +38,10 @@ class EduroamCard(context: Context) : Card(CardManager.CardTypes.EDUROAM, contex override fun shouldShow(prefs: SharedPreferences): Boolean { // Check if WiFi is turned on at all, as we cannot say if it was configured if it is off val wifiManager = context.wifiManager - return (wifiManager.isWifiEnabled - && EduroamController.getEduroamConfig(context) == null - && eduroamAvailable(wifiManager) - && prefs.getBoolean("card_eduroam_start", true)) + return (wifiManager.isWifiEnabled && + EduroamController.getEduroamConfig(context) == null && + eduroamAvailable(wifiManager) && + prefs.getBoolean("card_eduroam_start", true)) } private fun eduroamAvailable(wifi: WifiManager): Boolean { diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsStore.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsStore.kt index e70706c322..393e090c9c 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsStore.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsStore.kt @@ -62,7 +62,7 @@ class RealTopNewsStore @Inject constructor( } val displayUntil = sharedPrefs.getString(Const.NEWS_ALERT_SHOW_UNTIL, "")!! - if(displayUntil.isEmpty()){ + if (displayUntil.isEmpty()) { return null } val until: DateTime? = DateTimeUtils.parseIsoDateWithMillis(displayUntil) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt index b0f3f60b4c..261ff67a64 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt @@ -18,7 +18,7 @@ import org.jetbrains.anko.defaultSharedPreferences */ abstract class Card( val cardType: CardManager.CardTypes, - protected var context: Context, + protected var context: Context ) : Comparable { // stores information for dismiss @@ -131,9 +131,9 @@ abstract class Card( override fun getNewListSize() = newList.size override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int) = - oldList[oldItemPosition].cardType == newList[newItemPosition].cardType + oldList[oldItemPosition].cardType == newList[newItemPosition].cardType override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int) = - oldList[oldItemPosition] == newList[newItemPosition] + oldList[oldItemPosition] == newList[newItemPosition] } } From 292f5602c8cd9169272d65c112c3bcc5fea94e2a Mon Sep 17 00:00:00 2001 From: Franz Date: Thu, 6 Jul 2023 06:42:16 +0200 Subject: [PATCH 32/40] Fixed formatting --- .../de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt index 261ff67a64..a07ce8f653 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt @@ -68,7 +68,6 @@ abstract class Card( * Should be called after the user has dismissed the card */ fun discard() { - //val prefs = context.getSharedPreferences(DISCARD_SETTINGS_START, 0) val editor = dismissCardSharedPreferences.edit() discard(editor) editor.apply() From 92fc9558788e5f65f900a010f431561d3bebd512 Mon Sep 17 00:00:00 2001 From: Franz Date: Fri, 7 Jul 2023 15:29:35 +0200 Subject: [PATCH 33/40] Fixed bug where LoginPromptCard was incorrectly shown --- .../in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt index d766f9854d..10c549cf8d 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt @@ -11,6 +11,7 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.CardManager import de.tum.`in`.tumcampusapp.component.ui.overview.card.Card import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder import de.tum.`in`.tumcampusapp.utils.Const +import de.tum.`in`.tumcampusapp.utils.Utils /** * Card that prompts the user to login to TUMonline since we don't show the wizard after the first launch anymore. @@ -27,7 +28,7 @@ class LoginPromptCard(context: Context) : Card(CardManager.CardTypes.LOGIN, cont override fun shouldShow(prefs: SharedPreferences): Boolean { // show on top as long as user hasn't swiped it away and isn't connected to TUMonline return prefs.getBoolean(SHOW_LOGIN, true) && - prefs.getString(Const.LRZ_ID, "").isNullOrEmpty() + Utils.getSetting(context, Const.LRZ_ID, "").isEmpty() } override fun getId(): Int { From 5f564eb1128ba5c2fe209a2cf4bec68a7f235b5f Mon Sep 17 00:00:00 2001 From: Franz Date: Fri, 7 Jul 2023 15:34:45 +0200 Subject: [PATCH 34/40] Renamed Show_Login to showLogin --- .../tumcampusapp/component/ui/onboarding/LoginPromptCard.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt index 10c549cf8d..821b26f312 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/onboarding/LoginPromptCard.kt @@ -19,15 +19,15 @@ import de.tum.`in`.tumcampusapp.utils.Utils */ class LoginPromptCard(context: Context) : Card(CardManager.CardTypes.LOGIN, context) { - private val SHOW_LOGIN = "show_login" + private val showLogin = "show_login" public override fun discard(editor: SharedPreferences.Editor) { - editor.putBoolean(SHOW_LOGIN, false) + editor.putBoolean(showLogin, false) } override fun shouldShow(prefs: SharedPreferences): Boolean { // show on top as long as user hasn't swiped it away and isn't connected to TUMonline - return prefs.getBoolean(SHOW_LOGIN, true) && + return prefs.getBoolean(showLogin, true) && Utils.getSetting(context, Const.LRZ_ID, "").isEmpty() } From 71e602874e52fd751341109bf469e2e572dfb32f Mon Sep 17 00:00:00 2001 From: Franz Date: Fri, 7 Jul 2023 15:42:27 +0200 Subject: [PATCH 35/40] Added comment to discard(editor: Editor) to explain handling of the changes to the SharedPreferences --- .../de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt index a07ce8f653..3de56f7efd 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/card/Card.kt @@ -114,7 +114,8 @@ abstract class Card( } /** - * Save information about the dismissed card/notification to decide later if the cardView should be shown again + * Save information about the dismissed card/notification to decide later if the cardView should be shown again. + * It is exclusively called from [discard] where the changes made to the SharedPreferences are applied. * * @param editor Editor to be used for saving values */ From 5c14791025e8cf651e3888497581ec521fc93dae Mon Sep 17 00:00:00 2001 From: Franz Date: Fri, 7 Jul 2023 15:43:59 +0200 Subject: [PATCH 36/40] Removed left over println --- .../de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt index 7ab9193794..d6f3d3f63e 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt @@ -126,7 +126,6 @@ class MainFragment : BaseFragment( swipeRefreshLayout.isRefreshing = true onRefresh() downloadNewsAlert() - println("Refresh finished") } private fun onNewCardsAvailable(cards: List) { From d105ba0f10b6ee08cf08d0dcb998eb81c4c79b17 Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 12 Jul 2023 01:22:48 +0200 Subject: [PATCH 37/40] Fixed untranslated word startpage --- app/src/main/res/values-de/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 5516faabc8..9f49168e26 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -353,8 +353,8 @@ Startseite News - Startpage Top-News - Startpage Film-News + Startseite Top-News + Startseite Film-News Öffnet Schließt From 38364a279e458ee198b9ba84c4433ac4832a6c2e Mon Sep 17 00:00:00 2001 From: Franz Date: Wed, 12 Jul 2023 16:58:54 +0200 Subject: [PATCH 38/40] Fixes ImageView not shown for news with image --- .../de/tum/in/tumcampusapp/component/ui/news/NewsViewHolder.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsViewHolder.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsViewHolder.kt index 7219384597..9c878230ad 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsViewHolder.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsViewHolder.kt @@ -93,6 +93,7 @@ class NewsViewHolder( private fun bindNews(newsItem: News) { val imageUrl = newsItem.image if (imageUrl.isNotEmpty()) { + imageView?.visibility = VISIBLE loadNewsImage(imageUrl) } else { imageView?.visibility = GONE From 1df18e7d7e7ad812cbe6fb49c7aa5788c2745f6c Mon Sep 17 00:00:00 2001 From: Franz Date: Tue, 1 Aug 2023 05:44:52 +0200 Subject: [PATCH 39/40] Fixes discard cards reappearing after refreshing --- .../component/ui/overview/MainFragment.kt | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt index d6f3d3f63e..fcf7cb2e05 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt @@ -66,6 +66,8 @@ class MainFragment : BaseFragment( ViewModelProviders.of(this, factory).get(MainActivityViewModel::class.java) } + var snackBar: Snackbar? = null + override fun onAttach(context: Context) { super.onAttach(context) injector.inject(this) @@ -146,7 +148,18 @@ class MainFragment : BaseFragment( } override fun onRefresh() { - viewModel.refreshCards() + // check if SnackBar is shown + // if shown that means a card is in the process of being discarded + // to guarantee that the card is really discarded we will trigger the dismiss of the SnackBar manually + // if shown also refreshCards is called inside the dismiss-callback of the SnackBar + // this guarantees that it is always called after the dismissal is completed + // which because of the callback would not be the case otherwise + if(snackBar != null && snackBar!!.isShown){ + snackBar!!.dismiss() + } + else{ + viewModel.refreshCards() + } } override fun onAlwaysHideCard(position: Int) { @@ -225,7 +238,7 @@ class MainFragment : BaseFragment( cardsAdapter.remove(lastPos) with(binding) { - Snackbar.make(cardsRecyclerView, R.string.card_dismissed, Snackbar.LENGTH_LONG) + snackBar = Snackbar.make(cardsRecyclerView, R.string.card_dismissed, Snackbar.LENGTH_LONG) .setAction(R.string.undo) { card?.let { cardsAdapter.insert(lastPos, it) @@ -243,9 +256,13 @@ class MainFragment : BaseFragment( // and therefore, we didn't really dismiss the card card?.discard() } + if(event == DISMISS_EVENT_MANUAL){ + // manual dismissal means we need to call refresh here + viewModel.refreshCards() + } } }) - .show() + snackBar!!.show() } } } From 57cc222c662a8537dfbf6ace08a8fdb6b7337802 Mon Sep 17 00:00:00 2001 From: Franz Date: Tue, 1 Aug 2023 05:59:10 +0200 Subject: [PATCH 40/40] Fixed formatting --- .../in/tumcampusapp/component/ui/overview/MainFragment.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt index fcf7cb2e05..e997940d17 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/overview/MainFragment.kt @@ -154,10 +154,9 @@ class MainFragment : BaseFragment( // if shown also refreshCards is called inside the dismiss-callback of the SnackBar // this guarantees that it is always called after the dismissal is completed // which because of the callback would not be the case otherwise - if(snackBar != null && snackBar!!.isShown){ + if (snackBar != null && snackBar!!.isShown) { snackBar!!.dismiss() - } - else{ + } else { viewModel.refreshCards() } } @@ -256,7 +255,7 @@ class MainFragment : BaseFragment( // and therefore, we didn't really dismiss the card card?.discard() } - if(event == DISMISS_EVENT_MANUAL){ + if (event == DISMISS_EVENT_MANUAL) { // manual dismissal means we need to call refresh here viewModel.refreshCards() }