Skip to content

Commit

Permalink
./gradlew ktlintFormat and fix #67
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHappyface committed Oct 8, 2023
1 parent 89e1f97 commit 8eb1344
Show file tree
Hide file tree
Showing 29 changed files with 768 additions and 782 deletions.
6 changes: 2 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 2 additions & 12 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ScreenshotTest {
config.setLocale(locale)
InstrumentationRegistry.getInstrumentation().targetContext.resources.updateConfiguration(
config,
null
null,
)
}

Expand All @@ -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

Expand Down
39 changes: 21 additions & 18 deletions app/src/main/java/com/fredhappyface/ewesticker/ImageKeyboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -196,7 +199,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
this.currentInputConnection,
this.currentInputEditorInfo,
this.compatCache,
this.imageLoader
this.imageLoader,
)
}

Expand All @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
}
}

Expand All @@ -324,13 +326,14 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
override fun onStickerLongClicked(sticker: File) {
val fullStickerLayout =
layoutInflater.inflate(R.layout.sticker_preview, this.keyboardRoot, false) as
RelativeLayout
RelativeLayout
// 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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/java/com/fredhappyface/ewesticker/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MainActivity : AppCompatActivity() {
val contentResolver = applicationContext.contentResolver

val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
if (uri != null) {
contentResolver.takePersistableUriPermission(uri, takeFlags)
}
Expand Down Expand Up @@ -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),
)
}
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.io.IOException

private const val MAX_FILES = 4096
private const val MAX_PACK_SIZE = 128
private const val BUFFER_SIZE = 64 * 1024 // 64 KB
private const val BUFFER_SIZE = 64 * 1024 // 64 KB

/**
* The StickerImporter class includes a helper function to import stickers from a user-selected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import java.io.File
interface StickerClickListener {
fun onStickerClicked(sticker: File)
fun onStickerLongClicked(sticker: File)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class StickerSender(
bitmap.compress(
Bitmap.CompressFormat.PNG,
90,
FileOutputStream(compatSticker)
FileOutputStream(compatSticker),
)
}
.build()
Expand Down Expand Up @@ -112,7 +112,7 @@ class StickerSender(
val uri = FileProvider.getUriForFile(
context,
"com.fredhappyface.ewesticker.inputcontent",
file
file,
)

val shareIntent = Intent().apply {
Expand Down Expand Up @@ -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) {
Expand All @@ -162,7 +162,7 @@ class StickerSender(
currentInputEditorInfo,
inputContentInfoCompat,
InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION,
null
null,
)
}
}
Expand All @@ -176,7 +176,7 @@ class StickerSender(
*/
private fun isCommitContentSupported(editorInfo: EditorInfo?, mimeType: String?): Boolean {
return editorInfo?.packageName != null && mimeType != null && currentInputConnection != null &&
EditorInfoCompat.getContentMimeTypes(editorInfo)
.any { ClipDescription.compareMimeTypes(mimeType, it) }
EditorInfoCompat.getContentMimeTypes(editorInfo)
.any { ClipDescription.compareMimeTypes(mimeType, it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object Utils {
"video/3gpp",
"video/mp4",
"video/x-matroska",
"video/webm"
"video/webm",
)
}
}
Loading

0 comments on commit 8eb1344

Please sign in to comment.