WIP: JSON stream banner

This commit is contained in:
Philipp Heckel 2022-03-16 22:41:27 -04:00
parent 8e1830d361
commit 0bdcd3f85f
6 changed files with 135 additions and 6 deletions

View file

@ -301,6 +301,16 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas
.apply() .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? { fun getDefaultBaseUrl(): String? {
return sharedPrefs.getString(SHARED_PREFS_DEFAULT_BASE_URL, null) ?: 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! 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_BROADCAST_ENABLED = "BroadcastEnabled"
const val SHARED_PREFS_RECORD_LOGS_ENABLED = "RecordLogs" const val SHARED_PREFS_RECORD_LOGS_ENABLED = "RecordLogs"
const val SHARED_PREFS_BATTERY_OPTIMIZATIONS_REMIND_TIME = "BatteryOptimizationsRemindTime" 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_UNIFIED_PUSH_BASE_URL = "UnifiedPushBaseURL" // Legacy key required for migration to DefaultBaseURL
const val SHARED_PREFS_DEFAULT_BASE_URL = "DefaultBaseURL" const val SHARED_PREFS_DEFAULT_BASE_URL = "DefaultBaseURL"
const val SHARED_PREFS_LAST_TOPICS = "LastTopics" 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_ALWAYS = 1L
const val BATTERY_OPTIMIZATIONS_REMIND_TIME_NEVER = Long.MAX_VALUE 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 const val TAG = "NtfyRepository"
private var instance: Repository? = null private var instance: Repository? = null

View file

@ -119,8 +119,9 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
Log.addScrubTerm(s.topic) Log.addScrubTerm(s.topic)
} }
// Update battery banner // Update banner + JSON stream banner
showHideBatteryBanner(subscriptions) showHideBatteryBanner(subscriptions)
showHideJsonStreamBanner(subscriptions)
} }
} }
@ -168,6 +169,23 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
} }
} }
// JSON stream banner
val jsonStreamBanner = findViewById<View>(R.id.main_banner_json_stream) // Banner visibility is toggled in onResume()
val jsonStreamDismissButton = findViewById<Button>(R.id.main_banner_json_stream_dontaskagain)
val jsonStreamRemindButton = findViewById<Button>(R.id.main_banner_json_stream_remind_later)
val jsonStreamLearnMoreButton = findViewById<Button>(R.id.main_banner_json_stream_learn_mode)
jsonStreamDismissButton.setOnClickListener {
jsonStreamBanner.visibility = View.GONE
repository.setJsonStreamRemindTime(Repository.JSON_STREAM_REMIND_TIME_NEVER)
}
jsonStreamRemindButton.setOnClickListener {
jsonStreamBanner.visibility = View.GONE
repository.setJsonStreamRemindTime(System.currentTimeMillis() + ONE_DAY_MILLIS)
}
jsonStreamLearnMoreButton.setOnClickListener {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.main_banner_json_stream_button_learn_more_url))))
}
// Create notification channels right away, so we can configure them immediately after installing the app // Create notification channels right away, so we can configure them immediately after installing the app
dispatcher?.init() dispatcher?.init()
@ -199,6 +217,15 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
Log.d(TAG, "Battery: ignoring optimizations = $ignoringOptimizations (we want this to be true); instant subscriptions = $hasInstantSubscriptions; remind time reached = $batteryRemindTimeReached; banner = $showBanner") Log.d(TAG, "Battery: ignoring optimizations = $ignoringOptimizations (we want this to be true); instant subscriptions = $hasInstantSubscriptions; remind time reached = $batteryRemindTimeReached; banner = $showBanner")
} }
private fun showHideJsonStreamBanner(subscriptions: List<Subscription>) {
val hasSelfhostedSubscriptions = subscriptions.count { it.baseUrl != appBaseUrl } > 0
val usingWebSockets = repository.getConnectionProtocol() == Repository.CONNECTION_PROTOCOL_WS
val jsonStreamRemindTimeReached = repository.getJsonStreamRemindTime() < System.currentTimeMillis()
val showBanner = hasSelfhostedSubscriptions && jsonStreamRemindTimeReached && !usingWebSockets
val jsonStreamBanner = findViewById<View>(R.id.main_banner_json_stream)
jsonStreamBanner.visibility = if (showBanner) View.VISIBLE else View.GONE
}
private fun schedulePeriodicPollWorker() { private fun schedulePeriodicPollWorker() {
val workerVersion = repository.getPollWorkerVersion() val workerVersion = repository.getPollWorkerVersion()
val workPolicy = if (workerVersion == PollWorker.VERSION) { val workPolicy = if (workerVersion == PollWorker.VERSION) {

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M20,2L4,2c-1.1,0 -2,0.9 -2,2v18l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM20,16L5.17,16L4,17.17L4,4h16v12zM11,5h2v6h-2zM11,13h2v2h-2z"
android:fillColor="#FF9800"/>
</vector>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
@ -44,7 +44,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:text="@string/main_banner_battery_button_ask_later" android:text="@string/main_banner_battery_button_remind_later"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/main_banner_battery_fix_now" app:layout_constraintEnd_toStartOf="@id/main_banner_battery_fix_now"
app:layout_constraintTop_toBottomOf="@+id/main_banner_battery_text" app:layout_constraintTop_toBottomOf="@+id/main_banner_battery_text"
@ -77,6 +77,77 @@
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:shapeAppearance="?shapeAppearanceLargeComponent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@+id/main_banner_battery"
android:id="@+id/main_banner_json_stream" android:visibility="visible">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_banner_json_stream_constraint" android:elevation="5dp">
<ImageView
android:layout_width="28dp"
android:layout_height="28dp" app:srcCompat="@drawable/ic_announcement_orange_24dp"
android:id="@+id/main_banner_json_stream_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/main_banner_json_stream_text"
app:layout_constraintEnd_toStartOf="@id/main_banner_json_stream_text"
app:layout_constraintBottom_toBottomOf="@+id/main_banner_json_stream_text"
android:layout_marginStart="15dp"/>
<TextView
android:id="@+id/main_banner_json_stream_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/main_banner_json_stream_text"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="15dp" android:layout_marginTop="15dp"
app:layout_constraintStart_toEndOf="@+id/main_banner_json_stream_image"
android:layout_marginStart="10dp"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/main_banner_json_stream_remind_later"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/main_banner_json_stream_button_remind_later"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/main_banner_json_stream_text"
android:layout_marginBottom="5dp" app:layout_constraintEnd_toStartOf="@+id/main_banner_json_stream_learn_mode" android:layout_marginEnd="5dp"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/main_banner_json_stream_dontaskagain"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:text="@string/main_banner_json_stream_button_dismiss"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/main_banner_json_stream_remind_later"
app:layout_constraintTop_toBottomOf="@+id/main_banner_json_stream_text"
android:layout_marginBottom="5dp"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/main_banner_json_stream_learn_mode"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/main_banner_json_stream_button_learn_more"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/main_banner_json_stream_text"
android:layout_marginBottom="5dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="15dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/main_subscriptions_list_container" android:id="@+id/main_subscriptions_list_container"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -85,7 +156,7 @@
android:visibility="visible" android:visibility="visible"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/main_banner_battery"> app:layout_constraintTop_toBottomOf="@id/main_banner_json_stream">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/main_subscriptions_list" android:id="@+id/main_subscriptions_list"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -69,10 +69,17 @@
<!-- Main activity: Battery banner --> <!-- Main activity: Battery banner -->
<string name="main_banner_battery_text">Battery optimization should be disabled to avoid issues with notification delivery.</string> <string name="main_banner_battery_text">Battery optimization should be disabled to avoid issues with notification delivery.</string>
<string name="main_banner_battery_button_ask_later">Ask later</string> <string name="main_banner_battery_button_remind_later">Remind later</string>
<string name="main_banner_battery_button_dismiss">Don\'t ask again</string> <string name="main_banner_battery_button_dismiss">Dismiss</string>
<string name="main_banner_battery_button_fix_now">Fix now</string> <string name="main_banner_battery_button_fix_now">Fix now</string>
<!-- Main activity: JSON stream banner -->
<string name="main_banner_json_stream_text">Starting June 2022, WebSockets will be used to communicate with the server. Be sure get your selfhosted server ready.</string>
<string name="main_banner_json_stream_button_remind_later">Remind later</string>
<string name="main_banner_json_stream_button_dismiss">Dismiss</string>
<string name="main_banner_json_stream_button_learn_more">Learn more</string>
<string name="main_banner_json_stream_button_learn_more_url">https://ntfy.sh/docs/deprecations</string>
<!-- Add dialog --> <!-- Add dialog -->
<string name="add_dialog_title">Subscribe to topic</string> <string name="add_dialog_title">Subscribe to topic</string>
<string name="add_dialog_description_below"> <string name="add_dialog_description_below">

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H5.17L4 17.17V4h16v12zM11 5h2v6h-2zm0 8h2v2h-2z"/></svg>

After

Width:  |  Height:  |  Size: 277 B