From 25328e5d18455a5817b39702a7cb389f29037380 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 1 May 2020 10:50:40 +0800 Subject: Muting and unmuting audio when autoplaying are available. --- .../Adapter/PostRecyclerViewAdapter.java | 69 +++++++++++++++++++--- .../infinityforreddit/Fragment/PostFragment.java | 11 ++++ .../infinityforreddit/Post/Post.java | 2 +- .../infinityforreddit/Post/PostDataSource.java | 1 - 4 files changed, 73 insertions(+), 10 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 88175912..0e8bd1da 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -13,6 +13,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.FrameLayout; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.RelativeLayout; @@ -37,6 +38,10 @@ import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; +import com.google.android.exoplayer2.metadata.Metadata; +import com.google.android.exoplayer2.source.TrackGroupArray; +import com.google.android.exoplayer2.text.Cue; +import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.material.card.MaterialCardView; @@ -44,6 +49,8 @@ import com.libRG.CustomTextView; import org.greenrobot.eventbus.EventBus; +import java.util.List; + import butterknife.BindView; import butterknife.ButterKnife; import im.ene.toro.CacheManager; @@ -51,6 +58,7 @@ import im.ene.toro.ToroPlayer; import im.ene.toro.ToroUtil; import im.ene.toro.exoplayer.ExoCreator; import im.ene.toro.exoplayer.ExoPlayerViewHelper; +import im.ene.toro.exoplayer.Playable; import im.ene.toro.media.PlaybackInfo; import im.ene.toro.widget.Container; import jp.wasabeef.glide.transformations.BlurTransformation; @@ -1301,7 +1309,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - //Do nothing in order to prevent clicking this to start ViewPostDetailActivity - }); + scoreTextView.setOnClickListener(null); if (mVoteButtonsOnTheRight) { ConstraintSet constraintSet = new ConstraintSet(); @@ -1520,10 +1529,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { if (canStartActivity) { - canStartActivity = false; - Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, getItem(getAdapterPosition()).getAuthor()); - mActivity.startActivity(intent); + Post post = getItem(getAdapterPosition()); + if (post != null) { + canStartActivity = false; + Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor()); + mActivity.startActivity(intent); + } } }); @@ -1835,6 +1847,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + if (helper != null) { + if (helper.getVolume() != 0) { + muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_24dp)); + helper.setVolume(0f); + } else { + muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_24dp)); + helper.setVolume(1f); + } + } + }); } void bindVideoUri(Uri videoUri) { @@ -1903,6 +1929,33 @@ public class PostRecyclerViewAdapter extends PagedListAdapter cues) { + + } + }); } helper.initialize(container, playbackInfo); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index 5b76d340..9d058e3b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -47,6 +47,9 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import im.ene.toro.exoplayer.ExoCreator; +import im.ene.toro.media.PlaybackInfo; +import im.ene.toro.media.VolumeInfo; +import im.ene.toro.widget.Container; import ml.docilealligator.infinityforreddit.Activity.BaseActivity; import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity; import ml.docilealligator.infinityforreddit.Activity.MainActivity; @@ -78,6 +81,9 @@ import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; +import static im.ene.toro.media.PlaybackInfo.INDEX_UNSET; +import static im.ene.toro.media.PlaybackInfo.TIME_UNSET; + /** * A simple {@link Fragment} subclass. @@ -564,6 +570,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mPostRecyclerView.setAdapter(mAdapter); mPostRecyclerView.setCacheManager(mAdapter); + mPostRecyclerView.setPlayerInitializer(order -> { + VolumeInfo volumeInfo = new VolumeInfo(true, 0f); + return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo); + }); + mPostViewModel.getPosts().observe(this, posts -> mAdapter.submitList(posts)); mPostViewModel.hasPost().observe(this, hasPost -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java index eccc4388..b5aa1f1c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java @@ -514,6 +514,6 @@ public class Post implements Parcelable { if (!(obj instanceof Post)) { return false; } - return ((Post) obj).getFullName().equals(fullName); + return ((Post) obj).id.equals(id); } } \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java index e8e865b1..b26eef79 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java @@ -248,7 +248,6 @@ public class PostDataSource extends PageKeyedDataSource { nextPageKey = lastItem; } - int currentPostsSize = postLinkedHashSet.size(); if (newPosts.size() != 0) { postLinkedHashSet.addAll(newPosts); callback.onResult(new ArrayList<>(newPosts), null, nextPageKey); -- cgit v1.2.3