Skip to content

Instantly share code, notes, and snippets.

View hasankucuk's full-sized avatar

Hasan Küçük hasankucuk

View GitHub Profile
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)
}
@hasankucuk
hasankucuk / ActivitiesLaunchingWay.kt
Created September 27, 2021 08:48 — forked from wajahatkarim3/ActivitiesLaunchingWay.kt
Kotlin Extensions for simpler, easier and funw way of launching of Activities
/**
* 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 = {})
{
@hasankucuk
hasankucuk / SwipeEvents.java
Created May 2, 2021 19:23 — forked from bmutinda/SwipeEvents.java
Android swipe events detector
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;
@hasankucuk
hasankucuk / JsoupOgTagParser.kt
Created April 17, 2021 19:19 — forked from anandwana001/JsoupOgTagParser.kt
Android Kotlin - Extract og tags from website using jsoup
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)
public interface SharedFlow<out T> : Flow<T> { public val replayCache: List<T> }
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
} }
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
}
@hasankucuk
hasankucuk / flow1.kt
Created January 21, 2021 09:28
flow api
val flow: Flow<Int> = flow { delay(100) for(i in 1..10) { emit(i) } }.map { delay(100) it * it }
@hasankucuk
hasankucuk / android_aes_encrpytor.java
Created November 26, 2020 12:52 — forked from sdogruyol/android_aes_encrpytor.java
AES Encryption Singleton Class in Android Using CBC / PKCS7Padding
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;