diff --git a/app/build.gradle b/app/build.gradle
index fb0e7c5..c0f1f0c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -12,6 +12,8 @@ android {
versionName "2.1"
buildConfigField "String", "BASE_URL", "\"https://api.open-meteo.com/v1/\""
+ buildConfigField "String", "TILES_URL","\"https://tile.openstreetmap.org/\""
+ buildConfigField "String", "GEOCODING_URL","\"https://geocoding-api.open-meteo.com/\""
buildConfigField "String", "GITHUB_URL","\"https://github.com/woheller69/solxpect/\""
}
diff --git a/app/src/main/assets/map.html b/app/src/main/assets/map.html
index 37d7ee1..e694b29 100644
--- a/app/src/main/assets/map.html
+++ b/app/src/main/assets/map.html
@@ -34,7 +34,7 @@ var map = L.map('mapid', {
}).setView([getUrlParameter('lat'), getUrlParameter('lon')], 10); //zoom factor 10
- L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
+ L.tileLayer(getUrlParameter('tiles')+'{z}/{x}/{y}.png', {
attribution: 'Map data ©OpenStreetMap contributors'
}).addTo(map);
diff --git a/app/src/main/java/org/woheller69/weather/dialogs/AddLocationDialogOmGeocodingAPI.java b/app/src/main/java/org/woheller69/weather/dialogs/AddLocationDialogOmGeocodingAPI.java
index b51dd69..0b29c8c 100644
--- a/app/src/main/java/org/woheller69/weather/dialogs/AddLocationDialogOmGeocodingAPI.java
+++ b/app/src/main/java/org/woheller69/weather/dialogs/AddLocationDialogOmGeocodingAPI.java
@@ -6,6 +6,7 @@ import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
@@ -27,6 +28,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.os.ConfigurationCompat;
import androidx.fragment.app.DialogFragment;
+import androidx.preference.PreferenceManager;
import com.android.volley.Response;
import com.android.volley.VolleyError;
@@ -62,13 +64,14 @@ public class AddLocationDialogOmGeocodingAPI extends DialogFragment {
private static final long AUTO_COMPLETE_DELAY = 300;
private Handler handler;
private AutoSuggestAdapter autoSuggestAdapter;
- String url="https://geocoding-api.open-meteo.com/v1/search?name=";
- String lang="default";
+ String urlSuffix="v1/search?name=";
+ String url="";
+ String lang="en";
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
- if (context instanceof Activity){
+ if (context instanceof Activity){
this.activity=(Activity) context;
}
}
@@ -83,20 +86,22 @@ public class AddLocationDialogOmGeocodingAPI extends DialogFragment {
@SuppressLint("SetJavaScriptEnabled")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
-
+ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity);
+ url = sp.getString("pref_OMGEO_URL",BuildConfig.GEOCODING_URL);
+ url = url + urlSuffix;
Locale locale = ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).get(0);
- lang=locale.getLanguage();
+ if (locale != null) lang=locale.getLanguage();
- LayoutInflater inflater = getActivity().getLayoutInflater();
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ LayoutInflater inflater = activity.getLayoutInflater();
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
View view = inflater.inflate(R.layout.dialog_add_location, null);
rootView = view;
builder.setView(view);
- builder.setTitle(getActivity().getString(R.string.dialog_add_label));
+ builder.setTitle(activity.getString(R.string.dialog_add_label));
- this.database = SQLiteHelper.getInstance(getActivity());
+ this.database = SQLiteHelper.getInstance(activity);
final WebView webview= rootView.findViewById(R.id.webViewAddLocation);
@@ -121,10 +126,11 @@ public class AddLocationDialogOmGeocodingAPI extends DialogFragment {
int position, long id) {
selectedCity=autoSuggestAdapter.getObject(position);
//Hide keyboard to have more space
- final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(rootView.getWindowToken(), 0);
//Show city on map
- webview.loadUrl("file:///android_asset/map.html?lat=" + selectedCity.getLatitude() + "&lon=" + selectedCity.getLongitude());
+ String osmTiles = sp.getString("pref_OsmTiles_URL", BuildConfig.TILES_URL);
+ webview.loadUrl("file:///android_asset/map.html?lat=" + selectedCity.getLatitude() + "&lon=" + selectedCity.getLongitude() + "&tiles=" + osmTiles);
}
});
@@ -165,7 +171,7 @@ public class AddLocationDialogOmGeocodingAPI extends DialogFragment {
}
});
- builder.setPositiveButton(getActivity().getString(R.string.dialog_add_add_button), new DialogInterface.OnClickListener() {
+ builder.setPositiveButton(activity.getString(R.string.dialog_add_add_button), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@@ -173,7 +179,7 @@ public class AddLocationDialogOmGeocodingAPI extends DialogFragment {
}
});
- builder.setNegativeButton(getActivity().getString(android.R.string.cancel), null);
+ builder.setNegativeButton(activity.getString(android.R.string.cancel), null);
return builder.create();
diff --git a/app/src/main/java/org/woheller69/weather/weather_api/open_meteo/OMHttpRequest.java b/app/src/main/java/org/woheller69/weather/weather_api/open_meteo/OMHttpRequest.java
index c1d4678..c72ba4b 100644
--- a/app/src/main/java/org/woheller69/weather/weather_api/open_meteo/OMHttpRequest.java
+++ b/app/src/main/java/org/woheller69/weather/weather_api/open_meteo/OMHttpRequest.java
@@ -19,13 +19,12 @@ import java.util.List;
public class OMHttpRequest {
protected String getUrlForQueryingOMweatherAPI(Context context, float lat, float lon) {
- AppPreferencesManager prefManager =
- new AppPreferencesManager(PreferenceManager.getDefaultSharedPreferences(context));
+
SharedPreferences sharedPreferences=PreferenceManager.getDefaultSharedPreferences(context);
return String.format(
"%sforecast?latitude=%s&longitude=%s&forecast_days=%s&hourly=temperature_2m,diffuse_radiation,direct_normal_irradiance,shortwave_radiation,weathercode&daily=weathercode,sunrise,sunset,&timeformat=unixtime&timezone=auto",
- BuildConfig.BASE_URL,
+ sharedPreferences.getString("pref_OM_URL", BuildConfig.BASE_URL),
lat,
lon,
sharedPreferences.getInt("pref_number_days",7)
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index a3e43e4..97aedb6 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -108,6 +108,6 @@
ENTFERNT:\u0020\u0020%s
WIEDERHERSTELLEN
Albedo [0..1]
-
-
+ Server URLs
+ Nur ändern, wenn Sie Ihre eigenen Server betreiben wollen
diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml
index 0826c1d..8b7db3a 100644
--- a/app/src/main/res/values-tr/strings.xml
+++ b/app/src/main/res/values-tr/strings.xml
@@ -107,4 +107,6 @@
\u0020\u0020%s KALDIRILDI
GERİ AL
Albedo [0..1]
+ Sunucu URL\'leri
+ Yalnızca kendi sunucularınızı barındırmak istiyorsanız değiştirin
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 105cb2e..39fe573 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -111,4 +111,7 @@
UNDO
Albedo [0..1]
GitHub
+ Server URLs
+ Only change if you want to host your own servers
+
diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml
index f9839c8..84bfc28 100644
--- a/app/src/main/res/xml/pref_general.xml
+++ b/app/src/main/res/xml/pref_general.xml
@@ -51,4 +51,22 @@
android:title="@string/settings_update_interval" />
+
+
+
+
+
+