Tiny changes

This commit is contained in:
Philipp Heckel 2021-12-31 02:00:08 +01:00
parent 2bc87013d5
commit bec263d1c8
3 changed files with 6 additions and 10 deletions

View file

@ -7,6 +7,10 @@ import io.heckel.ntfy.data.Subscription
import io.heckel.ntfy.up.Distributor
import io.heckel.ntfy.util.safeLet
/**
* The notification dispatcher figures out what to do with a notification.
* It may display a notification, send out a broadcast, or forward via UnifiedPush.
*/
class NotificationDispatcher(val context: Context, val repository: Repository) {
private val notifier = NotificationService(context)
private val broadcaster = BroadcastService(context)
@ -48,8 +52,4 @@ class NotificationDispatcher(val context: Context, val repository: Repository) {
}
return subscription.mutedUntil == 1L || (subscription.mutedUntil > 1L && subscription.mutedUntil > System.currentTimeMillis()/1000)
}
companion object {
private const val TAG = "NtfyNotificationDispatcher"
}
}

View file

@ -42,7 +42,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
private val repository by lazy { (application as Application).repository }
private val api = ApiService()
private val messenger = FirebaseMessenger()
private var serviceManager: SubscriberServiceManager? = null // Context-dependent
private var notifier: NotificationService? = null // Context-dependent
private var appBaseUrl: String? = null // Context-dependent
@ -69,7 +68,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
Log.d(MainActivity.TAG, "Create $this")
// Dependencies that depend on Context
serviceManager = SubscriberServiceManager(this)
notifier = NotificationService(this)
appBaseUrl = getString(R.string.app_base_url)
@ -146,7 +144,7 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
// React to changes in fast delivery setting
repository.getSubscriptionIdsWithInstantStatusLiveData().observe(this) {
serviceManager?.refresh()
SubscriberServiceManager.refresh(this)
}
// Mark this subscription as "open" so we don't receive notifications for it

View file

@ -54,7 +54,6 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
private var actionMode: ActionMode? = null
private var workManager: WorkManager? = null // Context-dependent
private var dispatcher: NotificationDispatcher? = null // Context-dependent
private var serviceManager: SubscriberServiceManager? = null // Context-dependent
private var appBaseUrl: String? = null // Context-dependent
override fun onCreate(savedInstanceState: Bundle?) {
@ -66,7 +65,6 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
// Dependencies that depend on Context
workManager = WorkManager.getInstance(this)
dispatcher = NotificationDispatcher(this, repository)
serviceManager = SubscriberServiceManager(this)
appBaseUrl = getString(R.string.app_base_url)
// Action bar
@ -107,7 +105,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
// React to changes in instant delivery setting
viewModel.listIdsWithInstantStatus().observe(this) {
serviceManager?.refresh()
SubscriberServiceManager.refresh(this)
}
// Create notification channels right away, so we can configure them immediately after installing the app