Skip to content

Commit

Permalink
#1274 feat: inform the user that advanced triggers are only available…
Browse files Browse the repository at this point in the history
… from the google play build
  • Loading branch information
sds100 committed Nov 12, 2024
1 parent 38bde34 commit a4723b6
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
package io.github.sds100.keymapper.mappings.keymaps.trigger

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.foundation.layout.Arrangement
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.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.SheetState
import androidx.compose.material3.SheetValue.Expanded
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.github.sds100.keymapper.R
import io.github.sds100.keymapper.compose.KeyMapperTheme
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AdvancedTriggersBottomSheet(
modifier: Modifier = Modifier,
onDismissRequest: () -> Unit,
viewModel: ConfigTriggerViewModel,
sheetState: SheetState,
) {
AdvancedTriggersBottomSheet(
modifier,
onDismissRequest,
sheetState,
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun AdvancedTriggersBottomSheet(
modifier: Modifier = Modifier,
onDismissRequest: () -> Unit,
sheetState: SheetState,
) {
Expand All @@ -30,17 +57,85 @@ fun AdvancedTriggersBottomSheet(
onDismissRequest = onDismissRequest,
sheetState = sheetState,
) {
Text("I am free build.")
IconButton(onClick = {
scope.launch {
sheetState.hide()
onDismissRequest()
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
text = stringResource(R.string.advanced_triggers_sheet_title),
style = MaterialTheme.typography.headlineMedium,
)

Spacer(modifier = Modifier.height(8.dp))

Text(
modifier = Modifier
.padding(horizontal = 16.dp)
.fillMaxWidth(),
text = stringResource(R.string.advanced_triggers_sheet_text),
)

Spacer(modifier = Modifier.height(8.dp))

Text(
modifier = Modifier
.padding(horizontal = 16.dp)
.fillMaxWidth(),
text = stringResource(R.string.purchasing_not_implemented_bottom_sheet_text),
fontStyle = FontStyle.Italic,
)

Spacer(modifier = Modifier.height(8.dp))

val uriHandler = LocalUriHandler.current
val googlePlayUrl = stringResource(R.string.url_play_store_listing)

Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
) {
OutlinedButton(
modifier = Modifier,
onClick = {
scope.launch {
sheetState.hide()
onDismissRequest()
}
},
) {
Text(stringResource(R.string.neg_cancel))
}

FilledTonalButton(
modifier = Modifier,
onClick = {
scope.launch {
uriHandler.openUri(googlePlayUrl)
}
},
) {
Text(stringResource(R.string.purchasing_download_key_mapper_from_google_play))
}
}) {
Icon(
Icons.Default.Close,
contentDescription = stringResource(R.string.button_dismiss_advanced_triggers_sheet_content_description),
)
}

Spacer(Modifier.height(16.dp))
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Preview
@Composable
private fun Preview() {
KeyMapperTheme {
val sheetState = SheetState(
skipPartiallyExpanded = true,
density = LocalDensity.current,
initialValue = Expanded,
)

AdvancedTriggersBottomSheet(
onDismissRequest = {},
sheetState = sheetState,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package io.github.sds100.keymapper.mappings.keymaps.trigger

import android.os.Build
import android.view.KeyEvent
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import io.github.sds100.keymapper.R
import io.github.sds100.keymapper.mappings.ClickType
import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapUseCase
Expand Down Expand Up @@ -190,6 +193,8 @@ abstract class BaseConfigTriggerViewModel(
private val _fixAppKilling = MutableSharedFlow<Unit>()
val fixAppKilling = _fixAppKilling.asSharedFlow()

var showAdvancedTriggersBottomSheet: Boolean by mutableStateOf(false)

init {
val rebuildErrorList = MutableSharedFlow<State<KeyMap>>(replay = 1)

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1406,4 +1406,6 @@
<string name="purchasing_contact_email" translatable="false">[email protected]</string>
<string name="customer_email_subject" translatable="false">Key Mapper Pro query</string>
<string name="customer_email_body" translatable="false">Please describe the problem you are having here.</string>
<string name="purchasing_not_implemented_bottom_sheet_text">The advanced triggers are paid feature but you downloaded the FOSS build of Key Mapper that does not include this module or Google Play billing. Please download Key Mapper from Google Play to get access to this feature.</string>
<string name="purchasing_download_key_mapper_from_google_play">Download Play build</string>
</resources>

0 comments on commit a4723b6

Please sign in to comment.