small UI fix and download fix

This commit is contained in:
LagradOst 2021-10-31 19:28:35 +01:00
parent bd8350f255
commit 3cf79fa5b2
8 changed files with 68 additions and 36 deletions

View file

@ -36,11 +36,13 @@ object DownloadButtonSetup {
builder.setTitle(R.string.delete_file) builder.setTitle(R.string.delete_file)
.setMessage( .setMessage(
ctx.getString(R.string.delete_message).format(ctx.getNameFull( ctx.getString(R.string.delete_message).format(
ctx.getNameFull(
click.data.name, click.data.name,
click.data.episode, click.data.episode,
click.data.season click.data.season
)) )
)
) )
.setPositiveButton(R.string.delete, dialogClickListener) .setPositiveButton(R.string.delete, dialogClickListener)
.setNegativeButton(R.string.cancel, dialogClickListener) .setNegativeButton(R.string.cancel, dialogClickListener)
@ -54,6 +56,11 @@ object DownloadButtonSetup {
} }
DOWNLOAD_ACTION_RESUME_DOWNLOAD -> { DOWNLOAD_ACTION_RESUME_DOWNLOAD -> {
activity?.let { ctx -> activity?.let { ctx ->
if (VideoDownloadManager.downloadStatus.containsKey(id) && VideoDownloadManager.downloadStatus[id] == VideoDownloadManager.DownloadType.IsPaused) {
VideoDownloadManager.downloadEvent.invoke(
Pair(click.data.id, VideoDownloadManager.DownloadActionType.Resume)
)
} else {
val pkg = VideoDownloadManager.getDownloadResumePackage(ctx, id) val pkg = VideoDownloadManager.getDownloadResumePackage(ctx, id)
if (pkg != null) { if (pkg != null) {
VideoDownloadManager.downloadFromResumeUsingWorker(ctx, pkg) VideoDownloadManager.downloadFromResumeUsingWorker(ctx, pkg)
@ -64,12 +71,13 @@ object DownloadButtonSetup {
} }
} }
} }
}
DOWNLOAD_ACTION_LONG_CLICK -> { DOWNLOAD_ACTION_LONG_CLICK -> {
activity?.let { act -> activity?.let { act ->
val length = val length =
VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(act, click.data.id)?.fileLength VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(act, click.data.id)?.fileLength
?: 0 ?: 0
if(length > 0) { if (length > 0) {
MainActivity.showToast(act, R.string.delete, Toast.LENGTH_LONG) MainActivity.showToast(act, R.string.delete, Toast.LENGTH_LONG)
} else { } else {
MainActivity.showToast(act, R.string.download, Toast.LENGTH_LONG) MainActivity.showToast(act, R.string.download, Toast.LENGTH_LONG)
@ -86,7 +94,8 @@ object DownloadButtonSetup {
click.data.id.toString() click.data.id.toString()
) ?: return ) ?: return
act.navigate(R.id.global_to_navigation_player, PlayerFragment.newInstance( act.navigate(
R.id.global_to_navigation_player, PlayerFragment.newInstance(
UriData( UriData(
info.path.toString(), info.path.toString(),
keyInfo.relativePath, keyInfo.relativePath,
@ -98,7 +107,8 @@ object DownloadButtonSetup {
click.data.season click.data.season
), ),
act.getViewPos(click.data.id)?.position ?: 0 act.getViewPos(click.data.id)?.position ?: 0
)) )
)
} }
} }
} }

View file

@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
@ -15,8 +16,9 @@ import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.isMovieType import com.lagradost.cloudstream3.isMovieType
import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE
import com.lagradost.cloudstream3.utils.DataStore.getFolderName import com.lagradost.cloudstream3.utils.DataStore
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.VideoDownloadHelper import com.lagradost.cloudstream3.utils.VideoDownloadHelper
@ -99,13 +101,24 @@ class DownloadFragment : Fragment() {
DownloadHeaderAdapter( DownloadHeaderAdapter(
ArrayList(), ArrayList(),
{ click -> { click ->
when (click.action) {
0 -> {
if (click.data.type.isMovieType()) { if (click.data.type.isMovieType()) {
//wont be called //wont be called
} else { } else {
val folder = getFolderName(DOWNLOAD_EPISODE_CACHE, click.data.id.toString()) val folder = DataStore.getFolderName(DOWNLOAD_EPISODE_CACHE, click.data.id.toString())
val navController = activity?.findNavController(R.id.nav_host_fragment) val navController = activity?.findNavController(R.id.nav_host_fragment)
navController?.navigate(R.id.navigation_download_child, DownloadChildFragment.newInstance(click.data.name,folder)) navController?.navigate(
R.id.navigation_download_child,
DownloadChildFragment.newInstance(click.data.name, folder)
)
} }
}
1 -> {
(activity as AppCompatActivity?)?.loadResult(click.data.url, click.data.apiName)
}
}
}, },
{ downloadClickEvent -> { downloadClickEvent ->
if (downloadClickEvent.data !is VideoDownloadHelper.DownloadEpisodeCached) return@DownloadHeaderAdapter if (downloadClickEvent.data !is VideoDownloadHelper.DownloadEpisodeCached) return@DownloadHeaderAdapter

View file

@ -105,6 +105,9 @@ class DownloadHeaderAdapter(
val d = card.data val d = card.data
poster?.setImage(d.poster) poster?.setImage(d.poster)
poster?.setOnClickListener {
clickCallback.invoke(DownloadHeaderClickEvent(1, d))
}
title.text = d.name title.text = d.name
val mbString = "%.1f".format(card.totalBytes / 1000000f) val mbString = "%.1f".format(card.totalBytes / 1000000f)

View file

@ -85,6 +85,8 @@
android:visibility="visible" android:visibility="visible"
/> />
<ImageView <ImageView
android:tint="?attr/white"
android:visibility="visible" android:visibility="visible"
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"

View file

@ -40,7 +40,7 @@
<View <View
android:layout_weight="0.5" android:layout_weight="0.5"
android:id="@+id/download_used" android:id="@+id/download_used"
android:background="@color/usedStorageColor" android:background="?attr/white"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
<View <View
@ -52,7 +52,7 @@
<View <View
android:id="@+id/download_free" android:id="@+id/download_free"
android:layout_weight="0.10" android:layout_weight="0.10"
android:background="@color/freeStorageColor" android:background="?attr/grayTextColor"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
</LinearLayout> </LinearLayout>
@ -65,7 +65,7 @@
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" android:layout_marginBottom="5dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:background="@color/usedStorageColor" android:background="?attr/white"
android:layout_width="10dp" android:layout_width="10dp"
android:layout_height="10dp"/> android:layout_height="10dp"/>
<TextView <TextView
@ -94,7 +94,7 @@
<View <View
android:layout_margin="5dp" android:layout_margin="5dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:background="@color/freeStorageColor" android:background="?attr/grayTextColor"
android:layout_width="10dp" android:layout_width="10dp"
android:layout_height="10dp"/> android:layout_height="10dp"/>
<TextView <TextView

View file

@ -109,6 +109,8 @@
android:nextFocusLeft="@id/episode_holder" android:nextFocusLeft="@id/episode_holder"
android:nextFocusRight="@id/episode_holder" android:nextFocusRight="@id/episode_holder"
android:tint="?attr/white"
android:id="@+id/result_episode_download" android:id="@+id/result_episode_download"
android:visibility="visible" android:visibility="visible"
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"

View file

@ -113,6 +113,8 @@
android:nextFocusRight="@id/episode_holder" android:nextFocusRight="@id/episode_holder"
android:id="@+id/result_episode_download" android:id="@+id/result_episode_download"
android:tint="?attr/white"
android:visibility="visible" android:visibility="visible"
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"

View file

@ -37,8 +37,8 @@
<color name="iconColor">#9ba0a6</color> <color name="iconColor">#9ba0a6</color>
<color name="usedStorageColor">#FFF</color> <!-- <color name="usedStorageColor">?attr/white</color>#fff-->
<color name="freeStorageColor">#676767</color> <!-- <color name="freeStorageColor">?attr/grayTextColor</color> #676767-->
<!--Light Mode --> <!--Light Mode -->
<color name="lightPrimaryGrayBackground">#f1f1f1</color> <color name="lightPrimaryGrayBackground">#f1f1f1</color>