mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-23 12:53:08 +00:00
add eventDetailsFragment and refactor
This commit is contained in:
parent
b40a1098ad
commit
9ea551108d
10 changed files with 167 additions and 72 deletions
|
@ -79,3 +79,4 @@ dependencies {
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
private int getNumColumns() {
|
||||
return getResources().getInteger(R.integer.num_columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListFragmentInteraction(Object item) {
|
||||
if(item instanceof Conference){
|
||||
Conference con = (Conference) item;
|
||||
public void onConferenceSelected(Conference con) {
|
||||
Disposable disposable = getApiServiceObservable()
|
||||
.subscribe(mediaApiService -> {
|
||||
mediaApiService.getConference(con.getApiID())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(conference -> {
|
||||
EventsFragment eventsFragment = EventsFragment.newInstance(getNumColumns());
|
||||
eventsFragment.setContent(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));
|
||||
eventsFragment.setEnterTransition(
|
||||
fragment.setEnterTransition(
|
||||
transitionInflater.inflateTransition(android.R.transition.slide_right));
|
||||
|
||||
FragmentTransaction ft = fm.beginTransaction();
|
||||
ft.replace(R.id.fragment_container,eventsFragment);
|
||||
ft.replace(R.id.fragment_container, fragment);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Conference> {
|
||||
|
||||
public ConferenceRecyclerViewAdapter(List<Conference> items, OnListFragmentInteractionListener listener) {
|
||||
super(items, listener);
|
||||
private final ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener mListener;
|
||||
|
||||
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 -> {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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<Event> {
|
||||
|
||||
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<Event> {
|
|||
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,11 +14,9 @@ import de.nicidienase.chaosflix.R;
|
|||
public abstract class ItemRecyclerViewAdapter<T> extends RecyclerView.Adapter<ItemRecyclerViewAdapter.ViewHolder> {
|
||||
|
||||
protected final List<T> mItems;
|
||||
protected final OnListFragmentInteractionListener mListener;
|
||||
|
||||
public ItemRecyclerViewAdapter(List<T> items, OnListFragmentInteractionListener listener) {
|
||||
public ItemRecyclerViewAdapter(List<T> items) {
|
||||
mItems = items;
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,8 +54,4 @@ public abstract class ItemRecyclerViewAdapter<T> extends RecyclerView.Adapter<It
|
|||
return super.toString() + " '" + mTitleText.getText() + "'";
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnListFragmentInteractionListener {
|
||||
void onListFragmentInteraction(Object item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ConferenceGroupFragment extends Fragment {
|
|||
|
||||
private static final String ARG_COLUMN_COUNT = "column-count";
|
||||
private int mColumnCount = 1;
|
||||
private ItemRecyclerViewAdapter.OnListFragmentInteractionListener mListener;
|
||||
private ConferencesBrowseFragment.OnConferenceListFragmentInteractionListener mListener;
|
||||
private List<Conference> 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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
13
touch/src/main/res/layout/fragment_event_details.xml
Normal file
13
touch/src/main/res/layout/fragment_event_details.xml
Normal 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>
|
Loading…
Reference in a new issue