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 ExampleListUpdateCallback<T : RecyclerView.ViewHolder?>(val adapter: RecyclerView.Adapter<T>) : ListUpdateCallback { | |
override fun onChanged(position: Int, count: Int, payload: Any?) { | |
this.adapter.notifyItemRangeChanged(position, count, payload) | |
} | |
override fun onMoved(fromPosition: Int, toPosition: Int) { | |
this.adapter.notifyItemMoved(fromPosition, toPosition) | |
} | |
override fun onInserted(position: Int, count: Int) { |
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 ExampleCardsDiffCallback(private var oldList: List<ExampleModel>, | |
private var newList: List<ExampleModel>) : DiffUtil.Callback() { | |
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | |
return oldList[oldItemPosition].id == newList[newItemPosition].id | |
} | |
override fun getOldListSize(): Int { | |
return oldList.size | |
} |
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 ExampleCardsAdapter(private val context: Context) : RecyclerView.Adapter<ExampleViewHolder>() { | |
private var list: List<ExampleModel> = listOf() | |
fun updateList(newList: List<ExampleModel>) { | |
val diffResult = DiffUtil.calculateDiff(ExampleCardsDiffCallback(this.list, newList)) | |
this.list = newList | |
diffResult.dispatchUpdatesTo(ExampleListUpdateCallback(this)) | |
} |
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 AnkoActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val ankoComponent = ToolbarTemplateLayout<AnkoActivity>(object : ToolbarTemplateLayout.ToolbarTemplateLayoutInterface { | |
override fun toolbarStyleId(): Int = R.style.ToolbarStyle | |
override fun includedLayoutId(): Int = R.layout.activity_anko | |
}).setContentView(this) | |
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 AnkoActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val ankoComponent = ToolbarNBottombarTemplateLayout<AnkoActivity>(object : ToolbarNBottombarTemplateLayout.ToolbarNBottombarTemplateLayoutInterface { | |
override fun toolbarStyleId(): Int = R.style.ToolbarStyle | |
override fun includedLayoutId(): Int = R.layout.activity_anko | |
override fun footerStyleId(): Int = R.style.FooterStyle | |
}) |
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
<resources> | |
<!-- Base application theme. --> | |
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | |
<!-- Customize your theme here. --> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
<item name="windowActionBar">false</item> | |
<item name="windowNoTitle">true</item> |
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 ToolbarTemplateLayout<A: Activity>(private val layoutInterface: ToolbarTemplateLayoutInterface): AnkoComponent<A> { | |
override fun createView(ui: AnkoContext<A>): View { | |
return ui.verticalLayout { | |
themedToolbar(layoutInterface.toolbarStyleId()) | |
include<View>(layoutInterface.includedLayoutId()) | |
} | |
} | |
interface ToolbarTemplateLayoutInterface{ |
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 ToolbarNBottombarTemplateLayout<A : Activity>(private val layoutInterface: ToolbarNBottombarTemplateLayoutInterface) : AnkoComponent<A> { | |
override fun createView(ui: AnkoContext<A>): View { | |
return ui.constraintLayout { | |
val toolbar = themedToolbar(layoutInterface.toolbarStyleId()) | |
toolbar.layoutParams = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, | |
ConstraintLayout.LayoutParams.WRAP_CONTENT) | |
val included = include<View>(layoutInterface.includedLayoutId()) { |
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 ToolbarNBottombarTemplateLayout<A : Activity>(private val layoutInterface: ToolbarNBottombarTemplateLayoutInterface) : AnkoComponent<A> { | |
var binding: ViewDataBinding? = null | |
override fun createView(ui: AnkoContext<A>): View { | |
return ui.constraintLayout { | |
val toolbar = themedToolbar(layoutInterface.toolbarStyleId()) | |
toolbar.layoutParams = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, | |
ConstraintLayout.LayoutParams.WRAP_CONTENT) |
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 AnkoActivity : AppCompatActivity() { | |
lateinit var binding: ActivityAnkoBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val ankoComponent = ToolbarNBottombarTemplateLayout<AnkoActivity>(object : ToolbarNBottombarTemplateLayout.ToolbarNBottombarTemplateLayoutInterface { | |
override fun toolbarStyleId(): Int = R.style.ToolbarStyle | |
override fun includedLayoutId(): Int = R.layout.activity_anko |
OlderNewer