mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-04-20 03:24:50 +00:00
Toast on cancel creation, default subgroup creator image, fix subgroup cache load
This commit is contained in:
parent
0d80424799
commit
2f66f124aa
3 changed files with 58 additions and 9 deletions
|
@ -25,6 +25,7 @@ import com.futo.platformplayer.UIDialogs
|
|||
import com.futo.platformplayer.UISlideOverlays
|
||||
import com.futo.platformplayer.api.media.models.channels.IPlatformChannel
|
||||
import com.futo.platformplayer.dp
|
||||
import com.futo.platformplayer.models.ImageVariable
|
||||
import com.futo.platformplayer.models.Subscription
|
||||
import com.futo.platformplayer.models.SubscriptionGroup
|
||||
import com.futo.platformplayer.states.StateSubscriptionGroups
|
||||
|
@ -64,6 +65,11 @@ class SubscriptionGroupFragment : MainFragment() {
|
|||
return view;
|
||||
}
|
||||
|
||||
override fun onHide() {
|
||||
super.onHide();
|
||||
_view?.onHide();
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SourcesFragment";
|
||||
fun newInstance() = SubscriptionGroupFragment().apply {}
|
||||
|
@ -97,6 +103,8 @@ class SubscriptionGroupFragment : MainFragment() {
|
|||
|
||||
private var _group: SubscriptionGroup? = null;
|
||||
|
||||
private var _didDelete: Boolean = false;
|
||||
|
||||
constructor(context: Context, fragment: SubscriptionGroupFragment): super(context) {
|
||||
inflate(context, R.layout.fragment_subscriptions_group, this);
|
||||
_fragment = fragment;
|
||||
|
@ -137,6 +145,7 @@ class SubscriptionGroupFragment : MainFragment() {
|
|||
UIDialogs.Action("Delete", {
|
||||
_group?.let {
|
||||
it.urls.remove(channel.url);
|
||||
save();
|
||||
reloadCreators(it);
|
||||
}
|
||||
}, UIDialogs.ActionStyle.DANGEROUS))
|
||||
|
@ -178,6 +187,7 @@ class SubscriptionGroupFragment : MainFragment() {
|
|||
UIDialogs.Action("Cancel", {}),
|
||||
UIDialogs.Action("Delete", {
|
||||
StateSubscriptionGroups.instance.deleteSubscriptionGroup(g.id);
|
||||
_didDelete = true;
|
||||
fragment.close(true);
|
||||
}, UIDialogs.ActionStyle.DANGEROUS))
|
||||
};
|
||||
|
@ -246,6 +256,18 @@ class SubscriptionGroupFragment : MainFragment() {
|
|||
_overlay.animate().alpha(1f).setDuration(300).start();
|
||||
overlay.onSelected.subscribe {
|
||||
_group?.let { g ->
|
||||
if(g.urls.isEmpty() && g.image == null) {
|
||||
//Obtain image
|
||||
for(sub in it) {
|
||||
val sub = StateSubscriptions.instance.getSubscription(sub);
|
||||
if(sub != null && sub.channel.thumbnail != null) {
|
||||
g.image = ImageVariable.fromUrl(sub.channel.thumbnail!!);
|
||||
g.image?.setImageView(_imageGroup);
|
||||
g.image?.setImageView(_imageGroupBackground);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(url in it) {
|
||||
if(!g.urls.contains(url))
|
||||
g.urls.add(url);
|
||||
|
@ -262,6 +284,7 @@ class SubscriptionGroupFragment : MainFragment() {
|
|||
|
||||
|
||||
fun setGroup(group: SubscriptionGroup?) {
|
||||
_didDelete = false;
|
||||
_group = group;
|
||||
_textGroupTitle.text = group?.name;
|
||||
|
||||
|
@ -278,6 +301,12 @@ class SubscriptionGroupFragment : MainFragment() {
|
|||
reloadCreators(group);
|
||||
}
|
||||
|
||||
fun onHide() {
|
||||
if(!_didDelete && _group != null && StateSubscriptionGroups.instance.getSubscriptionGroup(_group!!.id) === null) {
|
||||
UIDialogs.toast(context, "Group creation cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun reloadCreators(group: SubscriptionGroup?) {
|
||||
_enabledCreators.clear();
|
||||
|
|
|
@ -17,7 +17,6 @@ import com.futo.platformplayer.api.media.platforms.js.JSClient
|
|||
import com.futo.platformplayer.api.media.structures.IPager
|
||||
import com.futo.platformplayer.constructs.TaskHandler
|
||||
import com.futo.platformplayer.engine.exceptions.PluginException
|
||||
import com.futo.platformplayer.engine.exceptions.ScriptCaptchaRequiredException
|
||||
import com.futo.platformplayer.exceptions.ChannelException
|
||||
import com.futo.platformplayer.exceptions.RateLimitException
|
||||
import com.futo.platformplayer.logging.Logger
|
||||
|
@ -53,6 +52,7 @@ class SubscriptionsFeedFragment : MainFragment() {
|
|||
override val hasBottomBar: Boolean get() = true;
|
||||
|
||||
private var _view: SubscriptionsFeedView? = null;
|
||||
private var _group: SubscriptionGroup? = null;
|
||||
private var _cachedRecyclerData: FeedView.RecyclerData<InsertedViewAdapterWithLoader<ContentPreviewViewHolder>, LinearLayoutManager, IPager<IPlatformContent>, IPlatformContent, IPlatformContent, InsertedViewHolder<ContentPreviewViewHolder>>? = null;
|
||||
|
||||
override fun onShownWithView(parameter: Any?, isBack: Boolean) {
|
||||
|
@ -73,6 +73,8 @@ class SubscriptionsFeedFragment : MainFragment() {
|
|||
override fun onCreateMainView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
val view = SubscriptionsFeedView(this, inflater, _cachedRecyclerData);
|
||||
_view = view;
|
||||
if(_group != null)
|
||||
view.selectSubgroup(_group);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -81,6 +83,7 @@ class SubscriptionsFeedFragment : MainFragment() {
|
|||
val view = _view;
|
||||
if (view != null) {
|
||||
_cachedRecyclerData = view.recyclerData;
|
||||
_group = view.subGroup;
|
||||
view.cleanup();
|
||||
_view = null;
|
||||
}
|
||||
|
@ -101,12 +104,12 @@ class SubscriptionsFeedFragment : MainFragment() {
|
|||
class SubscriptionsFeedView : ContentFeedView<SubscriptionsFeedFragment> {
|
||||
override val shouldShowTimeBar: Boolean get() = Settings.instance.subscriptions.progressBar
|
||||
|
||||
private var _subGroup: SubscriptionGroup? = null;
|
||||
var subGroup: SubscriptionGroup? = null;
|
||||
|
||||
constructor(fragment: SubscriptionsFeedFragment, inflater: LayoutInflater, cachedRecyclerData: RecyclerData<InsertedViewAdapterWithLoader<ContentPreviewViewHolder>, LinearLayoutManager, IPager<IPlatformContent>, IPlatformContent, IPlatformContent, InsertedViewHolder<ContentPreviewViewHolder>>? = null) : super(fragment, inflater, cachedRecyclerData) {
|
||||
Logger.i(TAG, "SubscriptionsFeedFragment constructor()");
|
||||
StateSubscriptions.instance.onFeedProgress.subscribe(this) { id, progress, total ->
|
||||
if(_subGroup?.id == id)
|
||||
if(subGroup?.id == id)
|
||||
fragment.lifecycleScope.launch(Dispatchers.Main) {
|
||||
try {
|
||||
setProgress(progress, total);
|
||||
|
@ -142,7 +145,6 @@ class SubscriptionsFeedFragment : MainFragment() {
|
|||
recyclerData.lastLoad = OffsetDateTime.now();
|
||||
|
||||
if(StateSubscriptions.instance.getOldestUpdateTime().getNowDiffMinutes() > 5 && Settings.instance.subscriptions.fetchOnTabOpen) {
|
||||
loadCache();
|
||||
loadResults(false);
|
||||
}
|
||||
else if(recyclerData.results.size == 0) {
|
||||
|
@ -200,7 +202,7 @@ class SubscriptionsFeedFragment : MainFragment() {
|
|||
private var _bypassRateLimit = false;
|
||||
private val _lastExceptions: List<Throwable>? = null;
|
||||
private val _taskGetPager = TaskHandler<Boolean, IPager<IPlatformContent>>({StateApp.instance.scope}, { withRefresh ->
|
||||
val group = _subGroup;
|
||||
val group = subGroup;
|
||||
if(!_bypassRateLimit) {
|
||||
val subRequestCounts = StateSubscriptions.instance.getSubscriptionRequestCount(group);
|
||||
val reqCountStr = subRequestCounts.map { " ${it.key.config.name}: ${it.value}/${it.key.getSubscriptionRateLimit()}" }.joinToString("\n");
|
||||
|
@ -260,6 +262,11 @@ class SubscriptionsFeedFragment : MainFragment() {
|
|||
}
|
||||
};
|
||||
|
||||
fun selectSubgroup(g: SubscriptionGroup?) {
|
||||
if(g != null)
|
||||
_subscriptionBar?.selectGroup(g);
|
||||
}
|
||||
|
||||
private fun initializeToolbarContent() {
|
||||
_subscriptionBar = SubscriptionBar(context).apply {
|
||||
layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
|
@ -269,11 +276,17 @@ class SubscriptionsFeedFragment : MainFragment() {
|
|||
if(g is SubscriptionGroup.Add)
|
||||
UISlideOverlays.showCreateSubscriptionGroup(_overlayContainer);
|
||||
else {
|
||||
_subGroup = g;
|
||||
subGroup = g;
|
||||
setProgress(0, 0);
|
||||
if(Settings.instance.subscriptions.fetchOnTabOpen)
|
||||
if(Settings.instance.subscriptions.fetchOnTabOpen) {
|
||||
loadCache();
|
||||
loadResults(false);
|
||||
else loadCache();
|
||||
}
|
||||
else if(g != null && StateSubscriptions.instance.getFeed(g.id) != null) {
|
||||
loadResults(false);
|
||||
}
|
||||
else
|
||||
loadCache();
|
||||
}
|
||||
};
|
||||
_subscriptionBar?.onHoldGroup?.subscribe { g ->
|
||||
|
@ -314,7 +327,7 @@ class SubscriptionsFeedFragment : MainFragment() {
|
|||
|
||||
override fun filterResults(results: List<IPlatformContent>): List<IPlatformContent> {
|
||||
val nowSoon = OffsetDateTime.now().plusMinutes(5);
|
||||
val filterGroup = _subGroup;
|
||||
val filterGroup = subGroup;
|
||||
return results.filter {
|
||||
val allowedContentType = _filterSettings.allowContentTypes.contains(if(it.contentType == ContentType.NESTED_VIDEO || it.contentType == ContentType.LOCKED) ContentType.MEDIA else it.contentType);
|
||||
|
||||
|
|
|
@ -88,6 +88,13 @@ class SubscriptionBar : LinearLayout {
|
|||
updateExplore();
|
||||
}
|
||||
|
||||
fun selectGroup(group: SubscriptionGroup) {
|
||||
val relevantGroup = _groups.find { it.id == group.id };
|
||||
if(relevantGroup != null && _group != relevantGroup) {
|
||||
groupClicked(relevantGroup);
|
||||
}
|
||||
}
|
||||
|
||||
private fun groupClicked(g: SubscriptionGroup) {
|
||||
if(g is SubscriptionGroup.Add) {
|
||||
onToggleGroup.emit(g);
|
||||
|
|
Loading…
Add table
Reference in a new issue