mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-25 16:07:47 +01:00
run getEvents on a background thread
This commit is contained in:
parent
8d10c1b164
commit
e154156628
@ -30,7 +30,7 @@ public class CalendarImpl implements DBHelper.DBOperationsListener {
|
||||
mTargetDate = targetDate;
|
||||
final int startTS = Formatter.getDayStartTS(Formatter.getDayCodeFromDateTime(mTargetDate.minusMonths(1)));
|
||||
final int endTS = Formatter.getDayEndTS(Formatter.getDayCodeFromDateTime(mTargetDate.plusMonths(1)));
|
||||
DBHelper.Companion.newInstance(mContext, this).getEvents(startTS, endTS);
|
||||
new DBHelper(mContext, this).getEvents(startTS, endTS);
|
||||
}
|
||||
|
||||
public void getPrevMonth() {
|
||||
|
@ -226,7 +226,7 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
||||
return;
|
||||
}
|
||||
|
||||
final DBHelper dbHelper = DBHelper.Companion.newInstance(getApplicationContext(), this);
|
||||
final DBHelper dbHelper = new DBHelper(getApplicationContext(), this);
|
||||
final String description = mDescriptionET.getText().toString().trim();
|
||||
mEvent.setStartTS(startTS);
|
||||
mEvent.setEndTS(mEndCheckbox.isChecked() ? endTS : startTS);
|
||||
|
@ -226,11 +226,16 @@ public class WidgetConfigureActivity extends AppCompatActivity implements Calend
|
||||
};
|
||||
|
||||
@Override
|
||||
public void updateCalendar(String month, List<Day> days) {
|
||||
this.mDays = days;
|
||||
public void updateCalendar(final String month, final List<Day> days) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mDays = days;
|
||||
updateMonth(month);
|
||||
updateDays();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateMonth(String month) {
|
||||
//mMonthTV.setText(month);
|
||||
|
@ -14,7 +14,7 @@ public class BootCompletedReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent arg1) {
|
||||
final List<Event> events = DBHelper.Companion.newInstance(context, null).getEventsAtReboot();
|
||||
final List<Event> events = new DBHelper(context, null).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 = DBHelper.Companion.newInstance(context, null).getEvent(id);
|
||||
final Event event = new DBHelper(context, null).getEvent(id);
|
||||
if (event == null || event.getReminderMinutes() == -1)
|
||||
return;
|
||||
|
||||
|
@ -13,7 +13,7 @@ import com.simplemobiletools.calendar.models.Event
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
||||
class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, null, DBHelper.DB_VERSION) {
|
||||
class DBHelper(context: Context, callback: DBOperationsListener?) : SQLiteOpenHelper(context, DBHelper.DB_NAME, null, DBHelper.DB_VERSION) {
|
||||
private val MAIN_TABLE_NAME = "events"
|
||||
private val COL_ID = "id"
|
||||
private val COL_START_TS = "start_ts"
|
||||
@ -29,21 +29,18 @@ 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: DBOperationsListener? = null
|
||||
|
||||
companion object {
|
||||
private val DB_NAME = "events.db"
|
||||
private val DB_VERSION = 3
|
||||
|
||||
private var mCallback: DBOperationsListener? = null
|
||||
lateinit private var mDb: SQLiteDatabase
|
||||
|
||||
fun newInstance(context: Context, callback: DBOperationsListener): DBHelper {
|
||||
mCallback = callback
|
||||
return DBHelper(context)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
mDb = writableDatabase
|
||||
mCallback = callback
|
||||
|
||||
}
|
||||
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
@ -149,6 +146,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
||||
}
|
||||
|
||||
fun getEvents(fromTS: Int, toTS: Int) {
|
||||
Thread({
|
||||
val events = ArrayList<Event>()
|
||||
var ts = fromTS
|
||||
while (ts <= toTS) {
|
||||
@ -162,6 +160,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DBHelper.DB_NAME, n
|
||||
events.addAll(fillEvents(cursor))
|
||||
|
||||
mCallback?.gotEvents(events)
|
||||
}).start()
|
||||
}
|
||||
|
||||
private fun getEventsFor(ts: Int): List<Event> {
|
||||
|
@ -118,7 +118,7 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
||||
private fun checkEvents() {
|
||||
val startTS = Formatter.getDayStartTS(mDayCode)
|
||||
val endTS = Formatter.getDayEndTS(mDayCode)
|
||||
DBHelper.newInstance(activity.applicationContext, this).getEvents(startTS, endTS)
|
||||
DBHelper(context, this).getEvents(startTS, endTS)
|
||||
}
|
||||
|
||||
private fun updateEvents(events: MutableList<Event>) {
|
||||
@ -172,7 +172,7 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
||||
|
||||
fun deleteEvents() {
|
||||
val eventIDs = Array(mToBeDeleted.size, { i -> (mToBeDeleted[i].toString()) })
|
||||
DBHelper.newInstance(activity.applicationContext, this).deleteEvents(eventIDs)
|
||||
DBHelper(activity.applicationContext, this).deleteEvents(eventIDs)
|
||||
}
|
||||
|
||||
fun undoDeletion() {
|
||||
@ -231,8 +231,10 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
||||
}
|
||||
|
||||
override fun gotEvents(events: MutableList<Event>) {
|
||||
activity?.runOnUiThread {
|
||||
updateEvents(events)
|
||||
}
|
||||
}
|
||||
|
||||
interface DeleteListener : NavigationListener {
|
||||
fun notifyDeletion(cnt: Int)
|
||||
|
@ -70,9 +70,11 @@ class MonthFragment : Fragment(), Calendar {
|
||||
}
|
||||
|
||||
override fun updateCalendar(month: String, days: List<Day>) {
|
||||
activity?.runOnUiThread {
|
||||
mHolder.month_value.text = month
|
||||
updateDays(days)
|
||||
}
|
||||
}
|
||||
|
||||
fun setListener(listener: NavigationListener) {
|
||||
mListener = listener
|
||||
|
Loading…
x
Reference in New Issue
Block a user