mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-27 18:27:43 +00:00
Set target activity
This commit is contained in:
parent
e042d7dd68
commit
c269fe2320
2 changed files with 34 additions and 0 deletions
|
@ -53,6 +53,7 @@ import androidx.core.graphics.ColorUtils;
|
||||||
import androidx.documentfile.provider.DocumentFile;
|
import androidx.documentfile.provider.DocumentFile;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.fragment.app.FragmentResultListener;
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.Lifecycle;
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
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);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
int colorPrimaryDark = Helper.resolveColor(this, R.attr.colorPrimaryDark);
|
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
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||||
EntityLog.log(this, "Result class=" + this.getClass().getSimpleName() +
|
EntityLog.log(this, "Result class=" + this.getClass().getSimpleName() +
|
||||||
|
|
|
@ -183,6 +183,11 @@ public class FragmentDialogBase extends DialogFragment {
|
||||||
targetRequestCode = requestCode;
|
targetRequestCode = requestCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTargetActivity(ActivityBase activity, int requestCode){
|
||||||
|
targetRequestKey = activity.getRequestKey();
|
||||||
|
targetRequestCode = requestCode;
|
||||||
|
}
|
||||||
|
|
||||||
protected void sendResult(int resultCode) {
|
protected void sendResult(int resultCode) {
|
||||||
EntityLog.log(getContext(), "Sending key=" + targetRequestKey +
|
EntityLog.log(getContext(), "Sending key=" + targetRequestKey +
|
||||||
" request=" + targetRequestCode +
|
" request=" + targetRequestCode +
|
||||||
|
|
Loading…
Reference in a new issue