Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Oct 30, 2024
1 parent 69c1e3d commit 2699dd6
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 64 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,12 @@ jobs:

# - name: Lint
# run: ./gradlew lint

# - name: Ktlint
# run: ./gradlew ktlintCheck

# - name: Detekt
# run: ./gradlew detekt

# - name: Spotless
# run: ./gradlew spotlessCheck

# - name: Unit Tests
# run: ./gradlew testDebugUnitTest

# - name: Instrimentation Tests
# uses: reactivecircus/android-emulator-runner@v2
# with:
# api-level: 29
# target: default
# arch: x86
# profile: Nexus 6
# script: ./gradlew connectedCheck --stacktrace

- name: Build
run: ./gradlew compileDebugKotlin
4 changes: 2 additions & 2 deletions core/src/main/kotlin/org/michaelbel/core/entity/Either.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("unused")
@file:Suppress("unused", "UnusedReceiverParameter")

package org.michaelbel.core.entity

Expand Down Expand Up @@ -102,7 +102,7 @@ fun <T> Either<T>.takeOrNull(): T? = when (this) {
* Transform the success result by applying a function to it to another Either
* ```kotlin
* useCase.getData()
* .flatMap { Reaction.of { "Flatmapped data" } }
* .flatMap { Reaction.of { "FlatMapped data" } }
* ```
*/
inline fun <T, R> Either<T>.flatMap(f: (T) -> Either<R>) = try {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/org/michaelbel/core/ktx/Bundle.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("unused")
@file:Suppress("unused", "UnusedReceiverParameter")

package org.michaelbel.core.ktx

Expand Down
23 changes: 2 additions & 21 deletions core/src/main/kotlin/org/michaelbel/core/ktx/EditText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,21 @@ package org.michaelbel.core.ktx
import android.text.InputFilter
import android.widget.EditText

private val PHONE_NUMBER_CHARS: CharArray =
charArrayOf('+', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
private val PHONE_NUMBER_CHARS: CharArray = charArrayOf('+', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9')

/**
* Устанавливает курсор в конец EditText
*/
fun EditText.selectionToEnd() {
if (text.isNotEmpty()) {
setSelection(text.length)
}
}

/**
* Установка ограничения на допустимость набора в [EditText] только текста.
*/
fun EditText.allowJustText() {
val notJustText: (Char) -> Boolean = {
!Character.isLetter(it) && !Character.isSpaceChar(it)
}
restrictMatch(notJustText)
}

/**
* Запрет ввода в [EditText] по предикату
*
* @param predicate предикат, ограничивающий возможность ввода текста
*/
private fun EditText.restrictMatch(predicate: (Char) -> Boolean) {
val inputTextFilter = InputFilter { source, start, end, _, _, _ ->
if ((start until end).any { predicate(source[it]) }) {
Expand All @@ -43,19 +31,12 @@ private fun EditText.restrictMatch(predicate: (Char) -> Boolean) {
this.filters = arrayOf(inputTextFilter).plus(filters)
}

/**
* Позволяет вводить только телефонный номер
*/
fun EditText.allowJustPhoneNumber() {
val inputTextFilter = InputFilter { source, _, _, _, _, _ ->
val inputString = source.toString()
val inputStringLength = inputString.length

//удаляем последний введеный символ если он не цифра или второй + в строке
val endWithPlus: Boolean = inputStringLength > 1 && inputString.endsWith("+")
val phoneNumberChars: Boolean = inputStringLength > 0
&& !PHONE_NUMBER_CHARS.contains(inputString[inputStringLength - 1])

val phoneNumberChars: Boolean = inputStringLength > 0 && !PHONE_NUMBER_CHARS.contains(inputString[inputStringLength - 1])
if (endWithPlus || phoneNumberChars) {
source.removeRange(inputStringLength - 1, inputStringLength)
} else {
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/kotlin/org/michaelbel/core/ktx/Flow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
package org.michaelbel.core.ktx

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

inline fun <T> Flow<T>.launchAndCollectIn(
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/kotlin/org/michaelbel/core/ktx/Intent.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("unused")

package org.michaelbel.core.ktx

import android.content.Context
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/kotlin/org/michaelbel/core/ktx/RecyclerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ val RecyclerView.gridLayoutManager: GridLayoutManager
val RecyclerView.staggeredGridLayoutManager: StaggeredGridLayoutManager
get() = layoutManager as StaggeredGridLayoutManager

/**
* Моментальный скролл списка до n-го элемента сверху [RecyclerView],
* а затем плавный скролл до первого.
*/
fun RecyclerView.smartScrollToTop() {
val smoothScrollCount = 10
val scrollLambda = { lastVisiblePosition: Int ->
Expand Down
9 changes: 0 additions & 9 deletions core/src/main/kotlin/org/michaelbel/core/ktx/String.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,12 @@ fun Context.loadProperty(fileName: String, key: String): String? {
}
}

/**
* Валидация текста на наличие только латиницы и кириллицы.
*/
inline val CharSequence.isTextOnly: Boolean
get() = isNotEmpty() && isNotBlank() && matches("[a-zA-Zа-яА-я]+".toRegex())

/**
* Проверка валидность URL.
*/
inline val String.isUrlValid: Boolean
get() = PatternsCompat.WEB_URL.matcher(this).matches()

/**
* Splits by spaces, newlines, and tabs only
*/
val String.camelCased: String
get() {
val split = lowercase().split(' ', '\n', '\t').toMutableList()
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/org/michaelbel/core/ktx/Uri.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("unused")
@file:Suppress("unused", "UnusedReceiverParameter")

package org.michaelbel.core.ktx

Expand Down
8 changes: 0 additions & 8 deletions core/src/main/kotlin/org/michaelbel/core/ktx/View.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ fun View.doOnApplyWindowInsets(block: (View, insets: WindowInsetsCompat) -> Wind
ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets -> block(v, insets) }
}

/**
* Задать действие по событию onGlobalLayout, снимающееся после первого срабатывания
*
* @param onGlobalLayoutAction действие, происходящее при событии onGlobalLayout
*/
fun View.setOnGlobalLayoutListenerSingle(onGlobalLayoutAction: () -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(object: ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
Expand All @@ -71,9 +66,6 @@ fun View.setOnGlobalLayoutListenerSingle(onGlobalLayoutAction: () -> Unit) {
})
}

/**
* Найти дочернее представление по координатам во время нажатия на экран.
*/
fun findViewAtPosition(parent: View, x: Int, y: Int): View? {
if (parent is ViewGroup) {
val viewGroup: ViewGroup = parent
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
:omega

0 comments on commit 2699dd6

Please sign in to comment.