Skip to content

Instantly share code, notes, and snippets.

View daeun1012's full-sized avatar
🏄‍♀️
mad for sufing

tatiana.76(타티아나) daeun1012

🏄‍♀️
mad for sufing
View GitHub Profile
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 객체
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);
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);
<!-- 레이아웃 태그 선언 -->
<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>
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
class MyLocationListener {
public MyLocationListener(Context context, Callback callback) {
// ...
}
void start() {
// connect to system location service
}
void stop() {
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();