move ViewModel-factory

This commit is contained in:
Felix 2017-10-04 22:06:46 +02:00
parent 12c417f24e
commit 258a0b5f41
3 changed files with 18 additions and 7 deletions

View file

@ -3,10 +3,13 @@ package de.nicidienase.chaosflix.touch;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.ViewModel;
import android.arch.lifecycle.ViewModelProvider;
import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
import java.util.List;
import de.nicidienase.chaosflix.R;
import de.nicidienase.chaosflix.common.entities.PlaybackProgress;
import de.nicidienase.chaosflix.common.entities.WatchlistItem;
import de.nicidienase.chaosflix.common.entities.recording.Conference;
@ -31,9 +34,21 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class ChaosflixViewModel extends ViewModel {
private static final String TAG = ChaosflixViewModel.class.getSimpleName();
private static Factory factory;
private final StreamingService mStreamingApi;
private final RecordingService mRecordingApi;
public static ChaosflixViewModel.Factory getFactory(Context context){
if(factory == null){
Resources res = context.getResources();
factory = new Factory(
res.getString(R.string.api_media_ccc_url),
res.getString(R.string.streaming_media_ccc_url));
}
return factory;
}
public ChaosflixViewModel(String recordingUrl, String streamingUrl){
OkHttpClient client = new OkHttpClient();
GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create();

View file

@ -50,12 +50,8 @@ public class BrowseActivity extends AppCompatActivity implements
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_container_layout);
Resources res = getResources();
ChaosflixViewModel.Factory factory =
new ChaosflixViewModel.Factory(
res.getString(R.string.api_media_ccc_url),
res.getString(R.string.streaming_media_ccc_url));
mViewModel = ViewModelProviders.of(this,factory).get(ChaosflixViewModel.class);
mViewModel = ViewModelProviders.of(this,ChaosflixViewModel.getFactory(this))
.get(ChaosflixViewModel.class);
if(savedInstanceState == null){
ConferencesTabBrowseFragment browseFragment

View file

@ -56,7 +56,7 @@ public class EventDetailsFragment extends Fragment {
if (getArguments() != null) {
mEvent = getArguments().getParcelable(EVENT_PARAM);
}
viewModel = ViewModelProviders.of(this).get(ChaosflixViewModel.class);
viewModel = ViewModelProviders.of(this,ChaosflixViewModel.getFactory(getContext())).get(ChaosflixViewModel.class);
}
@Override