Skip to content

Instantly share code, notes, and snippets.

View nlgtuankiet's full-sized avatar

nlgtuankiet

View GitHub Profile
// :app module
override fun detailIntent(context: Context, productId: String): Intent {
// old way
// return DetailActivity.starterIntent(context = context, productId = productId)
// new way
return Class.forName("com.nlgtuankiet.modularization.detail.DetailActivity")
.getDeclaredMethod("starterIntent", Context::class.java, String::class.java)
.invoke(null, context, productId) as Intent
@nlgtuankiet
nlgtuankiet / DetailActivity.kt
Last active January 17, 2020 06:03
starter intent keep
// :detail module
class DetailActivity : DaggerAppCompatActivity() {
// omitted
companion object {
@JvmStatic
@Keep
fun starterIntent(context: Context, productId: String): Intent {
return Intent(context, DetailActivity::class.java).apply {
class DetailActivity : DaggerAppCompatActivity() {
// omitted
companion object {
@JvmStatic
fun starterIntent(context: Context, productId: String): Intent {
return Intent(context, DetailActivity::class.java).apply {
putExtra("productId", productId)
}
}
@nlgtuankiet
nlgtuankiet / build.gradle
Last active January 17, 2020 00:32
app build.gradle exclude module setup
// app/build.gradle
apply plugin: 'com.android.application'
def include(moduleName) {
if (hasProperty('only')) {
return only.split(",").contains(moduleName)
}
return true
}
new ListUpdateCallback() {
@Override
public void onInserted(int position, int count) {
adapterCallback.onInserted(position + 1, count);
}
@Override
public void onRemoved(int position, int count) {
adapterCallback.onRemoved(position + 1, count);
}
class MainAdapter : PagedListAdapter<ItemViewModel, MainAdapter.ItemViewHolder>(ItemCallback) {
override fun getItemViewType(position: Int): Int {
return when (getItem(position)) {
is BannerView.Model -> 1
// bla bla
else -> 0 // loading model
}
}
class MainModelDataSource @Inject constructor(
private val args: MainArgs,
private val getBanner: GetBanner,
private val getCategory: GetCategory,
private val getDeal: GetDeal,
private val getMainLayout: GetMainLayout
) : PageKeyedDataSource<Int, ItemViewModel>() {
private lateinit var layout: List<MainViewType>
private val totalItemCount: Int by lazy {
layout.map { viewType ->
class MainController : PagedListEpoxyController<EpoxyModel<*>>() {
override fun buildItemModel(currentPosition: Int, item: EpoxyModel<*>?): EpoxyModel<*> {
return item ?: LoadingViewModel_()
.id("loading $currentPosition")
.content("loading $currentPosition")
}
}
override fun getItemViewType(position: Int): Int {
return when (getItem(position)) {
is BannerView.Model -> 1
is CategoryView.Model -> 2
is DealView.Model -> 3
is SeparatorView.Model -> 4
else -> 0 // loading model
}
}
private object ItemCallback : DiffUtil.ItemCallback<ItemViewModel>() {
override fun areItemsTheSame(oldItem: ItemViewModel, newItem: ItemViewModel): Boolean {
return when {
oldItem is BannerView.Model && newItem is BannerView.Model -> oldItem.id == newItem.id
oldItem is DealView.Model && newItem is DealView.Model -> oldItem.id == newItem.id
oldItem is CategoryView.Model && newItem is CategoryView.Model -> oldItem.id == newItem.id
oldItem is SeparatorView.Model && newItem is SeparatorView.Model -> oldItem.id == newItem.id
else -> false
}
}