This file contains hidden or 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
| /** | |
| * A data source that uses the before/after keys returned in page requests. | |
| */ | |
| class GithubPageKeyedDataSource : PageKeyedDataSource<Int, Item>() { | |
| override fun loadInitial(params: LoadInitialParams<Int>, | |
| callback: LoadInitialCallback<Int, Item>) { | |
| val currentPage = 1 | |
| val nextPage = currentPage + 1 |
This file contains hidden or 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
| /** | |
| * A data source that uses the "name" field of posts as the key for next/prev pages. | |
| */ | |
| class ItemKeyedSubredditDataSource : ItemKeyedDataSource<String, RedditPost>() { | |
| override fun loadInitial(params: LoadInitialParams<String>, | |
| callback: LoadInitialCallback<RedditPost>) { | |
| val request = redditApi.getTop( | |
| subreddit = subredditName, |
This file contains hidden or 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
| import 'package:flutter/material.dart'; | |
| void main() => runApp(new MyApp()); // Application | |
| class MyApp extends StatelessWidget { // MainActivity | |
| @override | |
| Widget build(BuildContext context) { // onCreate | |
| return new MaterialApp( | |
| title: 'Flutter Demo', // app_name |
This file contains hidden or 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
| quantity.addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() { | |
| override fun onPropertyChanged(p0: Observable, p1: Int) { | |
| presenter.onItemQuantityChange(cartItem, p0.get()) | |
| } | |
| }) |
This file contains hidden or 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
| <Spinner | |
| android:id="@+id/item_quantity_spinner" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="8dp" | |
| android:background="@drawable/ic_spinner_bg" | |
| android:gravity="center_vertical" | |
| android:paddingStart="4dp" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| android:textSize="16sp" |
This file contains hidden or 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 InverseSpinnerBindings { | |
| @BindingAdapter("selectedValue") | |
| fun Spinner.setSelectedValue(selectedValue: Any?) { | |
| setSpinnerValue(selectedValue) | |
| } | |
| @BindingAdapter("selectedValueAttrChanged") | |
| fun Spinner.setInverseBindingListener(inverseBindingListener: InverseBindingListener?) { | |
| setSpinnerInverseBindingListener(inverseBindingListener) |
This file contains hidden or 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
| <android.support.design.widget.FloatingActionButton | |
| android:id="@+id/add_to_cart_fab" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_gravity="bottom|end" | |
| android:layout_margin="16dp" | |
| android:onClick="@{() -> presenter.onAddToCartClick(model.cartItem)}" | |
| android:src="@drawable/ic_add_shopping_cart_white_24dp" | |
| android:tint="@android:color/white" /> |
This file contains hidden or 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
| <Spinner | |
| android:id="@+id/item_quantity_spinner" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="8dp" | |
| android:background="@drawable/ic_spinner_bg" | |
| android:gravity="center_vertical" | |
| android:paddingStart="4dp" | |
| android:textSize="16sp" | |
| app:entries="@{model.quantityEntries}" |
This file contains hidden or 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 SpinnerBindings { | |
| @BindingAdapter("entries") | |
| fun Spinner.setEntries(entries: List<Any>?) { | |
| setSpinnerEntries(entries) | |
| } | |
| @BindingAdapter("onItemSelected") | |
| fun Spinner.setItemSelectedListener(itemSelectedListener: ItemSelectedListener?) { | |
| setSpinnerItemSelectedListener(itemSelectedListener) |
This file contains hidden or 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 CartItemViewModel(var cartItem: CartItem, | |
| val name: ObservableField<String> = ObservableField(cartItem.name), | |
| val description: ObservableField<String> = ObservableField(cartItem.description), | |
| val image: ObservableField<Drawable> = ObservableField(cartItem.image), | |
| val price: ObservableField<Double> = ObservableField(cartItem.quantifiedPrice), | |
| val quantity: ObservableField<Int> = ObservableField(cartItem.quantity), | |
| val quantityEntries: ObservableField<List<Int>> = ObservableField(cartItem.maxQuantity.populateList())) { | |
| fun update(cartItem: CartItem) { | |
| this.cartItem = cartItem |
NewerOlder