mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-23 12:53:08 +00:00
move ViewModel-factory
This commit is contained in:
parent
12c417f24e
commit
258a0b5f41
3 changed files with 18 additions and 7 deletions
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue