diff --git a/app/build.gradle b/app/build.gradle index 311f198..3023a88 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,20 +34,16 @@ android { debug { minifyEnabled false debuggable true - applicationIdSuffix ".debug" - versionNameSuffix "-debug" } } flavorDimensions "store" productFlavors { - forPlay { - dimension "store" - buildConfigField 'String', 'STORE', '"play"' + play { + buildConfigField 'boolean', 'FIREBASE_AVAILABLE', 'true' } - forFDroid { - dimension "store" - buildConfigField 'String', 'STORE', '"fdroid"' + fdroid { + buildConfigField 'boolean', 'FIREBASE_AVAILABLE', 'false' } } @@ -81,7 +77,7 @@ dependencies { implementation "com.squareup.okhttp3:okhttp:4.9.2" // Firebase, sigh ... (only Google Play) - forPlayImplementation 'com.google.firebase:firebase-messaging:22.0.0' + playImplementation 'com.google.firebase:firebase-messaging:22.0.0' // RecyclerView implementation "androidx.recyclerview:recyclerview:$rootProject.recyclerViewVersion" diff --git a/app/src/fdroid/java/io/heckel/ntfy/firebase/FirebaseMessenger.kt b/app/src/fdroid/java/io/heckel/ntfy/firebase/FirebaseMessenger.kt new file mode 100644 index 0000000..e121d2f --- /dev/null +++ b/app/src/fdroid/java/io/heckel/ntfy/firebase/FirebaseMessenger.kt @@ -0,0 +1,11 @@ +package io.heckel.ntfy.firebase + +class FirebaseMessenger { + fun subscribe(topic: String) { + // Dummy to keep F-Droid flavor happy + } + + fun unsubscribe(topic: String) { + // Dummy to keep F-Droid flavor happy + } +} diff --git a/app/src/fdroid/java/io/heckel/ntfy/firebase/FirebaseService.kt b/app/src/fdroid/java/io/heckel/ntfy/firebase/FirebaseService.kt new file mode 100644 index 0000000..51030ce --- /dev/null +++ b/app/src/fdroid/java/io/heckel/ntfy/firebase/FirebaseService.kt @@ -0,0 +1,5 @@ +package io.heckel.ntfy.firebase + +class FirebaseService { + // Dummy to keep F-Droid flavor happy +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a3f257d..549fd3d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,9 +53,9 @@ - + diff --git a/app/src/main/java/io/heckel/ntfy/app/Application.kt b/app/src/main/java/io/heckel/ntfy/app/Application.kt index 79f3201..12e29f8 100644 --- a/app/src/main/java/io/heckel/ntfy/app/Application.kt +++ b/app/src/main/java/io/heckel/ntfy/app/Application.kt @@ -2,10 +2,8 @@ package io.heckel.ntfy.app import android.app.Application import android.content.Context -import com.google.firebase.messaging.FirebaseMessagingService import io.heckel.ntfy.data.Database import io.heckel.ntfy.data.Repository -import io.heckel.ntfy.msg.ApiService class Application : Application() { private val database by lazy { Database.getInstance(this) } diff --git a/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt b/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt index 160704c..3c923e8 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt @@ -15,6 +15,7 @@ import com.google.android.material.textfield.TextInputEditText import io.heckel.ntfy.R import io.heckel.ntfy.data.Database import io.heckel.ntfy.data.Repository +import io.heckel.ntfy.BuildConfig import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -60,13 +61,20 @@ class AddFragment : DialogFragment() { useAnotherServerCheckbox = view.findViewById(R.id.add_dialog_use_another_server_checkbox) as CheckBox useAnotherServerDescription = view.findViewById(R.id.add_dialog_use_another_server_description) + // Show/hide based on flavor + instantDeliveryBox.visibility = if (BuildConfig.FIREBASE_AVAILABLE) View.VISIBLE else View.GONE + // Build dialog val alert = AlertDialog.Builder(activity) .setView(view) .setPositiveButton(R.string.add_dialog_button_subscribe) { _, _ -> val topic = topicNameText.text.toString() val baseUrl = getBaseUrl() - val instant = if (useAnotherServerCheckbox.isChecked) true else instantDeliveryCheckbox.isChecked + val instant = if (!BuildConfig.FIREBASE_AVAILABLE || useAnotherServerCheckbox.isChecked) { + true + } else { + instantDeliveryCheckbox.isChecked + } subscribeListener.onSubscribe(topic, baseUrl, instant) } .setNegativeButton(R.string.add_dialog_button_cancel) { _, _ -> @@ -107,7 +115,7 @@ class AddFragment : DialogFragment() { } else { useAnotherServerDescription.visibility = View.GONE baseUrlText.visibility = View.GONE - instantDeliveryBox.visibility = View.VISIBLE + instantDeliveryBox.visibility = if (BuildConfig.FIREBASE_AVAILABLE) View.VISIBLE else View.GONE if (instantDeliveryCheckbox.isChecked) instantDeliveryDescription.visibility = View.VISIBLE else instantDeliveryDescription.visibility = View.GONE } @@ -149,6 +157,6 @@ class AddFragment : DialogFragment() { } companion object { - const val TAG = "NtfyAffFragment" + const val TAG = "NtfyAddFragment" } } diff --git a/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt index a6da265..6d0ecd4 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt @@ -20,6 +20,7 @@ import androidx.core.content.ContextCompat import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.RecyclerView import androidx.swiperefreshlayout.widget.SwipeRefreshLayout +import io.heckel.ntfy.BuildConfig import io.heckel.ntfy.R import io.heckel.ntfy.app.Application import io.heckel.ntfy.data.Notification @@ -372,7 +373,8 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra val enableInstantItem = menu.findItem(R.id.detail_menu_enable_instant) val disableInstantItem = menu.findItem(R.id.detail_menu_disable_instant) val instantInfoItem = menu.findItem(R.id.detail_menu_instant_info) - if (subscriptionBaseUrl == appBaseUrl) { + val allowToggleInstant = BuildConfig.FIREBASE_AVAILABLE && subscriptionBaseUrl == appBaseUrl + if (allowToggleInstant) { enableInstantItem?.isVisible = !subscriptionInstant disableInstantItem?.isVisible = subscriptionInstant instantInfoItem?.isVisible = false 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 36c97f9..5f3de63 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt @@ -19,7 +19,6 @@ import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.RecyclerView import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.work.* -import com.google.firebase.messaging.FirebaseMessaging import io.heckel.ntfy.R import io.heckel.ntfy.app.Application import io.heckel.ntfy.data.Subscription @@ -27,6 +26,7 @@ import io.heckel.ntfy.data.topicShortUrl import io.heckel.ntfy.msg.ApiService import io.heckel.ntfy.msg.NotificationService import io.heckel.ntfy.work.PollWorker +import io.heckel.ntfy.firebase.FirebaseMessenger import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.isActive @@ -41,6 +41,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc } private val repository by lazy { (application as Application).repository } private val api = ApiService() + private val messenger = FirebaseMessenger() // UI elements private lateinit var menu: Menu @@ -267,15 +268,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc // Subscribe to Firebase topic if ntfy.sh (even if instant, just to be sure!) if (baseUrl == appBaseUrl) { Log.d(TAG, "Subscribing to Firebase") - FirebaseMessaging - .getInstance() - .subscribeToTopic(topic) - .addOnCompleteListener { - Log.d(TAG, "Subscribing to topic complete: result=${it.result}, exception=${it.exception}, successful=${it.isSuccessful}") - } - .addOnFailureListener { - Log.e(TAG, "Subscribing to topic failed: $it") - } + messenger.subscribe(topic) } // Fetch cached messages @@ -366,7 +359,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc subscriptionBaseUrl?.let { baseUrl -> if (baseUrl == appBaseUrl) { Log.d(TAG, "Unsubscribing from Firebase") - subscriptionTopic?.let { topic -> FirebaseMessaging.getInstance().unsubscribeFromTopic(topic) } + subscriptionTopic?.let { topic -> messenger.unsubscribe(topic) } } // Subscriber service changes are triggered in the observe() call above } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a5549d2..072a1e6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,7 +86,7 @@ Copied to clipboard Instant delivery enabled Instant delivery disabled - Instant delivery cannot be disabled for subscriptions from other servers + Instant delivery is enabled Notifications enabled diff --git a/app/src/play/java/io/heckel/ntfy/firebase/FirebaseMessenger.kt b/app/src/play/java/io/heckel/ntfy/firebase/FirebaseMessenger.kt new file mode 100644 index 0000000..18b92f6 --- /dev/null +++ b/app/src/play/java/io/heckel/ntfy/firebase/FirebaseMessenger.kt @@ -0,0 +1,28 @@ +package io.heckel.ntfy.firebase + +import android.util.Log +import com.google.firebase.messaging.FirebaseMessaging + +class FirebaseMessenger { + fun subscribe(topic: String) { + FirebaseMessaging + .getInstance() + .subscribeToTopic(topic) + .addOnCompleteListener { + Log.d(TAG, "Subscribing to topic complete: result=${it.result}, exception=${it.exception}, successful=${it.isSuccessful}") + } + .addOnFailureListener { + Log.e(TAG, "Subscribing to topic failed: $it") + } + } + + fun unsubscribe(topic: String) { + FirebaseMessaging + .getInstance() + .unsubscribeFromTopic(topic) + } + + companion object { + private const val TAG = "NtfyFirebase" + } +} diff --git a/app/src/main/java/io/heckel/ntfy/msg/FirebaseService.kt b/app/src/play/java/io/heckel/ntfy/firebase/FirebaseService.kt similarity index 97% rename from app/src/main/java/io/heckel/ntfy/msg/FirebaseService.kt rename to app/src/play/java/io/heckel/ntfy/firebase/FirebaseService.kt index d61006f..5d8aff6 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/FirebaseService.kt +++ b/app/src/play/java/io/heckel/ntfy/firebase/FirebaseService.kt @@ -1,4 +1,4 @@ -package io.heckel.ntfy.msg +package io.heckel.ntfy.firebase import android.util.Log import com.google.firebase.messaging.FirebaseMessagingService @@ -6,6 +6,7 @@ import com.google.firebase.messaging.RemoteMessage import io.heckel.ntfy.R import io.heckel.ntfy.app.Application import io.heckel.ntfy.data.Notification +import io.heckel.ntfy.msg.NotificationService import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch