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
//region model | |
sealed interface NotesUiModel : UiModel { | |
object Loading : NotesUiModel | |
data class Data( | |
val notes: List<Note>, | |
val events: EventHandler<Event> | |
) : NotesUiModel { | |
data class Note( |
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
public class MainActivity extends AppCompatActivity { | |
List<Adapter.ViewHolder> listeners = new ArrayList<>(); | |
private boolean visible = true; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); |
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
recyclerView.addItemDecoration(new SpacingItemDecoration(context, 16)); |
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
public class SpacingItemDecoration extends RecyclerView.ItemDecoration { | |
private int spacing; | |
public SpacingItemDecoration(Context context, int padding) { | |
DisplayMetrics metrics = context.getResources().getDisplayMetrics(); | |
spacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, padding, metrics); | |
} | |
@Override | |
public final void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { |
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
<android.support.v7.widget.RecyclerView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:padding="16dp" | |
android:clipToPadding="false" /> |
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
Observable.just(1, 2, 3, 4, 5) | |
.groupBy(i -> i % 2 == 0 ? "even" : "odd") | |
.subscribe(obs -> { | |
if (obs.getKey().equals("even")) { | |
obs.subscribe(i -> System.out.println("even: " + i)); | |
} else { | |
obs.subscribe(i -> System.out.println("odd: " + i)); | |
} | |
}); |
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
BehaviorSubject<Integer> timerSubject = BehaviorSubject.create(1); | |
timerSubject | |
.switchMap(interval -> Observable.timer(interval, TimeUnit.SECONDS, Schedulers.newThread())) | |
.flatMap(i -> Observable.just(randomInt())) | |
.doOnNext(timerSubject::onNext) | |
.subscribe(System.out::println); |
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
List<Item> allBucket = ... | |
List<Item> genderBucket = ... | |
List<Item> sizeBucket = ... | |
List<Item> colorBucket = ... | |
List<Item> recommendations = new ArrayList<>(); | |
picker(recommendations, limit, colorBucket, sizeBucket, genderBucket, allBucket); | |
private <T> int picker(List<T> src, List<T> dst, int limit) { | |
Iterator<T> iterator = src.iterator(); |
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 <T> int picker(List<T> src, List<T> dst, int limit) { | |
Iterator<T> iterator = src.iterator(); | |
while (iterator.hasNext() && limit > 0) { | |
dst.add(iterator.next()); | |
limit--; | |
} | |
return limit; | |
} |
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
for (int i = 0, remaining = 5; i < colorBucket.size() && remaining > 0; i++, remaining--) { | |
... | |
} |
NewerOlder