From 0bdcd3f85f9f77bc9cac4dea153fe2e7ada2785a Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Wed, 16 Mar 2022 22:41:27 -0400 Subject: [PATCH] WIP: JSON stream banner --- .../main/java/io/heckel/ntfy/db/Repository.kt | 14 ++++ .../java/io/heckel/ntfy/ui/MainActivity.kt | 29 ++++++- .../drawable/ic_announcement_orange_24dp.xml | 9 +++ app/src/main/res/layout/activity_main.xml | 77 ++++++++++++++++++- app/src/main/res/values/strings.xml | 11 ++- assets/announcement_black_24dp.svg | 1 + 6 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable/ic_announcement_orange_24dp.xml create mode 100644 assets/announcement_black_24dp.svg diff --git a/app/src/main/java/io/heckel/ntfy/db/Repository.kt b/app/src/main/java/io/heckel/ntfy/db/Repository.kt index fada7d2..822f711 100644 --- a/app/src/main/java/io/heckel/ntfy/db/Repository.kt +++ b/app/src/main/java/io/heckel/ntfy/db/Repository.kt @@ -301,6 +301,16 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas .apply() } + fun getJsonStreamRemindTime(): Long { + return sharedPrefs.getLong(SHARED_PREFS_JSON_STREAM_REMIND_TIME, JSON_STREAM_REMIND_TIME_ALWAYS) + } + + fun setJsonStreamRemindTime(timeMillis: Long) { + sharedPrefs.edit() + .putLong(SHARED_PREFS_JSON_STREAM_REMIND_TIME, timeMillis) + .apply() + } + fun getDefaultBaseUrl(): String? { return sharedPrefs.getString(SHARED_PREFS_DEFAULT_BASE_URL, null) ?: sharedPrefs.getString(SHARED_PREFS_UNIFIED_PUSH_BASE_URL, null) // Fall back to UP URL, removed when default is set! @@ -434,6 +444,7 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas const val SHARED_PREFS_BROADCAST_ENABLED = "BroadcastEnabled" const val SHARED_PREFS_RECORD_LOGS_ENABLED = "RecordLogs" const val SHARED_PREFS_BATTERY_OPTIMIZATIONS_REMIND_TIME = "BatteryOptimizationsRemindTime" + const val SHARED_PREFS_JSON_STREAM_REMIND_TIME = "JsonStreamRemindTime" // Deprecation of JSON stream const val SHARED_PREFS_UNIFIED_PUSH_BASE_URL = "UnifiedPushBaseURL" // Legacy key required for migration to DefaultBaseURL const val SHARED_PREFS_DEFAULT_BASE_URL = "DefaultBaseURL" const val SHARED_PREFS_LAST_TOPICS = "LastTopics" @@ -464,6 +475,9 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas const val BATTERY_OPTIMIZATIONS_REMIND_TIME_ALWAYS = 1L const val BATTERY_OPTIMIZATIONS_REMIND_TIME_NEVER = Long.MAX_VALUE + const val JSON_STREAM_REMIND_TIME_ALWAYS = 1L + const val JSON_STREAM_REMIND_TIME_NEVER = Long.MAX_VALUE + private const val TAG = "NtfyRepository" private var instance: Repository? = null diff --git a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt index 6216d46..6d8db1d 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt @@ -119,8 +119,9 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc Log.addScrubTerm(s.topic) } - // Update battery banner + // Update banner + JSON stream banner showHideBatteryBanner(subscriptions) + showHideJsonStreamBanner(subscriptions) } } @@ -168,6 +169,23 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc } } + // JSON stream banner + val jsonStreamBanner = findViewById(R.id.main_banner_json_stream) // Banner visibility is toggled in onResume() + val jsonStreamDismissButton = findViewById