Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Fixes the CardView customization mentioned in #1582 #1595

Merged
merged 41 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ac8ce4c
Init commit
kunzef Jul 4, 2023
7ca7349
CardType as Enum and alyways hide to default prefs
kunzef Jul 5, 2023
bced1dc
Adopted to CardType enum
kunzef Jul 5, 2023
b5ca54c
Adopted to CardType enum
kunzef Jul 5, 2023
aebe782
Adopted to CardType enum and CardSharedPreferences
kunzef Jul 5, 2023
a14c91a
Adopted to CardType enum and CardSharedPreferences
kunzef Jul 5, 2023
4ebf413
Adopted to CardType enum
kunzef Jul 5, 2023
d9a8787
Adopted to CardType enum
kunzef Jul 5, 2023
bb415b8
Adopted to CardType enum
kunzef Jul 5, 2023
00414ea
Adopted to CardType enum
kunzef Jul 5, 2023
345e4b9
Adopted to CardType enum
kunzef Jul 5, 2023
8e91ec6
Adopted to CardType enum
kunzef Jul 5, 2023
a5622ed
Adopted to CardType enum
kunzef Jul 5, 2023
b5eb589
Adopted to CardType enum
kunzef Jul 5, 2023
45cfd35
Adopted to CardType enum
kunzef Jul 5, 2023
e1b7dee
Adopted to CardType enum and CardSharedPreferences
kunzef Jul 5, 2023
7a44d95
Adopted to CardType enum
kunzef Jul 5, 2023
1d3c745
Adopted to CardType enum and CardSharedPreferences
kunzef Jul 5, 2023
fc69a30
Adopted to CardType enum
kunzef Jul 5, 2023
4495bc5
Adopted to CardType enum
kunzef Jul 5, 2023
b489de0
Adopted to CardType enum
kunzef Jul 5, 2023
596884f
Replaced deprecated PreferenceManager
kunzef Jul 5, 2023
fa90129
Removed unnecessary apply
kunzef Jul 5, 2023
3282293
Added paths to shared prefs and updated settings
kunzef Jul 5, 2023
a72614a
Adopted pref key ifShown stored in strings
kunzef Jul 5, 2023
684b4dc
Adopted existing settings to new shared pref model
kunzef Jul 5, 2023
c37a589
Added previously ignored cards to settings
kunzef Jul 5, 2023
ccadf28
Removed unused settings prefix
kunzef Jul 6, 2023
3d096ab
Made card settings reachable from main screen
kunzef Jul 6, 2023
38eacda
Removed println
kunzef Jul 6, 2023
ce29bab
Fixed formatting
kunzef Jul 6, 2023
292f560
Fixed formatting
kunzef Jul 6, 2023
92fc955
Fixed bug where LoginPromptCard was incorrectly shown
kunzef Jul 7, 2023
5f564eb
Renamed Show_Login to showLogin
kunzef Jul 7, 2023
71e6028
Added comment to discard(editor: Editor) to explain handling of the c…
kunzef Jul 7, 2023
5c14791
Removed left over println
kunzef Jul 7, 2023
d105ba0
Fixed untranslated word startpage
kunzef Jul 11, 2023
38364a2
Fixes ImageView not shown for news with image
kunzef Jul 12, 2023
adce3f5
Merge branch 'TUM-Dev:master' into CardView-fix
kunzef Aug 1, 2023
1df18e7
Fixes discard cards reappearing after refreshing
kunzef Aug 1, 2023
57cc222
Fixed formatting
kunzef Aug 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,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()

Expand Down Expand Up @@ -91,18 +92,21 @@ 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")
setSummary("card_cafeteria_default_W")
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
}
Expand Down Expand Up @@ -139,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)
}

/**
Expand Down Expand Up @@ -219,13 +223,19 @@ 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() {
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 }
Expand Down Expand Up @@ -260,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(", ")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

private val calendarController: CalendarController = CalendarController(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

override val optionsMenuResId: Int
get() = R.menu.card_popup_menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ 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) {

override val optionsMenuResId: Int
get() = R.menu.card_popup_menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {

override val optionsMenuResId: Int
get() = R.menu.card_popup_menu
Expand All @@ -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 {
Expand All @@ -54,9 +56,7 @@ 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)
}

override fun getId(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.CARD_EDUROAM_FIX, context, "card_eduroam_fix_start") {
) : Card(CardManager.CardTypes.EDUROAM_FIX, context) {

private val errors: MutableList<String> = ArrayList()
private lateinit var eduroam: WifiConfiguration
Expand Down Expand Up @@ -72,11 +71,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import org.joda.time.DateTime
open class NewsCard @JvmOverloads constructor(
context: Context,
val news: News,
type: Int = CardManager.CARD_NEWS
) : Card(type, context, "card_news") {
type: CardManager.CardTypes = CardManager.CardTypes.NEWS
) : Card(type, context) {

override val optionsMenuResId: Int
get() = R.menu.card_popup_menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
private lateinit var imageView: ImageView
private lateinit var progress: ProgressBar
private val topNewsStore: TopNewsStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ 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) {

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()
}

override fun getId(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
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.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_LOGIN = "show_login"
const val SHOW_TOP_NEWS = "show_top_news"

/**
* Card typ constants
*/
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
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)
}

/**
* Resets dismiss settings for all cards
*/
fun restoreCards(context: Context) {
context.getSharedPreferences(DISCARD_SETTINGS_START, 0)
CardTypes.values().forEach {
context.getSharedPreferences("CardPref$it", Context.MODE_PRIVATE)
.edit()
.clear()
.apply()
}

TcaDb.getInstance(context)
.newsDao()
.restoreAllNews()
.newsDao()
.restoreAllNews()

Utils.setSetting(context, SHOW_TOP_NEWS, true)
restoreCardPositions(context)
}

private fun restoreCardPositions(context: Context) {
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val preferences = context.defaultSharedPreferences
val editor = preferences.edit()

for (s in preferences.all.keys) {
Expand Down
Loading