diff --git a/app/src/main/java/com/stevesoltys/backup/activity/PackageListActivity.java b/app/src/main/java/com/stevesoltys/backup/activity/PackageListActivity.java index fd488e17..7e7d99eb 100644 --- a/app/src/main/java/com/stevesoltys/backup/activity/PackageListActivity.java +++ b/app/src/main/java/com/stevesoltys/backup/activity/PackageListActivity.java @@ -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 selectedPackageList; + protected final Set 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); + }); + } } diff --git a/app/src/main/java/com/stevesoltys/backup/activity/backup/CreateBackupActivity.java b/app/src/main/java/com/stevesoltys/backup/activity/backup/CreateBackupActivity.java index cdfc0549..197ca520 100644 --- a/app/src/main/java/com/stevesoltys/backup/activity/backup/CreateBackupActivity.java +++ b/app/src/main/java/com/stevesoltys/backup/activity/backup/CreateBackupActivity.java @@ -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)); diff --git a/app/src/main/java/com/stevesoltys/backup/activity/backup/CreateBackupActivityController.java b/app/src/main/java/com/stevesoltys/backup/activity/backup/CreateBackupActivityController.java index 5109d229..db43cd92 100644 --- a/app/src/main/java/com/stevesoltys/backup/activity/backup/CreateBackupActivityController.java +++ b/app/src/main/java/com/stevesoltys/backup/activity/backup/CreateBackupActivityController.java @@ -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(); }); } diff --git a/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivity.java b/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivity.java index 4d206f57..056d19f4 100644 --- a/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivity.java +++ b/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivity.java @@ -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(); diff --git a/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivityController.java b/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivityController.java index 916a57dd..9daa8799 100644 --- a/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivityController.java +++ b/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivityController.java @@ -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(); }); } diff --git a/app/src/main/java/com/stevesoltys/backup/service/backup/BackupService.java b/app/src/main/java/com/stevesoltys/backup/service/backup/BackupService.java index 84be267f..779bcdd1 100644 --- a/app/src/main/java/com/stevesoltys/backup/service/backup/BackupService.java +++ b/app/src/main/java/com/stevesoltys/backup/service/backup/BackupService.java @@ -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()); diff --git a/app/src/main/res/menu/backup_menu.xml b/app/src/main/res/menu/backup_menu.xml index 4a0a4509..f475ef43 100644 --- a/app/src/main/res/menu/backup_menu.xml +++ b/app/src/main/res/menu/backup_menu.xml @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4bd56585..c68da057 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -18,7 +18,7 @@ Cancel - Select all + Unselect all Loading backup… Loading packages… Initializing…