Skip to content

Instantly share code, notes, and snippets.

package au.com.auspost.android.feature.postcode.model
import android.arch.persistence.room.ColumnInfo
import android.arch.persistence.room.Entity
import android.arch.persistence.room.PrimaryKey
@Entity(tableName = "branch_location")
data class BranchLocation(@PrimaryKey(autoGenerate = true) var id : Int,
@ColumnInfo(name = "postcode") var postcode : String?,
@ColumnInfo(name = "locality") var locality : String?,
@markchristopherng
markchristopherng / BranchLocation.kt
Created April 11, 2018 01:54
Room Entity with Parceler
@Entity(tableName = "branch_location")
@SuppressLint("ParcelCreator")
data class BranchLocation @ParcelConstructor constructor (@PrimaryKey(autoGenerate = true) var id : Int,
@ColumnInfo(name = "postcode") var postcode : String?,
@ColumnInfo(name = "locality") var locality : String?,
@ColumnInfo(name = "state") var state : String?,
@ColumnInfo(name = "delivery") var delivery : String? = null,
@ColumnInfo(name = "category") var category : String?)
package au.com.auspost.android.feature.postcode.service
import android.arch.persistence.room.Dao
import android.arch.persistence.room.Insert
import android.arch.persistence.room.OnConflictStrategy
import android.arch.persistence.room.Query
import au.com.auspost.android.feature.postcode.model.BranchLocation
import io.reactivex.Single
@Dao
package au.com.auspost.android.feature.postcode.service
import au.com.auspost.android.AuspostDatabase
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class BranchLocationManager {
@Inject
@markchristopherng
markchristopherng / AuspostDatabaseProvider.kt
Created April 11, 2018 04:45
AuspostDatabaseProvider
package au.com.auspost.android
import android.arch.persistence.db.SupportSQLiteDatabase
import android.arch.persistence.room.Room
import android.arch.persistence.room.migration.Migration
import android.content.Context
import android.support.annotation.VisibleForTesting
import io.reactivex.Observable
import timber.log.Timber
import toothpick.ProvidesSingletonInScope
package au.com.auspost.android
import android.arch.persistence.room.Database
import android.arch.persistence.room.RoomDatabase
import au.com.auspost.android.feature.postcode.model.BranchLocation
import au.com.auspost.android.feature.postcode.service.BranchLocationDao
@Database(entities = [
BranchLocation::class
], version = 2)
@markchristopherng
markchristopherng / BranchLocationDaoTest.kt
Last active April 11, 2018 05:17
BranchLocationDaoTest
package au.com.auspost.android.feature.postcode.service
import android.arch.core.executor.testing.InstantTaskExecutorRule
import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import au.com.auspost.android.AuspostDatabase
import au.com.auspost.android.feature.postcode.model.BranchLocation
import org.junit.After
import org.junit.Before
@markchristopherng
markchristopherng / BranchLocationPageAdapter.kt
Last active July 4, 2018 04:47
BranchLocationPageAdapter
class BranchLocationPageAdapter(var context: Context) : PagedListAdapter<BranchLocation, BranchLocationPageAdapter.ViewHolder>(diffCallback), FastScrollRecyclerView.SectionedAdapter {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
bindItem(holder, position)
}
fun getBranchLocation(position: Int) = getItem(position)
fun bindItem(holder: ViewHolder, position: Int) {
val obj = getItem(position)
@markchristopherng
markchristopherng / FindPostcodeActivity.kt
Last active July 6, 2018 06:57
FindPostcodeActivity
class FindPostcodeActivity : KAusPostActivity() {
@Inject
lateinit var mgr: BranchLocationManager
lateinit var searchText: EditText
lateinit var listAdapter: BranchLocationPageAdapter
public override fun doOnCreate(savedInstanceState: Bundle?) {
@markchristopherng
markchristopherng / BranchLocationDao.kt
Last active July 4, 2018 04:46
BranchLocationPagingDao
@Dao
interface BranchLocationDao {
@Query("SELECT * from branch_location where postcode like :arg0 OR locality like :arg0 ORDER BY locality ASC")
fun pageByKeyword(arg0: String): DataSource.Factory<Int, BranchLocation>
}