Updater: Unbreak "Export update" feature
Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/4736 Change-Id: I186a27d2e99098cf8ebb3dd5c7348cdb528baa78
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user