Pre-select all packages and give option to unselect all
This commit is contained in:
parent
1185e8dc71
commit
2f2fba8305
8 changed files with 25 additions and 13 deletions
|
@ -5,8 +5,10 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.stevesoltys.backup.R;
|
import com.stevesoltys.backup.R;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
@ -17,7 +19,7 @@ public abstract class PackageListActivity extends Activity implements AdapterVie
|
||||||
|
|
||||||
protected ListView packageListView;
|
protected ListView packageListView;
|
||||||
|
|
||||||
protected Set<String> selectedPackageList;
|
protected final Set<String> selectedPackageList = new HashSet<>();
|
||||||
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
String clickedPackage = (String) packageListView.getItemAtPosition(position);
|
String clickedPackage = (String) packageListView.getItemAtPosition(position);
|
||||||
|
@ -34,12 +36,12 @@ public abstract class PackageListActivity extends Activity implements AdapterVie
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
|
||||||
if (item.getItemId() == R.id.action_select_all) {
|
if (item.getItemId() == R.id.action_unselect_all) {
|
||||||
|
|
||||||
IntStream.range(0, packageListView.getCount())
|
IntStream.range(0, packageListView.getCount())
|
||||||
.forEach(position -> {
|
.forEach(position -> {
|
||||||
selectedPackageList.add((String) packageListView.getItemAtPosition(position));
|
selectedPackageList.remove((String) packageListView.getItemAtPosition(position));
|
||||||
packageListView.setItemChecked(position, true);
|
packageListView.setItemChecked(position, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -47,4 +49,12 @@ public abstract class PackageListActivity extends Activity implements AdapterVie
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void preSelectAllPackages() {
|
||||||
|
IntStream.range(0, packageListView.getCount())
|
||||||
|
.forEach(position -> {
|
||||||
|
selectedPackageList.add((String) packageListView.getItemAtPosition(position));
|
||||||
|
packageListView.setItemChecked(position, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ import android.view.View;
|
||||||
import com.stevesoltys.backup.R;
|
import com.stevesoltys.backup.R;
|
||||||
import com.stevesoltys.backup.activity.PackageListActivity;
|
import com.stevesoltys.backup.activity.PackageListActivity;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public class CreateBackupActivity extends PackageListActivity implements View.OnClickListener {
|
public class CreateBackupActivity extends PackageListActivity implements View.OnClickListener {
|
||||||
|
|
||||||
private CreateBackupActivityController controller;
|
private CreateBackupActivityController controller;
|
||||||
|
@ -32,7 +30,7 @@ public class CreateBackupActivity extends PackageListActivity implements View.On
|
||||||
findViewById(R.id.create_confirm_button).setOnClickListener(this);
|
findViewById(R.id.create_confirm_button).setOnClickListener(this);
|
||||||
|
|
||||||
packageListView = findViewById(R.id.create_package_list);
|
packageListView = findViewById(R.id.create_package_list);
|
||||||
selectedPackageList = new HashSet<>();
|
selectedPackageList.clear();
|
||||||
|
|
||||||
controller = new CreateBackupActivityController();
|
controller = new CreateBackupActivityController();
|
||||||
AsyncTask.execute(() -> controller.populatePackageList(packageListView, CreateBackupActivity.this));
|
AsyncTask.execute(() -> controller.populatePackageList(packageListView, CreateBackupActivity.this));
|
||||||
|
|
|
@ -64,6 +64,7 @@ class CreateBackupActivityController {
|
||||||
packageListView.setOnItemClickListener(parent);
|
packageListView.setOnItemClickListener(parent);
|
||||||
packageListView.setAdapter(new ArrayAdapter<>(parent, R.layout.checked_list_item, eligiblePackageList));
|
packageListView.setAdapter(new ArrayAdapter<>(parent, R.layout.checked_list_item, eligiblePackageList));
|
||||||
packageListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
packageListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||||
|
parent.preSelectAllPackages();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,10 @@ import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.stevesoltys.backup.R;
|
import com.stevesoltys.backup.R;
|
||||||
import com.stevesoltys.backup.activity.PackageListActivity;
|
import com.stevesoltys.backup.activity.PackageListActivity;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public class RestoreBackupActivity extends PackageListActivity implements View.OnClickListener {
|
public class RestoreBackupActivity extends PackageListActivity implements View.OnClickListener {
|
||||||
|
|
||||||
private RestoreBackupActivityController controller;
|
private RestoreBackupActivityController controller;
|
||||||
|
@ -34,7 +33,8 @@ public class RestoreBackupActivity extends PackageListActivity implements View.O
|
||||||
findViewById(R.id.restore_confirm_button).setOnClickListener(this);
|
findViewById(R.id.restore_confirm_button).setOnClickListener(this);
|
||||||
|
|
||||||
packageListView = findViewById(R.id.restore_package_list);
|
packageListView = findViewById(R.id.restore_package_list);
|
||||||
selectedPackageList = new HashSet<>();
|
selectedPackageList.clear();
|
||||||
|
|
||||||
contentUri = getIntent().getData();
|
contentUri = getIntent().getData();
|
||||||
|
|
||||||
controller = new RestoreBackupActivityController();
|
controller = new RestoreBackupActivityController();
|
||||||
|
|
|
@ -69,6 +69,7 @@ class RestoreBackupActivityController {
|
||||||
packageListView.setOnItemClickListener(parent);
|
packageListView.setOnItemClickListener(parent);
|
||||||
packageListView.setAdapter(new ArrayAdapter<>(parent, R.layout.checked_list_item, eligiblePackageList));
|
packageListView.setAdapter(new ArrayAdapter<>(parent, R.layout.checked_list_item, eligiblePackageList));
|
||||||
packageListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
packageListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||||
|
parent.preSelectAllPackages();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@ public class BackupService {
|
||||||
try {
|
try {
|
||||||
selectedPackages.add("@pm@");
|
selectedPackages.add("@pm@");
|
||||||
|
|
||||||
|
Log.i(TAG, "Backing up " + selectedPackages.size() + " packages...");
|
||||||
|
|
||||||
PopupWindow popupWindow = PopupWindowUtil.showLoadingPopupWindow(parent);
|
PopupWindow popupWindow = PopupWindowUtil.showLoadingPopupWindow(parent);
|
||||||
BackupObserver backupObserver = new BackupObserver(parent, popupWindow);
|
BackupObserver backupObserver = new BackupObserver(parent, popupWindow);
|
||||||
ConfigurableBackupTransport backupTransport = getBackupTransport(parent.getApplication());
|
ConfigurableBackupTransport backupTransport = getBackupTransport(parent.getApplication());
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item android:id="@+id/action_select_all"
|
<item android:id="@+id/action_unselect_all"
|
||||||
android:title="@string/select_all"
|
android:title="@string/unselect_all"
|
||||||
android:showAsAction="never" />
|
android:showAsAction="never" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
<string name="popup_cancel">Cancel</string>
|
<string name="popup_cancel">Cancel</string>
|
||||||
|
|
||||||
<string name="select_all">Select all</string>
|
<string name="unselect_all">Unselect all</string>
|
||||||
<string name="loading_backup">Loading backup…</string>
|
<string name="loading_backup">Loading backup…</string>
|
||||||
<string name="loading_packages">Loading packages…</string>
|
<string name="loading_packages">Loading packages…</string>
|
||||||
<string name="initializing">Initializing…</string>
|
<string name="initializing">Initializing…</string>
|
||||||
|
|
Loading…
Reference in a new issue