some callback and interface cleanup
This commit is contained in:
parent
fb12a8b38d
commit
8a64933652
|
@ -10,7 +10,7 @@ import org.joda.time.DateTime;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MonthlyCalendarImpl implements DBHelper.MonthlyEventsListener {
|
||||
public class MonthlyCalendarImpl implements DBHelper.GetEventsListener {
|
||||
private static final int DAYS_CNT = 42;
|
||||
private static final String YEAR_PATTERN = "YYYY";
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class MonthlyCalendarImpl implements DBHelper.MonthlyEventsListener {
|
|||
mTargetDate = targetDate;
|
||||
final int startTS = Formatter.getDayStartTS(Formatter.getDayCodeFromDateTime(mTargetDate.minusMonths(1)));
|
||||
final int endTS = Formatter.getDayEndTS(Formatter.getDayCodeFromDateTime(mTargetDate.plusMonths(1)));
|
||||
new DBHelper(mContext, this).getEvents(startTS, endTS);
|
||||
new DBHelper(mContext).getEvents(startTS, endTS, this);
|
||||
}
|
||||
|
||||
public void setTargetDate(DateTime dateTime) {
|
||||
|
@ -112,21 +112,6 @@ public class MonthlyCalendarImpl implements DBHelper.MonthlyEventsListener {
|
|||
return mTargetDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventInserted(Event event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventUpdated(Event event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventsDeleted(int cnt) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gotEvents(List<Event> events) {
|
||||
mEvents = events;
|
||||
|
|
|
@ -14,7 +14,7 @@ public class BootCompletedReceiver extends BroadcastReceiver {
|
|||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent arg1) {
|
||||
final List<Event> events = new DBHelper(context, null).getEventsAtReboot();
|
||||
final List<Event> events = new DBHelper(context).getEventsAtReboot();
|
||||
for (Event event : events) {
|
||||
Utils.scheduleNextEvent(context, event);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class NotificationReceiver extends BroadcastReceiver {
|
|||
if (id == -1)
|
||||
return;
|
||||
|
||||
final Event event = new DBHelper(context, null).getEvent(id);
|
||||
final Event event = new DBHelper(context).getEvent(id);
|
||||
if (event == null || event.getReminderMinutes() == -1)
|
||||
return;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
|||
private val COL_REPEAT_MONTH = "repeat_month"
|
||||
private val COL_REPEAT_DAY = "repeat_day"
|
||||
|
||||
private var mCallback: MonthlyEventsListener? = null
|
||||
private var mEventsListener: EventsListener? = null
|
||||
|
||||
companion object {
|
||||
private val DB_NAME = "events.db"
|
||||
|
@ -37,8 +37,8 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
|||
lateinit private var mDb: SQLiteDatabase
|
||||
}
|
||||
|
||||
constructor(context: Context, callback: MonthlyEventsListener?) : this(context) {
|
||||
mCallback = callback
|
||||
constructor(context: Context, callback: EventsListener?) : this(context) {
|
||||
mEventsListener = callback
|
||||
}
|
||||
|
||||
init {
|
||||
|
@ -76,7 +76,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
|||
mDb.insert(META_TABLE_NAME, null, metaValues)
|
||||
}
|
||||
|
||||
mCallback?.eventInserted(event)
|
||||
mEventsListener?.eventInserted(event)
|
||||
}
|
||||
|
||||
fun update(event: Event) {
|
||||
|
@ -93,7 +93,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
|||
mDb.insertWithOnConflict(META_TABLE_NAME, null, metaValues, SQLiteDatabase.CONFLICT_REPLACE)
|
||||
}
|
||||
|
||||
mCallback?.eventUpdated(event)
|
||||
mEventsListener?.eventUpdated(event)
|
||||
}
|
||||
|
||||
private fun fillContentValues(event: Event): ContentValues {
|
||||
|
@ -133,7 +133,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
|||
val metaSelection = "$COL_EVENT_ID IN ($args)"
|
||||
mDb.delete(META_TABLE_NAME, metaSelection, null)
|
||||
|
||||
mCallback?.eventsDeleted(ids.size)
|
||||
mEventsListener?.eventsDeleted(ids.size)
|
||||
}
|
||||
|
||||
fun getEvent(id: Int): Event? {
|
||||
|
@ -147,7 +147,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
|||
return null
|
||||
}
|
||||
|
||||
fun getEvents(fromTS: Int, toTS: Int) {
|
||||
fun getEvents(fromTS: Int, toTS: Int, callback: GetEventsListener?) {
|
||||
Thread({
|
||||
val events = ArrayList<Event>()
|
||||
var ts = fromTS
|
||||
|
@ -161,7 +161,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
|||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
events.addAll(fillEvents(cursor))
|
||||
|
||||
mCallback?.gotEvents(events)
|
||||
callback?.gotEvents(events)
|
||||
}).start()
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
|||
return events
|
||||
}
|
||||
|
||||
interface MonthlyEventsListener {
|
||||
interface EventsListener {
|
||||
fun eventInserted(event: Event)
|
||||
|
||||
fun eventUpdated(event: Event)
|
||||
|
@ -268,6 +268,10 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
|||
fun gotEvents(events: MutableList<Event>)
|
||||
}
|
||||
|
||||
interface GetEventsListener {
|
||||
fun gotEvents(events: MutableList<Event>)
|
||||
}
|
||||
|
||||
interface YearlyEventsListener {
|
||||
fun yearlyEvents(events: MutableList<String>)
|
||||
}
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
package com.simplemobiletools.calendar
|
||||
|
||||
class YearlyCalendarImpl(year: Int) : DBHelper.YearlyEventsListener {
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import org.joda.time.DateTime
|
||||
|
||||
fun getEvents() {
|
||||
class YearlyCalendarImpl(callback: YearlyCalendar, context: Context) : DBHelper.GetEventsListener {
|
||||
val mContext = context
|
||||
|
||||
fun getEvents(year: Int) {
|
||||
val startDateTime = DateTime().withTime(0, 0, 0, 0).withDate(year, 1, 1)
|
||||
val startTS = (startDateTime.millis / 1000).toInt()
|
||||
val endTS = (startDateTime.plusYears(1).minusSeconds(1).millis / 1000).toInt()
|
||||
DBHelper(mContext).getEvents(startTS, endTS, this)
|
||||
}
|
||||
|
||||
override fun yearlyEvents(events: MutableList<String>) {
|
||||
override fun gotEvents(events: MutableList<Event>) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import kotlinx.android.synthetic.main.activity_event.*
|
|||
import org.joda.time.DateTime
|
||||
import org.joda.time.DateTimeZone
|
||||
|
||||
class EventActivity : SimpleActivity(), DBHelper.MonthlyEventsListener {
|
||||
class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||
private var mWasReminderInit: Boolean = false
|
||||
private var mWasEndDateSet: Boolean = false
|
||||
private var mWasEndTimeSet: Boolean = false
|
||||
|
|
|
@ -23,7 +23,7 @@ import kotlinx.android.synthetic.main.day_fragment.view.*
|
|||
import kotlinx.android.synthetic.main.top_navigation.view.*
|
||||
import java.util.*
|
||||
|
||||
class DayFragment : Fragment(), DBHelper.MonthlyEventsListener, AdapterView.OnItemClickListener, AbsListView.MultiChoiceModeListener {
|
||||
class DayFragment : Fragment(), DBHelper.EventsListener, AdapterView.OnItemClickListener, AbsListView.MultiChoiceModeListener, DBHelper.GetEventsListener {
|
||||
|
||||
private val EDIT_EVENT = 1
|
||||
|
||||
|
@ -119,7 +119,7 @@ class DayFragment : Fragment(), DBHelper.MonthlyEventsListener, AdapterView.OnIt
|
|||
private fun checkEvents() {
|
||||
val startTS = Formatter.getDayStartTS(mDayCode)
|
||||
val endTS = Formatter.getDayEndTS(mDayCode)
|
||||
DBHelper(context, this).getEvents(startTS, endTS)
|
||||
DBHelper(context, this).getEvents(startTS, endTS, this)
|
||||
}
|
||||
|
||||
private fun updateEvents(events: MutableList<Event>) {
|
||||
|
|
|
@ -14,12 +14,18 @@ class YearFragment : Fragment(), YearlyCalendar {
|
|||
private var mListener: NavigationListener? = null
|
||||
private var mYear = 0
|
||||
private var mSundayFirst = false
|
||||
|
||||
lateinit var mView: View
|
||||
lateinit var mCalendar: YearlyCalendarImpl
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
mView = inflater!!.inflate(R.layout.year_fragment, container, false)
|
||||
mYear = arguments.getInt(Constants.YEAR_LABEL)
|
||||
setupMonths()
|
||||
|
||||
mCalendar = YearlyCalendarImpl(this, context)
|
||||
mCalendar.getEvents(mYear)
|
||||
|
||||
return mView
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue