-
-
Notifications
You must be signed in to change notification settings - Fork 245
Add WearOS companion app #3185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add WearOS companion app #3185
Changes from all commits
bf658e4
5a6aca2
9f6d0d4
302af3d
60df23c
a1d00e9
744a745
aa72cc1
7f08786
b7cbe83
06c2fc5
71bbb86
75fd1f2
33a36ef
6b769c6
5778d3e
f4a45bc
4fca884
c3511d8
08f352b
c53e05d
0a4374a
eb155f9
fc1c43d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| /app/*.log | ||
| /app/build | ||
| /app/release | ||
| /wear/build | ||
| /wear/release | ||
| /.idea/* | ||
| !/.idea/icon.svg | ||
| # Bundle | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package protect.card_locker | ||
|
|
||
| object NotificationInfo { | ||
| object WearBluetooth { | ||
| const val NOTIFICATION_ID = 1001 | ||
| const val CHANNEL_ID = "catima_wear_bt" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,26 @@ | ||
| package protect.card_locker.preferences | ||
|
|
||
| import android.app.Activity | ||
| import android.content.Intent | ||
| import android.content.pm.PackageManager | ||
| import android.os.Build | ||
| import android.os.Bundle | ||
| import android.view.MenuItem | ||
| import androidx.activity.OnBackPressedCallback | ||
| import androidx.activity.result.contract.ActivityResultContracts | ||
| import androidx.appcompat.app.AppCompatDelegate | ||
| import androidx.core.content.ContextCompat | ||
| import androidx.core.os.LocaleListCompat | ||
| import androidx.preference.ListPreference | ||
| import androidx.preference.Preference | ||
| import androidx.preference.PreferenceFragmentCompat | ||
| import androidx.preference.SwitchPreferenceCompat | ||
| import protect.card_locker.BuildConfig | ||
| import protect.card_locker.CatimaAppCompatActivity | ||
| import protect.card_locker.MainActivity | ||
| import protect.card_locker.R | ||
| import protect.card_locker.Utils | ||
| import protect.card_locker.databinding.SettingsActivityBinding | ||
| import protect.card_locker.wearos.BluetoothServerService | ||
|
|
||
| class SettingsActivity : CatimaAppCompatActivity() { | ||
|
|
||
|
|
@@ -81,6 +85,25 @@ class SettingsActivity : CatimaAppCompatActivity() { | |
| class SettingsFragment : PreferenceFragmentCompat() { | ||
| var mReloadMain: Boolean = false | ||
|
|
||
| private val mBtPermissionLauncher = registerForActivityResult( | ||
| ActivityResultContracts.RequestPermission() | ||
| ) { granted -> | ||
| if (granted && Settings(requireContext()).wearSyncEnabled) { | ||
| requireContext().startService(Intent(requireContext(), BluetoothServerService::class.java)) | ||
| } | ||
| } | ||
|
|
||
| override fun onResume() { | ||
| super.onResume() | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && | ||
| Settings(requireContext()).wearSyncEnabled && | ||
| ContextCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_CONNECT) | ||
| != PackageManager.PERMISSION_GRANTED | ||
| ) { | ||
| mBtPermissionLauncher.launch(android.Manifest.permission.BLUETOOTH_CONNECT) | ||
| } | ||
| } | ||
|
|
||
| override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
| // Load the preferences from an XML resource | ||
| addPreferencesFromResource(R.xml.preferences) | ||
|
|
@@ -104,7 +127,7 @@ class SettingsActivity : CatimaAppCompatActivity() { | |
|
|
||
| val oledDarkPreference = findPreference<Preference>(getString(R.string.settings_key_oled_dark)) | ||
| oledDarkPreference!!.setOnPreferenceChangeListener { _, _ -> | ||
| refreshActivity(true) | ||
| refreshActivity() | ||
| true | ||
| } | ||
|
|
||
|
|
@@ -148,7 +171,7 @@ class SettingsActivity : CatimaAppCompatActivity() { | |
| localePreference.setOnPreferenceChangeListener { _, newValue -> | ||
| // See corresponding comment in Utils.updateBaseContextLocale for Android 6- notes | ||
| if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { | ||
| refreshActivity(true) | ||
| refreshActivity() | ||
| return@setOnPreferenceChangeListener true | ||
| } | ||
| val newLocale = newValue as String | ||
|
|
@@ -157,13 +180,32 @@ class SettingsActivity : CatimaAppCompatActivity() { | |
| true | ||
| } | ||
|
|
||
| val wearSyncPreference = findPreference<SwitchPreferenceCompat>(getString(R.string.settings_key_wear_sync)) | ||
| wearSyncPreference!!.setOnPreferenceChangeListener { _, newValue -> | ||
| val enabled = newValue as Boolean | ||
| val ctx = requireContext() | ||
| if (enabled) { | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && | ||
| ContextCompat.checkSelfPermission(ctx, android.Manifest.permission.BLUETOOTH_CONNECT) | ||
| != PackageManager.PERMISSION_GRANTED | ||
| ) { | ||
| mBtPermissionLauncher.launch(android.Manifest.permission.BLUETOOTH_CONNECT) | ||
| } else { | ||
| ctx.startService(Intent(ctx, BluetoothServerService::class.java)) | ||
| } | ||
| } else { | ||
| ctx.stopService(Intent(ctx, BluetoothServerService::class.java)) | ||
| } | ||
| true | ||
| } | ||
|
|
||
|
Comment on lines
+183
to
+201
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On my test devices (Samsung Galaxy S20+ 5G (Android 13), Samsung Galaxy Watch 4) toggling this on does not seem to work. I've tried to restart the watch and the phone after enabling to no avail. I keep getting the "Could not reach Catima on your phone" alert. Anything I'm missing? I also noticed it didn't ask for bluetooth/location permission. Could it be you broke the permission request code in refactoring?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I was wrong about the permission request issue. I seemed to have had that permission granted already and forgot 😅 Sadly it not syncing is staying an issue.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed this in the logging. Watch side: So it looks like it does connect, retrieve the card request and data gets sent, but somehow the watch thinks the connection got closed unexpectedly?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a lot of cards (194 to be exact) on this test device because I was also testing some lag issues. Maybe that's the issue here?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can simplify the return value. If we just have the watch call a /VERSIONS endpoint and the Android app returns supported versions (for now only By doing versioning like that, we can also simplify I think paginating is a requirement sadly, though it shouldn't be too hard. |
||
| // Hide crash reporter settings on builds it's not enabled on | ||
| val crashReporterPreference = findPreference<Preference>("acra.enable") | ||
| crashReporterPreference!!.isVisible = BuildConfig.useAcraCrashReporter | ||
| } | ||
|
|
||
| private fun refreshActivity(reloadMain: Boolean) { | ||
| mReloadMain = reloadMain || mReloadMain | ||
| private fun refreshActivity() { | ||
| mReloadMain = true | ||
| activity?.recreate() | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.