Skip to content

Commit 787d7e5

Browse files
refactor #1532: profile fragment migrated to compose
1 parent 87f22c7 commit 787d7e5

File tree

4 files changed

+110
-44
lines changed

4 files changed

+110
-44
lines changed

mifospay/src/main/java/org/mifos/mobilewallet/mifospay/home/presenter/ProfileViewModel.kt

+25-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import okhttp3.ResponseBody
1212
import org.mifos.mobilewallet.core.base.UseCase
1313
import org.mifos.mobilewallet.core.base.UseCaseHandler
1414
import org.mifos.mobilewallet.core.domain.usecase.client.FetchClientImage
15+
import org.mifos.mobilewallet.datastore.PreferencesHelper
1516
import org.mifos.mobilewallet.mifospay.data.local.LocalRepository
1617
import org.mifos.mobilewallet.mifospay.utils.DebugUtil
1718
import javax.inject.Inject
@@ -20,14 +21,28 @@ import javax.inject.Inject
2021
class ProfileViewModel @Inject constructor(
2122
private val mUsecaseHandler: UseCaseHandler,
2223
private val fetchClientImageUseCase: FetchClientImage,
23-
private val localRepository: LocalRepository
24+
private val localRepository: LocalRepository,
25+
private val mPreferencesHelper: PreferencesHelper
2426
) : ViewModel() {
2527

2628
private val _bitmapImage = MutableStateFlow<Bitmap?>(null)
2729
val bitmapImage: StateFlow<Bitmap?> = _bitmapImage
2830

31+
private val _name = MutableStateFlow<String?>(null)
32+
val name: StateFlow<String?> = _name
33+
34+
private val _email = MutableStateFlow<String?>(null)
35+
val email: StateFlow<String?> = _email
36+
37+
private val _vpa = MutableStateFlow<String?>(null)
38+
val vpa: StateFlow<String?> = _vpa
39+
40+
private val _mobile = MutableStateFlow<String?>(null)
41+
val mobile: StateFlow<String?> = _mobile
42+
2943
init {
3044
fetchClientImage()
45+
fetchProfileDetails()
3146
}
3247

3348
private fun fetchClientImage() {
@@ -41,14 +56,19 @@ class ProfileViewModel @Inject constructor(
4156
}
4257

4358
override fun onError(message: String) {
44-
DebugUtil.log("image", message) }
59+
DebugUtil.log("image", message)
60+
}
4561
})
4662
}
4763
}
4864

49-
/**
50-
* convert the binary data from the ResponseBody into a Bitmap
51-
*/
65+
private fun fetchProfileDetails() {
66+
_name.value = mPreferencesHelper.fullName ?: "-"
67+
_email.value = mPreferencesHelper.email ?: "-"
68+
_vpa.value = mPreferencesHelper.clientVpa ?: "-"
69+
_mobile.value = mPreferencesHelper.mobile ?: "-"
70+
}
71+
5272
private fun convertResponseToBitmap(responseBody: ResponseBody?): Bitmap? {
5373
return try {
5474
responseBody?.byteStream()?.use { inputStream ->

mifospay/src/main/java/org/mifos/mobilewallet/mifospay/home/ui/ProfileFragment.kt

-5
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,16 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
1111
import dagger.hilt.android.AndroidEntryPoint
1212
import org.mifos.mobilewallet.mifospay.base.BaseFragment
1313
import org.mifos.mobilewallet.mifospay.editprofile.ui.EditProfileActivity
14-
import org.mifos.mobilewallet.mifospay.home.presenter.ProfilePresenter
1514
import org.mifos.mobilewallet.mifospay.settings.ui.SettingsActivity
1615
import org.mifos.mobilewallet.mifospay.theme.MifosTheme
1716
import org.mifos.mobilewallet.mifospay.utils.Constants
18-
import javax.inject.Inject
1917

2018
/**
2119
* Created by naman on 7/9/17.
2220
*/
2321
@AndroidEntryPoint
2422
class ProfileFragment : BaseFragment() {
2523

26-
@Inject
27-
lateinit var mPresenter: ProfilePresenter
28-
2924
override fun onCreateView(
3025
inflater: LayoutInflater, container: ViewGroup?,
3126
savedInstanceState: Bundle?

mifospay/src/main/java/org/mifos/mobilewallet/mifospay/home/ui/ProfileItemCard.kt

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.size
1111
import androidx.compose.foundation.layout.width
1212
import androidx.compose.foundation.shape.RoundedCornerShape
1313
import androidx.compose.material3.Icon
14+
import androidx.compose.material3.MaterialTheme
1415
import androidx.compose.material3.Text
1516
import androidx.compose.runtime.Composable
1617
import androidx.compose.ui.Alignment
@@ -25,7 +26,7 @@ import androidx.compose.ui.unit.sp
2526
import org.mifos.mobilewallet.mifospay.ui.utility.Orientation
2627

2728
@Composable
28-
fun ItemCard(
29+
fun ProfileItemCard(
2930
modifier: Modifier = Modifier,
3031
icon: Int,
3132
text: Int,
@@ -70,3 +71,12 @@ private fun ItemContent(icon: Int, text: Int, orientation: Orientation = Orienta
7071
style = TextStyle(fontSize = 18.sp, fontWeight = FontWeight.Medium)
7172
)
7273
}
74+
75+
@Composable
76+
fun DetailItem(label: String, value: String) {
77+
Text(
78+
text = "$label: $value",
79+
style = MaterialTheme.typography.bodyLarge,
80+
modifier = Modifier.padding(bottom = 12.dp)
81+
)
82+
}

mifospay/src/main/java/org/mifos/mobilewallet/mifospay/home/ui/ProfileScreen.kt

+74-33
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@ package org.mifos.mobilewallet.mifospay.home.ui
22

33
import androidx.compose.foundation.layout.Arrangement
44
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
6+
import androidx.compose.foundation.layout.FlowRow
57
import androidx.compose.foundation.layout.Row
6-
import androidx.compose.foundation.layout.Spacer
78
import androidx.compose.foundation.layout.fillMaxSize
89
import androidx.compose.foundation.layout.fillMaxWidth
9-
import androidx.compose.foundation.layout.height
1010
import androidx.compose.foundation.layout.padding
11-
import androidx.compose.foundation.layout.width
11+
import androidx.compose.material.icons.Icons
12+
import androidx.compose.material.icons.filled.ArrowDropDown
13+
import androidx.compose.material3.Icon
14+
import androidx.compose.material3.IconButton
1215
import androidx.compose.material3.Text
1316
import androidx.compose.runtime.Composable
1417
import androidx.compose.runtime.collectAsState
1518
import androidx.compose.runtime.getValue
19+
import androidx.compose.runtime.mutableStateOf
20+
import androidx.compose.runtime.remember
21+
import androidx.compose.runtime.setValue
22+
import androidx.compose.ui.Alignment
1623
import androidx.compose.ui.Modifier
24+
import androidx.compose.ui.graphics.Color
1725
import androidx.compose.ui.text.TextStyle
1826
import androidx.compose.ui.text.font.FontWeight
1927
import androidx.compose.ui.tooling.preview.Preview
@@ -25,68 +33,101 @@ import org.mifos.mobilewallet.mifospay.designsystem.component.ProfileImage
2533
import org.mifos.mobilewallet.mifospay.home.presenter.ProfileViewModel
2634
import org.mifos.mobilewallet.mifospay.ui.utility.Orientation
2735

36+
@OptIn(ExperimentalLayoutApi::class)
2837
@Composable
2938
fun ProfileScreen(
3039
viewModel: ProfileViewModel = hiltViewModel(),
3140
onEditProfile: () -> Unit,
3241
onSettings: () -> Unit,
3342
) {
3443
val bitmap by viewModel.bitmapImage.collectAsState()
44+
val name = viewModel.name.collectAsState().value
45+
val email = viewModel.email.collectAsState().value
46+
val vpa = viewModel.vpa.collectAsState().value
47+
val mobile = viewModel.mobile.collectAsState().value
48+
49+
var showDetails by remember { mutableStateOf(false) }
3550

3651
Column(modifier = Modifier.fillMaxSize()) {
3752
ProfileImage(bitmap = bitmap)
3853
Row(
3954
modifier = Modifier
4055
.fillMaxWidth()
41-
.padding(top = 12.dp, bottom = 20.dp),
42-
horizontalArrangement = Arrangement.Center
56+
.padding(top = 12.dp, bottom = 8.dp),
57+
horizontalArrangement = Arrangement.Center,
58+
verticalAlignment = Alignment.CenterVertically
4359
) {
4460
Text(
45-
text = "John Doe",
46-
style = TextStyle(fontSize = 24.sp, fontWeight = FontWeight.Medium)
61+
text = name.toString(),
62+
style = TextStyle(fontSize = 24.sp, fontWeight = FontWeight.Medium),
4763
)
64+
IconButton(onClick = { showDetails = !showDetails }) {
65+
Icon(
66+
imageVector = Icons.Default.ArrowDropDown,
67+
tint = Color.Black,
68+
contentDescription = null
69+
)
70+
}
71+
}
72+
73+
if (showDetails) {
74+
Column(
75+
modifier = Modifier.fillMaxWidth(),
76+
verticalArrangement = Arrangement.Center,
77+
horizontalAlignment = Alignment.CenterHorizontally
78+
) {
79+
DetailItem(label = "Email", value = email.toString())
80+
DetailItem(label = "VPA", value = vpa.toString())
81+
DetailItem(label = "Mobile", value = mobile.toString())
82+
}
4883
}
4984

5085
Column(
5186
modifier = Modifier
5287
.fillMaxSize()
5388
.padding(start = 24.dp, end = 24.dp)
5489
) {
55-
Row(
90+
FlowRow(
5691
modifier = Modifier
57-
.fillMaxWidth()
58-
.padding(bottom = 24.dp)
92+
.fillMaxWidth(),
93+
maxItemsInEachRow = 2
5994
) {
60-
ItemCard(
61-
modifier = Modifier.weight(1f),
95+
ProfileItemCard(
96+
modifier = Modifier
97+
.padding(end = 8.dp, bottom = 8.dp)
98+
.weight(1f),
6299
icon = R.drawable.qrcode_black,
63100
text = R.string.personal_qr_code,
64-
onClick = {},
65-
orientation = Orientation.VERTICAL
101+
onClick = {}
66102
)
67-
Spacer(modifier = Modifier.width(16.dp))
68-
ItemCard(
69-
modifier = Modifier.weight(1f),
103+
104+
ProfileItemCard(
105+
modifier = Modifier
106+
.padding(start = 8.dp, bottom = 8.dp)
107+
.weight(1f),
70108
icon = R.drawable.ic_bank,
71109
text = R.string.link_bank_account,
72-
onClick = {},
73-
orientation = Orientation.VERTICAL
110+
onClick = {}
74111
)
75-
}
76-
ItemCard(
77-
icon = R.drawable.ic_contact,
78-
text = R.string.edit_profile,
79-
onClick = { onEditProfile.invoke() },
80-
orientation = Orientation.HORIZONTAL
81-
)
82-
Spacer(modifier = Modifier.height(24.dp))
83-
ItemCard(
84-
icon = R.drawable.ic_setting,
85-
text = R.string.settings,
86-
onClick = { onSettings.invoke() },
87-
orientation = Orientation.HORIZONTAL
88-
)
89112

113+
ProfileItemCard(
114+
modifier = Modifier
115+
.padding(top = 8.dp, bottom = 8.dp),
116+
icon = R.drawable.ic_contact,
117+
text = R.string.edit_profile,
118+
onClick = { onEditProfile.invoke() },
119+
orientation = Orientation.HORIZONTAL
120+
)
121+
122+
ProfileItemCard(
123+
modifier = Modifier
124+
.padding(top = 8.dp),
125+
icon = R.drawable.ic_setting,
126+
text = R.string.settings,
127+
onClick = { onSettings.invoke() },
128+
orientation = Orientation.HORIZONTAL
129+
)
130+
}
90131
}
91132
}
92133
}

0 commit comments

Comments
 (0)