From aefd8df5c64b36da0fbb82564d3d97b009076c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Sch=C3=BCller?= Date: Sat, 1 Jan 2022 18:43:48 +0000 Subject: [PATCH] Player update --- .../peertube/activity/AccountActivity.java | 6 +- .../peertube/adapter/ChannelAdapter.java | 8 +- .../adapter/MultiViewRecyclerViewHolder.kt | 111 ++++++++++++------ .../peertube/helper/MetaDataHelper.kt | 76 ++++++++++-- app/src/main/res/layout/item_video_meta.xml | 24 ++-- app/src/main/res/values/constants.xml | 1 - app/src/main/res/values/strings.xml | 8 ++ 7 files changed, 172 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/activity/AccountActivity.java b/app/src/main/java/net/schueller/peertube/activity/AccountActivity.java index 58fe075..c14482e 100644 --- a/app/src/main/java/net/schueller/peertube/activity/AccountActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/AccountActivity.java @@ -175,11 +175,11 @@ public class AccountActivity extends CommonActivity { if (response.isSuccessful()) { Account account = response.body(); - String owner = MetaDataHelper.getOwnerString(account.getName(), - account.getHost(), - AccountActivity.this + String owner = MetaDataHelper.getOwnerString(account, + AccountActivity.this, true ); + // set view data TextView ownerStringView = findViewById(R.id.account_owner_string); ownerStringView.setText(owner); diff --git a/app/src/main/java/net/schueller/peertube/adapter/ChannelAdapter.java b/app/src/main/java/net/schueller/peertube/adapter/ChannelAdapter.java index ceca929..60d9690 100644 --- a/app/src/main/java/net/schueller/peertube/adapter/ChannelAdapter.java +++ b/app/src/main/java/net/schueller/peertube/adapter/ChannelAdapter.java @@ -94,15 +94,15 @@ public class ChannelAdapter extends RecyclerView.Adapter { - override fun onResponse( - call: Call, - response: Response - ) { - if (response.isSuccessful) { - binding.videoOwnerSubscribeButton.setText(string.subscribe) - isSubscribed = false - } + AlertDialog.Builder(context) + .setTitle(context.getString(string.video_sub_del_alert_title)) + .setMessage(context.getString(string.video_sub_del_alert_msg)) + .setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int -> + // Yes + val payload = video.channel.name + "@" + video.channel.host + val call = userService.unsubscribe(payload) + call.enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful) { + binding.videoOwnerSubscribeButton.setText(string.subscribe) + isSubscribed = false + } + } + override fun onFailure(call: Call, t: Throwable) { + // Do nothing. + } + }) } - override fun onFailure(call: Call, t: Throwable) { - // Do nothing. + .setNegativeButton(android.R.string.cancel) { _: DialogInterface?, _: Int -> + // No } - }) + .setIcon(android.R.drawable.ic_dialog_alert) + .show() } } else { Toast.makeText( @@ -337,7 +374,7 @@ sealed class MultiViewRecyclerViewHolder(binding: ViewBinding) : RecyclerView.Vi .into(binding.thumb) // Avatar - val avatar: Avatar? = video.account.avatar + val avatar = getCreatorAvatar(video, context) if (avatar != null) { val avatarPath = avatar.path Picasso.get() @@ -364,12 +401,8 @@ sealed class MultiViewRecyclerViewHolder(binding: ViewBinding) : RecyclerView.Vi ) // set owner - val displayNameAndHost = getOwnerString( - video.account.name, - video.account.host, - context - ) - binding.videoOwner.text = displayNameAndHost + val displayNameAndHost = getOwnerString(video.account, context, true) + binding.videoOwner.text = getCreatorString(video, context, true) // video owner click binding.videoOwner.setOnClickListener { diff --git a/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.kt b/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.kt index 3131ed0..1dcaae7 100644 --- a/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.kt +++ b/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.kt @@ -18,32 +18,92 @@ package net.schueller.peertube.helper import android.content.Context import android.text.format.DateUtils +import net.schueller.peertube.R import net.schueller.peertube.R.string +import net.schueller.peertube.model.Account +import net.schueller.peertube.model.Avatar +import net.schueller.peertube.model.Video import org.ocpsoft.prettytime.PrettyTime import java.util.Date import java.util.Locale +import kotlin.math.absoluteValue object MetaDataHelper { @JvmStatic - fun getMetaString(getCreatedAt: Date, viewCount: Int, context: Context): String { + fun getMetaString(getCreatedAt: Date, viewCount: Int, context: Context, reversed: Boolean = false): String { // Compatible with SDK 21+ val currentLanguage = Locale.getDefault().displayLanguage val p = PrettyTime(currentLanguage) val relativeTime = p.format(Date(getCreatedAt.time)) - return relativeTime + - context.resources.getString(string.meta_data_seperator) + - viewCount + context.resources.getString(string.meta_data_views) + return if (reversed) { + viewCount.toString() + + context.resources.getString(string.meta_data_views) + + context.resources.getString(string.meta_data_seperator) + + relativeTime + } else { + relativeTime + + context.resources.getString(string.meta_data_seperator) + + viewCount + context.resources.getString(string.meta_data_views) + } + } + + fun getTagsString(video: Video): String { + return if (video.tags.isNotEmpty()) { + " #" + video.tags.joinToString(" #", "", "", 3, "") + } else { + " " + } } @JvmStatic - fun getOwnerString(accountName: String, serverHost: String, context: Context): String { - return accountName + - context.resources.getString(string.meta_data_owner_seperator) + - serverHost + fun getCreatorString(video: Video, context: Context, fqdn: Boolean = false): String { + return if (isChannel(video)) { + if (!fqdn) { + video.channel.displayName + } else { + getConcatFqdnString(video.channel.name, video.channel.host, context) + } + } else { + getOwnerString(video.account, context, fqdn) + } } + @JvmStatic + fun getOwnerString(account: Account, context: Context, fqdn: Boolean = true): String { + return if (!fqdn) { + account.name + } else { + getConcatFqdnString(account.name, account.host, context) + } + } + + private fun getConcatFqdnString(user: String, host: String, context: Context): String { + return context.resources.getString(string.video_owner_fqdn_line, user, host) + } + + @JvmStatic + fun getCreatorAvatar(video: Video, context: Context): Avatar? { + return if (isChannel(video)) { + if (video.channel.avatar == null) { + video.account.avatar + } else { + video.channel.avatar + } + } else { + video.account.avatar + } + } + + @JvmStatic + fun isChannel(video: Video): Boolean { + // c285b523-d688-43c5-a9ad-f745ff09bbd1 + return !video.channel.name.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}".toRegex()) + } + + + @JvmStatic fun getDuration(duration: Long?): String { return DateUtils.formatElapsedTime(duration!!) diff --git a/app/src/main/res/layout/item_video_meta.xml b/app/src/main/res/layout/item_video_meta.xml index ab110c4..e15f7e5 100644 --- a/app/src/main/res/layout/item_video_meta.xml +++ b/app/src/main/res/layout/item_video_meta.xml @@ -13,6 +13,7 @@ + android:paddingStart="6dp" + android:paddingEnd="6dp" /> @@ -354,6 +355,13 @@ android:layout_height="wrap_content" android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" /> + + diff --git a/app/src/main/res/values/constants.xml b/app/src/main/res/values/constants.xml index 474066f..5c3eb17 100644 --- a/app/src/main/res/values/constants.xml +++ b/app/src/main/res/values/constants.xml @@ -58,7 +58,6 @@ {faw-download} {faw-save} - \@ \u0020-\u0020 VideoPlayActivity diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 35f9379..df6be17 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -376,4 +376,12 @@ Subscribe Unsubscribe Comments + + %1$d subscriber + %1$d subscribers + + By %1$s + %1$s@%2$s + Unsubscribe + Are you sure you would like to unsubscribe? \ No newline at end of file