summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2024-02-22 15:49:42 +0100
committerThomas <tschneider.ac@gmail.com>2024-02-22 15:49:42 +0100
commit28ca138e43825a1af6a4306651c225b215b23eb0 (patch)
tree63dd84e6d59899b1aa62d26448f1213faba63684
parentecd25badf781ab190a5fe1172a9dff9fa0879f3a (diff)
Fix #1040 - Fix a crash when reporting messages
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java32
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java28
2 files changed, 43 insertions, 17 deletions
diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java
index fcd4c1848..2f7a4b22b 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java
@@ -235,7 +235,14 @@ public class ReportActivity extends BaseBarActivity {
fragment = new FragmentMastodonTimeline();
Bundle args = new Bundle();
args.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE);
- args.putSerializable(Helper.ARG_ACCOUNT, account);
+ args.putBoolean(Helper.ARG_SHOW_PINNED, false);
+ args.putBoolean(Helper.ARG_SHOW_REPLIES, true);
+ args.putBoolean(Helper.ARG_SHOW_REBLOGS, false);
+ args.putBoolean(Helper.ARG_CHECK_REMOTELY, false);
+ args.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_REPORT_" + account.acct);
+ if (account != null) {
+ args.putSerializable(Helper.ARG_CACHED_ACCOUNT_ID, account.id);
+ }
//Set to display statuses with less options
args.putBoolean(Helper.ARG_MINIFIED, true);
if (status != null) {
@@ -245,12 +252,7 @@ public class ReportActivity extends BaseBarActivity {
new CachedBundle(ReportActivity.this).insertBundle(args, Helper.getCurrentAccount(ReportActivity.this), bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
- fragment.setArguments(bundle);
- FragmentManager fragmentManager = getSupportFragmentManager();
- FragmentTransaction fragmentTransaction =
- fragmentManager.beginTransaction();
- fragmentTransaction.replace(R.id.fram_spam_container, fragment);
- fragmentTransaction.commit();
+ Helper.addFragment(getSupportFragmentManager(), R.id.fram_spam_container, fragment, bundle, null, null);
});
binding.actionButton.setText(R.string.next);
@@ -265,7 +267,14 @@ public class ReportActivity extends BaseBarActivity {
fragment = new FragmentMastodonTimeline();
Bundle args = new Bundle();
args.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE);
- args.putSerializable(Helper.ARG_ACCOUNT, account);
+ args.putBoolean(Helper.ARG_SHOW_PINNED, false);
+ args.putBoolean(Helper.ARG_SHOW_REPLIES, true);
+ args.putBoolean(Helper.ARG_SHOW_REBLOGS, false);
+ args.putBoolean(Helper.ARG_CHECK_REMOTELY, false);
+ args.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_REPORT_" + account.acct);
+ if (account != null) {
+ args.putSerializable(Helper.ARG_CACHED_ACCOUNT_ID, account.id);
+ }
//Set to display statuses with less options
args.putBoolean(Helper.ARG_MINIFIED, true);
if (status != null) {
@@ -275,12 +284,7 @@ public class ReportActivity extends BaseBarActivity {
new CachedBundle(ReportActivity.this).insertBundle(args, Helper.getCurrentAccount(ReportActivity.this), bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
- fragment.setArguments(bundle);
- FragmentManager fragmentManager = getSupportFragmentManager();
- FragmentTransaction fragmentTransaction =
- fragmentManager.beginTransaction();
- fragmentTransaction.replace(R.id.fram_se_container, fragment);
- fragmentTransaction.commit();
+ Helper.addFragment(getSupportFragmentManager(), R.id.fram_se_container, fragment, bundle, null, null);
});
binding.actionButton.setText(R.string.next);
binding.actionButton.setOnClickListener(v -> {
diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java
index 24fa93927..b175eff91 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java
@@ -187,7 +187,15 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private String lemmy_post_id;
private boolean checkRemotely;
private String accountIDInRemoteInstance;
+ //This value is set to true in onResume meaning that the fragment is visible
private boolean isViewInitialized;
+ //If onResume is called before getting all parameters, needToCallResume will be set to true so it can call safely initializeView()
+ private boolean needToCallResume;
+ //Some operations need to be done once only in onResume, the lockForResumeCall will be incremented to avoid useless calls
+ private int lockForResumeCall;
+ //All timelines that are not pinned - it will take the initial value of isViewInitialized
+ private boolean isNotPinnedTimeline;
+ private boolean bundleParamsRetrieved;
private Statuses initialStatuses;
private String list_id;
private TagTimeline tagTimeline;
@@ -202,8 +210,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private boolean canBeFederated;
private boolean rememberPosition;
private String publicTrendsDomain;
- private int lockForResumeCall;
- private boolean isNotPinnedTimeline;
+
//Allow to recreate data when detaching/attaching fragment
@@ -235,6 +242,14 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
@Override
public void onResume() {
super.onResume();
+ if(bundleParamsRetrieved) {
+ initializeView();
+ } else {
+ needToCallResume = true;
+ }
+ }
+
+ private void initializeView() {
if (!isViewInitialized) {
isViewInitialized = true;
if (initialStatuses != null) {
@@ -255,6 +270,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
}
}
+
/**
* Return the position of the status in the ArrayList
*
@@ -359,6 +375,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
ViewGroup container, Bundle savedInstanceState) {
timelineType = Timeline.TimeLineEnum.HOME;
+ bundleParamsRetrieved = false;
+ needToCallResume = false;
binding = FragmentPaginationBinding.inflate(inflater, container, false);
arguments = getArguments();
return binding.getRoot();
@@ -486,7 +504,11 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
//Only fragment in main view pager should not have the view initialized
//AND Only the first fragment will initialize its view
flagLoading = false;
-
+ bundleParamsRetrieved = true;
+ if(needToCallResume) {
+ initializeView();
+ needToCallResume = false;
+ }
ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
}