use of com.djalel.android.bilal.datamodels.City in project Bilal by cdjalel.
the class PrayerTimesManager method updatePrayerTimes.
/*
* Here be dragons. This is an app entry point. All bets are off!
* See comment in MainActivity.onCreate()
*/
public static void updatePrayerTimes(Context context, boolean enableAlarm) {
Timber.i("--- updatePrayerTimes(..., " + enableAlarm + ")");
logBootAndTimeChangeReceiverSetting(context);
City city = UserSettings.getCity(context);
if (null == city) {
Timber.w("Location not set! Nothing todo until user chooses a city.");
return;
}
GregorianCalendar nowCal = new GregorianCalendar();
// next test includes location & time change see handlers above
if (null != sPrayerTimes && !sNewCalc && sameDay(sLastTime, nowCal)) {
sPrayerTimes.updateCurrent(nowCal);
Timber.d("Call it a day :)");
} else {
calcPrayerTimes(context, nowCal, city);
}
Timber.d("Current time: " + sPrayerTimes.format(nowCal));
Timber.d("Current prayer: " + sPrayerTimes.getCurrentName(context));
Timber.i("Next prayer: " + sPrayerTimes.getNextName(context));
Timber.d("UserSettings.isAlarmEnabled = " + UserSettings.isAlarmEnabled(context));
// enableAlarm boolean.
if (enableAlarm || UserSettings.isAlarmEnabled(context)) {
scheduleAlarm(context);
}
}
use of com.djalel.android.bilal.datamodels.City in project Bilal by cdjalel.
the class SearchCityActivity method onItemClick.
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
City newCity = (City) mCityListAdapter.getItem(i);
// get city name in Locale as search could be in EN
newCity = mDBHelper.getCity(newCity.getId(), mLanguage);
Timber.i("Selected city: " + newCity);
City oldCity = UserSettings.getCity(this);
if (null == oldCity || oldCity.getId() != newCity.getId()) {
// save new city
UserSettings.setCity(this, newCity);
// adapt preference summary
Intent resultIntent = new Intent();
resultIntent.putExtra("name", newCity.getName());
setResult(Activity.RESULT_OK, resultIntent);
}
finish();
}
use of com.djalel.android.bilal.datamodels.City in project Bilal by cdjalel.
the class LocationsDBHelper method searchCity.
public List<City> searchCity(double lat, double lng, String language) {
if (null == mDatabase) {
Timber.w("Open database first!");
return null;
}
language = sanitizeLanguage(language);
String query = prepareCityQuery(FORMAT_CITY_QUERY_2NAMES, language, language, "WHERE lat BETWEEN ? AND ? AND lng BETWEEN ? AND ?");
Cursor cursor = mDatabase.rawQuery(query, new String[] { String.valueOf(lat - 0.08), String.valueOf(lat + 0.08), String.valueOf(lng - 0.08), String.valueOf(lng + 0.08) });
List<City> cityList = new ArrayList<>();
while (cursor.moveToNext()) {
cityList.add(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("cityList:\n" + cityList);
return cityList;
}
use of com.djalel.android.bilal.datamodels.City in project Bilal by cdjalel.
the class LocationsDBHelper method getCities.
public List<City> getCities(String country, String language) {
if (null == mDatabase) {
Timber.d("Open DB first!");
return null;
}
language = sanitizeLanguage(language);
String query = prepareCityQuery(FORMAT_CITY_QUERY_2NAMES, language, language, "WHERE country LIKE ?");
Cursor cursor = mDatabase.rawQuery(query, new String[] { "%" + country + "%" });
List<City> cities = new ArrayList<>();
while (cursor.moveToNext()) {
cities.add(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("cities:\n" + cities);
return cities;
}
use of com.djalel.android.bilal.datamodels.City in project Bilal by cdjalel.
the class LocationsDBHelper method searchCity.
// Remaining methods are called only for city search.
public List<City> searchCity(String city, String language) {
if (null == mDatabase) {
Timber.w("Open database first!");
return null;
}
language = sanitizeLanguage(language);
city = "%" + city + "%";
// search local name column first, then fall back to english name if none
String query = prepareCityQuery(FORMAT_CITY_QUERY_1NAME, language, language, "WHERE nameL LIKE ?");
Cursor cursor = mDatabase.rawQuery(query, new String[] { city });
if (cursor.getCount() == 0) {
cursor.close();
query = prepareCityQuery(FORMAT_CITY_QUERY_1NAME, "EN", language, "WHERE nameL LIKE ?");
cursor = mDatabase.rawQuery(query, new String[] { city });
}
List<City> cityList = new ArrayList<>();
while (cursor.moveToNext()) {
cityList.add(new City(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getFloat(5), cursor.getFloat(6), cursor.getInt(7), cursor.getString(8)));
}
cursor.close();
Timber.d("cityList:\n" + cityList);
return cityList;
}
Aggregations