@@ -37,9 +37,15 @@ protected CustomWordsImporter getProcessor() {
3737 @ Override
3838 protected boolean onClick (Preference p ) {
3939 setDefaultHandlers ();
40+ getProcessor ().setCancelHandler (this ::onCancel );
4041 getProcessor ().setFailureHandler (this ::onFailure );
4142 getProcessor ().setProgressHandler (this ::onProgress );
42- browseFiles ();
43+
44+ if (getProcessor ().isRunning ()) {
45+ getProcessor ().cancel ();
46+ } else {
47+ browseFiles ();
48+ }
4349 return true ;
4450 }
4551
@@ -50,6 +56,18 @@ protected boolean onStartProcessing() {
5056 return false ;
5157 }
5258
59+ private void onCancel () {
60+ activity .runOnUiThread (() -> {
61+ final String statusMsg = activity .getString (R .string .dictionary_import_canceled );
62+
63+ setAndNotifyReady ();
64+ DictionaryProgressNotification .getInstance (activity ).showMessage ("" , statusMsg , statusMsg );
65+
66+ item .setTitle (R .string .dictionary_import_custom_words );
67+ item .setSummary (statusMsg );
68+ });
69+ }
70+
5371 private void onProgress (float progress ) {
5472 final String numberFormat = (progress - lastProgress ) < 2 ? "%1.3f%%" : "%1.0f%%" ;
5573 final String loadingMsg = activity .getString (R .string .dictionary_import_progress , String .format (Locale .getDefault (), numberFormat , progress ));
@@ -87,7 +105,12 @@ protected String getSuccessTitle() {
87105 @ Override
88106 public void enable () {
89107 item .setSummary (R .string .dictionary_import_custom_words_summary );
90- super .enable ();
108+ }
109+
110+ @ Override
111+ public void disable () {
112+ // we don't really disable this item, we just prevent browsing for files
113+ item .setTitle (R .string .dictionary_import_cancel );
91114 }
92115
93116 void setBrowseFilesLauncher (ActivityResultLauncher <Intent > launcher ) {
0 commit comments