Allow user to select all packages during backup and restore

This commit is contained in:
Steve Soltys 2019-02-11 22:07:57 -05:00
parent b714952b85
commit 656b7702e0
5 changed files with 87 additions and 13 deletions

View file

@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.stevesoltys.backup"
android:versionCode="1"
android:versionCode="100"
android:versionName="0.1.0">
<uses-permission android:name="android.permission.BACKUP" />

View file

@ -3,6 +3,9 @@ package com.stevesoltys.backup.activity.backup;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
@ -10,6 +13,7 @@ import com.stevesoltys.backup.R;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.IntStream;
public class CreateBackupActivity extends Activity implements View.OnClickListener, AdapterView.OnItemClickListener {
@ -21,6 +25,18 @@ public class CreateBackupActivity extends Activity implements View.OnClickListen
private Uri contentUri;
@Override
public void onClick(View view) {
int viewId = view.getId();
switch (viewId) {
case R.id.create_confirm_button:
controller.backupPackages(selectedPackageList, contentUri, this);
break;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -37,14 +53,30 @@ public class CreateBackupActivity extends Activity implements View.OnClickListen
}
@Override
public void onClick(View view) {
int viewId = view.getId();
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.backup_menu, menu);
return true;
}
switch (viewId) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_select_all:
IntStream.range(0, packageListView.getCount())
.forEach(position -> {
selectedPackageList.add((String) packageListView.getItemAtPosition(position));
packageListView.setItemChecked(position, true);
});
return true;
default:
return super.onOptionsItemSelected(item);
case R.id.create_confirm_button:
controller.backupPackages(selectedPackageList, contentUri, this);
break;
}
}

View file

@ -3,6 +3,9 @@ package com.stevesoltys.backup.activity.restore;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
@ -10,6 +13,7 @@ import com.stevesoltys.backup.R;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.IntStream;
public class RestoreBackupActivity extends Activity implements View.OnClickListener, AdapterView.OnItemClickListener {
@ -21,6 +25,18 @@ public class RestoreBackupActivity extends Activity implements View.OnClickListe
private Uri contentUri;
@Override
public void onClick(View view) {
int viewId = view.getId();
switch (viewId) {
case R.id.restore_confirm_button:
controller.restorePackages(selectedPackageList, contentUri, this);
break;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -37,14 +53,30 @@ public class RestoreBackupActivity extends Activity implements View.OnClickListe
}
@Override
public void onClick(View view) {
int viewId = view.getId();
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.backup_menu, menu);
return true;
}
switch (viewId) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_select_all:
IntStream.range(0, packageListView.getCount())
.forEach(position -> {
selectedPackageList.add((String) packageListView.getItemAtPosition(position));
packageListView.setItemChecked(position, true);
});
return true;
default:
return super.onOptionsItemSelected(item);
case R.id.restore_confirm_button:
controller.restorePackages(selectedPackageList, contentUri, this);
break;
}
}

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_select_all"
android:title="@string/select_all"
android:showAsAction="never" />
</menu>

View file

@ -18,4 +18,6 @@
<string name="popup_cancel">Cancel</string>
<string name="select_all">Select all</string>
</resources>