Skip to content

Commit

Permalink
Add support to decode image for theme intent
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavpandey committed Jul 21, 2024
1 parent e1795a8 commit 15911f8
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Pranav Pandey
* Copyright 2019-2024 Pranav Pandey
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -610,14 +610,14 @@ public static boolean isValidThemeIntent(@Nullable Context context, @Nullable In
|| (theme != null && theme.contains(Theme.QUERY)
&& (theme.contains(Theme.HOST) || theme.contains(Theme.SCHEME_CUSTOM)));
} else {
String data = intent.getData() != null ? intent.getData().toString() : null;
String theme = intent.getData() != null ? intent.getData().toString() : null;

return DynamicFileUtils.isValidMimeType(context,
intent, Theme.MIME, Theme.EXTENSION)
intent.getData(), Theme.MIME, Theme.EXTENSION)
|| DynamicFileUtils.isValidMimeType(context,
intent, Theme.MIME_IMAGE_MATCH, Theme.EXTENSION)
|| (data != null && data.contains(Theme.QUERY)
&& (data.contains(Theme.HOST) || data.contains(Theme.SCHEME_CUSTOM)));
intent.getData(), Theme.MIME_IMAGE_MATCH, Theme.EXTENSION)
|| (theme != null && theme.contains(Theme.QUERY)
&& (theme.contains(Theme.HOST) || theme.contains(Theme.SCHEME_CUSTOM)));
}
}

Expand Down Expand Up @@ -749,12 +749,13 @@ public static boolean isValidThemeIntent(@Nullable Context context, @Nullable In
}

try {
if (Intent.ACTION_SEND.equals(intent.getAction())
&& intent.getStringExtra(Intent.EXTRA_TEXT) != null
&& isValidTheme(intent.getStringExtra(Intent.EXTRA_TEXT))) {
return Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT));
if (Intent.ACTION_SEND.equals(intent.getAction())) {
return intent.getStringExtra(Intent.EXTRA_TEXT) != null
&& isValidTheme(intent.getStringExtra(Intent.EXTRA_TEXT))
? Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT))
: DynamicIntentUtils.getStreamOrData(intent, Intent.ACTION_SEND);
} else {
return DynamicIntentUtils.getStreamOrData(intent, Intent.ACTION_SEND);
return DynamicIntentUtils.getStreamOrData(intent, Intent.ACTION_VIEW);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -783,17 +784,17 @@ && isValidTheme(intent.getStringExtra(Intent.EXTRA_TEXT))) {
try {
if (uri.getQueryParameterNames().contains(Theme.PARAMETER)) {
data = DynamicThemeUtils.decodeTheme(uri.getQueryParameter(Theme.PARAMETER));
} else if (DynamicFileUtils.isValidMimeType(context, uri,
Theme.MIME_IMAGE_MATCH, Theme.EXTENSION_IMAGE)) {
data = DynamicCodeUtils.getTheme(DynamicBitmapUtils.getBitmap(context, uri));
} else if (DynamicFileUtils.isValidMimeType(context, uri,
Theme.MIME, Theme.EXTENSION)) {
data = DynamicFileUtils.readStringFromFile(context, uri);
} else if (DynamicFileUtils.isValidMimeType(context, uri,
Theme.MIME_IMAGE_MATCH, Theme.EXTENSION_IMAGE)) {
data = DynamicCodeUtils.getTheme(DynamicBitmapUtils.getBitmap(context, uri));
}
} catch (Exception ignored) {
}

return data;
return isValidTheme(data) ? data : null;
}

/**
Expand Down

0 comments on commit 15911f8

Please sign in to comment.