keep position with remote conversations

pull/946/head
Thomas 1 year ago
parent d017952ffe
commit 14515e6ba6

@ -62,6 +62,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
private Status firstMessage;
private String remote_instance;
private Status focusedStatus;
private String focusedStatusURI;
private boolean checkRemotely;
@Override
@ -91,11 +92,16 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
if (b != null) {
focusedStatus = (Status) b.getSerializable(Helper.ARG_STATUS);
remote_instance = b.getString(Helper.ARG_REMOTE_INSTANCE, null);
focusedStatusURI = b.getString(Helper.ARG_FOCUSED_STATUS_URI, null);
}
if (focusedStatus == null || currentAccount == null || currentAccount.mastodon_account == null) {
finish();
return;
}
if (focusedStatusURI == null && remote_instance == null) {
focusedStatusURI = focusedStatus.uri;
}
MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
checkRemotely = sharedpreferences.getBoolean(getString(R.string.SET_CONVERSATION_REMOTELY), false);
@ -236,6 +242,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.ARG_STATUS, status);
bundle.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance);
bundle.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI);
FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext();
fragmentMastodonContext.firstMessage = ContextActivity.this;
currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null);
@ -281,6 +288,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
if (status != null) {
Intent intentContext = new Intent(ContextActivity.this, ContextActivity.class);
intentContext.putExtra(Helper.ARG_STATUS, status);
intentContext.putExtra(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI);
intentContext.putExtra(Helper.ARG_REMOTE_INSTANCE, finalInstance);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentContext);

@ -214,6 +214,7 @@ public class Helper {
public static final String ARG_NOTIFICATION_TYPE = "ARG_NOTIFICATION_TYPE";
public static final String ARG_EXCLUDED_NOTIFICATION_TYPE = "ARG_EXCLUDED_NOTIFICATION_TYPE";
public static final String ARG_STATUS = "ARG_STATUS";
public static final String ARG_FOCUSED_STATUS_URI = "ARG_FOCUSED_STATUS_URI";
public static final String ARG_TIMELINE_REFRESH_ALL = "ARG_TIMELINE_REFRESH_ALL";
public static final String ARG_REFRESH_NOTFICATION = "ARG_REFRESH_NOTFICATION";
public static final String ARG_STATUS_DELETED = "ARG_STATUS_DELETED";

@ -124,7 +124,7 @@ public class FragmentMastodonContext extends Fragment {
}
};
private Status focusedStatus;
private String remote_instance;
private String remote_instance, focusedStatusURI;
private Status firstStatus;
private boolean pullToRefresh;
private String user_token, user_instance;
@ -153,9 +153,11 @@ public class FragmentMastodonContext extends Fragment {
focusedStatus = null;
pullToRefresh = false;
focusedStatusURI = null;
if (getArguments() != null) {
focusedStatus = (Status) getArguments().getSerializable(Helper.ARG_STATUS);
remote_instance = getArguments().getString(Helper.ARG_REMOTE_INSTANCE, null);
focusedStatusURI = getArguments().getString(Helper.ARG_FOCUSED_STATUS_URI, null);
}
if (remote_instance != null) {
user_instance = remote_instance;
@ -264,7 +266,22 @@ public class FragmentMastodonContext extends Fragment {
}
binding.recyclerView.addItemDecoration(new DividerDecoration(requireActivity(), statuses));
binding.swipeContainer.setRefreshing(false);
if (focusedStatusURI == null) {
binding.recyclerView.scrollToPosition(statusPosition);
} else {
int position = 0;
boolean found = false;
for (Status status : statuses) {
if (status.uri.compareToIgnoreCase(focusedStatusURI) == 0) {
found = true;
break;
}
position++;
}
if (found) {
binding.recyclerView.scrollToPosition(position);
}
}
}
@Override

Loading…
Cancel
Save