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
// :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 |
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
// :detail module | |
class DetailActivity : DaggerAppCompatActivity() { | |
// omitted | |
companion object { | |
@JvmStatic | |
@Keep | |
fun starterIntent(context: Context, productId: String): Intent { | |
return Intent(context, DetailActivity::class.java).apply { |
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 DetailActivity : DaggerAppCompatActivity() { | |
// omitted | |
companion object { | |
@JvmStatic | |
fun starterIntent(context: Context, productId: String): Intent { | |
return Intent(context, DetailActivity::class.java).apply { | |
putExtra("productId", productId) | |
} | |
} |
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
// app/build.gradle | |
apply plugin: 'com.android.application' | |
def include(moduleName) { | |
if (hasProperty('only')) { | |
return only.split(",").contains(moduleName) | |
} | |
return true | |
} |
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
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); | |
} |
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 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 | |
} | |
} |
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 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 -> |
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 MainController : PagedListEpoxyController<EpoxyModel<*>>() { | |
override fun buildItemModel(currentPosition: Int, item: EpoxyModel<*>?): EpoxyModel<*> { | |
return item ?: LoadingViewModel_() | |
.id("loading $currentPosition") | |
.content("loading $currentPosition") | |
} | |
} |
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
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 | |
} | |
} |
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
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 | |
} | |
} |