mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-27 19:38:22 +01:00
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.
This commit is contained in:
parent
c0deb78734
commit
483cb7023c
@ -8,6 +8,7 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
@ -269,16 +270,20 @@ public class CustomThemeListingActivity extends BaseActivity implements
|
|||||||
if (!clipboard.hasPrimaryClip()) {
|
if (!clipboard.hasPrimaryClip()) {
|
||||||
Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show();
|
||||||
} else if (clipboard.getPrimaryClipDescription() != null &&
|
} else if (clipboard.getPrimaryClipDescription() != null &&
|
||||||
!clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
|
!clipboard.getPrimaryClipDescription().hasMimeType("text/*")) {
|
||||||
// since the clipboard has data but it is not plain text
|
// since the clipboard has data but it is not text
|
||||||
Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show();
|
||||||
} else if (clipboard.getPrimaryClip() != null) {
|
} else if (clipboard.getPrimaryClip() != null) {
|
||||||
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
|
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
|
||||||
String json = item.getText().toString();
|
String json = item.coerceToText(this.getApplicationContext()).toString();
|
||||||
try {
|
if (!TextUtils.isEmpty(json)) {
|
||||||
CustomTheme customTheme = new Gson().fromJson(json, CustomTheme.class);
|
try {
|
||||||
checkDuplicateAndImportTheme(customTheme, true);
|
CustomTheme customTheme = new Gson().fromJson(json, CustomTheme.class);
|
||||||
} catch (JsonSyntaxException e) {
|
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();
|
Snackbar.make(coordinatorLayout, R.string.parse_theme_failed, Snackbar.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user