Skip to content
Snippets Groups Projects
Commit cfe2d160 authored by Julian Catoni's avatar Julian Catoni
Browse files

Show current ip in pref summary, fix crash when ip in wrong format

parent 68517f0e
No related branches found
No related tags found
No related merge requests found
......@@ -231,6 +231,7 @@ public class PreferencesActivity extends AppCompatActivity {
final Preference remoteConnPref = findPreference(Constants.SUBSCREEN_REMOTE_CONNECTION);
final Preference themePref = findPreference(Constants.PREFERENCE_THEME);
final Preference clearCachePref = findPreference(Constants.PREFERENCE_CLEAR_CACHE);
final Preference openLichtUrl = findPreference(Constants.PREFERENCE_OPENLICHT_URL);
final Preference clearDefaultSitemapPref =
findPreference(Constants.PREFERENCE_CLEAR_DEFAULT_SITEMAP);
final Preference ringtonePref = findPreference(Constants.PREFERENCE_TONE);
......@@ -246,7 +247,14 @@ public class PreferencesActivity extends AppCompatActivity {
clearDefaultSitemapPref.setSummary(getString(
R.string.settings_current_default_sitemap, currentDefaultSitemapLabel));
}
openLichtUrl.setOnPreferenceChangeListener((preference, newValue) -> {
if (!newValue.toString().isEmpty()) {
preference.setSummary(newValue.toString());
return true;
}
return false;
});
updateOpenLichtUrlPreference(openLichtUrl);
updateConnectionSummary(Constants.SUBSCREEN_LOCAL_CONNECTION,
Constants.PREFERENCE_LOCAL_URL, Constants.PREFERENCE_LOCAL_USERNAME,
Constants.PREFERENCE_LOCAL_PASSWORD);
......@@ -390,6 +398,15 @@ public class PreferencesActivity extends AppCompatActivity {
? R.drawable.ic_smartphone_grey_24dp : R.drawable.ic_vibration_grey_24dp);
}
private boolean updateOpenLichtUrlPreference(Preference pref) {
String currentUrl = getPreferenceString(Constants.PREFERENCE_OPENLICHT_URL, "");
if (!currentUrl.isEmpty()) {
pref.setSummary(currentUrl);
return true;
}
return false;
}
private void updateConnectionSummary(String subscreenPrefKey, String urlPrefKey,
String userPrefKey, String passwordPrefKey) {
Preference pref = findPreference(subscreenPrefKey);
......
......@@ -75,8 +75,8 @@ public class RecognitionsActivity extends AppCompatActivity implements WidgetAda
progressDialog.show();
// Interface for the RetrofitInstance
try {
GetDataService service = RetrofitClientInstance.getRetrofitInstance(this).create(GetDataService.class);
Call<List<Recognition>> call = service.getAllRecognitions();
call.enqueue(new Callback<List<Recognition>>() {
......@@ -95,6 +95,12 @@ public class RecognitionsActivity extends AppCompatActivity implements WidgetAda
Toast.makeText(RecognitionsActivity.this, "Error loading Recognition. Please check your network connection.", Toast.LENGTH_SHORT).show();
}
});
} catch (IllegalArgumentException e) {
progressDialog.dismiss();
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
}
......
......@@ -1000,7 +1000,7 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder
private static void showSnackbar(View v, int delay) {
mSnackbarHandler.removeCallbacksAndMessages(null);
final View currentView = v.getRootView().findFocus();
final View currentView = v.getRootView();
mSnackbarHandler.postDelayed(() -> {
Snackbar snackbar = Snackbar.make(currentView, "Manuelle Änderung als neuen Standardwert setzen?", Snackbar.LENGTH_LONG);
snackbar.setAction("Setze als\nStandard", v1 -> {
......@@ -1047,7 +1047,7 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder
if (v.getTag() instanceof String) {
final String cmd = (String) v.getTag();
Util.sendItemCommand(mConnection.getAsyncHttpClient(), mBoundItem, cmd);
WidgetAdapter.showSnackbar(v, DELAY_SNACKBAR);
WidgetAdapter.showSnackbar(itemView, DELAY_SNACKBAR);
} else {
showColorPickerDialog();
}
......
......@@ -20,7 +20,7 @@ public class RetrofitClientInstance {
public static Retrofit getRetrofitInstance(Activity activity) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
String url = preferences.getString(Constants.PREFERENCE_OPENLICHT_URL, "");
if (retrofit == null) {
if (retrofit == null || !retrofit.baseUrl().toString().equals(url)) {
retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment