diff --git a/app/build.gradle b/app/build.gradle index bbb5d217..0d333882 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,8 +35,8 @@ android { minSdkVersion 21 targetSdkVersion 31 - versionCode 35 - versionName "2.4.3" + versionCode 36 + versionName "2.4.4" resValue "string", "app_version", "${defaultConfig.versionName}${versionNameSuffix ?: ""}" diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt index 878970d9..74903cf4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt @@ -53,8 +53,9 @@ import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes import com.lagradost.cloudstream3.utils.UIHelper.setImage import com.lagradost.cloudstream3.widget.CenterZoomLayoutManager import kotlinx.android.synthetic.main.fragment_home.* +import java.util.* -const val HOME_BOOKMARK_VALUE = "home_bookmarked_last" +const val HOME_BOOKMARK_VALUE_LIST = "home_bookmarked_last_list" class HomeFragment : Fragment() { companion object { @@ -164,7 +165,11 @@ class HomeFragment : Fragment() { private fun reloadStored() { context?.let { ctx -> homeViewModel.loadResumeWatching(ctx) - homeViewModel.loadStoredData(ctx, WatchType.fromInternalId(ctx.getKey(HOME_BOOKMARK_VALUE))) + val list = EnumSet.noneOf(WatchType::class.java) + ctx.getKey(HOME_BOOKMARK_VALUE_LIST)?.map { WatchType.fromInternalId(it) }?.let { + list.addAll(it) + } + homeViewModel.loadStoredData(ctx, list) } } @@ -301,9 +306,46 @@ class HomeFragment : Fragment() { activity?.loadHomepageList(item) }) + val toggleList = listOf( + Pair(home_type_watching_btt, WatchType.WATCHING), + Pair(home_type_completed_btt, WatchType.COMPLETED), + Pair(home_type_dropped_btt, WatchType.DROPPED), + Pair(home_type_on_hold_btt, WatchType.ONHOLD), + Pair(home_plan_to_watch_btt, WatchType.PLANTOWATCH), + ) + + for (item in toggleList) { + val watch = item.second + item.first?.setOnClickListener { itemView -> + val list = EnumSet.noneOf(WatchType::class.java) + itemView.context.getKey(HOME_BOOKMARK_VALUE_LIST)?.map { WatchType.fromInternalId(it) }?.let { + list.addAll(it) + } + + if (list.contains(watch)) { + list.remove(watch) + } else { + list.add(watch) + } + homeViewModel.loadStoredData(itemView.context, list) + } + } + observe(homeViewModel.availableWatchStatusTypes) { availableWatchStatusTypes -> - context?.setKey(HOME_BOOKMARK_VALUE, availableWatchStatusTypes.first.internalId) - home_bookmark_select?.setOnClickListener { + context?.setKey( + HOME_BOOKMARK_VALUE_LIST, + availableWatchStatusTypes.first.map { it.internalId }.toIntArray() + ) + + for (item in toggleList) { + val watch = item.second + item.first?.apply { + isVisible = availableWatchStatusTypes.second.contains(watch) + isSelected = availableWatchStatusTypes.first.contains(watch) + } + } + + /*home_bookmark_select?.setOnClickListener { it.popupMenuNoIcons(availableWatchStatusTypes.second.map { type -> Pair( type.internalId, @@ -313,18 +355,20 @@ class HomeFragment : Fragment() { homeViewModel.loadStoredData(it.context, WatchType.fromInternalId(this.itemId)) } } - home_bookmarked_parent_item_title?.text = getString(availableWatchStatusTypes.first.stringRes) + home_bookmarked_parent_item_title?.text = getString(availableWatchStatusTypes.first.stringRes)*/ } - observe(homeViewModel.bookmarks) { bookmarks -> - home_bookmarked_holder.isVisible = bookmarks.isNotEmpty() + observe(homeViewModel.bookmarks) { pair -> + home_bookmarked_holder.isVisible = pair.first + + val bookmarks = pair.second (home_bookmarked_child_recyclerview?.adapter as HomeChildItemAdapter?)?.cardList = bookmarks home_bookmarked_child_recyclerview?.adapter?.notifyDataSetChanged() - home_bookmarked_child_more_info.setOnClickListener { + home_bookmarked_child_more_info?.setOnClickListener { activity?.loadHomepageList( HomePageList( - home_bookmarked_parent_item_title?.text?.toString() ?: getString(R.string.error_bookmarks_text), + getString(R.string.error_bookmarks_text), //home_bookmarked_parent_item_title?.text?.toString() ?: getString(R.string.error_bookmarks_text), bookmarks ) ) @@ -444,8 +488,8 @@ class HomeFragment : Fragment() { home_change_api_loading?.isFocusableInTouchMode = true home_change_api?.isFocusable = true home_change_api?.isFocusableInTouchMode = true - home_bookmark_select?.isFocusable = true - home_bookmark_select?.isFocusableInTouchMode = true + // home_bookmark_select?.isFocusable = true + // home_bookmark_select?.isFocusableInTouchMode = true } for (syncApi in OAuth2API.OAuth2Apis) { @@ -458,7 +502,5 @@ class HomeFragment : Fragment() { } } } - - } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt index df367e8a..10435b59 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt @@ -29,6 +29,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import java.util.* class HomeViewModel : ViewModel() { private var repo: APIRepository? = null @@ -46,10 +47,10 @@ class HomeViewModel : ViewModel() { return APIRepository(apis.first { it.hasMainPage }) } - private val _availableWatchStatusTypes = MutableLiveData>>() - val availableWatchStatusTypes: LiveData>> = _availableWatchStatusTypes - private val _bookmarks = MutableLiveData>() - val bookmarks: LiveData> = _bookmarks + private val _availableWatchStatusTypes = MutableLiveData, EnumSet>>() + val availableWatchStatusTypes: LiveData, EnumSet>> = _availableWatchStatusTypes + private val _bookmarks = MutableLiveData>>() + val bookmarks: LiveData>> = _bookmarks private val _resumeWatching = MutableLiveData>() val resumeWatching: LiveData> = _resumeWatching @@ -89,14 +90,14 @@ class HomeViewModel : ViewModel() { _resumeWatching.postValue(resumeWatchingResult) } - fun loadStoredData(context: Context, preferredWatchStatus: WatchType?) = viewModelScope.launch { + fun loadStoredData(context: Context, preferredWatchStatus: EnumSet?) = viewModelScope.launch { val watchStatusIds = withContext(Dispatchers.IO) { context.getAllWatchStateIds().map { id -> Pair(id, context.getResultWatchState(id)) } }.distinctBy { it.first } val length = WatchType.values().size - val currentWatchTypes = HashSet() + val currentWatchTypes = EnumSet.noneOf(WatchType::class.java) for (watch in watchStatusIds) { currentWatchTypes.add(watch.second) @@ -108,25 +109,26 @@ class HomeViewModel : ViewModel() { currentWatchTypes.remove(WatchType.NONE) if (currentWatchTypes.size <= 0) { - _bookmarks.postValue(ArrayList()) + _bookmarks.postValue(Pair(false, ArrayList())) return@launch } - val watchPrefNotNull = preferredWatchStatus ?: currentWatchTypes.first() - val watchStatus = - if (currentWatchTypes.contains(watchPrefNotNull)) watchPrefNotNull else currentWatchTypes.first() + val watchPrefNotNull = preferredWatchStatus ?: EnumSet.of(currentWatchTypes.first()) + //if (currentWatchTypes.any { watchPrefNotNull.contains(it) }) watchPrefNotNull else listOf(currentWatchTypes.first()) + _availableWatchStatusTypes.postValue( Pair( - watchStatus, - currentWatchTypes.sortedBy { it.internalId }.toList() + watchPrefNotNull, + currentWatchTypes, ) ) + val list = withContext(Dispatchers.IO) { - watchStatusIds.filter { it.second == watchStatus } + watchStatusIds.filter { watchPrefNotNull.contains(it.second) } .mapNotNull { context.getBookmarkedData(it.first) } .sortedBy { -it.latestUpdatedTime } } - _bookmarks.postValue(list) + _bookmarks.postValue(Pair(true,list)) } private var onGoingLoad: Job? = null diff --git a/app/src/main/res/color/toggle_button.xml b/app/src/main/res/color/toggle_button.xml new file mode 100644 index 00000000..d156c91d --- /dev/null +++ b/app/src/main/res/color/toggle_button.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/color/toggle_button_outline.xml b/app/src/main/res/color/toggle_button_outline.xml new file mode 100644 index 00000000..0599bb36 --- /dev/null +++ b/app/src/main/res/color/toggle_button_outline.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/color/toggle_button_text.xml b/app/src/main/res/color/toggle_button_text.xml new file mode 100644 index 00000000..9adb0159 --- /dev/null +++ b/app/src/main/res/color/toggle_button_text.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 1df4d34f..030274d8 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -332,28 +332,68 @@ android:foreground="?android:attr/selectableItemBackgroundBorderless" android:id="@+id/home_bookmarked_child_more_info" - android:padding="12dp" + android:paddingTop="5dp" + android:paddingBottom="5dp" + android:paddingStart="12dp" + android:paddingEnd="12dp" android:layout_width="match_parent" android:layout_height="wrap_content"> - + + + - - + android:id="@+id/home_plan_to_watch_btt" + android:text="@string/type_plan_to_watch" + style="@style/RoundedSelectableButton"/> + + + + + ?attr/textColor ?attr/textColor + +