Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="viewModel"
type="pl.marchuck.pagingexample.pagination.PaginationViewModel" />
</data>
@BindingAdapter("android:adapterSetup")
fun setupRecyclerViewAdapter(view: RecyclerView, viewModel: PaginationViewModel) {
view.layoutManager = LinearLayoutManager(view.context)
view.adapter = viewModel.adapter
}
class PaginationViewModel(pagedListProvider: PagedListProvider<Person?>) : ViewModel() {
val pagedListData = pagedListProvider.provide()
val adapter = SwapiAdapter()
}
class SwapiAdapter(diffCallback: DiffUtil.ItemCallback<Person?>)
: PagedListAdapter<Person, SwapiPersonViewHolder>(diffCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SwapiPersonViewHolder {
val inflater = LayoutInflater.from(parent.context)
val binding = DataBindingUtil.inflate<ItemSwapiPersonBinding>(
inflater, R.layout.item_swapi_person, parent, false)
return SwapiPersonViewHolder(binding)
}
class SwapiPersonViewHolder(private val binding: ItemSwapiPersonBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(item: Person?) {
binding.personModel = SwapiPersonViewModel(item)
binding.executePendingBindings()
}
}
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="personModel"
type="pl.marchuck.pagingexample.pagination.adapter.SwapiPersonViewModel" />
</data>
<android.support.v7.widget.CardView ...>
class SwapiPeoplePagedListProvider(private val factory: DataSource.Factory<Int, Person?>) : PagedListProvider<Person?> {
override fun provide(): LiveData<PagedList<Person?>> {
return LivePagedListBuilder(factory, PagedList.Config.Builder()
.setEnablePlaceholders(false)
.setPageSize(20)
.setInitialLoadSizeHint(20)
.build()
).setFetchExecutor(createFetchExecutor())
#!/bin/bash
for i in "${@:3}"
do
echo "generating $i x $i icon..."
sips -z $i $i $1 --out $2_$i.png
done
class Foo {
public void showNotification(String _subText,
String _bigContentTitle,
String _bigText) {
String channelId = "channelId";
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId);
notificationBuilder.setAutoCancel(true);
@Marchuck
Marchuck / LoginViewController.swift
Last active January 8, 2019 12:22
passing data for new screen using prepare for segue
class LoginViewController {
var userName: String = "joe@doe.com"
let HOME_SEGUE = "HOME_SEGUE"
let FORGOT_PASSWORD_SEGUE = "FORGOT_PASSWORD_SEGUE"
func startHomeScreen(){
self.performSegue(withIdentifier: HOME_SEGUE, sender: self)