mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-27 06:30:29 +00:00
try out LiveData
This commit is contained in:
parent
e363879708
commit
cd7039906e
2 changed files with 37 additions and 9 deletions
|
@ -1,5 +1,8 @@
|
|||
package de.nicidienase.chaosflix.touch;
|
||||
|
||||
import android.arch.lifecycle.LifecycleOwner;
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.lifecycle.Observer;
|
||||
import android.arch.lifecycle.ViewModel;
|
||||
import android.arch.lifecycle.ViewModelProvider;
|
||||
import android.arch.lifecycle.ViewModelStore;
|
||||
|
@ -7,6 +10,7 @@ import android.arch.lifecycle.ViewModelStoreOwner;
|
|||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -20,6 +24,8 @@ import de.nicidienase.chaosflix.common.network.RecordingService;
|
|||
import de.nicidienase.chaosflix.common.network.StreamingService;
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import retrofit2.Retrofit;
|
||||
|
@ -58,6 +64,18 @@ public class ChaosflixViewModel extends ViewModel {
|
|||
mStreamingApi = retrofigStreaming.create(StreamingService.class);
|
||||
}
|
||||
|
||||
public LiveData<ConferencesWrapper> getConferencesWrapperAsLiveData(){
|
||||
return new LiveData<ConferencesWrapper>() {
|
||||
@Override
|
||||
protected void onActive() {
|
||||
super.onActive();
|
||||
mRecordingApi.getConferences()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(conferencesWrapper -> setValue(conferencesWrapper));
|
||||
}
|
||||
};
|
||||
}
|
||||
public Observable<ConferencesWrapper> getConferencesWrapper() {
|
||||
return mRecordingApi.getConferences()
|
||||
.doOnError(throwable -> Log.d(TAG, String.valueOf(throwable.getCause())))
|
||||
|
|
|
@ -58,15 +58,25 @@ public class BrowseActivity extends AppCompatActivity implements
|
|||
mViewModel = ViewModelProviders.of(this,factory).get(ChaosflixViewModel.class);
|
||||
|
||||
if(savedInstanceState == null){
|
||||
mDisposables.add(mViewModel.getConferencesWrapper()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(conferencesWrapper -> {
|
||||
ConferencesTabBrowseFragment browseFragment
|
||||
= ConferencesTabBrowseFragment.newInstance(getNumColumns());
|
||||
mViewModel.getConferencesWrapperAsLiveData().observe(browseFragment,conferencesWrapper -> {
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.fragment_container,browseFragment);
|
||||
ft.setReorderingAllowed(true);
|
||||
ft.commit();
|
||||
}));
|
||||
});
|
||||
// mDisposables.add(mViewModel.getConferencesWrapper()
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .doOnError(throwable -> Log.d(TAG, String.valueOf(throwable.getCause())))
|
||||
// .subscribe(conferencesWrapper -> {
|
||||
// ConferencesTabBrowseFragment browseFragment
|
||||
// = ConferencesTabBrowseFragment.newInstance(getNumColumns());
|
||||
// FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
// ft.replace(R.id.fragment_container,browseFragment);
|
||||
// ft.setReorderingAllowed(true);
|
||||
// ft.commit();
|
||||
// }));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue