diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/ChannelFragment.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/ChannelFragment.kt index a1d1ed9f..da879032 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/ChannelFragment.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/ChannelFragment.kt @@ -54,6 +54,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.serialization.Serializable +import okhttp3.internal.platform.Platform @Serializable data class PolycentricProfile(val system: PublicKey, val systemState: SystemState, val ownedClaims: List); @@ -298,7 +299,7 @@ class ChannelFragment : MainFragment() { Glide.with(_imageBanner) .clear(_imageBanner); - _taskLoadPolycentricProfile.run(parameter.id); + loadPolycentricProfile(parameter.id, parameter.url) }; _url = parameter.url; @@ -311,7 +312,7 @@ class ChannelFragment : MainFragment() { Glide.with(_imageBanner) .clear(_imageBanner); - _taskLoadPolycentricProfile.run(parameter.channel.id); + loadPolycentricProfile(parameter.channel.id, parameter.channel.url) }; _url = parameter.channel.url; @@ -327,6 +328,18 @@ class ChannelFragment : MainFragment() { _tabs.selectTab(_tabs.getTabAt(selectedTabIndex)); } + private fun loadPolycentricProfile(id: PlatformID, url: String) { + val cachedPolycentricProfile = PolycentricCache.instance.getCachedProfile(url, true); + if (cachedPolycentricProfile != null) { + setPolycentricProfile(cachedPolycentricProfile, animate = true) + if (cachedPolycentricProfile.expired) { + _taskLoadPolycentricProfile.run(id); + } + } else { + _taskLoadPolycentricProfile.run(id); + } + } + private fun setLoading(isLoading: Boolean) { if (_isLoading == isLoading) { return; @@ -448,8 +461,6 @@ class ChannelFragment : MainFragment() { } private fun setPolycentricProfile(cachedPolycentricProfile: PolycentricCache.CachedPolycentricProfile?, animate: Boolean) { - Log.i(TAG, "setPolycentricProfile(cachedPolycentricProfile = $cachedPolycentricProfile, animate = $animate)") - val dp_35 = 35.dp(resources) val profile = cachedPolycentricProfile?.profile; val avatar = profile?.systemState?.avatar?.selectBestImage(dp_35 * dp_35) diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/PostDetailFragment.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/PostDetailFragment.kt index 667b6ac9..87185ba1 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/PostDetailFragment.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/PostDetailFragment.kt @@ -596,9 +596,12 @@ class PostDetailFragment : MainFragment { private fun fetchPolycentricProfile() { val author = _post?.author ?: _postOverview?.author ?: return; - val cachedPolycentricProfile = PolycentricCache.instance.getCachedProfile(author.url); + val cachedPolycentricProfile = PolycentricCache.instance.getCachedProfile(author.url, true); if (cachedPolycentricProfile != null) { setPolycentricProfile(cachedPolycentricProfile, animate = false); + if (cachedPolycentricProfile.expired) { + _taskLoadPolycentricProfile.run(author.id); + } } else { setPolycentricProfile(null, animate = false); _taskLoadPolycentricProfile.run(author.id); diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt index 3fb8cfd0..11f025f2 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt @@ -992,14 +992,17 @@ class VideoDetailView : ConstraintLayout { _descriptionContainer.visibility = View.GONE; _creatorThumbnail.setThumbnail(video.author.thumbnail, false); + _channelName.text = video.author.name; - val cachedPolycentricProfile = PolycentricCache.instance.getCachedProfile(video.author.url); + val cachedPolycentricProfile = PolycentricCache.instance.getCachedProfile(video.author.url, true); if (cachedPolycentricProfile != null) { setPolycentricProfile(cachedPolycentricProfile, animate = false); + if (cachedPolycentricProfile.expired) { + _taskLoadPolycentricProfile.run(video.author.id); + } } else { setPolycentricProfile(null, animate = false); _taskLoadPolycentricProfile.run(video.author.id); - _channelName.text = video.author.name; } _player.clear(); @@ -1146,7 +1149,7 @@ class VideoDetailView : ConstraintLayout { setDescription(video.description.fixHtmlLinks()); _creatorThumbnail.setThumbnail(video.author.thumbnail, false); - val cachedPolycentricProfile = PolycentricCache.instance.getCachedProfile(video.author.url); + val cachedPolycentricProfile = PolycentricCache.instance.getCachedProfile(video.author.url, true); if (cachedPolycentricProfile != null) { setPolycentricProfile(cachedPolycentricProfile, animate = false); } else { @@ -2169,6 +2172,11 @@ class VideoDetailView : ConstraintLayout { _creatorThumbnail.setHarborAvailable(profile != null, animate); } + val username = cachedPolycentricProfile?.profile?.systemState?.username + if (username != null) { + _channelName.text = username + } + _monetization.setPolycentricProfile(cachedPolycentricProfile, animate); } diff --git a/app/src/main/java/com/futo/platformplayer/polycentric/PolycentricCache.kt b/app/src/main/java/com/futo/platformplayer/polycentric/PolycentricCache.kt index 08a3f3da..fa174bc7 100644 --- a/app/src/main/java/com/futo/platformplayer/polycentric/PolycentricCache.kt +++ b/app/src/main/java/com/futo/platformplayer/polycentric/PolycentricCache.kt @@ -50,7 +50,9 @@ class PolycentricCache { ContentType.MEMBERSHIP_URLS.value, ContentType.DONATION_DESTINATIONS.value ) - ).eventsList.map { e -> SignedEvent.fromProto(e) }; + ).eventsList.map { e -> SignedEvent.fromProto(e) } + .groupBy { e -> e.event.contentType } + .map { (_, events) -> events.maxBy { it.event.unixMilliseconds ?: 0 } }; val storageSystemState = StorageTypeSystemState.create() for (signedEvent in signedProfileEvents) { diff --git a/app/src/main/java/com/futo/platformplayer/views/adapters/SubscriptionViewHolder.kt b/app/src/main/java/com/futo/platformplayer/views/adapters/SubscriptionViewHolder.kt index 8a28c260..4ee6f00f 100644 --- a/app/src/main/java/com/futo/platformplayer/views/adapters/SubscriptionViewHolder.kt +++ b/app/src/main/java/com/futo/platformplayer/views/adapters/SubscriptionViewHolder.kt @@ -82,7 +82,6 @@ class SubscriptionViewHolder : ViewHolder { this.subscription = sub; _creatorThumbnail.setThumbnail(sub.channel.thumbnail, false); - _taskLoadProfile.run(sub.channel.id); _textName.text = sub.channel.name; bindViewMetrics(sub); _platformIndicator.setPlatformFromClientID(sub.channel.id.pluginId); @@ -93,6 +92,8 @@ class SubscriptionViewHolder : ViewHolder { if (cachedProfile.expired) { _taskLoadProfile.run(sub.channel.id); } + } else { + _taskLoadProfile.run(sub.channel.id); } } diff --git a/app/src/main/java/com/futo/platformplayer/views/adapters/feedtypes/PreviewVideoView.kt b/app/src/main/java/com/futo/platformplayer/views/adapters/feedtypes/PreviewVideoView.kt index 565b6113..8d88a7d4 100644 --- a/app/src/main/java/com/futo/platformplayer/views/adapters/feedtypes/PreviewVideoView.kt +++ b/app/src/main/java/com/futo/platformplayer/views/adapters/feedtypes/PreviewVideoView.kt @@ -183,7 +183,7 @@ open class PreviewVideoView : LinearLayout { .placeholder(R.drawable.placeholder_channel_thumbnail) .into(_imageChannel); } - _taskLoadProfile.run(content.author.id); + _textChannelName.text = content.author.name val cachedProfile = PolycentricCache.instance.getCachedProfile(content.author.url, true); @@ -192,6 +192,8 @@ open class PreviewVideoView : LinearLayout { if (cachedProfile.expired) { _taskLoadProfile.run(content.author.id); } + } else { + _taskLoadProfile.run(content.author.id); } _imageChannel?.clipToOutline = true; diff --git a/app/src/main/java/com/futo/platformplayer/views/adapters/viewholders/CreatorViewHolder.kt b/app/src/main/java/com/futo/platformplayer/views/adapters/viewholders/CreatorViewHolder.kt index 845a179c..8187d21b 100644 --- a/app/src/main/java/com/futo/platformplayer/views/adapters/viewholders/CreatorViewHolder.kt +++ b/app/src/main/java/com/futo/platformplayer/views/adapters/viewholders/CreatorViewHolder.kt @@ -66,7 +66,6 @@ class CreatorViewHolder(private val _viewGroup: ViewGroup, private val _tiny: Bo _taskLoadProfile.cancel(); _creatorThumbnail.setThumbnail(authorLink.thumbnail, false); - _taskLoadProfile.run(authorLink.id); _textName.text = authorLink.name; val cachedProfile = PolycentricCache.instance.getCachedProfile(authorLink.url, true); @@ -75,6 +74,8 @@ class CreatorViewHolder(private val _viewGroup: ViewGroup, private val _tiny: Bo if (cachedProfile.expired) { _taskLoadProfile.run(authorLink.id); } + } else { + _taskLoadProfile.run(authorLink.id); } if(authorLink.subscribers == null || (authorLink.subscribers ?: 0) <= 0L) diff --git a/app/src/main/java/com/futo/platformplayer/views/adapters/viewholders/SubscriptionBarViewHolder.kt b/app/src/main/java/com/futo/platformplayer/views/adapters/viewholders/SubscriptionBarViewHolder.kt index 0661b28d..c8f25f89 100644 --- a/app/src/main/java/com/futo/platformplayer/views/adapters/viewholders/SubscriptionBarViewHolder.kt +++ b/app/src/main/java/com/futo/platformplayer/views/adapters/viewholders/SubscriptionBarViewHolder.kt @@ -52,7 +52,6 @@ class SubscriptionBarViewHolder(private val _viewGroup: ViewGroup) : AnyAdapter. _channel = subscription.channel; _creatorThumbnail.setThumbnail(subscription.channel.thumbnail, false); - _taskLoadProfile.run(subscription.channel.id); _name.text = subscription.channel.name; val cachedProfile = PolycentricCache.instance.getCachedProfile(subscription.channel.url, true); @@ -61,6 +60,8 @@ class SubscriptionBarViewHolder(private val _viewGroup: ViewGroup) : AnyAdapter. if (cachedProfile.expired) { _taskLoadProfile.run(subscription.channel.id); } + } else { + _taskLoadProfile.run(subscription.channel.id); } _subscription = subscription; diff --git a/app/src/main/res/layout/fragment_channel_monetization.xml b/app/src/main/res/layout/fragment_channel_monetization.xml index e41a8ee6..e17cb27a 100644 --- a/app/src/main/res/layout/fragment_channel_monetization.xml +++ b/app/src/main/res/layout/fragment_channel_monetization.xml @@ -3,11 +3,17 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="match_parent"> + + + + - + app:layout_constraintBottom_toBottomOf="parent"> + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_support.xml b/app/src/main/res/layout/view_support.xml index 392aefe9..902dfb5a 100644 --- a/app/src/main/res/layout/view_support.xml +++ b/app/src/main/res/layout/view_support.xml @@ -1,11 +1,9 @@ - - - - \ No newline at end of file + \ No newline at end of file