Skip to content

Instantly share code, notes, and snippets.

View SavedStateHandle.java
public final class SavedStateHandle {
final Map<String, Object> mRegular;
...
private final SavedStateProvider mSavedStateProvider = new SavedStateProvider() {
@NonNull
public Bundle saveState() {
Set<String> keySet = mRegular.keySet();
ArrayList keys = new ArrayList(keySet.size());
ArrayList value = new ArrayList(keys.size());
...
View SavedStateHandle.java
public final class SavedStateHandle {
static SavedStateHandle createHandle(@Nullable Bundle restoredState,
@Nullable Bundle defaultState) {
...
Map<String, Object> state = new HashMap<>();
if (defaultState != null) {
for (String key : defaultState.keySet()) {
state.put(key, defaultState.get(key));
}
}
View SavedStateViewModelFactory.java
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull String key, @NonNull Class<T> modelClass) {
boolean isAndroidViewModel = AndroidViewModel.class.isAssignableFrom(modelClass);
...
Constructor<T> constructor;
constructor = ... // Define ViewModel Constructor
// Case 1, SavedStateHandleが不要の場合
if (constructor == null) {
return mFactory.create(modelClass);
View ActivityViewModelLazy.kt
@MainThread
inline fun <reified VM : ViewModel> ComponentActivity.viewModels(
noinline factoryProducer: (() -> Factory)? = null
): Lazy<VM> {
val factoryPromise = factoryProducer ?: {
defaultViewModelProviderFactory
}
return ViewModelLazy(VM::class, { viewModelStore }, factoryPromise)
}
View Fragment.java
@NonNull
@Override
public ViewModelProvider.Factory getDefaultViewModelProviderFactory() {
...
mDefaultFactory = new SavedStateViewModelFactory(
requireActivity().getApplication(),
this,
getArguments()); // ◀ Fragmentに渡されたArgumentを代入
}
return mDefaultFactory;
View ComponentActivity.java
@NonNull
@Override
public ViewModelProvider.Factory getDefaultViewModelProviderFactory() {
...
mDefaultFactory = new SavedStateViewModelFactory(
getApplication(),
this,
getIntent() != null ? getIntent().getExtras() : null); // ◀ Activityに渡されたArgumentを代入
...
return mDefaultFactory;
View ViewModelProvider.java
public class ViewModelProvider {
...
private final Factory mFactory;
private final ViewModelStore mViewModelStore;
// ① Use ViewModelStoreOwner
public ViewModelProvider(@NonNull ViewModelStoreOwner owner) {
this(owner.getViewModelStore(), owner instanceof HasDefaultViewModelProviderFactory
? ((HasDefaultViewModelProviderFactory) owner).getDefaultViewModelProviderFactory()
: NewInstanceFactory.getInstance());
}
@Pluu
Pluu / RxJava-Part3.md
Last active Jun 11, 2020
RxJava 3장 ~ 연산자와 변환
View RxJava-Part3.md

RxJava 3장 ~ 연산자와 변환

핵심 연산자: 매핑과 필터링

map

Operator Wiki : Link

View DrawInsetsFrameLayout.java
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
View FloatLabelLayout.java
/*
* Copyright (C) 2014 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software