Skip to content

Commit 7da371e

Browse files
Added Common View Utils
1 parent 0af70e4 commit 7da371e

File tree

8 files changed

+164
-65
lines changed

8 files changed

+164
-65
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
.externalNativeBuild
1515
.cxx
1616
local.properties
17+
/.idea/inspectionProfiles/Project_Default.xml
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
<resources>
2-
<string name="app_name">CoreModule</string>
3-
<string name="confirm">Confirm</string>
4-
<string name="dismiss">Dismiss</string>
5-
<string name="are_you_sure_to_delete_all">Are you sure to delete all ?</string>
6-
<string name="delete_all_desc">All the tasks will be deleted once you click confirm. Click Confirm to delete or Dismiss.</string>
2+
73

84
</resources>

coremodule/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
android {
88
namespace = "com.vimalraj.coremodule"
9-
compileSdk = 34
9+
compileSdk = 35
1010

1111
defaultConfig {
1212
minSdk = 26
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.vimalraj.coremodule.common.utils
2+
3+
import androidx.compose.foundation.Image
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.fillMaxSize
7+
import androidx.compose.foundation.layout.height
8+
import androidx.compose.foundation.layout.padding
9+
import androidx.compose.foundation.layout.width
10+
import androidx.compose.material3.AlertDialog
11+
import androidx.compose.material3.CircularProgressIndicator
12+
import androidx.compose.material3.Icon
13+
import androidx.compose.material3.Text
14+
import androidx.compose.material3.TextButton
15+
import androidx.compose.runtime.Composable
16+
import androidx.compose.runtime.getValue
17+
import androidx.compose.runtime.mutableStateOf
18+
import androidx.compose.runtime.remember
19+
import androidx.compose.runtime.setValue
20+
import androidx.compose.ui.Alignment
21+
import androidx.compose.ui.Modifier
22+
import androidx.compose.ui.graphics.Color
23+
import androidx.compose.ui.graphics.vector.ImageVector
24+
import androidx.compose.ui.res.painterResource
25+
import androidx.compose.ui.res.stringResource
26+
import androidx.compose.ui.text.font.FontStyle
27+
import androidx.compose.ui.unit.dp
28+
import androidx.compose.ui.unit.sp
29+
import com.vimalraj.coremodule.R
30+
31+
@Composable
32+
fun CircularLoader(showLoader: Boolean, color: Color, trackColor: Color) {
33+
var loading by remember { mutableStateOf(false) }
34+
35+
loading = showLoader
36+
37+
if (!loading) return
38+
39+
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
40+
CircularProgressIndicator(
41+
modifier = Modifier.width(48.dp),
42+
color = color,
43+
trackColor = trackColor,
44+
)
45+
}
46+
}
47+
48+
@Composable
49+
fun ErrorScreen(showError: Boolean) {
50+
var isError by remember { mutableStateOf(false) }
51+
52+
isError = showError
53+
54+
if (!isError) return
55+
56+
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
57+
Column(
58+
horizontalAlignment = Alignment.CenterHorizontally
59+
) {
60+
Image(
61+
modifier = Modifier
62+
.width(48.dp)
63+
.height(48.dp),
64+
painter = painterResource(R.drawable.ic_error),
65+
contentDescription = "",
66+
)
67+
68+
Text(
69+
stringResource(R.string.something_went_wrong_try_again_later),
70+
modifier = Modifier.padding(vertical = 8.dp)
71+
)
72+
73+
}
74+
}
75+
}
76+
77+
78+
@Composable
79+
fun GenericAlertDialog(
80+
onDismissRequest: () -> Unit,
81+
onConfirmation: () -> Unit,
82+
dialogTitle: String,
83+
dialogText: String,
84+
confirmText: String = "",
85+
dismissText: String = "",
86+
icon: ImageVector?,
87+
iconColor: Color
88+
) {
89+
AlertDialog(
90+
icon = {
91+
if (icon != null) {
92+
Icon(icon, contentDescription = null, tint = iconColor)
93+
}
94+
},
95+
title = {
96+
Text(text = dialogTitle, fontSize = 22.sp, fontStyle = FontStyle.Normal)
97+
},
98+
text = {
99+
Text(text = dialogText)
100+
},
101+
onDismissRequest = {
102+
onDismissRequest()
103+
},
104+
confirmButton = {
105+
TextButton(
106+
onClick = {
107+
onConfirmation()
108+
}
109+
) {
110+
Text(confirmText)
111+
}
112+
},
113+
dismissButton = {
114+
TextButton(
115+
onClick = {
116+
onDismissRequest()
117+
}
118+
) {
119+
Text(dismissText)
120+
}
121+
}
122+
)
123+
}

coremodule/src/main/java/com/vimalraj/coremodule/views/GenericAlertDialog.kt

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:width="24dp"
5+
android:height="24dp"
6+
android:tint="#991308"
7+
android:viewportWidth="24"
8+
android:viewportHeight="24">
9+
10+
<path
11+
android:fillColor="@android:color/white"
12+
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z" />
13+
14+
</vector>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="purple_200">#FFBB86FC</color>
4+
<color name="purple_500">#FF6200EE</color>
5+
<color name="purple_700">#FF3700B3</color>
6+
<color name="teal_200">#FF03DAC5</color>
7+
<color name="teal_700">#FF018786</color>
8+
<color name="black">#FF000000</color>
9+
<color name="white">#FFFFFFFF</color>
10+
<color name="red40">#FFE86262</color>
11+
<color name="yellow40">#FFFFD976</color>
12+
<color name="blue40">#FF72BEF3</color>
13+
<color name="green">#4CAF50</color>
14+
15+
<color name="red30">#F43F3F</color>
16+
</resources>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
<string name="app_name">CoreModule</string>
3+
<string name="confirm">Confirm</string>
4+
<string name="dismiss">Dismiss</string>
5+
<string name="are_you_sure_to_delete_all">Are you sure to delete all ?</string>
6+
<string name="delete_all_desc">All the tasks will be deleted once you click confirm. Click Confirm to delete or Dismiss.</string>
7+
<string name="something_went_wrong_try_again_later">Something went wrong. Try again later.</string>
8+
</resources>

0 commit comments

Comments
 (0)