-
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.
- Loading branch information
Showing
8 changed files
with
141 additions
and
18 deletions.
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
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
62 changes: 62 additions & 0 deletions
62
app/src/main/java/com/cyb3rko/logviewerforopenhab/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,62 @@ | ||
package com.cyb3rko.logviewerforopenhab | ||
|
||
import android.content.SharedPreferences | ||
import android.os.Bundle | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.preference.SwitchPreferenceCompat | ||
import com.google.firebase.analytics.FirebaseAnalytics | ||
import com.google.firebase.crashlytics.FirebaseCrashlytics | ||
import es.dmoral.toasty.Toasty | ||
|
||
class PreferenceFragment : PreferenceFragmentCompat() { | ||
|
||
private lateinit var analyticsCollectionSwitch: SwitchPreferenceCompat | ||
private lateinit var autoUpdateSwitch: SwitchPreferenceCompat | ||
private lateinit var connectionOverviewSwitch: SwitchPreferenceCompat | ||
private lateinit var crashlyticsCollectionSwitch: SwitchPreferenceCompat | ||
private lateinit var mySPR: SharedPreferences | ||
|
||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
addPreferencesFromResource(R.xml.preferences) | ||
preferenceManager.sharedPreferencesName = SHARED_PREFERENCE | ||
mySPR = preferenceManager.sharedPreferences | ||
connectionOverviewSwitch = findPreference("connectionOverviewEnabled")!! | ||
autoUpdateSwitch = findPreference("autoUpdate")!! | ||
analyticsCollectionSwitch = findPreference("analyticsCollection")!! | ||
crashlyticsCollectionSwitch = findPreference("crashlyticsCollection")!! | ||
|
||
connectionOverviewSwitch.isChecked = mySPR.getBoolean("connectionOverviewEnabled", true) | ||
autoUpdateSwitch.isChecked = mySPR.getBoolean("autoUpdate", true) | ||
analyticsCollectionSwitch.isChecked = mySPR.getBoolean("analyticsCollection", false) | ||
crashlyticsCollectionSwitch.isChecked = mySPR.getBoolean("crashlyticsCollection", false) | ||
} | ||
|
||
override fun onPreferenceTreeClick(preference: Preference?): Boolean { | ||
return when (preference?.key) { | ||
"connectionOverviewEnabled" -> { | ||
if (connectionOverviewSwitch.isChecked) { | ||
showConnections(mySPR, getListOfConnections(mySPR), activity) | ||
} else { | ||
hideConnections(requireActivity()) | ||
} | ||
true | ||
} | ||
"analyticsCollection" -> { | ||
FirebaseAnalytics.getInstance(requireContext()).setAnalyticsCollectionEnabled(analyticsCollectionSwitch.isChecked) | ||
true | ||
} | ||
"crashlyticsCollection" -> { | ||
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(crashlyticsCollectionSwitch.isChecked) | ||
true | ||
} | ||
"dataDeletion" -> { | ||
FirebaseAnalytics.getInstance(requireActivity()).resetAnalyticsData() | ||
FirebaseCrashlytics.getInstance().deleteUnsentReports() | ||
Toasty.success(requireContext(), "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
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,48 @@ | ||
<?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"> | ||
|
||
<SwitchPreferenceCompat | ||
android:title="Connection Overview" | ||
android:summary="En-/Disable the overview of recent connections in the Navigation Drawer" | ||
app:iconSpaceReserved="false" | ||
android:defaultValue="true" | ||
android:key="connectionOverviewEnabled" /> | ||
|
||
<SwitchPreferenceCompat | ||
android:title="Auto Update" | ||
android:summary="En-/Disable checking for updates and optionally downloading the newewst version" | ||
android:key="autoUpdate" | ||
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="analyticsCollection" | ||
app:iconSpaceReserved="false" /> | ||
|
||
<SwitchPreferenceCompat | ||
android:title="Crashlytics Data Collection" | ||
android:summary="En-/Disable data collection via Firebase Crashlytics" | ||
android:key="crashlyticsCollection" | ||
app:iconSpaceReserved="false" /> | ||
|
||
<Preference | ||
android:title="Reset Data Collection" | ||
android:summary="Reset your collected data for Analytics and Crashlytics" | ||
android:key="dataDeletion" | ||
app:iconSpaceReserved="false" /> | ||
|
||
</PreferenceCategory> | ||
|
||
</PreferenceScreen> |