2013-12-20 19:25:49 +00:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.LayoutInflater;
|
2014-10-07 20:14:27 +00:00
|
|
|
import android.view.MotionEvent;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2014-05-24 22:47:05 +00:00
|
|
|
import android.widget.AbsListView;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.BaseAdapter;
|
2014-06-03 23:31:48 +00:00
|
|
|
import android.widget.EditText;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2013-12-20 19:25:49 +00:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.LocaleController;
|
2013-12-20 19:25:49 +00:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.Utilities;
|
2014-06-20 00:18:13 +00:00
|
|
|
import org.telegram.ui.Adapters.BaseFragmentAdapter;
|
2014-06-03 23:31:48 +00:00
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
|
|
|
|
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
2013-12-20 19:25:49 +00:00
|
|
|
import org.telegram.ui.Views.PinnedHeaderListView;
|
|
|
|
import org.telegram.ui.Views.SectionedBaseAdapter;
|
2014-10-21 20:35:16 +00:00
|
|
|
import org.telegram.ui.Views.SettingsSectionLayout;
|
2013-12-20 19:25:49 +00:00
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
2014-06-03 23:31:48 +00:00
|
|
|
import java.io.InputStream;
|
2013-12-20 19:25:49 +00:00
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
public class CountrySelectActivity extends BaseFragment {
|
|
|
|
|
|
|
|
public static interface CountrySelectActivityDelegate {
|
|
|
|
public abstract void didSelectCountry(String name);
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
private SectionedBaseAdapter listViewAdapter;
|
|
|
|
private PinnedHeaderListView listView;
|
|
|
|
private boolean searchWas;
|
|
|
|
private boolean searching;
|
|
|
|
private BaseAdapter searchListViewAdapter;
|
2014-03-25 00:25:32 +00:00
|
|
|
private TextView emptyTextView;
|
2013-12-20 19:25:49 +00:00
|
|
|
private HashMap<String, ArrayList<Country>> countries = new HashMap<String, ArrayList<Country>>();
|
|
|
|
private ArrayList<String> sortedCountries = new ArrayList<String>();
|
2014-06-03 23:31:48 +00:00
|
|
|
private CountrySelectActivityDelegate delegate;
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-03-25 00:25:32 +00:00
|
|
|
private Timer searchTimer;
|
2013-12-20 19:25:49 +00:00
|
|
|
public ArrayList<Country> searchResult;
|
|
|
|
|
|
|
|
public static class Country {
|
|
|
|
public String name;
|
|
|
|
public String code;
|
|
|
|
public String shortname;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-03 23:31:48 +00:00
|
|
|
public boolean onFragmentCreate() {
|
2013-12-20 19:25:49 +00:00
|
|
|
try {
|
2014-06-03 23:31:48 +00:00
|
|
|
InputStream stream = ApplicationLoader.applicationContext.getResources().getAssets().open("countries.txt");
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
2013-12-20 19:25:49 +00:00
|
|
|
String line;
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
String[] args = line.split(";");
|
|
|
|
Country c = new Country();
|
|
|
|
c.name = args[2];
|
|
|
|
c.code = args[0];
|
|
|
|
c.shortname = args[1];
|
|
|
|
String n = c.name.substring(0, 1).toUpperCase();
|
|
|
|
ArrayList<Country> arr = countries.get(n);
|
|
|
|
if (arr == null) {
|
|
|
|
arr = new ArrayList<Country>();
|
|
|
|
countries.put(n, arr);
|
|
|
|
sortedCountries.add(n);
|
|
|
|
}
|
|
|
|
arr.add(c);
|
|
|
|
}
|
2014-06-16 12:36:54 +00:00
|
|
|
reader.close();
|
2014-06-03 23:31:48 +00:00
|
|
|
stream.close();
|
2013-12-20 19:25:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
Collections.sort(sortedCountries, new Comparator<String>() {
|
|
|
|
@Override
|
|
|
|
public int compare(String lhs, String rhs) {
|
|
|
|
return lhs.compareTo(rhs);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for (ArrayList<Country> arr : countries.values()) {
|
|
|
|
Collections.sort(arr, new Comparator<Country>() {
|
|
|
|
@Override
|
|
|
|
public int compare(Country country, Country country2) {
|
|
|
|
return country.name.compareTo(country2.name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
return super.onFragmentCreate();
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
|
|
|
if (fragmentView == null) {
|
2014-06-12 01:13:15 +00:00
|
|
|
actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
|
2014-06-12 15:53:20 +00:00
|
|
|
actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setTitle(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
});
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
ActionBarMenu menu = actionBarLayer.createMenu();
|
|
|
|
menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
|
|
|
|
@Override
|
|
|
|
public void onSearchExpand() {
|
|
|
|
searching = true;
|
2014-05-24 22:47:05 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
public void onSearchCollapse() {
|
|
|
|
search(null);
|
|
|
|
searching = false;
|
|
|
|
searchWas = false;
|
|
|
|
ViewGroup group = (ViewGroup) listView.getParent();
|
|
|
|
listView.setAdapter(listViewAdapter);
|
|
|
|
if (!LocaleController.isRTL) {
|
2014-07-02 22:39:05 +00:00
|
|
|
listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(30), listView.getPaddingBottom());
|
2014-06-03 23:31:48 +00:00
|
|
|
} else {
|
2014-07-02 22:39:05 +00:00
|
|
|
listView.setPadding(AndroidUtilities.dp(30), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom());
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
listView.setFastScrollAlwaysVisible(true);
|
|
|
|
}
|
|
|
|
listView.setFastScrollEnabled(true);
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
emptyTextView.setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
|
|
|
|
}
|
2014-04-04 17:58:33 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
public void onTextChanged(EditText editText) {
|
|
|
|
String text = editText.getText().toString();
|
|
|
|
search(text);
|
|
|
|
if (text.length() != 0) {
|
|
|
|
searchWas = true;
|
|
|
|
if (listView != null) {
|
2014-07-02 22:39:05 +00:00
|
|
|
listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom());
|
2014-06-03 23:31:48 +00:00
|
|
|
listView.setAdapter(searchListViewAdapter);
|
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
listView.setFastScrollAlwaysVisible(false);
|
|
|
|
}
|
|
|
|
listView.setFastScrollEnabled(false);
|
|
|
|
listView.setVerticalScrollBarEnabled(true);
|
|
|
|
}
|
|
|
|
if (emptyTextView != null) {
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
});
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
searching = false;
|
|
|
|
searchWas = false;
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
fragmentView = inflater.inflate(R.layout.country_select_layout, container, false);
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
emptyTextView = (TextView)fragmentView.findViewById(R.id.searchEmptyView);
|
|
|
|
searchListViewAdapter = new SearchAdapter(getParentActivity());
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
listView = (PinnedHeaderListView)fragmentView.findViewById(R.id.listView);
|
|
|
|
listView.setEmptyView(emptyTextView);
|
2014-10-07 20:14:27 +00:00
|
|
|
emptyTextView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-06-03 23:31:48 +00:00
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
|
|
|
|
listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity()));
|
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
|
if (searching && searchWas) {
|
|
|
|
if (i < searchResult.size()) {
|
|
|
|
Country c = searchResult.get(i);
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.didSelectCountry(c.name);
|
|
|
|
}
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int section = listViewAdapter.getSectionForPosition(i);
|
|
|
|
int row = listViewAdapter.getPositionInSectionForPosition(i);
|
|
|
|
if (section < sortedCountries.size()) {
|
|
|
|
String n = sortedCountries.get(section);
|
|
|
|
ArrayList<Country> arr = countries.get(n);
|
|
|
|
if (row < arr.size()) {
|
|
|
|
Country c = arr.get(row);
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.didSelectCountry(c.name);
|
|
|
|
}
|
|
|
|
finishFragment();
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
});
|
2013-12-20 19:25:49 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(AbsListView absListView, int i) {
|
|
|
|
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
|
2014-07-02 22:39:05 +00:00
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
|
|
|
return fragmentView;
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 16:00:42 +00:00
|
|
|
super.onResume();
|
2014-06-03 23:31:48 +00:00
|
|
|
if (listViewAdapter != null) {
|
|
|
|
listViewAdapter.notifyDataSetChanged();
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 00:25:32 +00:00
|
|
|
public void search(final String query) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (query == null) {
|
|
|
|
searchResult = null;
|
|
|
|
} else {
|
|
|
|
try {
|
2014-03-25 00:25:32 +00:00
|
|
|
if (searchTimer != null) {
|
|
|
|
searchTimer.cancel();
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-03-25 00:25:32 +00:00
|
|
|
searchTimer = new Timer();
|
|
|
|
searchTimer.schedule(new TimerTask() {
|
2013-12-20 19:25:49 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
2014-03-25 00:25:32 +00:00
|
|
|
searchTimer.cancel();
|
|
|
|
searchTimer = null;
|
2013-12-20 19:25:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
processSearch(query);
|
|
|
|
}
|
|
|
|
}, 100, 300);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processSearch(final String query) {
|
2014-06-13 10:42:21 +00:00
|
|
|
Utilities.searchQueue.postRunnable(new Runnable() {
|
2013-12-20 19:25:49 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
String q = query.trim().toLowerCase();
|
|
|
|
if (q.length() == 0) {
|
|
|
|
updateSearchResults(new ArrayList<Country>());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
ArrayList<Country> resultArray = new ArrayList<Country>();
|
|
|
|
|
|
|
|
String n = query.substring(0, 1);
|
|
|
|
ArrayList<Country> arr = countries.get(n.toUpperCase());
|
|
|
|
if (arr != null) {
|
|
|
|
for (Country c : arr) {
|
|
|
|
if (c.name.toLowerCase().startsWith(query)) {
|
|
|
|
resultArray.add(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSearchResults(resultArray);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
public void setCountrySelectActivityDelegate(CountrySelectActivityDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
private void updateSearchResults(final ArrayList<Country> arrCounties) {
|
2014-08-22 14:24:33 +00:00
|
|
|
AndroidUtilities.RunOnUIThread(new Runnable() {
|
2013-12-20 19:25:49 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
searchResult = arrCounties;
|
|
|
|
searchListViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-20 00:18:13 +00:00
|
|
|
private class SearchAdapter extends BaseFragmentAdapter {
|
2013-12-20 19:25:49 +00:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public SearchAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areAllItemsEnabled() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(int i) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
if (searchResult == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return searchResult.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int i) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasStableIds() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.country_row_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
|
|
|
|
TextView detailTextView = (TextView)view.findViewById(R.id.settings_row_text_detail);
|
|
|
|
View divider = view.findViewById(R.id.settings_row_divider);
|
|
|
|
|
|
|
|
Country c = searchResult.get(i);
|
|
|
|
textView.setText(c.name);
|
|
|
|
detailTextView.setText("+" + c.code);
|
|
|
|
if (i == searchResult.size() - 1) {
|
|
|
|
divider.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
divider.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty() {
|
|
|
|
return searchResult == null || searchResult.size() == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ListAdapter extends SectionedBaseAdapter {
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int section, int position) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int section, int position) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSectionCount() {
|
|
|
|
return sortedCountries.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCountForSection(int section) {
|
|
|
|
String n = sortedCountries.get(section);
|
|
|
|
ArrayList<Country> arr = countries.get(n);
|
|
|
|
return arr.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getItemView(int section, int position, View convertView, ViewGroup parent) {
|
|
|
|
if (convertView == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
convertView = li.inflate(R.layout.country_row_layout, parent, false);
|
|
|
|
}
|
|
|
|
TextView textView = (TextView)convertView.findViewById(R.id.settings_row_text);
|
|
|
|
TextView detailTextView = (TextView)convertView.findViewById(R.id.settings_row_text_detail);
|
|
|
|
View divider = convertView.findViewById(R.id.settings_row_divider);
|
|
|
|
|
|
|
|
String n = sortedCountries.get(section);
|
|
|
|
ArrayList<Country> arr = countries.get(n);
|
|
|
|
Country c = arr.get(position);
|
|
|
|
textView.setText(c.name);
|
|
|
|
detailTextView.setText("+" + c.code);
|
|
|
|
if (position == arr.size() - 1) {
|
|
|
|
divider.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
divider.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return convertView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int section, int position) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewTypeCount() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSectionHeaderViewType(int section) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSectionHeaderViewTypeCount() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
|
|
|
|
if (convertView == null) {
|
2014-10-21 20:35:16 +00:00
|
|
|
convertView = new SettingsSectionLayout(mContext);
|
2013-12-20 19:25:49 +00:00
|
|
|
convertView.setBackgroundColor(0xfffafafa);
|
|
|
|
}
|
2014-10-21 20:35:16 +00:00
|
|
|
((SettingsSectionLayout) convertView).setText(sortedCountries.get(section).toUpperCase());
|
2013-12-20 19:25:49 +00:00
|
|
|
return convertView;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|