diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index b58df8e77b..93c875cdfd 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -53,6 +53,7 @@ import androidx.core.graphics.ColorUtils; import androidx.documentfile.provider.DocumentFile; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentResultListener; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleOwner; @@ -119,6 +120,30 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc } } + String requestKey = getRequestKey(); + if (!BuildConfig.PLAY_STORE_RELEASE) + EntityLog.log(this, "Listing key=" + requestKey); + getSupportFragmentManager().setFragmentResultListener(requestKey, this, new FragmentResultListener() { + @Override + public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) { + try { + result.setClassLoader(ApplicationEx.class.getClassLoader()); + int requestCode = result.getInt("requestCode"); + int resultCode = result.getInt("resultCode"); + + EntityLog.log(ActivityBase.this, "Received key=" + requestKey + + " request=" + requestCode + + " result=" + resultCode); + + Intent data = new Intent(); + data.putExtra("args", result); + onActivityResult(requestCode, resultCode, data); + } catch (Throwable ex) { + Log.e(ex); + } + } + }); + prefs.registerOnSharedPreferenceChangeListener(this); int colorPrimaryDark = Helper.resolveColor(this, R.attr.colorPrimaryDark); @@ -353,6 +378,10 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc } } + public String getRequestKey() { + return this.getClass().getName() + ":activity"; + } + @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { EntityLog.log(this, "Result class=" + this.getClass().getSimpleName() + diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogBase.java b/app/src/main/java/eu/faircode/email/FragmentDialogBase.java index 0c8a5fab2f..4bf6a9aea2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogBase.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogBase.java @@ -183,6 +183,11 @@ public class FragmentDialogBase extends DialogFragment { targetRequestCode = requestCode; } + public void setTargetActivity(ActivityBase activity, int requestCode){ + targetRequestKey = activity.getRequestKey(); + targetRequestCode = requestCode; + } + protected void sendResult(int resultCode) { EntityLog.log(getContext(), "Sending key=" + targetRequestKey + " request=" + targetRequestCode +