@@ -35,8 +35,10 @@ import androidx.compose.ui.graphics.Color
35
35
import androidx.compose.ui.text.style.TextOverflow
36
36
import androidx.compose.ui.unit.dp
37
37
import androidx.navigation.NavController
38
+ import dev.hossain.keepalive.data.SettingsRepository
38
39
import dev.hossain.keepalive.data.logging.AppActivityLogger
39
40
import dev.hossain.keepalive.data.model.AppActivityLog
41
+ import dev.hossain.keepalive.util.AppConfig.DEFAULT_APP_CHECK_INTERVAL_MIN
40
42
import kotlinx.coroutines.launch
41
43
import java.text.SimpleDateFormat
42
44
import java.util.Date
@@ -52,6 +54,11 @@ fun AppActivityLogScreen(
52
54
val coroutineScope = rememberCoroutineScope()
53
55
val isLoading = remember { mutableStateOf(false ) }
54
56
57
+ // Initialize SettingsRepository to get current settings
58
+ val settingsRepository = remember { SettingsRepository (context) }
59
+ val appCheckInterval by settingsRepository.appCheckIntervalFlow.collectAsState(initial = DEFAULT_APP_CHECK_INTERVAL_MIN )
60
+ val isForceStartAppsEnabled by settingsRepository.enableForceStartAppsFlow.collectAsState(initial = false )
61
+
55
62
Column (
56
63
modifier =
57
64
Modifier
@@ -71,7 +78,7 @@ fun AppActivityLogScreen(
71
78
color = Color .Gray ,
72
79
)
73
80
74
- Spacer (modifier = Modifier .height(16 .dp))
81
+ Spacer (modifier = Modifier .height(8 .dp))
75
82
76
83
// Clear logs button
77
84
Button (
@@ -101,6 +108,9 @@ fun AppActivityLogScreen(
101
108
CircularProgressIndicator ()
102
109
}
103
110
} else if (logs.isEmpty()) {
111
+ // Show Settings Card even when no logs
112
+ CurrentSettingsCard (appCheckInterval, isForceStartAppsEnabled)
113
+
104
114
Box (
105
115
contentAlignment = Alignment .Center ,
106
116
modifier =
@@ -116,6 +126,11 @@ fun AppActivityLogScreen(
116
126
}
117
127
} else {
118
128
LazyColumn {
129
+ // Add Settings Card as first item
130
+ item {
131
+ CurrentSettingsCard (appCheckInterval, isForceStartAppsEnabled)
132
+ }
133
+
119
134
items(logs) { logEntry ->
120
135
ActivityLogItem (logEntry)
121
136
Divider ()
@@ -125,6 +140,65 @@ fun AppActivityLogScreen(
125
140
}
126
141
}
127
142
143
+ @Composable
144
+ fun CurrentSettingsCard (
145
+ appCheckInterval : Int ,
146
+ isForceStartAppsEnabled : Boolean ,
147
+ ) {
148
+ Card (
149
+ modifier =
150
+ Modifier
151
+ .fillMaxWidth()
152
+ .padding(vertical = 8 .dp),
153
+ ) {
154
+ Column (modifier = Modifier .padding(12 .dp)) {
155
+ Text (
156
+ text = " Current Settings" ,
157
+ style = MaterialTheme .typography.titleMedium,
158
+ )
159
+
160
+ Spacer (modifier = Modifier .height(4 .dp))
161
+
162
+ Row (
163
+ modifier = Modifier .fillMaxWidth(),
164
+ horizontalArrangement = Arrangement .SpaceBetween ,
165
+ ) {
166
+ Text (
167
+ text = " Check Interval:" ,
168
+ style = MaterialTheme .typography.bodyMedium,
169
+ )
170
+ Text (
171
+ text = formatMinutesToHoursAndMinutes(appCheckInterval),
172
+ style = MaterialTheme .typography.bodyMedium,
173
+ color = MaterialTheme .colorScheme.primary,
174
+ )
175
+ }
176
+
177
+ Spacer (modifier = Modifier .height(4 .dp))
178
+
179
+ Row (
180
+ modifier = Modifier .fillMaxWidth(),
181
+ horizontalArrangement = Arrangement .SpaceBetween ,
182
+ ) {
183
+ Text (
184
+ text = " Force Start Apps:" ,
185
+ style = MaterialTheme .typography.bodyMedium,
186
+ )
187
+ Text (
188
+ text = if (isForceStartAppsEnabled) " Enabled" else " Disabled" ,
189
+ style = MaterialTheme .typography.bodyMedium,
190
+ color =
191
+ if (isForceStartAppsEnabled) {
192
+ MaterialTheme .colorScheme.primary
193
+ } else {
194
+ Color .Gray
195
+ },
196
+ )
197
+ }
198
+ }
199
+ }
200
+ }
201
+
128
202
@Composable
129
203
fun ActivityLogItem (log : AppActivityLog ) {
130
204
Card (
@@ -228,3 +302,28 @@ private fun formatTimestamp(timestamp: Long): String {
228
302
val dateFormat = SimpleDateFormat (" MMM d, yyyy 'at' h:mm:ss a" , Locale .getDefault())
229
303
return dateFormat.format(Date (timestamp))
230
304
}
305
+
306
+ /* *
307
+ * Formats a time in minutes to a readable string representation.
308
+ * When the time is less than 60 minutes, it's displayed as "X minutes".
309
+ * When the time is 60 minutes or more, it's displayed as "X hours Y minutes".
310
+ *
311
+ * @param minutes The time in minutes to format
312
+ * @return A formatted string representing the time in hours and minutes
313
+ */
314
+ private fun formatMinutesToHoursAndMinutes (minutes : Int ): String {
315
+ if (minutes < 60 ) {
316
+ return " $minutes minutes"
317
+ }
318
+
319
+ val hours = minutes / 60
320
+ val remainingMinutes = minutes % 60
321
+
322
+ return if (remainingMinutes == 0 ) {
323
+ if (hours == 1 ) " $hours hour" else " $hours hours"
324
+ } else {
325
+ val hoursText = if (hours == 1 ) " $hours hour" else " $hours hours"
326
+ val minutesText = if (remainingMinutes == 1 ) " $remainingMinutes minute" else " $remainingMinutes minutes"
327
+ " $hoursText $minutesText "
328
+ }
329
+ }
0 commit comments