Allow user to select all packages during backup and restore
This commit is contained in:
parent
b714952b85
commit
656b7702e0
5 changed files with 87 additions and 13 deletions
|
@ -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" />
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
8
app/src/main/res/menu/backup_menu.xml
Normal file
8
app/src/main/res/menu/backup_menu.xml
Normal 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>
|
|
@ -18,4 +18,6 @@
|
|||
|
||||
<string name="popup_cancel">Cancel</string>
|
||||
|
||||
<string name="select_all">Select all</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue