./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}]
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")
}
ktlint {
configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version.set("0.50.0")
android.set(true)
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)
InstrumentationRegistry.getInstrumentation().targetContext.resources.updateConfiguration(
config,
null
null,
)
}
@ -94,7 +94,7 @@ class ScreenshotTest {
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
values.put(
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

View File

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

View File

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

View File

@ -79,7 +79,7 @@ class StickerSender(
bitmap.compress(
Bitmap.CompressFormat.PNG,
90,
FileOutputStream(compatSticker)
FileOutputStream(compatSticker),
)
}
.build()
@ -112,7 +112,7 @@ class StickerSender(
val uri = FileProvider.getUriForFile(
context,
"com.fredhappyface.ewesticker.inputcontent",
file
file,
)
val shareIntent = Intent().apply {
@ -150,10 +150,10 @@ class StickerSender(
FileProvider.getUriForFile(
context,
"com.fredhappyface.ewesticker.inputcontent",
file
file,
),
ClipDescription(file.name, arrayOf(mimeType)),
null
null,
)
if (currentInputConnection != null && currentInputEditorInfo != null) {
@ -162,7 +162,7 @@ class StickerSender(
currentInputEditorInfo,
inputContentInfoCompat,
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) {
Toast.makeText(
this.context, string, if (string.length > 60) {
this.context,
string,
if (string.length > 60) {
Toast.LENGTH_LONG
} else {
Toast.LENGTH_SHORT
}
},
)
.show()
}

View File

@ -30,7 +30,7 @@ object Utils {
"video/3gpp",
"video/mp4",
"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:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bg"
tools:context="com.fredhappyface.ewesticker.ImageKeyboard">
<HorizontalScrollView

View File

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

View File

@ -3,22 +3,12 @@ plugins {
id("com.android.application") version "8.1.1" 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 "10.2.1"
id("org.jlleitschuh.gradle.ktlint") version "11.6.0"
}
tasks.register("clean") { delete(layout.buildDirectory) }
ktlint {
configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version.set("0.50.0")
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)
}
}