Skip to content

Commit

Permalink
Display error messages when no data
Browse files Browse the repository at this point in the history
  • Loading branch information
Protino committed Nov 8, 2016
1 parent b5e5328 commit 31bb510
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 577 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
compile 'com.android.support:support-annotations:23.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private void openPreferredLocationInMap() {
}
}


@Override
protected void onResume() {
super.onResume();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.calgen.prodek.sunshine_v2.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
Expand All @@ -9,11 +10,14 @@
import android.view.MenuItem;

import com.calgen.prodek.sunshine_v2.R;
import com.calgen.prodek.sunshine_v2.Utility;
import com.calgen.prodek.sunshine_v2.data.WeatherContract;
import com.calgen.prodek.sunshine_v2.sync.SunshineSyncAdapter;

/**
* Created by Gurupad on 15-Jun-16.
*/
public class SettingsActivity extends AppCompactPreferenceActivity implements Preference.OnPreferenceChangeListener {
public class SettingsActivity extends AppCompactPreferenceActivity implements Preference.OnPreferenceChangeListener, SharedPreferences.OnSharedPreferenceChangeListener {

private static final String TAG = SettingsActivity.class.getSimpleName();

Expand Down Expand Up @@ -61,6 +65,7 @@ private void bindPreferenceSummaryToValue(Preference preference) {
.getString(preference.getKey(), ""));
}


@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
Expand All @@ -75,9 +80,33 @@ public boolean onPreferenceChange(Preference preference, Object value) {
}
} else {
// For other preferences, set the summary to the value's simple string representation.
if (!(preference instanceof CheckBoxPreference))
preference.setSummary(stringValue);
if (!(preference instanceof CheckBoxPreference)) preference.setSummary(stringValue);

}
return true;
}

@Override
protected void onResume() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
sp.registerOnSharedPreferenceChangeListener(this);
super.onResume();
}

@Override
protected void onPause() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
sp.unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(getString(R.string.pref_location_key))) {
Utility.resetLocationStatus(this);
SunshineSyncAdapter.syncImmediately(this);
} else if (key.equals(getString(R.string.pref_temperature_key))) {
getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
}
}
}
Loading

0 comments on commit 31bb510

Please sign in to comment.