mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2026-05-16 04:52:39 +02:00
Various crash fixes.
This commit is contained in:
@@ -129,115 +129,163 @@ class UISlideOverlays {
|
|||||||
val originalVideo = subscription.doFetchVideos;
|
val originalVideo = subscription.doFetchVideos;
|
||||||
val originalPosts = subscription.doFetchPosts;
|
val originalPosts = subscription.doFetchPosts;
|
||||||
|
|
||||||
val menu = SlideUpMenuOverlay(container.context, container, "Subscription Settings", null, true, listOf());
|
val menu = SlideUpMenuOverlay(
|
||||||
|
container.context,
|
||||||
|
container,
|
||||||
|
"Subscription Settings",
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
listOf()
|
||||||
|
);
|
||||||
|
|
||||||
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO){
|
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
|
||||||
val plugin = StatePlatform.instance.getChannelClient(subscription.channel.url);
|
try {
|
||||||
val capabilities = plugin.getChannelCapabilities();
|
val plugin = StatePlatform.instance.getChannelClient(subscription.channel.url);
|
||||||
|
val capabilities = plugin.getChannelCapabilities();
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
items.addAll(listOf(
|
items.addAll(
|
||||||
SlideUpMenuItem(
|
listOf(
|
||||||
container.context,
|
SlideUpMenuItem(
|
||||||
R.drawable.ic_notifications,
|
container.context,
|
||||||
"Notifications",
|
R.drawable.ic_notifications,
|
||||||
"",
|
"Notifications",
|
||||||
tag = "notifications",
|
"",
|
||||||
call = {
|
tag = "notifications",
|
||||||
subscription.doNotifications = menu?.selectOption(null, "notifications", true, true) ?: subscription.doNotifications;
|
call = {
|
||||||
},
|
subscription.doNotifications =
|
||||||
invokeParent = false
|
menu?.selectOption(null, "notifications", true, true)
|
||||||
),
|
?: subscription.doNotifications;
|
||||||
if(StateSubscriptionGroups.instance.getSubscriptionGroups().isNotEmpty())
|
},
|
||||||
SlideUpMenuGroup(container.context, "Subscription Groups",
|
invokeParent = false
|
||||||
"You can select which groups this subscription is part of.",
|
),
|
||||||
-1, listOf()) else null,
|
if (StateSubscriptionGroups.instance.getSubscriptionGroups()
|
||||||
if(StateSubscriptionGroups.instance.getSubscriptionGroups().isNotEmpty())
|
.isNotEmpty()
|
||||||
SlideUpMenuRecycler(container.context, "as") {
|
)
|
||||||
val groups = ArrayList<SubscriptionGroup>(StateSubscriptionGroups.instance.getSubscriptionGroups()
|
SlideUpMenuGroup(
|
||||||
.map { SubscriptionGroup.Selectable(it, it.urls.contains(subscription.channel.url)) }
|
container.context, "Subscription Groups",
|
||||||
.sortedBy { !it.selected });
|
"You can select which groups this subscription is part of.",
|
||||||
var adapter: AnyAdapterView<SubscriptionGroup, SubscriptionGroupBarViewHolder>? = null;
|
-1, listOf()
|
||||||
adapter = it.asAny(groups, RecyclerView.HORIZONTAL) {
|
) else null,
|
||||||
it.onClick.subscribe {
|
if (StateSubscriptionGroups.instance.getSubscriptionGroups()
|
||||||
if(it is SubscriptionGroup.Selectable) {
|
.isNotEmpty()
|
||||||
val actualGroup = StateSubscriptionGroups.instance.getSubscriptionGroup(it.id)
|
)
|
||||||
?: return@subscribe;
|
SlideUpMenuRecycler(container.context, "as") {
|
||||||
groups.clear();
|
val groups =
|
||||||
if(it.selected)
|
ArrayList<SubscriptionGroup>(
|
||||||
actualGroup.urls.remove(subscription.channel.url);
|
StateSubscriptionGroups.instance.getSubscriptionGroups()
|
||||||
else
|
.map {
|
||||||
actualGroup.urls.add(subscription.channel.url);
|
SubscriptionGroup.Selectable(
|
||||||
|
it,
|
||||||
|
it.urls.contains(subscription.channel.url)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.sortedBy { !it.selected });
|
||||||
|
var adapter: AnyAdapterView<SubscriptionGroup, SubscriptionGroupBarViewHolder>? =
|
||||||
|
null;
|
||||||
|
adapter = it.asAny(groups, RecyclerView.HORIZONTAL) {
|
||||||
|
it.onClick.subscribe {
|
||||||
|
if (it is SubscriptionGroup.Selectable) {
|
||||||
|
val actualGroup =
|
||||||
|
StateSubscriptionGroups.instance.getSubscriptionGroup(
|
||||||
|
it.id
|
||||||
|
)
|
||||||
|
?: return@subscribe;
|
||||||
|
groups.clear();
|
||||||
|
if (it.selected)
|
||||||
|
actualGroup.urls.remove(subscription.channel.url);
|
||||||
|
else
|
||||||
|
actualGroup.urls.add(subscription.channel.url);
|
||||||
|
|
||||||
StateSubscriptionGroups.instance.updateSubscriptionGroup(actualGroup);
|
StateSubscriptionGroups.instance.updateSubscriptionGroup(
|
||||||
groups.addAll(StateSubscriptionGroups.instance.getSubscriptionGroups()
|
actualGroup
|
||||||
.map { SubscriptionGroup.Selectable(it, it.urls.contains(subscription.channel.url)) }
|
);
|
||||||
.sortedBy { !it.selected });
|
groups.addAll(
|
||||||
adapter?.notifyContentChanged();
|
StateSubscriptionGroups.instance.getSubscriptionGroups()
|
||||||
}
|
.map {
|
||||||
}
|
SubscriptionGroup.Selectable(
|
||||||
};
|
it,
|
||||||
return@SlideUpMenuRecycler adapter;
|
it.urls.contains(subscription.channel.url)
|
||||||
} else null,
|
)
|
||||||
SlideUpMenuGroup(container.context, "Fetch Settings",
|
}
|
||||||
"Depending on the platform you might not need to enable a type for it to be available.",
|
.sortedBy { !it.selected });
|
||||||
-1, listOf()),
|
adapter?.notifyContentChanged();
|
||||||
if(capabilities.hasType(ResultCapabilities.TYPE_LIVE)) SlideUpMenuItem(
|
}
|
||||||
container.context,
|
}
|
||||||
R.drawable.ic_live_tv,
|
};
|
||||||
"Livestreams",
|
return@SlideUpMenuRecycler adapter;
|
||||||
"Check for livestreams",
|
} else null,
|
||||||
tag = "fetchLive",
|
SlideUpMenuGroup(
|
||||||
call = {
|
container.context, "Fetch Settings",
|
||||||
subscription.doFetchLive = menu?.selectOption(null, "fetchLive", true, true) ?: subscription.doFetchLive;
|
"Depending on the platform you might not need to enable a type for it to be available.",
|
||||||
},
|
-1, listOf()
|
||||||
invokeParent = false
|
),
|
||||||
) else null,
|
if (capabilities.hasType(ResultCapabilities.TYPE_LIVE)) SlideUpMenuItem(
|
||||||
if(capabilities.hasType(ResultCapabilities.TYPE_STREAMS)) SlideUpMenuItem(
|
container.context,
|
||||||
container.context,
|
R.drawable.ic_live_tv,
|
||||||
R.drawable.ic_play,
|
"Livestreams",
|
||||||
"Streams",
|
"Check for livestreams",
|
||||||
"Check for streams",
|
tag = "fetchLive",
|
||||||
tag = "fetchStreams",
|
call = {
|
||||||
call = {
|
subscription.doFetchLive =
|
||||||
subscription.doFetchStreams = menu?.selectOption(null, "fetchStreams", true, true) ?: subscription.doFetchStreams;
|
menu?.selectOption(null, "fetchLive", true, true)
|
||||||
},
|
?: subscription.doFetchLive;
|
||||||
invokeParent = false
|
},
|
||||||
) else null,
|
invokeParent = false
|
||||||
if(capabilities.hasType(ResultCapabilities.TYPE_VIDEOS))
|
) else null,
|
||||||
SlideUpMenuItem(
|
if (capabilities.hasType(ResultCapabilities.TYPE_STREAMS)) SlideUpMenuItem(
|
||||||
container.context,
|
container.context,
|
||||||
R.drawable.ic_play,
|
R.drawable.ic_play,
|
||||||
"Videos",
|
"Streams",
|
||||||
"Check for videos",
|
"Check for streams",
|
||||||
tag = "fetchVideos",
|
tag = "fetchStreams",
|
||||||
call = {
|
call = {
|
||||||
subscription.doFetchVideos = menu?.selectOption(null, "fetchVideos", true, true) ?: subscription.doFetchVideos;
|
subscription.doFetchStreams =
|
||||||
},
|
menu?.selectOption(null, "fetchStreams", true, true)
|
||||||
invokeParent = false
|
?: subscription.doFetchStreams;
|
||||||
) else if(capabilities.hasType(ResultCapabilities.TYPE_MIXED) || capabilities.types.isEmpty())
|
},
|
||||||
SlideUpMenuItem(
|
invokeParent = false
|
||||||
container.context,
|
) else null,
|
||||||
R.drawable.ic_play,
|
if (capabilities.hasType(ResultCapabilities.TYPE_VIDEOS))
|
||||||
"Content",
|
SlideUpMenuItem(
|
||||||
"Check for content",
|
container.context,
|
||||||
tag = "fetchVideos",
|
R.drawable.ic_play,
|
||||||
call = {
|
"Videos",
|
||||||
subscription.doFetchVideos = menu?.selectOption(null, "fetchVideos", true, true) ?: subscription.doFetchVideos;
|
"Check for videos",
|
||||||
},
|
tag = "fetchVideos",
|
||||||
invokeParent = false
|
call = {
|
||||||
) else null,
|
subscription.doFetchVideos =
|
||||||
if(capabilities.hasType(ResultCapabilities.TYPE_POSTS)) SlideUpMenuItem(
|
menu?.selectOption(null, "fetchVideos", true, true)
|
||||||
container.context,
|
?: subscription.doFetchVideos;
|
||||||
R.drawable.ic_chat,
|
},
|
||||||
"Posts",
|
invokeParent = false
|
||||||
"Check for posts",
|
) else if (capabilities.hasType(ResultCapabilities.TYPE_MIXED) || capabilities.types.isEmpty())
|
||||||
tag = "fetchPosts",
|
SlideUpMenuItem(
|
||||||
call = {
|
container.context,
|
||||||
subscription.doFetchPosts = menu?.selectOption(null, "fetchPosts", true, true) ?: subscription.doFetchPosts;
|
R.drawable.ic_play,
|
||||||
},
|
"Content",
|
||||||
invokeParent = false
|
"Check for content",
|
||||||
) else null/*,,
|
tag = "fetchVideos",
|
||||||
|
call = {
|
||||||
|
subscription.doFetchVideos =
|
||||||
|
menu?.selectOption(null, "fetchVideos", true, true)
|
||||||
|
?: subscription.doFetchVideos;
|
||||||
|
},
|
||||||
|
invokeParent = false
|
||||||
|
) else null,
|
||||||
|
if (capabilities.hasType(ResultCapabilities.TYPE_POSTS)) SlideUpMenuItem(
|
||||||
|
container.context,
|
||||||
|
R.drawable.ic_chat,
|
||||||
|
"Posts",
|
||||||
|
"Check for posts",
|
||||||
|
tag = "fetchPosts",
|
||||||
|
call = {
|
||||||
|
subscription.doFetchPosts =
|
||||||
|
menu?.selectOption(null, "fetchPosts", true, true)
|
||||||
|
?: subscription.doFetchPosts;
|
||||||
|
},
|
||||||
|
invokeParent = false
|
||||||
|
) else null/*,,
|
||||||
|
|
||||||
SlideUpMenuGroup(container.context, "Actions",
|
SlideUpMenuGroup(container.context, "Actions",
|
||||||
"Various things you can do with this subscription",
|
"Various things you can do with this subscription",
|
||||||
@@ -245,61 +293,82 @@ class UISlideOverlays {
|
|||||||
SlideUpMenuItem(container.context, R.drawable.ic_list, "Add to Group", "", "btnAddToGroup", {
|
SlideUpMenuItem(container.context, R.drawable.ic_list, "Add to Group", "", "btnAddToGroup", {
|
||||||
showCreateSubscriptionGroup(container, subscription.channel);
|
showCreateSubscriptionGroup(container, subscription.channel);
|
||||||
}, false)*/
|
}, false)*/
|
||||||
).filterNotNull());
|
).filterNotNull()
|
||||||
|
);
|
||||||
|
|
||||||
menu.setItems(items);
|
menu.setItems(items);
|
||||||
|
|
||||||
if(subscription.doNotifications)
|
if (subscription.doNotifications)
|
||||||
menu.selectOption(null, "notifications", true, true);
|
menu.selectOption(null, "notifications", true, true);
|
||||||
if(subscription.doFetchLive)
|
if (subscription.doFetchLive)
|
||||||
menu.selectOption(null, "fetchLive", true, true);
|
menu.selectOption(null, "fetchLive", true, true);
|
||||||
if(subscription.doFetchStreams)
|
if (subscription.doFetchStreams)
|
||||||
menu.selectOption(null, "fetchStreams", true, true);
|
menu.selectOption(null, "fetchStreams", true, true);
|
||||||
if(subscription.doFetchVideos)
|
if (subscription.doFetchVideos)
|
||||||
menu.selectOption(null, "fetchVideos", true, true);
|
menu.selectOption(null, "fetchVideos", true, true);
|
||||||
if(subscription.doFetchPosts)
|
if (subscription.doFetchPosts)
|
||||||
menu.selectOption(null, "fetchPosts", true, true);
|
menu.selectOption(null, "fetchPosts", true, true);
|
||||||
|
|
||||||
menu.onOK.subscribe {
|
menu.onOK.subscribe {
|
||||||
subscription.save();
|
subscription.save();
|
||||||
menu.hide(true);
|
menu.hide(true);
|
||||||
|
|
||||||
if(subscription.doNotifications && !originalNotif) {
|
if (subscription.doNotifications && !originalNotif) {
|
||||||
val mainContext = StateApp.instance.contextOrNull;
|
val mainContext = StateApp.instance.contextOrNull;
|
||||||
if(Settings.instance.subscriptions.subscriptionsBackgroundUpdateInterval == 0) {
|
if (Settings.instance.subscriptions.subscriptionsBackgroundUpdateInterval == 0) {
|
||||||
UIDialogs.toast(container.context, "Enable 'Background Update' in settings for notifications to work");
|
UIDialogs.toast(
|
||||||
|
container.context,
|
||||||
|
"Enable 'Background Update' in settings for notifications to work"
|
||||||
|
);
|
||||||
|
|
||||||
if(mainContext is MainActivity) {
|
if (mainContext is MainActivity) {
|
||||||
UIDialogs.showDialog(mainContext, R.drawable.ic_settings, "Background Updating Required",
|
UIDialogs.showDialog(
|
||||||
"You need to set a Background Updating interval for notifications", null, 0,
|
mainContext,
|
||||||
UIDialogs.Action("Cancel", {}),
|
R.drawable.ic_settings,
|
||||||
UIDialogs.Action("Configure", {
|
"Background Updating Required",
|
||||||
val intent = Intent(mainContext, SettingsActivity::class.java);
|
"You need to set a Background Updating interval for notifications",
|
||||||
intent.putExtra("query", mainContext.getString(R.string.background_update));
|
null,
|
||||||
mainContext.startActivity(intent);
|
0,
|
||||||
}, UIDialogs.ActionStyle.PRIMARY));
|
UIDialogs.Action("Cancel", {}),
|
||||||
}
|
UIDialogs.Action("Configure", {
|
||||||
return@subscribe;
|
val intent = Intent(
|
||||||
}
|
mainContext,
|
||||||
else if(!(mainContext?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).areNotificationsEnabled()) {
|
SettingsActivity::class.java
|
||||||
UIDialogs.toast(container.context, "Android notifications are disabled");
|
);
|
||||||
if(mainContext is MainActivity) {
|
intent.putExtra(
|
||||||
mainContext.requestNotificationPermissions("Notifications are required for subscription updating and notifications to work");
|
"query",
|
||||||
|
mainContext.getString(R.string.background_update)
|
||||||
|
);
|
||||||
|
mainContext.startActivity(intent);
|
||||||
|
}, UIDialogs.ActionStyle.PRIMARY)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return@subscribe;
|
||||||
|
} else if (!(mainContext?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).areNotificationsEnabled()) {
|
||||||
|
UIDialogs.toast(
|
||||||
|
container.context,
|
||||||
|
"Android notifications are disabled"
|
||||||
|
);
|
||||||
|
if (mainContext is MainActivity) {
|
||||||
|
mainContext.requestNotificationPermissions("Notifications are required for subscription updating and notifications to work");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
menu.onCancel.subscribe {
|
||||||
menu.onCancel.subscribe {
|
subscription.doNotifications = originalNotif;
|
||||||
subscription.doNotifications = originalNotif;
|
subscription.doFetchLive = originalLive;
|
||||||
subscription.doFetchLive = originalLive;
|
subscription.doFetchStreams = originalStream;
|
||||||
subscription.doFetchStreams = originalStream;
|
subscription.doFetchVideos = originalVideo;
|
||||||
subscription.doFetchVideos = originalVideo;
|
subscription.doFetchPosts = originalPosts;
|
||||||
subscription.doFetchPosts = originalPosts;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
menu.setOk("Save");
|
menu.setOk("Save");
|
||||||
|
|
||||||
menu.show();
|
menu.show();
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.e(TAG, "Failed to show subscription overlay.", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import com.futo.platformplayer.activities.MainActivity
|
|||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.receivers.MediaControlReceiver
|
import com.futo.platformplayer.receivers.MediaControlReceiver
|
||||||
import com.futo.platformplayer.timestampRegex
|
import com.futo.platformplayer.timestampRegex
|
||||||
|
import com.futo.platformplayer.views.behavior.NonScrollingTextView
|
||||||
|
import com.futo.platformplayer.views.behavior.NonScrollingTextView.Companion
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -91,7 +93,11 @@ class PlatformLinkMovementMethod(private val _context: Context) : LinkMovementMe
|
|||||||
}
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
try {
|
||||||
|
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.i(TAG, "Failed to start activity.", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,12 +108,20 @@ class NonScrollingTextView : androidx.appcompat.widget.AppCompatTextView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
try {
|
||||||
|
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.i(TAG, "Failed to start activity.", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
StateApp.instance.scopeOrNull?.launch(Dispatchers.Main) {
|
StateApp.instance.scopeOrNull?.launch(Dispatchers.Main) {
|
||||||
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
try {
|
||||||
|
c.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link.url)))
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.i(TAG, "Failed to start activity.", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user