make png fallback configurable and improve share sheet

This commit is contained in:
Kieran W 2025-02-09 12:22:53 +00:00
parent c604547cad
commit 158ac3c19a
5 changed files with 23 additions and 1 deletions

View File

@ -58,6 +58,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
private var iconsPerX = 0
private var iconSize = 0
private var insensitiveSort = false
private var isPngFallback = true
// Constants
private lateinit var internalDir: File
@ -127,6 +128,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
this.scroll = this.backupSharedPreferences.getBoolean("scroll", false)
this.vibrate = this.backupSharedPreferences.getBoolean("vibrate", true)
this.insensitiveSort = this.backupSharedPreferences.getBoolean("insensitiveSort", false)
this.isPngFallback = this.backupSharedPreferences.getBoolean("isPngFallback", true)
this.iconsPerX = this.backupSharedPreferences.getInt("iconsPerX", 3)
this.totalIconPadding =
@ -228,6 +230,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
this.currentInputEditorInfo,
this.compatCache,
this.imageLoader,
this.isPngFallback,
)
}

View File

@ -91,6 +91,7 @@ class MainActivity : AppCompatActivity() {
toggle(findViewById(R.id.restoreOnClose), "restoreOnClose", false) {}
toggle(findViewById(R.id.scroll), "scroll", false) {}
toggle(findViewById(R.id.insensitive_sort), "insensitiveSort", false) {}
toggle(findViewById(R.id.pngFallback), "isPngFallback", true) {}
val versionText: TextView = findViewById(R.id.versionText)
var version = getString(R.string.version_text)

View File

@ -36,6 +36,7 @@ import java.io.IOException
* @property compatCache: used to track previous x converted compat stickers
* @property imageLoader: coil imageLoader object used to convert a sticker file to a drawable ready
* for writing to a compat sticker
* @property isPngFallback: is a png fallback enabled
*/
class StickerSender(
private val context: Context,
@ -45,6 +46,7 @@ class StickerSender(
private val currentInputEditorInfo: EditorInfo?,
private val compatCache: Cache,
private val imageLoader: ImageLoader,
private val isPngFallback: Boolean,
) {
private val supportedMimes = this.currentInputEditorInfo?.contentMimeTypes ?: emptyArray()
@ -175,7 +177,7 @@ class StickerSender(
*/
private suspend fun doFallbackCommitContent(mimeType: String, file: File) {
if ("image/png" in supportedMimes || "image/*" in supportedMimes) {
if (isPngFallback && ("image/png" in supportedMimes || "image/*" in supportedMimes)) {
val compatSticker = createCompatSticker(file)
if (compatSticker != null) {
if (!doCommitContent("image/png", compatSticker)) {
@ -209,6 +211,7 @@ class StickerSender(
}
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
shareIntent.setPackage(packageName)
val chooserIntent = Intent.createChooser(shareIntent, "Share Sticker")
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

View File

@ -259,6 +259,20 @@
android:text="@string/options_insensitive_sort" />
</LinearLayout>
<LinearLayout
style="@style/widthMatchHeightWrap"
android:orientation="horizontal">
<CheckBox
android:id="@+id/pngFallback"
style="@style/checkbox" />
<TextView
style="@style/body_text"
android:paddingBottom="@dimen/content_margin"
android:text="@string/options_png_fallback" />
</LinearLayout>
<LinearLayout
style="@style/widthMatchHeightWrap"
android:orientation="horizontal">

View File

@ -26,6 +26,7 @@
<string name="options_restore_on_close">Restore previous keyboard on keyboard close</string>
<string name="options_scroll">Enable swipe between packs (perpendicular to scroll direction)</string>
<string name="options_insensitive_sort">Enable case-insensitive pack sorting</string>
<string name="options_png_fallback">Enable PNG sticker fallback if sticker format isn\'t supported</string>
<string name="options_icons_per_x_lbl">"Number of Rows: "</string>
<string name="options_icon_size_status_lbl">"Icon size: "</string>
<!-- Info -->