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 MainActivity : ComponentActivity() { | |
@OptIn(ExperimentalFoundationApi::class) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
enableEdgeToEdge() | |
setContent { | |
var currentTextInput by remember { mutableStateOf(TextFieldValue("")) } | |
val notes = remember { mutableStateListOf<String>() } |
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 android.os.Bundle | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.activity.enableEdgeToEdge | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.Row | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.foundation.layout.padding |
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
@Composable | |
fun Modifier.neoClick( | |
buttonColor: Color = Color.Yellow, | |
shadowColor: Color = Color.Black, | |
borderWidth: Dp = 0.dp, | |
borderColor: Color = Color.Black, | |
// Choose between a RoundedRect (with embedded corner) or a Circle. | |
neoShape: NeoButtonShape = NeoButtonShape.RoundedRect(24.dp), | |
// How far to move the button at full press: | |
offsetX: Dp = 15.dp, |
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 MainActivity : AppCompatActivity() { | |
val textview by lazy { findViewById<View>(R.id.textView) as TextView } | |
val progressBar by lazy { findViewById<View>(R.id.progressbar) as ProgressBar } | |
val buttonMusic by lazy { findViewById<View>(R.id.button_music) as Button } | |
var progressPercentage = 0 | |
private var job: Job? = null | |
val scope by lazy { CoroutineScope(Dispatchers.Main) } | |
override fun onCreate(savedInstanceState: Bundle?) { |
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 MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
} | |
override fun onDestroy(){ | |
super.onDestroy() | |
} |
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
lifecycleScope.launch { | |
viewModel.dogImagesFlow.collect { | |
when (it) { | |
is ResultWrapper.NetworkError -> { | |
errorText.append("${it.errorMessage} \n") | |
... | |
} | |
is ResultWrapper.Success<*> -> { | |
... | |
showLoading(false) |
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 dogImagesFlow = getDogImages().flowOn(Dispatchers.IO) | |
.retryWhen { cause, attempt -> | |
if (cause is IOException && attempt < 3) { | |
val delay = 2000 * (attempt + 1) | |
emit( | |
ResultWrapper.NetworkError( | |
"Attempt No ${attempt + 1} Failed.Retrying again in time ${delay / 1000} sec...", | |
delay.toInt() | |
) | |
) |
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
private fun getDogImages(): Flow<ResultWrapper> { | |
return flow { | |
emit(ResultWrapper.Loading(true)) | |
delay(3000) | |
val randomNumber = (0..5).random() | |
emit(ResultWrapper.Loading(false)) | |
if (randomNumber < 3) { | |
throw IOException() | |
} | |
emit(ResultWrapper.Success(getList())) |
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
search.addTextChangedListener { | |
viewModel.setSearchQuery(it.toString()) | |
} | |
lifecycleScope.launch { | |
viewModel.networkOperationResult.collect { value -> | |
textView.append(value) | |
textView.append("\n") | |
} | |
} |
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
private val _searchQuery = MutableStateFlow("") | |
fun setSearchQuery(query: String) { | |
_searchQuery.value = query | |
} | |
val networkOperationResult: Flow<String> = _searchQuery.debounce(1000).mapLatest { | |
if (it.isEmpty()) { | |
return@mapLatest "" | |
} else { |
NewerOlder