|
13 | 13 | import android.net.Uri;
|
14 | 14 | import android.os.Bundle;
|
15 | 15 | import android.os.Environment;
|
| 16 | +import android.os.Handler; |
16 | 17 | import android.os.IBinder;
|
17 | 18 | import android.provider.Settings;
|
18 | 19 | import android.util.Log;
|
|
28 | 29 | import androidx.activity.result.ActivityResultLauncher;
|
29 | 30 | import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
|
30 | 31 | import androidx.annotation.IdRes;
|
| 32 | +import androidx.annotation.MainThread; |
31 | 33 | import androidx.annotation.NonNull;
|
32 | 34 | import androidx.annotation.Nullable;
|
33 | 35 | import androidx.annotation.StringRes;
|
@@ -110,6 +112,8 @@ public class DownloadDialog extends DialogFragment
|
110 | 112 | int selectedAudioIndex = 0; // default to the first item
|
111 | 113 | @State
|
112 | 114 | int selectedSubtitleIndex = 0; // default to the first item
|
| 115 | + @State |
| 116 | + boolean okClicked = false; // guard |
113 | 117 |
|
114 | 118 | private StoredDirectoryHelper mainStorageAudio = null;
|
115 | 119 | private StoredDirectoryHelper mainStorageVideo = null;
|
@@ -350,13 +354,35 @@ private void initToolbar(final Toolbar toolbar) {
|
350 | 354 |
|
351 | 355 | toolbar.setOnMenuItemClickListener(item -> {
|
352 | 356 | if (item.getItemId() == R.id.okay) {
|
353 |
| - prepareSelectedDownload(); |
| 357 | + if (!this.okClicked) { |
| 358 | + this.okClicked = true; |
| 359 | + prepareSelectedDownload(); |
| 360 | + } |
354 | 361 | return true;
|
355 | 362 | }
|
356 | 363 | return false;
|
357 | 364 | });
|
358 | 365 | }
|
359 | 366 |
|
| 367 | + @MainThread |
| 368 | + @Override |
| 369 | + public void onStart() { |
| 370 | + super.onStart(); |
| 371 | + final boolean autoOkDownloadDialog = |
| 372 | + PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean( |
| 373 | + context.getString(R.string.auto_ok_download_dialog_key), false); |
| 374 | + if (autoOkDownloadDialog) { |
| 375 | + final Handler timerHandler = new Handler(); |
| 376 | + final Runnable timerRunnable = new Runnable() { |
| 377 | + @Override |
| 378 | + public void run() { |
| 379 | + okButton.performClick(); |
| 380 | + } |
| 381 | + }; |
| 382 | + timerHandler.postDelayed(timerRunnable, 500); |
| 383 | + } |
| 384 | + } |
| 385 | + |
360 | 386 | @Override
|
361 | 387 | public void onDestroy() {
|
362 | 388 | super.onDestroy();
|
|
0 commit comments