This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preference screen with night mode and announcement settings
- Loading branch information
Showing
11 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.cyb3rko.cavedroid | ||
|
||
import android.app.Application | ||
import androidx.appcompat.app.AppCompatDelegate | ||
|
||
class App : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
AppCompatDelegate.setDefaultNightMode(getSharedPreferences(SHARED_PREFERENCE, MODE_PRIVATE).getString(NIGHTMODE, AppCompatDelegate | ||
.MODE_NIGHT_FOLLOW_SYSTEM.toString())!!.toInt()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/src/main/java/com/cyb3rko/cavedroid/PreferenceFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.cyb3rko.cavedroid | ||
|
||
import android.content.SharedPreferences | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.appcompat.app.AppCompatDelegate | ||
import androidx.preference.ListPreference | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.preference.SwitchPreference | ||
|
||
class PreferenceFragment : PreferenceFragmentCompat() { | ||
|
||
private lateinit var mySPR: SharedPreferences | ||
|
||
private lateinit var nightModeList: ListPreference | ||
private lateinit var showAnnouncementSwitch: SwitchPreference | ||
private lateinit var announcementImageSwitch: SwitchPreference | ||
private lateinit var analyticsCollectionSwitch: SwitchPreference | ||
private lateinit var crashlyticsCollectionSwitch: SwitchPreference | ||
|
||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
addPreferencesFromResource(R.xml.preferences) | ||
preferenceManager.sharedPreferencesName = SHARED_PREFERENCE | ||
mySPR = preferenceManager.sharedPreferences | ||
nightModeList = findPreference(NIGHTMODE)!! | ||
showAnnouncementSwitch = findPreference(SHOW_ANNOUNCEMENTS)!! | ||
announcementImageSwitch = findPreference(ANNOUNCEMENT_IMAGE)!! | ||
// analyticsCollectionSwitch = findPreference(ANALYTICS_COLLECTION)!! | ||
// crashlyticsCollectionSwitch = findPreference(CRASHLYTICS_COLLECTION)!! | ||
|
||
nightModeList.value = mySPR.getString(NIGHTMODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM.toString()) | ||
showAnnouncementSwitch.isChecked = mySPR.getBoolean(SHOW_ANNOUNCEMENTS, true) | ||
announcementImageSwitch.isChecked = mySPR.getBoolean(ANNOUNCEMENT_IMAGE, true) | ||
// analyticsCollectionSwitch.isChecked = mySPR.getBoolean(ANALYTICS_COLLECTION, true) | ||
// crashlyticsCollectionSwitch.isChecked = mySPR.getBoolean(CRASHLYTICS_COLLECTION, true) | ||
} | ||
|
||
override fun onPreferenceTreeClick(preference: Preference?): Boolean { | ||
return when (preference?.key) { | ||
NIGHTMODE -> { | ||
nightModeList.setOnPreferenceChangeListener { _, newValue -> | ||
AppCompatDelegate.setDefaultNightMode(newValue.toString().toInt()) | ||
true | ||
} | ||
true | ||
} | ||
// ANALYTICS_COLLECTION -> { | ||
// FirebaseAnalytics.getInstance(requireContext()).setAnalyticsCollectionEnabled(analyticsCollectionSwitch.isChecked) | ||
// true | ||
// } | ||
// CRASHLYTICS_COLLECTION -> { | ||
// FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(crashlyticsCollectionSwitch.isChecked) | ||
// true | ||
// } | ||
// DATA_DELETION -> { | ||
// FirebaseAnalytics.getInstance(requireActivity()).resetAnalyticsData() | ||
// FirebaseCrashlytics.getInstance().deleteUnsentReports() | ||
// Toasty.success(requireContext(), getString("Deletion done"), Toasty.LENGTH_SHORT).show() | ||
// true | ||
// } | ||
else -> false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.cyb3rko.cavedroid | ||
|
||
//internal const val PRIVACY_POLICY = "privacy_policy" | ||
//internal const val TERMS_OF_USE = "terms_of_use" | ||
|
||
//internal const val ANALYTICS_COLLECTION = "analytics_collection" | ||
internal const val ANNOUNCEMENT_IMAGE = "announcement_image" | ||
//internal const val CONSENT_DATE = "consent_date" | ||
//internal const val CONSENT_TIME = "consent_time" | ||
//internal const val CRASHLYTICS_COLLECTION = "crashlytics_collection" | ||
//internal const val DATA_DELETION = "data_deletion" | ||
//internal const val FIRST_START = "first_start" | ||
internal const val NIGHTMODE = "nightmode" | ||
internal const val SHARED_PREFERENCE = "Safe" | ||
internal const val SHOW_ANNOUNCEMENTS = "show_announcements" | ||
|
||
object Utils { | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string-array name="night_modes"> | ||
<item>System Default</item> | ||
<item>On</item> | ||
<item>Off</item> | ||
</string-array> | ||
<string-array name="night_modes_values"> | ||
<item>-1</item> | ||
<item>2</item> | ||
<item>1</item> | ||
</string-array> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<PreferenceCategory | ||
android:title="User Experience" | ||
app:iconSpaceReserved="false"> | ||
|
||
<ListPreference | ||
android:title="Night Mode" | ||
android:summary="Toggle the dark appearance of the app" | ||
app:iconSpaceReserved="false" | ||
android:defaultValue="" | ||
android:entries="@array/night_modes" | ||
android:entryValues="@array/night_modes_values" | ||
android:key="nightmode"/> | ||
|
||
</PreferenceCategory> | ||
|
||
<PreferenceCategory | ||
android:title="Announcements" | ||
app:iconSpaceReserved="false"> | ||
|
||
<SwitchPreference | ||
android:title="Show Announcements" | ||
android:summary="En-/Disable the anouncement dialog to view the latest Cavetale announcement" | ||
android:key="show_announcements" | ||
app:iconSpaceReserved="false" /> | ||
|
||
<SwitchPreference | ||
android:title="Include image of announcements (if available)" | ||
android:summary="Download and show images of anouncements if any available" | ||
android:key="announcement_image" | ||
app:iconSpaceReserved="false" /> | ||
|
||
</PreferenceCategory> | ||
|
||
<!-- <PreferenceCategory--> | ||
<!-- android:title="Data Collection"--> | ||
<!-- app:iconSpaceReserved="false">--> | ||
|
||
<!-- <SwitchPreferenceCompat--> | ||
<!-- android:title="Analytics Data Collection"--> | ||
<!-- android:summary="En-/Disable data collection via Firebase Analytics"--> | ||
<!-- android:key="analytics_collection"--> | ||
<!-- app:iconSpaceReserved="false" />--> | ||
|
||
<!-- <SwitchPreferenceCompat--> | ||
<!-- android:title="Crashlytics Data Collection"--> | ||
<!-- android:summary="En-/Disable data collection via Firebase Crashlytics"--> | ||
<!-- android:key="crashlytics_collection"--> | ||
<!-- app:iconSpaceReserved="false" />--> | ||
|
||
<!-- <Preference--> | ||
<!-- android:title="Reset Data Collection"--> | ||
<!-- android:summary="Reset your collected data for Analytics and Crashlytics"--> | ||
<!-- android:key="data_deletion"--> | ||
<!-- app:iconSpaceReserved="false" />--> | ||
|
||
<!-- </PreferenceCategory>--> | ||
|
||
</PreferenceScreen> |