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

Commit 377cc3b

Browse files
authored
Fixes the CardView customization mentioned in #1582 (#1595)
* Init commit * CardType as Enum and alyways hide to default prefs * Adopted to CardType enum * Adopted to CardType enum * Adopted to CardType enum and CardSharedPreferences * Adopted to CardType enum and CardSharedPreferences * Adopted to CardType enum * Adopted to CardType enum * Adopted to CardType enum * Adopted to CardType enum * Adopted to CardType enum * Adopted to CardType enum * Adopted to CardType enum * Adopted to CardType enum * Adopted to CardType enum * Adopted to CardType enum and CardSharedPreferences * Adopted to CardType enum * Adopted to CardType enum and CardSharedPreferences * Adopted to CardType enum * Adopted to CardType enum * Adopted to CardType enum * Replaced deprecated PreferenceManager * Removed unnecessary apply * Added paths to shared prefs and updated settings To include support card * Adopted pref key ifShown stored in strings * Adopted existing settings to new shared pref model * Added previously ignored cards to settings * Removed unused settings prefix * Made card settings reachable from main screen * Removed println * Fixed formatting * Fixed formatting * Fixed bug where LoginPromptCard was incorrectly shown * Renamed Show_Login to showLogin * Added comment to discard(editor: Editor) to explain handling of the changes to the SharedPreferences * Removed left over println * Fixed untranslated word startpage * Fixes ImageView not shown for news with image * Fixes discard cards reappearing after refreshing * Fixed formatting
1 parent f966253 commit 377cc3b

33 files changed

+369
-138
lines changed

app/src/main/java/de/tum/in/tumcampusapp/component/other/settings/SettingsFragment.kt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import de.tum.`in`.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocal
2929
import de.tum.`in`.tumcampusapp.component.ui.eduroam.SetupEduroamActivity
3030
import de.tum.`in`.tumcampusapp.component.ui.news.NewsController
3131
import de.tum.`in`.tumcampusapp.component.ui.onboarding.StartupActivity
32+
import de.tum.`in`.tumcampusapp.component.ui.overview.CardManager
3233
import de.tum.`in`.tumcampusapp.database.TcaDb
3334
import de.tum.`in`.tumcampusapp.di.injector
3435
import de.tum.`in`.tumcampusapp.service.SilenceWorker
@@ -46,7 +47,7 @@ import java.util.concurrent.ExecutionException
4647
import javax.inject.Inject
4748

4849
class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClickListener,
49-
SharedPreferences.OnSharedPreferenceChangeListener {
50+
SharedPreferences.OnSharedPreferenceChangeListener {
5051

5152
private val compositeDisposable = CompositeDisposable()
5253

@@ -91,18 +92,21 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic
9192
setSummary("silent_mode_set_to")
9293
setSummary("background_mode_set_to")
9394
}
95+
9496
"card_cafeteria" -> {
9597
setSummary("card_cafeteria_default_G")
9698
setSummary("card_cafeteria_default_K")
9799
setSummary("card_cafeteria_default_W")
98100
setSummary("card_role")
99101
initCafeteriaCardSelections()
100102
}
103+
101104
"card_mvv" -> {
102105
setSummary("card_stations_default_G")
103106
setSummary("card_stations_default_C")
104107
setSummary("card_stations_default_K")
105108
}
109+
106110
"card_eduroam" -> {
107111
findPreference(SETUP_EDUROAM).onPreferenceClickListener = this
108112
}
@@ -139,11 +143,11 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic
139143
url: String
140144
) {
141145
compositeDisposable += Single
142-
.fromCallable { Picasso.get().load(url).get() }
143-
.subscribeOn(Schedulers.io())
144-
.map { BitmapDrawable(resources, it) }
145-
.observeOn(AndroidSchedulers.mainThread())
146-
.subscribe(preference::setIcon, Utils::log)
146+
.fromCallable { Picasso.get().load(url).get() }
147+
.subscribeOn(Schedulers.io())
148+
.map { BitmapDrawable(resources, it) }
149+
.observeOn(AndroidSchedulers.mainThread())
150+
.subscribe(preference::setIcon, Utils::log)
147151
}
148152

149153
/**
@@ -219,13 +223,19 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic
219223
if (key == "language_preference" && activity != null) {
220224
(activity as SettingsActivity).restartApp()
221225
}
226+
// restart app after visibility of card changed
227+
val cardTypesPrefNames = CardManager.CardTypes.values().map { context?.getString(it.showCardPreferenceStringRes) }
228+
// restart when visibility changed
229+
if (key in cardTypesPrefNames) {
230+
(activity as SettingsActivity).restartApp()
231+
}
222232
}
223233

224234
private fun initCafeteriaCardSelections() {
225235
val cafeterias = cafeteriaLocalRepository
226-
.getAllCafeterias()
227-
.blockingFirst()
228-
.sortedBy { it.name }
236+
.getAllCafeterias()
237+
.blockingFirst()
238+
.sortedBy { it.name }
229239

230240
val cafeteriaByLocationName = getString(R.string.settings_cafeteria_depending_on_location)
231241
val cafeteriaNames = listOf(cafeteriaByLocationName) + cafeterias.map { it.name }
@@ -260,11 +270,11 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic
260270
preference.setSummary(R.string.settings_no_location_selected)
261271
} else {
262272
preference.summary = values
263-
.map { preference.findIndexOfValue(it) }
264-
.map { preference.entries[it] }
265-
.map { it.toString() }
266-
.sorted()
267-
.joinToString(", ")
273+
.map { preference.findIndexOfValue(it) }
274+
.map { preference.entries[it] }
275+
.map { it.toString() }
276+
.sorted()
277+
.joinToString(", ")
268278
}
269279
}
270280

app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/NextLectureCard.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder
1414
import org.joda.time.DateTime
1515
import java.util.*
1616

17-
class NextLectureCard(context: Context) : Card(CardManager.CARD_NEXT_LECTURE, context, "card_next_lecture") {
17+
class NextLectureCard(context: Context) : Card(CardManager.CardTypes.NEXT_LECTURE, context) {
1818

1919
private val calendarController: CalendarController = CalendarController(context)
2020

app/src/main/java/de/tum/in/tumcampusapp/component/tumui/tutionfees/TuitionFeesCard.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.joda.time.format.DateTimeFormat
2424
class TuitionFeesCard(
2525
context: Context,
2626
private val tuition: Tuition
27-
) : Card(CardManager.CARD_TUITION_FEE, context, "card_tuition_fee") {
27+
) : Card(CardManager.CardTypes.TUITION_FEE, context) {
2828

2929
override val optionsMenuResId: Int
3030
get() = R.menu.card_popup_menu

app/src/main/java/de/tum/in/tumcampusapp/component/ui/cafeteria/CafeteriaMenuCard.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import java.util.*
2222
/**
2323
* Card that shows the cafeteria menu
2424
*/
25-
class CafeteriaMenuCard(context: Context, private val cafeteria: CafeteriaWithMenus) : Card(CardManager.CARD_CAFETERIA, context, "card_cafeteria") {
25+
class CafeteriaMenuCard(context: Context, private val cafeteria: CafeteriaWithMenus) :
26+
Card(CardManager.CardTypes.CAFETERIA, context) {
2627

2728
override val optionsMenuResId: Int
2829
get() = R.menu.card_popup_menu

app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamCard.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.content.Intent
77
import android.content.SharedPreferences
88
import android.content.pm.PackageManager.PERMISSION_GRANTED
99
import android.net.wifi.WifiManager
10-
import android.preference.PreferenceManager
1110
import android.view.LayoutInflater
1211
import android.view.ViewGroup
1312
import androidx.core.content.ContextCompat.checkSelfPermission
@@ -24,7 +23,7 @@ import org.jetbrains.anko.wifiManager
2423
/**
2524
* Card that can start [SetupEduroamActivity]
2625
*/
27-
class EduroamCard(context: Context) : Card(CardManager.CARD_EDUROAM, context, "card_eduroam") {
26+
class EduroamCard(context: Context) : Card(CardManager.CardTypes.EDUROAM, context) {
2827

2928
override val optionsMenuResId: Int
3029
get() = R.menu.card_popup_menu
@@ -39,7 +38,10 @@ class EduroamCard(context: Context) : Card(CardManager.CARD_EDUROAM, context, "c
3938
override fun shouldShow(prefs: SharedPreferences): Boolean {
4039
// Check if WiFi is turned on at all, as we cannot say if it was configured if it is off
4140
val wifiManager = context.wifiManager
42-
return (wifiManager.isWifiEnabled && EduroamController.getEduroamConfig(context) == null && eduroamAvailable(wifiManager))
41+
return (wifiManager.isWifiEnabled &&
42+
EduroamController.getEduroamConfig(context) == null &&
43+
eduroamAvailable(wifiManager) &&
44+
prefs.getBoolean("card_eduroam_start", true))
4345
}
4446

4547
private fun eduroamAvailable(wifi: WifiManager): Boolean {
@@ -54,9 +56,7 @@ class EduroamCard(context: Context) : Card(CardManager.CARD_EDUROAM, context, "c
5456
}
5557

5658
override fun discard(editor: SharedPreferences.Editor) {
57-
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
58-
prefs.edit().putBoolean("card_eduroam_start", false)
59-
.apply()
59+
editor.putBoolean("card_eduroam_start", false)
6060
}
6161

6262
override fun getId(): Int {

app/src/main/java/de/tum/in/tumcampusapp/component/ui/eduroam/EduroamFixCard.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.card.Card
1919
import de.tum.`in`.tumcampusapp.component.ui.overview.card.CardViewHolder
2020
import de.tum.`in`.tumcampusapp.utils.Const
2121
import de.tum.`in`.tumcampusapp.utils.Utils
22-
import org.jetbrains.anko.defaultSharedPreferences
2322
import org.jetbrains.anko.wifiManager
2423
import java.util.*
2524
import java.util.regex.Pattern
2625

2726
class EduroamFixCard(
2827
context: Context
29-
) : Card(CardManager.CARD_EDUROAM_FIX, context, "card_eduroam_fix_start") {
28+
) : Card(CardManager.CardTypes.EDUROAM_FIX, context) {
3029

3130
private val errors: MutableList<String> = ArrayList()
3231
private lateinit var eduroam: WifiConfiguration
@@ -72,11 +71,11 @@ class EduroamFixCard(
7271
// Check if wifi is turned on at all, as we cannot say if it was configured if its off
7372
return if (!context.wifiManager.isWifiEnabled) {
7473
false
75-
} else !isConfigValid()
74+
} else !isConfigValid() && prefs.getBoolean("card_eduroam_fix_start", true)
7675
}
7776

7877
override fun discard(editor: SharedPreferences.Editor) {
79-
context.defaultSharedPreferences.edit().putBoolean("card_eduroam_fix_start", false).apply()
78+
editor.putBoolean("card_eduroam_fix_start", false)
8079
}
8180

8281
override fun getId(): Int {

app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsCard.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import org.joda.time.DateTime
2020
open class NewsCard @JvmOverloads constructor(
2121
context: Context,
2222
val news: News,
23-
type: Int = CardManager.CARD_NEWS
24-
) : Card(type, context, "card_news") {
23+
type: CardManager.CardTypes = CardManager.CardTypes.NEWS
24+
) : Card(type, context) {
2525

2626
override val optionsMenuResId: Int
2727
get() = R.menu.card_popup_menu

app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/NewsViewHolder.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class NewsViewHolder(
9393
private fun bindNews(newsItem: News) {
9494
val imageUrl = newsItem.image
9595
if (imageUrl.isNotEmpty()) {
96+
imageView?.visibility = VISIBLE
9697
loadNewsImage(imageUrl)
9798
} else {
9899
imageView?.visibility = GONE

app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsCard.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.jetbrains.anko.defaultSharedPreferences
2424
/**
2525
* Shows important news
2626
*/
27-
class TopNewsCard(context: Context) : Card(CardManager.CARD_TOP_NEWS, context, "top_news") {
27+
class TopNewsCard(context: Context) : Card(CardManager.CardTypes.TOP_NEWS, context) {
2828
private lateinit var imageView: ImageView
2929
private lateinit var progress: ProgressBar
3030
private val topNewsStore: TopNewsStore

app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/TopNewsStore.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class RealTopNewsStore @Inject constructor(
6262
}
6363

6464
val displayUntil = sharedPrefs.getString(Const.NEWS_ALERT_SHOW_UNTIL, "")!!
65+
if (displayUntil.isEmpty()) {
66+
return null
67+
}
6568
val until: DateTime? = DateTimeUtils.parseIsoDateWithMillis(displayUntil)
6669
if (until == null || until.isBeforeNow) {
6770
return null

0 commit comments

Comments
 (0)