Curated list of Most commonly used Kotlin Extensions.
This file contains hidden or 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 Fragment.isGranted(permission: AppPermission) = run { | |
| context?.let { | |
| (PermissionChecker.checkSelfPermission(it, permission.permissionName | |
| ) == PermissionChecker.PERMISSION_GRANTED) | |
| } ?: false | |
| } | |
| fun Fragment.shouldShowRationale(permission: AppPermission) = run { | |
| shouldShowRequestPermissionRationale(permission.permissionName) | |
| } |
This file contains hidden or 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
| /** | |
| * Kotlin Extensions for simpler, easier and funw way | |
| * of launching of Activities | |
| */ | |
| inline fun <reified T : Any> Activity.launchActivity ( | |
| requestCode: Int = -1, | |
| options: Bundle? = null, | |
| noinline init: Intent.() -> Unit = {}) | |
| { |
This file contains hidden or 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
| package bmutinda.com.androidutils.libs; | |
| import android.view.MotionEvent; | |
| import android.view.View; | |
| /** | |
| * Created by Mutinda Boniface on 7/5/2015. | |
| */ | |
| public class SwipeEvents implements View.OnTouchListener { | |
| private SwipeCallback swipeCallback; |
This file contains hidden or 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
| class JsoupOgTagParser(var urlToParse: String) : AsyncTask<Void, Void, Void?>() { | |
| private var title: String? = null | |
| private var desc: String? = null | |
| private var image: String? = null | |
| private var url: String? = null | |
| private var listener: Listener? = null | |
| override fun doInBackground(vararg voids: Void): Void? { | |
| val con = Jsoup.connect(urlToParse) |
This file contains hidden or 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
| public interface SharedFlow<out T> : Flow<T> { public val replayCache: List<T> } |
This file contains hidden or 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
| class DownloadingModel { | |
| private val _state = MutableStateFlow<DownloadStatus>(DownloadStatus.NOT_REQUESTED) val state: StateFlow<DownloadStatus> get() = _state | |
| suspend fun download() { | |
| _state.value = DownloadStatus.INITIALIZED initializeConnection() processAvailableContent { | |
| partialData: ByteArray, downloadedBytes: Long, totalBytes: Long -> | |
| storePartialData(partialData) _state.value = DownloadStatus.IN_PROGRESS } _state.value = DownloadStatus.SUCCESS | |
| } } |
This file contains hidden or 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
| public interface StateFlow<out T> : SharedFlow<T> { public val value: T } | |
| public interface MutableStateFlow<out T>: StateFlow<T>, MutableSharedFlow<T> { | |
| public override var value: T public fun compareAndSet(expect: T, update: T): Boolean | |
| } |
This file contains hidden or 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
| val flow: Flow<Int> = flow { delay(100) for(i in 1..10) { emit(i) } }.map { delay(100) it * it } |
This file contains hidden or 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 java.io.UnsupportedEncodingException; | |
| import java.security.InvalidAlgorithmParameterException; | |
| import java.security.InvalidKeyException; | |
| import java.security.NoSuchAlgorithmException; | |
| import javax.crypto.BadPaddingException; | |
| import javax.crypto.Cipher; | |
| import javax.crypto.IllegalBlockSizeException; | |
| import javax.crypto.NoSuchPaddingException; | |
| import javax.crypto.spec.IvParameterSpec; | |
| import javax.crypto.spec.SecretKeySpec; |
NewerOlder