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 /app/src/main/java/com | |
parent | c6ef99ae64b2c1fe399f13ac7c9634cc33db57b1 (diff) | |
download | rempe-b99764128aec28d4c30f07371852556d9d31151a.tar.gz rempe-b99764128aec28d4c30f07371852556d9d31151a.zip |
Diffstat (limited to 'app/src/main/java/com')
-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 |
2 files changed, 38 insertions, 0 deletions
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) { |