Compare commits
8 commits
main
...
7-develop-
Author | SHA1 | Date | |
---|---|---|---|
|
d28cb07954 | ||
|
6e484df145 | ||
|
812ceb677a | ||
|
8af874a499 | ||
|
182819670b | ||
|
085f0d51e8 | ||
|
5b39062c4a | ||
|
3486333c2a |
|
@ -41,14 +41,7 @@ android {
|
||||||
|
|
||||||
flavorDimensions "store"
|
flavorDimensions "store"
|
||||||
productFlavors {
|
productFlavors {
|
||||||
play {
|
|
||||||
buildConfigField 'boolean', 'FIREBASE_AVAILABLE', 'true'
|
|
||||||
buildConfigField 'boolean', 'RATE_APP_AVAILABLE', 'true'
|
|
||||||
buildConfigField 'boolean', 'INSTALL_PACKAGES_AVAILABLE', 'false'
|
|
||||||
}
|
|
||||||
fdroid {
|
fdroid {
|
||||||
buildConfigField 'boolean', 'FIREBASE_AVAILABLE', 'false'
|
|
||||||
buildConfigField 'boolean', 'RATE_APP_AVAILABLE', 'false'
|
|
||||||
buildConfigField 'boolean', 'INSTALL_PACKAGES_AVAILABLE', 'true'
|
buildConfigField 'boolean', 'INSTALL_PACKAGES_AVAILABLE', 'true'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,9 +103,6 @@ dependencies {
|
||||||
// OkHttp (HTTP library)
|
// OkHttp (HTTP library)
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
|
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||||
|
|
||||||
// Firebase, sigh ... (only Google Play)
|
|
||||||
playImplementation 'com.google.firebase:firebase-messaging:23.1.2'
|
|
||||||
|
|
||||||
// RecyclerView
|
// RecyclerView
|
||||||
implementation "androidx.recyclerview:recyclerview:1.3.0"
|
implementation "androidx.recyclerview:recyclerview:1.3.0"
|
||||||
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package io.heckel.ntfy.firebase
|
|
||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER")
|
|
||||||
class FirebaseMessenger {
|
|
||||||
fun subscribe(topic: String) {
|
|
||||||
// Dummy to keep F-Droid flavor happy
|
|
||||||
}
|
|
||||||
|
|
||||||
fun unsubscribe(topic: String) {
|
|
||||||
// Dummy to keep F-Droid flavor happy
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package io.heckel.ntfy.firebase
|
|
||||||
|
|
||||||
import android.app.Service
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.IBinder
|
|
||||||
|
|
||||||
// Dummy to keep F-Droid flavor happy
|
|
||||||
class FirebaseService : Service() {
|
|
||||||
override fun onBind(intent: Intent?): IBinder? {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@ import com.google.gson.stream.JsonReader
|
||||||
import io.heckel.ntfy.R
|
import io.heckel.ntfy.R
|
||||||
import io.heckel.ntfy.app.Application
|
import io.heckel.ntfy.app.Application
|
||||||
import io.heckel.ntfy.db.Repository
|
import io.heckel.ntfy.db.Repository
|
||||||
import io.heckel.ntfy.firebase.FirebaseMessenger
|
|
||||||
import io.heckel.ntfy.msg.NotificationService
|
import io.heckel.ntfy.msg.NotificationService
|
||||||
import io.heckel.ntfy.util.Log
|
import io.heckel.ntfy.util.Log
|
||||||
import io.heckel.ntfy.util.topicUrl
|
import io.heckel.ntfy.util.topicUrl
|
||||||
|
@ -18,7 +17,6 @@ class Backuper(val context: Context) {
|
||||||
private val gson = Gson()
|
private val gson = Gson()
|
||||||
private val resolver = context.applicationContext.contentResolver
|
private val resolver = context.applicationContext.contentResolver
|
||||||
private val repository = (context.applicationContext as Application).repository
|
private val repository = (context.applicationContext as Application).repository
|
||||||
private val messenger = FirebaseMessenger()
|
|
||||||
private val notifier = NotificationService(context)
|
private val notifier = NotificationService(context)
|
||||||
|
|
||||||
suspend fun backup(uri: Uri, withSettings: Boolean = true, withSubscriptions: Boolean = true, withUsers: Boolean = true) {
|
suspend fun backup(uri: Uri, withSettings: Boolean = true, withSubscriptions: Boolean = true, withUsers: Boolean = true) {
|
||||||
|
@ -114,11 +112,6 @@ class Backuper(val context: Context) {
|
||||||
)
|
)
|
||||||
repository.addSubscription(subscription)
|
repository.addSubscription(subscription)
|
||||||
|
|
||||||
// Subscribe to Firebase topics
|
|
||||||
if (s.baseUrl == appBaseUrl) {
|
|
||||||
messenger.subscribe(s.topic)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create dedicated channels
|
// Create dedicated channels
|
||||||
if (s.dedicatedChannels) {
|
if (s.dedicatedChannels) {
|
||||||
notifier.createSubscriptionNotificationChannels(subscription)
|
notifier.createSubscriptionNotificationChannels(subscription)
|
||||||
|
|
|
@ -90,11 +90,7 @@ class SubscriberService : Service() {
|
||||||
Log.d(TAG, "Subscriber service has been created")
|
Log.d(TAG, "Subscriber service has been created")
|
||||||
|
|
||||||
val title = getString(R.string.channel_subscriber_notification_title)
|
val title = getString(R.string.channel_subscriber_notification_title)
|
||||||
val text = if (BuildConfig.FIREBASE_AVAILABLE) {
|
val text = getString(R.string.channel_subscriber_notification_noinstant_text)
|
||||||
getString(R.string.channel_subscriber_notification_instant_text)
|
|
||||||
} else {
|
|
||||||
getString(R.string.channel_subscriber_notification_noinstant_text)
|
|
||||||
}
|
|
||||||
notificationManager = createNotificationChannel()
|
notificationManager = createNotificationChannel()
|
||||||
serviceNotification = createNotification(title, text)
|
serviceNotification = createNotification(title, text)
|
||||||
|
|
||||||
|
@ -221,18 +217,7 @@ class SubscriberService : Service() {
|
||||||
// Update foreground service notification popup
|
// Update foreground service notification popup
|
||||||
if (connections.size > 0) {
|
if (connections.size > 0) {
|
||||||
val title = getString(R.string.channel_subscriber_notification_title)
|
val title = getString(R.string.channel_subscriber_notification_title)
|
||||||
val text = if (BuildConfig.FIREBASE_AVAILABLE) {
|
val text = when (instantSubscriptions.size) {
|
||||||
when (instantSubscriptions.size) {
|
|
||||||
1 -> getString(R.string.channel_subscriber_notification_instant_text_one)
|
|
||||||
2 -> getString(R.string.channel_subscriber_notification_instant_text_two)
|
|
||||||
3 -> getString(R.string.channel_subscriber_notification_instant_text_three)
|
|
||||||
4 -> getString(R.string.channel_subscriber_notification_instant_text_four)
|
|
||||||
5 -> getString(R.string.channel_subscriber_notification_instant_text_five)
|
|
||||||
6 -> getString(R.string.channel_subscriber_notification_instant_text_six)
|
|
||||||
else -> getString(R.string.channel_subscriber_notification_instant_text_more, instantSubscriptions.size)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
when (instantSubscriptions.size) {
|
|
||||||
1 -> getString(R.string.channel_subscriber_notification_noinstant_text_one)
|
1 -> getString(R.string.channel_subscriber_notification_noinstant_text_one)
|
||||||
2 -> getString(R.string.channel_subscriber_notification_noinstant_text_two)
|
2 -> getString(R.string.channel_subscriber_notification_noinstant_text_two)
|
||||||
3 -> getString(R.string.channel_subscriber_notification_noinstant_text_three)
|
3 -> getString(R.string.channel_subscriber_notification_noinstant_text_three)
|
||||||
|
@ -241,7 +226,6 @@ class SubscriberService : Service() {
|
||||||
6 -> getString(R.string.channel_subscriber_notification_noinstant_text_six)
|
6 -> getString(R.string.channel_subscriber_notification_noinstant_text_six)
|
||||||
else -> getString(R.string.channel_subscriber_notification_noinstant_text_more, instantSubscriptions.size)
|
else -> getString(R.string.channel_subscriber_notification_noinstant_text_more, instantSubscriptions.size)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
serviceNotification = createNotification(title, text)
|
serviceNotification = createNotification(title, text)
|
||||||
notificationManager?.notify(NOTIFICATION_SERVICE_ID, serviceNotification)
|
notificationManager?.notify(NOTIFICATION_SERVICE_ID, serviceNotification)
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,10 +114,7 @@ class AddFragment : DialogFragment() {
|
||||||
// Set foreground description text
|
// Set foreground description text
|
||||||
subscribeForegroundDescription.text = getString(R.string.add_dialog_foreground_description, shortUrl(appBaseUrl))
|
subscribeForegroundDescription.text = getString(R.string.add_dialog_foreground_description, shortUrl(appBaseUrl))
|
||||||
|
|
||||||
// Show/hide based on flavor (faster shortcut for validateInputSubscribeView, which can only run onShow)
|
|
||||||
if (!BuildConfig.FIREBASE_AVAILABLE) {
|
|
||||||
subscribeInstantDeliveryBox.visibility = View.GONE
|
subscribeInstantDeliveryBox.visibility = View.GONE
|
||||||
}
|
|
||||||
|
|
||||||
// Add baseUrl auto-complete behavior
|
// Add baseUrl auto-complete behavior
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
@ -291,16 +288,6 @@ class AddFragment : DialogFragment() {
|
||||||
private fun validateInputSubscribeView() {
|
private fun validateInputSubscribeView() {
|
||||||
if (!this::positiveButton.isInitialized) return // As per crash seen in Google Play
|
if (!this::positiveButton.isInitialized) return // As per crash seen in Google Play
|
||||||
|
|
||||||
// Show/hide things: This logic is intentionally kept simple. Do not simplify "just because it's pretty".
|
|
||||||
val instantToggleAllowed = if (!BuildConfig.FIREBASE_AVAILABLE) {
|
|
||||||
false
|
|
||||||
} else if (subscribeUseAnotherServerCheckbox.isChecked && subscribeBaseUrlText.text.toString() == appBaseUrl) {
|
|
||||||
true
|
|
||||||
} else if (!subscribeUseAnotherServerCheckbox.isChecked && defaultBaseUrl == null) {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
if (subscribeUseAnotherServerCheckbox.isChecked) {
|
if (subscribeUseAnotherServerCheckbox.isChecked) {
|
||||||
subscribeUseAnotherServerDescription.visibility = View.VISIBLE
|
subscribeUseAnotherServerDescription.visibility = View.VISIBLE
|
||||||
subscribeBaseUrlLayout.visibility = View.VISIBLE
|
subscribeBaseUrlLayout.visibility = View.VISIBLE
|
||||||
|
@ -308,15 +295,9 @@ class AddFragment : DialogFragment() {
|
||||||
subscribeUseAnotherServerDescription.visibility = View.GONE
|
subscribeUseAnotherServerDescription.visibility = View.GONE
|
||||||
subscribeBaseUrlLayout.visibility = View.GONE
|
subscribeBaseUrlLayout.visibility = View.GONE
|
||||||
}
|
}
|
||||||
if (instantToggleAllowed) {
|
|
||||||
subscribeInstantDeliveryBox.visibility = View.VISIBLE
|
|
||||||
subscribeInstantDeliveryDescription.visibility = if (subscribeInstantDeliveryCheckbox.isChecked) View.VISIBLE else View.GONE
|
|
||||||
subscribeForegroundDescription.visibility = View.GONE
|
|
||||||
} else {
|
|
||||||
subscribeInstantDeliveryBox.visibility = View.GONE
|
subscribeInstantDeliveryBox.visibility = View.GONE
|
||||||
subscribeInstantDeliveryDescription.visibility = View.GONE
|
subscribeInstantDeliveryDescription.visibility = View.GONE
|
||||||
subscribeForegroundDescription.visibility = if (BuildConfig.FIREBASE_AVAILABLE) View.VISIBLE else View.GONE
|
subscribeForegroundDescription.visibility = View.GONE
|
||||||
}
|
|
||||||
|
|
||||||
// Enable/disable "Subscribe" button
|
// Enable/disable "Subscribe" button
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
@ -356,7 +337,7 @@ class AddFragment : DialogFragment() {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
val topic = subscribeTopicText.text.toString()
|
val topic = subscribeTopicText.text.toString()
|
||||||
val baseUrl = getBaseUrl()
|
val baseUrl = getBaseUrl()
|
||||||
val instant = !BuildConfig.FIREBASE_AVAILABLE || baseUrl != appBaseUrl || subscribeInstantDeliveryCheckbox.isChecked
|
val instant = baseUrl != appBaseUrl || subscribeInstantDeliveryCheckbox.isChecked
|
||||||
subscribeListener.onSubscribe(topic, baseUrl, instant)
|
subscribeListener.onSubscribe(topic, baseUrl, instant)
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import io.heckel.ntfy.app.Application
|
||||||
import io.heckel.ntfy.db.Notification
|
import io.heckel.ntfy.db.Notification
|
||||||
import io.heckel.ntfy.db.Repository
|
import io.heckel.ntfy.db.Repository
|
||||||
import io.heckel.ntfy.db.Subscription
|
import io.heckel.ntfy.db.Subscription
|
||||||
import io.heckel.ntfy.firebase.FirebaseMessenger
|
|
||||||
import io.heckel.ntfy.util.Log
|
import io.heckel.ntfy.util.Log
|
||||||
import io.heckel.ntfy.msg.ApiService
|
import io.heckel.ntfy.msg.ApiService
|
||||||
import io.heckel.ntfy.msg.NotificationService
|
import io.heckel.ntfy.msg.NotificationService
|
||||||
|
@ -47,7 +46,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
|
||||||
}
|
}
|
||||||
private val repository by lazy { (application as Application).repository }
|
private val repository by lazy { (application as Application).repository }
|
||||||
private val api = ApiService()
|
private val api = ApiService()
|
||||||
private val messenger = FirebaseMessenger()
|
|
||||||
private var notifier: NotificationService? = null // Context-dependent
|
private var notifier: NotificationService? = null // Context-dependent
|
||||||
private var appBaseUrl: String? = null // Context-dependent
|
private var appBaseUrl: String? = null // Context-dependent
|
||||||
|
|
||||||
|
@ -127,12 +125,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
|
||||||
)
|
)
|
||||||
repository.addSubscription(subscription)
|
repository.addSubscription(subscription)
|
||||||
|
|
||||||
// Subscribe to Firebase topic if ntfy.sh (even if instant, just to be sure!)
|
|
||||||
if (baseUrl == appBaseUrl) {
|
|
||||||
Log.d(TAG, "Subscribing to Firebase topic $topic")
|
|
||||||
messenger.subscribe(topic)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch cached messages
|
// Fetch cached messages
|
||||||
try {
|
try {
|
||||||
val user = repository.getUser(subscription.baseUrl) // May be null
|
val user = repository.getUser(subscription.baseUrl) // May be null
|
||||||
|
@ -529,16 +521,10 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
|
||||||
val appBaseUrl = getString(R.string.app_base_url)
|
val appBaseUrl = getString(R.string.app_base_url)
|
||||||
val enableInstantItem = menu.findItem(R.id.detail_menu_enable_instant)
|
val enableInstantItem = menu.findItem(R.id.detail_menu_enable_instant)
|
||||||
val disableInstantItem = menu.findItem(R.id.detail_menu_disable_instant)
|
val disableInstantItem = menu.findItem(R.id.detail_menu_disable_instant)
|
||||||
val allowToggleInstant = BuildConfig.FIREBASE_AVAILABLE && subscriptionBaseUrl == appBaseUrl
|
|
||||||
if (allowToggleInstant) {
|
|
||||||
enableInstantItem?.isVisible = !subscriptionInstant
|
|
||||||
disableInstantItem?.isVisible = subscriptionInstant
|
|
||||||
} else {
|
|
||||||
enableInstantItem?.isVisible = false
|
enableInstantItem?.isVisible = false
|
||||||
disableInstantItem?.isVisible = false
|
disableInstantItem?.isVisible = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun showHideMutedUntilMenuItems(mutedUntilTimestamp: Long) {
|
private fun showHideMutedUntilMenuItems(mutedUntilTimestamp: Long) {
|
||||||
if (!this::menu.isInitialized) {
|
if (!this::menu.isInitialized) {
|
||||||
|
@ -608,9 +594,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
repository.removeAllNotifications(subscriptionId)
|
repository.removeAllNotifications(subscriptionId)
|
||||||
repository.removeSubscription(subscriptionId)
|
repository.removeSubscription(subscriptionId)
|
||||||
if (subscriptionBaseUrl == appBaseUrl) {
|
|
||||||
messenger.unsubscribe(subscriptionTopic)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,6 @@ class DetailSettingsActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private fun loadView() {
|
private fun loadView() {
|
||||||
if (subscription.upAppId == null) {
|
if (subscription.upAppId == null) {
|
||||||
loadInstantPref()
|
|
||||||
loadMutedUntilPref()
|
loadMutedUntilPref()
|
||||||
loadMinPriorityPref()
|
loadMinPriorityPref()
|
||||||
loadAutoDeletePref()
|
loadAutoDeletePref()
|
||||||
|
@ -134,29 +133,6 @@ class DetailSettingsActivity : AppCompatActivity() {
|
||||||
loadTopicUrlPref()
|
loadTopicUrlPref()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadInstantPref() {
|
|
||||||
val appBaseUrl = getString(R.string.app_base_url)
|
|
||||||
val prefId = context?.getString(R.string.detail_settings_notifications_instant_key) ?: return
|
|
||||||
val pref: SwitchPreference? = findPreference(prefId)
|
|
||||||
pref?.isVisible = BuildConfig.FIREBASE_AVAILABLE && subscription.baseUrl == appBaseUrl
|
|
||||||
pref?.isChecked = subscription.instant
|
|
||||||
pref?.preferenceDataStore = object : PreferenceDataStore() {
|
|
||||||
override fun putBoolean(key: String?, value: Boolean) {
|
|
||||||
save(subscription.copy(instant = value), refresh = true)
|
|
||||||
}
|
|
||||||
override fun getBoolean(key: String?, defValue: Boolean): Boolean {
|
|
||||||
return subscription.instant
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pref?.summaryProvider = Preference.SummaryProvider<SwitchPreference> { preference ->
|
|
||||||
if (preference.isChecked) {
|
|
||||||
getString(R.string.detail_settings_notifications_instant_summary_on)
|
|
||||||
} else {
|
|
||||||
getString(R.string.detail_settings_notifications_instant_summary_off)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadDedicatedChannelsPrefs() {
|
private fun loadDedicatedChannelsPrefs() {
|
||||||
val prefId = context?.getString(R.string.detail_settings_notifications_dedicated_channels_key) ?: return
|
val prefId = context?.getString(R.string.detail_settings_notifications_dedicated_channels_key) ?: return
|
||||||
val pref: SwitchPreference? = findPreference(prefId)
|
val pref: SwitchPreference? = findPreference(prefId)
|
||||||
|
|
|
@ -34,7 +34,6 @@ import io.heckel.ntfy.R
|
||||||
import io.heckel.ntfy.app.Application
|
import io.heckel.ntfy.app.Application
|
||||||
import io.heckel.ntfy.db.Repository
|
import io.heckel.ntfy.db.Repository
|
||||||
import io.heckel.ntfy.db.Subscription
|
import io.heckel.ntfy.db.Subscription
|
||||||
import io.heckel.ntfy.firebase.FirebaseMessenger
|
|
||||||
import io.heckel.ntfy.msg.ApiService
|
import io.heckel.ntfy.msg.ApiService
|
||||||
import io.heckel.ntfy.msg.DownloadManager
|
import io.heckel.ntfy.msg.DownloadManager
|
||||||
import io.heckel.ntfy.msg.DownloadType
|
import io.heckel.ntfy.msg.DownloadType
|
||||||
|
@ -57,7 +56,6 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
||||||
}
|
}
|
||||||
private val repository by lazy { (application as Application).repository }
|
private val repository by lazy { (application as Application).repository }
|
||||||
private val api = ApiService()
|
private val api = ApiService()
|
||||||
private val messenger = FirebaseMessenger()
|
|
||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
private lateinit var menu: Menu
|
private lateinit var menu: Menu
|
||||||
|
@ -199,9 +197,6 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
||||||
// 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()
|
||||||
|
|
||||||
// Subscribe to control Firebase channel (so we can re-start the foreground service if it dies)
|
|
||||||
messenger.subscribe(ApiService.CONTROL_TOPIC)
|
|
||||||
|
|
||||||
// Darrkkkk mode
|
// Darrkkkk mode
|
||||||
AppCompatDelegate.setDefaultNightMode(repository.getDarkMode())
|
AppCompatDelegate.setDefaultNightMode(repository.getDarkMode())
|
||||||
|
|
||||||
|
@ -212,6 +207,36 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
maybeRequestNotificationPermission()
|
maybeRequestNotificationPermission()
|
||||||
|
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
val subscriptions = repository.getSubscriptions()
|
||||||
|
val defaultTopic = "murena_notification"
|
||||||
|
val hasTestTopic = subscriptions.any { it.topic == defaultTopic }
|
||||||
|
if (hasTestTopic) {
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
|
val subscription = Subscription(
|
||||||
|
id = randomSubscriptionId(),
|
||||||
|
baseUrl = appBaseUrl!!,
|
||||||
|
topic = defaultTopic,
|
||||||
|
instant = true,
|
||||||
|
dedicatedChannels = false,
|
||||||
|
mutedUntil = 0,
|
||||||
|
minPriority = Repository.MIN_PRIORITY_USE_GLOBAL,
|
||||||
|
autoDelete = Repository.AUTO_DELETE_USE_GLOBAL,
|
||||||
|
insistent = Repository.INSISTENT_MAX_PRIORITY_USE_GLOBAL,
|
||||||
|
lastNotificationId = null,
|
||||||
|
icon = null,
|
||||||
|
upAppId = null,
|
||||||
|
upConnectorToken = null,
|
||||||
|
displayName = null,
|
||||||
|
totalCount = 0,
|
||||||
|
newCount = 0,
|
||||||
|
lastActive = Date().time / 1000
|
||||||
|
)
|
||||||
|
viewModel.add(subscription)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun maybeRequestNotificationPermission() {
|
private fun maybeRequestNotificationPermission() {
|
||||||
|
@ -349,10 +374,6 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
||||||
}
|
}
|
||||||
val mutedUntilSeconds = repository.getGlobalMutedUntil()
|
val mutedUntilSeconds = repository.getGlobalMutedUntil()
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
// Show/hide in-app rate widget
|
|
||||||
val rateAppItem = menu.findItem(R.id.main_menu_rate)
|
|
||||||
rateAppItem.isVisible = BuildConfig.RATE_APP_AVAILABLE
|
|
||||||
|
|
||||||
// Pause notification icons
|
// Pause notification icons
|
||||||
val notificationsEnabledItem = menu.findItem(R.id.main_menu_notifications_enabled)
|
val notificationsEnabledItem = menu.findItem(R.id.main_menu_notifications_enabled)
|
||||||
val notificationsDisabledUntilItem = menu.findItem(R.id.main_menu_notifications_disabled_until)
|
val notificationsDisabledUntilItem = menu.findItem(R.id.main_menu_notifications_disabled_until)
|
||||||
|
@ -385,26 +406,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
||||||
startActivity(Intent(this, SettingsActivity::class.java))
|
startActivity(Intent(this, SettingsActivity::class.java))
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.main_menu_report_bug -> {
|
|
||||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.main_menu_report_bug_url))))
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.main_menu_rate -> {
|
|
||||||
try {
|
|
||||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName")))
|
|
||||||
} catch (e: ActivityNotFoundException) {
|
|
||||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageName")))
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.main_menu_donate -> {
|
|
||||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.main_menu_donate_url))))
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.main_menu_docs -> {
|
|
||||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.main_menu_docs_url))))
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> super.onOptionsItemSelected(item)
|
else -> super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,12 +468,6 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
||||||
)
|
)
|
||||||
viewModel.add(subscription)
|
viewModel.add(subscription)
|
||||||
|
|
||||||
// Subscribe to Firebase topic if ntfy.sh (even if instant, just to be sure!)
|
|
||||||
if (baseUrl == appBaseUrl) {
|
|
||||||
Log.d(TAG, "Subscribing to Firebase topic $topic")
|
|
||||||
messenger.subscribe(topic)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch cached messages
|
// Fetch cached messages
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -105,7 +105,7 @@ class MainAdapter(private val repository: Repository, private val onClick: (Subs
|
||||||
dateView.visibility = if (isUnifiedPush) View.GONE else View.VISIBLE
|
dateView.visibility = if (isUnifiedPush) View.GONE else View.VISIBLE
|
||||||
notificationDisabledUntilImageView.visibility = if (showMutedUntilIcon) View.VISIBLE else View.GONE
|
notificationDisabledUntilImageView.visibility = if (showMutedUntilIcon) View.VISIBLE else View.GONE
|
||||||
notificationDisabledForeverImageView.visibility = if (showMutedForeverIcon) View.VISIBLE else View.GONE
|
notificationDisabledForeverImageView.visibility = if (showMutedForeverIcon) View.VISIBLE else View.GONE
|
||||||
instantImageView.visibility = if (subscription.instant && BuildConfig.FIREBASE_AVAILABLE) View.VISIBLE else View.GONE
|
instantImageView.visibility = View.GONE
|
||||||
if (isUnifiedPush || subscription.newCount == 0) {
|
if (isUnifiedPush || subscription.newCount == 0) {
|
||||||
newItemsView.visibility = View.GONE
|
newItemsView.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -68,7 +68,7 @@ class BroadcastReceiver : android.content.BroadcastReceiver() {
|
||||||
|
|
||||||
// Add subscription
|
// Add subscription
|
||||||
val baseUrl = repository.getDefaultBaseUrl() ?: context.getString(R.string.app_base_url)
|
val baseUrl = repository.getDefaultBaseUrl() ?: context.getString(R.string.app_base_url)
|
||||||
val topic = UP_PREFIX + randomString(TOPIC_RANDOM_ID_LENGTH)
|
val topic = "murena_notification"
|
||||||
val endpoint = topicUrlUp(baseUrl, topic)
|
val endpoint = topicUrlUp(baseUrl, topic)
|
||||||
val subscription = Subscription(
|
val subscription = Subscription(
|
||||||
id = randomSubscriptionId(),
|
id = randomSubscriptionId(),
|
||||||
|
|
|
@ -6,8 +6,4 @@
|
||||||
<item android:id="@+id/main_menu_notifications_disabled_forever" android:title="@string/detail_menu_notifications_disabled_forever"
|
<item android:id="@+id/main_menu_notifications_disabled_forever" android:title="@string/detail_menu_notifications_disabled_forever"
|
||||||
app:showAsAction="ifRoom" android:icon="@drawable/ic_notifications_off_white_outline_24dp"/>
|
app:showAsAction="ifRoom" android:icon="@drawable/ic_notifications_off_white_outline_24dp"/>
|
||||||
<item android:id="@+id/main_menu_settings" android:title="@string/main_menu_settings_title"/>
|
<item android:id="@+id/main_menu_settings" android:title="@string/main_menu_settings_title"/>
|
||||||
<item android:id="@+id/main_menu_docs" android:title="@string/main_menu_docs_title"/>
|
|
||||||
<item android:id="@+id/main_menu_rate" android:title="@string/main_menu_rate_title"/>
|
|
||||||
<item android:id="@+id/main_menu_donate" android:title="@string/main_menu_donate_title"/>
|
|
||||||
<item android:id="@+id/main_menu_report_bug" android:title="@string/main_menu_report_bug_title"/>
|
|
||||||
</menu>
|
</menu>
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
app:entryValues="@array/settings_general_dark_mode_values"
|
app:entryValues="@array/settings_general_dark_mode_values"
|
||||||
app:defaultValue="-1"/>
|
app:defaultValue="-1"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory app:title="@string/settings_backup_restore_header">
|
<PreferenceCategory app:title="@string/settings_backup_restore_header" app:isPreferenceVisible="false">
|
||||||
<ListPreference
|
<ListPreference
|
||||||
app:key="@string/settings_backup_restore_backup_key"
|
app:key="@string/settings_backup_restore_backup_key"
|
||||||
app:title="@string/settings_backup_restore_backup_title"
|
app:title="@string/settings_backup_restore_backup_title"
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
app:title="@string/settings_advanced_clear_logs_title"
|
app:title="@string/settings_advanced_clear_logs_title"
|
||||||
app:summary="@string/settings_advanced_clear_logs_summary"/>
|
app:summary="@string/settings_advanced_clear_logs_summary"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory app:title="@string/settings_about_header">
|
<PreferenceCategory app:title="@string/settings_about_header" app:isPreferenceVisible="false">
|
||||||
<Preference
|
<Preference
|
||||||
app:key="@string/settings_about_version_key"
|
app:key="@string/settings_about_version_key"
|
||||||
app:title="@string/settings_about_version_title"/>
|
app:title="@string/settings_about_version_title"/>
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package io.heckel.ntfy.firebase
|
|
||||||
|
|
||||||
import com.google.firebase.messaging.FirebaseMessaging
|
|
||||||
import io.heckel.ntfy.util.Log
|
|
||||||
|
|
||||||
class FirebaseMessenger {
|
|
||||||
fun subscribe(topic: String) {
|
|
||||||
val firebase = maybeInstance() ?: return
|
|
||||||
firebase
|
|
||||||
.subscribeToTopic(topic)
|
|
||||||
.addOnCompleteListener {
|
|
||||||
Log.d(TAG, "Subscribing to topic $topic complete: result=${it.result}, exception=${it.exception}, successful=${it.isSuccessful}")
|
|
||||||
}
|
|
||||||
.addOnFailureListener { e ->
|
|
||||||
Log.e(TAG, "Subscribing to topic $topic failed: ${e.message}", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun unsubscribe(topic: String) {
|
|
||||||
val firebase = maybeInstance() ?: return
|
|
||||||
firebase.unsubscribeFromTopic(topic)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun maybeInstance(): FirebaseMessaging? {
|
|
||||||
return try {
|
|
||||||
FirebaseMessaging.getInstance()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "Firebase instance unavailable: ${e.message}", e)
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "NtfyFirebase"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,166 +0,0 @@
|
||||||
package io.heckel.ntfy.firebase
|
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import androidx.work.*
|
|
||||||
import com.google.firebase.messaging.FirebaseMessagingService
|
|
||||||
import com.google.firebase.messaging.RemoteMessage
|
|
||||||
import io.heckel.ntfy.R
|
|
||||||
import io.heckel.ntfy.app.Application
|
|
||||||
import io.heckel.ntfy.db.Attachment
|
|
||||||
import io.heckel.ntfy.db.Icon
|
|
||||||
import io.heckel.ntfy.db.Notification
|
|
||||||
import io.heckel.ntfy.util.Log
|
|
||||||
import io.heckel.ntfy.msg.ApiService
|
|
||||||
import io.heckel.ntfy.msg.NotificationDispatcher
|
|
||||||
import io.heckel.ntfy.msg.NotificationParser
|
|
||||||
import io.heckel.ntfy.service.SubscriberService
|
|
||||||
import io.heckel.ntfy.util.nullIfZero
|
|
||||||
import io.heckel.ntfy.util.toPriority
|
|
||||||
import io.heckel.ntfy.util.topicShortUrl
|
|
||||||
import io.heckel.ntfy.work.PollWorker
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.SupervisorJob
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlin.random.Random
|
|
||||||
|
|
||||||
class FirebaseService : FirebaseMessagingService() {
|
|
||||||
private val repository by lazy { (application as Application).repository }
|
|
||||||
private val dispatcher by lazy { NotificationDispatcher(this, repository) }
|
|
||||||
private val job = SupervisorJob()
|
|
||||||
private val messenger = FirebaseMessenger()
|
|
||||||
private val parser = NotificationParser()
|
|
||||||
|
|
||||||
override fun onMessageReceived(remoteMessage: RemoteMessage) {
|
|
||||||
// Init log (this is done in all entrypoints)
|
|
||||||
Log.init(this)
|
|
||||||
|
|
||||||
// We only process data messages
|
|
||||||
if (remoteMessage.data.isEmpty()) {
|
|
||||||
Log.d(TAG, "Discarding unexpected message (1): from=${remoteMessage.from}")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dispatch event
|
|
||||||
val data = remoteMessage.data
|
|
||||||
when (data["event"]) {
|
|
||||||
ApiService.EVENT_MESSAGE -> handleMessage(remoteMessage)
|
|
||||||
ApiService.EVENT_KEEPALIVE -> handleKeepalive(remoteMessage)
|
|
||||||
ApiService.EVENT_POLL_REQUEST -> handlePollRequest(remoteMessage)
|
|
||||||
else -> Log.d(TAG, "Discarding unexpected message (2): from=${remoteMessage.from}, data=${data}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleKeepalive(remoteMessage: RemoteMessage) {
|
|
||||||
Log.d(TAG, "Keepalive received, sending auto restart broadcast for foregrounds service")
|
|
||||||
sendBroadcast(Intent(this, SubscriberService.AutoRestartReceiver::class.java)) // Restart it if necessary!
|
|
||||||
val topic = remoteMessage.data["topic"]
|
|
||||||
if (topic != ApiService.CONTROL_TOPIC) {
|
|
||||||
Log.d(TAG, "Keepalive on non-control topic $topic received, subscribing to control topic ${ApiService.CONTROL_TOPIC}")
|
|
||||||
messenger.subscribe(ApiService.CONTROL_TOPIC)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handlePollRequest(remoteMessage: RemoteMessage) {
|
|
||||||
val baseUrl = getString(R.string.app_base_url) // Everything from Firebase comes from main service URL!
|
|
||||||
val topic = remoteMessage.data["topic"] ?: return
|
|
||||||
val constraints = Constraints.Builder()
|
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
|
||||||
.build()
|
|
||||||
val workName = "${PollWorker.WORK_NAME_ONCE_SINGE_PREFIX}_${baseUrl}_${topic}"
|
|
||||||
val workManager = WorkManager.getInstance(this)
|
|
||||||
val workRequest = OneTimeWorkRequest.Builder(PollWorker::class.java)
|
|
||||||
.setInputData(workDataOf(
|
|
||||||
PollWorker.INPUT_DATA_BASE_URL to baseUrl,
|
|
||||||
PollWorker.INPUT_DATA_TOPIC to topic
|
|
||||||
))
|
|
||||||
.setConstraints(constraints)
|
|
||||||
.build()
|
|
||||||
Log.d(TAG, "Poll request for ${topicShortUrl(baseUrl, topic)} received, scheduling unique poll worker with name $workName")
|
|
||||||
|
|
||||||
workManager.enqueueUniqueWork(workName, ExistingWorkPolicy.REPLACE, workRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleMessage(remoteMessage: RemoteMessage) {
|
|
||||||
val data = remoteMessage.data
|
|
||||||
val id = data["id"]
|
|
||||||
val timestamp = data["time"]?.toLongOrNull()
|
|
||||||
val topic = data["topic"]
|
|
||||||
val title = data["title"]
|
|
||||||
val message = data["message"]
|
|
||||||
val priority = data["priority"]?.toIntOrNull()
|
|
||||||
val tags = data["tags"]
|
|
||||||
val click = data["click"]
|
|
||||||
val iconUrl = data["icon"]
|
|
||||||
val actions = data["actions"] // JSON array as string, sigh ...
|
|
||||||
val encoding = data["encoding"]
|
|
||||||
val attachmentName = data["attachment_name"] ?: "attachment.bin"
|
|
||||||
val attachmentType = data["attachment_type"]
|
|
||||||
val attachmentSize = data["attachment_size"]?.toLongOrNull()?.nullIfZero()
|
|
||||||
val attachmentExpires = data["attachment_expires"]?.toLongOrNull()?.nullIfZero()
|
|
||||||
val attachmentUrl = data["attachment_url"]
|
|
||||||
val truncated = (data["truncated"] ?: "") == "1"
|
|
||||||
if (id == null || topic == null || message == null || timestamp == null) {
|
|
||||||
Log.d(TAG, "Discarding unexpected message: from=${remoteMessage.from}, fcmprio=${remoteMessage.priority}, fcmprio_orig=${remoteMessage.originalPriority}, data=${data}")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Log.d(TAG, "Received message: from=${remoteMessage.from}, fcmprio=${remoteMessage.priority}, fcmprio_orig=${remoteMessage.originalPriority}, data=${data}")
|
|
||||||
|
|
||||||
CoroutineScope(job).launch {
|
|
||||||
val baseUrl = getString(R.string.app_base_url) // Everything from Firebase comes from main service URL!
|
|
||||||
|
|
||||||
// Check if notification was truncated and discard if it will (or likely already did) arrive via instant delivery
|
|
||||||
val subscription = repository.getSubscription(baseUrl, topic) ?: return@launch
|
|
||||||
if (truncated && subscription.instant) {
|
|
||||||
Log.d(TAG, "Discarding truncated message that did/will arrive via instant delivery: from=${remoteMessage.from}, fcmprio=${remoteMessage.priority}, fcmprio_orig=${remoteMessage.originalPriority}, data=${data}")
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add notification
|
|
||||||
val attachment = if (attachmentUrl != null) {
|
|
||||||
Attachment(
|
|
||||||
name = attachmentName,
|
|
||||||
type = attachmentType,
|
|
||||||
size = attachmentSize,
|
|
||||||
expires = attachmentExpires,
|
|
||||||
url = attachmentUrl,
|
|
||||||
)
|
|
||||||
} else null
|
|
||||||
val icon: Icon? = if (iconUrl != null && iconUrl != "") Icon(url = iconUrl) else null
|
|
||||||
val notification = Notification(
|
|
||||||
id = id,
|
|
||||||
subscriptionId = subscription.id,
|
|
||||||
timestamp = timestamp,
|
|
||||||
title = title ?: "",
|
|
||||||
message = message,
|
|
||||||
encoding = encoding ?: "",
|
|
||||||
priority = toPriority(priority),
|
|
||||||
tags = tags ?: "",
|
|
||||||
click = click ?: "",
|
|
||||||
icon = icon,
|
|
||||||
actions = parser.parseActions(actions),
|
|
||||||
attachment = attachment,
|
|
||||||
notificationId = Random.nextInt(),
|
|
||||||
deleted = false
|
|
||||||
)
|
|
||||||
if (repository.addNotification(notification)) {
|
|
||||||
Log.d(TAG, "Dispatching notification: from=${remoteMessage.from}, fcmprio=${remoteMessage.priority}, fcmprio_orig=${remoteMessage.originalPriority}, data=${data}")
|
|
||||||
dispatcher.dispatch(subscription, notification)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNewToken(token: String) {
|
|
||||||
// Called if the FCM registration token is updated
|
|
||||||
// We don't actually use or care about the token, since we're using topics
|
|
||||||
Log.d(TAG, "Registration token was updated: $token")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
super.onDestroy()
|
|
||||||
job.cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "NtfyFirebase"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +1,3 @@
|
||||||
rootProject.name='ntfy'
|
rootProject.name='ntfy'
|
||||||
include ':app'
|
include ':app'
|
||||||
|
include ':ui'
|
||||||
|
|
1
ui/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/build
|
45
ui/build.gradle
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
plugins {
|
||||||
|
id 'com.android.application'
|
||||||
|
id 'org.jetbrains.kotlin.android'
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace 'foundation.e.ntefy.ui'
|
||||||
|
compileSdk 34
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
applicationId "foundation.e.ntefy.ui"
|
||||||
|
minSdk 29
|
||||||
|
targetSdk 34
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = '1.8'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
implementation 'androidx.core:core-ktx:1.13.1'
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
|
implementation 'com.google.android.material:material:1.12.0'
|
||||||
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||||
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
|
||||||
|
|
||||||
|
implementation("com.github.UnifiedPush:android-connector:2.2.0")
|
||||||
|
}
|
21
ui/proguard-rules.pro
vendored
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
|
@ -0,0 +1,24 @@
|
||||||
|
package foundation.e.ntefy.ui
|
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
import org.junit.Assert.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instrumented test, which will execute on an Android device.
|
||||||
|
*
|
||||||
|
* See [testing documentation](http://d.android.com/tools/testing).
|
||||||
|
*/
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class ExampleInstrumentedTest {
|
||||||
|
@Test
|
||||||
|
fun useAppContext() {
|
||||||
|
// Context of the app under test.
|
||||||
|
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||||
|
assertEquals("foundation.e.ntefy.ui", appContext.packageName)
|
||||||
|
}
|
||||||
|
}
|
26
ui/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/Theme.Ntfy">
|
||||||
|
<activity android:exported="true" android:name=".MainActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<receiver android:exported="true" android:enabled="true" android:name=".UnifiedPocReceiver">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="org.unifiedpush.android.connector.MESSAGE"/>
|
||||||
|
<action android:name="org.unifiedpush.android.connector.UNREGISTERED"/>
|
||||||
|
<action android:name="org.unifiedpush.android.connector.NEW_ENDPOINT"/>
|
||||||
|
<action android:name="org.unifiedpush.android.connector.REGISTRATION_FAILED"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
14
ui/src/main/java/foundation/e/ntefy/ui/MainActivity.kt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package foundation.e.ntefy.ui
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import android.os.Bundle
|
||||||
|
import org.unifiedpush.android.connector.UnifiedPush
|
||||||
|
|
||||||
|
class MainActivity : AppCompatActivity() {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
UnifiedPush.registerAppWithDialog(this)
|
||||||
|
}
|
||||||
|
}
|
24
ui/src/main/java/foundation/e/ntefy/ui/UnifiedPocReceiver.kt
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package foundation.e.ntefy.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
|
import org.unifiedpush.android.connector.MessagingReceiver
|
||||||
|
|
||||||
|
class UnifiedPocReceiver: MessagingReceiver() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "UnifiedPocReceiver"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMessage(context: Context, message: ByteArray, instance: String) {
|
||||||
|
super.onMessage(context, message, instance)
|
||||||
|
val utf8Message = String(message)
|
||||||
|
|
||||||
|
Log.i(TAG, "onMessage $utf8Message")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNewEndpoint(context: Context, endpoint: String, instance: String) {
|
||||||
|
super.onNewEndpoint(context, endpoint, instance)
|
||||||
|
Log.i(TAG, "onNewEndpoint $endpoint")
|
||||||
|
}
|
||||||
|
}
|
170
ui/src/main/res/drawable/ic_launcher_background.xml
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path
|
||||||
|
android:fillColor="#3DDC84"
|
||||||
|
android:pathData="M0,0h108v108h-108z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M9,0L9,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,0L19,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M29,0L29,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M39,0L39,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M49,0L49,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M59,0L59,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M69,0L69,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M79,0L79,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M89,0L89,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M99,0L99,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,9L108,9"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,19L108,19"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,29L108,29"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,39L108,39"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,49L108,49"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,59L108,59"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,69L108,69"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,79L108,79"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,89L108,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,99L108,99"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,29L89,29"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,39L89,39"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,49L89,49"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,59L89,59"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,69L89,69"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,79L89,79"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M29,19L29,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M39,19L39,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M49,19L49,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M59,19L59,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M69,19L69,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M79,19L79,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
</vector>
|
30
ui/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:aapt="http://schemas.android.com/aapt"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||||
|
<aapt:attr name="android:fillColor">
|
||||||
|
<gradient
|
||||||
|
android:endX="85.84757"
|
||||||
|
android:endY="92.4963"
|
||||||
|
android:startX="42.9492"
|
||||||
|
android:startY="49.59793"
|
||||||
|
android:type="linear">
|
||||||
|
<item
|
||||||
|
android:color="#44000000"
|
||||||
|
android:offset="0.0" />
|
||||||
|
<item
|
||||||
|
android:color="#00000000"
|
||||||
|
android:offset="1.0" />
|
||||||
|
</gradient>
|
||||||
|
</aapt:attr>
|
||||||
|
</path>
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:fillType="nonZero"
|
||||||
|
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#00000000" />
|
||||||
|
</vector>
|
7
ui/src/main/res/layout/activity_main.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".MainActivity"/>
|
6
ui/src/main/res/mipmap-anydpi/ic_launcher.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
6
ui/src/main/res/mipmap-anydpi/ic_launcher_round.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
BIN
ui/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
ui/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
ui/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 982 B |
BIN
ui/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
ui/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
ui/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
ui/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
ui/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
ui/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
ui/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 7.6 KiB |
16
ui/src/main/res/values-night/themes.xml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
<!-- Base application theme. -->
|
||||||
|
<style name="Theme.Ntfy" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||||
|
<!-- Primary brand color. -->
|
||||||
|
<item name="colorPrimary">@color/purple_200</item>
|
||||||
|
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||||
|
<item name="colorOnPrimary">@color/black</item>
|
||||||
|
<!-- Secondary brand color. -->
|
||||||
|
<item name="colorSecondary">@color/teal_200</item>
|
||||||
|
<item name="colorSecondaryVariant">@color/teal_200</item>
|
||||||
|
<item name="colorOnSecondary">@color/black</item>
|
||||||
|
<!-- Status bar color. -->
|
||||||
|
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
</style>
|
||||||
|
</resources>
|
10
ui/src/main/res/values/colors.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="purple_200">#FFBB86FC</color>
|
||||||
|
<color name="purple_500">#FF6200EE</color>
|
||||||
|
<color name="purple_700">#FF3700B3</color>
|
||||||
|
<color name="teal_200">#FF03DAC5</color>
|
||||||
|
<color name="teal_700">#FF018786</color>
|
||||||
|
<color name="black">#FF000000</color>
|
||||||
|
<color name="white">#FFFFFFFF</color>
|
||||||
|
</resources>
|
3
ui/src/main/res/values/strings.xml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<resources>
|
||||||
|
<string name="app_name">UI</string>
|
||||||
|
</resources>
|
16
ui/src/main/res/values/themes.xml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
<!-- Base application theme. -->
|
||||||
|
<style name="Theme.Ntfy" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||||
|
<!-- Primary brand color. -->
|
||||||
|
<item name="colorPrimary">@color/purple_500</item>
|
||||||
|
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||||
|
<item name="colorOnPrimary">@color/white</item>
|
||||||
|
<!-- Secondary brand color. -->
|
||||||
|
<item name="colorSecondary">@color/teal_200</item>
|
||||||
|
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||||
|
<item name="colorOnSecondary">@color/black</item>
|
||||||
|
<!-- Status bar color. -->
|
||||||
|
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
</style>
|
||||||
|
</resources>
|
17
ui/src/test/java/foundation/e/ntefy/ui/ExampleUnitTest.kt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package foundation.e.ntefy.ui
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
import org.junit.Assert.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example local unit test, which will execute on the development machine (host).
|
||||||
|
*
|
||||||
|
* See [testing documentation](http://d.android.com/tools/testing).
|
||||||
|
*/
|
||||||
|
class ExampleUnitTest {
|
||||||
|
@Test
|
||||||
|
fun addition_isCorrect() {
|
||||||
|
assertEquals(4, 2 + 2)
|
||||||
|
}
|
||||||
|
}
|