mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Also support bookmarks
This commit is contained in:
parent
67c1ac3da4
commit
e1f833ad3a
6 changed files with 64 additions and 29 deletions
|
@ -1306,7 +1306,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
this@MainActivity.getString(R.string.action_add_to_bookmarks),
|
this@MainActivity.getString(R.string.action_add_to_bookmarks),
|
||||||
showApply = false,
|
showApply = false,
|
||||||
{}) {
|
{}) {
|
||||||
viewModel.updateWatchStatus(WatchType.values()[it])
|
viewModel.updateWatchStatus(WatchType.values()[it], this@MainActivity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -974,7 +974,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
|
||||||
fab.context.getString(R.string.action_add_to_bookmarks),
|
fab.context.getString(R.string.action_add_to_bookmarks),
|
||||||
showApply = false,
|
showApply = false,
|
||||||
{}) {
|
{}) {
|
||||||
viewModel.updateWatchStatus(WatchType.values()[it])
|
viewModel.updateWatchStatus(WatchType.values()[it], context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -531,7 +531,7 @@ class ResultFragmentTv : Fragment() {
|
||||||
view.context.getString(R.string.action_add_to_bookmarks),
|
view.context.getString(R.string.action_add_to_bookmarks),
|
||||||
showApply = false,
|
showApply = false,
|
||||||
{}) {
|
{}) {
|
||||||
viewModel.updateWatchStatus(WatchType.values()[it])
|
viewModel.updateWatchStatus(WatchType.values()[it], context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,11 @@ import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.ioWork
|
import com.lagradost.cloudstream3.utils.Coroutines.ioWork
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.ioWorkSafe
|
import com.lagradost.cloudstream3.utils.Coroutines.ioWorkSafe
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.deleteBookmarkedData
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAllBookmarkedDataByWatchType
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAllFavorites
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAllFavorites
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAllSubscriptions
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAllSubscriptions
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getBookmarkedData
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getDub
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getDub
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getFavoritesData
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getFavoritesData
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getResultEpisode
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getResultEpisode
|
||||||
|
@ -64,17 +67,20 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.getSubscribedData
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.removeFavoritesData
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.removeFavoritesData
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.removeSubscribedData
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.removeSubscribedData
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setBookmarkedData
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setDub
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setDub
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setFavoritesData
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setFavoritesData
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultEpisode
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultEpisode
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultSeason
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultSeason
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.updateSubscribedData
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
interface AlertDialogResponseCallback {
|
interface AlertDialogResponseCallback {
|
||||||
fun onUserResponse(response: Boolean)
|
fun onUserResponse(action: Boolean)
|
||||||
|
|
||||||
fun onUserResponseReplace(duplicateId: Int)
|
fun onUserResponseReplace(duplicateId: Int)
|
||||||
}
|
}
|
||||||
|
@ -458,10 +464,10 @@ class ResultViewModel2 : ViewModel() {
|
||||||
|
|
||||||
val currentWatchType = getResultWatchState(currentId)
|
val currentWatchType = getResultWatchState(currentId)
|
||||||
|
|
||||||
DataStoreHelper.setResultWatchState(currentId, status.internalId)
|
setResultWatchState(currentId, status.internalId)
|
||||||
val current = DataStoreHelper.getBookmarkedData(currentId)
|
val current = getBookmarkedData(currentId)
|
||||||
val currentTime = System.currentTimeMillis()
|
val currentTime = System.currentTimeMillis()
|
||||||
DataStoreHelper.setBookmarkedData(
|
setBookmarkedData(
|
||||||
currentId,
|
currentId,
|
||||||
DataStoreHelper.BookmarkedData(
|
DataStoreHelper.BookmarkedData(
|
||||||
current?.bookmarkedTime ?: currentTime,
|
current?.bookmarkedTime ?: currentTime,
|
||||||
|
@ -834,10 +840,32 @@ class ResultViewModel2 : ViewModel() {
|
||||||
val selectPopup: LiveData<SelectPopup?> = _selectPopup
|
val selectPopup: LiveData<SelectPopup?> = _selectPopup
|
||||||
|
|
||||||
|
|
||||||
fun updateWatchStatus(status: WatchType) {
|
fun updateWatchStatus(status: WatchType, context: Context?) {
|
||||||
updateWatchStatus(currentResponse ?: return, status)
|
val currentStatus = _watchStatus.value ?: return
|
||||||
|
if (status == currentStatus) return
|
||||||
|
|
||||||
|
val response = currentResponse ?: return
|
||||||
|
|
||||||
|
checkAndWarnDuplicates(
|
||||||
|
context,
|
||||||
|
R.string.bookmarks_duplicate_title,
|
||||||
|
R.string.bookmarks_duplicate_message,
|
||||||
|
response.name,
|
||||||
|
getAllBookmarkedDataByWatchType()[status] ?: emptyList(),
|
||||||
|
object : AlertDialogResponseCallback {
|
||||||
|
override fun onUserResponseReplace(duplicateId: Int) {
|
||||||
|
deleteBookmarkedData(duplicateId)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onUserResponse(action: Boolean) {
|
||||||
|
if (!action) return
|
||||||
|
|
||||||
|
updateWatchStatus(response, status)
|
||||||
_watchStatus.postValue(status)
|
_watchStatus.postValue(status)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun startChromecast(
|
private fun startChromecast(
|
||||||
activity: Activity?,
|
activity: Activity?,
|
||||||
|
@ -863,13 +891,13 @@ class ResultViewModel2 : ViewModel() {
|
||||||
if (isSubscribed) {
|
if (isSubscribed) {
|
||||||
removeSubscribedData(currentId)
|
removeSubscribedData(currentId)
|
||||||
|
|
||||||
_subscribeStatus.postValue(!isSubscribed)
|
_subscribeStatus.postValue(false)
|
||||||
return !isSubscribed
|
return false
|
||||||
} else {
|
} else {
|
||||||
checkAndWarnDuplicates(
|
checkAndWarnDuplicates(
|
||||||
context,
|
context,
|
||||||
R.string.subscription_duplicate_title,
|
R.string.subscriptions_duplicate_title,
|
||||||
R.string.subscription_duplicate_message,
|
R.string.subscriptions_duplicate_message,
|
||||||
response.name,
|
response.name,
|
||||||
getAllSubscriptions(),
|
getAllSubscriptions(),
|
||||||
object : AlertDialogResponseCallback {
|
object : AlertDialogResponseCallback {
|
||||||
|
@ -878,10 +906,7 @@ class ResultViewModel2 : ViewModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUserResponse(action: Boolean) {
|
override fun onUserResponse(action: Boolean) {
|
||||||
if (!action) {
|
if (!action) return
|
||||||
_subscribeStatus.postValue(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val current = getSubscribedData(currentId)
|
val current = getSubscribedData(currentId)
|
||||||
|
|
||||||
|
@ -928,8 +953,8 @@ class ResultViewModel2 : ViewModel() {
|
||||||
if (isFavorite) {
|
if (isFavorite) {
|
||||||
removeFavoritesData(currentId)
|
removeFavoritesData(currentId)
|
||||||
|
|
||||||
_favoriteStatus.postValue(!isFavorite)
|
_favoriteStatus.postValue(false)
|
||||||
return !isFavorite
|
return false
|
||||||
} else {
|
} else {
|
||||||
checkAndWarnDuplicates(
|
checkAndWarnDuplicates(
|
||||||
context,
|
context,
|
||||||
|
@ -943,10 +968,7 @@ class ResultViewModel2 : ViewModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUserResponse(action: Boolean) {
|
override fun onUserResponse(action: Boolean) {
|
||||||
if (!action) {
|
if (!action) return
|
||||||
_favoriteStatus.postValue(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val current = getFavoritesData(currentId)
|
val current = getFavoritesData(currentId)
|
||||||
|
|
||||||
|
@ -1895,8 +1917,8 @@ class ResultViewModel2 : ViewModel() {
|
||||||
private fun postSubscription(loadResponse: LoadResponse) {
|
private fun postSubscription(loadResponse: LoadResponse) {
|
||||||
if (loadResponse.isEpisodeBased()) {
|
if (loadResponse.isEpisodeBased()) {
|
||||||
val id = loadResponse.getId()
|
val id = loadResponse.getId()
|
||||||
val data = DataStoreHelper.getSubscribedData(id)
|
val data = getSubscribedData(id)
|
||||||
DataStoreHelper.updateSubscribedData(id, data, loadResponse as? EpisodeResponse)
|
updateSubscribedData(id, data, loadResponse as? EpisodeResponse)
|
||||||
val isSubscribed = data != null
|
val isSubscribed = data != null
|
||||||
_subscribeStatus.postValue(isSubscribed)
|
_subscribeStatus.postValue(isSubscribed)
|
||||||
}
|
}
|
||||||
|
@ -2274,7 +2296,7 @@ class ResultViewModel2 : ViewModel() {
|
||||||
postResume()
|
postResume()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun postResume() {
|
private fun postResume() {
|
||||||
_resumeWatching.postValue(resume())
|
_resumeWatching.postValue(resume())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -583,6 +583,17 @@ object DataStoreHelper {
|
||||||
return getKey("$currentAccount/$RESULT_WATCH_STATE_DATA", id.toString())
|
return getKey("$currentAccount/$RESULT_WATCH_STATE_DATA", id.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getAllBookmarkedDataByWatchType(): Map<WatchType, List<BookmarkedData>> {
|
||||||
|
val allBookmarkedData: List<BookmarkedData> =
|
||||||
|
getKeys("$currentAccount/$RESULT_WATCH_STATE_DATA")?.mapNotNull {
|
||||||
|
getKey(it)
|
||||||
|
} ?: emptyList()
|
||||||
|
|
||||||
|
return allBookmarkedData
|
||||||
|
.groupBy { getResultWatchState(it.id ?: return emptyMap()) }
|
||||||
|
.mapValues { it.value }
|
||||||
|
}
|
||||||
|
|
||||||
fun getAllSubscriptions(): List<SubscribedData> {
|
fun getAllSubscriptions(): List<SubscribedData> {
|
||||||
return getKeys("$currentAccount/$RESULT_SUBSCRIBED_STATE_DATA")?.mapNotNull {
|
return getKeys("$currentAccount/$RESULT_SUBSCRIBED_STATE_DATA")?.mapNotNull {
|
||||||
getKey(it)
|
getKey(it)
|
||||||
|
|
|
@ -695,10 +695,12 @@
|
||||||
<string name="favorite_removed">%s removed from favorites</string>
|
<string name="favorite_removed">%s removed from favorites</string>
|
||||||
<string name="action_add_to_favorites">Add to favorites</string>
|
<string name="action_add_to_favorites">Add to favorites</string>
|
||||||
<string name="action_remove_from_favorites">Remove from favorites</string>
|
<string name="action_remove_from_favorites">Remove from favorites</string>
|
||||||
<string name="subscription_duplicate_title">Possible Duplicate Subscription</string>
|
<string name="subscriptions_duplicate_title">Possible Duplicate Subscription</string>
|
||||||
<string name="subscription_duplicate_message">A possible duplicate with the same name already exists in your subscrptions.</string>
|
<string name="subscriptions_duplicate_message">A possible duplicate with the same name already exists in your subscrptions.</string>
|
||||||
<string name="favorites_duplicate_title">Possible Duplicate Found</string>
|
<string name="favorites_duplicate_title">Possible Duplicate Found</string>
|
||||||
<string name="favorites_duplicate_message">A possible duplicate with the same name already exists in your favorites.</string>
|
<string name="favorites_duplicate_message">A possible duplicate with the same name already exists in your favorites.</string>
|
||||||
<string name="add_anyway">Add Anyway</string>
|
<string name="add_anyway">Add Anyway</string>
|
||||||
<string name="replace">Replace</string>
|
<string name="replace">Replace</string>
|
||||||
|
<string name="bookmarks_duplicate_title">Possible Duplicate Found</string>
|
||||||
|
<string name="bookmarks_duplicate_message">A possible duplicate with the same name and watch status already exists in your library.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue