-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from rommansabbir/dev
Version 4.2.0
- Loading branch information
Showing
17 changed files
with
358 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.rommansabbir.networkx"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application> | ||
|
||
</application> | ||
|
||
</manifest> |
This file contains 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
9 changes: 9 additions & 0 deletions
9
NetworkX/src/main/java/com/rommansabbir/networkx/dialog/compose/Button.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.rommansabbir.networkx.dialog.compose | ||
|
||
data class Button( | ||
val title: String, | ||
val onPressed: () -> Unit, | ||
val leftIcon: Int? = null, | ||
val rightIcon: Int? = null, | ||
val buttonStyle: ButtonStyle? = null | ||
) |
9 changes: 9 additions & 0 deletions
9
NetworkX/src/main/java/com/rommansabbir/networkx/dialog/compose/ButtonStyle.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.rommansabbir.networkx.dialog.compose | ||
|
||
import androidx.compose.ui.graphics.Color | ||
|
||
data class ButtonStyle( | ||
val textColor: Color, | ||
val backgroundColor: Color | ||
) | ||
|
123 changes: 123 additions & 0 deletions
123
NetworkX/src/main/java/com/rommansabbir/networkx/dialog/compose/ComposeVersion.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.rommansabbir.networkx.dialog.compose | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.AlertDialog | ||
import androidx.compose.material.Card | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.compose.ui.window.DialogProperties | ||
import com.rommansabbir.networkx.ui.theme.Green | ||
|
||
|
||
@Composable | ||
fun NoInternetDialogCompose( | ||
dialogState: Boolean = false, | ||
ui: NoInternetUI, | ||
onCancelled: () -> Unit = {}, | ||
onButtonPressed: () -> Unit = {}, | ||
) { | ||
val dialogShape = RoundedCornerShape(10.dp) | ||
|
||
// To understand that if the dialog closed manually by client or not | ||
val dialogClosedManually: Boolean by remember { | ||
mutableStateOf(false) | ||
} | ||
|
||
val dialogCloseAction = { | ||
if (!dialogClosedManually) { | ||
onCancelled.invoke() | ||
} else { | ||
onButtonPressed.invoke() | ||
} | ||
} | ||
|
||
if (dialogState) { | ||
AlertDialog( | ||
onDismissRequest = { | ||
dialogCloseAction.invoke() | ||
}, | ||
title = null, | ||
text = null, | ||
buttons = { | ||
Card(modifier = Modifier.fillMaxWidth()) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.background(ui.UIStyle?.dialogBackgroundColor ?: Color.White), | ||
verticalArrangement = Arrangement.SpaceBetween, | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.background(ui.UIStyle?.backgroundColor ?: Green) | ||
.fillMaxWidth(), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Spacer(modifier = Modifier.padding(16.dp)) | ||
Column( | ||
modifier = Modifier.fillMaxWidth(), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Padding(value = 8) | ||
Box( | ||
modifier = Modifier | ||
.size(50.dp) | ||
.width(50.dp) | ||
) { | ||
Image( | ||
painter = painterResource(id = ui.headerLogo), | ||
contentDescription = "" | ||
) | ||
} | ||
Text( | ||
text = ui.headerTitle, | ||
fontWeight = FontWeight.Bold, | ||
color = ui.UIStyle?.titleColor ?: Color.White, | ||
fontSize = 18.sp, | ||
modifier = Modifier.padding(16.dp, 0.dp, 16.dp, 0.dp) | ||
) | ||
Padding(value = 8) | ||
} | ||
Padding(value = 16) | ||
} | ||
Padding(value = 16) | ||
Text( | ||
text = ui.message, | ||
textAlign = TextAlign.Justify, | ||
color = ui.UIStyle?.messageTextColor ?: Color.Black, | ||
modifier = Modifier.padding(16.dp, 0.dp, 16.dp, 0.dp) | ||
) | ||
Padding(value = 8) | ||
SimpleButton( | ||
Button( | ||
title = ui.actionBtnTitle, | ||
onPressed = { dialogCloseAction.invoke() }, | ||
buttonStyle = ui.buttonStyle | ||
) | ||
) | ||
} | ||
} | ||
}, | ||
properties = DialogProperties( | ||
dismissOnBackPress = ui.isCancelable, | ||
dismissOnClickOutside = ui.isCancelable | ||
), | ||
shape = dialogShape | ||
) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
NetworkX/src/main/java/com/rommansabbir/networkx/dialog/compose/NoInternetUI.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.rommansabbir.networkx.dialog.compose | ||
|
||
import androidx.annotation.DrawableRes | ||
|
||
data class NoInternetUI( | ||
val headerTitle: String, | ||
@DrawableRes val headerLogo: Int, | ||
val message: String, | ||
val actionBtnTitle: String, | ||
val isCancelable: Boolean, | ||
val UIStyle: UIStyle? = null, | ||
val buttonStyle: ButtonStyle? = null | ||
) |
70 changes: 70 additions & 0 deletions
70
NetworkX/src/main/java/com/rommansabbir/networkx/dialog/compose/SimpleButton.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.rommansabbir.networkx.dialog.compose | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.ArrowBack | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.SolidColor | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.semantics.Role | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.rommansabbir.networkx.ui.theme.Green | ||
|
||
@Composable | ||
fun SimpleButton(state: Button) { | ||
val modifier = Modifier.size(width = 50.dp, height = 50.dp) | ||
|
||
val rowModifier = Modifier | ||
.fillMaxWidth() | ||
.padding(16.dp) | ||
.clip(shape = RoundedCornerShape(8.dp)) | ||
.background(brush = SolidColor(state.buttonStyle?.backgroundColor ?: Green)) | ||
.clickable(enabled = true, onClick = { | ||
state.onPressed.invoke() | ||
}, role = Role.Button) | ||
|
||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
modifier = rowModifier | ||
) { | ||
Box(modifier = modifier, contentAlignment = Alignment.Center) { | ||
state.leftIcon?.let { | ||
IconButton(onClick = {}) { | ||
Icon(painterResource(id = it), contentDescription = "") | ||
} | ||
} ?: run { EmptySquareButton() } | ||
} | ||
Padding(value = 8) | ||
Text( | ||
text = state.title, | ||
fontSize = 16.sp, | ||
textAlign = TextAlign.Center, | ||
color = state.buttonStyle?.textColor ?: Color.White, | ||
fontWeight = FontWeight.Bold | ||
) | ||
Padding(value = 8) | ||
Box(modifier = modifier, contentAlignment = Alignment.Center) { | ||
state.rightIcon?.let { | ||
IconButton(onClick = {}) { | ||
Icon(Icons.Filled.ArrowBack, contentDescription = "") | ||
} | ||
} ?: run { EmptySquareButton() } | ||
} | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
NetworkX/src/main/java/com/rommansabbir/networkx/dialog/compose/UIStyle.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.rommansabbir.networkx.dialog.compose | ||
|
||
import androidx.compose.ui.graphics.Color | ||
|
||
data class UIStyle( | ||
val titleColor: Color, | ||
val messageTextColor: Color, | ||
val backgroundColor: Color, | ||
val dialogBackgroundColor: Color | ||
) |
50 changes: 50 additions & 0 deletions
50
NetworkX/src/main/java/com/rommansabbir/networkx/dialog/compose/Views.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.rommansabbir.networkx.dialog.compose | ||
|
||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.unit.dp | ||
import com.rommansabbir.networkx.R | ||
import com.rommansabbir.networkx.ui.theme.Green | ||
|
||
|
||
@Composable | ||
fun Padding(value: Int) = Spacer(modifier = Modifier.padding(value.dp)) | ||
|
||
@Composable | ||
fun EmptySquareButton(title: String = "") { | ||
IconButton(onClick = { }) { | ||
Icon( | ||
ImageVector.Builder( | ||
title, | ||
defaultHeight = 0.dp, | ||
defaultWidth = 0.dp, | ||
viewportHeight = 0F, | ||
viewportWidth = 0F | ||
).build(), contentDescription = "" | ||
) | ||
} | ||
} | ||
|
||
fun defaultNoInternetUI() = NoInternetUI( | ||
headerTitle = "No Internet", | ||
headerLogo = R.drawable.ic_baseline_cloud_off_24, | ||
message = "Device is not connected to the internet. Make sure your device is connected to the internet.", | ||
actionBtnTitle = "OK", | ||
true, | ||
UIStyle = UIStyle( | ||
Color.White, | ||
Color.Black, | ||
Green, | ||
Color.White | ||
), | ||
buttonStyle = ButtonStyle( | ||
Color.White, | ||
Green | ||
) | ||
) |
Oops, something went wrong.