Skip to content

Commit

Permalink
Merge pull request #747 from fmidev/feature/703-search-screen-url-han…
Browse files Browse the repository at this point in the history
…dler

issue-703: Added fmiweather://search url handler
  • Loading branch information
geosaaga authored Jan 8, 2025
2 parents 6425efe + cea0c41 commit 119c52c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
11 changes: 10 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="fmiweather" />
</intent-filter>

</activity>

<receiver android:name=".SmallForecastWidgetProvider" android:label="@string/small_widget" android:exported="false">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -100,6 +97,8 @@ public void onResume(){
} else {
batteryOptimizationWarning.setVisibility(GONE);
}

setLocationFavoritesButtons();
}

public static boolean isPowerSavingEnabled(Context context) {
Expand Down Expand Up @@ -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());
Expand All @@ -189,7 +192,7 @@ 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));
Expand Down
19 changes: 18 additions & 1 deletion src/navigators/TabNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ const Navigator: React.FC<Props> = ({

const SearchScreenOptions = {
...CommonHeaderOptions,
path: 'search',
headerBackTitleVisible: false,
headerTitle: t('navigation:search'),
headerRight: () => (
Expand Down Expand Up @@ -430,6 +431,19 @@ const Navigator: React.FC<Props> = ({
);
}

const linking = {
prefixes: ['fmiweather://'],
config: {
screens: {
Weather: {
screens: {
Search: 'search',
},
},
},
},
};

return (
<>
<StatusBar
Expand All @@ -438,7 +452,10 @@ const Navigator: React.FC<Props> = ({
/>
<NavigationContainer
onStateChange={navigationTabChanged}
theme={useDarkTheme ? darkTheme : lightTheme}>
theme={useDarkTheme ? darkTheme : lightTheme}
/*
// @ts-ignore */
linking={linking}>
<Tab.Navigator
initialRouteName={initialTab}
screenOptions={{
Expand Down

0 comments on commit 119c52c

Please sign in to comment.