diff options
author | Sergei Kozelko <KozelkoS@yandex.ru> | 2022-12-23 21:47:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-23 21:47:41 +0000 |
commit | 483cb7023c9cbb536978d487e4d9a4efb27a32d7 (patch) | |
tree | 47c41eef22be98360e1f4d02402cd4dd7f2261ac /app/src/main/java/ml/docilealligator | |
parent | c0deb78734e0869fd86742414bee825ebd5466c4 (diff) | |
download | infinity-for-reddit-483cb7023c9cbb536978d487e4d9a4efb27a32d7.tar infinity-for-reddit-483cb7023c9cbb536978d487e4d9a4efb27a32d7.tar.gz infinity-for-reddit-483cb7023c9cbb536978d487e4d9a4efb27a32d7.tar.bz2 infinity-for-reddit-483cb7023c9cbb536978d487e4d9a4efb27a32d7.tar.lz infinity-for-reddit-483cb7023c9cbb536978d487e4d9a4efb27a32d7.tar.xz infinity-for-reddit-483cb7023c9cbb536978d487e4d9a4efb27a32d7.tar.zst infinity-for-reddit-483cb7023c9cbb536978d487e4d9a4efb27a32d7.zip |
Allow importing theme as any text (#1275)
* Allow importing theme as any text
Browsers copy content as text/html and it caused theme import to fail
* Coerce clipboard data to text
Clipboard can have mime type of text even when it doesn't actually contain text. For example it can contain uri to text content provider. Using `coerceToText` automatically handles all cases and returns best text representation of content.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java index c18fd0fc..3aeb102a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java @@ -8,6 +8,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; +import android.text.TextUtils; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -269,16 +270,20 @@ public class CustomThemeListingActivity extends BaseActivity implements if (!clipboard.hasPrimaryClip()) { Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show(); } else if (clipboard.getPrimaryClipDescription() != null && - !clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) { - // since the clipboard has data but it is not plain text + !clipboard.getPrimaryClipDescription().hasMimeType("text/*")) { + // since the clipboard has data but it is not text Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show(); } else if (clipboard.getPrimaryClip() != null) { ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); - String json = item.getText().toString(); - try { - CustomTheme customTheme = new Gson().fromJson(json, CustomTheme.class); - checkDuplicateAndImportTheme(customTheme, true); - } catch (JsonSyntaxException e) { + String json = item.coerceToText(this.getApplicationContext()).toString(); + if (!TextUtils.isEmpty(json)) { + try { + CustomTheme customTheme = new Gson().fromJson(json, CustomTheme.class); + checkDuplicateAndImportTheme(customTheme, true); + } catch (JsonSyntaxException e) { + Snackbar.make(coordinatorLayout, R.string.parse_theme_failed, Snackbar.LENGTH_SHORT).show(); + } + } else { Snackbar.make(coordinatorLayout, R.string.parse_theme_failed, Snackbar.LENGTH_SHORT).show(); } } |