Search in sources :

Example 6 with City

use of com.djalel.android.bilal.datamodels.City in project Bilal by cdjalel.

the class UserSettings method updateCity.

private static City updateCity(Context context, String language) {
    City city = getCity(context);
    if (null != city) {
        LocationsDBHelper dbHelper = new LocationsDBHelper(context);
        dbHelper.openReadable();
        city = dbHelper.getCity(city.getId(), language.toUpperCase());
        dbHelper.close();
        if (null != city) {
            saveCity(context, city);
            return city;
        }
    }
    return null;
}
Also used : LocationsDBHelper(com.djalel.android.bilal.databases.LocationsDBHelper) City(com.djalel.android.bilal.datamodels.City)

Example 7 with City

use of com.djalel.android.bilal.datamodels.City in project Bilal by cdjalel.

the class UserSettings method getLocale.

private static Locale getLocale(Context context) {
    String lang = getPrefLanguage(context);
    if (languageUsesDeviceSettings(context, lang)) {
        lang = getDeviceLanguage();
    }
    String numerals = getNumerals(context);
    String cc;
    if (numeralsUseCountryCode(context, numerals)) {
        City city = getCity(context);
        cc = null != city ? city.getCountryCode() : null;
    } else {
        cc = numerals;
    }
    return null != cc ? new Locale(lang, cc) : new Locale(lang);
}
Also used : Locale(java.util.Locale) City(com.djalel.android.bilal.datamodels.City)

Example 8 with City

use of com.djalel.android.bilal.datamodels.City in project Bilal by cdjalel.

the class SearchCityActivity method searchCity.

private void searchCity(String query) {
    List<City> cityList = mDBHelper.searchCity(query, mLanguage);
    if (cityList != null) {
        mCityListAdapter = new CityListAdapter(this, cityList);
        mCityListView = findViewById(R.id.list_city);
        mCityListView.setAdapter(mCityListAdapter);
        mCityListView.setOnItemClickListener(this);
    }
}
Also used : City(com.djalel.android.bilal.datamodels.City) CityListAdapter(com.djalel.android.bilal.adapters.CityListAdapter)

Example 9 with City

use of com.djalel.android.bilal.datamodels.City in project Bilal by cdjalel.

the class LocationsDBHelper method getCity.

// Caller is in charge of DB open/close as it might issue many calls to browse DB.
// called only when other settings affecting DB (e.g., language) changes
public City getCity(int id, String language) {
    if (-1 >= id) {
        Timber.e("Bad city id: " + id);
        return null;
    }
    language = sanitizeLanguage(language);
    String query = prepareCityQuery(FORMAT_CITY_QUERY_2NAMES, language, language, "WHERE id = ?");
    Cursor cursor = mDatabase.rawQuery(query, new String[] { String.valueOf(id) });
    City city = null;
    if (cursor.moveToNext()) {
        city = new City(cursor.getInt(0), cursor.getString(2).isEmpty() ? cursor.getString(1) : cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getFloat(6), cursor.getFloat(7), cursor.getInt(8), cursor.getString(9));
    }
    cursor.close();
    Timber.d("city:\n" + city);
    return city;
}
Also used : City(com.djalel.android.bilal.datamodels.City) Cursor(android.database.Cursor)

Example 10 with City

use of com.djalel.android.bilal.datamodels.City in project Bilal by cdjalel.

the class UserSettings method setLocale.

public static void setLocale(Context context, String newLang, String newCC) {
    // saving in shared prefs. is handled by the framework after the caller
    City city = null;
    if (null != newLang) {
        if (languageUsesDeviceSettings(context, newLang)) {
            newLang = getDeviceLanguage();
        }
        // update saved city as it depends on language
        city = updateCity(context, newLang);
    } else {
        newLang = getLanguage(context);
    }
    if (null == newCC) {
        newCC = getNumerals(context);
    }
    if (numeralsUseCountryCode(context, newCC)) {
        if (null == city) {
            city = getCity(context);
        }
        if (null != city) {
            newCC = city.getCountryCode();
        } else {
            newCC = null;
        }
    }
    setLocale(context, null != newCC ? new Locale(newLang, newCC) : new Locale(newLang));
}
Also used : Locale(java.util.Locale) City(com.djalel.android.bilal.datamodels.City)

Aggregations

City (com.djalel.android.bilal.datamodels.City)10 Cursor (android.database.Cursor)4 ArrayList (java.util.ArrayList)3 Locale (java.util.Locale)2 Intent (android.content.Intent)1 CityListAdapter (com.djalel.android.bilal.adapters.CityListAdapter)1 LocationsDBHelper (com.djalel.android.bilal.databases.LocationsDBHelper)1 GregorianCalendar (java.util.GregorianCalendar)1