From 4dfef382a9ea8c632c68576e96530ee369df6696 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Sat, 14 Jan 2017 18:19:41 +0100 Subject: [PATCH] Pebble: change the overflow menu of the weather system app. If the weather notification app is not installed, link to fdroid (app if installed, web page of the app if not). If the weather notification app is installed, show the options to activate and deactivate it. --- .../appmanager/AbstractAppManagerFragment.java | 17 +++++++++++++++++ app/src/main/res/menu/appmanager_context.xml | 3 +++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 21 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java index 3e68b2dfa..946d72ae3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -298,6 +299,7 @@ public abstract class AbstractAppManagerFragment extends Fragment { if (!PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) { menu.removeItem(R.id.appmanager_weather_activate); menu.removeItem(R.id.appmanager_weather_deactivate); + menu.removeItem(R.id.appmanager_weather_install_provider); } if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM || selectedApp.getType() == GBDeviceApp.Type.WATCHFACE_SYSTEM) { menu.removeItem(R.id.appmanager_app_delete); @@ -305,6 +307,18 @@ public abstract class AbstractAppManagerFragment extends Fragment { if (!selectedApp.isConfigurable()) { menu.removeItem(R.id.appmanager_app_configure); } + + if (PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) { + PackageManager pm = getActivity().getPackageManager(); + try { + pm.getPackageInfo("ru.gelin.android.weather.notification", PackageManager.GET_ACTIVITIES); + menu.removeItem(R.id.appmanager_weather_install_provider); + } catch (PackageManager.NameNotFoundException e) { + menu.removeItem(R.id.appmanager_weather_activate); + menu.removeItem(R.id.appmanager_weather_deactivate); + } + } + switch (selectedApp.getType()) { case WATCHFACE: case APP_GENERIC: @@ -382,6 +396,9 @@ public abstract class AbstractAppManagerFragment extends Fragment { case R.id.appmanager_weather_deactivate: GBApplication.deviceService().onAppDelete(selectedApp.getUUID()); return true; + case R.id.appmanager_weather_install_provider: + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://f-droid.org/app/ru.gelin.android.weather.notification"))); + return true; case R.id.appmanager_app_configure: GBApplication.deviceService().onAppStart(selectedApp.getUUID(), true); diff --git a/app/src/main/res/menu/appmanager_context.xml b/app/src/main/res/menu/appmanager_context.xml index 766f6c5a2..2f281ce82 100644 --- a/app/src/main/res/menu/appmanager_context.xml +++ b/app/src/main/res/menu/appmanager_context.xml @@ -27,6 +27,9 @@ + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e51eea292..cabf031ab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,6 +32,7 @@ Deactivate HRM Activate system weather app Deactivate system weather app + Install the weather notification app Configure Move to top