diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationIcon.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationIcon.kt index 1073945d4..0fb6877a6 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationIcon.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationIcon.kt @@ -10,6 +10,10 @@ import io.reactivex.rxjava3.core.SingleEmitter import io.reactivex.rxjava3.core.SingleOnSubscribe import org.schabi.newpipe.util.PicassoHelper +/** + * Helper class to handle loading and resizing of icons + * which are used going to be used in notifications. + */ internal class NotificationIcon( context: Context, private val url: String, diff --git a/app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationsConfigAdapter.kt b/app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationModeConfigAdapter.kt similarity index 85% rename from app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationsConfigAdapter.kt rename to app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationModeConfigAdapter.kt index 2fa916166..156877b4e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationsConfigAdapter.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationModeConfigAdapter.kt @@ -10,9 +10,14 @@ import androidx.recyclerview.widget.RecyclerView import org.schabi.newpipe.R import org.schabi.newpipe.database.subscription.NotificationMode import org.schabi.newpipe.database.subscription.SubscriptionEntity -import org.schabi.newpipe.settings.notifications.NotificationsConfigAdapter.SubscriptionHolder +import org.schabi.newpipe.settings.notifications.NotificationModeConfigAdapter.SubscriptionHolder -class NotificationsConfigAdapter( +/** + * This [RecyclerView.Adapter] is used in the [NotificationModeConfigFragment]. + * The adapter holds all subscribed channels and their [NotificationMode]s + * and provides the needed data structures and methods for this task. + */ +class NotificationModeConfigAdapter( private val listener: ModeToggleListener ) : RecyclerView.Adapter() { @@ -87,7 +92,7 @@ class NotificationsConfigAdapter( } else { NotificationMode.ENABLED } - listener.onModeToggle(adapterPosition, mode) + listener.onModeChange(adapterPosition, mode) } } @@ -111,6 +116,9 @@ class NotificationsConfigAdapter( } interface ModeToggleListener { - fun onModeToggle(position: Int, @NotificationMode mode: Int) + /** + * Triggered when the UI representation of a notification mode is changed. + */ + fun onModeChange(position: Int, @NotificationMode mode: Int) } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationsChannelsConfigFragment.kt b/app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationModeConfigFragment.kt similarity index 84% rename from app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationsChannelsConfigFragment.kt rename to app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationModeConfigFragment.kt index 9c4797237..9021fd68c 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationsChannelsConfigFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationModeConfigFragment.kt @@ -16,13 +16,18 @@ import io.reactivex.rxjava3.schedulers.Schedulers import org.schabi.newpipe.R import org.schabi.newpipe.database.subscription.NotificationMode import org.schabi.newpipe.local.subscription.SubscriptionManager -import org.schabi.newpipe.settings.notifications.NotificationsConfigAdapter.ModeToggleListener +import org.schabi.newpipe.settings.notifications.NotificationModeConfigAdapter.ModeToggleListener -class NotificationsChannelsConfigFragment : Fragment(), ModeToggleListener { +/** + * [NotificationModeConfigFragment] is a settings fragment + * which allows changing the [NotificationMode] of all subscribed channels. + * The [NotificationMode] can either be changed one by one or toggled for all channels. + */ +class NotificationModeConfigFragment : Fragment(), ModeToggleListener { private lateinit var updaters: CompositeDisposable private var loader: Disposable? = null - private var adapter: NotificationsConfigAdapter? = null + private var adapter: NotificationModeConfigAdapter? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -39,7 +44,7 @@ class NotificationsChannelsConfigFragment : Fragment(), ModeToggleListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view) - adapter = NotificationsConfigAdapter(this) + adapter = NotificationModeConfigAdapter(this) recyclerView.adapter = adapter loader?.dispose() loader = SubscriptionManager(requireContext()) @@ -74,7 +79,9 @@ class NotificationsChannelsConfigFragment : Fragment(), ModeToggleListener { } } - override fun onModeToggle(position: Int, @NotificationMode mode: Int) { + override fun onModeChange(position: Int, @NotificationMode mode: Int) { + // Notification mode has been changed via the UI. + // Now change it in the database. val subscription = adapter?.getItem(position) ?: return updaters.add( SubscriptionManager(requireContext()) diff --git a/app/src/main/res/xml/notifications_settings.xml b/app/src/main/res/xml/notifications_settings.xml index 4390dc48c..60d0428f7 100644 --- a/app/src/main/res/xml/notifications_settings.xml +++ b/app/src/main/res/xml/notifications_settings.xml @@ -32,7 +32,7 @@ app:iconSpaceReserved="false" />