This file contains hidden or 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
class EventLiveData<T> : MutableLiveData<T>() { | |
private var isRead: AtomicBoolean = AtomicBoolean(false) | |
/** | |
* ensure the event is non-null and can only been seen once | |
*/ | |
fun observeEvent(owner: LifecycleOwner, observer: Observer<T>) { | |
super.observe(owner, Observer { | |
if (it != null && isRead.compareAndSet(false, true)) { |
This file contains hidden or 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
fun refreshSavedBillers() { | |
payBillManager.getAll() | |
.compose(defaultOptions()) | |
.autoDisposable() | |
.subscribe({ | |
displaySavedBillers(it) | |
}) { Timber.d(it) } | |
} |
This file contains hidden or 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
class StateLiveData<T> : MutableLiveData<T>() { | |
val state = EventLiveData<State>() | |
} |
This file contains hidden or 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
class SimpleViewModel : ViewModel() { | |
var data: LiveData<String> = MutableLiveData() | |
var loading: LiveData<Boolean> = MutableLiveData() | |
var error: LiveData<Throwable> = MutableLiveData() | |
} |
This file contains hidden or 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
/** | |
* A generic class that holds a value with its loading status. | |
* @param <T> | |
</T> */ | |
data class Resource<out T>(val status: Status, val data: T?, val message: String?) { | |
companion object { | |
fun <T> success(data: T?): Resource<T> { | |
return Resource(SUCCESS, data, null) | |
} |
This file contains hidden or 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
@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> | |
} |
This file contains hidden or 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
class FindPostcodeActivity : KAusPostActivity() { | |
@Inject | |
lateinit var mgr: BranchLocationManager | |
lateinit var searchText: EditText | |
lateinit var listAdapter: BranchLocationPageAdapter | |
public override fun doOnCreate(savedInstanceState: Bundle?) { |
This file contains hidden or 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
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) |
This file contains hidden or 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
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 |
This file contains hidden or 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
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) |