Skip to content

Commit

Permalink
Merge pull request #19 from rommansabbir/dev
Browse files Browse the repository at this point in the history
Version 4.2.0
  • Loading branch information
rommansabbir authored Nov 25, 2022
2 parents 1055811 + 1a7f6d8 commit bba27c6
Show file tree
Hide file tree
Showing 17 changed files with 358 additions and 35 deletions.
28 changes: 25 additions & 3 deletions NetworkX/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
group = 'rommansabbir'
version '3.4.1'
version '4.2.0'

android {
compileSdkVersion 31
Expand All @@ -18,6 +18,9 @@ android {
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
vectorDrawables {
useSupportLibrary true
}
}
dataBinding {
enabled = true
Expand All @@ -35,7 +38,18 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.1.1'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}

Expand All @@ -45,9 +59,17 @@ dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.1.1'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
def lifecycle_version = "2.3.1"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
Expand All @@ -62,7 +84,7 @@ afterEvaluate {
from components.release
groupId = 'com.github.rommansabbir'
artifactId = 'NetworkX'
version = '3.4.1'
version = '4.2.0'
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions NetworkX/src/main/AndroidManifest.xml
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>
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,12 @@ internal class NetworkXManager constructor(
private val getNetworkCallBack = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
super.onAvailable(network)
/*NetworkXProvider.setConnection(true)*/
updateInternetConnectionStatus()
}

override fun onLost(network: Network) {
super.onLost(network)
NetworkXProvider.setConnection(false)
updateInternetConnectionStatus()
}
}

Expand Down
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
)
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
)

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
)
}
}
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
)
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() }
}
}
}

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
)
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
)
)
Loading

0 comments on commit bba27c6

Please sign in to comment.