implement saving of bookmarks
|
@ -5,11 +5,10 @@ import android.arch.lifecycle.ViewModel;
|
|||
import android.arch.lifecycle.ViewModelProvider;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.nicidienase.chaosflix.common.entities.PlaybackProgress;
|
||||
import de.nicidienase.chaosflix.common.entities.WatchlistItem;
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Conference;
|
||||
import de.nicidienase.chaosflix.common.entities.recording.ConferencesWrapper;
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Event;
|
||||
|
@ -123,6 +122,28 @@ public class ChaosflixViewModel extends ViewModel {
|
|||
}).subscribeOn(Schedulers.io());
|
||||
}
|
||||
|
||||
public void createBookmark(int apiId){
|
||||
WatchlistItem bookmark = getBookmark(apiId);
|
||||
if(bookmark != null){
|
||||
bookmark = new WatchlistItem(apiId);
|
||||
bookmark.save();
|
||||
} else {
|
||||
// Bookmark already exists
|
||||
}
|
||||
}
|
||||
|
||||
public WatchlistItem getBookmark(int apiId){
|
||||
return WatchlistItem.findById(WatchlistItem.class, apiId);
|
||||
}
|
||||
|
||||
public boolean bookmarkExists(int apiId) {
|
||||
return getBookmark(apiId) != null;
|
||||
}
|
||||
|
||||
public boolean removeBookmark(int apiID) {
|
||||
return getBookmark(apiID).delete();
|
||||
}
|
||||
|
||||
public static class Factory extends ViewModelProvider.NewInstanceFactory{
|
||||
|
||||
private final String recordingUrl;
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package de.nicidienase.chaosflix.touch.fragments;
|
||||
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.transition.Transition;
|
||||
import android.transition.TransitionInflater;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
@ -22,6 +23,7 @@ import de.nicidienase.chaosflix.R;
|
|||
import de.nicidienase.chaosflix.common.entities.recording.Event;
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Recording;
|
||||
import de.nicidienase.chaosflix.databinding.FragmentEventDetailsNewBinding;
|
||||
import de.nicidienase.chaosflix.touch.ChaosflixViewModel;
|
||||
|
||||
public class EventDetailsFragment extends Fragment {
|
||||
private static final String TAG = EventDetailsFragment.class.getSimpleName();
|
||||
|
@ -31,6 +33,7 @@ public class EventDetailsFragment extends Fragment {
|
|||
private Event mEvent;
|
||||
|
||||
private boolean appBarExpanded;
|
||||
private ChaosflixViewModel viewModel;
|
||||
|
||||
public static EventDetailsFragment newInstance(Event event) {
|
||||
EventDetailsFragment fragment = new EventDetailsFragment();
|
||||
|
@ -53,6 +56,7 @@ public class EventDetailsFragment extends Fragment {
|
|||
if (getArguments() != null) {
|
||||
mEvent = getArguments().getParcelable(EVENT_PARAM);
|
||||
}
|
||||
viewModel = ViewModelProviders.of(this).get(ChaosflixViewModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -127,6 +131,10 @@ public class EventDetailsFragment extends Fragment {
|
|||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
if(viewModel.bookmarkExists(mEvent.getApiID())){
|
||||
menu.findItem(R.id.action_bookmark).setVisible(false);
|
||||
menu.findItem(R.id.action_unbookmark).setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -139,9 +147,21 @@ public class EventDetailsFragment extends Fragment {
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()){
|
||||
case R.id.play:
|
||||
case R.id.action_play:
|
||||
play();
|
||||
return true;
|
||||
case R.id.action_bookmark:
|
||||
viewModel.createBookmark(mEvent.getApiID());
|
||||
return true;
|
||||
case R.id.action_unbookmark:
|
||||
boolean success = viewModel.removeBookmark(mEvent.getApiID());
|
||||
if(!success){
|
||||
Snackbar.make(item.getActionView(),"Error removing Bookmark",Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
return true;
|
||||
case R.id.action_download:
|
||||
Snackbar.make(item.getActionView(),"Start download",Snackbar.LENGTH_LONG).show();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
BIN
touch/src/main/res/drawable-hdpi/ic_bookmark.png
Normal file
After Width: | Height: | Size: 310 B |
BIN
touch/src/main/res/drawable-hdpi/ic_bookmark_border.png
Normal file
After Width: | Height: | Size: 412 B |
BIN
touch/src/main/res/drawable-hdpi/ic_download.png
Normal file
After Width: | Height: | Size: 250 B |
BIN
touch/src/main/res/drawable-mdpi/ic_bookmark.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
touch/src/main/res/drawable-mdpi/ic_bookmark_border.png
Normal file
After Width: | Height: | Size: 296 B |
BIN
touch/src/main/res/drawable-mdpi/ic_download.png
Normal file
After Width: | Height: | Size: 184 B |
BIN
touch/src/main/res/drawable-xhdpi/ic_bookmark.png
Normal file
After Width: | Height: | Size: 375 B |
BIN
touch/src/main/res/drawable-xhdpi/ic_bookmark_border.png
Normal file
After Width: | Height: | Size: 496 B |
BIN
touch/src/main/res/drawable-xhdpi/ic_download.png
Normal file
After Width: | Height: | Size: 253 B |
BIN
touch/src/main/res/drawable-xxhdpi/ic_bookmark.png
Normal file
After Width: | Height: | Size: 643 B |
BIN
touch/src/main/res/drawable-xxhdpi/ic_bookmark_border.png
Normal file
After Width: | Height: | Size: 853 B |
BIN
touch/src/main/res/drawable-xxhdpi/ic_download.png
Normal file
After Width: | Height: | Size: 400 B |
|
@ -3,8 +3,24 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/play"
|
||||
android:id="@+id/action_play"
|
||||
android:icon="@android:drawable/ic_media_play"
|
||||
android:title="Play"
|
||||
android:title="@string/play"
|
||||
app:showAsAction="always"/>
|
||||
<item
|
||||
android:id="@+id/action_bookmark"
|
||||
android:title="@string/bookmark"
|
||||
android:icon="@drawable/ic_bookmark_border"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/action_unbookmark"
|
||||
android:icon="@drawable/ic_bookmark"
|
||||
android:title="Remove Bookmark"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/action_download"
|
||||
android:title="@string/download"
|
||||
android:icon="@drawable/ic_download"
|
||||
app:showAsAction="ifRoom"/>
|
||||
</menu>
|
|
@ -6,4 +6,7 @@
|
|||
<string name="card">card</string>
|
||||
<string name="select_option">Select Media Option</string>
|
||||
<string name="search_title">Search</string>
|
||||
<string name="download">Download</string>
|
||||
<string name="bookmark">Bookmark</string>
|
||||
<string name="play">Play</string>
|
||||
</resources>
|