Skip to content

Commit

Permalink
Merge pull request #76 from Wottrich/issues-75
Browse files Browse the repository at this point in the history
[issue-75] A big medication name hide "Take now" button from Home screen
  • Loading branch information
waseefakhtar authored Oct 11, 2023
2 parents 83b6610 + a35d6bc commit 545828c
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import com.waseefakhtar.doseapp.domain.model.Medication
import com.waseefakhtar.doseapp.feature.addmedication.navigation.AddMedicationDestination
import com.waseefakhtar.doseapp.feature.home.viewmodel.HomeState
import com.waseefakhtar.doseapp.feature.home.viewmodel.HomeViewModel
import com.waseefakhtar.doseapp.util.getTimeRemaining
import java.util.Calendar

@Composable
Expand Down Expand Up @@ -273,7 +272,13 @@ fun DailyMedications(navController: NavController, analyticsHelper: AnalyticsHel
)
}
is MedicationListItem.MedicationItem -> {
MedicationCard(it.medication, viewModel, analyticsHelper)
MedicationCard(
it.medication,
onTakeButtonClicked = { medication ->
analyticsHelper.logEvent(AnalyticsEvents.TAKE_MEDICATION_CLICKED)
viewModel.takeMedication(medication)
}
)
}
}
}
Expand All @@ -287,72 +292,6 @@ sealed class MedicationListItem {
data class HeaderItem(val headerText: String) : MedicationListItem()
}

@Composable
fun MedicationCard(medication: Medication, viewModel: HomeViewModel, analyticsHelper: AnalyticsHelper) {

Card(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 8.dp),
shape = RoundedCornerShape(30.dp),
colors = cardColors(
containerColor = MaterialTheme.colorScheme.surfaceVariant,
)
) {

Row(
verticalAlignment = Alignment.CenterVertically
) {

Column(
modifier = Modifier
.padding(16.dp),
horizontalAlignment = Alignment.Start
) {
Text(
text = medication.name,
fontWeight = FontWeight.Bold,
style = MaterialTheme.typography.titleLarge
)
Text(
text = medication.timesOfDay.joinToString(", ")
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = getTimeRemaining(medication),
fontWeight = FontWeight.Bold
)
}

Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
horizontalAlignment = Alignment.End
) {

Button(
onClick = {
analyticsHelper.logEvent(AnalyticsEvents.TAKE_MEDICATION_CLICKED)
viewModel.takeMedication(medication)
},
enabled = !medication.medicationTaken
) {
if (medication.medicationTaken) {
Text(
text = "Taken"
)
} else {
Text(
text = "Take now"
)
}
}
}
}
}
}

@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun PermissionDialog(analyticsHelper: AnalyticsHelper, askNotificationPermission: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.waseefakhtar.doseapp.feature.home

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.waseefakhtar.doseapp.domain.model.Medication
import com.waseefakhtar.doseapp.util.getTimeRemaining
import java.util.Date

@Composable
fun MedicationCard(
medication: Medication,
onTakeButtonClicked: (Medication) -> Unit
) {

Card(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 8.dp),
shape = RoundedCornerShape(30.dp),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surfaceVariant,
)
) {

Row(
verticalAlignment = Alignment.CenterVertically
) {

Column(
modifier = Modifier
.weight(2f)
.padding(16.dp),
horizontalAlignment = Alignment.Start
) {
Text(
text = medication.name,
fontWeight = FontWeight.Bold,
style = MaterialTheme.typography.titleLarge
)
Text(
text = medication.timesOfDay.joinToString(", ")
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = getTimeRemaining(medication),
fontWeight = FontWeight.Bold
)
}

Button(
modifier = Modifier.weight(1f).padding(end = 16.dp),
onClick = { onTakeButtonClicked(medication) },
enabled = !medication.medicationTaken
) {
if (medication.medicationTaken) {
Text(
text = "Taken"
)
} else {
Text(
text = "Take now"
)
}
}
}
}
}

@Preview
@Composable
private fun MedicationCardTakeNowPreview() {
MedicationCard(
Medication(
id = 123L,
name = "A big big name for a little medication I needs to take",
dosage = 1,
recurrence = "2",
endDate = Date(),
timesOfDay = listOf(),
medicationTaken = false,
date = Date(),
)
) {
}
}

@Preview
@Composable
private fun MedicationCardTakenPreview() {
MedicationCard(
Medication(
id = 123L,
name = "A big big name for a little medication I needs to take",
dosage = 1,
recurrence = "2",
endDate = Date(),
timesOfDay = listOf(),
medicationTaken = true,
date = Date(),
)
) {
}
}

0 comments on commit 545828c

Please sign in to comment.