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
const val MIN_PASSWORD_LENGTH = 8 // 최소 비밀번호 길이 | |
const val TAG = "LoginViewModel" | |
class LoginViewModel(lifecycleOwner: LifecycleOwner, private val loginActions: LoginActions) : ViewModel(), LifecycleObserver, LoginFragment.LoginFragmentActions { | |
val loginData = MutableLiveData<LoginViewData>() // view data | |
private val fbAuthListener: FirebaseAuth.AuthStateListener //로그인 상태 리스너 | |
private val fbAuth = FirebaseAuth.getInstance() // firebase auth 객체 |
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 ProductAdapter mProductAdapter; | |
private ListFragmentBinding mBinding; | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, | |
@Nullable Bundle savedInstanceState) { | |
// 바인딩 생성 | |
mBinding = DataBindingUtil.inflate(inflater, R.layout.list_fragment, container, 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
private void subscribeUi(ProductListViewModel viewModel) { | |
// Update the list when the data changes | |
viewModel.getProducts().observe(this, new Observer<List<ProductEntity>>() { | |
@Override | |
public void onChanged(@Nullable List<ProductEntity> myProducts) { | |
if (myProducts != null) { | |
mBinding.setIsLoading(false); | |
mProductAdapter.setProductList(myProducts); | |
} else { | |
mBinding.setIsLoading(true); |
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
<!-- 레이아웃 태그 선언 --> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<data> | |
<variable | |
name="isLoading" | |
type="boolean" /> | |
</data> |
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 MyLocationListener implements LifecycleObserver { | |
private boolean enabled = false; | |
public MyLocationListener(Context context, Lifecycle lifecycle, Callback callback) { | |
... | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) // lifecycle event : onStart() | |
void start() { | |
if (enabled) { | |
// connect |
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 MyLocationListener { | |
public MyLocationListener(Context context, Callback callback) { | |
// ... | |
} | |
void start() { | |
// connect to system location service | |
} | |
void stop() { |
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 LiveDataTimerViewModel extends ViewModel { | |
private static final int ONE_SECOND = 1000; //1초 스케줄링 (카운팅) | |
private MutableLiveData<Long> mElapsedTime = new MutableLiveData<>(); // LiveData | |
private long mInitialTime; | |
public LiveDataTimerViewModel() { | |
mInitialTime = SystemClock.elapsedRealtime(); |