Add activity for timelines

This commit is contained in:
Thomas 2023-07-08 16:17:13 +02:00
parent c331cbeb26
commit 5ca288a04b
15 changed files with 233 additions and 3 deletions

View File

@ -265,6 +265,10 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/action_about"
android:theme="@style/AppThemeBar" />
<activity
android:name=".mastodon.activities.TimelineActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/AppThemeBar" />
<activity
android:name=".mastodon.activities.CheckHomeCacheActivity"
android:configChanges="keyboardHidden|orientation|screenSize"

View File

@ -0,0 +1,77 @@
package app.fedilab.android.mastodon.activities;
/* Copyright 2023 Thomas Schneider
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import android.os.Bundle;
import android.view.MenuItem;
import org.jetbrains.annotations.NotNull;
import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityTimelineBinding;
import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline;
import app.fedilab.android.mastodon.client.entities.app.Timeline;
import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.ui.fragment.timeline.FragmentMastodonTimeline;
public class TimelineActivity extends BaseBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app.fedilab.android.databinding.ActivityTimelineBinding binding = ActivityTimelineBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
Bundle b = getIntent().getExtras();
Timeline.TimeLineEnum timelineType = null;
String lemmy_post_id = null;
PinnedTimeline pinnedTimeline = null;
if (b != null) {
timelineType = (Timeline.TimeLineEnum) b.get(Helper.ARG_TIMELINE_TYPE);
lemmy_post_id = b.getString(Helper.ARG_LEMMY_POST_ID, null);
pinnedTimeline = (PinnedTimeline) b.getSerializable(Helper.ARG_REMOTE_INSTANCE);
}
if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null) {
setTitle(pinnedTimeline.remoteInstance.displayName);
}
FragmentMastodonTimeline fragmentMastodonTimeline = new FragmentMastodonTimeline();
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, timelineType);
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinnedTimeline);
bundle.putSerializable(Helper.ARG_LEMMY_POST_ID, lemmy_post_id);
fragmentMastodonTimeline.setArguments(bundle);
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container_view, fragmentMastodonTimeline).commit();
}
@Override
public boolean onOptionsItemSelected(@NotNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -22,6 +22,7 @@ import app.fedilab.android.mastodon.client.entities.api.Marker;
import app.fedilab.android.mastodon.client.entities.api.MastodonList;
import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.api.Tag;
import app.fedilab.android.mastodon.client.entities.lemmy.LemmyPost;
import app.fedilab.android.mastodon.client.entities.misskey.MisskeyNote;
import app.fedilab.android.mastodon.client.entities.nitter.Nitter;
import app.fedilab.android.mastodon.client.entities.peertube.PeertubeVideo;
@ -230,6 +231,15 @@ public interface MastodonTimelinesService {
Call<List<MisskeyNote>> getMisskey(@Body MisskeyNote.MisskeyParams params);
@GET("api/v3/post/list")
Call<List<LemmyPost>> getLemmyMain(@Query("limit") Integer limit,
@Query("page") String page);
@GET("api/v3/comment/list")
Call<List<LemmyPost>> getLemmyThread(@Query("post_id") String post_id,
@Query("limit") Integer limit,
@Query("page") String page);
//Public timelines for Misskey
@FormUrlEncoded
@POST("api/notes")

View File

@ -259,6 +259,8 @@ public class Helper {
public static final String ARG_STATUS_ID = "ARG_STATUS_ID";
public static final String ARG_WORK_ID = "ARG_WORK_ID";
public static final String ARG_LIST_ID = "ARG_LIST_ID";
public static final String ARG_LEMMY_POST_ID = "ARG_LEMMY_POST_ID";
public static final String ARG_SEARCH_KEYWORD = "ARG_SEARCH_KEYWORD";
public static final String ARG_DIRECTORY_ORDER = "ARG_DIRECTORY_ORDER";
public static final String ARG_DIRECTORY_LOCAL = "ARG_DIRECTORY_LOCAL";

View File

@ -370,7 +370,9 @@ public class PinnedTimelineHelper {
case MASTODON:
tabCustomViewBinding.icon.setImageResource(R.drawable.mastodon_icon_item);
break;
case LEMMY:
tabCustomViewBinding.icon.setImageResource(R.drawable.lemmy);
break;
case MISSKEY:
tabCustomViewBinding.icon.setImageResource(R.drawable.misskey);
break;
@ -461,6 +463,9 @@ public class PinnedTimelineHelper {
case MISSKEY:
item.setIcon(R.drawable.misskey);
break;
case LEMMY:
item.setIcon(R.drawable.lemmy);
break;
case PIXELFED:
item.setIcon(R.drawable.pixelfed);
break;

View File

@ -139,6 +139,7 @@ import app.fedilab.android.mastodon.activities.ProfileActivity;
import app.fedilab.android.mastodon.activities.ReportActivity;
import app.fedilab.android.mastodon.activities.StatusHistoryActivity;
import app.fedilab.android.mastodon.activities.StatusInfoActivity;
import app.fedilab.android.mastodon.activities.TimelineActivity;
import app.fedilab.android.mastodon.activities.admin.AdminAccountActivity;
import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Poll;
@ -146,6 +147,8 @@ import app.fedilab.android.mastodon.client.entities.api.Reaction;
import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.app.Account;
import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline;
import app.fedilab.android.mastodon.client.entities.app.RemoteInstance;
import app.fedilab.android.mastodon.client.entities.app.StatusCache;
import app.fedilab.android.mastodon.client.entities.app.StatusDraft;
import app.fedilab.android.mastodon.client.entities.app.Timeline;
@ -187,6 +190,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private final List<Status> statusList;
private final boolean minified;
private final Timeline.TimeLineEnum timelineType;
public RemoteInstance.InstanceType type;
public String lemmy_post_id;
public PinnedTimeline pinnedTimeline;
private final boolean canBeFederated;
private final boolean checkRemotely;
public FetchMoreCallBack fetchMoreCallBack;
@ -1989,7 +1995,18 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
((ContextActivity) context).setCurrentFragment((FragmentMastodonContext) fragment);
} else {
if (remote) {
if (!(context instanceof ContextActivity)) { //We are not already checking a remote conversation
//Lemmy main post that should open Lemmy threads
if (adapter instanceof StatusAdapter && ((StatusAdapter) adapter).type == RemoteInstance.InstanceType.LEMMY && ((StatusAdapter) adapter).lemmy_post_id == null) {
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, ((StatusAdapter) adapter).pinnedTimeline);
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
bundle.putSerializable(Helper.ARG_LEMMY_POST_ID, ((StatusAdapter) adapter).lemmy_post_id);
Intent intent = new Intent(context, TimelineActivity.class);
intent.putExtras(bundle);
context.startActivity(intent);
} //Classic other cases for remote instances that will search the remote context
else if (!(context instanceof ContextActivity)) { //We are not already checking a remote conversation
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {

View File

@ -89,6 +89,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private List<Status> timelineStatuses;
private boolean retry_for_home_done;
private String lemmy_post_id;
//Handle actions that can be done in other fragments
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
@ -382,6 +383,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
retry_for_home_done = false;
if (getArguments() != null) {
timelineType = (Timeline.TimeLineEnum) getArguments().get(Helper.ARG_TIMELINE_TYPE);
lemmy_post_id = getArguments().getString(Helper.ARG_LEMMY_POST_ID, null);
list_id = getArguments().getString(Helper.ARG_LIST_ID, null);
search = getArguments().getString(Helper.ARG_SEARCH_KEYWORD, null);
searchCache = getArguments().getString(Helper.ARG_SEARCH_KEYWORD_CACHE, null);
@ -625,6 +627,14 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
}
statusAdapter = new StatusAdapter(timelineStatuses, timelineType, minified, canBeFederated, checkRemotely);
statusAdapter.fetchMoreCallBack = this;
statusAdapter.pinnedTimeline = pinnedTimeline;
//------Specifications for Lemmy timelines
if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null) {
statusAdapter.type = pinnedTimeline.remoteInstance.type;
}
statusAdapter.lemmy_post_id = lemmy_post_id;
//---------------
if (statusReport != null) {
scrollToTop();
}
@ -1019,7 +1029,27 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
}
});
}
} //PEERTUBE TIMELINES
} //LEMMY TIMELINES
else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.LEMMY) {
if (direction == null) {
timelinesVM.getLemmy(remoteInstance, lemmy_post_id, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getLemmy(remoteInstance, lemmy_post_id, max_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else if (direction == DIRECTION.TOP) {
flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) {
timelinesVM.getLemmy(remoteInstance, lemmy_post_id, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true, true, fetchStatus);
} else {
initializeStatusesCommonView(statusesRefresh);
}
});
}
}//PEERTUBE TIMELINES
else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.PEERTUBE) {
if (direction == null) {
timelinesVM.getPeertube(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))

View File

@ -52,6 +52,7 @@ import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
import app.fedilab.android.mastodon.client.entities.app.StatusCache;
import app.fedilab.android.mastodon.client.entities.app.StatusDraft;
import app.fedilab.android.mastodon.client.entities.app.Timeline;
import app.fedilab.android.mastodon.client.entities.lemmy.LemmyPost;
import app.fedilab.android.mastodon.client.entities.misskey.MisskeyNote;
import app.fedilab.android.mastodon.client.entities.nitter.Nitter;
import app.fedilab.android.mastodon.client.entities.peertube.PeertubeVideo;
@ -335,6 +336,60 @@ public class TimelinesVM extends AndroidViewModel {
return statusesMutableLiveData;
}
/**
* Public timeline for Lemmy
*
* @param post_id Return comments for post_id, if null it's for main threads
* @param page Return results from this page
* @param limit Maximum number of results to return. Defaults to 20.
* @return {@link LiveData} containing a {@link Statuses}
*/
public LiveData<Statuses> getLemmy(@NonNull String instance, String post_id,
String page,
Integer limit) {
MastodonTimelinesService mastodonTimelinesService = initInstanceOnly(instance);
statusesMutableLiveData = new MutableLiveData<>();
new Thread(() -> {
Call<List<LemmyPost>> publicTlCall;
if (post_id == null) {
publicTlCall = mastodonTimelinesService.getLemmyMain(limit, page);
} else {
publicTlCall = mastodonTimelinesService.getLemmyThread(post_id, limit, page);
}
Statuses statuses = new Statuses();
if (publicTlCall != null) {
try {
Response<List<LemmyPost>> publicTlResponse = publicTlCall.execute();
if (publicTlResponse.isSuccessful()) {
List<LemmyPost> lemmyPostList = publicTlResponse.body();
List<Status> statusList = new ArrayList<>();
if (lemmyPostList != null) {
for (LemmyPost lemmyPost : lemmyPostList) {
Status status = LemmyPost.convert(lemmyPost, instance);
statusList.add(status);
}
}
statuses.statuses = TimelineHelper.filterStatus(getApplication(), statusList, Timeline.TimeLineEnum.PUBLIC);
statuses.pagination = new Pagination();
if (statusList.size() > 0) {
statuses.pagination.min_id = statusList.get(0).id;
statuses.pagination.max_id = statusList.get(statusList.size() - 1).id;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> statusesMutableLiveData.setValue(statuses);
mainHandler.post(myRunnable);
}).start();
return statusesMutableLiveData;
}
/**
* Public timeline for Peertube
*

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M21,6h-7.59l3.29,-3.29L16,2l-4,4 -4,-4 -0.71,0.71L10.59,6L3,6c-1.1,0 -2,0.89 -2,2v12c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,8c0,-1.11 -0.9,-2 -2,-2zM21,20L3,20L3,8h18v12zM9,10v8l7,-4z" />
</vector>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2023 Thomas Schneider
This file is a part of Fedilab
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 3 of the
License, or (at your option) any later version.
Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with Fedilab; if not,
see <http://www.gnu.org/licenses>.
-->
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />