mirror of
https://github.com/woheller69/solxpect.git
synced 2025-12-16 09:20:12 +01:00
Add option to run own servers for APIs
This commit is contained in:
parent
5b43313882
commit
836376d7dd
8 changed files with 49 additions and 19 deletions
|
|
@ -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/\""
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ©<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}).addTo(map);
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -108,6 +108,6 @@
|
|||
<string name="itemRemoved">ENTFERNT:\u0020\u0020%s</string>
|
||||
<string name="undo">WIEDERHERSTELLEN</string>
|
||||
<string name="edit_location_hint_albedo">Albedo [0..1]</string>
|
||||
|
||||
|
||||
<string name="settings_server_urls">Server URLs</string>
|
||||
<string name="settings_server_summary">Nur ändern, wenn Sie Ihre eigenen Server betreiben wollen</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -107,4 +107,6 @@
|
|||
<string name="itemRemoved">\u0020\u0020%s KALDIRILDI</string>
|
||||
<string name="undo">GERİ AL</string>
|
||||
<string name="edit_location_hint_albedo">Albedo [0..1]</string>
|
||||
<string name="settings_server_urls">Sunucu URL\'leri</string>
|
||||
<string name="settings_server_summary">Yalnızca kendi sunucularınızı barındırmak istiyorsanız değiştirin</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -111,4 +111,7 @@
|
|||
<string name="undo">UNDO</string>
|
||||
<string name="edit_location_hint_albedo">Albedo [0..1]</string>
|
||||
<string name="github" translatable="false">GitHub</string>
|
||||
<string name="settings_server_urls">Server URLs</string>
|
||||
<string name="settings_server_summary">Only change if you want to host your own servers</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -51,4 +51,22 @@
|
|||
android:title="@string/settings_update_interval" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/settings_server_urls" android:summary="@string/settings_server_summary">
|
||||
<EditTextPreference
|
||||
android:title="Open-Meteo API"
|
||||
android:key="pref_OM_URL"
|
||||
android:defaultValue="https://api.open-meteo.com/v1/"
|
||||
/>
|
||||
<EditTextPreference
|
||||
android:title="OpenStreetMap API"
|
||||
android:key="pref_OsmTiles_URL"
|
||||
android:defaultValue="https://tile.openstreetmap.org/"
|
||||
/>
|
||||
<EditTextPreference
|
||||
android:title="Open-Meteo Geocoding API"
|
||||
android:key="pref_OMGEO_URL"
|
||||
android:defaultValue="https://geocoding-api.open-meteo.com/"
|
||||
/>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue