提交 0962a910 编写于 作者: A amitshekhariitbhu

Add Seeding Functionality

上级 eef5ae37
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2017 MINDORKS NEXTGEN PRIVATE LIMITED
~
~ Licensed under the Apache License, Version 2.0 (the "License");
......@@ -33,6 +32,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.main.MainActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait" />
</application>
</manifest>
\ No newline at end of file
......@@ -41,11 +41,11 @@ public abstract class BaseViewModel<V> {
this.mCompositeDisposable = compositeDisposable;
}
public void onAttach(V callback) {
public void setCallback(V callback) {
this.mCallback = callback;
}
public void onDetach() {
public void onDestroy() {
mCompositeDisposable.dispose();
}
......
......@@ -24,6 +24,7 @@ import android.os.Bundle;
import com.mindorks.framework.mvvm.R;
import com.mindorks.framework.mvvm.databinding.ActivitySplashBinding;
import com.mindorks.framework.mvvm.ui.base.BaseActivity;
import com.mindorks.framework.mvvm.ui.main.MainActivity;
import javax.inject.Inject;
......@@ -33,7 +34,7 @@ import butterknife.ButterKnife;
* Created by amitshekhar on 08/07/17.
*/
public class SplashActivity extends BaseActivity {
public class SplashActivity extends BaseActivity implements SplashCallback {
@Inject
SplashViewModel mSplashViewModel;
......@@ -55,5 +56,22 @@ public class SplashActivity extends BaseActivity {
setUnBinder(ButterKnife.bind(this));
binding.setViewmodel(mSplashViewModel);
mSplashViewModel.setCallback(this);
mSplashViewModel.startSeeding();
}
@Override
protected void onDestroy() {
super.onDestroy();
mSplashViewModel.onDestroy();
}
@Override
public void onSeedingComplete() {
Intent intent = MainActivity.getStartIntent(SplashActivity.this);
startActivity(intent);
finish();
}
}
/*
* Copyright (C) 2017 MINDORKS NEXTGEN PRIVATE LIMITED
*
* 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
*
* https://mindorks.com/license/apache-v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.mindorks.framework.mvvm.ui.splash;
/**
* Created by amitshekhar on 08/07/17.
*/
public interface SplashCallback {
void onSeedingComplete();
}
......@@ -20,13 +20,16 @@ import com.mindorks.framework.mvvm.data.DataManager;
import com.mindorks.framework.mvvm.ui.base.BaseViewModel;
import com.mindorks.framework.mvvm.utils.rx.SchedulerProvider;
import io.reactivex.ObservableSource;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
/**
* Created by amitshekhar on 08/07/17.
*/
public class SplashViewModel extends BaseViewModel {
public class SplashViewModel extends BaseViewModel<SplashCallback> {
public SplashViewModel(DataManager dataManager,
SchedulerProvider schedulerProvider,
......@@ -34,4 +37,29 @@ public class SplashViewModel extends BaseViewModel {
super(dataManager, schedulerProvider, compositeDisposable);
}
public void startSeeding() {
getCompositeDisposable().add(getDataManager()
.seedDatabaseQuestions()
.flatMap(new Function<Boolean, ObservableSource<Boolean>>() {
@Override
public ObservableSource<Boolean> apply(Boolean aBoolean) throws Exception {
return getDataManager().seedDatabaseOptions();
}
})
.subscribeOn(getSchedulerProvider().io())
.observeOn(getSchedulerProvider().ui())
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
getCallback().onSeedingComplete();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
getCallback().onSeedingComplete();
}
}));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册