Skip to content

Instantly share code, notes, and snippets.

View kaiyrzhanDE's full-sized avatar
👾
Android developer

veildc kaiyrzhanDE

👾
Android developer
View GitHub Profile
data class WebViewArgs(
val url: String,
val topBarTitle: String,
)
@SuppressLint("SetJavaScriptEnabled")
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
@Composable
fun WebViewScreen(
ExposedDropdownMenuBox(
expanded = isExpanded.value,
onExpandedChange = { isExpanded.value = it },
) {
FilterContainer(
title = R.string.input_customer_name,
) {
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
@kaiyrzhanDE
kaiyrzhanDE / Modifier.thenIf
Created June 14, 2024 10:41
If condition is true, factory is invoked with the current Modifier instance; otherwise, the function returns the current Modifier unchanged. This enables conditional styling and layout adjustments within Jetpack Compose components based on application logic.
@Composable
fun Modifier.thenIf(
condition: Boolean,
factory: @Composable Modifier.() -> Modifier
): Modifier {
return if (condition) factory.invoke(this) else this
}
@kaiyrzhanDE
kaiyrzhanDE / InAppUpdateSample.kt
Created June 12, 2024 11:06
in-app update sample
class MainActivity : ComponentActivity() {
private val appUpdateManager = AppUpdateManagerFactory.create(applicationContext)
private val appUpdateType = AppUpdateType.IMMEDIATE
private val updateLauncher = registerForActivityResult(
ActivityResultContracts.StartIntentSenderForResult()
) { result ->
if (result.resultCode == RESULT_OK) {
appUpdateManager.completeUpdate()
}
@kaiyrzhanDE
kaiyrzhanDE / gitignore.git
Created May 21, 2024 05:18
gitignore template for android project
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Log/OS Files
*.log
@kaiyrzhanDE
kaiyrzhanDE / OpenFile.kt
Last active June 12, 2024 11:08
Extension function for open any files in kotlin
fun File.openFile(context: Context, authority: String) {
val uri = FileProvider.getUriForFile(
context,
authority,
this
)
val intent = Intent(Intent.ACTION_VIEW)
if (this.toString().contains(".doc") || this.toString().contains(".docx")) {
// Word document
@kaiyrzhanDE
kaiyrzhanDE / ComposableLifecycle.kt
Last active June 12, 2024 11:09
Lifecycle In Jetpack Compose
@Composable
fun ComposableLifecycle(
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
onEvent: (LifecycleOwner, Lifecycle.Event) -> Unit
) {
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { source, event ->
onEvent(source, event)
}
@kaiyrzhanDE
kaiyrzhanDE / SingleEventEffect.kt
Last active June 12, 2024 11:10
For single ui event in jetpack compose
import android.util.Log
import android.view.Gravity
import android.widget.Toast
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier