-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Event Insert and Delete on a background thread for ListActivity
- database insertion and deletion now on a background thread through asynctask - updating the recycler view is managed through LiveData observable Signed-off-by: Arka Prava Basu <[email protected]>
- Loading branch information
Showing
6 changed files
with
128 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/org/havenapp/main/database/async/EventDeleteAllAsync.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.havenapp.main.database.async | ||
|
||
import android.os.AsyncTask | ||
import org.havenapp.main.HavenApp | ||
import org.havenapp.main.model.Event | ||
|
||
/** | ||
* Created by Arka Prava Basu <[email protected]> on 6/9/18. | ||
*/ | ||
class EventDeleteAllAsync(private val listener: EventDeleteAllListener) | ||
: AsyncTask<List<Event>, Unit, Unit>() { | ||
override fun doInBackground(vararg params: List<Event>) { | ||
HavenApp.dataBaseInstance.getEventDAO().deleteAll(params.get(0)) | ||
} | ||
|
||
override fun onPostExecute(result: Unit?) { | ||
listener.onEventsDeleted() | ||
} | ||
|
||
interface EventDeleteAllListener { | ||
fun onEventsDeleted() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/havenapp/main/database/async/EventDeleteAsync.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.havenapp.main.database.async | ||
|
||
import android.os.AsyncTask | ||
import org.havenapp.main.HavenApp | ||
import org.havenapp.main.model.Event | ||
|
||
/** | ||
* Created by Arka Prava Basu <[email protected]> on 6/9/18. | ||
*/ | ||
class EventDeleteAsync(private val listener: EventDeleteListener) | ||
: AsyncTask<Event, Unit, Unit>() { | ||
override fun doInBackground(vararg params: Event) { | ||
HavenApp.dataBaseInstance.getEventDAO().delete(params.get(0)) | ||
} | ||
|
||
override fun onPostExecute(result: Unit?) { | ||
listener.onDeleteEvent() | ||
} | ||
|
||
interface EventDeleteListener { | ||
fun onDeleteEvent() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/havenapp/main/database/async/EventInsertAllAsync.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.havenapp.main.database.async | ||
|
||
import android.os.AsyncTask | ||
import org.havenapp.main.HavenApp | ||
import org.havenapp.main.model.Event | ||
|
||
/** | ||
* Created by Arka Prava Basu <[email protected]> on 6/9/18. | ||
*/ | ||
class EventInsertAllAsync(private val listener: EventInsertListener) | ||
: AsyncTask<List<Event>, Unit, List<Long>>() { | ||
override fun doInBackground(vararg params: List<Event>): List<Long> { | ||
return HavenApp.dataBaseInstance.getEventDAO().insertAll(params.get(0)) | ||
} | ||
|
||
override fun onPostExecute(result: List<Long>) { | ||
listener.onInsertionComplete(result) | ||
} | ||
|
||
interface EventInsertListener { | ||
fun onInsertionComplete(eventIdList: List<Long>) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/havenapp/main/database/async/EventInsertAsync.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.havenapp.main.database.async | ||
|
||
import android.os.AsyncTask | ||
import org.havenapp.main.HavenApp | ||
import org.havenapp.main.model.Event | ||
|
||
/** | ||
* Created by Arka Prava Basu <[email protected]> on 6/9/18. | ||
*/ | ||
class EventInsertAsync(val listener: EventInsertListener): AsyncTask<Event, Unit, Long>() { | ||
override fun doInBackground(vararg params: Event): Long { | ||
val event = params.get(0) | ||
return HavenApp.dataBaseInstance.getEventDAO().insert(event) | ||
} | ||
|
||
override fun onPostExecute(result: Long) { | ||
listener.onInsertionComplete(result) | ||
} | ||
|
||
interface EventInsertListener { | ||
fun onInsertionComplete(eventId: Long) | ||
} | ||
} |