From fa399cd350f30a70ac80c5167f422707a6680b7b Mon Sep 17 00:00:00 2001 From: reduplicated <110570621+reduplicated@users.noreply.github.com> Date: Sun, 30 Oct 2022 02:35:37 +0100 Subject: [PATCH] play video and delete stuff --- app/build.gradle | 2 +- .../lagradost/cloudstream3/CommonActivity.kt | 18 ++-- .../lagradost/cloudstream3/MainActivity.kt | 31 ++++++- .../cloudstream3/ui/download/Aria2cHelper.kt | 65 ++++++++++++++ .../ui/download/DownloadButtonSetup.kt | 7 +- .../ui/download/DownloadChildAdapter.kt | 64 +++++++++++-- .../ui/download/DownloadChildFragment.kt | 17 +++- .../cloudstream3/ui/result/DownloadHelper.kt | 90 +++++++++++-------- .../ui/result/ResultViewModel2.kt | 26 +++--- .../utils/VideoDownloadManager.kt | 30 +++---- app/src/main/res/values/colors.xml | 4 + app/src/main/res/values/styles.xml | 34 +++---- 12 files changed, 287 insertions(+), 101 deletions(-) create mode 100644 app/src/main/java/com/lagradost/cloudstream3/ui/download/Aria2cHelper.kt diff --git a/app/build.gradle b/app/build.gradle index 3aa9b56b..0fa0e7f1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -201,7 +201,7 @@ dependencies { implementation 'me.xdrop:fuzzywuzzy:1.4.0' // aria2c downloader - implementation 'com.github.LagradOst:Aria2cButton:v0.0.5' + implementation 'com.github.LagradOst:Aria2cButton:v0.0.6' } task androidSourcesJar(type: Jar) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt index 28e2857d..4eb1181d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt @@ -17,6 +17,8 @@ import androidx.appcompat.widget.SearchView import androidx.preference.PreferenceManager import com.google.android.gms.cast.framework.CastSession import com.lagradost.cloudstream3.mvvm.logError +import com.lagradost.cloudstream3.ui.download.Aria2cHelper.removeMetadata +import com.lagradost.cloudstream3.ui.download.Aria2cHelper.saveMetadata import com.lagradost.cloudstream3.ui.player.PlayerEventType import com.lagradost.cloudstream3.ui.result.UiText import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.updateTv @@ -25,10 +27,10 @@ import com.lagradost.cloudstream3.utils.UIHelper import com.lagradost.cloudstream3.utils.UIHelper.hasPIPPermission import com.lagradost.cloudstream3.utils.UIHelper.shouldShowPIPMode import com.lagradost.cloudstream3.utils.UIHelper.toPx -import com.lagradost.cloudstream3.utils.VideoDownloadManager import com.lagradost.fetchbutton.aria2c.Aria2Settings import com.lagradost.fetchbutton.aria2c.Aria2Starter import com.lagradost.fetchbutton.aria2c.DownloadListener +import com.lagradost.fetchbutton.aria2c.DownloadStatusTell import org.schabi.newpipe.extractor.NewPipe import java.util.* import kotlin.concurrent.thread @@ -121,7 +123,6 @@ object CommonActivity { val localeCode = settingsManager.getString(getString(R.string.locale_key), null) setLocale(this, localeCode) } - const val KEY_DOWNLOAD_INFO_METADATA = "download_info_metadata" fun init(act: Activity?) { if (act == null) return @@ -136,10 +137,17 @@ object CommonActivity { act.updateTv() NewPipe.init(DownloaderTestImpl.getInstance()) - DownloadListener.mainListener = { metadata -> + DownloadListener.mainListener = { (data, metadata) -> //TODO FIX - DownloadListener.sessionGidToId[metadata.items.firstOrNull()?.gid]?.let { id -> - AcraApplication.setKey(KEY_DOWNLOAD_INFO_METADATA,id.toString(),metadata) + DownloadListener.sessionGidToId[data.gid]?.let { id -> + if (metadata.status == DownloadStatusTell.Removed + || metadata.status == DownloadStatusTell.Error + || metadata.status == DownloadStatusTell.Waiting + || metadata.status == null) { + removeMetadata(id) + } else { + saveMetadata(id, metadata) + } /*val mainpath = metadata.items[0].files[0].path AcraApplication.setKey( VideoDownloadManager.KEY_DOWNLOAD_INFO, diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 7686a84c..6dbdd594 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -10,10 +10,10 @@ import android.view.KeyEvent import android.view.Menu import android.view.MenuItem import android.view.WindowManager -import android.widget.Toast import androidx.annotation.IdRes import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.fragment.app.FragmentActivity import androidx.navigation.NavController @@ -107,6 +107,8 @@ const val VLC_EXTRA_POSITION_OUT = "extra_position" const val VLC_EXTRA_DURATION_OUT = "extra_duration" const val VLC_LAST_ID_KEY = "vlc_last_open_id" +const val DOWNLOAD_COUNT_KEY = "download_badge_count" + // Short name for requests client to make it nicer to use var app = Requests(responseParser = object : ResponseParser { @@ -150,7 +152,11 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { * @return true if the str has launched an app task (be it successful or not) * @param isWebview does not handle providers and opening download page if true. Can still add repos and login. * */ - fun handleAppIntentUrl(activity: FragmentActivity?, str: String?, isWebview: Boolean): Boolean = + fun handleAppIntentUrl( + activity: FragmentActivity?, + str: String?, + isWebview: Boolean + ): Boolean = with(activity) { if (str != null && this != null) { if (str.startsWith("https://cs.repo")) { @@ -191,7 +197,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { val url = str.replaceFirst(appStringRepo, "https") loadRepository(url) return true - } else if (!isWebview){ + } else if (!isWebview) { if (str.startsWith(DOWNLOAD_NAVIGATE_TO)) { this.navigate(R.id.navigation_downloads) return true @@ -267,6 +273,25 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { } } + if (destination.id == R.id.navigation_download_child || destination.id == R.id.navigation_downloads) { + setKey(DOWNLOAD_COUNT_KEY, 0) + } + + nav_view?.getOrCreateBadge(R.id.navigation_downloads)?.apply { + val count = getKey(DOWNLOAD_COUNT_KEY) ?: 0 + if (count <= 0) { + clearNumber() + isVisible = false + } else { + this.backgroundColor = + getResourceColor(R.attr.colorPrimary) + this.badgeTextColor = + getResourceColor(R.attr.colorOnPrimary) + isVisible = true + number = count + } + } + nav_view?.isVisible = isNavVisible && !landscape nav_rail_view?.isVisible = isNavVisible && landscape } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/Aria2cHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/Aria2cHelper.kt new file mode 100644 index 00000000..cb920f7c --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/Aria2cHelper.kt @@ -0,0 +1,65 @@ +package com.lagradost.cloudstream3.ui.download + +import com.lagradost.cloudstream3.AcraApplication +import com.lagradost.cloudstream3.utils.VideoDownloadManager +import com.lagradost.cloudstream3.utils.VideoDownloadManager.KEY_DOWNLOAD_INFO +import com.lagradost.fetchbutton.aria2c.Aria2Starter +import com.lagradost.fetchbutton.aria2c.DownloadListener +import com.lagradost.fetchbutton.aria2c.Metadata +import java.io.File + +const val KEY_DOWNLOAD_INFO_METADATA = "download_info_metadata" + +object Aria2cHelper { + fun deleteId(id: Long) { + // backward compatibility + VideoDownloadManager.downloadDeleteEvent.invoke(id.toInt()) + + getMetadata(id)?.let { data -> + Aria2Starter.deleteFiles(data.items.flatMap { it.files }) + } + removeMetadata(id) + AcraApplication.removeKey(KEY_DOWNLOAD_INFO, id.toString()) + } + + fun saveMetadata(id: Long, meta: Metadata) { + AcraApplication.setKey(KEY_DOWNLOAD_INFO_METADATA, id.toString(), meta) + } + + fun removeMetadata(id: Long) { + AcraApplication.removeKey(KEY_DOWNLOAD_INFO_METADATA, id.toString()) + } + + fun downloadExist(data: Metadata): Boolean { + return data.items.any { + it.files.any { file -> + try { + //println("TESTING PATH: ${file.path}") + File(file.path).exists() + } catch (e: Exception) { + false + } + } + } + } + + fun downloadExist(id: Long): Boolean { + return downloadExist(getMetadata(id) ?: return false) + } + + fun getMetadata(id: Long): Metadata? { + return AcraApplication.getKey(KEY_DOWNLOAD_INFO_METADATA, id.toString()) + } + + fun pause(id: Long) { + DownloadListener.sessionIdToGid[id]?.let { gid -> + Aria2Starter.pause(gid, all = true) + } + } + + fun unpause(id: Long) { + DownloadListener.sessionIdToGid[id]?.let { gid -> + Aria2Starter.unpause(gid, all = true) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt index 0069be3a..6fca517a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt @@ -16,6 +16,7 @@ import com.lagradost.cloudstream3.utils.ExtractorUri import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.VideoDownloadHelper import com.lagradost.cloudstream3.utils.VideoDownloadManager +import com.lagradost.fetchbutton.aria2c.Aria2Starter object DownloadButtonSetup { fun handleDownloadClick(activity: Activity?, click: DownloadClickEvent) { @@ -29,6 +30,7 @@ object DownloadButtonSetup { DialogInterface.OnClickListener { _, which -> when (which) { DialogInterface.BUTTON_POSITIVE -> { + Aria2cHelper.deleteId(id.toLong()) VideoDownloadManager.deleteFileAndUpdateSettings(ctx, id) } DialogInterface.BUTTON_NEGATIVE -> { @@ -57,11 +59,14 @@ object DownloadButtonSetup { } } DOWNLOAD_ACTION_PAUSE_DOWNLOAD -> { + Aria2cHelper.pause(click.data.id.toLong()) VideoDownloadManager.downloadEvent.invoke( Pair(click.data.id, VideoDownloadManager.DownloadActionType.Pause) ) } DOWNLOAD_ACTION_RESUME_DOWNLOAD -> { + Aria2cHelper.unpause(click.data.id.toLong()) + activity?.let { ctx -> if (VideoDownloadManager.downloadStatus.containsKey(id) && VideoDownloadManager.downloadStatus[id] == VideoDownloadManager.DownloadType.IsPaused) { VideoDownloadManager.downloadEvent.invoke( @@ -85,7 +90,7 @@ object DownloadButtonSetup { VideoDownloadManager.getDownloadFileInfoAndUpdateSettings( act, click.data.id - )?.fileLength + )?.fileLength ?: Aria2cHelper.getMetadata(click.data.id.toLong())?.downloadedLength ?: 0 if (length > 0) { showToast(act, R.string.delete, Toast.LENGTH_LONG) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildAdapter.kt index 5856a748..544a6985 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildAdapter.kt @@ -1,11 +1,15 @@ package com.lagradost.cloudstream3.ui.download +import android.text.format.Formatter import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.cardview.widget.CardView +import androidx.core.view.doOnAttach +import androidx.core.view.isVisible import androidx.core.widget.ContentLoadingProgressBar +import androidx.lifecycle.findViewTreeLifecycleOwner import androidx.recyclerview.widget.RecyclerView import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.ui.result.DownloadHelper.play @@ -15,6 +19,7 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.fixVisual import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIcons import com.lagradost.cloudstream3.utils.VideoDownloadHelper +import com.lagradost.fetchbutton.aria2c.DownloadListener import com.lagradost.fetchbutton.aria2c.DownloadStatusTell import com.lagradost.fetchbutton.ui.PieFetchButton import kotlinx.android.synthetic.main.download_child_episode.view.* @@ -93,15 +98,52 @@ class DownloadChildAdapter( title.isSelected = true // is needed for text repeating //extraInfo.text = card.currentBytes + fun updateText(downloadBytes: Long, totalBytes: Long) { + extraInfo?.apply { + text = + context.getString(R.string.download_size_format).format( + Formatter.formatShortFileSize(context, downloadBytes), + Formatter.formatShortFileSize(context, totalBytes) + ) + } + } + updateText(card.currentBytes, card.totalBytes) + downloadButton.apply { val play = R.string.play_episode//if (card.episode <= 0) R.string.play_movie_button else R.string.play_episode - setPersistentId(card.data.id.toLong()) + setPersistentId(d.id.toLong()) + doOnAttach { view -> + view.findViewTreeLifecycleOwner()?.let { life -> + DownloadListener.observe(life) { + gid?.let { realGId -> + val meta = DownloadListener.getInfo(realGId) + updateText(meta.downloadedLength, meta.totalLength) + } + } + } + } + + downloadButton.isVisible = when (downloadButton.currentStatus) { + null, DownloadStatusTell.Removed -> false + else -> true + } + downloadButton.setOnClickListener { val view = downloadButton + fun delete() { + // view.deleteAllFiles() + clickCallback.invoke( + DownloadClickEvent( + DOWNLOAD_ACTION_DELETE_FILE, + d + ) + ) + } + //if (view !is PieFetchButton) return@setOnClickListener when (view.currentStatus) { /*null, DownloadStatusTell.Removed -> { @@ -130,8 +172,8 @@ class DownloadChildAdapter( ) )*/ } - 2 -> play(card.data) - 3 -> view.deleteAllFiles() + 2 -> play(d) + 3 -> delete() } } } @@ -143,8 +185,8 @@ class DownloadChildAdapter( ) ) { when (itemId) { - 2 -> play(card.data) - 3 -> view.deleteAllFiles() + 2 -> play(d) + 3 -> delete() } } } @@ -158,8 +200,8 @@ class DownloadChildAdapter( ) { when (itemId) { 4 -> view.pauseDownload() - 2 -> play(card.data) - 3 -> view.deleteAllFiles() + 2 -> play(d) + 3 -> delete() } } } @@ -174,7 +216,13 @@ class DownloadChildAdapter( } } holder.setOnClickListener { - clickCallback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_PLAY_FILE, d)) + if (downloadButton.isVisible) { + downloadButton.play(d) + } else { + holder.setOnClickListener { + clickCallback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_PLAY_FILE, d)) + } + } } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt index 722d1ef5..b96d097e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt @@ -21,7 +21,7 @@ import kotlinx.coroutines.withContext class DownloadChildFragment : Fragment() { companion object { - fun newInstance(headerName: String, folder: String) : Bundle { + fun newInstance(headerName: String, folder: String): Bundle { return Bundle().apply { putString("folder", folder) putString("name", headerName) @@ -34,7 +34,11 @@ class DownloadChildFragment : Fragment() { super.onDestroyView() } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_child_downloads, container, false) } @@ -49,7 +53,7 @@ class DownloadChildFragment : Fragment() { ?: return@mapNotNull null VisualDownloadChildCached(info.fileLength, info.totalBytes, it) } - }.sortedBy { it.data.episode + (it.data.season?: 0)*100000 } + }.sortedBy { it.data.episode + (it.data.season ?: 0) * 100000 } if (eps.isEmpty()) { activity?.onBackPressed() return@main @@ -84,6 +88,13 @@ class DownloadChildFragment : Fragment() { ArrayList(), ) { click -> handleDownloadClick(activity, click) + /* println("HANDLE ACTION :${click.action}") + if (click.action == DOWNLOAD_ACTION_DELETE_FILE) { + val list = (download_child_list?.adapter as DownloadChildAdapter?)?.cardList + if (list != null) { + updateList(folder) + } + }*/ } downloadDeleteEventListener = { id: Int -> diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/DownloadHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/DownloadHelper.kt index 2d93d142..9cc1489c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/DownloadHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/DownloadHelper.kt @@ -1,65 +1,74 @@ package com.lagradost.cloudstream3.ui.result -import android.app.Activity -import android.net.Uri -import android.widget.Toast -import com.lagradost.cloudstream3.CommonActivity.showToast +import androidx.core.net.toUri import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_LONG_CLICK import com.lagradost.cloudstream3.ui.download.DownloadEpisodeClickEvent -import com.lagradost.cloudstream3.ui.download.VisualDownloadChildCached import com.lagradost.cloudstream3.ui.player.DownloadFileGenerator +import com.lagradost.cloudstream3.ui.player.GeneratorPlayer import com.lagradost.cloudstream3.utils.ExtractorUri +import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIcons import com.lagradost.cloudstream3.utils.VideoDownloadHelper import com.lagradost.fetchbutton.aria2c.Aria2Starter import com.lagradost.fetchbutton.aria2c.DownloadStatusTell import com.lagradost.fetchbutton.ui.PieFetchButton +import java.io.File object DownloadHelper { fun PieFetchButton.play(card: VideoDownloadHelper.DownloadEpisodeCached) { val files = this.getVideos() - DownloadFileGenerator( - files.map { path -> - ExtractorUri( - uri = Uri.parse(path), + // fucked af, but who cares + Aria2Starter.saveActivity.get()?.navigate( + R.id.global_to_navigation_player, GeneratorPlayer.newInstance(DownloadFileGenerator( + files.map { path -> + val file = File(path) - id = card.id, - parentId = card.parentId, - name = context.getString(R.string.downloaded_file), //click.data.name ?: keyInfo.displayName - season = card.season, - episode = card.episode + ExtractorUri( + uri = file.toUri(), - //basePath = keyInfo.basePath, - //displayName = keyInfo.displayName, - //relativePath = keyInfo.relativePath, - ) - } - ) + id = card.id, + parentId = card.parentId, + name = context.getString(R.string.downloaded_file), //click.data.name ?: keyInfo.displayName + season = card.season, + episode = card.episode, + + basePath = file.path, + displayName = file.name + //displayName = keyInfo.displayName, + //relativePath = keyInfo.relativePath, + ) + } + ))) } fun PieFetchButton.play(card: ResultEpisode) { val files = this.getVideos() - DownloadFileGenerator( - files.map { path -> - ExtractorUri( - uri = Uri.parse(path), + // fucked af, but who cares + Aria2Starter.saveActivity.get()?.navigate( - id = card.id, - parentId = card.parentId, - name = context.getString(R.string.downloaded_file), //click.data.name ?: keyInfo.displayName - season = card.season, - episode = card.episode, - headerName = card.headerName, - tvType = card.tvType, + R.id.global_to_navigation_player, GeneratorPlayer.newInstance(DownloadFileGenerator( + files.map { path -> + val file = File(path) - //basePath = keyInfo.basePath, - //displayName = keyInfo.displayName, - //relativePath = keyInfo.relativePath, - ) - } - ) + ExtractorUri( + uri = file.toUri(), + + id = card.id, + parentId = card.parentId, + name = context.getString(R.string.downloaded_file), //click.data.name ?: keyInfo.displayName + season = card.season, + episode = card.episode, + headerName = card.headerName, + tvType = card.tvType, + + basePath = file.path, + displayName = file.name, + //relativePath = keyInfo.relativePath, + ) + } + ))) } fun PieFetchButton.setUp( @@ -70,7 +79,12 @@ object DownloadHelper { val play = if (card.episode <= 0) R.string.play_movie_button else R.string.play_episode setOnLongClickListener { //Aria2Starter.saveActivity.get() - downloadClickCallback.invoke(DownloadEpisodeClickEvent(DOWNLOAD_ACTION_LONG_CLICK, card)) + downloadClickCallback.invoke( + DownloadEpisodeClickEvent( + DOWNLOAD_ACTION_LONG_CLICK, + card + ) + ) //showToast(it.context as? Activity, R.string.download, Toast.LENGTH_SHORT) return@setOnLongClickListener true } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt index a5917a9f..a47c653c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt @@ -16,6 +16,8 @@ import androidx.lifecycle.viewModelScope import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.APIHolder.getId import com.lagradost.cloudstream3.APIHolder.unixTime +import com.lagradost.cloudstream3.AcraApplication.Companion.getKey +import com.lagradost.cloudstream3.AcraApplication.Companion.setKey import com.lagradost.cloudstream3.CommonActivity.getCastSession import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer @@ -55,8 +57,6 @@ import com.lagradost.cloudstream3.utils.UIHelper.checkWrite import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.requestRW -import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath -import com.lagradost.cloudstream3.utils.VideoDownloadManager.gotoDir import com.lagradost.fetchbutton.NotificationMetaData import com.lagradost.fetchbutton.aria2c.Aria2Starter import com.lagradost.fetchbutton.aria2c.UriRequest @@ -604,10 +604,12 @@ class ResultViewModel2 : ViewModel() { currentType ) - val topFolder = VideoDownloadManager.getDownloadDir()?.filePath ?: throw RuntimeException("FUCK YOU")//AcraApplication.context?.getBasePath()?.first //?.second?.also { println("URIIIIII: $it") } ?: throw RuntimeException("FUCK YOU") - //?: VideoDownloadManager.getDownloadDir()?.filePath ?: return null + val topFolder = VideoDownloadManager.getDownloadDir()?.filePath + ?: throw RuntimeException("FUCK YOU")//AcraApplication.context?.getBasePath()?.first //?.second?.also { println("URIIIIII: $it") } ?: throw RuntimeException("FUCK YOU") + //?: VideoDownloadManager.getDownloadDir()?.filePath ?: return null - val folder = topFolder//topFolder?.gotoDir(getFolder(currentType, currentHeaderName).replace(".", ""), true)?.uri?.toString() ?: throw RuntimeException("FUCK YOU") + val folder = + topFolder//topFolder?.gotoDir(getFolder(currentType, currentHeaderName).replace(".", ""), true)?.uri?.toString() ?: throw RuntimeException("FUCK YOU") //val folder = // topFolder + "/" + getFolder(currentType, currentHeaderName).replace(".", "") //val src = "$DOWNLOAD_NAVIGATE_TO/$parentId" // url ?: return@let @@ -670,12 +672,13 @@ class ResultViewModel2 : ViewModel() { val linkRequests = links.filter { link -> !link.isM3u8 }.map { link -> newUriRequest( episode.id.toLong(), link.url, - VideoDownloadManager.getDisplayName( - VideoDownloadManager.getFileName( - AcraApplication.context ?: return null, - meta - ), "mp4" - ), null, + getFolder(currentType, currentHeaderName) + File.pathSeparator + + VideoDownloadManager.getDisplayName( + VideoDownloadManager.getFileName( + AcraApplication.context ?: return null, + meta + ), "mp4" + ), null, // we use the dir set at start link.headers, USER_AGENT, notificationMetaData = notification?.copy( linkName = "${link.name} ${ @@ -1107,6 +1110,7 @@ class ResultViewModel2 : ViewModel() { Aria2Starter.download(sub) } val linksFound = req.links.isNotEmpty() + setKey(DOWNLOAD_COUNT_KEY, (getKey(DOWNLOAD_COUNT_KEY) ?: 0) + 1) mainThread { showToast( activity, diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt index c03af2aa..498b68e9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt @@ -29,12 +29,12 @@ import com.lagradost.cloudstream3.AcraApplication.Companion.setKey import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.normalSafeApiCall import com.lagradost.cloudstream3.services.VideoDownloadService +import com.lagradost.cloudstream3.ui.download.Aria2cHelper import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.removeKey import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute -import com.lagradost.fetchbutton.aria2c.Metadata import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking @@ -1487,17 +1487,17 @@ object VideoDownloadManager { fun getDownloadFileInfoAndUpdateSettings(context: Context, id: Int): DownloadedFileInfoResult? { val res = getDownloadFileInfo(context, id) if (res == null) { - AcraApplication.getKey( - CommonActivity.KEY_DOWNLOAD_INFO_METADATA, - id.toString() - )?.let { data -> - if (data.totalLength > 1000L) + Aria2cHelper.getMetadata(id.toLong())?.let { data -> + if (Aria2cHelper.downloadExist(data)) { return DownloadedFileInfoResult( - data.downloadedLength, data.totalLength, + data.downloadedLength, + data.totalLength, Uri.EMPTY ) + } } + Aria2cHelper.deleteId(id.toLong()) context.removeKey(KEY_DOWNLOAD_INFO, id.toString()) } return res @@ -1629,15 +1629,15 @@ object VideoDownloadManager { } } - /*fun isMyServiceRunning(context: Context, serviceClass: Class<*>): Boolean { - val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager? - for (service in manager!!.getRunningServices(Int.MAX_VALUE)) { - if (serviceClass.name == service.service.className) { - return true - } +/*fun isMyServiceRunning(context: Context, serviceClass: Class<*>): Boolean { + val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager? + for (service in manager!!.getRunningServices(Int.MAX_VALUE)) { + if (serviceClass.name == service.service.className) { + return true } - return false - }*/ + } + return false +}*/ fun downloadEpisode( context: Context?, diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index d745c7a1..c9a61b37 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -22,6 +22,10 @@ #FFF #000 + #FFF + #000 + + #3d50fa #121213 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index bdf2ccd1..6ff90a6b 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -55,6 +55,8 @@ @color/colorPrimary @color/colorPrimaryDark + @color/whiteText + @color/colorAccent @color/textColor @color/grayTextColor @@ -105,7 +107,7 @@ @color/colorPrimary @color/colorPrimaryDark @color/colorAccent - @color/colorAccent + @color/whiteText @color/colorAccent @@ -115,7 +117,7 @@ @color/colorPrimaryBlue #4855A2 #5A6BCB - #5A6BCB + @color/whiteText @color/colorPrimaryBlue @@ -125,7 +127,7 @@ @color/colorPrimaryPurple #4704A3 #7125DB - #7125DB + @color/whiteText @color/colorPrimaryPurple @@ -134,7 +136,7 @@ @color/colorPrimaryGreen #007363 #39C1AE - #39C1AE + @color/blackText @color/colorPrimaryGreen @@ -143,7 +145,7 @@ @color/colorPrimaryGreenApple #319B5A #51C57E - #51C57E + @color/blackText @color/colorPrimaryGreenApple @@ -152,7 +154,7 @@ @color/colorPrimaryRed #B62B2B @color/colorPrimaryRed - @color/colorPrimaryRed + @color/whiteText @color/colorPrimaryRed @@ -162,7 +164,7 @@ @color/colorPrimaryBanana #9B7D31 #C5B251 - #C5A851 + @color/blackText @color/colorPrimaryBanana @@ -171,7 +173,7 @@ @color/colorPrimaryParty #C1495B #FD798C - #BF5968 + @color/blackText @color/colorPrimaryParty @@ -180,7 +182,7 @@ @color/colorPrimaryPink #DD1280 #FF4DAE - #DD1280 + @color/blackText @color/colorPrimaryPink @@ -189,7 +191,7 @@ @color/colorPrimaryCarnationPink #83366f #BD5DA5 - #BD5DA5 + @color/blackText @color/colorPrimaryCarnationPink @@ -199,7 +201,7 @@ @color/colorPrimaryMaroon #370C0C #451010 - #451010 + @color/whiteText @color/colorPrimaryMaroon @@ -209,7 +211,7 @@ @color/colorPrimaryDarkGreen #003d00 #004500 - #004500 + @color/whiteText @color/colorPrimaryDarkGreen @@ -219,7 +221,7 @@ @color/colorPrimaryNavyBlue #000073 #000080 - #000080 + @color/whiteText @color/colorPrimaryNavyBlue @@ -229,7 +231,7 @@ @color/colorPrimaryGrey #484848 #515151 - #515151 + @color/whiteText @color/colorPrimaryGrey @@ -239,7 +241,7 @@ @color/colorPrimaryWhite #CCCCCC #FFFFFF - #FFFFFF + @color/blackText @color/colorPrimaryWhite @@ -249,7 +251,7 @@ @color/colorPrimaryBrown #582700 #622C00 - #622C00 + @color/whiteText @color/colorPrimaryBrown