Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da14d098 authored by Annie Chin's avatar Annie Chin Committed by Android (Google) Code Review
Browse files

Merge "Add provisions for translators to manually specify city name indeces."...

Merge "Add provisions for translators to manually specify city name indeces." into ub-deskclock-business
parents db840e4a 454a73df
Loading
Loading
Loading
Loading
+324 −301

File changed.

Preview size limit exceeded, changes collapsed.

+17 −1
Original line number Diff line number Diff line
@@ -632,7 +632,23 @@ public class Utils {
        }
        CityObj[] cities = new CityObj[minLength];
        for (int i = 0; i < cities.length; i++) {
            cities[i] = new CityObj(cityNames[i], timezones[i], ids[i]);
            // Default to using the first character of the city name as the index unless one is
            // specified. The indicator for a specified index is the addition of character(s)
            // before the "=" separator.
            final String parseString = cityNames[i];
            final int separatorIndex = parseString.indexOf("=");
            final String index;
            final String cityName;
            if (separatorIndex == 0) {
                // Default to using second character (the first character after the = separator)
                // as the index.
                index = parseString.substring(1, 2);
                cityName = parseString.substring(1, parseString.length());
            } else {
                 index = parseString.substring(0, separatorIndex);
                 cityName = parseString.substring(separatorIndex + 1, parseString.length());
            }
            cities[i] = new CityObj(cityName, timezones[i], ids[i], index);
        }
        return cities;
    }
+9 −10
Original line number Diff line number Diff line
@@ -143,9 +143,9 @@ public class CitiesActivity extends BaseActivity implements OnCheckedChangeListe
                FilterResults results = new FilterResults();
                String modifiedQuery = constraint.toString().trim().toUpperCase();

                ArrayList<CityObj> filteredList = new ArrayList<CityObj>();
                ArrayList<String> sectionHeaders = new ArrayList<String>();
                ArrayList<Integer> sectionPositions = new ArrayList<Integer>();
                ArrayList<CityObj> filteredList = new ArrayList<>();
                ArrayList<String> sectionHeaders = new ArrayList<>();
                ArrayList<Integer> sectionPositions = new ArrayList<>();

                // Update the list first when user using search filter
                final Collection<CityObj> selectedCities = mUserSelectedCities.values();
@@ -156,8 +156,7 @@ public class CitiesActivity extends BaseActivity implements OnCheckedChangeListe
                        sectionHeaders.add("+");
                        sectionPositions.add(0);
                        filteredList.add(new CityObj(mSelectedCitiesHeaderString,
                                mSelectedCitiesHeaderString,
                                null));
                                mSelectedCitiesHeaderString, null, null));
                    }
                    for (CityObj city : mSelectedCities) {
                        city.isHeader = false;
@@ -184,11 +183,11 @@ public class CitiesActivity extends BaseActivity implements OnCheckedChangeListe
                    // If the search query is empty, add section headers.
                    if (TextUtils.isEmpty(modifiedQuery)) {
                        if (!selectedCityIds.contains(city.mCityId)) {
                            // If the list is sorted by name, and the city begins with a letter
                            // different than the previous city's letter, insert a section header.
                            // If the list is sorted by name, and the city has an index
                            // different than the previous city's index, update the section header.
                            if (mSortType == SORT_BY_NAME
                                    && !city.mCityName.substring(0, 1).equals(val)) {
                                val = city.mCityName.substring(0, 1).toUpperCase();
                                    && !city.mCityIndex.equals(val)) {
                                val = city.mCityIndex.toUpperCase();
                                sectionHeaders.add(val);
                                sectionPositions.add(filteredList.size());
                                city.isHeader = true;
@@ -377,7 +376,7 @@ public class CitiesActivity extends BaseActivity implements OnCheckedChangeListe
                if (c.isHeader) {
                    holder.index.setVisibility(View.VISIBLE);
                    if (mSortType == SORT_BY_NAME) {
                        holder.index.setText(c.mCityName.substring(0, 1));
                        holder.index.setText(c.mCityIndex);
                        holder.index.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
                    } else { // SORT_BY_GMT_OFFSET
                        holder.index.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
+10 −4
Original line number Diff line number Diff line
@@ -23,16 +23,19 @@ public class CityObj {
    private static final String CITY_NAME = "city_name_";
    private static final String CITY_TIME_ZONE = "city_tz_";
    private static final String CITY_ID = "city_id_";
    private static final String CITY_INDEX = "city_index_";

    public String mCityName;
    public String mTimeZone;
    public String mCityId;
    public String mCityIndex;
    public boolean isHeader;

    public CityObj(String name, String timezone, String id) {
    public CityObj(String name, String timezone, String id, String index) {
        mCityName = name;
        mTimeZone = timezone;
        mCityId = id;
        mCityIndex = index;
    }

    @Override
@@ -41,6 +44,7 @@ public class CityObj {
                "name=" + mCityName +
                ", timezone=" + mTimeZone +
                ", id=" + mCityId +
                ", index=" + mCityIndex +
                '}';
    }

@@ -48,11 +52,13 @@ public class CityObj {
        mCityName = prefs.getString(CITY_NAME + index, null);
        mTimeZone = prefs.getString(CITY_TIME_ZONE + index, null);
        mCityId = prefs.getString(CITY_ID + index, null);
        mCityIndex = prefs.getString(CITY_INDEX + index, null);
    }

    public void saveCityToSharedPrefs(SharedPreferences.Editor editor, int index) {
        editor.putString(CITY_NAME + index, mCityName);
        editor.putString(CITY_TIME_ZONE + index, mTimeZone);
        editor.putString(CITY_ID + index, mCityId);
        editor.putString(CITY_INDEX + index, mCityIndex);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public class WorldClockAdapter extends BaseAdapter {
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
            String homeTZ = sharedPref.getString(SettingsActivity.KEY_HOME_TZ, "");
            CityObj c = new CityObj(
                    mContext.getResources().getString(R.string.home_label), homeTZ, null);
                    mContext.getResources().getString(R.string.home_label), homeTZ, null, null);
            Object[] temp = new Object[mCitiesList.length + 1];
            temp[0] = c;
            for (int i = 0; i < mCitiesList.length; i++) {