mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-26 09:47:13 +00:00
Generate unique request keys
This commit is contained in:
parent
38ae8960c6
commit
6ddd7d83ce
2 changed files with 15 additions and 3 deletions
|
@ -73,11 +73,14 @@ public class FragmentBase extends Fragment {
|
|||
private String subtitle = " ";
|
||||
private boolean finish = false;
|
||||
private boolean finished = false;
|
||||
private String requestKey = null;
|
||||
|
||||
private long message = -1;
|
||||
private long attachment = -1;
|
||||
private int scrollTo = 0;
|
||||
|
||||
private static int requestSequence = 0;
|
||||
|
||||
private static final int REQUEST_ATTACHMENT = 51;
|
||||
private static final int REQUEST_ATTACHMENTS = 52;
|
||||
private static final int REQUEST_RECOVERABLE_PERMISSION = 53;
|
||||
|
@ -183,6 +186,7 @@ public class FragmentBase extends Fragment {
|
|||
Log.d("Save instance " + this);
|
||||
int before = Helper.getSize(outState);
|
||||
outState.putString("fair:subtitle", subtitle);
|
||||
outState.putString("fair:requestKey", requestKey);
|
||||
super.onSaveInstanceState(outState);
|
||||
int after = Helper.getSize(outState);
|
||||
Log.d("Saved instance " + this + " size=" + before + "/" + after);
|
||||
|
@ -201,16 +205,24 @@ public class FragmentBase extends Fragment {
|
|||
Log.d("Saved " + this + " " + key + "=" + outState.get(key));
|
||||
}
|
||||
|
||||
public String getRequestKey() {
|
||||
if (requestKey == null)
|
||||
requestKey = getClass().getName() + "_" + (++requestSequence);
|
||||
return requestKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i("Create " + this + " saved=" + (savedInstanceState != null));
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null)
|
||||
if (savedInstanceState != null) {
|
||||
subtitle = savedInstanceState.getString("fair:subtitle");
|
||||
requestKey = savedInstanceState.getString("fair:requestKey");
|
||||
}
|
||||
|
||||
// https://developer.android.com/training/basics/fragments/pass-data-between
|
||||
getParentFragmentManager().setFragmentResultListener(getClass().getName(), this, new FragmentResultListener() {
|
||||
getParentFragmentManager().setFragmentResultListener(getRequestKey(), this, new FragmentResultListener() {
|
||||
@Override
|
||||
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
|
||||
int requestCode = result.getInt("requestCode");
|
||||
|
|
|
@ -146,7 +146,7 @@ public class FragmentDialogBase extends DialogFragment {
|
|||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setTargetFragment(@Nullable Fragment fragment, int requestCode) {
|
||||
targetRequestKey = fragment.getClass().getName();
|
||||
targetRequestKey = ((FragmentBase) fragment).getRequestKey();
|
||||
targetRequestCode = requestCode;
|
||||
Log.i("Set target " + this + " " + fragment + " request=" + requestCode);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue