Web support, additional article support

This commit is contained in:
Kelvin 2025-05-29 18:02:55 +02:00
commit 5bb3466ffe
8 changed files with 67 additions and 1 deletions

View file

@ -292,6 +292,22 @@ class PlatformPostDetails extends PlatformPost {
}
}
class PlatformWeb extends PlatformContent {
constructor(obj) {
super(obj, 7);
obj = obj ?? {};
this.plugin_type = "PlatformWeb";
}
}
class PlatformWebDetails extends PlatformWeb {
constructor(obj) {
super(obj, 7);
obj = obj ?? {};
this.plugin_type = "PlatformWebDetails";
this.html = obj.html;
}
}
class PlatformArticle extends PlatformContent {
constructor(obj) {
super(obj, 3);

View file

@ -455,6 +455,8 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
_fragMainPlaylist.topBar = _fragTopBarNavigation;
_fragMainRemotePlaylist.topBar = _fragTopBarNavigation;
_fragPostDetail.topBar = _fragTopBarNavigation;
_fragArticleDetail.topBar = _fragTopBarNavigation;
_fragWebDetail.topBar = _fragTopBarNavigation;
_fragWatchlist.topBar = _fragTopBarNavigation;
_fragHistory.topBar = _fragTopBarNavigation;
_fragSourceDetail.topBar = _fragTopBarNavigation;

View file

@ -17,6 +17,7 @@ interface IJSContentDetails: IPlatformContent {
ContentType.MEDIA -> JSVideoDetails(plugin, obj);
ContentType.POST -> JSPostDetails(plugin.config, obj);
ContentType.ARTICLE -> JSArticleDetails(plugin, obj);
ContentType.WEB -> JSWebDetails(plugin, obj);
else -> throw NotImplementedError("Unknown content type ${type}");
}
}

View file

@ -23,7 +23,7 @@ import com.futo.platformplayer.getOrThrowNullableList
import com.futo.platformplayer.states.StateDeveloper
open class JSWeb : JSContent, IPluginSourced {
final override val contentType: ContentType get() = ContentType.POST;
final override val contentType: ContentType get() = ContentType.WEB;
constructor(config: SourcePluginConfig, obj: V8ValueObject): super(config, obj) {
val contextName = "PlatformWeb";

View file

@ -17,6 +17,7 @@ import com.futo.platformplayer.api.media.models.playlists.IPlatformPlaylist
import com.futo.platformplayer.api.media.models.post.IPlatformPost
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
import com.futo.platformplayer.api.media.models.video.SerializedPlatformVideo
import com.futo.platformplayer.api.media.platforms.js.models.JSWeb
import com.futo.platformplayer.api.media.structures.IPager
import com.futo.platformplayer.logging.Logger
import com.futo.platformplayer.states.StateMeta
@ -200,6 +201,9 @@ abstract class ContentFeedView<TFragment> : FeedView<TFragment, IPlatformContent
} else if(content is IPlatformArticle) {
fragment.navigate<ArticleDetailFragment>(content);
}
else if(content is JSWeb) {
fragment.navigate<WebDetailFragment>(content);
}
else
UIDialogs.appToast("Unknown content type [" + content.contentType.name + "]");
}

View file

@ -26,6 +26,7 @@ import com.futo.platformplayer.Settings
import com.futo.platformplayer.UIDialogs
import com.futo.platformplayer.api.media.PlatformID
import com.futo.platformplayer.api.media.models.Thumbnails
import com.futo.platformplayer.api.media.models.article.IPlatformArticleDetails
import com.futo.platformplayer.api.media.models.comments.PolycentricPlatformComment
import com.futo.platformplayer.api.media.models.post.IPlatformPost
import com.futo.platformplayer.api.media.models.post.IPlatformPostDetails
@ -99,6 +100,10 @@ class WebDetailFragment : MainFragment {
override fun onShownWithView(parameter: Any?, isBack: Boolean) {
super.onShownWithView(parameter, isBack);
if (parameter is JSWeb) {
_viewDetail?.clear();
_viewDetail?.setWeb(parameter);
}
if (parameter is JSWebDetails) {
_viewDetail?.clear();
_viewDetail?.setWebDetails(parameter);
@ -116,6 +121,20 @@ class WebDetailFragment : MainFragment {
private val _webview: WebView;
private val _taskLoadPost = if(!isInEditMode) TaskHandler<String, JSWebDetails>(
StateApp.instance.scopeGetter,
{
val result = StatePlatform.instance.getContentDetails(it).await();
if(result !is JSWebDetails)
throw IllegalStateException(context.getString(R.string.expected_media_content_found) + " ${result.contentType}");
return@TaskHandler result;
})
.success { setWebDetails(it) }
.exception<Throwable> {
Logger.w(ChannelFragment.TAG, context.getString(R.string.failed_to_load_post), it);
UIDialogs.showGeneralRetryErrorDialog(context, context.getString(R.string.failed_to_load_post), it, ::fetchPost, null, _fragment);
} else TaskHandler(IPlatformPostDetails::class.java) { _fragment.lifecycleScope };
constructor(context: Context) : super(context) {
inflate(context, R.layout.fragview_web_detail, this);
@ -145,6 +164,12 @@ class WebDetailFragment : MainFragment {
_webview.loadUrl("about:blank");
}
fun setWeb(value: JSWeb) {
_url = value.url;
setLoading(true);
clear();
fetchPost();
}
fun setWebDetails(value: JSWebDetails) {
_web = value;
setLoading(true);
@ -155,6 +180,17 @@ class WebDetailFragment : MainFragment {
_webview.loadUrl(value.url ?: "about:blank");
}
private fun fetchPost() {
Logger.i(WebDetailView.TAG, "fetchWeb")
_web = null;
val url = _url;
if (!url.isNullOrBlank()) {
setLoading(true);
_taskLoadPost.run(url);
}
}
fun onDestroy() {
_webview.loadUrl("about:blank");
}

View file

@ -80,6 +80,7 @@ class PreviewContentListAdapter : InsertedViewAdapterWithLoader<ContentPreviewVi
ContentType.PLACEHOLDER -> createPlaceholderViewHolder(viewGroup);
ContentType.MEDIA -> createVideoPreviewViewHolder(viewGroup);
ContentType.ARTICLE -> createPostViewHolder(viewGroup);
ContentType.WEB -> createPostViewHolder(viewGroup);
ContentType.POST -> createPostViewHolder(viewGroup);
ContentType.PLAYLIST -> createPlaylistViewHolder(viewGroup);
ContentType.NESTED_VIDEO -> createNestedViewHolder(viewGroup);

View file

@ -25,6 +25,7 @@ import com.futo.platformplayer.api.media.models.article.IPlatformArticle
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
import com.futo.platformplayer.api.media.models.post.IPlatformPost
import com.futo.platformplayer.api.media.models.post.IPlatformPostDetails
import com.futo.platformplayer.api.media.platforms.js.models.JSWeb
import com.futo.platformplayer.constructs.Event1
import com.futo.platformplayer.constructs.TaskHandler
import com.futo.platformplayer.dp
@ -147,6 +148,11 @@ class PreviewPostView : LinearLayout {
content.summary ?: ""
else
""
} else if(content is JSWeb) {
if(!content.url.isNullOrEmpty())
"WEB:" + content.url
else
""
} else "";
if (content.name.isNullOrEmpty()) {