Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show toot stat inline #3413

Merged
merged 17 commits into from
Mar 18, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ public void setMediaPreviewEnabled(boolean mediaPreviewEnabled) {
statusDisplayOptions.confirmReblogs(),
statusDisplayOptions.confirmFavourites(),
statusDisplayOptions.hideStats(),
statusDisplayOptions.animateEmojis()
statusDisplayOptions.animateEmojis(),
statusDisplayOptions.showStatsInline()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.keylesspalace.tusky.util.CustomEmojiHelper;
import com.keylesspalace.tusky.util.ImageLoadingHelper;
import com.keylesspalace.tusky.util.LinkHelper;
import com.keylesspalace.tusky.util.NumberUtilsKt;
import com.keylesspalace.tusky.util.StatusDisplayOptions;
import com.keylesspalace.tusky.util.TimestampUtils;
import com.keylesspalace.tusky.util.TouchDelegateHelper;
Expand Down Expand Up @@ -80,7 +81,9 @@ public static class Key {
private final ImageButton replyButton;
private final TextView replyCountLabel;
private final SparkButton reblogButton;
private final TextView reblogsCountLabel;
private final SparkButton favouriteButton;
private final TextView favouritedCountLabel;
private final SparkButton bookmarkButton;
private final ImageButton moreButton;
private final ConstraintLayout mediaContainer;
Expand Down Expand Up @@ -127,8 +130,10 @@ protected StatusBaseViewHolder(View itemView) {
avatar = itemView.findViewById(R.id.status_avatar);
replyButton = itemView.findViewById(R.id.status_reply);
replyCountLabel = itemView.findViewById(R.id.status_replies);
reblogsCountLabel = itemView.findViewById(R.id.status_insets);
reblogButton = itemView.findViewById(R.id.status_inset);
favouriteButton = itemView.findViewById(R.id.status_favourite);
favouritedCountLabel = itemView.findViewById(R.id.status_favourites_count);
bookmarkButton = itemView.findViewById(R.id.status_bookmark);
moreButton = itemView.findViewById(R.id.status_more);

Expand Down Expand Up @@ -380,7 +385,19 @@ protected void setIsReply(boolean isReply) {
private void setReplyCount(int repliesCount) {
// This label only exists in the non-detailed view (to match the web ui)
if (replyCountLabel != null) {
replyCountLabel.setText((repliesCount > 1 ? replyCountLabel.getContext().getString(R.string.status_count_one_plus) : Integer.toString(repliesCount)));
replyCountLabel.setText(NumberUtilsKt.shortNumber(repliesCount));
}
}

private void setReblogsCount(int reblogsCount) {
if (reblogsCountLabel != null) {
reblogsCountLabel.setText(NumberUtilsKt.shortNumber(reblogsCount));
}
}

private void setFavouritedCount(int favouritedCount) {
if (favouritedCountLabel != null) {
favouritedCountLabel.setText(NumberUtilsKt.shortNumber(favouritedCount));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it does not affect conversations or detailed statuses, all these changes should be in StatusViewHolder. No more null check necessary then.

}
}

Expand Down Expand Up @@ -615,12 +632,21 @@ protected void setupButtons(final StatusActionListener listener,
avatar.setOnClickListener(profileButtonClickListener);
displayName.setOnClickListener(profileButtonClickListener);

if (replyCountLabel != null) {
replyCountLabel.setVisibility(statusDisplayOptions.showStatsInline() ? View.VISIBLE : View.INVISIBLE);
}

replyButton.setOnClickListener(v -> {
int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
listener.onReply(position);
}
});

if (reblogsCountLabel != null) {
reblogsCountLabel.setVisibility(statusDisplayOptions.showStatsInline() ? View.VISIBLE : View.INVISIBLE);
}

if (reblogButton != null) {
reblogButton.setEventListener((button, buttonState) -> {
// return true to play animation
Expand All @@ -639,6 +665,10 @@ protected void setupButtons(final StatusActionListener listener,
});
}

if (favouritedCountLabel != null) {
favouritedCountLabel.setVisibility(statusDisplayOptions.showStatsInline() ? View.VISIBLE : View.INVISIBLE);
}

favouriteButton.setEventListener((button, buttonState) -> {
// return true to play animation
int position = getBindingAdapterPosition();
Expand Down Expand Up @@ -733,6 +763,8 @@ public void setupWithStatus(@NonNull StatusViewData.Concrete status,
setMetaData(status, statusDisplayOptions, listener);
setIsReply(actionable.getInReplyToId() != null);
setReplyCount(actionable.getRepliesCount());
setReblogsCount(actionable.getReblogsCount());
setFavouritedCount(actionable.getFavouritesCount());
setAvatar(actionable.getAccount().getAvatar(), status.getRebloggedAvatar(),
actionable.getAccount().getBot(), statusDisplayOptions);
setReblogged(actionable.getReblogged());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class ConversationsFragment :
confirmReblogs = preferences.getBoolean("confirmReblogs", true),
confirmFavourites = preferences.getBoolean("confirmFavourites", false),
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
showStatsInline = preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false)
)

adapter = ConversationAdapter(statusDisplayOptions, this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class PreferencesActivity :
}
"statusTextSize", "absoluteTimeView", "showBotOverlay", "animateGifAvatars", "useBlurhash",
"showSelfUsername", "showCardsInTimelines", "confirmReblogs", "confirmFavourites",
"enableSwipeForTabs", "mainNavPosition", PrefKeys.HIDE_TOP_TOOLBAR -> {
"enableSwipeForTabs", "mainNavPosition", PrefKeys.HIDE_TOP_TOOLBAR, PrefKeys.SHOW_STATS_INLINE -> {
restartActivitiesOnBackPressedCallback.isEnabled = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ class PreferencesFragment : PreferenceFragmentCompat(), Injectable {
setTitle(R.string.pref_title_enable_swipe_for_tabs)
isSingleLineTitle = false
}

switchPreference {
setDefaultValue(false)
key = PrefKeys.SHOW_STATS_INLINE
setTitle(R.string.pref_title_show_stat_inline)
isSingleLineTitle = false
}
}

preferenceCategory(R.string.pref_title_browser_settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ class ReportStatusesFragment :
confirmReblogs = preferences.getBoolean("confirmReblogs", true),
confirmFavourites = preferences.getBoolean("confirmFavourites", false),
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
showStatsInline = preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false)
)

adapter = StatusesAdapter(statusDisplayOptions, viewModel.statusViewState, this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class SearchStatusesFragment : SearchFragment<StatusViewData.Concrete>(), Status
confirmReblogs = preferences.getBoolean("confirmReblogs", true),
confirmFavourites = preferences.getBoolean("confirmFavourites", false),
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
showStatsInline = preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false)
)

binding.searchRecyclerView.addItemDecoration(DividerItemDecoration(binding.searchRecyclerView.context, DividerItemDecoration.VERTICAL))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ class TimelineFragment :
confirmReblogs = preferences.getBoolean(PrefKeys.CONFIRM_REBLOGS, true),
confirmFavourites = preferences.getBoolean(PrefKeys.CONFIRM_FAVOURITES, false),
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
showStatsInline = preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false)
)
adapter = TimelinePagingAdapter(
statusDisplayOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class ViewThreadFragment :
confirmReblogs = preferences.getBoolean("confirmReblogs", true),
confirmFavourites = preferences.getBoolean("confirmFavourites", false),
hideStats = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
showStatsInline = preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false)
)
adapter = ThreadAdapter(statusDisplayOptions, this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
preferences.getBoolean("confirmReblogs", true),
preferences.getBoolean("confirmFavourites", false),
preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false),
preferences.getBoolean(PrefKeys.SHOW_STATS_INLINE, false)
);

adapter = new NotificationsAdapter(accountManager.getActiveAccount().getAccountId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ object PrefKeys {
const val CONFIRM_FAVOURITES = "confirmFavourites"
const val ENABLE_SWIPE_FOR_TABS = "enableSwipeForTabs"
const val ANIMATE_CUSTOM_EMOJIS = "animateCustomEmojis"
const val SHOW_STATS_INLINE = "showStatsInline"

const val CUSTOM_TABS = "customTabs"
const val WELLBEING_LIMITED_NOTIFICATIONS = "wellbeingModeLimitedNotifications"
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/keylesspalace/tusky/util/NumberUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.keylesspalace.tusky.util
zikasak marked this conversation as resolved.
Show resolved Hide resolved

import java.text.DecimalFormat
import kotlin.math.floor
import kotlin.math.log10
import kotlin.math.pow

fun shortNumber(number: Number): String {
zikasak marked this conversation as resolved.
Show resolved Hide resolved
val array = arrayOf(' ', 'k', 'M', 'B', 'T', 'P', 'E')
zikasak marked this conversation as resolved.
Show resolved Hide resolved
val value = floor(log10(number.toDouble())).toInt()
val base = value / 3
if (value >= 3 && base < array.size) {
return DecimalFormat("#0.0").format(number.toDouble() / 10.0.pow((base * 3).toDouble())) + array[base]
} else {
return DecimalFormat("#,##0").format(number)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ data class StatusDisplayOptions(
@get:JvmName("hideStats")
val hideStats: Boolean,
@get:JvmName("animateEmojis")
val animateEmojis: Boolean
val animateEmojis: Boolean,
@get:JvmName("showStatsInline")
val showStatsInline: Boolean
)
22 changes: 22 additions & 0 deletions app/src/main/res/layout/item_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@
sparkbutton:primaryColor="@color/tusky_blue"
sparkbutton:secondaryColor="@color/tusky_blue_light" />

<TextView
zikasak marked this conversation as resolved.
Show resolved Hide resolved
android:id="@+id/status_insets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:textSize="?attr/status_text_medium"
app:layout_constraintBottom_toBottomOf="@id/status_inset"
app:layout_constraintStart_toStartOf="@id/status_inset"
app:layout_constraintTop_toTopOf="@id/status_inset"
tools:text="1+" />

<at.connyduck.sparkbutton.SparkButton
android:id="@+id/status_favourite"
android:layout_width="52dp"
Expand All @@ -370,6 +381,17 @@
sparkbutton:primaryColor="@color/tusky_orange"
sparkbutton:secondaryColor="@color/tusky_orange_light" />

<TextView
android:id="@+id/status_favourites_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:textSize="?attr/status_text_medium"
app:layout_constraintBottom_toBottomOf="@id/status_inset"
app:layout_constraintStart_toStartOf="@id/status_favourite"
app:layout_constraintTop_toTopOf="@id/status_inset"
tools:text="" />

<at.connyduck.sparkbutton.SparkButton
android:id="@+id/status_bookmark"
android:layout_width="52dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@

<string name="pref_title_show_notifications_filter">Show Notifications filter</string>
<string name="pref_title_enable_swipe_for_tabs">Enable swipe gesture to switch between tabs</string>
<string name="pref_title_show_stat_inline">Show toot statistics</string>
zikasak marked this conversation as resolved.
Show resolved Hide resolved


<string name="create_poll_title">Poll</string>
Expand Down