|
60 | 60 | import android.content.UriPermission; |
61 | 61 | import java.util.Objects; |
62 | 62 |
|
63 | | -import android.app.AlertDialog; |
64 | 63 | import android.content.DialogInterface; |
65 | 64 | import android.os.CountDownTimer; |
66 | 65 | import android.os.Message; |
67 | 66 | 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; |
68 | 76 |
|
69 | 77 | public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener, CompoundButton.OnCheckedChangeListener { |
70 | 78 | private static final int REQUEST_CODE_SAF = 2000; |
@@ -199,28 +207,83 @@ public void onFinish() { |
199 | 207 | } |
200 | 208 |
|
201 | 209 | 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 | + }); |
213 | 282 | } |
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(); |
223 | 284 | } |
| 285 | + |
| 286 | + |
224 | 287 | private void showFinalDialog() { |
225 | 288 | new MaterialAlertDialogBuilder(this) |
226 | 289 | .setTitle(R.string.remove_complete_title) |
@@ -302,7 +365,6 @@ private void resetApplicationState() { |
302 | 365 | hideOptions(); |
303 | 366 | } |
304 | 367 |
|
305 | | - |
306 | 368 | private void showOptions() { |
307 | 369 | try { |
308 | 370 | isSpinnerInitialized = false; |
|
0 commit comments