Skip to content

Commit

Permalink
Show trailer thumbnail (#29) and fix #28
Browse files Browse the repository at this point in the history
  • Loading branch information
enginebai committed Apr 13, 2015
1 parent eab9ac4 commit 982690a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="play-services-appstate-7.0.0" level="project" />
<orderEntry type="library" exported="" name="android-async-http-1.4.6" level="project" />
<orderEntry type="library" exported="" name="butterknife-6.1.0" level="project" />
<orderEntry type="library" exported="" name="android-async-http-1.4.6" level="project" />
<orderEntry type="library" exported="" name="play-services-drive-7.0.0" level="project" />
<orderEntry type="library" exported="" name="play-services-analytics-7.0.0" level="project" />
<orderEntry type="library" exported="" name="play-services-games-7.0.0" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "com.moviebomber"
minSdkVersion 16
targetSdkVersion 21
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
Expand Down
56 changes: 47 additions & 9 deletions app/src/main/java/com/moviebomber/ui/activity/TrailerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubeThumbnailLoader;
import com.google.android.youtube.player.YouTubeThumbnailView;
import com.moviebomber.R;
import com.moviebomber.model.api.Trailer;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.ButterKnife;
import butterknife.InjectView;
Expand All @@ -34,9 +40,10 @@ public class TrailerActivity extends ActionBarActivity {
ImageView mImageTrailer;
@InjectView(R.id.text_trailer_title)
TextView mTextTitle;
@InjectView(R.id.list_trailer)
ListView mListTrailer;

private List<Trailer> mTrailerList;
private YouTubeThumbnailLoader mThumbnailLoader;
private Map<View, YouTubeThumbnailLoader> mListThumbnailLoaderMap = new HashMap<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -49,7 +56,14 @@ protected void onCreate(Bundle savedInstanceState) {
this.getSupportActionBar().setTitle("");
}
if (this.getIntent() != null) {
this.mTrailerList = this.getIntent().getParcelableArrayListExtra(EXTRA_TRAILER_LIST);
List<Trailer> mTrailerList = this.getIntent().getParcelableArrayListExtra(EXTRA_TRAILER_LIST);
List<Trailer> newTrailerList = new ArrayList<>();
// filter playerlist or user
for (Trailer t : mTrailerList) {
if (t.getUrl().contains("v="))
newTrailerList.add(t);
}
this.mListTrailer.setAdapter(new TrailerAdatper(this, R.layout.item_trailer, newTrailerList));
}
}

Expand All @@ -76,26 +90,50 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

class TrailerAdatper extends ArrayAdapter<Trailer> {
class TrailerAdatper extends ArrayAdapter<Trailer> implements YouTubeThumbnailView.OnInitializedListener {
TrailerAdatper(Context context, int resource, List<Trailer> objects) {
super(context, resource, objects);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
final ViewHolder holder;
String videoUrl = this.getItem(position).getUrl();
Logger.wtf(videoUrl);
String id = videoUrl.split("=")[1];
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_trailer, parent, false);
holder = new ViewHolder(convertView);
holder.mImageTrailer.setTag(id);
holder.mImageTrailer.initialize(KEY, this);
convertView.setTag(holder);
} else
holder = (ViewHolder)convertView.getTag();

} else {
holder = (ViewHolder) convertView.getTag();
YouTubeThumbnailLoader loader = mListThumbnailLoaderMap.get(holder.mImageTrailer);
if (loader == null) {
holder.mImageTrailer.setTag(id);
} else {
loader.setVideo(id);
}
}
holder.mTextTitle.setText(this.getItem(position).getTitle());
return convertView;
}

@Override
public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader youTubeThumbnailLoader) {
String videoId = (String)youTubeThumbnailView.getTag();
mListThumbnailLoaderMap.put(youTubeThumbnailView, youTubeThumbnailLoader);
youTubeThumbnailLoader.setVideo(videoId);
}

@Override
public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {

}

class ViewHolder {
@InjectView(R.id.image_trailer)
@InjectView(R.id.image_trailer_thumbnail)
YouTubeThumbnailView mImageTrailer;
@InjectView(R.id.text_trailer_title)
TextView mTextTitle;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_trailer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
android:layout_marginTop="165dp"/>

<ListView
android:id="@+id/list_trailer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/layout_trailer_title"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/item_trailer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
android:layout_height="match_parent">

<com.google.android.youtube.player.YouTubeThumbnailView
android:id="@+id/image_trailer_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:layout_weight="1"
android:src="@drawable/user_cover_a"
android:scaleType="centerCrop"/>
<TextView
android:id="@+id/text_trailer_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
Expand Down

0 comments on commit 982690a

Please sign in to comment.