1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

comments & rename

This commit is contained in:
TobiGr 2021-10-18 13:11:44 +02:00
parent 793ff1a728
commit 7d4c7718aa
4 changed files with 29 additions and 10 deletions

View File

@ -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,

View File

@ -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<SubscriptionHolder>() {
@ -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)
}
}

View File

@ -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())

View File

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