Commit 28ca138e authored by Thomas's avatar Thomas
Browse files

Fix #1040 - Fix a crash when reporting messages

parent ecd25bad
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -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 -> {
+25 −3
Original line number Diff line number Diff line
@@ -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);
    }