Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import org.schabi.newpipe.util.ThemeHelper.resolveDrawable
import org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout

class FeedFragment : BaseStateFragment<FeedState>() {
private lateinit var feedLoadServiceIntent: Intent
private var _feedBinding: FragmentFeedBinding? = null
private val feedBinding get() = _feedBinding!!

Expand Down Expand Up @@ -200,6 +201,11 @@ class FeedFragment : BaseStateFragment<FeedState>() {
hideNewItemsLoaded(true)
feedBinding.itemsList.scrollToPosition(0)
}
feedBinding.cancelFeedReloadingButton.setOnClickListener {
hideNewItemsLoaded(false)
hideLoading()
cancelReloadingContent()
}
}

// /////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -320,6 +326,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
feedBinding.itemsList.animateHideRecyclerViewAllowingScrolling()
feedBinding.refreshRootView.animate(false, 0)
feedBinding.loadingProgressText.animate(true, 200)
feedBinding.cancelFeedReloadingButton.animate(true, 200)
feedBinding.swipeRefreshLayout.isRefreshing = true
isRefreshing = true
}
Expand All @@ -329,6 +336,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
feedBinding.itemsList.animate(true, 0)
feedBinding.refreshRootView.animate(true, 200)
feedBinding.loadingProgressText.animate(false, 0)
feedBinding.cancelFeedReloadingButton.animate(false, 0)
feedBinding.swipeRefreshLayout.isRefreshing = false
isRefreshing = false
}
Expand Down Expand Up @@ -367,7 +375,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
progressState.maxProgress == -1

feedBinding.loadingProgressText.text = if (!isIndeterminate) {
"${progressState.currentProgress}/${progressState.maxProgress}"
"${progressState.progressDescription} (${progressState.currentProgress}/${progressState.maxProgress})"
} else if (progressState.progressMessage > 0) {
getString(progressState.progressMessage)
} else {
Expand Down Expand Up @@ -680,14 +688,18 @@ class FeedFragment : BaseStateFragment<FeedState>() {
override fun reloadContent() {
hideNewItemsLoaded(false)

getActivity()?.startService(
Intent(requireContext(), FeedLoadService::class.java).apply {
putExtra(FeedLoadService.EXTRA_GROUP_ID, groupId)
}
)
feedLoadServiceIntent = Intent(requireContext(), FeedLoadService::class.java).apply {
putExtra(FeedLoadService.EXTRA_GROUP_ID, groupId)
}

getActivity()?.startService(feedLoadServiceIntent)
listState = null
}

fun cancelReloadingContent() {
getActivity()?.stopService(feedLoadServiceIntent)
}

companion object {
const val KEY_GROUP_ID = "ARG_GROUP_ID"
const val KEY_GROUP_NAME = "ARG_GROUP_NAME"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/schabi/newpipe/local/feed/FeedState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ sealed class FeedState {
data class ProgressState(
val currentProgress: Int = -1,
val maxProgress: Int = -1,
@StringRes val progressMessage: Int = 0
@StringRes val progressMessage: Int = 0,
val progressDescription: String = ""
) : FeedState()

data class LoadedState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class FeedViewModel(
mutableStateLiveData.postValue(
when (event) {
is IdleEvent -> FeedState.LoadedState(listFromDB.map { e -> StreamItem(e) }, oldestUpdate, notLoadedCount, listOf())
is ProgressEvent -> FeedState.ProgressState(event.currentProgress, event.maxProgress, event.progressMessage)
is ProgressEvent -> FeedState.ProgressState(event.currentProgress, event.maxProgress, event.progressMessage, event.progressDescription)
is SuccessResultEvent -> FeedState.LoadedState(listFromDB.map { e -> StreamItem(e) }, oldestUpdate, notLoadedCount, event.itemsErrors)
is ErrorResultEvent -> FeedState.ErrorState(event.error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object FeedEventManager {

sealed class Event {
data object IdleEvent : Event()
data class ProgressEvent(val currentProgress: Int = -1, val maxProgress: Int = -1, @StringRes val progressMessage: Int = 0) : Event() {
data class ProgressEvent(val currentProgress: Int = -1, val maxProgress: Int = -1, @StringRes val progressMessage: Int = 0, val progressDescription: String = "") : Event() {
constructor(@StringRes progressMessage: Int) : this(-1, -1, progressMessage)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class FeedLoadManager(private val context: Context) {

private val notificationUpdater = PublishProcessor.create<String>()
private val currentProgress = AtomicInteger(-1)
private var currentProgressDescription = ""
private val maxProgress = AtomicInteger(-1)
private val cancelSignal = AtomicBoolean()
private val feedResultsHolder = FeedResultsHolder()
Expand Down Expand Up @@ -148,7 +149,8 @@ class FeedLoadManager(private val context: Context) {
FeedEventManager.postEvent(
FeedEventManager.Event.ProgressEvent(
currentProgress.get(),
maxProgress.get()
maxProgress.get(),
progressDescription = currentProgressDescription
)
)
}
Expand Down Expand Up @@ -278,7 +280,8 @@ class FeedLoadManager(private val context: Context) {
private inner class NotificationConsumer : Consumer<Notification<FeedUpdateInfo>> {
override fun accept(item: Notification<FeedUpdateInfo>) {
currentProgress.incrementAndGet()
notificationUpdater.onNext(item.value?.name.orEmpty())
currentProgressDescription = item.value?.name.orEmpty()
notificationUpdater.onNext(currentProgressDescription)

broadcastProgress()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.PendingIntentCompat
import androidx.core.app.ServiceCompat
import androidx.core.content.ContextCompat
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Flowable
Expand Down Expand Up @@ -101,7 +100,7 @@ class FeedLoadService : Service() {
handleError(error)
return@subscribe
}
stopService()
stopSelf()
}
return START_NOT_STICKY
}
Expand All @@ -112,10 +111,8 @@ class FeedLoadService : Service() {
notificationDisposable?.dispose()
}

private fun stopService() {
override fun onDestroy() {
disposeAll()
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
stopSelf()
}

override fun onBind(intent: Intent): IBinder? {
Expand Down Expand Up @@ -213,6 +210,6 @@ class FeedLoadService : Service() {

private fun handleError(error: Throwable) {
postEvent(ErrorResultEvent(error))
stopService()
stopSelf()
}
}
13 changes: 12 additions & 1 deletion app/src/main/res/layout/fragment_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,23 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="∞/∞"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textSize="16sp"
android:visibility="gone"
tools:text="1/120"
tools:visibility="visible" />

<Button
android:id="@+id/cancel_feed_reloading_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:text="@string/cancel"
android:textSize="12sp"
android:theme="@style/Base"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>

<!--ERROR PANEL-->
Expand Down
Loading