testing aria2c UI

This commit is contained in:
reduplicated 2022-09-18 00:05:28 +02:00
parent 2f44c97b86
commit 266a511cd7
13 changed files with 136 additions and 232 deletions

View file

@ -199,6 +199,9 @@ dependencies {
// Library/extensions searching with Levenshtein distance // Library/extensions searching with Levenshtein distance
implementation 'me.xdrop:fuzzywuzzy:1.4.0' implementation 'me.xdrop:fuzzywuzzy:1.4.0'
// aria2c downloader
implementation 'com.github.LagradOst:Aria2cButton:master-SNAPSHOT'
} }
task androidSourcesJar(type: Jar) { task androidSourcesJar(type: Jar) {

View file

@ -25,8 +25,11 @@ import com.lagradost.cloudstream3.utils.UIHelper
import com.lagradost.cloudstream3.utils.UIHelper.hasPIPPermission import com.lagradost.cloudstream3.utils.UIHelper.hasPIPPermission
import com.lagradost.cloudstream3.utils.UIHelper.shouldShowPIPMode import com.lagradost.cloudstream3.utils.UIHelper.shouldShowPIPMode
import com.lagradost.cloudstream3.utils.UIHelper.toPx import com.lagradost.cloudstream3.utils.UIHelper.toPx
import com.lagradost.fetchbutton.aria2c.Aria2Settings
import com.lagradost.fetchbutton.aria2c.Aria2Starter
import org.schabi.newpipe.extractor.NewPipe import org.schabi.newpipe.extractor.NewPipe
import java.util.* import java.util.*
import kotlin.concurrent.thread
object CommonActivity { object CommonActivity {
@MainThread @MainThread
@ -129,6 +132,18 @@ object CommonActivity {
act.updateLocale() act.updateLocale()
act.updateTv() act.updateTv()
NewPipe.init(DownloaderTestImpl.getInstance()) NewPipe.init(DownloaderTestImpl.getInstance())
thread {
Aria2Starter.start(
act,
Aria2Settings(
UUID.randomUUID().toString(),
4337,
act.filesDir.path,
"${act.filesDir.path}/session"
)
)
}
} }
private fun Activity.enterPIPMode() { private fun Activity.enterPIPMode() {

View file

@ -13,23 +13,17 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
import com.lagradost.cloudstream3.ui.download.DownloadButtonViewHolder import com.lagradost.cloudstream3.ui.download.DownloadButtonViewHolder
import com.lagradost.cloudstream3.ui.download.DownloadClickEvent import com.lagradost.cloudstream3.ui.download.DownloadClickEvent
import com.lagradost.cloudstream3.ui.download.EasyDownloadButton
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
import com.lagradost.cloudstream3.utils.AppUtils.html import com.lagradost.cloudstream3.utils.AppUtils.html
import com.lagradost.cloudstream3.utils.UIHelper.setImage import com.lagradost.cloudstream3.utils.UIHelper.setImage
import com.lagradost.cloudstream3.utils.VideoDownloadHelper import com.lagradost.fetchbutton.aria2c.newUriRequest
import com.lagradost.cloudstream3.utils.VideoDownloadManager
import kotlinx.android.synthetic.main.result_episode.view.* import kotlinx.android.synthetic.main.result_episode.view.*
import kotlinx.android.synthetic.main.result_episode.view.episode_text import kotlinx.android.synthetic.main.result_episode.view.episode_text
import kotlinx.android.synthetic.main.result_episode_large.view.*
import kotlinx.android.synthetic.main.result_episode_large.view.episode_filler import kotlinx.android.synthetic.main.result_episode_large.view.episode_filler
import kotlinx.android.synthetic.main.result_episode_large.view.episode_progress import kotlinx.android.synthetic.main.result_episode_large.view.episode_progress
import kotlinx.android.synthetic.main.result_episode_large.view.result_episode_download import kotlinx.android.synthetic.main.result_episode_large_tv.view.*
import kotlinx.android.synthetic.main.result_episode_large.view.result_episode_progress_downloaded
import java.util.*
const val ACTION_PLAY_EPISODE_IN_PLAYER = 1 const val ACTION_PLAY_EPISODE_IN_PLAYER = 1
const val ACTION_PLAY_EPISODE_IN_VLC_PLAYER = 2 const val ACTION_PLAY_EPISODE_IN_VLC_PLAYER = 2
@ -62,17 +56,6 @@ class EpisodeAdapter(
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { ) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var cardList: MutableList<ResultEpisode> = mutableListOf() private var cardList: MutableList<ResultEpisode> = mutableListOf()
private val mBoundViewHolders: HashSet<DownloadButtonViewHolder> = HashSet()
private fun getAllBoundViewHolders(): Set<DownloadButtonViewHolder?>? {
return Collections.unmodifiableSet(mBoundViewHolders)
}
fun killAdapter() {
getAllBoundViewHolders()?.forEach { view ->
view?.downloadButton?.dispose()
}
}
override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) { override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) {
if (holder.itemView.hasFocus()) { if (holder.itemView.hasFocus()) {
holder.itemView.clearFocus() holder.itemView.clearFocus()
@ -85,15 +68,6 @@ class EpisodeAdapter(
} }
} }
override fun onViewRecycled(holder: RecyclerView.ViewHolder) {
if (holder is DownloadButtonViewHolder) {
holder.downloadButton.dispose()
mBoundViewHolders.remove(holder)
//(holder.itemView as? FrameLayout?)?.descendantFocusability =
// ViewGroup.FOCUS_BLOCK_DESCENDANTS
}
}
override fun onViewAttachedToWindow(holder: RecyclerView.ViewHolder) { override fun onViewAttachedToWindow(holder: RecyclerView.ViewHolder) {
if (holder is DownloadButtonViewHolder) { if (holder is DownloadButtonViewHolder) {
//println("onViewAttachedToWindow = ${holder.absoluteAdapterPosition}") //println("onViewAttachedToWindow = ${holder.absoluteAdapterPosition}")
@ -138,7 +112,6 @@ class EpisodeAdapter(
when (holder) { when (holder) {
is EpisodeCardViewHolder -> { is EpisodeCardViewHolder -> {
holder.bind(cardList[position]) holder.bind(cardList[position])
mBoundViewHolders.add(holder)
} }
} }
} }
@ -153,17 +126,11 @@ class EpisodeAdapter(
private val hasDownloadSupport: Boolean, private val hasDownloadSupport: Boolean,
private val clickCallback: (EpisodeClickEvent) -> Unit, private val clickCallback: (EpisodeClickEvent) -> Unit,
private val downloadClickCallback: (DownloadClickEvent) -> Unit, private val downloadClickCallback: (DownloadClickEvent) -> Unit,
) : RecyclerView.ViewHolder(itemView), DownloadButtonViewHolder { ) : RecyclerView.ViewHolder(itemView) {
override var downloadButton = EasyDownloadButton() //override var downloadButton = EasyDownloadButton()
var episodeDownloadBar: ContentLoadingProgressBar? = null
var episodeDownloadImage: ImageView? = null
var localCard: ResultEpisode? = null
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
fun bind(card: ResultEpisode) { fun bind(card: ResultEpisode) {
localCard = card
val isTrueTv = isTrueTvSettings() val isTrueTv = isTrueTvSettings()
val (parentView, otherView) = if (card.poster == null) { val (parentView, otherView) = if (card.poster == null) {
@ -181,9 +148,17 @@ class EpisodeAdapter(
val episodeProgress: ContentLoadingProgressBar? = parentView.episode_progress val episodeProgress: ContentLoadingProgressBar? = parentView.episode_progress
val episodePoster: ImageView? = parentView.episode_poster val episodePoster: ImageView? = parentView.episode_poster
episodeDownloadBar = val downloadButton = parentView.result_episode_download
parentView.result_episode_progress_downloaded
episodeDownloadImage = parentView.result_episode_download downloadButton.setPersistentId(card.id.toLong())
downloadButton.isVisible = hasDownloadSupport
downloadButton.setDefaultClickListener {
listOf(
newUriRequest(
card.id.toLong(), "https://speed.hetzner.de/100MB.bin", "Hello World",
)
)
}
val name = val name =
if (card.name == null) "${episodeText.context.getString(R.string.episode)} ${card.episode}" else "${card.episode}. ${card.name}" if (card.name == null) "${episodeText.context.getString(R.string.episode)} ${card.episode}" else "${card.episode}. ${card.name}"
@ -242,49 +217,6 @@ class EpisodeAdapter(
return@setOnLongClickListener true return@setOnLongClickListener true
} }
episodeDownloadImage?.isVisible = hasDownloadSupport
episodeDownloadBar?.isVisible = hasDownloadSupport
reattachDownloadButton()
}
override fun reattachDownloadButton() {
downloadButton.dispose()
val card = localCard
if (hasDownloadSupport && card != null) {
if (episodeDownloadBar == null ||
episodeDownloadImage == null
) return
val downloadInfo = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(
itemView.context,
card.id
)
downloadButton.setUpButton(
downloadInfo?.fileLength,
downloadInfo?.totalBytes,
episodeDownloadBar ?: return,
episodeDownloadImage ?: return,
null,
VideoDownloadHelper.DownloadEpisodeCached(
card.name,
card.poster,
card.episode,
card.season,
card.id,
card.parentId,
card.rating,
card.description,
System.currentTimeMillis(),
)
) {
if (it.action == DOWNLOAD_ACTION_DOWNLOAD) {
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
} else {
downloadClickCallback.invoke(it)
}
}
}
} }
} }
} }

View file

@ -256,7 +256,6 @@ open class ResultFragment : ResultTrailerPlayer() {
private var downloadButton: EasyDownloadButton? = null private var downloadButton: EasyDownloadButton? = null
override fun onDestroyView() { override fun onDestroyView() {
updateUIListener = null updateUIListener = null
(result_episodes?.adapter as EpisodeAdapter?)?.killAdapter()
downloadButton?.dispose() downloadButton?.dispose()
super.onDestroyView() super.onDestroyView()

View file

@ -90,8 +90,8 @@
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:indeterminate="false" android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar" android:progressDrawable="@drawable/circular_progress_bar_cs3"
android:background="@drawable/circle_shape" android:background="@drawable/circle_shape_cs3"
style="?android:attr/progressBarStyleHorizontal" style="?android:attr/progressBarStyleHorizontal"
android:max="100" android:max="100"
android:layout_margin="5dp" android:layout_margin="5dp"

View file

@ -78,8 +78,8 @@
android:layout_height="40dp" android:layout_height="40dp"
android:id="@+id/download_header_progress_downloaded" android:id="@+id/download_header_progress_downloaded"
android:indeterminate="false" android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar" android:progressDrawable="@drawable/circular_progress_bar_cs3"
android:background="@drawable/circle_shape" android:background="@drawable/circle_shape_cs3"
style="?android:attr/progressBarStyleHorizontal" style="?android:attr/progressBarStyleHorizontal"
android:max="100" android:max="100"
android:layout_margin="5dp" android:layout_margin="5dp"

View file

@ -604,13 +604,13 @@
android:layout_height="25dp" android:layout_height="25dp"
android:layout_gravity="end|center_vertical" android:layout_gravity="end|center_vertical"
android:layout_margin="5dp" android:layout_margin="5dp"
android:background="@drawable/circle_shape" android:background="@drawable/circle_shape_cs3"
android:indeterminate="false" android:indeterminate="false"
android:max="100" android:max="100"
android:paddingStart="5dp" android:paddingStart="5dp"
android:paddingEnd="5dp" android:paddingEnd="5dp"
android:progress="30" android:progress="30"
android:progressDrawable="@drawable/circular_progress_bar_filled" android:progressDrawable="@drawable/circular_progress_bar_filled_cs3"
android:visibility="visible" /> android:visibility="visible" />
<ImageView <ImageView

View file

@ -460,13 +460,13 @@
android:layout_height="25dp" android:layout_height="25dp"
android:layout_gravity="end|center_vertical" android:layout_gravity="end|center_vertical"
android:layout_margin="5dp" android:layout_margin="5dp"
android:background="@drawable/circle_shape" android:background="@drawable/circle_shape_cs3"
android:indeterminate="false" android:indeterminate="false"
android:max="100" android:max="100"
android:paddingStart="5dp" android:paddingStart="5dp"
android:paddingEnd="5dp" android:paddingEnd="5dp"
android:progress="30" android:progress="30"
android:progressDrawable="@drawable/circular_progress_bar_filled" android:progressDrawable="@drawable/circular_progress_bar_filled_cs3"
android:visibility="visible" /> android:visibility="visible" />
<ImageView <ImageView

View file

@ -95,35 +95,12 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.core.widget.ContentLoadingProgressBar <com.lagradost.fetchbutton.ui.PieFetchButton
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/result_episode_progress_downloaded"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar"
android:background="@drawable/circle_shape"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:layout_margin="5dp"
android:layout_gravity="end|center_vertical"
android:progress="0"
android:visibility="visible" />
<!--
android:nextFocusRight="@id/episode_holder"-->
<ImageView
android:nextFocusLeft="@id/episode_holder"
app:tint="?attr/white"
android:id="@+id/result_episode_download"
android:visibility="visible"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="10dp"
android:layout_width="50dp"
android:background="?selectableItemBackgroundBorderless" android:background="?selectableItemBackgroundBorderless"
android:src="@drawable/ic_baseline_play_arrow_24" android:id="@+id/result_episode_download"
android:contentDescription="@string/download" /> android:layout_gravity="center"
android:layout_width="50dp"
android:layout_height="50dp">
</com.lagradost.fetchbutton.ui.PieFetchButton>
</FrameLayout> </FrameLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>

View file

@ -3,27 +3,27 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:nextFocusRight="@id/result_episode_download"
android:id="@+id/episode_holder_large" android:id="@+id/episode_holder_large"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/rounded_image_radius" android:layout_marginBottom="10dp"
android:nextFocusRight="@id/result_episode_download"
app:cardBackgroundColor="?attr/boxItemBackground" app:cardBackgroundColor="?attr/boxItemBackground"
android:layout_marginBottom="10dp"> app:cardCornerRadius="@dimen/rounded_image_radius">
<LinearLayout <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackgroundBorderless" android:foreground="?android:attr/selectableItemBackgroundBorderless"
android:padding="10dp"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:padding="10dp">
android:layout_height="wrap_content">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:orientation="horizontal" android:layout_height="wrap_content"
android:layout_height="wrap_content"> android:orientation="horizontal">
<!--app:cardCornerRadius="@dimen/roundedImageRadius"--> <!--app:cardCornerRadius="@dimen/roundedImageRadius"-->
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:layout_width="126dp" android:layout_width="126dp"
@ -31,121 +31,99 @@
android:foreground="@drawable/outline_drawable"> android:foreground="@drawable/outline_drawable">
<ImageView <ImageView
android:nextFocusRight="@id/result_episode_download"
android:id="@+id/episode_poster" android:id="@+id/episode_poster"
tools:src="@drawable/example_poster"
android:foreground="?android:attr/selectableItemBackgroundBorderless"
android:scaleType="centerCrop"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:contentDescription="@string/episode_poster_img_des" /> android:contentDescription="@string/episode_poster_img_des"
android:foreground="?android:attr/selectableItemBackgroundBorderless"
android:nextFocusRight="@id/result_episode_download"
android:scaleType="centerCrop"
tools:src="@drawable/example_poster" />
<ImageView <ImageView
android:src="@drawable/play_button"
android:layout_gravity="center"
android:layout_width="36dp" android:layout_width="36dp"
android:layout_height="36dp" android:layout_height="36dp"
android:contentDescription="@string/play_episode" /> android:layout_gravity="center"
android:contentDescription="@string/play_episode"
android:src="@drawable/play_button" />
<androidx.core.widget.ContentLoadingProgressBar <androidx.core.widget.ContentLoadingProgressBar
android:layout_marginBottom="-1.5dp"
android:id="@+id/episode_progress" android:id="@+id/episode_progress"
android:progressTint="?attr/colorPrimary"
android:progressBackgroundTint="?attr/colorPrimary"
style="@android:style/Widget.Material.ProgressBar.Horizontal" style="@android:style/Widget.Material.ProgressBar.Horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
tools:progress="50" android:layout_height="5dp"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_height="5dp" /> android:layout_marginBottom="-1.5dp"
android:progressBackgroundTint="?attr/colorPrimary"
android:progressTint="?attr/colorPrimary"
tools:progress="50" />
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<LinearLayout <LinearLayout
android:layout_marginStart="15dp"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="15dp"
android:layout_marginEnd="50dp" android:layout_marginEnd="50dp"
android:layout_height="wrap_content"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:layout_gravity="start" android:id="@+id/episode_filler"
style="@style/SmallBlackButton" style="@style/SmallBlackButton"
android:layout_gravity="start"
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:text="@string/filler" android:text="@string/filler" />
android:id="@+id/episode_filler" />
<TextView <TextView
android:layout_gravity="center_vertical"
android:id="@+id/episode_text" android:id="@+id/episode_text"
tools:text="1. Jobless"
android:textStyle="bold"
android:textColor="?attr/textColor"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?attr/textColor"
android:textStyle="bold"
tools:text="1. Jobless" />
</LinearLayout> </LinearLayout>
<TextView <TextView
android:id="@+id/episode_rating" android:id="@+id/episode_rating"
tools:text="Rated: 8.8"
android:textColor="?attr/grayTextColor"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:textColor="?attr/grayTextColor"
tools:text="Rated: 8.8" />
</LinearLayout> </LinearLayout>
<FrameLayout <FrameLayout
android:layout_marginStart="-50dp"
android:layout_gravity="end"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:layout_gravity="end"
android:layout_marginStart="-50dp">
<androidx.core.widget.ContentLoadingProgressBar <com.lagradost.fetchbutton.ui.PieFetchButton
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/result_episode_progress_downloaded"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar"
android:background="@drawable/circle_shape"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:layout_margin="5dp"
android:layout_gravity="end|center_vertical"
android:progress="0"
android:visibility="visible" />
<ImageView
android:nextFocusLeft="@id/episode_poster"
android:id="@+id/result_episode_download"
android:visibility="visible"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="10dp"
android:layout_width="50dp"
android:background="?selectableItemBackgroundBorderless" android:background="?selectableItemBackgroundBorderless"
android:src="@drawable/ic_baseline_play_arrow_24" android:id="@+id/result_episode_download"
android:contentDescription="@string/download" android:layout_gravity="center"
app:tint="?attr/white" /> android:layout_width="50dp"
android:layout_height="50dp">
</com.lagradost.fetchbutton.ui.PieFetchButton>
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>
<TextView <TextView
android:maxLines="4" android:id="@+id/episode_descript"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="4"
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp" android:paddingBottom="10dp"
android:id="@+id/episode_descript"
android:textColor="?attr/grayTextColor" android:textColor="?attr/grayTextColor"
tools:text="Jon and Daenerys arrive in Winterfell and are met with skepticism. Sam learns about the fate of his family. Cersei gives Euron the reward he aims for. Theon follows his heart. Jon and Daenerys arrive in Winterfell and are met with skepticism. Sam learns about the fate of his family. Cersei gives Euron the reward he aims for. Theon follows his heart." tools:text="Jon and Daenerys arrive in Winterfell and are met with skepticism. Sam learns about the fate of his family. Cersei gives Euron the reward he aims for. Theon follows his heart. Jon and Daenerys arrive in Winterfell and are met with skepticism. Sam learns about the fate of his family. Cersei gives Euron the reward he aims for. Theon follows his heart." />
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>