./gradlew ktlintFormat and fix #67

This commit is contained in:
Kieran W 2023-10-08 13:12:10 +01:00
parent 6b41417d16
commit cd776a522c
29 changed files with 768 additions and 782 deletions

View File

@ -6,8 +6,6 @@ indent_size = 4
[*.{kt,kts}] [*.{kt,kts}]
max_line_length = 100 max_line_length = 100
ktlint_standard_indent = disabled
ktlint_wrapping = disabled
[kotlin]
kotlin_comments.indent_size = tab
kotlin_comments.wrap_text = true

View File

@ -86,18 +86,8 @@ dependencies {
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
} }
ktlint { configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version.set("0.50.0")
android.set(true) android.set(true)
coloredOutput.set(false) coloredOutput.set(false)
enableExperimentalRules.set(true)
disabledRules.set(
setOf(
"indent",
"parameter-list-wrapping",
"experimental:argument-list-wrapping"
)
)
reporters {
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.PLAIN)
}
} }

View File

@ -80,7 +80,7 @@ class ScreenshotTest {
config.setLocale(locale) config.setLocale(locale)
InstrumentationRegistry.getInstrumentation().targetContext.resources.updateConfiguration( InstrumentationRegistry.getInstrumentation().targetContext.resources.updateConfiguration(
config, config,
null null,
) )
} }
@ -94,7 +94,7 @@ class ScreenshotTest {
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg") values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
values.put( values.put(
MediaStore.MediaColumns.RELATIVE_PATH, MediaStore.MediaColumns.RELATIVE_PATH,
"${Environment.DIRECTORY_DCIM}/$subdirectory" "${Environment.DIRECTORY_DCIM}/$subdirectory",
) )
values.put(MediaStore.Images.Media.IS_PENDING, 1) // Mark the image as pending values.put(MediaStore.Images.Media.IS_PENDING, 1) // Mark the image as pending

View File

@ -109,12 +109,13 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
// Constants // Constants
this.internalDir = File(filesDir, "stickers") this.internalDir = File(filesDir, "stickers")
this.iconSize = this.iconSize =
(if (this.vertical) { (
if (this.vertical) {
(resources.displayMetrics.widthPixels - this.totalIconPadding) / this.iconsPerX.toFloat() (resources.displayMetrics.widthPixels - this.totalIconPadding) / this.iconsPerX.toFloat()
} else { } else {
(this.sharedPreferences.getInt("iconSize", 80) * scale) (this.sharedPreferences.getInt("iconSize", 80) * scale)
}) }
.toInt() ).toInt()
this.toaster = Toaster(baseContext) this.toaster = Toaster(baseContext)
// Load Packs // Load Packs
this.loadedPacks = HashMap() this.loadedPacks = HashMap()
@ -163,11 +164,13 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
} }
this.packContent.layoutParams?.height = this.keyboardHeight this.packContent.layoutParams?.height = this.keyboardHeight
this.fullIconSize = this.fullIconSize =
(min( (
min(
resources.displayMetrics.widthPixels, resources.displayMetrics.widthPixels,
this.keyboardHeight - this.keyboardHeight -
resources.getDimensionPixelOffset(R.dimen.text_size_body) * 2 resources.getDimensionPixelOffset(R.dimen.text_size_body) * 2,
) * 0.95) ) * 0.95
)
.toInt() .toInt()
createPackIcons() createPackIcons()
return keyboardLayout return keyboardLayout
@ -196,7 +199,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
this.currentInputConnection, this.currentInputConnection,
this.currentInputEditorInfo, this.currentInputEditorInfo,
this.compatCache, this.compatCache,
this.imageLoader this.imageLoader,
) )
} }
@ -220,7 +223,6 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
* @param packName String * @param packName String
*/ */
private fun switchPackLayout(packName: String) { private fun switchPackLayout(packName: String) {
this.activePack = packName this.activePack = packName
for (packCard in this.packsList) { for (packCard in this.packsList) {
val packButton = packCard.findViewById<ImageButton>(R.id.stickerButton) val packButton = packCard.findViewById<ImageButton>(R.id.stickerButton)
@ -243,13 +245,12 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
this, this,
iconsPerX, iconsPerX,
if (vertical) RecyclerView.VERTICAL else RecyclerView.HORIZONTAL, if (vertical) RecyclerView.VERTICAL else RecyclerView.HORIZONTAL,
false false,
) )
recyclerView.layoutManager = layoutManager recyclerView.layoutManager = layoutManager
recyclerView.adapter = adapter recyclerView.adapter = adapter
packContent.removeAllViewsInLayout() packContent.removeAllViewsInLayout()
packContent.addView(recyclerView) packContent.addView(recyclerView)
} }
private fun addPackButton(tag: Any): ImageButton { private fun addPackButton(tag: Any): ImageButton {
@ -296,9 +297,10 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
if (SDK_INT >= 28) { if (SDK_INT >= 28) {
this.switchToPreviousInputMethod() this.switchToPreviousInputMethod()
} else { } else {
(baseContext.getSystemService(INPUT_METHOD_SERVICE) as (
InputMethodManager) baseContext.getSystemService(INPUT_METHOD_SERVICE) as
.showInputMethodPicker() InputMethodManager
).showInputMethodPicker()
} }
} }
@ -328,9 +330,10 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
// Set dimens + load image // Set dimens + load image
fullStickerLayout.layoutParams.height = fullStickerLayout.layoutParams.height =
this.keyboardHeight + this.keyboardHeight +
(resources.getDimension(R.dimen.pack_dimens) + (
resources.getDimension(R.dimen.sticker_padding) * 4) resources.getDimension(R.dimen.pack_dimens) +
.toInt() resources.getDimension(R.dimen.sticker_padding) * 4
).toInt()
val fSticker = fullStickerLayout.findViewById<ImageButton>(R.id.stickerButton) val fSticker = fullStickerLayout.findViewById<ImageButton>(R.id.stickerButton)
fSticker.layoutParams.height = this.fullIconSize fSticker.layoutParams.height = this.fullIconSize
fSticker.layoutParams.width = this.fullIconSize fSticker.layoutParams.width = this.fullIconSize
@ -389,7 +392,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
e1: MotionEvent, e1: MotionEvent,
e2: MotionEvent, e2: MotionEvent,
velocityX: Float, velocityX: Float,
velocityY: Float velocityY: Float,
): Boolean { ): Boolean {
val diffX = e2.x - e1.x val diffX = e2.x - e1.x
val diffY = e2.y - e1.y val diffY = e2.y - e1.y

View File

@ -122,13 +122,14 @@ class MainActivity : AppCompatActivity() {
*/ */
fun reloadStickers(ignoredView: View) { fun reloadStickers(ignoredView: View) {
val stickerDirPath = this.sharedPreferences.getString( val stickerDirPath = this.sharedPreferences.getString(
"stickerDirPath", null "stickerDirPath",
null,
) )
if (stickerDirPath != null) { if (stickerDirPath != null) {
importStickers(stickerDirPath) importStickers(stickerDirPath)
} else { } else {
this.toaster.toast( this.toaster.toast(
getString(R.string.imported_034) getString(R.string.imported_034),
) )
} }
} }
@ -153,7 +154,7 @@ class MainActivity : AppCompatActivity() {
getString(R.string.imported_031, totalStickers), getString(R.string.imported_031, totalStickers),
getString(R.string.imported_032, totalStickers), getString(R.string.imported_032, totalStickers),
getString(R.string.imported_033, totalStickers), getString(R.string.imported_033, totalStickers),
) ),
) )
val editor = sharedPreferences.edit() val editor = sharedPreferences.edit()
editor.putInt("numStickersImported", totalStickers) editor.putInt("numStickersImported", totalStickers)
@ -178,7 +179,7 @@ class MainActivity : AppCompatActivity() {
compoundButton: CompoundButton, compoundButton: CompoundButton,
sharedPrefKey: String, sharedPrefKey: String,
sharedPrefDefault: Boolean = false, sharedPrefDefault: Boolean = false,
callback: (Boolean) -> Unit callback: (Boolean) -> Unit,
) { ) {
compoundButton.isChecked = compoundButton.isChecked =
this.sharedPreferences.getBoolean(sharedPrefKey, sharedPrefDefault) this.sharedPreferences.getBoolean(sharedPrefKey, sharedPrefDefault)
@ -207,7 +208,7 @@ class MainActivity : AppCompatActivity() {
seekBarLabel: TextView, seekBarLabel: TextView,
sharedPrefKey: String, sharedPrefKey: String,
sharedPrefDefault: Int, sharedPrefDefault: Int,
multiplier: Int = 1 multiplier: Int = 1,
) { ) {
seekBarLabel.text = seekBarLabel.text =
this.sharedPreferences.getInt(sharedPrefKey, sharedPrefDefault).toString() this.sharedPreferences.getInt(sharedPrefKey, sharedPrefDefault).toString()
@ -228,18 +229,19 @@ class MainActivity : AppCompatActivity() {
editor.apply() editor.apply()
showChangedPrefText() showChangedPrefText()
} }
}) },
)
} }
/** Reads saved sticker dir path from preferences */ /** Reads saved sticker dir path from preferences */
private fun refreshStickerDirPath() { private fun refreshStickerDirPath() {
findViewById<TextView>(R.id.stickerPackInfoPath).text = findViewById<TextView>(R.id.stickerPackInfoPath).text =
this.sharedPreferences.getString( this.sharedPreferences.getString(
"stickerDirPath", resources.getString(R.string.update_sticker_pack_info_path) "stickerDirPath", resources.getString(R.string.update_sticker_pack_info_path),
) )
findViewById<TextView>(R.id.stickerPackInfoDate).text = findViewById<TextView>(R.id.stickerPackInfoDate).text =
this.sharedPreferences.getString( this.sharedPreferences.getString(
"lastUpdateDate", resources.getString(R.string.update_sticker_pack_info_date) "lastUpdateDate", resources.getString(R.string.update_sticker_pack_info_date),
) )
findViewById<TextView>(R.id.stickerPackInfoTotal).text = findViewById<TextView>(R.id.stickerPackInfoTotal).text =
this.sharedPreferences.getInt("numStickersImported", 0).toString() this.sharedPreferences.getInt("numStickersImported", 0).toString()
@ -248,7 +250,7 @@ class MainActivity : AppCompatActivity() {
/** Reusable function to warn about changing preferences */ /** Reusable function to warn about changing preferences */
private fun showChangedPrefText() { private fun showChangedPrefText() {
this.toaster.toast( this.toaster.toast(
getString(R.string.pref_000) getString(R.string.pref_000),
) )
} }
} }

View File

@ -79,7 +79,7 @@ class StickerSender(
bitmap.compress( bitmap.compress(
Bitmap.CompressFormat.PNG, Bitmap.CompressFormat.PNG,
90, 90,
FileOutputStream(compatSticker) FileOutputStream(compatSticker),
) )
} }
.build() .build()
@ -112,7 +112,7 @@ class StickerSender(
val uri = FileProvider.getUriForFile( val uri = FileProvider.getUriForFile(
context, context,
"com.fredhappyface.ewesticker.inputcontent", "com.fredhappyface.ewesticker.inputcontent",
file file,
) )
val shareIntent = Intent().apply { val shareIntent = Intent().apply {
@ -150,10 +150,10 @@ class StickerSender(
FileProvider.getUriForFile( FileProvider.getUriForFile(
context, context,
"com.fredhappyface.ewesticker.inputcontent", "com.fredhappyface.ewesticker.inputcontent",
file file,
), ),
ClipDescription(file.name, arrayOf(mimeType)), ClipDescription(file.name, arrayOf(mimeType)),
null null,
) )
if (currentInputConnection != null && currentInputEditorInfo != null) { if (currentInputConnection != null && currentInputEditorInfo != null) {
@ -162,7 +162,7 @@ class StickerSender(
currentInputEditorInfo, currentInputEditorInfo,
inputContentInfoCompat, inputContentInfoCompat,
InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION, InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION,
null null,
) )
} }
} }

View File

@ -21,11 +21,13 @@ class Toaster(private val context: Context) {
*/ */
fun toast(string: String) { fun toast(string: String) {
Toast.makeText( Toast.makeText(
this.context, string, if (string.length > 60) { this.context,
string,
if (string.length > 60) {
Toast.LENGTH_LONG Toast.LENGTH_LONG
} else { } else {
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
} },
) )
.show() .show()
} }

View File

@ -30,7 +30,7 @@ object Utils {
"video/3gpp", "video/3gpp",
"video/mp4", "video/mp4",
"video/x-matroska", "video/x-matroska",
"video/webm" "video/webm",
) )
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,7 @@
android:id="@+id/keyboardRoot" android:id="@+id/keyboardRoot"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/bg"
tools:context="com.fredhappyface.ewesticker.ImageKeyboard"> tools:context="com.fredhappyface.ewesticker.ImageKeyboard">
<HorizontalScrollView <HorizontalScrollView

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/> <background android:drawable="@color/ic_launcher_background" />
<foreground android:drawable="@mipmap/ic_launcher_foreground"/> <foreground android:drawable="@mipmap/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_mono"/> <monochrome android:drawable="@drawable/ic_launcher_mono" />
</adaptive-icon> </adaptive-icon>

View File

@ -3,22 +3,12 @@ plugins {
id("com.android.application") version "8.1.1" apply false id("com.android.application") version "8.1.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("org.jetbrains.dokka") version "1.8.20" id("org.jetbrains.dokka") version "1.8.20"
id("org.jlleitschuh.gradle.ktlint") version "10.2.1" id("org.jlleitschuh.gradle.ktlint") version "11.6.0"
} }
tasks.register("clean") { delete(layout.buildDirectory) } tasks.register("clean") { delete(layout.buildDirectory) }
ktlint { configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version.set("0.50.0")
coloredOutput.set(false) coloredOutput.set(false)
enableExperimentalRules.set(true)
disabledRules.set(
setOf(
"indent",
"parameter-list-wrapping",
"experimental:argument-list-wrapping"
)
)
reporters {
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.PLAIN)
}
} }