diff --git a/touch/build.gradle b/touch/build.gradle index e10ffcf5..66faf1ea 100644 --- a/touch/build.gradle +++ b/touch/build.gradle @@ -79,3 +79,4 @@ dependencies { + diff --git a/touch/src/main/java/de/nicidienase/chaosflix/touch/activities/BrowseActivity.java b/touch/src/main/java/de/nicidienase/chaosflix/touch/activities/BrowseActivity.java index 6ec532c2..78b41333 100644 --- a/touch/src/main/java/de/nicidienase/chaosflix/touch/activities/BrowseActivity.java +++ b/touch/src/main/java/de/nicidienase/chaosflix/touch/activities/BrowseActivity.java @@ -16,6 +16,7 @@ import de.nicidienase.chaosflix.common.entities.recording.Event; import de.nicidienase.chaosflix.touch.adapters.ItemRecyclerViewAdapter; import de.nicidienase.chaosflix.touch.ConferenceGroupsFragmentPager; import de.nicidienase.chaosflix.touch.fragments.ConferencesBrowseFragment; +import de.nicidienase.chaosflix.touch.fragments.EventDetailsFragment; import de.nicidienase.chaosflix.touch.fragments.EventsFragment; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; @@ -25,7 +26,10 @@ import io.reactivex.disposables.Disposable; * Created by felix on 17.09.17. */ -public class BrowseActivity extends TouchBaseActivity implements ItemRecyclerViewAdapter.OnListFragmentInteractionListener{ +public class BrowseActivity extends TouchBaseActivity implements + ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener, + EventsFragment.OnEventsListFragmentInteractionListener, + EventDetailsFragment.OnEventDetailsFragmentInteractionListener{ private static final String TAG = BrowseActivity.class.getSimpleName(); CompositeDisposable mDisposables = new CompositeDisposable(); @@ -56,41 +60,51 @@ public class BrowseActivity extends TouchBaseActivity implements ItemRecyclerVie mDisposables.dispose(); } - @Override - public void onListFragmentInteraction(Object item) { - if(item instanceof Conference){ - Conference con = (Conference) item; - Disposable disposable = getApiServiceObservable() - .subscribe(mediaApiService -> { - mediaApiService.getConference(con.getApiID()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(conference -> { - EventsFragment eventsFragment = EventsFragment.newInstance(getNumColumns()); - eventsFragment.setContent(conference); - FragmentManager fm = getSupportFragmentManager(); - Fragment oldFragment = fm.findFragmentById(R.id.fragment_container); - - TransitionInflater transitionInflater = TransitionInflater.from(this); - oldFragment.setExitTransition( - transitionInflater.inflateTransition(android.R.transition.fade)); - eventsFragment.setEnterTransition( - transitionInflater.inflateTransition(android.R.transition.slide_right)); - - FragmentTransaction ft = fm.beginTransaction(); - ft.replace(R.id.fragment_container,eventsFragment); - ft.addToBackStack(null); - ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); - ft.commit(); - }); - }); - mDisposables.add(disposable); - } else if (item instanceof Event){ - Event event = (Event) item; - // TODO show event details - } - } - private int getNumColumns() { return getResources().getInteger(R.integer.num_columns); } + + @Override + public void onConferenceSelected(Conference con) { + Disposable disposable = getApiServiceObservable() + .subscribe(mediaApiService -> { + mediaApiService.getConference(con.getApiID()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(conference -> { + EventsFragment eventsFragment = EventsFragment.newInstance(conference,getNumColumns()); + updateFragment(eventsFragment); + }); + }); + mDisposables.add(disposable); + } + + @Override + public void onEventSelected(Event e) { + Disposable disposable = getApiServiceObservable() + .subscribe(mediaApiService -> { + mediaApiService.getEvent(e.getApiID()) + .subscribe(event -> { + EventDetailsFragment detailsFragment = EventDetailsFragment.newInstance(event); + updateFragment(detailsFragment); + }); + }); + mDisposables.add(disposable); + } + + private void updateFragment(Fragment fragment) { + FragmentManager fm = getSupportFragmentManager(); + Fragment oldFragment = fm.findFragmentById(R.id.fragment_container); + + TransitionInflater transitionInflater = TransitionInflater.from(this); + oldFragment.setExitTransition( + transitionInflater.inflateTransition(android.R.transition.fade)); + fragment.setEnterTransition( + transitionInflater.inflateTransition(android.R.transition.slide_right)); + + FragmentTransaction ft = fm.beginTransaction(); + ft.replace(R.id.fragment_container, fragment); + ft.addToBackStack(null); + ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); + ft.commit(); + } } diff --git a/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/ConferenceRecyclerViewAdapter.java b/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/ConferenceRecyclerViewAdapter.java index 51db6ea9..456d2432 100644 --- a/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/ConferenceRecyclerViewAdapter.java +++ b/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/ConferenceRecyclerViewAdapter.java @@ -5,11 +5,15 @@ import com.bumptech.glide.Glide; import java.util.List; import de.nicidienase.chaosflix.common.entities.recording.Conference; +import de.nicidienase.chaosflix.touch.fragments.ConferencesBrowseFragment; public class ConferenceRecyclerViewAdapter extends ItemRecyclerViewAdapter { - public ConferenceRecyclerViewAdapter(List items, OnListFragmentInteractionListener listener) { - super(items, listener); + private final ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener mListener; + + public ConferenceRecyclerViewAdapter(List items, ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener listener) { + super(items); + mListener = listener; } @@ -25,9 +29,7 @@ public class ConferenceRecyclerViewAdapter extends ItemRecyclerViewAdapter { if (null != mListener) { - // Notify the active callbacks interface (the activity, if the - // fragment is attached to one) that an item has been selected. - mListener.onListFragmentInteraction(holder.mItem); + mListener.onConferenceSelected((Conference) holder.mItem); } }); } diff --git a/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/EventRecyclerViewAdapter.java b/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/EventRecyclerViewAdapter.java index eba4f84b..aa0d6428 100644 --- a/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/EventRecyclerViewAdapter.java +++ b/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/EventRecyclerViewAdapter.java @@ -3,17 +3,19 @@ package de.nicidienase.chaosflix.touch.adapters; import com.bumptech.glide.Glide; import java.util.Collections; -import java.util.List; import de.nicidienase.chaosflix.common.entities.recording.Conference; import de.nicidienase.chaosflix.common.entities.recording.Event; +import de.nicidienase.chaosflix.touch.fragments.EventsFragment; public class EventRecyclerViewAdapter extends ItemRecyclerViewAdapter { private final boolean areTagsUsefull; + private final EventsFragment.OnEventsListFragmentInteractionListener mListener; - public EventRecyclerViewAdapter(Conference conference, OnListFragmentInteractionListener listener) { - super(conference.getEvents(), listener); + public EventRecyclerViewAdapter(Conference conference, EventsFragment.OnEventsListFragmentInteractionListener listener) { + super(conference.getEvents()); + mListener = listener; areTagsUsefull = conference.areTagsUsefull(); Collections.sort(mItems,(o1, o2) -> o1.getTitle().compareTo(o2.getTitle())); } @@ -42,9 +44,7 @@ public class EventRecyclerViewAdapter extends ItemRecyclerViewAdapter { holder.mView.setOnClickListener(v -> { if (null != mListener) { - // Notify the active callbacks interface (the activity, if the - // fragment is attached to one) that an item has been selected. - mListener.onListFragmentInteraction(holder.mItem); + mListener.onEventSelected((Event) holder.mItem); } }); } diff --git a/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/ItemRecyclerViewAdapter.java b/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/ItemRecyclerViewAdapter.java index 0b4f6acf..53ecdc3d 100644 --- a/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/ItemRecyclerViewAdapter.java +++ b/touch/src/main/java/de/nicidienase/chaosflix/touch/adapters/ItemRecyclerViewAdapter.java @@ -14,11 +14,9 @@ import de.nicidienase.chaosflix.R; public abstract class ItemRecyclerViewAdapter extends RecyclerView.Adapter { protected final List mItems; - protected final OnListFragmentInteractionListener mListener; - public ItemRecyclerViewAdapter(List items, OnListFragmentInteractionListener listener) { + public ItemRecyclerViewAdapter(List items) { mItems = items; - mListener = listener; } @Override @@ -56,8 +54,4 @@ public abstract class ItemRecyclerViewAdapter extends RecyclerView.Adapter mItmes = new ArrayList<>(); public ConferenceGroupFragment() { @@ -74,8 +74,8 @@ public class ConferenceGroupFragment extends Fragment { @Override public void onAttach(Context context) { super.onAttach(context); - if (context instanceof ItemRecyclerViewAdapter.OnListFragmentInteractionListener) { - mListener = (ItemRecyclerViewAdapter.OnListFragmentInteractionListener) context; + if (context instanceof ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener) { + mListener = (ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener) context; } else { throw new RuntimeException(context.toString() + " must implement OnListFragmentInteractionListener"); diff --git a/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/ConferencesBrowseFragment.java b/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/ConferencesBrowseFragment.java index 158c5f70..769191d2 100644 --- a/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/ConferencesBrowseFragment.java +++ b/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/ConferencesBrowseFragment.java @@ -23,7 +23,7 @@ public class ConferencesBrowseFragment extends Fragment { private static final String ARG_COLUMN_COUNT = "column-count"; private int mColumnCount = 1; - private ItemRecyclerViewAdapter.OnListFragmentInteractionListener mListener; + private OnConferenceListFragmentInteractionListener mListener; private ConferencesWrapper conferencesWrapper; public ConferencesBrowseFragment() { @@ -69,8 +69,8 @@ public class ConferencesBrowseFragment extends Fragment { @Override public void onAttach(Context context) { super.onAttach(context); - if (context instanceof ItemRecyclerViewAdapter.OnListFragmentInteractionListener) { - mListener = (ItemRecyclerViewAdapter.OnListFragmentInteractionListener) context; + if (context instanceof OnConferenceListFragmentInteractionListener) { + mListener = (OnConferenceListFragmentInteractionListener) context; } else { throw new RuntimeException(context.toString() + " must implement OnListFragmentInteractionListener"); @@ -82,4 +82,8 @@ public class ConferencesBrowseFragment extends Fragment { super.onDetach(); mListener = null; } + + public interface OnConferenceListFragmentInteractionListener{ + void onConferenceSelected(Conference conference); + } } diff --git a/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/EventDetailsFragment.java b/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/EventDetailsFragment.java new file mode 100644 index 00000000..ec2bdb13 --- /dev/null +++ b/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/EventDetailsFragment.java @@ -0,0 +1,69 @@ +package de.nicidienase.chaosflix.touch.fragments; + +import android.content.Context; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import de.nicidienase.chaosflix.R; +import de.nicidienase.chaosflix.common.entities.recording.Event; + +public class EventDetailsFragment extends Fragment { + private static final String EVENT_PARAM = "event_param"; + + private OnEventDetailsFragmentInteractionListener mListener; + private Event mEvent; + + public EventDetailsFragment() { + // Required empty public constructor + } + + public static EventDetailsFragment newInstance(Event event) { + EventDetailsFragment fragment = new EventDetailsFragment(); + Bundle args = new Bundle(); + args.putParcelable(EVENT_PARAM,event); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mEvent = getArguments().getParcelable(EVENT_PARAM); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_event_details, container, false); + // TODO setup Content + return view; + } + + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof OnEventDetailsFragmentInteractionListener) { + mListener = (OnEventDetailsFragmentInteractionListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnFragmentInteractionListener"); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + public interface OnEventDetailsFragmentInteractionListener { + void onEventSelected(Event event); + } +} diff --git a/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/EventsFragment.java b/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/EventsFragment.java index 71339f56..ff2ede1e 100644 --- a/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/EventsFragment.java +++ b/touch/src/main/java/de/nicidienase/chaosflix/touch/fragments/EventsFragment.java @@ -12,9 +12,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import java.util.ArrayList; -import java.util.List; - import de.nicidienase.chaosflix.R; import de.nicidienase.chaosflix.common.entities.recording.Conference; import de.nicidienase.chaosflix.common.entities.recording.Event; @@ -25,8 +22,9 @@ public class EventsFragment extends Fragment { private static final String ARG_COLUMN_COUNT = "column-count"; + private static final String ARG_CONFERENCE = "conference"; private int mColumnCount = 1; - private ItemRecyclerViewAdapter.OnListFragmentInteractionListener mListener; + private OnEventsListFragmentInteractionListener mListener; private Conference mConference; private CharSequence mPreviousTitle; private ActionBar mActionBar; @@ -34,14 +32,11 @@ public class EventsFragment extends Fragment { public EventsFragment() { } - public void setContent(Conference conference){ - mConference = conference; - } - - public static EventsFragment newInstance(int columnCount) { + public static EventsFragment newInstance(Conference conference, int columnCount) { EventsFragment fragment = new EventsFragment(); Bundle args = new Bundle(); args.putInt(ARG_COLUMN_COUNT, columnCount); + args.putParcelable(ARG_CONFERENCE, conference); fragment.setArguments(args); return fragment; } @@ -51,6 +46,7 @@ public class EventsFragment extends Fragment { super.onCreate(savedInstanceState); if (getArguments() != null) { mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT); + mConference = getArguments().getParcelable(ARG_CONFERENCE); } } @@ -58,7 +54,7 @@ public class EventsFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.recycler_view_layout, container, false); - + mActionBar.setTitle(mConference.getTitle()); // Set the adapter if (view instanceof RecyclerView) { Context context = view.getContext(); @@ -81,9 +77,8 @@ public class EventsFragment extends Fragment { super.onAttach(context); mActionBar = ((AppCompatActivity) context).getSupportActionBar(); mPreviousTitle = mActionBar.getTitle(); - mActionBar.setTitle(mConference.getTitle()); - if (context instanceof ItemRecyclerViewAdapter.OnListFragmentInteractionListener) { - mListener = (ItemRecyclerViewAdapter.OnListFragmentInteractionListener) context; + if (context instanceof OnEventsListFragmentInteractionListener) { + mListener = (OnEventsListFragmentInteractionListener) context; } else { throw new RuntimeException(context.toString() + " must implement OnListFragmentInteractionListener"); @@ -97,5 +92,8 @@ public class EventsFragment extends Fragment { mActionBar.setTitle(mPreviousTitle); } + public interface OnEventsListFragmentInteractionListener{ + void onEventSelected(Event event); + } } diff --git a/touch/src/main/res/layout/fragment_event_details.xml b/touch/src/main/res/layout/fragment_event_details.xml new file mode 100644 index 00000000..fe80a8c1 --- /dev/null +++ b/touch/src/main/res/layout/fragment_event_details.xml @@ -0,0 +1,13 @@ + + + + + +