add eventDetailsFragment and refactor

This commit is contained in:
Felix 2017-09-19 19:43:23 +02:00
parent b40a1098ad
commit 9ea551108d
10 changed files with 167 additions and 72 deletions

View file

@ -79,3 +79,4 @@ dependencies {

View file

@ -16,6 +16,7 @@ import de.nicidienase.chaosflix.common.entities.recording.Event;
import de.nicidienase.chaosflix.touch.adapters.ItemRecyclerViewAdapter; import de.nicidienase.chaosflix.touch.adapters.ItemRecyclerViewAdapter;
import de.nicidienase.chaosflix.touch.ConferenceGroupsFragmentPager; import de.nicidienase.chaosflix.touch.ConferenceGroupsFragmentPager;
import de.nicidienase.chaosflix.touch.fragments.ConferencesBrowseFragment; import de.nicidienase.chaosflix.touch.fragments.ConferencesBrowseFragment;
import de.nicidienase.chaosflix.touch.fragments.EventDetailsFragment;
import de.nicidienase.chaosflix.touch.fragments.EventsFragment; import de.nicidienase.chaosflix.touch.fragments.EventsFragment;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
@ -25,7 +26,10 @@ import io.reactivex.disposables.Disposable;
* Created by felix on 17.09.17. * 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(); private static final String TAG = BrowseActivity.class.getSimpleName();
CompositeDisposable mDisposables = new CompositeDisposable(); CompositeDisposable mDisposables = new CompositeDisposable();
@ -56,41 +60,51 @@ public class BrowseActivity extends TouchBaseActivity implements ItemRecyclerVie
mDisposables.dispose(); 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() { private int getNumColumns() {
return getResources().getInteger(R.integer.num_columns); 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();
}
} }

View file

@ -5,11 +5,15 @@ import com.bumptech.glide.Glide;
import java.util.List; import java.util.List;
import de.nicidienase.chaosflix.common.entities.recording.Conference; import de.nicidienase.chaosflix.common.entities.recording.Conference;
import de.nicidienase.chaosflix.touch.fragments.ConferencesBrowseFragment;
public class ConferenceRecyclerViewAdapter extends ItemRecyclerViewAdapter<Conference> { public class ConferenceRecyclerViewAdapter extends ItemRecyclerViewAdapter<Conference> {
public ConferenceRecyclerViewAdapter(List<Conference> items, OnListFragmentInteractionListener listener) { private final ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener mListener;
super(items, listener);
public ConferenceRecyclerViewAdapter(List<Conference> items, ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener listener) {
super(items);
mListener = listener;
} }
@ -25,9 +29,7 @@ public class ConferenceRecyclerViewAdapter extends ItemRecyclerViewAdapter<Confe
holder.mView.setOnClickListener(v -> { holder.mView.setOnClickListener(v -> {
if (null != mListener) { if (null != mListener) {
// Notify the active callbacks interface (the activity, if the mListener.onConferenceSelected((Conference) holder.mItem);
// fragment is attached to one) that an item has been selected.
mListener.onListFragmentInteraction(holder.mItem);
} }
}); });
} }

View file

@ -3,17 +3,19 @@ package de.nicidienase.chaosflix.touch.adapters;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import de.nicidienase.chaosflix.common.entities.recording.Conference; import de.nicidienase.chaosflix.common.entities.recording.Conference;
import de.nicidienase.chaosflix.common.entities.recording.Event; import de.nicidienase.chaosflix.common.entities.recording.Event;
import de.nicidienase.chaosflix.touch.fragments.EventsFragment;
public class EventRecyclerViewAdapter extends ItemRecyclerViewAdapter<Event> { public class EventRecyclerViewAdapter extends ItemRecyclerViewAdapter<Event> {
private final boolean areTagsUsefull; private final boolean areTagsUsefull;
private final EventsFragment.OnEventsListFragmentInteractionListener mListener;
public EventRecyclerViewAdapter(Conference conference, OnListFragmentInteractionListener listener) { public EventRecyclerViewAdapter(Conference conference, EventsFragment.OnEventsListFragmentInteractionListener listener) {
super(conference.getEvents(), listener); super(conference.getEvents());
mListener = listener;
areTagsUsefull = conference.areTagsUsefull(); areTagsUsefull = conference.areTagsUsefull();
Collections.sort(mItems,(o1, o2) -> o1.getTitle().compareTo(o2.getTitle())); Collections.sort(mItems,(o1, o2) -> o1.getTitle().compareTo(o2.getTitle()));
} }
@ -42,9 +44,7 @@ public class EventRecyclerViewAdapter extends ItemRecyclerViewAdapter<Event> {
holder.mView.setOnClickListener(v -> { holder.mView.setOnClickListener(v -> {
if (null != mListener) { if (null != mListener) {
// Notify the active callbacks interface (the activity, if the mListener.onEventSelected((Event) holder.mItem);
// fragment is attached to one) that an item has been selected.
mListener.onListFragmentInteraction(holder.mItem);
} }
}); });
} }

View file

@ -14,11 +14,9 @@ import de.nicidienase.chaosflix.R;
public abstract class ItemRecyclerViewAdapter<T> extends RecyclerView.Adapter<ItemRecyclerViewAdapter.ViewHolder> { public abstract class ItemRecyclerViewAdapter<T> extends RecyclerView.Adapter<ItemRecyclerViewAdapter.ViewHolder> {
protected final List<T> mItems; protected final List<T> mItems;
protected final OnListFragmentInteractionListener mListener;
public ItemRecyclerViewAdapter(List<T> items, OnListFragmentInteractionListener listener) { public ItemRecyclerViewAdapter(List<T> items) {
mItems = items; mItems = items;
mListener = listener;
} }
@Override @Override
@ -56,8 +54,4 @@ public abstract class ItemRecyclerViewAdapter<T> extends RecyclerView.Adapter<It
return super.toString() + " '" + mTitleText.getText() + "'"; return super.toString() + " '" + mTitleText.getText() + "'";
} }
} }
public interface OnListFragmentInteractionListener {
void onListFragmentInteraction(Object item);
}
} }

View file

@ -23,7 +23,7 @@ public class ConferenceGroupFragment extends Fragment {
private static final String ARG_COLUMN_COUNT = "column-count"; private static final String ARG_COLUMN_COUNT = "column-count";
private int mColumnCount = 1; private int mColumnCount = 1;
private ItemRecyclerViewAdapter.OnListFragmentInteractionListener mListener; private ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener mListener;
private List<Conference> mItmes = new ArrayList<>(); private List<Conference> mItmes = new ArrayList<>();
public ConferenceGroupFragment() { public ConferenceGroupFragment() {
@ -74,8 +74,8 @@ public class ConferenceGroupFragment extends Fragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
if (context instanceof ItemRecyclerViewAdapter.OnListFragmentInteractionListener) { if (context instanceof ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener) {
mListener = (ItemRecyclerViewAdapter.OnListFragmentInteractionListener) context; mListener = (ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener) context;
} else { } else {
throw new RuntimeException(context.toString() throw new RuntimeException(context.toString()
+ " must implement OnListFragmentInteractionListener"); + " must implement OnListFragmentInteractionListener");

View file

@ -23,7 +23,7 @@ public class ConferencesBrowseFragment extends Fragment {
private static final String ARG_COLUMN_COUNT = "column-count"; private static final String ARG_COLUMN_COUNT = "column-count";
private int mColumnCount = 1; private int mColumnCount = 1;
private ItemRecyclerViewAdapter.OnListFragmentInteractionListener mListener; private OnConferenceListFragmentInteractionListener mListener;
private ConferencesWrapper conferencesWrapper; private ConferencesWrapper conferencesWrapper;
public ConferencesBrowseFragment() { public ConferencesBrowseFragment() {
@ -69,8 +69,8 @@ public class ConferencesBrowseFragment extends Fragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
if (context instanceof ItemRecyclerViewAdapter.OnListFragmentInteractionListener) { if (context instanceof OnConferenceListFragmentInteractionListener) {
mListener = (ItemRecyclerViewAdapter.OnListFragmentInteractionListener) context; mListener = (OnConferenceListFragmentInteractionListener) context;
} else { } else {
throw new RuntimeException(context.toString() throw new RuntimeException(context.toString()
+ " must implement OnListFragmentInteractionListener"); + " must implement OnListFragmentInteractionListener");
@ -82,4 +82,8 @@ public class ConferencesBrowseFragment extends Fragment {
super.onDetach(); super.onDetach();
mListener = null; mListener = null;
} }
public interface OnConferenceListFragmentInteractionListener{
void onConferenceSelected(Conference conference);
}
} }

View file

@ -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);
}
}

View file

@ -12,9 +12,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
import de.nicidienase.chaosflix.R; import de.nicidienase.chaosflix.R;
import de.nicidienase.chaosflix.common.entities.recording.Conference; import de.nicidienase.chaosflix.common.entities.recording.Conference;
import de.nicidienase.chaosflix.common.entities.recording.Event; 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_COLUMN_COUNT = "column-count";
private static final String ARG_CONFERENCE = "conference";
private int mColumnCount = 1; private int mColumnCount = 1;
private ItemRecyclerViewAdapter.OnListFragmentInteractionListener mListener; private OnEventsListFragmentInteractionListener mListener;
private Conference mConference; private Conference mConference;
private CharSequence mPreviousTitle; private CharSequence mPreviousTitle;
private ActionBar mActionBar; private ActionBar mActionBar;
@ -34,14 +32,11 @@ public class EventsFragment extends Fragment {
public EventsFragment() { public EventsFragment() {
} }
public void setContent(Conference conference){ public static EventsFragment newInstance(Conference conference, int columnCount) {
mConference = conference;
}
public static EventsFragment newInstance(int columnCount) {
EventsFragment fragment = new EventsFragment(); EventsFragment fragment = new EventsFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt(ARG_COLUMN_COUNT, columnCount); args.putInt(ARG_COLUMN_COUNT, columnCount);
args.putParcelable(ARG_CONFERENCE, conference);
fragment.setArguments(args); fragment.setArguments(args);
return fragment; return fragment;
} }
@ -51,6 +46,7 @@ public class EventsFragment extends Fragment {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (getArguments() != null) { if (getArguments() != null) {
mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT); 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, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.recycler_view_layout, container, false); View view = inflater.inflate(R.layout.recycler_view_layout, container, false);
mActionBar.setTitle(mConference.getTitle());
// Set the adapter // Set the adapter
if (view instanceof RecyclerView) { if (view instanceof RecyclerView) {
Context context = view.getContext(); Context context = view.getContext();
@ -81,9 +77,8 @@ public class EventsFragment extends Fragment {
super.onAttach(context); super.onAttach(context);
mActionBar = ((AppCompatActivity) context).getSupportActionBar(); mActionBar = ((AppCompatActivity) context).getSupportActionBar();
mPreviousTitle = mActionBar.getTitle(); mPreviousTitle = mActionBar.getTitle();
mActionBar.setTitle(mConference.getTitle()); if (context instanceof OnEventsListFragmentInteractionListener) {
if (context instanceof ItemRecyclerViewAdapter.OnListFragmentInteractionListener) { mListener = (OnEventsListFragmentInteractionListener) context;
mListener = (ItemRecyclerViewAdapter.OnListFragmentInteractionListener) context;
} else { } else {
throw new RuntimeException(context.toString() throw new RuntimeException(context.toString()
+ " must implement OnListFragmentInteractionListener"); + " must implement OnListFragmentInteractionListener");
@ -97,5 +92,8 @@ public class EventsFragment extends Fragment {
mActionBar.setTitle(mPreviousTitle); mActionBar.setTitle(mPreviousTitle);
} }
public interface OnEventsListFragmentInteractionListener{
void onEventSelected(Event event);
}
} }

View file

@ -0,0 +1,13 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.nicidienase.chaosflix.touch.fragments.EventDetailsFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Event Details"/>
</FrameLayout>