Fixes to Polycentric flows.

This commit is contained in:
Koen 2023-12-06 10:34:20 +01:00
commit fe02197bd8
11 changed files with 65 additions and 26 deletions

View file

@ -54,6 +54,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import okhttp3.internal.platform.Platform
@Serializable @Serializable
data class PolycentricProfile(val system: PublicKey, val systemState: SystemState, val ownedClaims: List<OwnedClaim>); data class PolycentricProfile(val system: PublicKey, val systemState: SystemState, val ownedClaims: List<OwnedClaim>);
@ -298,7 +299,7 @@ class ChannelFragment : MainFragment() {
Glide.with(_imageBanner) Glide.with(_imageBanner)
.clear(_imageBanner); .clear(_imageBanner);
_taskLoadPolycentricProfile.run(parameter.id); loadPolycentricProfile(parameter.id, parameter.url)
}; };
_url = parameter.url; _url = parameter.url;
@ -311,7 +312,7 @@ class ChannelFragment : MainFragment() {
Glide.with(_imageBanner) Glide.with(_imageBanner)
.clear(_imageBanner); .clear(_imageBanner);
_taskLoadPolycentricProfile.run(parameter.channel.id); loadPolycentricProfile(parameter.channel.id, parameter.channel.url)
}; };
_url = parameter.channel.url; _url = parameter.channel.url;
@ -327,6 +328,18 @@ class ChannelFragment : MainFragment() {
_tabs.selectTab(_tabs.getTabAt(selectedTabIndex)); _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) { private fun setLoading(isLoading: Boolean) {
if (_isLoading == isLoading) { if (_isLoading == isLoading) {
return; return;
@ -448,8 +461,6 @@ class ChannelFragment : MainFragment() {
} }
private fun setPolycentricProfile(cachedPolycentricProfile: PolycentricCache.CachedPolycentricProfile?, animate: Boolean) { private fun setPolycentricProfile(cachedPolycentricProfile: PolycentricCache.CachedPolycentricProfile?, animate: Boolean) {
Log.i(TAG, "setPolycentricProfile(cachedPolycentricProfile = $cachedPolycentricProfile, animate = $animate)")
val dp_35 = 35.dp(resources) val dp_35 = 35.dp(resources)
val profile = cachedPolycentricProfile?.profile; val profile = cachedPolycentricProfile?.profile;
val avatar = profile?.systemState?.avatar?.selectBestImage(dp_35 * dp_35) val avatar = profile?.systemState?.avatar?.selectBestImage(dp_35 * dp_35)

View file

@ -596,9 +596,12 @@ class PostDetailFragment : MainFragment {
private fun fetchPolycentricProfile() { private fun fetchPolycentricProfile() {
val author = _post?.author ?: _postOverview?.author ?: return; 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) { if (cachedPolycentricProfile != null) {
setPolycentricProfile(cachedPolycentricProfile, animate = false); setPolycentricProfile(cachedPolycentricProfile, animate = false);
if (cachedPolycentricProfile.expired) {
_taskLoadPolycentricProfile.run(author.id);
}
} else { } else {
setPolycentricProfile(null, animate = false); setPolycentricProfile(null, animate = false);
_taskLoadPolycentricProfile.run(author.id); _taskLoadPolycentricProfile.run(author.id);

View file

@ -992,14 +992,17 @@ class VideoDetailView : ConstraintLayout {
_descriptionContainer.visibility = View.GONE; _descriptionContainer.visibility = View.GONE;
_creatorThumbnail.setThumbnail(video.author.thumbnail, false); _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) { if (cachedPolycentricProfile != null) {
setPolycentricProfile(cachedPolycentricProfile, animate = false); setPolycentricProfile(cachedPolycentricProfile, animate = false);
if (cachedPolycentricProfile.expired) {
_taskLoadPolycentricProfile.run(video.author.id);
}
} else { } else {
setPolycentricProfile(null, animate = false); setPolycentricProfile(null, animate = false);
_taskLoadPolycentricProfile.run(video.author.id); _taskLoadPolycentricProfile.run(video.author.id);
_channelName.text = video.author.name;
} }
_player.clear(); _player.clear();
@ -1146,7 +1149,7 @@ class VideoDetailView : ConstraintLayout {
setDescription(video.description.fixHtmlLinks()); setDescription(video.description.fixHtmlLinks());
_creatorThumbnail.setThumbnail(video.author.thumbnail, false); _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) { if (cachedPolycentricProfile != null) {
setPolycentricProfile(cachedPolycentricProfile, animate = false); setPolycentricProfile(cachedPolycentricProfile, animate = false);
} else { } else {
@ -2169,6 +2172,11 @@ class VideoDetailView : ConstraintLayout {
_creatorThumbnail.setHarborAvailable(profile != null, animate); _creatorThumbnail.setHarborAvailable(profile != null, animate);
} }
val username = cachedPolycentricProfile?.profile?.systemState?.username
if (username != null) {
_channelName.text = username
}
_monetization.setPolycentricProfile(cachedPolycentricProfile, animate); _monetization.setPolycentricProfile(cachedPolycentricProfile, animate);
} }

View file

@ -50,7 +50,9 @@ class PolycentricCache {
ContentType.MEMBERSHIP_URLS.value, ContentType.MEMBERSHIP_URLS.value,
ContentType.DONATION_DESTINATIONS.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() val storageSystemState = StorageTypeSystemState.create()
for (signedEvent in signedProfileEvents) { for (signedEvent in signedProfileEvents) {

View file

@ -82,7 +82,6 @@ class SubscriptionViewHolder : ViewHolder {
this.subscription = sub; this.subscription = sub;
_creatorThumbnail.setThumbnail(sub.channel.thumbnail, false); _creatorThumbnail.setThumbnail(sub.channel.thumbnail, false);
_taskLoadProfile.run(sub.channel.id);
_textName.text = sub.channel.name; _textName.text = sub.channel.name;
bindViewMetrics(sub); bindViewMetrics(sub);
_platformIndicator.setPlatformFromClientID(sub.channel.id.pluginId); _platformIndicator.setPlatformFromClientID(sub.channel.id.pluginId);
@ -93,6 +92,8 @@ class SubscriptionViewHolder : ViewHolder {
if (cachedProfile.expired) { if (cachedProfile.expired) {
_taskLoadProfile.run(sub.channel.id); _taskLoadProfile.run(sub.channel.id);
} }
} else {
_taskLoadProfile.run(sub.channel.id);
} }
} }

View file

@ -183,7 +183,7 @@ open class PreviewVideoView : LinearLayout {
.placeholder(R.drawable.placeholder_channel_thumbnail) .placeholder(R.drawable.placeholder_channel_thumbnail)
.into(_imageChannel); .into(_imageChannel);
} }
_taskLoadProfile.run(content.author.id);
_textChannelName.text = content.author.name _textChannelName.text = content.author.name
val cachedProfile = PolycentricCache.instance.getCachedProfile(content.author.url, true); val cachedProfile = PolycentricCache.instance.getCachedProfile(content.author.url, true);
@ -192,6 +192,8 @@ open class PreviewVideoView : LinearLayout {
if (cachedProfile.expired) { if (cachedProfile.expired) {
_taskLoadProfile.run(content.author.id); _taskLoadProfile.run(content.author.id);
} }
} else {
_taskLoadProfile.run(content.author.id);
} }
_imageChannel?.clipToOutline = true; _imageChannel?.clipToOutline = true;

View file

@ -66,7 +66,6 @@ class CreatorViewHolder(private val _viewGroup: ViewGroup, private val _tiny: Bo
_taskLoadProfile.cancel(); _taskLoadProfile.cancel();
_creatorThumbnail.setThumbnail(authorLink.thumbnail, false); _creatorThumbnail.setThumbnail(authorLink.thumbnail, false);
_taskLoadProfile.run(authorLink.id);
_textName.text = authorLink.name; _textName.text = authorLink.name;
val cachedProfile = PolycentricCache.instance.getCachedProfile(authorLink.url, true); 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) { if (cachedProfile.expired) {
_taskLoadProfile.run(authorLink.id); _taskLoadProfile.run(authorLink.id);
} }
} else {
_taskLoadProfile.run(authorLink.id);
} }
if(authorLink.subscribers == null || (authorLink.subscribers ?: 0) <= 0L) if(authorLink.subscribers == null || (authorLink.subscribers ?: 0) <= 0L)

View file

@ -52,7 +52,6 @@ class SubscriptionBarViewHolder(private val _viewGroup: ViewGroup) : AnyAdapter.
_channel = subscription.channel; _channel = subscription.channel;
_creatorThumbnail.setThumbnail(subscription.channel.thumbnail, false); _creatorThumbnail.setThumbnail(subscription.channel.thumbnail, false);
_taskLoadProfile.run(subscription.channel.id);
_name.text = subscription.channel.name; _name.text = subscription.channel.name;
val cachedProfile = PolycentricCache.instance.getCachedProfile(subscription.channel.url, true); val cachedProfile = PolycentricCache.instance.getCachedProfile(subscription.channel.url, true);
@ -61,6 +60,8 @@ class SubscriptionBarViewHolder(private val _viewGroup: ViewGroup) : AnyAdapter.
if (cachedProfile.expired) { if (cachedProfile.expired) {
_taskLoadProfile.run(subscription.channel.id); _taskLoadProfile.run(subscription.channel.id);
} }
} else {
_taskLoadProfile.run(subscription.channel.id);
} }
_subscription = subscription; _subscription = subscription;

View file

@ -3,12 +3,18 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.futo.platformplayer.views.SupportView <com.futo.platformplayer.views.SupportView
android:id="@+id/support" android:id="@+id/support"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:visibility="gone"/> android:visibility="gone"/>
</androidx.core.widget.NestedScrollView>
<TextView <TextView
android:id="@+id/text_monetization" android:id="@+id/text_monetization"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -15,11 +15,18 @@
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" /> app:layout_constraintRight_toRightOf="parent" />
<com.futo.platformplayer.views.SupportView <ScrollView
android:id="@+id/support"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/topbar" app:layout_constraintTop_toBottomOf="@id/topbar"
app:layout_constraintBottom_toBottomOf="parent" /> app:layout_constraintBottom_toBottomOf="parent">
<com.futo.platformplayer.views.SupportView
android:id="@+id/support"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:layout_margin="18dp" android:layout_margin="18dp"
android:showDividers="middle" android:showDividers="middle"
@ -188,4 +186,3 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView>