Skip to content

Instantly share code, notes, and snippets.

View mitchtabian's full-sized avatar
🎞️
Building stuff

Mitch Tabian mitchtabian

🎞️
Building stuff
View GitHub Profile

Updates for the Food2ForkCompose app from alpha-11 to beta01.

Versions

  1. kotlin -> 1.4.30
    • Make sure Kotlin is updated to early version
    • Settings > Languages and Frameworks > Kotlin > Early Access Preview 1.4.x
  2. kotlin_compiler_extension -> 1.0.0-beta01
  3. compose -> 1.0.0-beta01 (from alpha11)
  4. navigation-compose -> 1.0.0-alpha08 (from alpha06)
  5. Add const val compose_constraint = "1.0.0-alpha03"
val isShowing = remember{ mutableStateOf(true) }
if(isShowing.value){
AlertDialog(
onDismissRequest = {isShowing.value = false},
title = { Text("Dialog Title") },
text = { Text("Here is the description text for a dialog.") },
buttons = {
Row(
modifier = Modifier
.fillMaxWidth()
data class Recipe (
val id: Int? = null,
val title: String? = null,
val publisher: String? = null,
val featuredImage: String? = null,
val rating: Int? = 0,
val sourceUrl: String? = null,
val description: String? = null,
val cookingInstructions: String? = null,
val ingredients: List<String> = listOf(),

Features:

  1. Kotlin
  2. MVVM
  3. Compose navigation (one activity, zero fragments)
  4. Retrieve Network Data from API (REST API)
  5. Database caching
  6. Monitoring Network Connectivity
  7. Use cases
  8. Datastore (New Shared Preferences)
  9. Unit Tests
fun <VM : ViewModel> createViewModel(
viewModelClass: KClass<VM>,
storeProducer: ViewModelStore,
factory: ViewModelProvider.Factory,
): VM {
return ViewModelProvider(storeProducer, factory).get(viewModelClass.java)
}
override fun mapFromEntity(entity: OrganisationCacheEntity): OrganisationModel {
return OrganisationModel(
children = entity.children,
// organisation = entity.organisation,
organisation = Organisation(
_attachments = entity.organisation._attachments,
_etag = entity.organisation._etag,
_rid = entity.organisation._rid,
_self = entity.organisation._self,
_ts = entity.organisation._ts,
setContent{
val snackbarHostState = remember{SnackbarHostState()}
Column {
Button(
onClick = {
lifecycleScope.launch {
val time = System.currentTimeMillis()
Log.d(TAG, "showing snackbar")
snackbarHostState.showSnackbar(
setContent{
val showSnackbar = remember{ mutableStateOf(false)}
Column{
Button(
onClick = {
showSnackbar.value = true
}
) {
Text("Show snackbar")
// Align composables with respect to one another
@Composable
fun CircularIndeterminateProgressBar(isDisplayed: Boolean) {
if (isDisplayed) {
ConstraintLayout(
modifier = Modifier.fillMaxSize()
) {
val (progress, text) = createRefs()
CircularProgressIndicator(
modifier = Modifier.constrainAs(progress) {
fun isConnectedToTheInternet(): Boolean{
val cm = application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
try{
return cm.activeNetworkInfo.isConnected
}catch (e: Exception){
Log.e(TAG, "isConnectedToTheInternet: ${e.message}")
}
return false
}