From fe33f4633decddf8a37fcfe033129bfdbd66e1c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pekka=20Ker=C3=A4nen?= Date: Fri, 3 Jan 2025 14:42:23 +0200 Subject: [PATCH 1/2] issue-703: Added fmiweather://search url handler --- android/app/src/main/AndroidManifest.xml | 11 +++++++- .../BaseWidgetConfigurationActivity.java | 25 +++++++++++-------- src/navigators/TabNavigator.tsx | 19 +++++++++++++- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 621dcfda..413c0315 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -50,7 +50,16 @@ android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" - android:exported="true" /> + android:exported="true"> + + + + + + + + + diff --git a/android/app/src/main/java/fi/fmi/mobileweather/BaseWidgetConfigurationActivity.java b/android/app/src/main/java/fi/fmi/mobileweather/BaseWidgetConfigurationActivity.java index e2111076..ac1cef6f 100644 --- a/android/app/src/main/java/fi/fmi/mobileweather/BaseWidgetConfigurationActivity.java +++ b/android/app/src/main/java/fi/fmi/mobileweather/BaseWidgetConfigurationActivity.java @@ -5,7 +5,6 @@ import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID; import static android.content.res.Configuration.UI_MODE_NIGHT_MASK; import static android.content.res.Configuration.UI_MODE_NIGHT_NO; -import static android.graphics.Color.BLACK; import static android.view.View.GONE; import static android.view.View.VISIBLE; @@ -23,7 +22,6 @@ import android.content.Context; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; -import android.graphics.Typeface; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -42,7 +40,6 @@ import android.content.pm.PackageManager; import androidx.annotation.NonNull; -import androidx.appcompat.content.res.AppCompatResources; import androidx.core.app.ActivityCompat; import com.reactnativecommunity.asyncstorage.AsyncLocalStorageUtil; @@ -100,6 +97,8 @@ public void onResume(){ } else { batteryOptimizationWarning.setVisibility(GONE); } + + setLocationFavoritesButtons(); } public static boolean isPowerSavingEnabled(Context context) { @@ -159,11 +158,15 @@ private void setLocationFavoritesButtons() { int geoId = current.getInt("id"); String name = current.getString("name"); - RadioButton favoriteRadioButton = (RadioButton) inflater.inflate(R.layout.favorite_radio_button, locationRadioGroup, false); - favoriteRadioButton.setText(name); - favoriteRadioButton.setTag(geoId); - favoriteRadioButton.setId(geoId); - locationRadioGroup.addView(favoriteRadioButton); + RadioButton existingRadioButton = findViewById(geoId); + + if (existingRadioButton == null) { + RadioButton favoriteRadioButton = (RadioButton) inflater.inflate(R.layout.favorite_radio_button, locationRadioGroup, false); + favoriteRadioButton.setText(name); + favoriteRadioButton.setTag(geoId); + favoriteRadioButton.setId(geoId); + locationRadioGroup.addView(favoriteRadioButton); + } } } catch (JSONException e) { Log.d("Widget Update", "Error parsing location favorites: " + e.getMessage()); @@ -189,10 +192,12 @@ private void setReadyButton() { } private void setAddFavoriteLocationsClickListener() { - Intent intent = new Intent(this, MainActivity.class); + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fmiweather://search")); Button addFavoriteLocationsButton = findViewById(R.id.addFavoriteLocationsButton); // on click send the intent to open the app main activity - addFavoriteLocationsButton.setOnClickListener(v -> startActivity(intent)); + addFavoriteLocationsButton.setOnClickListener(v -> { + startActivity(intent); + }); } public void onRequestPermissionsResult(int requestCode, diff --git a/src/navigators/TabNavigator.tsx b/src/navigators/TabNavigator.tsx index 175beef0..21c8b033 100644 --- a/src/navigators/TabNavigator.tsx +++ b/src/navigators/TabNavigator.tsx @@ -253,6 +253,7 @@ const Navigator: React.FC = ({ const SearchScreenOptions = { ...CommonHeaderOptions, + path: 'search', headerBackTitleVisible: false, headerTitle: t('navigation:search'), headerRight: () => ( @@ -430,6 +431,19 @@ const Navigator: React.FC = ({ ); } + const linking = { + prefixes: ['fmiweather://'], + config: { + screens: { + Weather: { + screens: { + Search: 'search', + }, + }, + }, + }, + }; + return ( <> = ({ /> + theme={useDarkTheme ? darkTheme : lightTheme} + /* + // @ts-ignore */ + linking={linking}> Date: Fri, 3 Jan 2025 14:49:40 +0200 Subject: [PATCH 2/2] issue-703: Small code style fix --- .../fi/fmi/mobileweather/BaseWidgetConfigurationActivity.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/android/app/src/main/java/fi/fmi/mobileweather/BaseWidgetConfigurationActivity.java b/android/app/src/main/java/fi/fmi/mobileweather/BaseWidgetConfigurationActivity.java index ac1cef6f..80d150fe 100644 --- a/android/app/src/main/java/fi/fmi/mobileweather/BaseWidgetConfigurationActivity.java +++ b/android/app/src/main/java/fi/fmi/mobileweather/BaseWidgetConfigurationActivity.java @@ -195,9 +195,7 @@ private void setAddFavoriteLocationsClickListener() { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fmiweather://search")); Button addFavoriteLocationsButton = findViewById(R.id.addFavoriteLocationsButton); // on click send the intent to open the app main activity - addFavoriteLocationsButton.setOnClickListener(v -> { - startActivity(intent); - }); + addFavoriteLocationsButton.setOnClickListener(v -> startActivity(intent)); } public void onRequestPermissionsResult(int requestCode,