Skip to content

Commit

Permalink
preference listens to changes
Browse files Browse the repository at this point in the history
  • Loading branch information
midorikocak committed Oct 18, 2017
1 parent 8331d47 commit a550887
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.widget.ListView;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
Expand Down Expand Up @@ -66,9 +67,12 @@ public CurrencyPreference(Context context, AttributeSet attrs) {

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals("selectedCurrency")){
if (key.equals("selectedCurrency")) {
setSummary(getValue());
}
if (key.equals("selectedCurrencies")) {
setCurrenciesList(preferences.getStringSet("selectedCurrencies", new HashSet<String>()));
}
}

@Override
Expand Down Expand Up @@ -145,15 +149,14 @@ private void search(String text) {
}



public void setCurrenciesList(List<ExtendedCurrency> newCurrencies) {
this.currenciesList.clear();
this.currenciesList.addAll(newCurrencies);
}

public void setCurrenciesList(Set<String> savedCurrencies) {
this.currenciesList.clear();
for(String code : savedCurrencies){
for (String code : savedCurrencies) {
this.currenciesList.add(ExtendedCurrency.getCurrencyByISO(code));
}
}
Expand Down

0 comments on commit a550887

Please sign in to comment.