Last active
July 6, 2018 06:57
-
-
Save markchristopherng/a975a0b53323cc9aad4e896073a09b0c to your computer and use it in GitHub Desktop.
FindPostcodeActivity
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
class FindPostcodeActivity : KAusPostActivity() { | |
@Inject | |
lateinit var mgr: BranchLocationManager | |
lateinit var searchText: EditText | |
lateinit var listAdapter: BranchLocationPageAdapter | |
public override fun doOnCreate(savedInstanceState: Bundle?) { | |
setContentView(R.layout.activity_find_postcode) | |
Toothpick.inject(this, appScope) | |
setupList() | |
setupSearchView() | |
} | |
private fun setupSearchView() { | |
searchText.textChanges() | |
.debounce(300, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread()) | |
.subscribe { text: CharSequence -> | |
loadList(text.toString()) | |
} | |
} | |
private fun setupList() { | |
text_no_results.visibility = View.GONE | |
loadList("") | |
} | |
private fun setupListAdapter() { | |
listAdapter = BranchLocationPageAdapter(this) | |
with(list_postcode) { | |
adapter = listAdapter | |
visibility = View.GONE | |
setHasFixedSize(true) | |
layoutManager = LinearLayoutManager(this@FindPostcodeActivity) | |
} | |
} | |
private fun loadList(filterKeyword: String) { | |
setupListAdapter() | |
val postcodeList = RxPagedListBuilder(mgr.pageByKeyword(filterKeyword), PagedList.Config | |
.Builder() | |
.setPageSize(1500) | |
.setEnablePlaceholders(true) | |
.build()) | |
.buildFlowable(BackpressureStrategy.LATEST) | |
postcodeList.compose(defaultOptions()) | |
.autoDisposable() | |
.subscribe { | |
val hasResult = it?.isNotEmpty() ?: false | |
displayList(hasResult) | |
listAdapter.submitList(it) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment