Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
eneim committed Aug 24, 2018
1 parent d6fe963 commit 0ed56c3
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 26 deletions.
6 changes: 5 additions & 1 deletion app-youtube/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ dependencies {
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibraryVersion}"
implementation "com.android.support:cardview-v7:${rootProject.ext.supportLibraryVersion}"

implementation "com.google.apis:google-api-services-youtube:v3-rev205-1.24.1"
implementation "com.google.apis:google-api-services-youtube:v3-rev205-${rootProject.ext.googleApiClient}"
implementation "com.google.http-client:google-http-client-android:${rootProject.ext.googleApiClient}"
implementation "com.google.api-client:google-api-client-android:${rootProject.ext.googleApiClient}"
implementation "com.google.api-client:google-api-client-gson:${rootProject.ext.googleApiClient}"
Expand Down Expand Up @@ -129,6 +129,10 @@ dependencies {
transitive = true
}

debugImplementation "com.squareup.leakcanary:leakcanary-android:${rootProject.ext.leackCanary}"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.ext.leackCanary}"
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.ext.leackCanary}"

// implementation "com.android.support:multidex:1.0.3"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ public class HomeActivity extends AppCompatActivity

// Prepare Container
playerManager = new YouTubePlayerManager(getSupportFragmentManager(), this);
container = findViewById(R.id.container);
adapter = new YouTubePlaylistAdapter(playerManager);
int spanCount = getResources().getInteger(R.integer.span_count);
layoutManager = new StaggeredGridLayoutManager(spanCount, VERTICAL);

container = findViewById(R.id.container);
container.setLayoutManager(layoutManager);
container.setAdapter(adapter);
container.setCacheManager(CacheManager.DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ void updateResumePosition() {
// Since this is Fragment transaction, it will be handled by the Manager.
break;
case MSG_PLAY:
if (ytFragment == null || !ytFragment.isVisible()) break;
final YouTubePlayerHelper helper = YouTubePlayerHelper.this; // make a local access
if (ytFragment == null || !ytFragment.isVisible()) break; // Not visible, do nothing.
final YouTubePlayerHelper helper = YouTubePlayerHelper.this; // Make a local copy.
ytFragment.initialize(BuildConfig.API_KEY, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean b) {
Expand All @@ -170,14 +170,15 @@ public void onInitializationSuccess(Provider provider, YouTubePlayer player, boo
player.setPlayerStateChangeListener(new StateChangeListenerImpl());
player.setPlaybackEventListener(new PlaybackEventListenerImpl());
player.setShowFullscreenButton(false); // fullscreen requires more work ...
if (shouldPlay()) { // make sure YouTubePlayerView is fully visible.
if (shouldPlay()) { // Make sure YouTubePlayerView is playable at this moment.
player.loadVideo(videoId, (int) helper.playbackInfo.getResumePosition());
}
}

@Override public void onInitializationFailure(Provider provider,
YouTubeInitializationResult result) {
errorListeners.onError(new RuntimeException("YouTube init error: " + result.name()));
Exception error = new RuntimeException("YouTube init error: " + result.name());
errorListeners.onError(error);
}
});
break;
Expand Down Expand Up @@ -263,7 +264,7 @@ class PlaybackEventListenerImpl implements YouTubePlayer.PlaybackEventListener {
boolean shouldPlay() {
if (ytFragment == null || !ytFragment.isVisible()) return false;
View ytView = ytFragment.getView();
return ytView != null && visibleAreaOffset(ytView) >= 0.999;
return ytView != null && visibleAreaOffset(ytView) >= 0.999; // fully visible.
}

@Override public String toString() {
Expand Down
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ dependencies {
implementation "com.android.support:support-vector-drawable:${rootProject.ext.supportLibraryVersion}"
implementation "com.android.support.constraint:constraint-layout:${rootProject.ext.constrainLayoutVersion}"

implementation ('net.opacapp:multiline-collapsingtoolbar:1.6.0') {
implementation ('net.opacapp:multiline-collapsingtoolbar:27.1.1') {
transitive = false
}

// additional dependencies.
//noinspection GradleDependency
implementation "com.google.android.exoplayer:exoplayer:${rootProject.ext.exoPlayer2Version}"

implementation 'com.jakewharton:butterknife:8.8.1'
Expand All @@ -96,12 +97,11 @@ dependencies {

implementation 'io.reactivex.rxjava2:rxjava:2.2.0'

// https://mvnrepository.com/artifact/org.jsoup/jsoup
implementation group: 'org.jsoup', name: 'jsoup', version: '1.11.3'
implementation "org.jsoup:jsoup:1.11.3"

debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
debugImplementation "com.squareup.leakcanary:leakcanary-android:${rootProject.ext.leackCanary}"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.ext.leackCanary}"
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.ext.leackCanary}"

implementation "com.github.bumptech.glide:glide:${rootProject.ext.glide}"
kapt "com.github.bumptech.glide:compiler:${rootProject.ext.glide}"
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ buildscript {

dependencies {
//noinspection GradleDependency
classpath 'com.android.tools.build:gradle:3.2.0-beta05'
classpath 'com.android.tools.build:gradle:3.2.0-rc01'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.7.3"

classpath 'io.fabric.tools:gradle:1.25.4'
Expand All @@ -50,6 +50,7 @@ ext {
exoPlayer2Version = '2.8.2'
googleApiClient = '1.24.1'
glide = '4.8.0'
leackCanary = '1.6.1'
}

allprojects {
Expand Down Expand Up @@ -95,7 +96,7 @@ task clean(type: Delete) {
}

task wrapper(type: Wrapper) {
gradleVersion = '4.8.1'
gradleVersion = '4.9'
//noinspection GroovyAccessibility
distributionType = 'ALL'
}
Expand Down
4 changes: 4 additions & 0 deletions demo-ads/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ dependencies {
// (see https://github.com/ReactiveX/RxJava/releases for latest 2.x.x version)
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'

debugImplementation "com.squareup.leakcanary:leakcanary-android:${rootProject.ext.leackCanary}"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.ext.leackCanary}"
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.ext.leackCanary}"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package toro.demo.ads.ima

import android.net.Uri
import android.util.Log
import android.view.View
import com.google.android.exoplayer2.ext.ima.ImaAdsLoader
import com.google.android.exoplayer2.ui.PlayerView
Expand All @@ -39,7 +40,9 @@ class ImaVideoViewHolder(itemView: View) : BaseViewHolder(itemView), ToroPlayer

val mediaUri = Uri.parse(itemView.context.getString(R.string.ima_content_url))!!
val adTagUri = Uri.parse(itemView.context.getString(R.string.ima_ad_tag_url))!!
val adLoader = ImaAdsLoader(itemView.context, adTagUri)
val adLoader = ImaAdsLoader.Builder(itemView.context)
.setAdEventListener { Log.d("Toro:VH:$adapterPosition", "ev: $it") }
.buildForAdTag(adTagUri)!!

override fun getPlayerView() = this.exoPlayerView

Expand Down
6 changes: 3 additions & 3 deletions demo-mopub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ dependencies {
implementation "com.github.bumptech.glide:glide:${rootProject.ext.glide}"
annotationProcessor "com.github.bumptech.glide:compiler:${rootProject.ext.glide}"

debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
debugImplementation "com.squareup.leakcanary:leakcanary-android:${rootProject.ext.leackCanary}"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.ext.leackCanary}"
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${rootProject.ext.leackCanary}"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import im.ene.toro.ToroUtil;
import im.ene.toro.media.PlaybackInfo;
import im.ene.toro.media.VolumeInfo;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

import static im.ene.toro.ToroUtil.checkNotNull;
import static im.ene.toro.exoplayer.ToroExo.with;
Expand All @@ -54,8 +53,8 @@ class PlayableImpl implements Playable {
private final PlaybackInfo playbackInfo = new PlaybackInfo(); // never expose to outside.

protected final EventListeners listeners = new EventListeners(); // original listener.
// Use a Set to prevent duplicated setup.
protected Set<ToroPlayer.OnVolumeChangeListener> volumeChangeListeners;
// Use a CopyOnWriteArraySet to prevent duplicated setup and modify while iterating.
protected CopyOnWriteArraySet<ToroPlayer.OnVolumeChangeListener> volumeChangeListeners;
protected ToroPlayer.ErrorListeners errorListeners;

protected final Uri mediaUri; // immutable, parcelable
Expand Down Expand Up @@ -207,7 +206,7 @@ class PlayableImpl implements Playable {

@Override
public void addOnVolumeChangeListener(@NonNull ToroPlayer.OnVolumeChangeListener listener) {
if (volumeChangeListeners == null) volumeChangeListeners = new HashSet<>();
if (volumeChangeListeners == null) volumeChangeListeners = new CopyOnWriteArraySet<>();
volumeChangeListeners.add(ToroUtil.checkNotNull(listener));
if (this.player instanceof ToroExoPlayer) {
((ToroExoPlayer) this.player).addOnVolumeChangeListener(listener);
Expand Down

0 comments on commit 0ed56c3

Please sign in to comment.