comments & rename

pull/2335/head
TobiGr 2021-10-18 13:11:44 +02:00
rodzic 793ff1a728
commit 7d4c7718aa
4 zmienionych plików z 29 dodań i 10 usunięć

Wyświetl plik

@ -10,6 +10,10 @@ import io.reactivex.rxjava3.core.SingleEmitter
import io.reactivex.rxjava3.core.SingleOnSubscribe import io.reactivex.rxjava3.core.SingleOnSubscribe
import org.schabi.newpipe.util.PicassoHelper 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( internal class NotificationIcon(
context: Context, context: Context,
private val url: String, private val url: String,

Wyświetl plik

@ -10,9 +10,14 @@ import androidx.recyclerview.widget.RecyclerView
import org.schabi.newpipe.R import org.schabi.newpipe.R
import org.schabi.newpipe.database.subscription.NotificationMode import org.schabi.newpipe.database.subscription.NotificationMode
import org.schabi.newpipe.database.subscription.SubscriptionEntity 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 private val listener: ModeToggleListener
) : RecyclerView.Adapter<SubscriptionHolder>() { ) : RecyclerView.Adapter<SubscriptionHolder>() {
@ -87,7 +92,7 @@ class NotificationsConfigAdapter(
} else { } else {
NotificationMode.ENABLED NotificationMode.ENABLED
} }
listener.onModeToggle(adapterPosition, mode) listener.onModeChange(adapterPosition, mode)
} }
} }
@ -111,6 +116,9 @@ class NotificationsConfigAdapter(
} }
interface ModeToggleListener { 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)
} }
} }

Wyświetl plik

@ -16,13 +16,18 @@ import io.reactivex.rxjava3.schedulers.Schedulers
import org.schabi.newpipe.R import org.schabi.newpipe.R
import org.schabi.newpipe.database.subscription.NotificationMode import org.schabi.newpipe.database.subscription.NotificationMode
import org.schabi.newpipe.local.subscription.SubscriptionManager 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 lateinit var updaters: CompositeDisposable
private var loader: Disposable? = null private var loader: Disposable? = null
private var adapter: NotificationsConfigAdapter? = null private var adapter: NotificationModeConfigAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -39,7 +44,7 @@ class NotificationsChannelsConfigFragment : Fragment(), ModeToggleListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view) val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view)
adapter = NotificationsConfigAdapter(this) adapter = NotificationModeConfigAdapter(this)
recyclerView.adapter = adapter recyclerView.adapter = adapter
loader?.dispose() loader?.dispose()
loader = SubscriptionManager(requireContext()) 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 val subscription = adapter?.getItem(position) ?: return
updaters.add( updaters.add(
SubscriptionManager(requireContext()) SubscriptionManager(requireContext())

Wyświetl plik

@ -32,7 +32,7 @@
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<Preference <Preference
android:fragment="org.schabi.newpipe.settings.notifications.NotificationsChannelsConfigFragment" android:fragment="org.schabi.newpipe.settings.notifications.NotificationModeConfigFragment"
android:dependency="@string/enable_streams_notifications" android:dependency="@string/enable_streams_notifications"
android:key="@string/streams_notifications_channels_key" android:key="@string/streams_notifications_channels_key"
android:title="@string/channels" android:title="@string/channels"