mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
make unread conversations float to the top of conversation lists and widgets. satisifies https://github.com/octoshrimpy/quik/issues/41 and largely satisfies https://github.com/octoshrimpy/quik/issues/99
This commit is contained in:
@@ -23,17 +23,45 @@ import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.klinker.android.send_message.BroadcastUtils
|
||||
import dev.octoshrimpy.quik.util.Preferences
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import javax.inject.Inject
|
||||
|
||||
class WidgetManagerImpl @Inject constructor(private val context: Context) : WidgetManager {
|
||||
class WidgetManagerImpl @Inject constructor(
|
||||
private val context: Context,
|
||||
private val prefs: Preferences
|
||||
) : WidgetManager {
|
||||
|
||||
override fun updateUnreadCount() {
|
||||
BroadcastUtils.sendExplicitBroadcast(context, Intent(), WidgetManager.ACTION_NOTIFY_DATASET_CHANGED)
|
||||
companion object {
|
||||
private var staticUnreadAtTopPrefsDisposable = AtomicReference<Disposable>(null)
|
||||
|
||||
fun sendDatasetChanged(context: Context) {
|
||||
BroadcastUtils.sendExplicitBroadcast(context, Intent(), WidgetManager.ACTION_NOTIFY_DATASET_CHANGED)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
// this class is always instantiated by it's factory with the application context so we can capture that context value below
|
||||
// when unreadAtTop preference changes, send broadcast to widgets to update themselves
|
||||
if (staticUnreadAtTopPrefsDisposable.get() === null)
|
||||
staticUnreadAtTopPrefsDisposable.set(prefs.unreadAtTop.asObservable()
|
||||
.skip(1)
|
||||
.debounce(400, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext { sendDatasetChanged(context) }
|
||||
.subscribe())
|
||||
}
|
||||
|
||||
override fun sendDatasetChanged() {
|
||||
sendDatasetChanged(context)
|
||||
}
|
||||
|
||||
override fun updateTheme() {
|
||||
val ids = AppWidgetManager.getInstance(context)
|
||||
.getAppWidgetIds(ComponentName("dev.octoshrimpy.quik", "dev.octoshrimpy.quik.feature.widget.WidgetProvider"))
|
||||
.getAppWidgetIds(ComponentName(context.packageName, "dev.octoshrimpy.quik.feature.widget.WidgetProvider"))
|
||||
|
||||
val intent = Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user