diff options
author | Javier <dev.git@javispedro.com> | 2021-04-16 22:43:35 +0200 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2021-04-16 22:43:35 +0200 |
commit | b99764128aec28d4c30f07371852556d9d31151a (patch) | |
tree | 8d8331a55922200280fa1e4b5f302e7397e9f770 | |
parent | c6ef99ae64b2c1fe399f13ac7c9634cc33db57b1 (diff) | |
download | rempe-master.tar.gz rempe-master.zip |
-rw-r--r-- | app/src/main/AndroidManifest.xml | 4 | ||||
-rw-r--r-- | app/src/main/java/com/javispedro/rempe/MainActivity.java | 32 | ||||
-rw-r--r-- | app/src/main/java/com/javispedro/rempe/SettingsActivity.java | 6 | ||||
-rw-r--r-- | app/src/main/res/menu/menu_main.xml | 4 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 8 |
5 files changed, 52 insertions, 2 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cc27544..3e81d66 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,7 +11,9 @@ android:theme="@style/Theme.Rempe"> <activity android:name=".SettingsActivity" - android:label="@string/settings_title"></activity> + android:label="@string/settings_title" + android:parentActivityName=".MainActivity"> + </activity> <activity android:name=".MainActivity" android:label="@string/app_name" diff --git a/app/src/main/java/com/javispedro/rempe/MainActivity.java b/app/src/main/java/com/javispedro/rempe/MainActivity.java index 77caa96..b81b0ba 100644 --- a/app/src/main/java/com/javispedro/rempe/MainActivity.java +++ b/app/src/main/java/com/javispedro/rempe/MainActivity.java @@ -2,6 +2,7 @@ package com.javispedro.rempe; import android.content.Intent; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.Menu; @@ -20,6 +21,8 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult; +import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; @@ -107,6 +110,12 @@ public class MainActivity extends AppCompatActivity { case R.id.action_settings: startActivity(new Intent(this, SettingsActivity.class)); return true; + case R.id.action_open_antplus_plugin_manager: + if (!AntPluginPcc.startPluginManagerActivity(this)) { + Log.e(TAG, "plugin manager not found"); + showDependencyRequiredMsg("ANT+ plugin manager", "com.dsi.ant.plugins.antplus"); + } + return true; } return super.onOptionsItemSelected(item); @@ -159,6 +168,12 @@ public class MainActivity extends AppCompatActivity { mSearchDevice.setObserver(null); mSearchDevice = null; // Ownership of mSearchDevice passed to addDevice below runOnUiThread(() -> addDevice(device)); + } else if (result == RequestAccessResult.DEPENDENCY_NOT_INSTALLED) { + final String dependency = AntPluginPcc.getMissingDependencyName(); + final String packageName = AntPluginPcc.getMissingDependencyPackageName(); + runOnUiThread(() -> { + showDependencyRequiredMsg(dependency, packageName); + }); } else if (result != RequestAccessResult.USER_CANCELLED) { runOnUiThread(() -> { final String resultText = Device.connectionRequestAccessResultToString(MainActivity.this, result); @@ -193,6 +208,23 @@ public class MainActivity extends AppCompatActivity { } }; + public void showDependencyRequiredMsg(String name, String packageName) { + Log.d(TAG, "showDependencyRequiredMsg for " + name + " (" + packageName + ")"); + new MaterialAlertDialogBuilder(this) + .setTitle(R.string.antplus_required_title) + .setMessage(getString(R.string.antplus_required_msg, name)) + .setPositiveButton(R.string.antplus_required_go_to_store, (dialog, which) -> { + dialog.dismiss(); + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse("market://details?id=" + packageName)); + startActivity(intent); + }) + .setNeutralButton(R.string.antplus_required_close, (dialog, which) -> { + dialog.dismiss(); + }) + .show(); + } + public void searchForNewDevice() { if (mSearchDevice != null) { mSearchDevice.close(); diff --git a/app/src/main/java/com/javispedro/rempe/SettingsActivity.java b/app/src/main/java/com/javispedro/rempe/SettingsActivity.java index f660c70..d42c493 100644 --- a/app/src/main/java/com/javispedro/rempe/SettingsActivity.java +++ b/app/src/main/java/com/javispedro/rempe/SettingsActivity.java @@ -24,6 +24,12 @@ public class SettingsActivity extends AppCompatActivity { } } + @Override + public boolean onSupportNavigateUp() { + finish(); + return true; + } + public static class SettingsFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index b11af65..c39abfd 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -8,4 +8,8 @@ android:orderInCategory="100" android:title="@string/action_settings" app:showAsAction="never" /> + <item + android:id="@+id/action_open_antplus_plugin_manager" + android:orderInCategory="101" + android:title="@string/action_open_antplus_plugin_manager" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index df21b28..3ab9a52 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,12 @@ <resources> <string name="app_name">Rempe</string> <string name="action_settings">Settings</string> + <string name="action_open_antplus_plugin_manager">ANT+ Plugin Manager</string> + + <string name="antplus_required_title">App required</string> + <string name="antplus_required_msg">The following app is required to connect to ANT+ devices:\n\n%s</string> + <string name="antplus_required_go_to_store">Go to Store</string> + <string name="antplus_required_close">Close</string> <string name="fab_add_device">Add device…</string> <string name="add_device_failed">Cannot connect to device: %1$s</string> @@ -10,7 +16,7 @@ <string name="device_placeholder_name">Device</string> <string name="device_placeholder_status">Status</string> - <string name="device_unnamed">dev#%d</string> + <string name="device_unnamed">ID<%d></string> <string name="temperature_nothing">—</string> <string name="temperature_celsius">%.1f °C</string> |