Skip to content

Commit 282c06e

Browse files
committed
show a notification for floating buttons
1 parent 07a3544 commit 282c06e

File tree

10 files changed

+73
-53
lines changed

10 files changed

+73
-53
lines changed

app/src/main/java/io/github/sds100/keymapper/BaseMainActivity.kt

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ import com.anggrayudi.storage.extension.toDocumentFile
2929
import io.github.sds100.keymapper.Constants.PACKAGE_NAME
3030
import io.github.sds100.keymapper.compose.ComposeColors
3131
import io.github.sds100.keymapper.databinding.ActivityMainBinding
32-
import io.github.sds100.keymapper.home.HomeViewModel
3332
import io.github.sds100.keymapper.mappings.keymaps.trigger.RecordTriggerController
3433
import io.github.sds100.keymapper.system.accessibility.AccessibilityServiceAdapter
3534
import io.github.sds100.keymapper.system.files.FileUtils
3635
import io.github.sds100.keymapper.system.inputevents.MyMotionEvent
3736
import io.github.sds100.keymapper.system.permissions.AndroidPermissionAdapter
3837
import io.github.sds100.keymapper.system.permissions.RequestPermissionDelegate
39-
import io.github.sds100.keymapper.util.Inject
4038
import io.github.sds100.keymapper.util.launchRepeatOnLifecycle
4139
import io.github.sds100.keymapper.util.ui.showPopups
4240
import kotlinx.coroutines.Dispatchers
@@ -55,8 +53,8 @@ abstract class BaseMainActivity : AppCompatActivity() {
5553
const val ACTION_SHOW_ACCESSIBILITY_SETTINGS_NOT_FOUND_DIALOG =
5654
"$PACKAGE_NAME.ACTION_SHOW_ACCESSIBILITY_SETTINGS_NOT_FOUND_DIALOG"
5755

58-
const val ACTION_USE_ASSISTANT_TRIGGER =
59-
"$PACKAGE_NAME.ACTION_USE_ASSISTANT_TRIGGER"
56+
const val ACTION_USE_FLOATING_BUTTONS =
57+
"$PACKAGE_NAME.ACTION_USE_FLOATING_BUTTONS"
6058

6159
const val ACTION_SAVE_FILE = "$PACKAGE_NAME.ACTION_SAVE_FILE"
6260
const val EXTRA_FILE_URI = "$PACKAGE_NAME.EXTRA_FILE_URI"
@@ -74,10 +72,6 @@ abstract class BaseMainActivity : AppCompatActivity() {
7472
ActivityViewModel.Factory(ServiceLocator.resourceProvider(this))
7573
}
7674

77-
private val homeViewModel by viewModels<HomeViewModel> {
78-
Inject.homeViewModel(this)
79-
}
80-
8175
private val currentNightMode: Int
8276
get() = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
8377

@@ -162,16 +156,6 @@ abstract class BaseMainActivity : AppCompatActivity() {
162156
viewModel.onCantFindAccessibilitySettings()
163157
viewModel.handledActivityLaunchIntent = true
164158
}
165-
166-
ACTION_USE_ASSISTANT_TRIGGER -> {
167-
findNavController(R.id.container).navigate(
168-
NavAppDirections.actionToConfigKeymap(
169-
keymapUid = null,
170-
showAdvancedTriggers = true,
171-
),
172-
)
173-
viewModel.handledActivityLaunchIntent = true
174-
}
175159
}
176160
}
177161

@@ -201,6 +185,8 @@ abstract class BaseMainActivity : AppCompatActivity() {
201185
}
202186

203187
override fun onDestroy() {
188+
UseCases.onboarding(this).shownAppIntro = true
189+
204190
viewModel.previousNightMode = currentNightMode
205191
unregisterReceiver(broadcastReceiver)
206192
super.onDestroy()

app/src/main/java/io/github/sds100/keymapper/data/Keys.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ object Keys {
4343
val acknowledgedGuiKeyboard = booleanPreferencesKey("pref_acknowledged_gui_keyboard")
4444
val showDeviceDescriptors = booleanPreferencesKey("pref_show_device_descriptors")
4545

46-
val approvedAssistantTriggerFeaturePrompt =
47-
booleanPreferencesKey("pref_approved_assistant_trigger_feature_prompt")
46+
// val approvedAssistantTriggerFeaturePrompt =
47+
// booleanPreferencesKey("pref_approved_assistant_trigger_feature_prompt")
48+
val approvedFloatingButtonFeaturePrompt =
49+
booleanPreferencesKey("pref_approved_floating_button_feature_prompt")
50+
4851
val shownParallelTriggerOrderExplanation =
4952
booleanPreferencesKey("key_shown_parallel_trigger_order_warning")
5053
val shownSequenceTriggerExplanation =

app/src/main/java/io/github/sds100/keymapper/home/HomeFragment.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import androidx.compose.ui.platform.ViewCompositionStrategy
88
import androidx.fragment.app.Fragment
99
import androidx.fragment.app.activityViewModels
1010
import androidx.navigation.findNavController
11+
import io.github.sds100.keymapper.ActivityViewModel
12+
import io.github.sds100.keymapper.BaseMainActivity
1113
import io.github.sds100.keymapper.NavAppDirections
14+
import io.github.sds100.keymapper.ServiceLocator
1215
import io.github.sds100.keymapper.compose.KeyMapperTheme
1316
import io.github.sds100.keymapper.databinding.FragmentComposeBinding
1417
import io.github.sds100.keymapper.util.Inject
@@ -21,6 +24,10 @@ class HomeFragment : Fragment() {
2124
Inject.homeViewModel(requireContext())
2225
}
2326

27+
val activityViewModel: ActivityViewModel by activityViewModels<ActivityViewModel> {
28+
ActivityViewModel.Factory(ServiceLocator.resourceProvider(requireContext()))
29+
}
30+
2431
override fun onCreate(savedInstanceState: Bundle?) {
2532
super.onCreate(savedInstanceState)
2633

@@ -33,6 +40,16 @@ class HomeFragment : Fragment() {
3340
container: ViewGroup?,
3441
savedInstanceState: Bundle?,
3542
): View {
43+
val startDestination =
44+
if (!activityViewModel.handledActivityLaunchIntent &&
45+
requireActivity().intent?.action == BaseMainActivity.ACTION_USE_FLOATING_BUTTONS
46+
) {
47+
activityViewModel.handledActivityLaunchIntent = true
48+
HomeDestination.FloatingButtons
49+
} else {
50+
HomeDestination.KeyMaps
51+
}
52+
3653
FragmentComposeBinding.inflate(inflater, container, false).apply {
3754
composeView.apply {
3855
// Dispose of the Composition when the view's LifecycleOwner
@@ -49,6 +66,7 @@ class HomeFragment : Fragment() {
4966
findNavController().navigate(NavAppDirections.actionGlobalAboutFragment())
5067
},
5168
finishActivity = requireActivity()::finish,
69+
startDestination = startDestination,
5270
)
5371
}
5472
}

app/src/main/java/io/github/sds100/keymapper/home/HomeScreen.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ fun HomeScreen(
146146
onSettingsClick: () -> Unit,
147147
onAboutClick: () -> Unit,
148148
finishActivity: () -> Unit,
149+
startDestination: HomeDestination = HomeDestination.KeyMaps,
149150
) {
150151
val homeState by viewModel.state.collectAsStateWithLifecycle()
151152

@@ -270,6 +271,7 @@ fun HomeScreen(
270271
HomeScreen(
271272
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
272273
navController = navController,
274+
startDestination = startDestination,
273275
homeState = homeState,
274276
snackBarState = snackbarState,
275277
navBarItems = navBarItems,
@@ -382,6 +384,7 @@ fun HomeScreen(
382384
private fun HomeScreen(
383385
modifier: Modifier = Modifier,
384386
homeState: HomeState,
387+
startDestination: HomeDestination = HomeDestination.KeyMaps,
385388
navController: NavHostController,
386389
snackBarState: SnackbarHostState = SnackbarHostState(),
387390
navBarItems: List<HomeNavBarItem>,
@@ -493,7 +496,7 @@ private fun HomeScreen(
493496
),
494497
contentAlignment = Alignment.TopCenter,
495498
navController = navController,
496-
startDestination = HomeDestination.KeyMaps.route,
499+
startDestination = startDestination.route,
497500
// use no animations because otherwise the transition freezes
498501
// when quickly navigating to another page while the transition is still happening.
499502
enterTransition = { EnterTransition.None },

app/src/main/java/io/github/sds100/keymapper/onboarding/OnboardingUseCase.kt

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,23 @@ class OnboardingUseCaseImpl(
7777
readText()
7878
}
7979

80-
override var approvedAssistantTriggerFeaturePrompt by PrefDelegate(
81-
Keys.approvedAssistantTriggerFeaturePrompt,
80+
override var approvedFloatingButtonFeaturePrompt by PrefDelegate(
81+
Keys.approvedFloatingButtonFeaturePrompt,
8282
false,
8383
)
8484

8585
/**
86-
* Show the assistant trigger only when they *upgrade* to the new version and after they've
86+
* Show only when they *upgrade* to the new version and after they've
8787
* completed the app intro, which asks them whether they want to receive notifications.
8888
*/
89-
override val showAssistantTriggerFeatureNotification: Flow<Boolean> =
90-
combine(
91-
get(Keys.lastInstalledVersionCodeBackground).map { it ?: -1 },
92-
get(Keys.shownAppIntro).map { it ?: false },
93-
get(Keys.approvedAssistantTriggerFeaturePrompt).map { it ?: false },
94-
) { oldVersionCode, shownAppIntro, approvedPrompt ->
95-
oldVersionCode < VersionHelper.ASSISTANT_TRIGGER_MIN_VERSION &&
96-
shownAppIntro &&
97-
!approvedPrompt
98-
}
89+
override val showFloatingButtonFeatureNotification: Flow<Boolean> = combine(
90+
get(Keys.lastInstalledVersionCodeBackground).map { it ?: -1 },
91+
get(Keys.approvedFloatingButtonFeaturePrompt).map { it ?: false },
92+
) { oldVersionCode, approvedPrompt ->
93+
oldVersionCode < VersionHelper.FLOATING_BUTTON_MIN_VERSION && !approvedPrompt
94+
}
9995

100-
override fun showedAssistantTriggerFeatureNotification() {
96+
override fun showedFloatingButtonFeatureNotification() {
10197
set(Keys.lastInstalledVersionCodeBackground, Constants.VERSION_CODE)
10298
}
10399

@@ -172,9 +168,9 @@ interface OnboardingUseCase {
172168
var shownParallelTriggerOrderExplanation: Boolean
173169
var shownSequenceTriggerExplanation: Boolean
174170

175-
val showAssistantTriggerFeatureNotification: Flow<Boolean>
176-
fun showedAssistantTriggerFeatureNotification()
177-
var approvedAssistantTriggerFeaturePrompt: Boolean
171+
val showFloatingButtonFeatureNotification: Flow<Boolean>
172+
fun showedFloatingButtonFeatureNotification()
173+
var approvedFloatingButtonFeaturePrompt: Boolean
178174

179175
val showWhatsNew: Flow<Boolean>
180176
fun showedWhatsNew()

app/src/main/java/io/github/sds100/keymapper/system/notifications/NotificationController.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class NotificationController(
5252
private const val ID_KEYBOARD_HIDDEN = 747
5353
private const val ID_TOGGLE_MAPPINGS = 231
5454
private const val ID_TOGGLE_KEYBOARD = 143
55-
private const val ID_FEATURE_ASSISTANT_TRIGGER = 900
55+
56+
// private const val ID_FEATURE_ASSISTANT_TRIGGER = 900
57+
private const val ID_FEATURE_FLOATING_BUTTONS = 901
5658

5759
const val CHANNEL_TOGGLE_KEYMAPS = "channel_toggle_remaps"
5860
const val CHANNEL_IME_PICKER = "channel_ime_picker"
@@ -156,15 +158,15 @@ class NotificationController(
156158

157159
coroutineScope.launch(dispatchers.default()) {
158160
// suspend until the notification should be shown.
159-
onboardingUseCase.showAssistantTriggerFeatureNotification.first { it }
161+
onboardingUseCase.showFloatingButtonFeatureNotification.first { it }
160162

161-
manageNotifications.show(assistantTriggerFeatureNotification())
163+
manageNotifications.show(floatingButtonFeatureNotification())
162164

163165
// Only save that the notification is shown if the app has
164166
// permissions to show notifications so that it is shown
165167
// the next time permission is granted.
166168
if (manageNotifications.isPermissionGranted()) {
167-
onboardingUseCase.showedAssistantTriggerFeatureNotification()
169+
onboardingUseCase.showedFloatingButtonFeatureNotification()
168170
}
169171
}
170172

@@ -438,13 +440,13 @@ class NotificationController(
438440
priority = NotificationCompat.PRIORITY_LOW,
439441
)
440442

441-
private fun assistantTriggerFeatureNotification(): NotificationModel = NotificationModel(
442-
id = ID_FEATURE_ASSISTANT_TRIGGER,
443+
private fun floatingButtonFeatureNotification(): NotificationModel = NotificationModel(
444+
id = ID_FEATURE_FLOATING_BUTTONS,
443445
channel = CHANNEL_NEW_FEATURES,
444-
title = getString(R.string.notification_assistant_trigger_feature_title),
445-
text = getString(R.string.notification_assistant_trigger_feature_text),
446-
icon = R.drawable.ic_outline_assistant_24,
447-
onClickAction = NotificationIntentType.MainActivity(BaseMainActivity.ACTION_USE_ASSISTANT_TRIGGER),
446+
title = getString(R.string.notification_floating_buttons_feature_title),
447+
text = getString(R.string.notification_floating_buttons_feature_text),
448+
icon = R.drawable.outline_bubble_chart_24,
449+
onClickAction = NotificationIntentType.MainActivity(BaseMainActivity.ACTION_USE_FLOATING_BUTTONS),
448450
priority = NotificationCompat.PRIORITY_LOW,
449451
autoCancel = true,
450452
onGoing = false,

app/src/main/java/io/github/sds100/keymapper/util/VersionHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object VersionHelper {
1313
const val FINGERPRINT_GESTURES_MIN_VERSION = 40
1414

1515
/**
16-
* This is version 2.7.0 when the assistant trigger was first introduced.
16+
* This is version 3.0.0-beta.1 when the assistant trigger was first introduced.
1717
*/
18-
const val ASSISTANT_TRIGGER_MIN_VERSION = 66
18+
const val FLOATING_BUTTON_MIN_VERSION = 81
1919
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="#000000"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
8+
<path
9+
android:fillColor="@android:color/white"
10+
android:pathData="M7,10c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM7,16c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.01,15c-1.65,0 -3,1.35 -3,3s1.35,3 3,3 3,-1.35 3,-3 -1.35,-3 -3,-3zM15.01,19c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM16.5,3C13.47,3 11,5.47 11,8.5s2.47,5.5 5.5,5.5S22,11.53 22,8.5 19.53,3 16.5,3zM16.5,12c-1.93,0 -3.5,-1.57 -3.5,-3.5S14.57,5 16.5,5 20,6.57 20,8.5 18.43,12 16.5,12z" />
11+
12+
</vector>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,8 +1178,6 @@
11781178
<string name="assistant_trigger_product_description">Did you know you can remap your side key, power button, or device assistant? Instead of launching the assistant or the power menu, your device can perform an action of your choice. It works even when the screen is off!</string>
11791179
<string name="trigger_error_assistant_not_purchased">You must purchase the side key trigger feature.</string>
11801180
<string name="advanced_triggers_learn_more_button">Learn more</string>
1181-
<string name="notification_assistant_trigger_feature_title">New trigger! Did you know you can remap your side key, power button, or device assistant?</string>
1182-
<string name="notification_assistant_trigger_feature_text">Instead of launching the assistant or the power menu, your device can perform an action of your choice. Tap to learn more.</string>
11831181
<string name="trigger_error_floating_buttons_not_purchased">You must purchase floating buttons.</string>
11841182
<string name="trigger_error_floating_button_deleted">Button was deleted.</string>
11851183
<string name="trigger_error_floating_button_deleted_title">Floating button</string>
@@ -1267,6 +1265,8 @@
12671265
<string name="floating_button_trigger_option_configure_button">Configure button</string>
12681266
<string name="floating_button_trigger_option_edit_layout">Edit layout</string>
12691267
<string name="floating_buttons_product_min_api_error">Requires Android 11 or newer.</string>
1268+
<string name="notification_floating_buttons_feature_title">Don’t have enough buttons? Now you can make your own!</string>
1269+
<string name="notification_floating_buttons_feature_text">Floating buttons display over the apps you want. They work just like real buttons, and you can place, style, and map them however you like.</string>
12701270

12711271
<!-- Home screen -->
12721272
<string name="sort_bottom_sheet_trigger">Trigger</string>

app/src/test/java/io/github/sds100/keymapper/onboarding/FakeOnboardingUseCase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
88
* Created by sds100 on 26/04/2021.
99
*/
1010
class FakeOnboardingUseCase : OnboardingUseCase {
11-
override var shownAppIntro: Boolean = false
11+
override var firstTime: Boolean = false
1212

1313
override suspend fun showInstallGuiKeyboardPrompt(action: ActionData): Boolean {
1414
throw NotImplementedError()

0 commit comments

Comments
 (0)