Skip to content

Commit

Permalink
Merge pull request #5 from TalhaFaki/refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tfaki authored Dec 4, 2021
2 parents a310dcb + bb626dc commit 7878463
Showing 1 changed file with 60 additions and 5 deletions.
65 changes: 60 additions & 5 deletions app/src/main/java/com/android/composablesweettoast/MainScreen.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package com.android.composablesweettoast

import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.talhafaki.composablesweettoast.util.SweetToastUtil.SweetError
import com.talhafaki.composablesweettoast.util.SweetToastUtil.SweetInfo
import com.talhafaki.composablesweettoast.util.SweetToastUtil.SweetSuccess
import com.talhafaki.composablesweettoast.util.SweetToastUtil.SweetWarning

/**
* Created by stekinarslan on 02,December,2021
Expand All @@ -12,14 +23,58 @@ import com.talhafaki.composablesweettoast.util.SweetToastUtil.SweetSuccess
@Composable
fun MainScreen() {
var openDialogSuccess by remember { mutableStateOf(false) }
var openDialogError by remember { mutableStateOf(false) }
var openDialogWarning by remember { mutableStateOf(false) }
var openDialogInfo by remember { mutableStateOf(false) }

Button(onClick = {
openDialogSuccess = true
}) {
Text("Sweet Toast Success")
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(modifier = Modifier.padding(12.dp), onClick = {
openDialogSuccess = true
}) {
Text("Sweet Toast Success")
}

Button(modifier = Modifier.padding(12.dp), onClick = {
openDialogError = true
}) {
Text("Sweet Toast Error")
}

Button(modifier = Modifier.padding(12.dp), onClick = {
openDialogWarning = true
}) {
Text("Sweet Toast Warning")
}

Button(modifier = Modifier.padding(12.dp), onClick = {
openDialogInfo = true
}) {
Text("Sweet Toast Info")
}
}

if (openDialogSuccess) {
SweetSuccess(message = "Success Text!")
openDialogSuccess = false
SweetSuccess(message = "Success Text!", duration = Toast.LENGTH_SHORT)
}

if (openDialogError) {
openDialogError = false
SweetError(message = "Error Text!")
}

if (openDialogWarning) {
openDialogWarning = false
SweetWarning(message = "Warning Text!")
}

if (openDialogInfo) {
openDialogInfo = false
SweetInfo(message = "Info Text!")
}

}

0 comments on commit 7878463

Please sign in to comment.