Skip to content
This repository has been archived by the owner on Nov 22, 2017. It is now read-only.

Commit

Permalink
backup renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
ppamorim committed Jan 25, 2015
1 parent 8ea582b commit ae82e03
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 19 deletions.
11 changes: 11 additions & 0 deletions sample/res/layout/activity_grid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"/>
</LinearLayout>
18 changes: 18 additions & 0 deletions sample/res/layout/video_row.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/frame_image"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<TextView
android:id="@+id/frame_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>

</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,72 @@
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import com.github.pedrovgs.sample.R;
import com.github.pedrovgs.sample.viewmodel.TvShowViewModel;
import com.github.pedrovgs.sample.viewmodel.VideoViewModel;
import com.pedrogomez.renderers.RendererAdapter;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import javax.inject.Inject;

/**
* @author Pedro Vicente Gómez Sánchez.
*/
public class MainActivity extends Activity {
public class MainActivity extends DIFragmentActivity {

@InjectView(R.id.grid_view) GridView gridView;

@Inject RendererAdapter<VideoViewModel> adapter;

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_grid);
ButterKnife.inject(this);
initializeGridView();
}

@OnClick(R.id.iv_places) void openSimpleSampleActivity() {
Intent intent = new Intent(this, PlacesSampleActivity.class);
startActivity(intent);
}
// @OnClick(R.id.iv_places) void openSimpleSampleActivity() {
// Intent intent = new Intent(this, PlacesSampleActivity.class);
// startActivity(intent);
// }
//
// @OnClick(R.id.iv_tv_shows) void openTvShowsSampleActivity() {
// Intent intent = new Intent(this, TvShowsActivity.class);
// startActivity(intent);
// }
//
// @OnClick(R.id.iv_youtube) void openYoutubeSampleActivity() {
// Intent intent = new Intent(this, YoutubeSampleActivity.class);
// startActivity(intent);
// }
//
// @OnClick(R.id.iv_video) void openVideoSampleActivity() {
// Intent intent = new Intent(this, VideoSampleActivity.class);
// startActivity(intent);
// }

@OnClick(R.id.iv_tv_shows) void openTvShowsSampleActivity() {
Intent intent = new Intent(this, TvShowsActivity.class);
startActivity(intent);
}
/**
* Initialize GridView with some injected data and configure OnItemClickListener.
*/
private void initializeGridView() {
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) {

}
});
}

@OnClick(R.id.iv_youtube) void openYoutubeSampleActivity() {
Intent intent = new Intent(this, YoutubeSampleActivity.class);
startActivity(intent);
}

@OnClick(R.id.iv_video) void openVideoSampleActivity() {
Intent intent = new Intent(this, VideoSampleActivity.class);
startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import butterknife.OnClick;
import com.github.pedrovgs.DraggableListener;
import com.github.pedrovgs.DraggableView;
import com.github.pedrovgs.sample.DraggablePanelApplication;
import com.github.pedrovgs.sample.R;
import com.squareup.picasso.Picasso;

Expand Down Expand Up @@ -57,6 +58,7 @@ public class VideoSampleActivity extends FragmentActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_sample);
((DraggablePanelApplication) getApplication()).inject(this);
ButterKnife.inject(this);
initializeVideoView();
initializePoster();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@
import android.content.Context;
import android.view.LayoutInflater;
import com.github.pedrovgs.sample.DraggablePanelApplication;
import com.github.pedrovgs.sample.activity.MainActivity;
import com.github.pedrovgs.sample.activity.PlacesSampleActivity;
import com.github.pedrovgs.sample.activity.TvShowsActivity;
import com.github.pedrovgs.sample.renderer.PlaceRenderer;
import com.github.pedrovgs.sample.renderer.TvShowRenderer;
import com.github.pedrovgs.sample.renderer.VideoRenderer;
import com.github.pedrovgs.sample.renderer.rendererbuilder.PlacesCollectionRendererBuilder;
import com.github.pedrovgs.sample.renderer.rendererbuilder.TvShowCollectionRendererBuilder;
import com.github.pedrovgs.sample.renderer.rendererbuilder.VideoCollectionRendererBuilder;
import com.github.pedrovgs.sample.viewmodel.PlaceCollectionViewModel;
import com.github.pedrovgs.sample.viewmodel.PlaceViewModel;
import com.github.pedrovgs.sample.viewmodel.TvShowCollectionViewModel;
import com.github.pedrovgs.sample.viewmodel.TvShowViewModel;
import com.github.pedrovgs.sample.viewmodel.VideoCollectionViewModel;
import com.github.pedrovgs.sample.viewmodel.VideoViewModel;
import com.pedrogomez.renderers.Renderer;
import com.pedrogomez.renderers.RendererAdapter;
import dagger.Module;
Expand All @@ -42,7 +47,7 @@
* @author Pedro Vicente Gómez Sánchez.
*/
@Module(injects = {
PlacesSampleActivity.class, TvShowsActivity.class, DraggablePanelApplication.class
PlacesSampleActivity.class, TvShowsActivity.class, DraggablePanelApplication.class, MainActivity.class
}) public class MainModule {

private final Application application;
Expand Down Expand Up @@ -110,4 +115,27 @@ public MainModule(Application application) {
return new RendererAdapter<TvShowViewModel>(layoutInflater, tvShowCollectionRendererBuilder,
tvShowCollectionViewModel);
}

/**
* Provisioning of a RendererBuilder implementation to work with video Gridview. More
* information in this library: {@link https://github.com/pedrovgs/Renderers}
*/
@Provides protected VideoCollectionRendererBuilder provideVideoCollectionRendererBuilder(
Context context) {
List<Renderer<VideoViewModel>> prototypes = new LinkedList<Renderer<VideoViewModel>>();
prototypes.add(new VideoRenderer(context));
return new VideoCollectionRendererBuilder(prototypes);
}

/**
* Provisioning of a RendererAdapter implementation to work with video Gridview. More
* information in this library: {@link https://github.com/pedrovgs/Renderers}
*/
@Provides protected RendererAdapter<VideoViewModel> provideVideoRendererAdapter(
LayoutInflater layoutInflater,
VideoCollectionRendererBuilder videoCollectionRendererBuilder,
VideoCollectionViewModel videoCollectionViewModel) {
return new RendererAdapter<VideoViewModel>(layoutInflater, videoCollectionRendererBuilder,
videoCollectionViewModel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2014 Pedro Paulo de Amorim.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.pedrovgs.sample.renderer;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.pedrovgs.sample.R;
import com.github.pedrovgs.sample.viewmodel.VideoViewModel;
import com.pedrogomez.renderers.Renderer;
import com.squareup.picasso.Picasso;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
* Renderer implementation used to render video inside ListView or GridViews. More info in
* this link: {@link https://github.com/pedrovgs/Renderers}
*
* @author Pedro Paulo de Amorim.
*/
public class VideoRenderer extends Renderer<VideoViewModel> {

private Context context;

@InjectView(R.id.frame_image) ImageView frameImage;
@InjectView(R.id.frame_title) TextView frameTitle;

private int position;

public VideoRenderer(Context context) {
this.context = context;
}

/**
* Configure the position associated to this renderer.
*/
public void setPosition(int position) {
this.position = position;
}

/**
* Apply ButterKnife inject method to support view injections.
*/
@Override
protected void setUpView(View view) {
ButterKnife.inject(this, view);
}

@Override
protected void hookListeners(View rootView) {
//Empty
}

/**
* Inflate the layout associated to this renderer
*/
@Override
protected View inflate(LayoutInflater layoutInflater, ViewGroup viewGroup) {
return layoutInflater.inflate(R.layout.video_row, viewGroup, false);
}

/**
* Render the PlaceViewModel information.
*/
@Override
protected void render() {
VideoViewModel item = getContent();
frameTitle.setText(item.getTitle());
Picasso.with(context)
.load(item.getImage())
.placeholder(R.drawable.maps_placeholder)
.into(frameImage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.pedrovgs.sample.renderer;

import android.view.LayoutInflater;

import com.github.pedrovgs.sample.viewmodel.EpisodeViewModel;
import com.github.pedrovgs.sample.viewmodel.VideoViewModel;
import com.pedrogomez.renderers.AdapteeCollection;
import com.pedrogomez.renderers.Renderer;
import com.pedrogomez.renderers.RendererAdapter;
import com.pedrogomez.renderers.RendererBuilder;

/**
* Created by pedro on 1/24/15.
*/
public class VideoRendererAdapter extends RendererAdapter<VideoViewModel> {

public VideoRendererAdapter(LayoutInflater layoutInflater, RendererBuilder rendererBuilder, AdapteeCollection<VideoViewModel> collection) {
super(layoutInflater, rendererBuilder, collection);
}

/**
* Override method used to update the EpisodeRenderer position.
*/
@Override protected void updateRendererExtraValues(VideoViewModel content,
Renderer<VideoViewModel> renderer, int position) {
super.updateRendererExtraValues(content, renderer, position);
VideoRenderer episodeRenderer = (VideoRenderer) renderer;
episodeRenderer.setPosition(position);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.pedrovgs.sample.renderer.rendererbuilder;

import android.content.Context;

import com.github.pedrovgs.sample.renderer.VideoRenderer;
import com.github.pedrovgs.sample.viewmodel.VideoViewModel;
import com.pedrogomez.renderers.Renderer;
import com.pedrogomez.renderers.RendererBuilder;

import java.util.Collection;

import javax.inject.Inject;

/**
* RendererBuilder implementation created to map VideoViewModel with VideoRenderer
* implementations. More info in this link: {@link https://github.com/pedrovgs/Renderers}
*
* @author Pedro Paulo de Amorim
*/
public class VideoCollectionRendererBuilder extends RendererBuilder<VideoViewModel> {

public VideoCollectionRendererBuilder(Collection<Renderer<VideoViewModel>> prototypes) {
super(prototypes);
}

@Override protected Class getPrototypeClass(VideoViewModel tvShowViewModel) {
return VideoRenderer.class;
}
}
Loading

0 comments on commit ae82e03

Please sign in to comment.