handle recursive compose/drafts list

This commit is contained in:
sk 2022-12-30 22:34:41 +01:00 committed by LucasGGamerM
parent 6eedb0e156
commit eecc1242be
2 changed files with 26 additions and 5 deletions

View File

@ -144,6 +144,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
private static final int MEDIA_RESULT=717; private static final int MEDIA_RESULT=717;
private static final int IMAGE_DESCRIPTION_RESULT=363; private static final int IMAGE_DESCRIPTION_RESULT=363;
private static final int SCHEDULED_STATUS_OPENED_RESULT=161;
private static final int MAX_ATTACHMENTS=4; private static final int MAX_ATTACHMENTS=4;
private static final String TAG="ComposeFragment"; private static final String TAG="ComposeFragment";
@ -249,7 +250,6 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
AccountSessionManager.getInstance().updateInstanceInfo(instanceDomain); AccountSessionManager.getInstance().updateInstanceInfo(instanceDomain);
} }
// sorry about all this ugly code, but i can't find any consistency in ComposeFragment.java
Bundle bundle = savedInstanceState != null ? savedInstanceState : getArguments(); Bundle bundle = savedInstanceState != null ? savedInstanceState : getArguments();
if (bundle.containsKey("scheduledStatus")) scheduledStatus=Parcels.unwrap(bundle.getParcelable("scheduledStatus")); if (bundle.containsKey("scheduledStatus")) scheduledStatus=Parcels.unwrap(bundle.getParcelable("scheduledStatus"));
if (bundle.containsKey("scheduledAt")) scheduledAt=(Instant) bundle.getSerializable("scheduledAt"); if (bundle.containsKey("scheduledAt")) scheduledAt=(Instant) bundle.getSerializable("scheduledAt");
@ -708,9 +708,14 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
args.putString("account", accountID); args.putString("account", accountID);
InputMethodManager imm=getActivity().getSystemService(InputMethodManager.class); InputMethodManager imm=getActivity().getSystemService(InputMethodManager.class);
imm.hideSoftInputFromWindow(draftsBtn.getWindowToken(), 0); imm.hideSoftInputFromWindow(draftsBtn.getWindowToken(), 0);
if (hasDraft()) {
Nav.go(getActivity(), ScheduledStatusListFragment.class, args); Nav.go(getActivity(), ScheduledStatusListFragment.class, args);
// TODO: figure out a better way to handle the back stack } else {
// if (!hasDraft()) content.postDelayed(()->Nav.finish(this), 200); // result for the previous ScheduledStatusList
setResult(true, null);
// finishing fragment in "onFragmentResult"
Nav.goForResult(getActivity(), ScheduledStatusListFragment.class, args, SCHEDULED_STATUS_OPENED_RESULT, this);
}
} }
private void updateLanguage(String lang) { private void updateLanguage(String lang) {
@ -1040,6 +1045,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
break; break;
} }
} }
} else if (reqCode == SCHEDULED_STATUS_OPENED_RESULT && success && getActivity() != null) {
Nav.finish(this);
} }
} }

View File

@ -2,6 +2,8 @@ package org.joinmastodon.android.fragments;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
@ -18,6 +20,7 @@ import org.joinmastodon.android.model.HeaderPaginationList;
import org.joinmastodon.android.model.ScheduledStatus; import org.joinmastodon.android.model.ScheduledStatus;
import org.joinmastodon.android.model.Status; import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.displayitems.StatusDisplayItem; import org.joinmastodon.android.ui.displayitems.StatusDisplayItem;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.parceler.Parcels; import org.parceler.Parcels;
import java.util.Collections; import java.util.Collections;
@ -28,6 +31,7 @@ import me.grishka.appkit.api.SimpleCallback;
public class ScheduledStatusListFragment extends BaseStatusListFragment<ScheduledStatus> { public class ScheduledStatusListFragment extends BaseStatusListFragment<ScheduledStatus> {
private String nextMaxID; private String nextMaxID;
private static final int SCHEDULED_STATUS_LIST_OPENED = 161;
@Override @Override
public void onCreate(Bundle savedInstanceState){ public void onCreate(Bundle savedInstanceState){
@ -68,7 +72,17 @@ public class ScheduledStatusListFragment extends BaseStatusListFragment<Schedule
args.putString("sourceText", status.text); args.putString("sourceText", status.text);
args.putString("sourceSpoiler", status.spoilerText); args.putString("sourceSpoiler", status.spoilerText);
args.putBoolean("redraftStatus", true); args.putBoolean("redraftStatus", true);
Nav.go(getActivity(), ComposeFragment.class, args); setResult(true, null);
// closing this scheduled status list if another status list is opened from compose fragment
Nav.goForResult(getActivity(), ComposeFragment.class, args, SCHEDULED_STATUS_LIST_OPENED, this);
}
@Override
public void onFragmentResult(int reqCode, boolean success, Bundle result) {
if (reqCode == SCHEDULED_STATUS_LIST_OPENED && success && getActivity() != null) {
Nav.finish(this);
}
} }
@Override @Override