diff --git a/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java b/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java index 5eef44bfa..740227686 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java +++ b/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java @@ -13,7 +13,6 @@ import java.util.List; public class DBHelper extends SQLiteOpenHelper { private static SQLiteDatabase mDb; - private static String[] mProjection; private static DBOperationsListener mCallback; private static final String DB_NAME = "events.db"; @@ -34,7 +33,6 @@ public class DBHelper extends SQLiteOpenHelper { public DBHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); mDb = getWritableDatabase(); - mProjection = new String[]{COL_ID, COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION}; } @Override @@ -64,10 +62,11 @@ public class DBHelper extends SQLiteOpenHelper { } public void getEvents(int fromTS, int toTS) { + final String[] projection = {COL_ID, COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION}; List events = new ArrayList<>(); final String selection = COL_START_TS + " <= ? AND " + COL_END_TS + " >= ?"; final String[] selectionArgs = {String.valueOf(toTS), String.valueOf(fromTS)}; - final Cursor cursor = mDb.query(TABLE_NAME, mProjection, selection, selectionArgs, null, null, COL_START_TS); + final Cursor cursor = mDb.query(TABLE_NAME, projection, selection, selectionArgs, null, null, COL_START_TS); if (cursor != null) { if (cursor.moveToFirst()) { do { diff --git a/app/src/main/java/com/simplemobiletools/calendar/Formatter.java b/app/src/main/java/com/simplemobiletools/calendar/Formatter.java index b1719142a..660d93e76 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/Formatter.java +++ b/app/src/main/java/com/simplemobiletools/calendar/Formatter.java @@ -10,7 +10,7 @@ public class Formatter { private static final String EVENT_TIME_PATTERN = "HH:mm"; public static String getEventDate(String dayCode) { - return getDateTime(dayCode).toString(EVENT_DATE_PATTERN); + return getDateTimeFromCode(dayCode).toString(EVENT_DATE_PATTERN); } public static String getEventDate(DateTime dateTime) { @@ -21,7 +21,7 @@ public class Formatter { return dateTime.toString(EVENT_TIME_PATTERN); } - public static DateTime getDateTime(String dayCode) { + public static DateTime getDateTimeFromCode(String dayCode) { final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(Constants.DATE_PATTERN).withZone(DateTimeZone.UTC); return dateTimeFormatter.parseDateTime(dayCode); } @@ -30,4 +30,14 @@ public class Formatter { final DateTime dateTime = new DateTime(ts * 1000L, DateTimeZone.UTC); return getEventTime(dateTime); } + + public static int getDayStartTS(String dayCode) { + final DateTime dateTime = getDateTimeFromCode(dayCode); + return (int) (dateTime.getMillis() / 1000); + } + + public static int getDayEndTS(String dayCode) { + final DateTime dateTime = getDateTimeFromCode(dayCode); + return (int) (dateTime.plusDays(1).minusMinutes(1).getMillis() / 1000); + } } diff --git a/app/src/main/java/com/simplemobiletools/calendar/activities/DetailsActivity.java b/app/src/main/java/com/simplemobiletools/calendar/activities/DetailsActivity.java index 79eb47ca7..39dc98786 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/DetailsActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/DetailsActivity.java @@ -14,9 +14,6 @@ import com.simplemobiletools.calendar.Formatter; import com.simplemobiletools.calendar.R; import com.simplemobiletools.calendar.models.Event; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; - import java.util.List; import butterknife.BindView; @@ -61,9 +58,8 @@ public class DetailsActivity extends AppCompatActivity implements DBHelper.DBOpe } private void checkEvents() { - final DateTime dateTime = Formatter.getDateTime(dayCode).withZone(DateTimeZone.UTC); - final int startTS = (int) (dateTime.getMillis() / 1000); - final int endTS = (int) (dateTime.plusDays(1).minusMinutes(1).getMillis() / 1000); + final int startTS = Formatter.getDayStartTS(dayCode); + final int endTS = Formatter.getDayEndTS(dayCode); DBHelper.newInstance(getApplicationContext(), this).getEvents(startTS, endTS); } diff --git a/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java b/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java index 9abb2f717..615320a3c 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java @@ -53,11 +53,11 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera if (dayCode == null || dayCode.isEmpty()) return; - mEventStartDateTime = Formatter.getDateTime(dayCode); + mEventStartDateTime = Formatter.getDateTimeFromCode(dayCode); updateStartDate(); updateStartTime(); - mEventEndDateTime = Formatter.getDateTime(dayCode); + mEventEndDateTime = Formatter.getDateTimeFromCode(dayCode); updateEndDate(); updateEndTime(); }