2424
2525package com.phpbg.easysync.ui
2626
27+ import android.content.ActivityNotFoundException
2728import android.content.Intent
2829import android.content.res.Configuration
2930import android.net.Uri
@@ -47,6 +48,7 @@ import androidx.compose.material.icons.Icons
4748import androidx.compose.material.icons.filled.Cancel
4849import androidx.compose.material.icons.filled.CheckCircle
4950import androidx.compose.material.icons.filled.Help
51+ import androidx.compose.material.icons.filled.Info
5052import androidx.compose.material.icons.filled.Schedule
5153import androidx.compose.material.icons.filled.Settings
5254import androidx.compose.material.icons.filled.Warning
@@ -58,15 +60,18 @@ import androidx.compose.material3.SnackbarHostState
5860import androidx.compose.material3.Surface
5961import androidx.compose.material3.Text
6062import androidx.compose.runtime.Composable
63+ import androidx.compose.runtime.IntState
6164import androidx.compose.runtime.State
6265import androidx.compose.runtime.livedata.observeAsState
66+ import androidx.compose.runtime.mutableIntStateOf
6367import androidx.compose.runtime.mutableStateOf
6468import androidx.compose.runtime.remember
6569import androidx.compose.runtime.rememberCoroutineScope
6670import androidx.compose.ui.Alignment
6771import androidx.compose.ui.Modifier
6872import androidx.compose.ui.graphics.Color
6973import androidx.compose.ui.platform.LocalContext
74+ import androidx.compose.ui.res.pluralStringResource
7075import androidx.compose.ui.res.stringResource
7176import androidx.compose.ui.tooling.preview.Preview
7277import androidx.compose.ui.unit.dp
@@ -126,7 +131,9 @@ class MainActivity : ComponentActivity() {
126131 showDavStatus = viewModel.showDavStatus,
127132 isDavLoading = viewModel.isDavLoading,
128133 isDavConnected = viewModel.isDavConnected,
129- hasOptionalPermissions = hasOptionalPermissions
134+ isTrial = viewModel.isTrial,
135+ hasOptionalPermissions = hasOptionalPermissions,
136+ trialRemainingDays = viewModel.trialRemainingDays
130137 )
131138 }
132139 }
@@ -148,7 +155,9 @@ private fun Main(
148155 showDavStatus : State <Boolean >,
149156 isDavLoading : State <Boolean >,
150157 isDavConnected : State <Boolean >,
158+ isTrial : State <Boolean >,
151159 hasOptionalPermissions : State <Boolean >,
160+ trialRemainingDays : IntState ,
152161) {
153162 val mContext = LocalContext .current
154163 val syncEnabled = workerState == null || workerState != WorkInfo .State .RUNNING
@@ -163,7 +172,7 @@ private fun Main(
163172 .padding(16 .dp)
164173 .verticalScroll(rememberScrollState())
165174 ) {
166- Title (text = stringResource(R .string.app_name ))
175+ Title (text = stringResource(R .string.flavored_app_name ))
167176
168177 val davSettingsHandler = fun (_: Int ) {
169178 val myIntent = Intent (mContext, DavSettingsActivity ::class .java)
@@ -247,6 +256,23 @@ private fun Main(
247256 },
248257 )
249258
259+ if (isTrial.value) {
260+ val msg = if (trialRemainingDays.intValue == 0 ) stringResource(R .string.home_trial_over) else pluralStringResource(R .plurals.home_trial_days_left, trialRemainingDays.intValue, trialRemainingDays.intValue)
261+ StatusTitleClickable (
262+ title = null ,
263+ actionTitle = msg,
264+ statusColor = Color .Gray ,
265+ statusIcon = Icons .Default .Info ,
266+ clickHandler = {
267+ try {
268+ mContext.startActivity(Intent (Intent .ACTION_VIEW , Uri .parse(" market://details?id=com.phpbg.easysync" )))
269+ } catch (e: ActivityNotFoundException ) {
270+ mContext.startActivity(Intent (Intent .ACTION_VIEW , Uri .parse(" https://play.google.com/store/apps/details?id=com.phpbg.easysync" )))
271+ }
272+ },
273+ )
274+ }
275+
250276 Spacer (modifier = Modifier .height(16 .dp))
251277
252278 val syncedPercent = if (localCount > 0 && syncedCount >= 0 ) {
@@ -354,7 +380,29 @@ private fun MainPreview() {
354380 showDavStatus = remember { mutableStateOf(true ) },
355381 isDavLoading = remember { mutableStateOf(false ) },
356382 isDavConnected = remember { mutableStateOf(true ) },
383+ isTrial = remember { mutableStateOf(false ) },
384+ hasOptionalPermissions = remember { mutableStateOf(false ) },
385+ trialRemainingDays = remember { mutableIntStateOf(0 ) }
386+ )
387+ }
388+ }
389+
390+ @Preview(name = " Trial Mode" , showBackground = false )
391+ @Composable
392+ private fun MainPreviewTrial () {
393+ MyApplicationTheme {
394+ Main (
395+ fullSyncNowHandler = {},
396+ workerState = WorkInfo .State .RUNNING ,
397+ syncedCount = 10000 ,
398+ localCount = 100 ,
399+ jobCount = - 1 ,
400+ showDavStatus = remember { mutableStateOf(true ) },
401+ isDavLoading = remember { mutableStateOf(false ) },
402+ isDavConnected = remember { mutableStateOf(true ) },
403+ isTrial = remember { mutableStateOf(true ) },
357404 hasOptionalPermissions = remember { mutableStateOf(false ) },
405+ trialRemainingDays = remember { mutableIntStateOf(28 ) }
358406 )
359407 }
360408}
0 commit comments