mirror of https://github.com/readrops/Readrops.git
Add a switch to enable disable all feeds notifications
This commit is contained in:
parent
2d809f3c6b
commit
6600090525
|
@ -9,7 +9,7 @@ import androidx.databinding.DataBindingUtil
|
|||
import androidx.lifecycle.Observer
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.readrops.app.R
|
||||
import com.readrops.app.adapters.NotificationPermissionAdapter
|
||||
import com.readrops.app.adapters.NotificationPermissionListAdapter
|
||||
import com.readrops.app.databinding.ActivityNotificationPermissionBinding
|
||||
import com.readrops.app.utils.Utils
|
||||
import com.readrops.app.viewmodels.NotificationPermissionViewModel
|
||||
|
@ -29,7 +29,7 @@ class NotificationPermissionActivity : AppCompatActivity() {
|
|||
|
||||
val accountId = intent.getIntExtra(ACCOUNT_ID, 0)
|
||||
val viewModel by viewModels<NotificationPermissionViewModel>()
|
||||
var adapter: NotificationPermissionAdapter? = null
|
||||
var adapter: NotificationPermissionListAdapter? = null
|
||||
|
||||
viewModel.getAccount(accountId).observe(this, Observer { account ->
|
||||
viewModel.account = account
|
||||
|
@ -39,6 +39,8 @@ class NotificationPermissionActivity : AppCompatActivity() {
|
|||
binding.notifPermissionAccountSwitch.isChecked = account.isNotificationsEnabled
|
||||
binding.notifPermissionAccountSwitch.setOnCheckedChangeListener { _, isChecked ->
|
||||
account.isNotificationsEnabled = isChecked
|
||||
binding.notifPermissionFeedsSwitch.isEnabled = isChecked
|
||||
|
||||
adapter?.enableAll = isChecked
|
||||
adapter?.notifyDataSetChanged()
|
||||
|
||||
|
@ -49,7 +51,16 @@ class NotificationPermissionActivity : AppCompatActivity() {
|
|||
.subscribe()
|
||||
}
|
||||
|
||||
adapter = NotificationPermissionAdapter(account.isNotificationsEnabled) { feed ->
|
||||
binding.notifPermissionFeedsSwitch.isEnabled = account.isNotificationsEnabled
|
||||
binding.notifPermissionFeedsSwitch.setOnCheckedChangeListener { _, isChecked ->
|
||||
viewModel.setAllFeedsNotificationState(isChecked)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnError { Utils.showSnackbar(binding.root, it.message) }
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
adapter = NotificationPermissionListAdapter(account.isNotificationsEnabled) { feed ->
|
||||
viewModel.setFeedNotificationState(feed)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -60,8 +71,9 @@ class NotificationPermissionActivity : AppCompatActivity() {
|
|||
binding.notifPermissionAccountList.layoutManager = LinearLayoutManager(this)
|
||||
binding.notifPermissionAccountList.adapter = adapter
|
||||
|
||||
viewModel.getFeedsWithNotifPermission().observe(this, Observer {
|
||||
adapter?.submitList(it)
|
||||
viewModel.getFeedsWithNotifPermission().observe(this, Observer { feeds ->
|
||||
binding.notifPermissionFeedsSwitch.isChecked = feeds.all { it.isNotificationEnabled }
|
||||
adapter?.submitList(feeds)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ import com.readrops.app.databinding.NotificationLayoutBinding
|
|||
import com.readrops.app.utils.GlideApp
|
||||
import com.readrops.readropsdb.entities.Feed
|
||||
|
||||
class NotificationPermissionAdapter(var enableAll: Boolean, val listener: (feed: Feed) -> Unit) :
|
||||
ListAdapter<Feed, NotificationPermissionAdapter.NotificationPermissionViewHolder>(DIFF_CALLBACK) {
|
||||
class NotificationPermissionListAdapter(var enableAll: Boolean, val listener: (feed: Feed) -> Unit) :
|
||||
ListAdapter<Feed, NotificationPermissionListAdapter.NotificationPermissionViewHolder>(DIFF_CALLBACK) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotificationPermissionViewHolder {
|
||||
val binding = DataBindingUtil.inflate<NotificationLayoutBinding>(LayoutInflater.from(parent.context),
|
||||
|
@ -49,7 +49,8 @@ class NotificationPermissionAdapter(var enableAll: Boolean, val listener: (feed:
|
|||
} else onBindViewHolder(holder, position)
|
||||
}
|
||||
|
||||
inner class NotificationPermissionViewHolder(val binding: NotificationLayoutBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
inner class NotificationPermissionViewHolder(val binding: NotificationLayoutBinding) :
|
||||
RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
companion object {
|
||||
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Feed>() {
|
||||
|
@ -60,6 +61,10 @@ class NotificationPermissionAdapter(var enableAll: Boolean, val listener: (feed:
|
|||
override fun areContentsTheSame(oldItem: Feed, newItem: Feed): Boolean {
|
||||
return oldItem.isNotificationEnabled == newItem.isNotificationEnabled
|
||||
}
|
||||
|
||||
override fun getChangePayload(oldItem: Feed, newItem: Feed): Any? {
|
||||
return newItem
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,7 +39,7 @@ class SyncResultDebugData {
|
|||
|
||||
val database = Database.getInstance(context)
|
||||
val item = database.itemDao().select(5055)
|
||||
database.feedDao().updateNotificationState(item.feedId, false).subscribe()
|
||||
database.feedDao().updateFeedNotificationState(item.feedId, false).subscribe()
|
||||
|
||||
val item2 = database.itemDao().select(5056)
|
||||
|
||||
|
|
|
@ -22,5 +22,8 @@ class NotificationPermissionViewModel(application: Application) : AndroidViewMod
|
|||
.updateNotificationState(account?.id!!, enabled)
|
||||
|
||||
fun setFeedNotificationState(feed: Feed): Completable = database.feedDao()
|
||||
.updateNotificationState(feed.id, !feed.isNotificationEnabled)
|
||||
.updateFeedNotificationState(feed.id, !feed.isNotificationEnabled)
|
||||
|
||||
fun setAllFeedsNotificationState(enabled: Boolean) = database.feedDao()
|
||||
.updateAllFeedsNotificationState(account?.id!!, enabled)
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/md_white_1000"
|
||||
android:padding="16dp"
|
||||
android:padding="12dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
@ -38,6 +38,38 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/notif_permission_account_switch"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:paddingTop="6dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notif_permission_feeds"
|
||||
style="@style/TextAppearance.AppCompat.Body1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="@string/enable_all_feeds"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/notif_permission_feeds_switch"
|
||||
app:layout_constraintHorizontal_chainStyle="packed"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/notif_permission_feeds_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/notif_permission_feeds"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
|
|
@ -125,5 +125,6 @@
|
|||
<string name="new_items">%1$s nouveaux articles</string>
|
||||
<string name="enable_notifications">Activer les notifications</string>
|
||||
<string name="notifications">Notifications</string>
|
||||
<string name="enable_all_feeds">Activer tous les flux</string>
|
||||
|
||||
</resources>
|
|
@ -131,4 +131,5 @@
|
|||
<string name="new_items">%1$s new articles</string>
|
||||
<string name="enable_notifications">Enable notifications</string>
|
||||
<string name="notifications">Notifications</string>
|
||||
<string name="enable_all_feeds">Enable all feeds</string>
|
||||
</resources>
|
||||
|
|
|
@ -85,7 +85,10 @@ public abstract class FeedDao implements BaseDao<Feed> {
|
|||
abstract int getRemoteFolderLocalId(String remoteId, int accountId);
|
||||
|
||||
@Query("Update Feed set notification_enabled = :enabled Where id = :feedId")
|
||||
public abstract Completable updateNotificationState(int feedId, boolean enabled);
|
||||
public abstract Completable updateFeedNotificationState(int feedId, boolean enabled);
|
||||
|
||||
@Query("Update Feed set notification_enabled = :enabled Where account_id = :accountId")
|
||||
public abstract Completable updateAllFeedsNotificationState(int accountId, boolean enabled);
|
||||
|
||||
/**
|
||||
* Insert, update and delete feeds, by account
|
||||
|
|
Loading…
Reference in New Issue