Skip to content

Commit

Permalink
Merge pull request #2 from barrywe7/cypressFlagAndOptionalDiallingCode
Browse files Browse the repository at this point in the history
A couple of changes
  • Loading branch information
EKami committed Jul 29, 2015
2 parents 001abc6 + 63d2f44 commit bd84689
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/heetch/countrypicker/CountryListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public class CountryListAdapter extends BaseAdapter {
private static final String TAG = CountryListAdapter.class.getSimpleName();
private LayoutInflater inflater;
private List<Country> countries;
private boolean showDialingCode;

public CountryListAdapter(Context context, List<Country> countries) {
public CountryListAdapter(Context context, List<Country> countries, boolean showDialingCode) {
mContext = context;
this.countries = countries;
this.showDialingCode = showDialingCode;
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

Expand All @@ -50,7 +52,7 @@ public View getView(int position, View convertView, ViewGroup parent) {

if (convertView == null) {
item = new Item();
itemView = inflater.inflate(R.layout.item_country, null);
itemView = inflater.inflate(R.layout.item_country, parent, false);
item.setIcon((ImageView) itemView.findViewById(R.id.icon));
item.setName((TextView) itemView.findViewById(R.id.name));
itemView.setTag(item);
Expand All @@ -59,8 +61,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
}

item.getName().setText(new Locale(mContext.getResources().getConfiguration().locale.getLanguage(),
country.getIsoCode()).getDisplayCountry() +
" (+" + country.getDialingCode() + ")");
country.getIsoCode()).getDisplayCountry() + (showDialingCode ?
" (+" + country.getDialingCode() + ")" : ""));

// Load drawable dynamically from country code
String drawableName = country.getIsoCode().toLowerCase(Locale.ENGLISH) + "_flag";
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/heetch/countrypicker/CountryPickerDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public class CountryPickerDialog extends AppCompatDialog {
private CountryPickerCallbacks callbacks;
private ListView listview;
private String headingCountryCode;
private boolean showDialingCode;

public CountryPickerDialog(Context context, CountryPickerCallbacks callbacks) {
this(context, callbacks, null, true);
}

public CountryPickerDialog(Context context, CountryPickerCallbacks callbacks, @Nullable String headingCountryCode) {
this(context, callbacks, headingCountryCode, true);
}

/**
* You can set the heading country in headingCountryCode to show
Expand All @@ -34,10 +43,11 @@ public class CountryPickerDialog extends AppCompatDialog {
* @param headingCountryCode
*/
public CountryPickerDialog(Context context, CountryPickerCallbacks callbacks,
@Nullable String headingCountryCode) {
@Nullable String headingCountryCode, boolean showDialingCode) {
super(context);
this.callbacks = callbacks;
this.headingCountryCode = headingCountryCode;
this.showDialingCode = showDialingCode;
countries = Utils.parseCountries(Utils.getCountriesJSON(this.getContext()));
Collections.sort(countries, new Comparator<Country>() {
@Override
Expand All @@ -57,7 +67,7 @@ protected void onCreate(Bundle savedInstanceState) {
ViewCompat.setElevation(getWindow().getDecorView(), 3);
listview = (ListView) findViewById(R.id.country_picker_listview);

CountryListAdapter adapter = new CountryListAdapter(this.getContext(), countries);
CountryListAdapter adapter = new CountryListAdapter(this.getContext(), countries, showDialingCode);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
Expand Down
Binary file modified src/main/res/mipmap-hdpi/cy_flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/mipmap-mdpi/cy_flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/mipmap-xhdpi/cy_flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/mipmap-xxhdpi/cy_flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/mipmap-xxxhdpi/cy_flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bd84689

Please sign in to comment.