Some fixes

This commit is contained in:
Thomas 2022-05-04 11:22:51 +02:00
parent 4fb0f168c8
commit 735882fb7e
19 changed files with 152 additions and 92 deletions

View file

@ -60,6 +60,7 @@ public class ActionActivity extends BaseActivity {
fragmentMastodonAccount = new FragmentMastodonAccount(); fragmentMastodonAccount = new FragmentMastodonAccount();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, type); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, type);
bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + type.getValue());
fragmentMastodonAccount.setArguments(bundle); fragmentMastodonAccount.setArguments(bundle);
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = FragmentTransaction fragmentTransaction =
@ -74,6 +75,7 @@ public class ActionActivity extends BaseActivity {
fragmentMastodonTimeline = new FragmentMastodonTimeline(); fragmentMastodonTimeline = new FragmentMastodonTimeline();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, type); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, type);
bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + type.getValue());
fragmentMastodonTimeline.setArguments(bundle); fragmentMastodonTimeline.setArguments(bundle);
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = FragmentTransaction fragmentTransaction =

View file

@ -119,7 +119,7 @@ public class StatusInfoActivity extends BaseActivity {
startId = accountList.size(); startId = accountList.size();
} }
accountList.addAll(accounts.accounts); accountList.addAll(accounts.accounts);
max_id = accounts.pagination.min_id; max_id = accounts.pagination.max_id;
accountAdapter.notifyItemRangeInserted(startId, accounts.accounts.size()); accountAdapter.notifyItemRangeInserted(startId, accounts.accounts.size());
} }
} }

View file

@ -29,12 +29,12 @@ public interface MastodonSearchService {
@Query("q") String q, @Query("q") String q,
@Query("account_id") String account_id, @Query("account_id") String account_id,
@Query("type") String type, @Query("type") String type,
@Query("exclude_unreviewed") boolean exclude_unreviewed, @Query("exclude_unreviewed") Boolean exclude_unreviewed,
@Query("resolve") boolean resolve, @Query("resolve") Boolean resolve,
@Query("following") boolean following, @Query("following") Boolean following,
@Query("offset") int offset, @Query("offset") Integer offset,
@Query("max_id") String max_id, @Query("max_id") String max_id,
@Query("min_id") String min_id, @Query("min_id") String min_id,
@Query("limit") int limit @Query("limit") Integer limit
); );
} }

View file

@ -38,13 +38,13 @@ public interface MastodonTimelinesService {
@GET("timelines/public") @GET("timelines/public")
Call<List<Status>> getPublic( Call<List<Status>> getPublic(
@Header("Authorization") String token, @Header("Authorization") String token,
@Query("local") boolean local, @Query("local") Boolean local,
@Query("remote") boolean remote, @Query("remote") Boolean remote,
@Query("only_media") boolean only_media, @Query("only_media") Boolean only_media,
@Query("max_id") String max_id, @Query("max_id") String max_id,
@Query("since_id") String since_id, @Query("since_id") String since_id,
@Query("min_id") String min_id, @Query("min_id") String min_id,
@Query("limit") int limit @Query("limit") Integer limit
); );
//Public Tags timelines //Public Tags timelines

View file

@ -15,6 +15,7 @@ package app.fedilab.android.helper;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -31,6 +32,7 @@ import java.util.List;
import app.fedilab.android.BaseMainActivity; import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.activities.ComposeActivity;
import app.fedilab.android.client.entities.Account; import app.fedilab.android.client.entities.Account;
import app.fedilab.android.client.mastodon.entities.Status; import app.fedilab.android.client.mastodon.entities.Status;
import app.fedilab.android.exception.DBException; import app.fedilab.android.exception.DBException;
@ -224,6 +226,12 @@ public class CrossActionHelper {
statusesVM.unReblog(ownerAccount.instance, ownerAccount.token, targetedStatus.id) statusesVM.unReblog(ownerAccount.instance, ownerAccount.token, targetedStatus.id)
.observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_unreblog), Toasty.LENGTH_SHORT).show()); .observe((LifecycleOwner) context, status -> Toasty.info(context, context.getString(R.string.toast_unreblog), Toasty.LENGTH_SHORT).show());
break; break;
case REPLY_ACTION:
Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_STATUS_REPLY, targetedStatus);
intent.putExtra(Helper.ARG_ACCOUNT, ownerAccount);
context.startActivity(intent);
break;
} }
} }
@ -239,6 +247,7 @@ public class CrossActionHelper {
BOOKMARK_ACTION, BOOKMARK_ACTION,
UNBOOKMARK_ACTION, UNBOOKMARK_ACTION,
REBLOG_ACTION, REBLOG_ACTION,
UNREBLOG_ACTION UNREBLOG_ACTION,
REPLY_ACTION
} }
} }

View file

@ -42,20 +42,17 @@ import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern;
import app.fedilab.android.BaseMainActivity; import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.client.entities.ScheduledBoost; import app.fedilab.android.client.entities.ScheduledBoost;
import app.fedilab.android.client.mastodon.entities.Account; import app.fedilab.android.client.mastodon.entities.Account;
import app.fedilab.android.client.mastodon.entities.Conversation;
import app.fedilab.android.client.mastodon.entities.Notification;
import app.fedilab.android.client.mastodon.entities.Pagination; import app.fedilab.android.client.mastodon.entities.Pagination;
import app.fedilab.android.client.mastodon.entities.RelationShip; import app.fedilab.android.client.mastodon.entities.RelationShip;
import app.fedilab.android.client.mastodon.entities.ScheduledStatus;
import app.fedilab.android.client.mastodon.entities.Status; import app.fedilab.android.client.mastodon.entities.Status;
import app.fedilab.android.databinding.DatetimePickerBinding; import app.fedilab.android.databinding.DatetimePickerBinding;
import app.fedilab.android.exception.DBException; import app.fedilab.android.exception.DBException;
@ -63,6 +60,7 @@ import app.fedilab.android.jobs.ScheduleBoostWorker;
import app.fedilab.android.ui.drawer.ComposeAdapter; import app.fedilab.android.ui.drawer.ComposeAdapter;
import app.fedilab.android.viewmodel.mastodon.AccountsVM; import app.fedilab.android.viewmodel.mastodon.AccountsVM;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
import okhttp3.Headers;
public class MastodonHelper { public class MastodonHelper {
@ -114,13 +112,13 @@ public class MastodonHelper {
return "https://" + instance + "/oauth/authorize" + "?" + queryString; return "https://" + instance + "/oauth/authorize" + "?" + queryString;
} }
/* /** /**
* Retrieve pagination from header * Retrieve pagination from header
* *
* @param headers Headers * @param headers Headers
* @return Pagination * @return Pagination
*/ */
/* public static Pagination getPagination(Headers headers) { public static Pagination getPagination(Headers headers) {
String link = headers.get("Link"); String link = headers.get("Link");
Pagination pagination = new Pagination(); Pagination pagination = new Pagination();
if (link != null) { if (link != null) {
@ -141,9 +139,9 @@ public class MastodonHelper {
} }
} }
return pagination; return pagination;
}*/ }
public static Pagination getPaginationNotification(List<Notification> notificationList) { /*public static Pagination getPaginationNotification(List<Notification> notificationList) {
Pagination pagination = new Pagination(); Pagination pagination = new Pagination();
if (notificationList == null || notificationList.size() == 0) { if (notificationList == null || notificationList.size() == 0) {
return pagination; return pagination;
@ -192,7 +190,7 @@ public class MastodonHelper {
pagination.min_id = conversationList.get(conversationList.size() - 1).id; pagination.min_id = conversationList.get(conversationList.size() - 1).id;
return pagination; return pagination;
} }
*/
public static void loadPPMastodon(ImageView view, app.fedilab.android.client.mastodon.entities.Account account) { public static void loadPPMastodon(ImageView view, app.fedilab.android.client.mastodon.entities.Account account) {
loadProfileMediaMastodon(view, account, MediaAccountType.AVATAR); loadProfileMediaMastodon(view, account, MediaAccountType.AVATAR);
} }

View file

@ -114,7 +114,7 @@ public class NotificationsHelper {
} }
} }
} }
notifications.pagination = MastodonHelper.getPaginationNotification(notifications.notifications); notifications.pagination = MastodonHelper.getPagination(notificationsResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -49,11 +49,16 @@ public class TimelineHelper {
//A security to make sure filters have been fetched before displaying messages //A security to make sure filters have been fetched before displaying messages
List<Status> statusesToRemove = new ArrayList<>(); List<Status> statusesToRemove = new ArrayList<>();
if (!BaseMainActivity.filterFetched) { if (!BaseMainActivity.filterFetched) {
AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class); try {
accountsVM.getFilters(BaseMainActivity.currentInstance, BaseMainActivity.currentToken).observe((LifecycleOwner) context, filters -> { AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class);
BaseMainActivity.filterFetched = true; accountsVM.getFilters(BaseMainActivity.currentInstance, BaseMainActivity.currentToken).observe((LifecycleOwner) context, filters -> {
BaseMainActivity.mainFilters = filters; BaseMainActivity.filterFetched = true;
}); BaseMainActivity.mainFilters = filters;
});
} catch (ClassCastException e) {
e.printStackTrace();
return statuses;
}
} }
//If there are filters: //If there are filters:
if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0) { if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0) {

View file

@ -174,6 +174,16 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
// start the new activity // start the new activity
context.startActivity(intent, options.toBundle()); context.startActivity(intent, options.toBundle());
}); });
holderStatus.bindingNotification.status.statusUserInfo.setOnClickListener(v -> {
Intent intent = new Intent(context, ProfileActivity.class);
Bundle b = new Bundle();
b.putSerializable(Helper.ARG_ACCOUNT, notification.account);
intent.putExtras(b);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, holderStatus.bindingNotification.status.avatar, context.getString(R.string.activity_porfile_pp));
// start the new activity
context.startActivity(intent, options.toBundle());
});
holderStatus.bindingNotification.status.displayName.setText(title); holderStatus.bindingNotification.status.displayName.setText(title);
holderStatus.bindingNotification.status.username.setText(String.format("@%s", notification.account.acct)); holderStatus.bindingNotification.status.username.setText(String.format("@%s", notification.account.acct));
holderStatus.bindingNotification.status.actionButtons.setVisibility(View.GONE); holderStatus.bindingNotification.status.actionButtons.setVisibility(View.GONE);

View file

@ -236,7 +236,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
while (matcherAcct.find()) { while (matcherAcct.find()) {
int matchStart = matcherAcct.start(1); int matchStart = matcherAcct.start(1);
int matchEnd = matcherAcct.end(); int matchEnd = matcherAcct.end();
if (wordToSpan.length() >= matchEnd && matchStart < matchEnd) { if (wordToSpan.length() >= matchEnd && matchStart < matchEnd && matchStart >= 0) {
wordToSpan.setSpan(new ForegroundColorSpan(theme_text_header_2_line), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); wordToSpan.setSpan(new ForegroundColorSpan(theme_text_header_2_line), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
} }
} }
@ -330,6 +330,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}); });
holder.binding.actionButtonBookmark.setOnClickListener(v -> { holder.binding.actionButtonBookmark.setOnClickListener(v -> {
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
@ -366,10 +367,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.actionButtonFavorite.setChecked(statusToDeal.favourited); holder.binding.actionButtonFavorite.setChecked(statusToDeal.favourited);
holder.binding.statusUserInfo.setOnClickListener(v -> { holder.binding.statusUserInfo.setOnClickListener(v -> {
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0); Status fetchedStatus = results.statuses.get(0);
Intent intent = new Intent(context, ProfileActivity.class); Intent intent = new Intent(context, ProfileActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.reblog != null ? fetchedStatus.reblog.account : fetchedStatus.account); b.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.reblog != null ? fetchedStatus.reblog.account : fetchedStatus.account);
@ -395,10 +397,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}); });
holder.binding.statusBoosterAvatar.setOnClickListener(v -> { holder.binding.statusBoosterAvatar.setOnClickListener(v -> {
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0); Status fetchedStatus = results.statuses.get(0);
Intent intent = new Intent(context, ProfileActivity.class); Intent intent = new Intent(context, ProfileActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.account); b.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.account);
@ -440,10 +443,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> { alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> {
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0); Status fetchedStatus = results.statuses.get(0);
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null) statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null)
.observe((LifecycleOwner) context, _status -> { .observe((LifecycleOwner) context, _status -> {
statusToDeal.reblogged = _status.reblogged; statusToDeal.reblogged = _status.reblogged;
@ -482,10 +486,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
alert.show(); alert.show();
} else { } else {
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0); Status fetchedStatus = results.statuses.get(0);
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null) statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null)
.observe((LifecycleOwner) context, _status -> { .observe((LifecycleOwner) context, _status -> {
statusToDeal.reblogged = _status.reblogged; statusToDeal.reblogged = _status.reblogged;
@ -538,10 +543,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> { alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> {
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0); Status fetchedStatus = results.statuses.get(0);
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id) statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
.observe((LifecycleOwner) context, _status -> { .observe((LifecycleOwner) context, _status -> {
statusToDeal.favourited = _status.favourited; statusToDeal.favourited = _status.favourited;
@ -579,10 +585,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
alert.show(); alert.show();
} else { } else {
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0); Status fetchedStatus = results.statuses.get(0);
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id) statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
.observe((LifecycleOwner) context, _status -> { .observe((LifecycleOwner) context, _status -> {
statusToDeal.favourited = _status.favourited; statusToDeal.favourited = _status.favourited;
@ -855,10 +862,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.reblogInfo.setOnClickListener(v -> { holder.binding.reblogInfo.setOnClickListener(v -> {
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0); Status fetchedStatus = results.statuses.get(0);
if (fetchedStatus.reblogs_count > 0) { if (fetchedStatus.reblogs_count > 0) {
Intent intent = new Intent(context, StatusInfoActivity.class); Intent intent = new Intent(context, StatusInfoActivity.class);
intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.BOOSTED_BY); intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.BOOSTED_BY);
@ -881,10 +889,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.favouriteInfo.setOnClickListener(v -> { holder.binding.favouriteInfo.setOnClickListener(v -> {
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0); Status fetchedStatus = results.statuses.get(0);
if (fetchedStatus.favourites_count > 0) { if (fetchedStatus.favourites_count > 0) {
Intent intent = new Intent(context, StatusInfoActivity.class); Intent intent = new Intent(context, StatusInfoActivity.class);
intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.LIKED_BY); intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.LIKED_BY);
@ -1004,10 +1013,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
//Vote on the poll //Vote on the poll
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0); Status fetchedStatus = results.statuses.get(0);
statusesVM.votePoll(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.poll.id, choice) statusesVM.votePoll(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.poll.id, choice)
.observe((LifecycleOwner) context, poll -> { .observe((LifecycleOwner) context, poll -> {
int i = 0; int i = 0;
@ -1084,10 +1094,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
((ContextActivity) context).setCurrentFragment((FragmentMastodonContext) fragment); ((ContextActivity) context).setCurrentFragment((FragmentMastodonContext) fragment);
} else { } else {
if (remote) { if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0); Status fetchedStatus = results.statuses.get(0);
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, fetchedStatus); intent.putExtra(Helper.ARG_STATUS, fetchedStatus);
context.startActivity(intent); context.startActivity(intent);
@ -1354,10 +1365,29 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}); });
popup.show(); popup.show();
}); });
holder.binding.actionButtonReply.setOnLongClickListener(v -> {
CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.REPLY_ACTION, null, statusToDeal);
return true;
});
holder.binding.actionButtonReply.setOnClickListener(v -> { holder.binding.actionButtonReply.setOnClickListener(v -> {
Intent intent = new Intent(context, ComposeActivity.class); if (remote) {
intent.putExtra(Helper.ARG_STATUS_REPLY, statusToDeal); Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
context.startActivity(intent); searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0);
Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_STATUS_REPLY, fetchedStatus);
context.startActivity(intent);
} else {
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
}
});
} else {
Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_STATUS_REPLY, statusToDeal);
context.startActivity(intent);
}
}); });
//For reports //For reports

View file

@ -202,7 +202,7 @@ public class FragmentMastodonAccount extends Fragment {
binding.recyclerView.setAdapter(accountAdapter); binding.recyclerView.setAdapter(accountAdapter);
//Fetch the relationship //Fetch the relationship
fetchRelationShip(accounts.accounts, 0); fetchRelationShip(accounts.accounts, 0);
max_id = accounts.pagination.min_id; max_id = accounts.pagination.max_id;
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
@ -253,7 +253,7 @@ public class FragmentMastodonAccount extends Fragment {
accounts.addAll(fetched_accounts.accounts); accounts.addAll(fetched_accounts.accounts);
//Fetch the relationship //Fetch the relationship
fetchRelationShip(fetched_accounts.accounts, position); fetchRelationShip(fetched_accounts.accounts, position);
max_id = fetched_accounts.pagination.min_id; max_id = fetched_accounts.pagination.max_id;
accountAdapter.notifyItemRangeInserted(startId, fetched_accounts.accounts.size()); accountAdapter.notifyItemRangeInserted(startId, fetched_accounts.accounts.size());
} }
} }

View file

@ -99,7 +99,7 @@ public class FragmentMastodonConversation extends Fragment {
LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity()); LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
binding.recyclerView.setLayoutManager(mLayoutManager); binding.recyclerView.setLayoutManager(mLayoutManager);
binding.recyclerView.setAdapter(conversationAdapter); binding.recyclerView.setAdapter(conversationAdapter);
max_id = conversations.pagination.min_id; max_id = conversations.pagination.max_id;
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
@ -122,7 +122,7 @@ public class FragmentMastodonConversation extends Fragment {
startId = currentFragment.conversations.size(); startId = currentFragment.conversations.size();
} }
currentFragment.conversations.addAll(fetched_conversations.conversations); currentFragment.conversations.addAll(fetched_conversations.conversations);
max_id = fetched_conversations.pagination.min_id; max_id = fetched_conversations.pagination.max_id;
conversationAdapter.notifyItemRangeInserted(startId, fetched_conversations.conversations.size()); conversationAdapter.notifyItemRangeInserted(startId, fetched_conversations.conversations.size());
} }
}); });

View file

@ -144,7 +144,7 @@ public class FragmentMastodonNotification extends Fragment {
LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity()); LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
binding.recyclerView.setLayoutManager(mLayoutManager); binding.recyclerView.setLayoutManager(mLayoutManager);
binding.recyclerView.setAdapter(notificationAdapter); binding.recyclerView.setAdapter(notificationAdapter);
max_id = notifications.pagination.min_id; max_id = notifications.pagination.max_id;
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
@ -196,7 +196,7 @@ public class FragmentMastodonNotification extends Fragment {
startId = currentFragment.notifications.size(); startId = currentFragment.notifications.size();
} }
currentFragment.notifications.addAll(fetched_notifications.notifications); currentFragment.notifications.addAll(fetched_notifications.notifications);
max_id = fetched_notifications.pagination.min_id; max_id = fetched_notifications.pagination.max_id;
notificationAdapter.notifyItemRangeInserted(startId, fetched_notifications.notifications.size()); notificationAdapter.notifyItemRangeInserted(startId, fetched_notifications.notifications.size());
} }
} }

View file

@ -196,7 +196,6 @@ public class FragmentMastodonTimeline extends Fragment {
timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class); timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class);
accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class); accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class);
binding.loader.setVisibility(View.VISIBLE); binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE); binding.recyclerView.setVisibility(View.GONE);
//Markers for home and notifications to get last read ones //Markers for home and notifications to get last read ones
@ -244,9 +243,8 @@ public class FragmentMastodonTimeline extends Fragment {
} }
this.statuses.addAll(statuses.statuses); this.statuses.addAll(statuses.statuses);
max_id = this.statuses.get(this.statuses.size() - 1).id; max_id = statuses.pagination.max_id;
min_id = this.statuses.get(0).id; min_id = statuses.pagination.min_id;
statusAdapter = new StatusAdapter(this.statuses, timelineType == Timeline.TimeLineEnum.REMOTE, minified); statusAdapter = new StatusAdapter(this.statuses, timelineType == Timeline.TimeLineEnum.REMOTE, minified);
if (statusReport != null) { if (statusReport != null) {
@ -317,8 +315,8 @@ public class FragmentMastodonTimeline extends Fragment {
statuses.addAll(fetched_statuses.statuses); statuses.addAll(fetched_statuses.statuses);
statusAdapter.notifyItemRangeInserted(startId, fetched_statuses.statuses.size()); statusAdapter.notifyItemRangeInserted(startId, fetched_statuses.statuses.size());
} }
max_id = statuses.get(statuses.size() - 1).id; max_id = fetched_statuses.pagination.max_id;
min_id = statuses.get(0).id; min_id = fetched_statuses.pagination.min_id;
} }
} }
@ -403,13 +401,13 @@ public class FragmentMastodonTimeline extends Fragment {
} }
} else if (timelineType == Timeline.TimeLineEnum.REMOTE) { //REMOTE TIMELINE } else if (timelineType == Timeline.TimeLineEnum.REMOTE) { //REMOTE TIMELINE
if (direction == null) { if (direction == null) {
timelinesVM.getPublic(null, remoteInstance, false, true, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPublic(null, remoteInstance, true, false, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getPublic(null, remoteInstance, false, true, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPublic(null, remoteInstance, true, false, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
timelinesVM.getPublic(null, remoteInstance, false, true, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPublic(null, remoteInstance, true, false, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
} }
} else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE } else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE
@ -445,8 +443,10 @@ public class FragmentMastodonTimeline extends Fragment {
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, null, null, false, true, MastodonHelper.statusesPerCall(requireActivity())) accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, null, null, false, true, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), pinnedStatuses -> accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity())) .observe(getViewLifecycleOwner(), pinnedStatuses -> accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), otherStatuses -> { .observe(getViewLifecycleOwner(), otherStatuses -> {
otherStatuses.statuses.addAll(0, pinnedStatuses.statuses); if (otherStatuses != null && otherStatuses.statuses != null) {
initializeStatusesCommonView(otherStatuses); otherStatuses.statuses.addAll(0, pinnedStatuses.statuses);
initializeStatusesCommonView(otherStatuses);
}
})); }));
} else { } else {
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity())) accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
@ -483,20 +483,18 @@ public class FragmentMastodonTimeline extends Fragment {
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
accountsVM.getFavourites(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, max_id) accountsVM.getFavourites(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, max_id)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
} else if (direction == DIRECTION.TOP) { } else {
accountsVM.getFavourites(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), min_id, null) flagLoading = false;
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
} }
} else if (timelineType == Timeline.TimeLineEnum.BOOKMARK_TIMELINE) { } else if (timelineType == Timeline.TimeLineEnum.BOOKMARK_TIMELINE) {
if (direction == null) { if (direction == null) {
accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, null, null) accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, null, null)
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, max_id, null) accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), max_id, null, null)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
} else if (direction == DIRECTION.TOP) { } else {
accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), min_id, null, null) flagLoading = false;
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP));
} }
} }
} }

View file

@ -339,7 +339,7 @@ public class AccountsVM extends AndroidViewModel {
Response<List<Status>> accountStatusesResponse = accountStatusesCall.execute(); Response<List<Status>> accountStatusesResponse = accountStatusesCall.execute();
if (accountStatusesResponse.isSuccessful()) { if (accountStatusesResponse.isSuccessful()) {
statusList = SpannableHelper.convertStatus(getApplication().getApplicationContext(), accountStatusesResponse.body()); statusList = SpannableHelper.convertStatus(getApplication().getApplicationContext(), accountStatusesResponse.body());
pagination = MastodonHelper.getPaginationStatus(statusList); pagination = MastodonHelper.getPagination(accountStatusesResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
@ -375,7 +375,7 @@ public class AccountsVM extends AndroidViewModel {
Response<List<Account>> followersResponse = followersCall.execute(); Response<List<Account>> followersResponse = followersCall.execute();
if (followersResponse.isSuccessful()) { if (followersResponse.isSuccessful()) {
accountList = followersResponse.body(); accountList = followersResponse.body();
pagination = MastodonHelper.getPaginationAccount(accountList); pagination = MastodonHelper.getPagination(followersResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -411,7 +411,7 @@ public class AccountsVM extends AndroidViewModel {
Response<List<Account>> followingResponse = followingCall.execute(); Response<List<Account>> followingResponse = followingCall.execute();
if (followingResponse.isSuccessful()) { if (followingResponse.isSuccessful()) {
accountList = followingResponse.body(); accountList = followingResponse.body();
pagination = MastodonHelper.getPaginationAccount(accountList); pagination = MastodonHelper.getPagination(followingResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -909,7 +909,7 @@ public class AccountsVM extends AndroidViewModel {
if (bookmarksResponse.isSuccessful()) { if (bookmarksResponse.isSuccessful()) {
statusList = bookmarksResponse.body(); statusList = bookmarksResponse.body();
statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), statusList); statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), statusList);
statuses.pagination = MastodonHelper.getPaginationStatus(statusList); statuses.pagination = MastodonHelper.getPagination(bookmarksResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -940,7 +940,7 @@ public class AccountsVM extends AndroidViewModel {
if (favouritesResponse.isSuccessful()) { if (favouritesResponse.isSuccessful()) {
statusList = favouritesResponse.body(); statusList = favouritesResponse.body();
statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), statusList); statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), statusList);
statuses.pagination = MastodonHelper.getPaginationStatus(statusList); statuses.pagination = MastodonHelper.getPagination(favouritesResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -972,7 +972,7 @@ public class AccountsVM extends AndroidViewModel {
if (mutesResponse.isSuccessful()) { if (mutesResponse.isSuccessful()) {
accountList = mutesResponse.body(); accountList = mutesResponse.body();
accounts.accounts = SpannableHelper.convertAccounts(getApplication().getApplicationContext(), accountList); accounts.accounts = SpannableHelper.convertAccounts(getApplication().getApplicationContext(), accountList);
accounts.pagination = MastodonHelper.getPaginationAccount(accountList); accounts.pagination = MastodonHelper.getPagination(mutesResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -1004,7 +1004,7 @@ public class AccountsVM extends AndroidViewModel {
if (blocksResponse.isSuccessful()) { if (blocksResponse.isSuccessful()) {
accountList = blocksResponse.body(); accountList = blocksResponse.body();
accounts.accounts = SpannableHelper.convertAccounts(getApplication().getApplicationContext(), accountList); accounts.accounts = SpannableHelper.convertAccounts(getApplication().getApplicationContext(), accountList);
accounts.pagination = MastodonHelper.getPaginationAccount(accountList); accounts.pagination = MastodonHelper.getPagination(blocksResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -99,12 +99,14 @@ public class NotificationsVM extends AndroidViewModel {
if (notificationsResponse.isSuccessful()) { if (notificationsResponse.isSuccessful()) {
List<Notification> notFilteredNotifications = notificationsResponse.body(); List<Notification> notFilteredNotifications = notificationsResponse.body();
notifications.notifications = TimelineHelper.filterNotification(getApplication().getApplicationContext(), notFilteredNotifications); notifications.notifications = TimelineHelper.filterNotification(getApplication().getApplicationContext(), notFilteredNotifications);
for (Notification notification : notifications.notifications) { if (notifications.notifications != null) {
if (notification != null) { for (Notification notification : notifications.notifications) {
notification.status = SpannableHelper.convertStatus(getApplication().getApplicationContext(), notification.status); if (notification != null) {
notification.status = SpannableHelper.convertStatus(getApplication().getApplicationContext(), notification.status);
}
} }
} }
notifications.pagination = MastodonHelper.getPaginationNotification(notifications.notifications); notifications.pagination = MastodonHelper.getPagination(notificationsResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -86,13 +86,13 @@ public class SearchVM extends AndroidViewModel {
@NonNull String q, @NonNull String q,
String account_id, String account_id,
String type, String type,
boolean exclude_unreviewed, Boolean exclude_unreviewed,
boolean resolve, Boolean resolve,
boolean following, Boolean following,
int offset, Integer offset,
String max_id, String max_id,
String min_id, String min_id,
int limit) { Integer limit) {
MastodonSearchService mastodonSearchService = init(instance); MastodonSearchService mastodonSearchService = init(instance);
resultsMutableLiveData = new MutableLiveData<>(); resultsMutableLiveData = new MutableLiveData<>();
new Thread(() -> { new Thread(() -> {

View file

@ -400,7 +400,7 @@ public class StatusesVM extends AndroidViewModel {
} }
Accounts accountsPagination = new Accounts(); Accounts accountsPagination = new Accounts();
accountsPagination.accounts = accounts; accountsPagination.accounts = accounts;
accountsPagination.pagination = MastodonHelper.getPaginationAccount(accounts); accountsPagination.pagination = MastodonHelper.getPagination(headers);
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> accountsMutableLiveData.setValue(accountsPagination); Runnable myRunnable = () -> accountsMutableLiveData.setValue(accountsPagination);
mainHandler.post(myRunnable); mainHandler.post(myRunnable);
@ -446,7 +446,7 @@ public class StatusesVM extends AndroidViewModel {
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Accounts accountsPagination = new Accounts(); Accounts accountsPagination = new Accounts();
accountsPagination.accounts = accounts; accountsPagination.accounts = accounts;
accountsPagination.pagination = MastodonHelper.getPaginationAccount(accounts); accountsPagination.pagination = MastodonHelper.getPagination(headers);
Runnable myRunnable = () -> accountsMutableLiveData.setValue(accountsPagination); Runnable myRunnable = () -> accountsMutableLiveData.setValue(accountsPagination);
mainHandler.post(myRunnable); mainHandler.post(myRunnable);
}).start(); }).start();
@ -1098,7 +1098,7 @@ public class StatusesVM extends AndroidViewModel {
Response<List<ScheduledStatus>> scheduledStatusResponse = scheduledStatuseCall.execute(); Response<List<ScheduledStatus>> scheduledStatusResponse = scheduledStatuseCall.execute();
if (scheduledStatusResponse.isSuccessful()) { if (scheduledStatusResponse.isSuccessful()) {
scheduledStatusList = scheduledStatusResponse.body(); scheduledStatusList = scheduledStatusResponse.body();
pagination = MastodonHelper.getPaginationScheduledStatus(scheduledStatusList); pagination = MastodonHelper.getPagination(scheduledStatusResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -37,6 +37,7 @@ import app.fedilab.android.client.mastodon.entities.Conversation;
import app.fedilab.android.client.mastodon.entities.Conversations; import app.fedilab.android.client.mastodon.entities.Conversations;
import app.fedilab.android.client.mastodon.entities.Marker; import app.fedilab.android.client.mastodon.entities.Marker;
import app.fedilab.android.client.mastodon.entities.MastodonList; import app.fedilab.android.client.mastodon.entities.MastodonList;
import app.fedilab.android.client.mastodon.entities.Pagination;
import app.fedilab.android.client.mastodon.entities.Status; import app.fedilab.android.client.mastodon.entities.Status;
import app.fedilab.android.client.mastodon.entities.Statuses; import app.fedilab.android.client.mastodon.entities.Statuses;
import app.fedilab.android.exception.DBException; import app.fedilab.android.exception.DBException;
@ -95,13 +96,13 @@ public class TimelinesVM extends AndroidViewModel {
* @return {@link LiveData} containing a {@link Statuses} * @return {@link LiveData} containing a {@link Statuses}
*/ */
public LiveData<Statuses> getPublic(String token, @NonNull String instance, public LiveData<Statuses> getPublic(String token, @NonNull String instance,
boolean local, Boolean local,
boolean remote, Boolean remote,
boolean onlyMedia, Boolean onlyMedia,
String maxId, String maxId,
String sinceId, String sinceId,
String minId, String minId,
int limit) { Integer limit) {
MastodonTimelinesService mastodonTimelinesService = init(instance); MastodonTimelinesService mastodonTimelinesService = init(instance);
statusesMutableLiveData = new MutableLiveData<>(); statusesMutableLiveData = new MutableLiveData<>();
new Thread(() -> { new Thread(() -> {
@ -114,7 +115,7 @@ public class TimelinesVM extends AndroidViewModel {
List<Status> notFilteredStatuses = publicTlResponse.body(); List<Status> notFilteredStatuses = publicTlResponse.body();
List<Status> filteredStatuses = TimelineHelper.filterStatus(getApplication(), notFilteredStatuses, TimelineHelper.FilterTimeLineType.PUBLIC); List<Status> filteredStatuses = TimelineHelper.filterStatus(getApplication(), notFilteredStatuses, TimelineHelper.FilterTimeLineType.PUBLIC);
statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), filteredStatuses); statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), filteredStatuses);
statuses.pagination = MastodonHelper.getPaginationStatus(statuses.statuses); statuses.pagination = MastodonHelper.getPagination(publicTlResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -163,7 +164,7 @@ public class TimelinesVM extends AndroidViewModel {
List<Status> notFilteredStatuses = hashTagTlResponse.body(); List<Status> notFilteredStatuses = hashTagTlResponse.body();
List<Status> filteredStatuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), notFilteredStatuses, TimelineHelper.FilterTimeLineType.PUBLIC); List<Status> filteredStatuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), notFilteredStatuses, TimelineHelper.FilterTimeLineType.PUBLIC);
statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), filteredStatuses); statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), filteredStatuses);
statuses.pagination = MastodonHelper.getPaginationStatus(statuses.statuses); statuses.pagination = MastodonHelper.getPagination(hashTagTlResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -205,7 +206,7 @@ public class TimelinesVM extends AndroidViewModel {
List<Status> notFilteredStatuses = homeTlResponse.body(); List<Status> notFilteredStatuses = homeTlResponse.body();
List<Status> filteredStatuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), notFilteredStatuses, TimelineHelper.FilterTimeLineType.HOME); List<Status> filteredStatuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), notFilteredStatuses, TimelineHelper.FilterTimeLineType.HOME);
statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), filteredStatuses); statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), filteredStatuses);
statuses.pagination = MastodonHelper.getPaginationStatus(statuses.statuses); statuses.pagination = MastodonHelper.getPagination(homeTlResponse.headers());
for (Status status : statuses.statuses) { for (Status status : statuses.statuses) {
StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext()); StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext());
StatusCache statusCache = new StatusCache(); StatusCache statusCache = new StatusCache();
@ -253,6 +254,11 @@ public class TimelinesVM extends AndroidViewModel {
statuses = statusCacheDAO.geStatuses(StatusCache.CacheEnum.HOME, instance, user_id, maxId, minId); statuses = statusCacheDAO.geStatuses(StatusCache.CacheEnum.HOME, instance, user_id, maxId, minId);
if (statuses != null) { if (statuses != null) {
statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), statuses.statuses); statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), statuses.statuses);
if (statuses.statuses != null && statuses.statuses.size() > 0) {
statuses.pagination = new Pagination();
statuses.pagination.min_id = statuses.statuses.get(0).id;
statuses.pagination.max_id = statuses.statuses.get(statuses.statuses.size() - 1).id;
}
} }
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();
@ -315,7 +321,7 @@ public class TimelinesVM extends AndroidViewModel {
Response<List<Status>> listTlResponse = listTlCall.execute(); Response<List<Status>> listTlResponse = listTlCall.execute();
if (listTlResponse.isSuccessful()) { if (listTlResponse.isSuccessful()) {
statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), listTlResponse.body()); statuses.statuses = SpannableHelper.convertStatus(getApplication().getApplicationContext(), listTlResponse.body());
statuses.pagination = MastodonHelper.getPaginationStatus(statuses.statuses); statuses.pagination = MastodonHelper.getPagination(listTlResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -355,7 +361,7 @@ public class TimelinesVM extends AndroidViewModel {
conversation.last_status = SpannableHelper.convertStatus(getApplication().getApplicationContext(), conversation.last_status); conversation.last_status = SpannableHelper.convertStatus(getApplication().getApplicationContext(), conversation.last_status);
} }
} }
conversations.pagination = MastodonHelper.getPaginationConversation(conversations.conversations); conversations.pagination = MastodonHelper.getPagination(conversationsResponse.headers());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();