Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow upload to custom na-ovoce server #275

Merged
merged 5 commits into from
Aug 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
,"49ee98cf1acc59441b01a2b9505cbdee367ff317": "Update Privacy Policy to include Nominatim and ArcGIS World Imagery."
,"c370065a08cf78836e5e052912bdd331d634f143": "Add progress circle when the search is running so users know when it is done."
,"8043699f99a2d8ce7d862f51d49f15ef1b7a360e": "Fix the search of the main map. It would not open the map at the search location but now does."
,"1a81d2208e95ebff35ca2c3ba49d28fd8a45204e": "Add the ability to upload plants to self-hosted servers using the na-ovoce.cz API."
,"13a52d003db6088b7cc445eec5fab04df5935514": "Add a text if the search has no results."
,"607ff6a9c8c6d841ba407c15911e8ef4fea4fc42": "Fix bug: The search order of the saved results is kept and not reversed."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
public class SettingsActivity extends MundraubBaseActivity {

private static BackgroundDownloadTask mapDownload = null;
private static final String NA_OVOCE_GITHUB_URL = "https://github.com/jsmesami/naovoce";

private ProgressBar updateProgress;
final Handler handler = new Handler();
Expand Down Expand Up @@ -231,7 +232,27 @@ public void onClick(View v) {
});
updateProgressMap = (ProgressBar) findViewById(R.id.update_progress_map);
updateMapOfflineButtons();
EditText customNaOvoceDomain = (EditText) findViewById(R.id.my_na_ovoce_server_domain);
customNaOvoceDomain.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
String url = s.toString();
Settings.setCustomNaOvoceHost(url.isEmpty() ? Settings.DEFAULT_CUSTOM_NA_OVOCE_DOMAIN : url);
}
});
customNaOvoceDomain.setHint(Settings.DEFAULT_CUSTOM_NA_OVOCE_DOMAIN);

Button setupNaOvoce = (Button) findViewById(R.id.button_setup_na_ovoce);
setupNaOvoce.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openURLInBrowser(NA_OVOCE_GITHUB_URL);
}
});
}

private void buttonStartMapDownloadClicked(){
Expand Down Expand Up @@ -410,7 +431,8 @@ protected void onPause() {
}

private void update() {
apiRadioGroup.check(API.instance().radioButtonId());
API api = API.instance();
apiRadioGroup.check(api.radioButtonId());
apiRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Expand All @@ -422,6 +444,8 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
update();
}
});
View customInputs = findViewById(R.id.custom_na_ovoce_inputs);
customInputs.setVisibility(api.isCustomNaOvoceAPI() ? View.VISIBLE : View.GONE);
synchronizeBooleanSetting(R.id.toggle_secure_connection, new Toggled() {
@Override
public int onToggle(boolean checked) {
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/eu/quelltext/mundraub/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public abstract class API extends AsyncNetworkInteraction implements BackgroundD
private boolean isLoggedIn;

public static API[] all() {
return new API[]{DUMMY, MUNDRAUB, FRUITMAP, NA_OVOCE};
return new API[]{
DUMMY, MUNDRAUB, FRUITMAP, NA_OVOCE,
new CustomNaOvoceAPI(Settings.getCustomNaOvoceHost())
};
}

public static API instance() {
Expand Down Expand Up @@ -157,5 +160,7 @@ public Set<String> getDownloadUrls() {
public abstract String getPlantUrl(String id);
public abstract int nameResourceId();


public boolean isCustomNaOvoceAPI() {
return false;
}
}
39 changes: 39 additions & 0 deletions app/src/main/java/eu/quelltext/mundraub/api/CustomNaOvoceAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package eu.quelltext.mundraub.api;

import eu.quelltext.mundraub.R;
import eu.quelltext.mundraub.common.Settings;

public class CustomNaOvoceAPI extends NaOvoceAPI {


private final String host;

public CustomNaOvoceAPI(String host) {
this.host = host;
}

@Override
protected String host() {
return host;
}

@Override
public String id() {
return Settings.API_ID_MY_NA_OVOCE;
}

@Override
public int nameResourceId() {
return R.string.login_api_name_my_na_ovoce;
}

@Override
public boolean isCustomNaOvoceAPI() {
return true;
}

@Override
public int radioButtonId() {
return R.id.radioButton_my_na_ovoce;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public int radioButtonId(){
}

public String getPlantUrl(String id) {
return "https://na-ovoce.cz/fruit/detail/" + id + "/";
return host() + "/fruit/detail/" + id + "/";
};

@Override
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/eu/quelltext/mundraub/common/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ public class Settings {

public static final String API_ID_MUNDRAUB = "mundraub";
public static final String API_ID_NA_OVOCE = "na-ovoce";
public static final String API_ID_MY_NA_OVOCE = "my-na-ovoce";
public static final String API_ID_DUMMY = "dummy";
public static final String API_ID_FRUITMAP = "fruitmap";
public static final String API_ID_COMMUNITY = "community"; // only for markers

public static final String TILES_OSM = "osm";
public static final String TILES_SATELLITE = "satellite";
public static final String DEFAULT_CUSTOM_NA_OVOCE_DOMAIN = "http://na-ovoce.cz";

private static final String PLANT_STORAGE_DIRECTORY_NAME = "eu.quelltext.mundraub";
public static final String INVALID_HASH = "0000000000000000000000000000000000000000";
Expand Down Expand Up @@ -139,6 +141,7 @@ public void setChecked(String apiId, boolean checked) {
* https://github.com/niccokunzmann/mundraub-android/commit/1d8bf40aa68d71cd35eb65e0e25986f6a8a1913e#diff-6cf4fcc1ccb27f70ca10a1b54612d568
*/
private static String useAPIId = API_ID_MUNDRAUB;
private static String customNaOvoceHost = DEFAULT_CUSTOM_NA_OVOCE_DOMAIN;
private static boolean useInsecureConnections = false;
private static boolean useCacheForPlants = true;
private static File persistentPathForPlants = new File(Environment.getExternalStorageDirectory(), PLANT_STORAGE_DIRECTORY_NAME);
Expand Down Expand Up @@ -181,6 +184,7 @@ public static void print() {
log.d("Permissions.CAN_ASK_FOR_PERMISSIONS", Permissions.CAN_ASK_FOR_PERMISSIONS);
log.d("useInsecureConnections", useInsecureConnections);
log.d("useAPIId", useAPIId);
log.d("customNaOvoceHost", customNaOvoceHost);
log.d("useCacheForPlants", useCacheForPlants);
log.d("useErrorReport", useErrorReport);
log.d("useOfflineMapAPI", useOfflineMapAPI);
Expand Down Expand Up @@ -213,6 +217,7 @@ private static void load() {
useOfflineMapAPI = preferences.getBoolean("useOfflineMapAPI", useOfflineMapAPI);
debugMundraubMapAPI = preferences.getBoolean("debugMundraubMapAPI", debugMundraubMapAPI);
vibrateWhenPlantIsInRange = preferences.getBoolean("vibrateWhenPlantIsInRange", vibrateWhenPlantIsInRange);
customNaOvoceHost = preferences.getString("customNaOvoceHost", customNaOvoceHost);
useFruitRadarNotifications = preferences.getBoolean("useFruitRadarNotifications", useFruitRadarNotifications);
maximumDisplayedMarkers = preferences.getInt("maximumDisplayedMarkers", maximumDisplayedMarkers);
radarPlantRangeMeters = preferences.getInt("radarPlantRangeMeters", radarPlantRangeMeters);
Expand Down Expand Up @@ -248,6 +253,7 @@ private static int commit() {
editor.putBoolean("useOfflineMapAPI", useOfflineMapAPI);
editor.putBoolean("debugMundraubMapAPI", debugMundraubMapAPI);
editor.putBoolean("vibrateWhenPlantIsInRange", vibrateWhenPlantIsInRange);
editor.putString("customNaOvoceHost", customNaOvoceHost);
editor.putBoolean("useFruitRadarNotifications", useFruitRadarNotifications);
editor.putInt("maximumDisplayedMarkers", maximumDisplayedMarkers);
editor.putInt("radarPlantRangeMeters", radarPlantRangeMeters);
Expand Down Expand Up @@ -366,6 +372,15 @@ public static int vibrateWhenPlantIsInRange(boolean isChecked) {
return commit();
}

public static String getCustomNaOvoceHost() {
return customNaOvoceHost;
}

public static int setCustomNaOvoceHost(String customNaOvoceHost) {
Settings.customNaOvoceHost = customNaOvoceHost;
return commit();
}

public static boolean useCacheForPlants() {
return useCacheForPlants;
}
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,38 @@
android:layout_weight="1"
android:text="@string/settings_use_na_ovoce" />

<RadioButton
android:id="@+id/radioButton_my_na_ovoce"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/settings_use_my_na_ovoce" />

<LinearLayout
android:id="@+id/custom_na_ovoce_inputs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/text_margin"
android:layout_marginRight="@dimen/text_margin"
android:layout_weight="1"
android:orientation="horizontal">

<EditText
android:id="@+id/my_na_ovoce_server_domain"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textUri" />

<Button
android:id="@+id/button_setup_na_ovoce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/settings_setup_na_ovoce" />
</LinearLayout>

<RadioButton
android:id="@+id/radioButton_fruitmap"
android:layout_width="match_parent"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@
<string name="login_api_name_mundraub">Mundraub.org</string>
<!-- Login: API name for na ovoce -->
<string name="login_api_name_na_ovoce">Na-Ovoce.cz</string>
<!-- Login: API name for a na-ovoce server running under an own domain -->
<string name="login_api_name_my_na_ovoce">Custom Na-Ovoce Server</string>
<!-- Login: API name for the local test API for development -->
<string name="login_api_name_dummy">Local Dummy API</string>
<!-- Login: API name for fruit map -->
Expand Down Expand Up @@ -412,6 +414,8 @@
<!-- settings: API choice -->
<string name="settings_use_na_ovoce">If this is enabled, this app publishes the plants to Na-Ovoce.cz.</string>
<!-- settings: API choice -->
<string name="settings_use_my_na_ovoce">If this is enabled, this app publishes the plants to a self-hosted Na-Ovoce server.</string>
<!-- settings: API choice -->
<string name="settings_use_fruitmap">If this is enabled, this app publishes the plants to FruitMap.org.</string>
<!-- settings: API choice -->
<string name="settings_use_dummy">If this is enabled, this app does not publish the plants but instead simulates a local API for testing.</string>
Expand Down Expand Up @@ -535,6 +539,8 @@
<string name="settings_success_download_map">All selected parts of the map have been downloaded and are now available offline.</string>
<!-- settings: max number of displayed markers on map : text -->
<string name="settings_max_num_of_markers" formatted="false">Maximum of <xliff:g example="100" id="maxMarkers">%1$d</xliff:g> markers will be displayed on map.</string>
<!-- settings: when you choose a custom na-ovoce server as a target for upload, you can click this button to reach the source code of na-ovoce.cz -->
<string name="settings_setup_na_ovoce">Setup</string>

<!-- ============== Community Codex ============== -->
<!-- https://mundraub.org/mundraeuber-regeln -->
Expand Down