View CoroutineDispatcherHelper.kt
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
class CoroutineDispatcherHelper : IDispatcher { | |
override fun dispatcherIO(): CoroutineDispatcher = Dispatchers.IO | |
override fun dispatcherMain(): CoroutineDispatcher = Dispatchers.Main | |
override fun dispatcherDefault(): CoroutineDispatcher = Dispatchers.Default | |
} |
View FlowThrottleDebounce.kt
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>.throttle(waitMillis: Int) = flow { | |
coroutineScope { | |
val context = coroutineContext | |
var nextMillis = 0L | |
var delayPost: Deferred<Unit>? = null | |
collect { | |
val current = SystemClock.uptimeMillis() | |
if (nextMillis < current) { | |
nextMillis = current + waitMillis |
View EncryptFiles.kt
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
// Although you can define your own key generation parameter specification, it's | |
// recommended that you use the value specified here. | |
val keyGenParameterSpec = MasterKeys.AES256_GCM_SPEC | |
val mainKeyAlias = MasterKeys.getOrCreate(keyGenParameterSpec) | |
val encrypFile = EncryptedFile.Builder( | |
File(directoryPath, "file_name"), | |
context, | |
mainKeyAlias, | |
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB |
View AdvMasterKey.kt
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 generateAdvMasterKey(context: Context): MasterKey { | |
val advSpec = KeyGenParameterSpec.Builder( | |
"key_name", // define your master key name | |
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT | |
).apply { | |
setBlockModes(KeyProperties.BLOCK_MODE_GCM) | |
setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE) | |
setKeySize(256) | |
setUserAuthenticationRequired(true) | |
setUserAuthenticationValidityDurationSeconds(120) |
View MasterKey.kt
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 getMasterKey(context: Context): MasterKey { | |
return | |
MasterKey.Builder(context) | |
.setKeyGenParameterSpec(AES256_GCM_SPEC) | |
.build() | |
} |
View DiffUtilsActivity.kt
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
private lateinit var adapter: GenericListAdapter<ImagesInfo> | |
adapter = GenericListAdapter(R.layout.product_view) { item, position -> | |
viewModel.setSelectedProduct(item) | |
findNavController().navigate(ImageListFragmentDirections.actionImageListFragmentToImageDetailFragment()) | |
} |
View MediaStorageFetchingFromManager.kt
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
/* | |
* Credit to: https://stackoverflow.com/a/60642994/9764941 | |
* */ | |
object ImageMediaStoreFetching { | |
@JvmStatic | |
@SuppressLint("NewApi") | |
fun getPath(uri: Uri): String? { | |
val selection: String? | |
val selectionArgs: Array<String>? |
View Keys.kt
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
package edu.practice.utils.shared | |
object Keys { | |
init { | |
System.loadLibrary("native-lib") | |
} | |
external fun apiKey(): String | |
} |
View lib.cpp
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
#include <jni.h> | |
#include <string> | |
extern "C" | |
JNIEXPORT jstring JNICALL | |
Java_edu_practice_utils_shared_Keys_apiKey(JNIEnv *env, jobject thiz) { | |
std::string api_key = "c527aa8fadcb58f1cccef75e3a64a3ae"; | |
return env->NewStringUTF(api_key.c_str()); | |
} |
NewerOlder