Pre-select all packages and give option to unselect all

This commit is contained in:
Torsten Grote 2019-06-14 11:33:21 -03:00
parent 1185e8dc71
commit 2f2fba8305
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
8 changed files with 25 additions and 13 deletions

View file

@ -5,8 +5,10 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import com.stevesoltys.backup.R;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.IntStream;
@ -17,7 +19,7 @@ public abstract class PackageListActivity extends Activity implements AdapterVie
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) {
String clickedPackage = (String) packageListView.getItemAtPosition(position);
@ -34,12 +36,12 @@ public abstract class PackageListActivity extends Activity implements AdapterVie
@Override
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())
.forEach(position -> {
selectedPackageList.add((String) packageListView.getItemAtPosition(position));
packageListView.setItemChecked(position, true);
selectedPackageList.remove((String) packageListView.getItemAtPosition(position));
packageListView.setItemChecked(position, false);
});
return true;
@ -47,4 +49,12 @@ public abstract class PackageListActivity extends Activity implements AdapterVie
return super.onOptionsItemSelected(item);
}
public void preSelectAllPackages() {
IntStream.range(0, packageListView.getCount())
.forEach(position -> {
selectedPackageList.add((String) packageListView.getItemAtPosition(position));
packageListView.setItemChecked(position, true);
});
}
}

View file

@ -9,8 +9,6 @@ import android.view.View;
import com.stevesoltys.backup.R;
import com.stevesoltys.backup.activity.PackageListActivity;
import java.util.HashSet;
public class CreateBackupActivity extends PackageListActivity implements View.OnClickListener {
private CreateBackupActivityController controller;
@ -32,7 +30,7 @@ public class CreateBackupActivity extends PackageListActivity implements View.On
findViewById(R.id.create_confirm_button).setOnClickListener(this);
packageListView = findViewById(R.id.create_package_list);
selectedPackageList = new HashSet<>();
selectedPackageList.clear();
controller = new CreateBackupActivityController();
AsyncTask.execute(() -> controller.populatePackageList(packageListView, CreateBackupActivity.this));

View file

@ -64,6 +64,7 @@ class CreateBackupActivityController {
packageListView.setOnItemClickListener(parent);
packageListView.setAdapter(new ArrayAdapter<>(parent, R.layout.checked_list_item, eligiblePackageList));
packageListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
parent.preSelectAllPackages();
});
}

View file

@ -6,11 +6,10 @@ import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import com.stevesoltys.backup.R;
import com.stevesoltys.backup.activity.PackageListActivity;
import java.util.HashSet;
public class RestoreBackupActivity extends PackageListActivity implements View.OnClickListener {
private RestoreBackupActivityController controller;
@ -34,7 +33,8 @@ public class RestoreBackupActivity extends PackageListActivity implements View.O
findViewById(R.id.restore_confirm_button).setOnClickListener(this);
packageListView = findViewById(R.id.restore_package_list);
selectedPackageList = new HashSet<>();
selectedPackageList.clear();
contentUri = getIntent().getData();
controller = new RestoreBackupActivityController();

View file

@ -69,6 +69,7 @@ class RestoreBackupActivityController {
packageListView.setOnItemClickListener(parent);
packageListView.setAdapter(new ArrayAdapter<>(parent, R.layout.checked_list_item, eligiblePackageList));
packageListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
parent.preSelectAllPackages();
});
}

View file

@ -30,6 +30,8 @@ public class BackupService {
try {
selectedPackages.add("@pm@");
Log.i(TAG, "Backing up " + selectedPackages.size() + " packages...");
PopupWindow popupWindow = PopupWindowUtil.showLoadingPopupWindow(parent);
BackupObserver backupObserver = new BackupObserver(parent, popupWindow);
ConfigurableBackupTransport backupTransport = getBackupTransport(parent.getApplication());

View file

@ -1,8 +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"
<item android:id="@+id/action_unselect_all"
android:title="@string/unselect_all"
android:showAsAction="never" />
</menu>

View file

@ -18,7 +18,7 @@
<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_packages">Loading packages…</string>
<string name="initializing">Initializing…</string>