Fix issue #1152 - Add a pinned Trending timeline (can be hidden in Manage Timelines)

This commit is contained in:
Thomas 2025-03-25 16:55:55 +01:00
parent 1b711d03eb
commit 2e66b1dad6
3 changed files with 50 additions and 11 deletions

View file

@ -183,15 +183,18 @@ public class PinnedTimelineHelper {
}
}
}
if (extraFeatures) {
try {
Pinned pinnedAll = new Pinned(activity).getAllPinned(Helper.getCurrentAccount(activity));
if (pinnedAll == null) {
pinnedAll = new Pinned();
pinnedAll.user_id = currentUserID;
pinnedAll.instance = currentInstance;
pinnedAll.pinnedTimelines = new ArrayList<>();
}
//Create other default timelines
try {
Pinned pinnedAll = new Pinned(activity).getAllPinned(Helper.getCurrentAccount(activity));
if (pinnedAll == null) {
pinnedAll = new Pinned();
pinnedAll.user_id = currentUserID;
pinnedAll.instance = currentInstance;
pinnedAll.pinnedTimelines = new ArrayList<>();
}
if (extraFeatures) {
//Bubble timeline
boolean createDefaultBubbleAtTop = true;
for (PinnedTimeline pinnedTimeline : pinnedAll.pinnedTimelines) {
if (pinnedTimeline.type == Timeline.TimeLineEnum.BUBBLE) {
@ -211,11 +214,34 @@ public class PinnedTimelineHelper {
new Pinned(activity).insertPinned(pinned);
}
}
} catch (DBException e) {
e.printStackTrace();
}
//Trend timeline
boolean createDefaultTrendAtTop = true;
for (PinnedTimeline pinnedTimeline : pinnedAll.pinnedTimelines) {
if (pinnedTimeline.type == Timeline.TimeLineEnum.TREND_MESSAGE) {
createDefaultTrendAtTop = false;
break;
}
}
if (createDefaultTrendAtTop) {
PinnedTimeline pinnedTimelineBubble = new PinnedTimeline();
pinnedTimelineBubble.type = Timeline.TimeLineEnum.TREND_MESSAGE;
pinnedTimelineBubble.position = pinnedAll.pinnedTimelines != null ? pinnedAll.pinnedTimelines.size() : 0;
pinned.pinnedTimelines.add(pinnedTimelineBubble);
boolean exist = new Pinned(activity).pinnedExist(pinned);
if (exist) {
new Pinned(activity).updatePinned(pinned);
} else {
new Pinned(activity).insertPinned(pinned);
}
}
} catch (DBException e) {
e.printStackTrace();
}
sortPositionAsc(pinnedTimelines);
//Check if changes occurred, if mastodonLists is null it does need, because it is the first call to draw pinned
boolean needRedraw = mastodonLists == null;
@ -413,6 +439,9 @@ public class PinnedTimelineHelper {
case BUBBLE:
tabCustomDefaultViewBinding.icon.setImageResource(R.drawable.ic_baseline_bubble_chart_24);
break;
case TREND_MESSAGE:
tabCustomDefaultViewBinding.icon.setImageResource(R.drawable.baseline_moving_24);
break;
}
tab.setCustomView(tabCustomDefaultViewBinding.getRoot());
}
@ -535,6 +564,7 @@ public class PinnedTimelineHelper {
break;
case HOME:
case LOCAL:
case TREND_MESSAGE:
case PUBLIC:
defaultClick(activity, pinnedTimelineVisibleList.get(position).type, v, activityMainBinding, finalI);
break;

View file

@ -150,6 +150,10 @@ public class ReorderTabAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
holder.binding.icon.setImageResource(R.drawable.ic_baseline_bubble_chart_24);
holder.binding.text.setText(R.string.bubble);
break;
case TREND_MESSAGE:
holder.binding.icon.setImageResource(R.drawable.baseline_moving_24);
holder.binding.text.setText(R.string.trending);
break;
}

View file

@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?attr/colorControlNormal" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M19.71,9.71L22,12V6h-6l2.29,2.29l-4.17,4.17c-0.39,0.39 -1.02,0.39 -1.41,0l-1.17,-1.17c-1.17,-1.17 -3.07,-1.17 -4.24,0L2,16.59L3.41,18l5.29,-5.29c0.39,-0.39 1.02,-0.39 1.41,0l1.17,1.17c1.17,1.17 3.07,1.17 4.24,0L19.71,9.71z"/>
</vector>