limit search results to 128 + update agp + ktlintCheck passes

This commit is contained in:
Kieran W 2024-03-21 23:56:29 +00:00
parent 92492c934d
commit cc1535edcd
8 changed files with 87 additions and 91 deletions

View File

@ -69,15 +69,15 @@ android {
}
dependencies {
dokkaPlugin("org.jetbrains.dokka:android-documentation-plugin:1.9.10")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.22")
dokkaPlugin("org.jetbrains.dokka:android-documentation-plugin:1.9.20")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.23")
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.preference:preference-ktx:1.2.1")
implementation("io.coil-kt:coil:2.5.0")
implementation("io.coil-kt:coil-gif:2.5.0")
implementation("io.coil-kt:coil-video:2.5.0")
implementation("io.coil-kt:coil:2.6.0")
implementation("io.coil-kt:coil-gif:2.6.0")
implementation("io.coil-kt:coil-video:2.6.0")
implementation("androidx.gridlayout:gridlayout:1.0.0")
implementation("io.noties.markwon:core:4.6.2")
androidTestImplementation("junit:junit:4.13.2")

View File

@ -2,15 +2,15 @@ package com.fredhappyface.ewesticker
import android.content.SharedPreferences
import android.inputmethodservice.InputMethodService
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.view.GestureDetector
import android.view.LayoutInflater
import android.view.HapticFeedbackConstants
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.Button
import android.widget.ImageButton
import android.widget.LinearLayout
import android.widget.RelativeLayout
@ -117,11 +117,11 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
this.iconSize =
(
if (this.vertical) {
(resources.displayMetrics.widthPixels - this.totalIconPadding) / this.iconsPerX.toFloat()
} else {
(this.sharedPreferences.getInt("iconSize", 80) * scale)
}
).toInt()
(resources.displayMetrics.widthPixels - this.totalIconPadding) / this.iconsPerX.toFloat()
} else {
(this.sharedPreferences.getInt("iconSize", 80) * scale)
}
).toInt()
this.toaster = Toaster(baseContext)
// Load Packs
this.loadedPacks = HashMap()
@ -173,11 +173,11 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
this.fullIconSize =
(
min(
resources.displayMetrics.widthPixels,
this.keyboardHeight -
resources.displayMetrics.widthPixels,
this.keyboardHeight -
resources.getDimensionPixelOffset(R.dimen.text_size_body) * 2,
) * 0.95
)
) * 0.95
)
.toInt()
createPackIcons()
return keyboardLayout
@ -260,8 +260,10 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
packContent.addView(recyclerView)
}
/**
* Set the current tab to the search page/ view
*/
private fun searchView() {
for (packCard in this.packsList) {
val packButton = packCard.findViewById<ImageButton>(R.id.stickerButton)
if (packButton.tag == "__search__") {
@ -273,66 +275,69 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
qwertyWidth = (resources.displayMetrics.widthPixels / 10.4).toInt()
val qwertyLayout = layoutInflater.inflate(R.layout.qwerty_layout, packContent, false)
val searchText = qwertyLayout.findViewById<TextView>(R.id.search_text)
val search_results = qwertyLayout.findViewById<LinearLayout>(R.id.search_results)
val searchResults = qwertyLayout.findViewById<LinearLayout>(R.id.search_results)
val searchResultsHeight =
packContent.layoutParams.height -
(
resources.getDimension(R.dimen.qwerty_row_height) +
resources.getDimension(R.dimen.qwerty_row_height) * 4
resources.getDimension(R.dimen.qwerty_row_height) * 4
)
search_results.layoutParams.height = searchResultsHeight.toInt()
searchResults.layoutParams.height = searchResultsHeight.toInt()
fun searchStickers(query: String): List<File> {
return this.allStickers.filter { it.name.contains(query, ignoreCase = true) }
}
// Function to update the search results view with a list of stickers
fun updateSearchResults(stickers: List<File>) {
val recyclerView = RecyclerView(this)
val adapter = StickerPackAdapter((searchResultsHeight*.95).toInt(), stickers.toTypedArray(), this, gestureDetector)
val layoutManager = GridLayoutManager(
val recyclerView = RecyclerView(baseContext)
val adapter = StickerPackAdapter(
(searchResultsHeight * 0.9).toInt(),
stickers.take(128).toTypedArray(),
this,
gestureDetector,
)
val layoutManager = GridLayoutManager(
baseContext,
1,
RecyclerView.HORIZONTAL,
false,
)
recyclerView.layoutManager = layoutManager
recyclerView.adapter = adapter
search_results.removeAllViewsInLayout()
search_results.addView(recyclerView)
searchResults.removeAllViewsInLayout()
searchResults.addView(recyclerView)
}
fun searchAppend(char:String){
fun searchAppend(char: String) {
searchText.append(char)
val query = searchText.text.toString()
val searchResults = searchStickers(query)
updateSearchResults(searchResults)
updateSearchResults(searchStickers(query))
}
fun searchBack(char:String){
fun searchBack(char: String) {
if (searchText.text.isNotEmpty()) {
val newText = searchText.text.substring(0, searchText.text.length - 1)
searchText.text = newText
}
val query = searchText.text.toString()
val searchResults = searchStickers(query)
updateSearchResults(searchResults)
updateSearchResults(searchStickers(query))
}
fun searchClear(char:String){
searchText.text = ""
search_results.removeAllViews()
}
fun searchClear(char: String) {
searchText.text = ""
searchResults.removeAllViews()
}
fun _addKey(char: String, secondaryChar: String,tap: (String) -> Unit = ::searchAppend,longTap: (String) -> Unit = ::searchAppend) : RelativeLayout {
fun addKey(
char: String,
secondaryChar: String,
tap: (String) -> Unit = ::searchAppend,
longTap: (String) -> Unit = ::searchAppend,
): RelativeLayout {
val buttonView = layoutInflater.inflate(R.layout.qwerty_key, null, false)
val button = buttonView.findViewById<RelativeLayout>(R.id.btn)
val layoutParams =
@ -346,6 +351,9 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
val sText = buttonView.findViewById<TextView>(R.id.secondaryText)
sText.text = secondaryChar
button.setOnClickListener {
if (SDK_INT >= Build.VERSION_CODES.O_MR1) {
it.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_PRESS)
}
tap((it.tag as Array<String>)[0])
}
button.setOnLongClickListener {
@ -355,38 +363,40 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
return button
}
fun _addRow(row: LinearLayout, chars: List<String>, secondaryChars: List<String>, ){
fun addRow(row: LinearLayout, chars: List<String>, secondaryChars: List<String>) {
for ((index, key) in chars.withIndex()) {
val button = _addKey(key, secondaryChars[index])
val button = addKey(key, secondaryChars[index])
row.addView(button)
}
}
val row1 = qwertyLayout.findViewById<LinearLayout>(R.id.qwerty_row_1)
_addRow(row1, "QWERTYUIOP".map { it.toString() }, "1234567890".map { it.toString() })
addRow(row1, "QWERTYUIOP".map { it.toString() }, "1234567890".map { it.toString() })
val row2 = qwertyLayout.findViewById<LinearLayout>(R.id.qwerty_row_2)
_addRow(row2, "ASDFGHJKL".map { it.toString() }, "@#£_&-+()".map { it.toString() })
addRow(row2, "ASDFGHJKL".map { it.toString() }, "@#£_&-+()".map { it.toString() })
val row3 = qwertyLayout.findViewById<LinearLayout>(R.id.qwerty_row_3)
_addRow(row3, "ZXCVBNM".map { it.toString() }, "*\"':;!?".map { it.toString() })
addRow(row3, "ZXCVBNM".map { it.toString() }, "*\"':;!?".map { it.toString() })
val row4 = qwertyLayout.findViewById<LinearLayout>(R.id.qwerty_row_4)
val backspace = addKey("", "", ::searchBack, ::searchClear)
backspace.layoutParams.width = qwertyWidth * 2
row3.addView(backspace)
row3.addView(_addKey("", "", ::searchBack, ::searchClear))
val spacebar = _addKey(" ", " ", )
val spacebar = addKey(" ", " ")
spacebar.layoutParams.width = qwertyWidth * 7
row4.addView(spacebar)
// Add the inflated layout to packContent
packContent.removeAllViewsInLayout()
packContent.addView(qwertyLayout)
}
private fun addPackButton(tag: Any): ImageButton {
/**
* Adds a pack button to the packsList/ tab bar.
*
* @param tag The pack name associated with the pack button.
* @return The ImageButton representing the added pack button.
*/
private fun addPackButton(tag: String): ImageButton {
val packCard = layoutInflater.inflate(R.layout.sticker_card, this.packsList, false)
val packButton = packCard.findViewById<ImageButton>(R.id.stickerButton)
packButton.tag = tag
@ -438,8 +448,8 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
} else {
(
baseContext.getSystemService(INPUT_METHOD_SERVICE) as
InputMethodManager
).showInputMethodPicker()
InputMethodManager
).showInputMethodPicker()
}
}
@ -471,8 +481,8 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
this.keyboardHeight +
(
resources.getDimension(R.dimen.pack_dimens) +
resources.getDimension(R.dimen.sticker_padding) * 4
).toInt()
resources.getDimension(R.dimen.sticker_padding) * 4
).toInt()
val fSticker = fullStickerLayout.findViewById<ImageButton>(R.id.stickerButton)
fSticker.layoutParams.height = this.fullIconSize
fSticker.layoutParams.width = this.fullIconSize
@ -550,7 +560,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
* @return String
*/
fun trimString(str: String?): String {
if (str == null){
if (str == null) {
return "null"
}
if (str.length > 32) {

View File

@ -1,9 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="@color/fg"
android:pathData="M48,256c0,114.87 93.13,208 208,208s208,-93.13 208,-208S370.87,48 256,48 48,141.13 48,256zM260.65,164.64a16,16 0,0 1,0.09 22.63L208.42,240L342,240a16,16 0,0 1,0 32L208.42,272l52.32,52.73A16,16 0,1 1,238 347.27l-79.39,-80a16,16 0,0 1,0 -22.54l79.39,-80a16,16 0,0 1,22.65 -0.09z" />
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="200dp" android:viewportHeight="512" android:viewportWidth="512" android:width="200dp">
<path android:fillColor="@color/fg" android:pathData="M48,256c0,114.87 93.13,208 208,208s208,-93.13 208,-208S370.87,48 256,48 48,141.13 48,256zM260.65,164.64a16,16 0,0 1,0.09 22.63L208.42,240L342,240a16,16 0,0 1,0 32L208.42,272l52.32,52.73A16,16 0,1 1,238 347.27l-79.39,-80a16,16 0,0 1,0 -22.54l79.39,-80a16,16 0,0 1,22.65 -0.09z"/>
</vector>

View File

@ -1,12 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="@color/fg"
android:pathData="M256,48C141.31,48 48,141.31 48,256 48,370.69 141.31,464 256,464 370.69,464 464,370.69 464,256 464,141.31 370.69,48 256,48ZM354.92,354.92a17.33,17.33 0,0 1,-24.5 0l-46.41,-46.4a95.42,95.42 0,1 1,24.52 -24.52l46.4,46.41a17.33,17.33 0,0 1,0 24.5z"/>
<path
android:fillColor="@color/fg"
android:pathData="M230,230m-60.67,0a60.67,60.67 0,1 1,121.33 0a60.67,60.67 0,1 1,-121.33 0"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="200dp" android:viewportHeight="512" android:viewportWidth="512" android:width="200dp">
<path android:fillColor="@color/fg" android:pathData="M256,48C141.31,48 48,141.31 48,256 48,370.69 141.31,464 256,464 370.69,464 464,370.69 464,256 464,141.31 370.69,48 256,48ZM354.92,354.92a17.33,17.33 0,0 1,-24.5 0l-46.41,-46.4a95.42,95.42 0,1 1,24.52 -24.52l46.4,46.41a17.33,17.33 0,0 1,0 24.5z"/>
<path android:fillColor="@color/fg" android:pathData="M230,230m-60.67,0a60.67,60.67 0,1 1,121.33 0a60.67,60.67 0,1 1,-121.33 0"/>
</vector>

View File

@ -1,9 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="@color/fg"
android:pathData="M256,48C141.13,48 48,141.13 48,256s93.13,208 208,208 208,-93.13 208,-208S370.87,48 256,48zM352,288h-96a16,16 0,0 1,-16 -16L240,128a16,16 0,0 1,32 0v128h80a16,16 0,0 1,0 32z" />
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="200dp" android:viewportHeight="512" android:viewportWidth="512" android:width="200dp">
<path android:fillColor="@color/fg" android:pathData="M256,48C141.13,48 48,141.13 48,256s93.13,208 208,208 208,-93.13 208,-208S370.87,48 256,48zM352,288h-96a16,16 0,0 1,-16 -16L240,128a16,16 0,0 1,32 0v128h80a16,16 0,0 1,0 32z"/>
</vector>

View File

@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.2.1" apply false
id("com.android.application") version "8.3.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("org.jetbrains.dokka") version "1.8.20"
id("org.jlleitschuh.gradle.ktlint") version "11.6.0"

View File

@ -21,5 +21,4 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false

View File

@ -1,6 +1,6 @@
#Sun Aug 20 19:56:21 BST 2023
#Thu Mar 21 23:12:37 GMT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists