Skip to content

Commit c440cc5

Browse files
committed
[Feat] (Remove): Add progress bar for removal operation.
1 parent 518bbdd commit c440cc5

4 files changed

Lines changed: 122 additions & 22 deletions

File tree

app/src/main/java/com/fcl/plugin/mobileglues/MainActivity.java

Lines changed: 84 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@
6060
import android.content.UriPermission;
6161
import java.util.Objects;
6262

63-
import android.app.AlertDialog;
6463
import android.content.DialogInterface;
6564
import android.os.CountDownTimer;
6665
import android.os.Message;
6766
import android.widget.Button;
67+
import android.view.LayoutInflater;
68+
import android.view.View;
69+
import android.widget.ProgressBar;
70+
import android.widget.TextView;
71+
import java.util.concurrent.ExecutorService;
72+
import java.util.concurrent.Executors;
73+
import android.os.Handler;
74+
import android.os.Looper;
75+
import androidx.annotation.StringRes;
6876

6977
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener, CompoundButton.OnCheckedChangeListener {
7078
private static final int REQUEST_CODE_SAF = 2000;
@@ -199,28 +207,83 @@ public void onFinish() {
199207
}
200208

201209
private void removeMobileGluesCompletely() {
202-
try {
203-
if (config != null) {
204-
config.deleteConfig(this);
205-
}
206-
deleteFileIfExists("glsl_cache.tmp");
207-
deleteFileIfExists("latest.log");
208-
209-
checkAndDeleteEmptyDirectory();
210-
211-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && MGDirectoryUri != null) {
212-
releaseSafPermissions();
210+
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(
211+
this,
212+
com.google.android.material.R.style.ThemeOverlay_Material3_MaterialAlertDialog
213+
);
214+
View view = LayoutInflater.from(this)
215+
.inflate(R.layout.progress_dialog_md3, null);
216+
ProgressBar progressBar = view.findViewById(R.id.progress_bar);
217+
TextView progressText = view.findViewById(R.id.progress_text);
218+
builder.setTitle(R.string.removing_mobileglues)
219+
.setView(view)
220+
.setCancelable(false);
221+
222+
final androidx.appcompat.app.AlertDialog progressDialog = builder.create();
223+
runOnUiThread(progressDialog::show);
224+
225+
new Thread(() -> {
226+
try {
227+
final int[] step = {0};
228+
229+
runOnUiThread(() -> {
230+
progressText.setText(R.string.deleting_config);
231+
progressBar.setProgress((step[0] + 1) * 20);
232+
});
233+
if (config != null) {
234+
config.deleteConfig(MainActivity.this);
235+
}
236+
237+
step[0]++;
238+
runOnUiThread(() -> {
239+
progressText.setText(R.string.deleting_cache);
240+
progressBar.setProgress((step[0] + 1) * 20);
241+
});
242+
deleteFileIfExists("glsl_cache.tmp");
243+
244+
step[0]++;
245+
runOnUiThread(() -> {
246+
progressText.setText(R.string.deleting_logs);
247+
progressBar.setProgress((step[0] + 1) * 20);
248+
});
249+
deleteFileIfExists("latest.log");
250+
251+
step[0]++;
252+
runOnUiThread(() -> {
253+
progressText.setText(R.string.cleaning_directory);
254+
progressBar.setProgress((step[0] + 1) * 20);
255+
});
256+
checkAndDeleteEmptyDirectory();
257+
258+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && MGDirectoryUri != null) {
259+
step[0]++;
260+
runOnUiThread(() -> {
261+
progressText.setText(R.string.removing_permissions);
262+
progressBar.setProgress((step[0] + 1) * 20);
263+
});
264+
releaseSafPermissions();
265+
}
266+
267+
runOnUiThread(() -> {
268+
resetApplicationState();
269+
progressDialog.dismiss();
270+
showFinalDialog();
271+
});
272+
273+
} catch (Exception e) {
274+
runOnUiThread(() -> {
275+
progressDialog.dismiss();
276+
Toast.makeText(
277+
MainActivity.this,
278+
getString(R.string.remove_failed, e.getMessage()),
279+
Toast.LENGTH_SHORT
280+
).show();
281+
});
213282
}
214-
215-
resetApplicationState();
216-
217-
showFinalDialog();
218-
219-
} catch (Exception e) {
220-
Logger.getLogger("MG").log(Level.SEVERE, "移除失败: ", e);
221-
Toast.makeText(this, getString(R.string.remove_failed, e.getMessage()), Toast.LENGTH_SHORT).show();
222-
}
283+
}).start();
223284
}
285+
286+
224287
private void showFinalDialog() {
225288
new MaterialAlertDialogBuilder(this)
226289
.setTitle(R.string.remove_complete_title)
@@ -302,7 +365,6 @@ private void resetApplicationState() {
302365
hideOptions();
303366
}
304367

305-
306368
private void showOptions() {
307369
try {
308370
isSpinnerInitialized = false;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:orientation="vertical"
7+
android:padding="24dp">
8+
9+
<com.google.android.material.progressindicator.LinearProgressIndicator
10+
android:id="@+id/progress_bar"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:indeterminate="false"
14+
app:trackColor="?attr/colorSurfaceVariant"
15+
app:trackCornerRadius="4dp"
16+
app:trackThickness="4dp" />
17+
18+
<com.google.android.material.textview.MaterialTextView
19+
android:id="@+id/progress_text"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:layout_marginTop="16dp"
23+
android:textAppearance="?attr/textAppearanceBodyMedium"
24+
android:textAlignment="center" />
25+
26+
</LinearLayout>

app/src/main/res/values-zh/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
<b><font color="@android:color/holo_red_dark">确定要继续吗?</font></b></string>
7878
<string name="ok">确定</string>
7979
<string name="ok_with_countdown">确定 (%d 秒)</string>
80+
<string name="removing_mobileglues">正在移除 MobileGlues...</string>
81+
<string name="deleting_config">正在删除配置文件...</string>
82+
<string name="deleting_cache">正在删除缓存文件...</string>
83+
<string name="deleting_logs">正在删除日志文件...</string>
84+
<string name="cleaning_directory">正在清理目录...</string>
85+
<string name="removing_permissions">正在移除权限...</string>
8086
<string name="remove_failed">移除失败: %s</string>
8187
<string name="remove_complete_title">移除完成</string>
8288
<string name="remove_complete_message">MobileGlues 相关文件已完全移除。\n若需进一步完全在您的设备上移除 MobileGlues,请卸载此软件。</string>

app/src/main/res/values/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ Please note, this action is <b><font color="@android:color/holo_red_dark">irreve
7979
<b><font color="@android:color/holo_red_dark">Are you sure you want to continue?</font></b></string>
8080
<string name="ok">OK</string>
8181
<string name="ok_with_countdown">OK (%d s)</string>
82+
<string name="removing_mobileglues">Removing MobileGlues...</string>
83+
<string name="deleting_config">Deleting config files...</string>
84+
<string name="deleting_cache">Deleting cache files...</string>
85+
<string name="deleting_logs">Deleting log files...</string>
86+
<string name="cleaning_directory">Cleaning directory...</string>
87+
<string name="removing_permissions">Removing permissions...</string>
8288
<string name="remove_failed">Remove failed: %s</string>
8389
<string name="remove_complete_title">Removal Complete</string>
8490
<string name="remove_complete_message">MobileGlues related files have been completely removed.\nIf you need to completely remove MobileGlues from your device, please uninstall this software.</string>

0 commit comments

Comments
 (0)