Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1507: fix settings visibility & migrated to compose #1508

Merged
merged 3 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.res.stringResource

/**
* @author pratyush
* @since 12/02/2024
*/

@Composable
fun MifosDialogBox(
showDialogState: MutableState<Boolean>,
onDismiss: () -> Unit,
title: Int,
message: Int? = null,
confirmButtonText: Int,
onConfirm: () -> Unit,
dismissButtonText: Int
) {
if (showDialogState.value) {
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(text = stringResource(id = title)) },
text = {
if (message != null) {
Text(text = stringResource(id = message))
}
},
confirmButton = {
TextButton(
onClick = {
onConfirm()
}
) {
Text(stringResource(id = confirmButtonText))
}
},
dismissButton = {
TextButton(onClick = onDismiss) {
Text(stringResource(id = dismissButtonText))
}
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.mifos.mobilewallet.mifospay.designsystem.component

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardColors
import androidx.compose.material3.CardDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

@Composable
fun MifosItemCard(
modifier: Modifier = Modifier,
shape: Shape = RoundedCornerShape(8.dp),
elevation: Dp = 1.dp,
onClick: (() -> Unit)? = null,
colors: CardColors = CardDefaults.cardColors(),
content: @Composable ColumnScope.() -> Unit
) {
Card(
shape = shape,
modifier = modifier
.fillMaxWidth()
.then(if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier),
elevation = CardDefaults.cardElevation(
defaultElevation = elevation
),
colors = colors,
content = content
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.mifos.mobilewallet.mifospay.designsystem.component

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import org.mifos.mobilewallet.mifospay.designsystem.theme.mifosText
import org.mifos.mobilewallet.mifospay.designsystem.theme.styleMifosTopBar

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MifosTopBar(
topBarTitle: Int,
backPress: () -> Unit
) {
TopAppBar(
title = {
Text(
text = stringResource(id = topBarTitle),
style = styleMifosTopBar
)
},
navigationIcon = {
IconButton(onClick = { backPress.invoke() }) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = "Back",
tint = mifosText
)
}
},
colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = Color.White)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ val grey = Color(0xFF757074)
val lightGrey = Color(0xFFD9D9D9)
val border = Color(0x66000000)
val green = Color(0xFF008135)
val red = Color(0xFFCD0000)
val red = Color(0xFFCD0000)
val mifosText = Color(0xFF212121)
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.mifos.mobilewallet.mifospay.designsystem.theme

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp

val styleMedium16sp = TextStyle(
Expand All @@ -25,3 +27,11 @@ val styleMedium30sp = TextStyle(
fontWeight = FontWeight.Medium,
color = black,
)

val styleMifosTopBar = TextStyle(
color = Color(0xFF212121),
fontWeight = FontWeight.SemiBold,
fontSize = 20.sp
)

val styleSettingsButton = TextStyle(color = Color.White, textAlign = TextAlign.Center)
2 changes: 1 addition & 1 deletion core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.mifos.mobilewallet.mifospay.ui.utility

data class DialogState(
val type: DialogType = DialogType.NONE,
val onConfirm: () -> Unit = {}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.mifos.mobilewallet.mifospay.ui.utility

enum class DialogType {
NONE,
DISABLE_ACCOUNT,
LOGOUT
}
2 changes: 2 additions & 0 deletions mifospay/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ dependencies {
implementation(projects.core.data)
implementation(libs.androidx.constraintlayout)

implementation(projects.core.ui)
implementation(projects.core.designsystem)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.activity.ktx)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.mifos.mobilewallet.mifospay.settings.ui

import MifosDialogBox
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.ui.utility.DialogState
import org.mifos.mobilewallet.mifospay.ui.utility.DialogType

@Composable
fun DialogManager(dialogState: DialogState, onDismiss: () -> Unit) {
when (dialogState.type) {
DialogType.DISABLE_ACCOUNT -> MifosDialogBox(
showDialogState = remember { mutableStateOf(true) },
title = R.string.alert_disable_account,
message = R.string.alert_disable_account_desc,
confirmButtonText = R.string.ok,
dismissButtonText = R.string.cancel,
onConfirm = dialogState.onConfirm,
onDismiss = onDismiss
)

DialogType.LOGOUT -> MifosDialogBox(
showDialogState = remember { mutableStateOf(true) },
title = R.string.log_out_title,
message = R.string.empty,
confirmButtonText = R.string.yes,
dismissButtonText = R.string.no,
onConfirm = dialogState.onConfirm,
onDismiss = onDismiss
)

DialogType.NONE -> {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,50 @@ package org.mifos.mobilewallet.mifospay.settings.ui

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import butterknife.ButterKnife
import butterknife.OnClick
import androidx.activity.compose.setContent
import dagger.hilt.android.AndroidEntryPoint
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.auth.ui.LoginActivity
import org.mifos.mobilewallet.mifospay.base.BaseActivity
import org.mifos.mobilewallet.mifospay.settings.SettingsContract
import org.mifos.mobilewallet.mifospay.settings.SettingsContract.SettingsView
import org.mifos.mobilewallet.mifospay.settings.presenter.SettingsPresenter
import org.mifos.mobilewallet.mifospay.theme.MifosTheme
import org.mifos.mobilewallet.mifospay.utils.Constants
import org.mifos.mobilewallet.mifospay.utils.DialogBox
import javax.inject.Inject

@AndroidEntryPoint
class SettingsActivity : BaseActivity(), SettingsView {
var dialogBox = DialogBox()

@JvmField
@Inject
var mPresenter: SettingsPresenter? = null
var mSettingsPresenter: SettingsContract.SettingsPresenter? = null
lateinit var mPresenter: SettingsPresenter

private var mSettingsPresenter: SettingsContract.SettingsPresenter? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
ButterKnife.bind(this)
showColoredBackButton(Constants.BLACK_BACK_BUTTON)
setToolbarTitle(Constants.SETTINGS)
mPresenter!!.attachView(this)
mPresenter.attachView(this)
setContent {
MifosTheme {
SettingsScreen(
backPress = { backToHome() },
disable = { onDisableAccountClicked() },
logout = { onLogoutClicked() }
)
}
}
}

@OnClick(R.id.btn_logout)
fun onLogoutClicked() {
val builder = AlertDialog.Builder(this, R.style.AppTheme_Dialog)
builder.setTitle(R.string.log_out_title)
builder.setCancelable(false)
.setPositiveButton(R.string.yes) { dialog, id ->
showProgressDialog(Constants.LOGGING_OUT)
mPresenter!!.logout()
}
.setNegativeButton(R.string.no, null)
val alert = builder.create()
alert.show()
private fun onLogoutClicked() {
showProgressDialog(Constants.LOGGING_OUT)
mPresenter.logout()
}

@OnClick(R.id.btn_disable_account)
fun onDisableAccountClicked() {
dialogBox.setPositiveListener() { dialog, which -> mSettingsPresenter!!.disableAccount() }
dialogBox.setNegativeListener() { dialog, which -> dialog.dismiss() }
dialogBox.show(
this, R.string.alert_disable_account,
R.string.alert_disable_account_desc, R.string.ok, R.string.cancel
)
private fun onDisableAccountClicked() {
mSettingsPresenter?.disableAccount()
}

private fun backToHome() {
onBackPressedDispatcher.onBackPressed()
}

override fun startLoginActivity() {
Expand Down
Loading
Loading