mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-23 04:43:07 +00:00
Got all Conferences in BrowseConferenceFragment
This commit is contained in:
parent
768beeca78
commit
c3f90d0419
11 changed files with 236 additions and 54 deletions
|
@ -91,7 +91,7 @@ public class CardPresenter extends Presenter {
|
|||
|
||||
Glide.with(viewHolder.view.getContext())
|
||||
.load(conference.getLogoUrl())
|
||||
.centerCrop()
|
||||
.fitCenter()
|
||||
.error(mDefaultCardImage)
|
||||
.into(cardView.getMainImageView());
|
||||
}
|
||||
|
@ -100,7 +100,6 @@ public class CardPresenter extends Presenter {
|
|||
|
||||
@Override
|
||||
public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {
|
||||
Log.d(TAG, "onUnbindViewHolder");
|
||||
ImageCardView cardView = (ImageCardView) viewHolder.view;
|
||||
// Remove references to images so that the garbage collector can free up memory
|
||||
cardView.setBadgeImage(null);
|
||||
|
|
|
@ -13,6 +13,7 @@ public class ConferencesActivity extends Activity {
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_conferences);
|
||||
// setContentView(R.layout.activity_conferences_grid);
|
||||
setContentView(R.layout.activity_conferences_browse);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ public class Conference extends SugarRecord implements Parcelable,Comparable<Con
|
|||
|
||||
@Override
|
||||
public int compareTo(Conference conference) {
|
||||
return updatedAt.compareTo(conference.getUpdatedAt());
|
||||
return getSlug().compareTo(conference.getSlug());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
package de.nicidienase.chaosflix.entities;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by felix on 17.03.17.
|
||||
*/
|
||||
|
||||
public class Conferences{
|
||||
private static final String TAG = Conferences.class.getSimpleName();
|
||||
private List<Conference> conferences;
|
||||
|
||||
private final String CONGRESS = "congress";
|
||||
private final String EVENTS = "events";
|
||||
private final String CONFERENCES = "conferences";
|
||||
private final String DEFAULT_CONFERENCE_GROUP = "other Conferences";
|
||||
private final String DEFAULT_CONFERENCE_GROUP = "other conferences";
|
||||
private final String EVENT_GROUP = "Events";
|
||||
|
||||
private Map<String,List<Conference>> conferenceMap = null;
|
||||
private int MIN_NUM_CONS = 1;
|
||||
|
||||
|
||||
public List<Conference> getConferences() {
|
||||
|
@ -33,12 +39,24 @@ public class Conferences{
|
|||
List<Conference> list;
|
||||
switch (split[0]){
|
||||
case CONGRESS:
|
||||
getListForTag(CONGRESS).add(conference);
|
||||
if(split[1].endsWith("sendezentrum")){
|
||||
getListForTag("sendezentrum").add(conference);
|
||||
} else {
|
||||
getListForTag(CONGRESS).add(conference);
|
||||
}
|
||||
break;
|
||||
case CONFERENCES:
|
||||
switch (split.length){
|
||||
case 2:
|
||||
getListForTag(DEFAULT_CONFERENCE_GROUP).add(conference);
|
||||
if(split[1].startsWith("camp")){
|
||||
getListForTag("camp").add(conference);
|
||||
} else if(split[1].startsWith("sigint")){
|
||||
getListForTag("sigint").add(conference);
|
||||
} else if(split[1].startsWith("eh")){
|
||||
getListForTag("eh").add(conference);
|
||||
} else {
|
||||
getListForTag(DEFAULT_CONFERENCE_GROUP).add(conference);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
getListForTag(split[1]).add(conference);
|
||||
|
@ -51,9 +69,29 @@ public class Conferences{
|
|||
case EVENTS:
|
||||
getListForTag(EVENT_GROUP).add(conference);
|
||||
break;
|
||||
default:
|
||||
getListForTag(conference.getSlug()).add(conference);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Conference> other = conferenceMap.get(DEFAULT_CONFERENCE_GROUP);
|
||||
Set<String> keySet = conferenceMap.keySet();
|
||||
List<String> removeList = new ArrayList<>();
|
||||
for(String tag: keySet){
|
||||
if(!tag.equals(DEFAULT_CONFERENCE_GROUP)){
|
||||
List<Conference> list = conferenceMap.get(tag);
|
||||
Collections.sort(list);
|
||||
Collections.reverse(list);
|
||||
if(list.size() <= MIN_NUM_CONS){
|
||||
Log.d(TAG,"To few conferences: " + tag);
|
||||
other.addAll(list);
|
||||
removeList.add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(String key:removeList){
|
||||
conferenceMap.remove(key);
|
||||
}
|
||||
return conferenceMap;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
package de.nicidienase.chaosflix.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v17.leanback.app.BrowseFragment;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
import android.support.v17.leanback.widget.HeaderItem;
|
||||
import android.support.v17.leanback.widget.ListRow;
|
||||
import android.support.v17.leanback.widget.ListRowPresenter;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import de.nicidienase.chaosflix.CardPresenter;
|
||||
import de.nicidienase.chaosflix.entities.Conference;
|
||||
import de.nicidienase.chaosflix.entities.Conferences;
|
||||
import de.nicidienase.chaosflix.network.MediaCCCClient;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Created by felix on 21.03.17.
|
||||
*/
|
||||
|
||||
public class ConferencesBrowseFragment extends BrowseFragment {
|
||||
|
||||
private static final String TAG = ConferencesBrowseFragment.class.getSimpleName();
|
||||
private MediaCCCClient mMediaCCCClient;
|
||||
private ArrayObjectAdapter mRowsAdapter;
|
||||
private Map<String, List<Conference>> mConferences;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mMediaCCCClient = new MediaCCCClient();
|
||||
|
||||
mMediaCCCClient.listConferences().enqueue(new Callback<Conferences>() {
|
||||
@Override
|
||||
public void onResponse(Call<Conferences> call, Response<Conferences> response) {
|
||||
Conferences body = response.body();
|
||||
mConferences = body.getConferencesBySeries();
|
||||
mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
|
||||
CardPresenter cardPresenter = new CardPresenter();
|
||||
Set<String> keySet = mConferences.keySet();
|
||||
for(String tag: getOrderedConferencesList()){
|
||||
if(keySet.contains(tag)){
|
||||
addRow(mConferences, cardPresenter,tag);
|
||||
}
|
||||
}
|
||||
for(String tag: keySet){
|
||||
if(!getOrderedConferencesList().contains(tag)){
|
||||
addRow(mConferences, cardPresenter, tag);
|
||||
}
|
||||
}
|
||||
setAdapter(mRowsAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Conferences> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener(this));
|
||||
}
|
||||
|
||||
private void addRow(Map<String, List<Conference>> conferences, CardPresenter cardPresenter, String tag) {
|
||||
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
|
||||
listRowAdapter.addAll(0,conferences.get(tag));
|
||||
HeaderItem header = new HeaderItem(getStringForTag(tag));
|
||||
mRowsAdapter.add(new ListRow(header, listRowAdapter));
|
||||
}
|
||||
|
||||
private String getStringForTag(String tag) {
|
||||
switch (tag){
|
||||
case "congress":
|
||||
return "Congress";
|
||||
case "sendezentrum":
|
||||
return "Sendezentrum";
|
||||
case "camp":
|
||||
return "Camp";
|
||||
case "broadcast/chaosradio":
|
||||
return "Chaosradio";
|
||||
case "eh":
|
||||
return "Easterhegg";
|
||||
case "gpn":
|
||||
return "GPN";
|
||||
case "froscon":
|
||||
return "FrOSCon";
|
||||
case "mrmcd":
|
||||
return "MRMCD";
|
||||
case "sigint":
|
||||
return "SIGINT";
|
||||
case "datenspuren":
|
||||
return "Datenspuren";
|
||||
case "fiffkon":
|
||||
return "FifFKon";
|
||||
case "other mConferences":
|
||||
return "other Conferences";
|
||||
case "blinkenlights":
|
||||
return "Blinkenlights";
|
||||
case "chaoscologne":
|
||||
return "1c2 Chaos Cologne";
|
||||
case "cryptocon":
|
||||
return "CryptoCon";
|
||||
case "other conferences":
|
||||
return "Other Conferences";
|
||||
case "denog":
|
||||
return "DENOG";
|
||||
case "vcfb":
|
||||
return "Vintage Computing Festival Berlin";
|
||||
case "hackover":
|
||||
return "Hackover";
|
||||
case "netzpolitik":
|
||||
return "Das ist Netzpolitik!";
|
||||
default:
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getOrderedConferencesList(){
|
||||
return Arrays.asList(new String[]{"congress", "sendezentrum", "camp", "broadcast/chaosradio", "eh", "gpn", "froscon", "mrmcd",
|
||||
"sigint", "datenspuren", "fiffkon", "cryptocon"});
|
||||
}
|
||||
}
|
|
@ -1,25 +1,15 @@
|
|||
package de.nicidienase.chaosflix.fragments;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v17.leanback.app.VerticalGridFragment;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
import android.support.v17.leanback.widget.CursorObjectAdapter;
|
||||
import android.support.v17.leanback.widget.ImageCardView;
|
||||
import android.support.v17.leanback.widget.ObjectAdapter;
|
||||
import android.support.v17.leanback.widget.OnItemViewClickedListener;
|
||||
import android.support.v17.leanback.widget.Presenter;
|
||||
import android.support.v17.leanback.widget.Row;
|
||||
import android.support.v17.leanback.widget.RowPresenter;
|
||||
import android.support.v17.leanback.widget.VerticalGridPresenter;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import de.nicidienase.chaosflix.CardPresenter;
|
||||
import de.nicidienase.chaosflix.activities.EventsActivity;
|
||||
import de.nicidienase.chaosflix.entities.Conference;
|
||||
import de.nicidienase.chaosflix.entities.Conferences;
|
||||
import de.nicidienase.chaosflix.network.MediaCCCClient;
|
||||
|
@ -72,26 +62,7 @@ public class ConferencesGridFragment extends VerticalGridFragment {
|
|||
}
|
||||
}, 500);
|
||||
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener());
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener(this));
|
||||
}
|
||||
|
||||
private final class ItemViewClickedListener implements OnItemViewClickedListener{
|
||||
|
||||
@Override
|
||||
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
if(item instanceof Conference){
|
||||
Conference conference = (Conference) item;
|
||||
// Start EventsActivity for this conference
|
||||
Intent i = new Intent(getActivity(), EventsActivity.class);
|
||||
i.putExtra(EventsActivity.CONFERENCE,conference);
|
||||
i.putExtra(EventsActivity.CONFERENCE_ID,conference.getApiID());
|
||||
// Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
// getActivity(),
|
||||
// ((ImageCardView) itemViewHolder.view).getMainImageView(),
|
||||
// EventsActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ public class EventsBrowseFragment extends BrowseFragment {
|
|||
}
|
||||
|
||||
private void setupEventListeners() {
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener());
|
||||
setOnItemViewClickedListener(new ItemViewClickedListener(this));
|
||||
setOnItemViewSelectedListener(new ItemViewSelectedListener());
|
||||
}
|
||||
|
||||
|
@ -202,21 +202,6 @@ public class EventsBrowseFragment extends BrowseFragment {
|
|||
mBackgroundTimer.schedule(new UpdateBackgroundTask(), BACKGROUND_UPDATE_DELAY);
|
||||
}
|
||||
|
||||
private final class ItemViewClickedListener implements OnItemViewClickedListener {
|
||||
@Override
|
||||
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
Event event = (Event) item;
|
||||
Intent i = new Intent(getActivity(), DetailsActivity.class);
|
||||
i.putExtra(DetailsActivity.EVENT,event);
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
getActivity(),
|
||||
((ImageCardView) itemViewHolder.view).getMainImageView(),
|
||||
DetailsActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
getActivity().startActivity(i, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
private final class ItemViewSelectedListener implements OnItemViewSelectedListener {
|
||||
@Override
|
||||
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package de.nicidienase.chaosflix.fragments;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v17.leanback.widget.ImageCardView;
|
||||
import android.support.v17.leanback.widget.OnItemViewClickedListener;
|
||||
import android.support.v17.leanback.widget.Presenter;
|
||||
import android.support.v17.leanback.widget.Row;
|
||||
import android.support.v17.leanback.widget.RowPresenter;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
|
||||
import de.nicidienase.chaosflix.activities.DetailsActivity;
|
||||
import de.nicidienase.chaosflix.activities.EventsActivity;
|
||||
import de.nicidienase.chaosflix.entities.Conference;
|
||||
import de.nicidienase.chaosflix.entities.Event;
|
||||
|
||||
/**
|
||||
* Created by felix on 21.03.17.
|
||||
*/
|
||||
final class ItemViewClickedListener implements OnItemViewClickedListener {
|
||||
|
||||
private Fragment fragment;
|
||||
|
||||
public ItemViewClickedListener(Fragment fragment) {
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
if (item instanceof Conference) {
|
||||
Conference conference = (Conference) item;
|
||||
// Start EventsActivity for this conference
|
||||
Intent i = new Intent(fragment.getActivity(), EventsActivity.class);
|
||||
i.putExtra(EventsActivity.CONFERENCE, conference);
|
||||
i.putExtra(EventsActivity.CONFERENCE_ID, conference.getApiID());
|
||||
// Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
// getActivity(),
|
||||
// ((ImageCardView) itemViewHolder.view).getMainImageView(),
|
||||
// EventsActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
fragment.startActivity(i);
|
||||
|
||||
} else if(item instanceof Event){
|
||||
Event event = (Event) item;
|
||||
Intent i = new Intent(fragment.getActivity(), DetailsActivity.class);
|
||||
i.putExtra(DetailsActivity.EVENT,event);
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
fragment.getActivity(),
|
||||
((ImageCardView) itemViewHolder.view).getMainImageView(),
|
||||
DetailsActivity.SHARED_ELEMENT_NAME).toBundle();
|
||||
fragment.getActivity().startActivity(i, bundle);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -242,7 +242,6 @@ public class VideoDetailsFragment extends DetailsFragment {
|
|||
@Override
|
||||
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
|
||||
RowPresenter.ViewHolder rowViewHolder, Row row) {
|
||||
|
||||
if (item instanceof Event) {
|
||||
Event event = (Event) item;
|
||||
Log.d(TAG, "Item: " + event.getTitle());
|
||||
|
|
6
app/src/main/res/layout/activity_conferences_browse.xml
Normal file
6
app/src/main/res/layout/activity_conferences_browse.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:name="de.nicidienase.chaosflix.fragments.ConferencesBrowseFragment"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
Loading…
Reference in a new issue