This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// Similar to https://lsreg.ru/realizaciya-algoritma-poiska-a-na-c/ | |
/* | |
List<Vector2Int> path = AStar.FindPath( | |
current, target, 200, cell => { return isCleanToMovement(cell); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// Similar to https://lsreg.ru/realizaciya-algoritma-poiska-a-na-c/ | |
public class AStar | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
viewModel.someValue.observe(viewLifecycleOwner) { | |
binding.someView.text = it | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T : Any> Observable<T>.observeWhenStarted( | |
lifecycleOwner: LifecycleOwner, | |
onNext: (T) -> Unit, | |
) { | |
lifecycleOwner.lifecycle.addObserver(object : LifecycleObserver { | |
private var disposable: Disposable? = null | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) | |
fun onStart() { | |
disposable = subscribe { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Like [runCatching] but doesn't change the coroutines cancellation mechanism that relies on [CancellationException]. | |
* | |
* See: [Documentation](https://kotlinlang.org/docs/exception-handling.html) | |
*/ | |
inline fun <R> runCoroutinesCatching(block: () -> R): Result<R> { | |
return try { | |
Result.success(block()) | |
} catch (e: Throwable) { | |
if (e is CancellationException) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> Flow<T>.observeWhenStarted(activity: FragmentActivity, action: (T) -> Unit) { | |
activity.lifecycleScope.launch { | |
activity.repeatOnLifecycle(Lifecycle.State.STARTED) { | |
[email protected] { | |
action(it) | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.Paint | |
import android.util.TypedValue | |
import android.widget.TextView | |
/** | |
* Use it for [android.widget.EditText], because on it autoSize doesn't work | |
*/ | |
class TextMeasure( | |
private val textView: TextView, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun ATest() { | |
val frequentlyChangedState = remember { mutableStateOf(0) } | |
LaunchedEffect(Unit) { | |
launch { | |
delay(5000) // delay so you can attach with Layout Inspector if you don't trust logs enough. | |
while (frequentlyChangedState.value < 10) { | |
delay(200) | |
frequentlyChangedState.value++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.reactivex.rxjava3.core.Completable | |
import io.reactivex.rxjava3.core.Observable | |
import io.reactivex.rxjava3.core.Single | |
import timber.log.Timber | |
import java.util.concurrent.TimeUnit | |
fun Completable.networkCommonRetrying() = | |
withRetrying(3, { 4000L * it }, networkRetryCheck) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Suppress("Unused") | |
object DebugAssert { | |
fun ensure(predicate: () -> Boolean) { | |
ensure(predicate, null) | |
} | |
fun ensure(predicate: () -> Boolean, description: String? = null) { | |
if (BuildConfig.DEBUG && !predicate()) { |
OlderNewer