diff options
author | LuK1337 <priv.luk@gmail.com> | 2022-05-26 00:03:21 +0200 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2022-06-29 12:32:24 +0800 |
commit | 458f2a2e609feabb845c343d18442e4a69b9ddf5 (patch) | |
tree | ce2765ef5c716c150827f1fdcd30b388ab8d03c9 | |
parent | d62aa86abfa996196528e58823a5760397713926 (diff) |
Updater: Unbreak "Export update" featureHEADsugisawa-mr1
Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/4736
Change-Id: I186a27d2e99098cf8ebb3dd5c7348cdb528baa78
-rw-r--r-- | src/org/lineageos/updater/UpdatesActivity.java | 36 | ||||
-rw-r--r-- | src/org/lineageos/updater/UpdatesListActivity.java | 3 | ||||
-rw-r--r-- | src/org/lineageos/updater/UpdatesListAdapter.java | 39 |
3 files changed, 42 insertions, 36 deletions
diff --git a/src/org/lineageos/updater/UpdatesActivity.java b/src/org/lineageos/updater/UpdatesActivity.java index 1ff629b..b66f35c 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<Intent> 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 fe0f4bd..fd63178 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 608ad7e..6650a78 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<UpdatesListAdapter. private AlertDialog infoDialog; - private UpdateInfo mToBeExported = null; - private enum Action { DOWNLOAD, PAUSE, @@ -549,7 +547,9 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. mActivity.getString(R.string.toast_download_url_copied)); return true; } else if (itemId == R.id.menu_export_update) { - exportUpdate(update); + if (mActivity != null) { + mActivity.exportUpdate(update); + } return true; } return false; @@ -559,39 +559,6 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. helper.show(); } - private void exportUpdate(UpdateInfo update) { - if (mActivity == null) { - return; - } - mToBeExported = update; - ActivityResultLauncher<Intent> 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), |