diff --git a/src/org/lineageos/updater/UpdatesActivity.java b/src/org/lineageos/updater/UpdatesActivity.java index 395e801b..9c56f0bb 100644 --- a/src/org/lineageos/updater/UpdatesActivity.java +++ b/src/org/lineageos/updater/UpdatesActivity.java @@ -16,6 +16,7 @@ package org.lineageos.updater; import android.annotation.SuppressLint; +import android.app.Activity; import android.app.UiModeManager; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -44,6 +45,8 @@ import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.SwitchCompat; @@ -87,6 +90,19 @@ public class UpdatesActivity extends UpdatesListActivity { private boolean mIsTV; + private UpdateInfo mToBeExported = null; + private final ActivityResultLauncher mExportUpdate = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> { + if (result.getResultCode() == Activity.RESULT_OK) { + Intent intent = result.getData(); + if (intent != null) { + Uri uri = intent.getData(); + exportUpdate(uri); + } + } + }); + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -402,6 +418,26 @@ public class UpdatesActivity extends UpdatesListActivity { } } + @Override + public void exportUpdate(UpdateInfo update) { + mToBeExported = update; + + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("application/zip"); + intent.putExtra(Intent.EXTRA_TITLE, update.getName()); + + mExportUpdate.launch(intent); + } + + private void exportUpdate(Uri uri) { + Intent intent = new Intent(this, ExportUpdateService.class); + intent.setAction(ExportUpdateService.ACTION_START_EXPORTING); + intent.putExtra(ExportUpdateService.EXTRA_SOURCE_FILE, mToBeExported.getFile()); + intent.putExtra(ExportUpdateService.EXTRA_DEST_URI, uri); + startService(intent); + } + @Override public void showSnackbar(int stringId, int duration) { Snackbar.make(findViewById(R.id.main_container), stringId, duration).show(); diff --git a/src/org/lineageos/updater/UpdatesListActivity.java b/src/org/lineageos/updater/UpdatesListActivity.java index fe0f4bd4..fd631785 100644 --- a/src/org/lineageos/updater/UpdatesListActivity.java +++ b/src/org/lineageos/updater/UpdatesListActivity.java @@ -17,6 +17,9 @@ package org.lineageos.updater; import androidx.appcompat.app.AppCompatActivity; +import org.lineageos.updater.model.UpdateInfo; + public abstract class UpdatesListActivity extends AppCompatActivity { + public abstract void exportUpdate(UpdateInfo update); public abstract void showSnackbar(int stringId, int duration); } diff --git a/src/org/lineageos/updater/UpdatesListAdapter.java b/src/org/lineageos/updater/UpdatesListAdapter.java index 608ad7ea..6650a783 100644 --- a/src/org/lineageos/updater/UpdatesListAdapter.java +++ b/src/org/lineageos/updater/UpdatesListAdapter.java @@ -84,8 +84,6 @@ public class UpdatesListAdapter extends RecyclerView.Adapter resultLauncher = mActivity.registerForActivityResult( - new ActivityResultContracts.StartActivityForResult(), - result -> { - if (result.getResultCode() == Activity.RESULT_OK) { - Intent intent = result.getData(); - if (intent != null) { - Uri uri = intent.getData(); - exportUpdate(uri); - } - } - }); - - Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("application/zip"); - intent.putExtra(Intent.EXTRA_TITLE, update.getName()); - - resultLauncher.launch(intent); - } - - private void exportUpdate(Uri uri) { - Intent intent = new Intent(mActivity, ExportUpdateService.class); - intent.setAction(ExportUpdateService.ACTION_START_EXPORTING); - intent.putExtra(ExportUpdateService.EXTRA_SOURCE_FILE, mToBeExported.getFile()); - intent.putExtra(ExportUpdateService.EXTRA_DEST_URI, uri); - mActivity.startService(intent); - } - private void showInfoDialog() { String messageString = String.format(StringGenerator.getCurrentLocale(mActivity), mActivity.getString(R.string.blocked_update_dialog_message),