|
|
@@ -2,40 +2,36 @@ package com.example.modifier;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.content.Context;
|
|
|
+import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
-import androidx.core.view.LayoutInflaterCompat;
|
|
|
+import androidx.core.content.ContextCompat;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
import com.example.modifier.databinding.ItemBackupBinding;
|
|
|
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|
|
|
|
|
-import java.text.DateFormat;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
|
-import java.util.Locale;
|
|
|
|
|
|
public class BackupAdapter extends RecyclerView.Adapter<BackupAdapter.BackupViewHolder> {
|
|
|
|
|
|
- public interface OnRestoreListener {
|
|
|
- void onRestore(Backup backup);
|
|
|
- }
|
|
|
|
|
|
private Context context;
|
|
|
private List<Backup> backups;
|
|
|
- private OnRestoreListener onRestoreListener;
|
|
|
|
|
|
public BackupAdapter(Context context, List<Backup> backups) {
|
|
|
this.context = context;
|
|
|
this.backups = backups;
|
|
|
}
|
|
|
|
|
|
- public void setOnRestoreListener(OnRestoreListener onRestoreListener) {
|
|
|
- this.onRestoreListener = onRestoreListener;
|
|
|
- }
|
|
|
-
|
|
|
@NonNull
|
|
|
@Override
|
|
|
public BackupAdapter.BackupViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
@@ -52,9 +48,45 @@ public class BackupAdapter extends RecyclerView.Adapter<BackupAdapter.BackupView
|
|
|
holder.binding.tvInfo.setText(String.format("MCC: %s, MNC: %s, Country: %s",
|
|
|
backup.getConfig().getMcc(), backup.getConfig().getMnc(), backup.getConfig().getCountry()));
|
|
|
holder.binding.btnRestore.setOnClickListener(v -> {
|
|
|
- if (onRestoreListener != null) {
|
|
|
- onRestoreListener.onRestore(backup);
|
|
|
- }
|
|
|
+ new MaterialAlertDialogBuilder(context)
|
|
|
+ .setTitle("Restore backup")
|
|
|
+ .setMessage("Are you sure you want to restore this backup?")
|
|
|
+ .setPositiveButton("Yes", (dialog, which) -> {
|
|
|
+ new Thread(() -> {
|
|
|
+ try {
|
|
|
+ Global.save(backup.getConfig());
|
|
|
+ Global.stop(false, false, true);
|
|
|
+ Utils.runAsRoot("pm clear com.google.android.apps.messaging", "cp -rf " + backup.getPath() + "/data/* /data/data/com.google.android.apps.messaging/");
|
|
|
+ Global.stop(false, false, true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ })
|
|
|
+ .setNegativeButton("No", null)
|
|
|
+ .show();
|
|
|
+ });
|
|
|
+ holder.binding.btnDel.setOnClickListener(v -> {
|
|
|
+ new MaterialAlertDialogBuilder(context)
|
|
|
+ .setTitle("Delete backup")
|
|
|
+ .setMessage("Are you sure you want to delete this backup?")
|
|
|
+ .setPositiveButton("Yes", (dialog, which) -> {
|
|
|
+ File file = new File(backup.getPath());
|
|
|
+ if (file.exists()) {
|
|
|
+ try {
|
|
|
+ Utils.runAsRoot("rm -rf " + backup.getPath());
|
|
|
+ backups.remove(backup);
|
|
|
+ notifyItemRemoved(position);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Log.e("BackupAdapter", "File not found");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setNegativeButton("No", null)
|
|
|
+ .show();
|
|
|
});
|
|
|
}
|
|
|
|