From 86ea4c8982e954957dc0868fb086483af6e98d23 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 27 Oct 2018 00:06:35 +0800 Subject: [PATCH] Bind views using ButterKnife. Let volume controls adjust music stream in ViewVideoActivity. --- .idea/caches/build_file_checksums.ser | Bin 533 -> 533 bytes app/build.gradle | 1 - .../infinityforreddit/MainActivity.java | 12 +- .../infinityforreddit/ViewImageActivity.java | 18 +- .../ViewPostDetailActivity.java | 197 +++++++++--------- .../ViewSubredditDetailActivity.java | 19 +- .../infinityforreddit/ViewVideoActivity.java | 12 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 9 files changed, 138 insertions(+), 127 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 70fbae61775ff46cf3bd92136c89087f36bb19bc..37c1f9d050f7116c72ffa218e96fce080105ff22 100644 GIT binary patch delta 53 zcmV-50LuTB1eFAkm;{s}@*a_#pAZ#@dj{-b+=w-0jF*fN!Ap}%0l5)JmslqXZYvc* Lc^y&o+Y8fpKamwd delta 53 zcmV-50LuTB1eFAkm;_EqL{^cUpAekYaW*`oHr{qMPY_@ 0) { - gildedImageView.setVisibility(View.VISIBLE); - Glide.with(this).load(R.drawable.gold).into(gildedImageView); - gildedNumberTextView.setVisibility(View.VISIBLE); + mGildedImageView.setVisibility(View.VISIBLE); + Glide.with(this).load(R.drawable.gold).into(mGildedImageView); + mGildedNumberTextView.setVisibility(View.VISIBLE); String gildedNumber = getResources().getString(R.string.gilded, mPostData.getGilded()); - gildedNumberTextView.setText(gildedNumber); + mGildedNumberTextView.setText(gildedNumber); } if(mPostData.isNSFW()) { - nsfwTextView.setVisibility(View.VISIBLE); + mNSFWTextView.setVisibility(View.VISIBLE); } - scoreTextView.setText(Integer.toString(mPostData.getScore())); + mScoreTextView.setText(Integer.toString(mPostData.getScore())); - shareButton.setOnClickListener(new View.OnClickListener() { + mShareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_SEND); @@ -229,7 +220,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { switch (mPostData.getPostType()) { case PostData.IMAGE_TYPE: - typeTextView.setText("IMAGE"); + mTypeTextView.setText("IMAGE"); mImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -243,10 +234,10 @@ public class ViewPostDetailActivity extends AppCompatActivity { }); break; case PostData.LINK_TYPE: - typeTextView.setText("LINK"); + mTypeTextView.setText("LINK"); if(mPostData.getSelfText() != null && !mPostData.getSelfText().equals("")) { - contentTextView.setVisibility(View.VISIBLE); - contentTextView.setHtml(mPostData.getSelfText()); + mContentTextView.setVisibility(View.VISIBLE); + mContentTextView.setHtml(mPostData.getSelfText()); } mImageView.setOnClickListener(new View.OnClickListener() { @@ -262,7 +253,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { }); break; case PostData.GIF_VIDEO_TYPE: - typeTextView.setText("GIF"); + mTypeTextView.setText("GIF"); final Uri gifVideoUri = Uri.parse(mPostData.getVideoUrl()); mImageView.setOnClickListener(new View.OnClickListener() { @@ -283,7 +274,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { }); break; case PostData.VIDEO_TYPE: - typeTextView.setText("VIDEO"); + mTypeTextView.setText("VIDEO"); final Uri videoUri = Uri.parse(mPostData.getVideoUrl()); mImageView.setOnClickListener(new View.OnClickListener() { @@ -304,13 +295,13 @@ public class ViewPostDetailActivity extends AppCompatActivity { }); break; case PostData.NO_PREVIEW_LINK_TYPE: - typeTextView.setText("LINK"); + mTypeTextView.setText("LINK"); if(!mPostData.getSelfText().equals("")) { - contentTextView.setVisibility(View.VISIBLE); - contentTextView.setHtml(mPostData.getSelfText()); + mContentTextView.setVisibility(View.VISIBLE); + mContentTextView.setHtml(mPostData.getSelfText()); } - noPreviewLinkImageView.setVisibility(View.VISIBLE); - noPreviewLinkImageView.setOnClickListener(new View.OnClickListener() { + mNoPreviewLinkImageView.setVisibility(View.VISIBLE); + mNoPreviewLinkImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); @@ -323,10 +314,10 @@ public class ViewPostDetailActivity extends AppCompatActivity { }); break; case PostData.TEXT_TYPE: - typeTextView.setText("TEXT"); + mTypeTextView.setText("TEXT"); if(!mPostData.getSelfText().equals("")) { - contentTextView.setVisibility(View.VISIBLE); - contentTextView.setHtml(mPostData.getSelfText()); + mContentTextView.setVisibility(View.VISIBLE); + mContentTextView.setHtml(mPostData.getSelfText()); } } queryComment(); @@ -365,21 +356,21 @@ public class ViewPostDetailActivity extends AppCompatActivity { } };*/ - upvoteButton.setOnClickListener(new View.OnClickListener() { + mUpvoteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //observable.subscribe(observer); - final boolean isDownvotedBefore = downvoteButton.getColorFilter() != null; + final boolean isDownvotedBefore = mDownvoteButton.getColorFilter() != null; - final ColorFilter downVoteButtonColorFilter = downvoteButton.getColorFilter(); - downvoteButton.clearColorFilter(); + final ColorFilter downVoteButtonColorFilter = mDownvoteButton.getColorFilter(); + mDownvoteButton.clearColorFilter(); - if (upvoteButton.getColorFilter() == null) { - upvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN); + if (mUpvoteButton.getColorFilter() == null) { + mUpvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN); if(isDownvotedBefore) { - scoreTextView.setText(Integer.toString(mPostData.getScore() + 2)); + mScoreTextView.setText(Integer.toString(mPostData.getScore() + 2)); } else { - scoreTextView.setText(Integer.toString(mPostData.getScore() + 1)); + mScoreTextView.setText(Integer.toString(mPostData.getScore() + 1)); } VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingWithoutPositionListener() { @@ -396,15 +387,15 @@ public class ViewPostDetailActivity extends AppCompatActivity { @Override public void onVoteThingFail() { Toast.makeText(ViewPostDetailActivity.this, "Cannot upvote this post", Toast.LENGTH_SHORT).show(); - upvoteButton.clearColorFilter(); - scoreTextView.setText(Integer.toString(mPostData.getScore())); - downvoteButton.setColorFilter(downVoteButtonColorFilter); + mUpvoteButton.clearColorFilter(); + mScoreTextView.setText(Integer.toString(mPostData.getScore())); + mDownvoteButton.setColorFilter(downVoteButtonColorFilter); } }, mPostData.getFullName(), RedditUtils.DIR_UPVOTE); } else { //Upvoted before - upvoteButton.clearColorFilter(); - scoreTextView.setText(Integer.toString(mPostData.getScore() - 1)); + mUpvoteButton.clearColorFilter(); + mScoreTextView.setText(Integer.toString(mPostData.getScore() - 1)); VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingWithoutPositionListener() { @Override @@ -416,8 +407,8 @@ public class ViewPostDetailActivity extends AppCompatActivity { @Override public void onVoteThingFail() { Toast.makeText(ViewPostDetailActivity.this, "Cannot unvote this post", Toast.LENGTH_SHORT).show(); - scoreTextView.setText(Integer.toString(mPostData.getScore() + 1)); - upvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN); + mScoreTextView.setText(Integer.toString(mPostData.getScore() + 1)); + mUpvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN); mPostData.setScore(mPostData.getScore() + 1); } }, mPostData.getFullName(), RedditUtils.DIR_UNVOTE); @@ -425,21 +416,21 @@ public class ViewPostDetailActivity extends AppCompatActivity { } }); - downvoteButton.setOnClickListener(new View.OnClickListener() { + mDownvoteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //observable.subscribe(observer); - final boolean isUpvotedBefore = upvoteButton.getColorFilter() != null; + final boolean isUpvotedBefore = mUpvoteButton.getColorFilter() != null; - final ColorFilter upvoteButtonColorFilter = upvoteButton.getColorFilter(); - upvoteButton.clearColorFilter(); + final ColorFilter upvoteButtonColorFilter = mUpvoteButton.getColorFilter(); + mUpvoteButton.clearColorFilter(); - if (downvoteButton.getColorFilter() == null) { - downvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + if (mDownvoteButton.getColorFilter() == null) { + mDownvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); if (isUpvotedBefore) { - scoreTextView.setText(Integer.toString(mPostData.getScore() - 2)); + mScoreTextView.setText(Integer.toString(mPostData.getScore() - 2)); } else { - scoreTextView.setText(Integer.toString(mPostData.getScore() - 1)); + mScoreTextView.setText(Integer.toString(mPostData.getScore() - 1)); } VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingWithoutPositionListener() { @@ -456,15 +447,15 @@ public class ViewPostDetailActivity extends AppCompatActivity { @Override public void onVoteThingFail() { Toast.makeText(ViewPostDetailActivity.this, "Cannot downvote this post", Toast.LENGTH_SHORT).show(); - downvoteButton.clearColorFilter(); - scoreTextView.setText(Integer.toString(mPostData.getScore())); - upvoteButton.setColorFilter(upvoteButtonColorFilter); + mDownvoteButton.clearColorFilter(); + mScoreTextView.setText(Integer.toString(mPostData.getScore())); + mUpvoteButton.setColorFilter(upvoteButtonColorFilter); } }, mPostData.getFullName(), RedditUtils.DIR_DOWNVOTE); } else { //Down voted before - downvoteButton.clearColorFilter(); - scoreTextView.setText(Integer.toString(mPostData.getScore() + 1)); + mDownvoteButton.clearColorFilter(); + mScoreTextView.setText(Integer.toString(mPostData.getScore() + 1)); VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingWithoutPositionListener() { @Override @@ -476,8 +467,8 @@ public class ViewPostDetailActivity extends AppCompatActivity { @Override public void onVoteThingFail() { Toast.makeText(ViewPostDetailActivity.this, "Cannot unvote this post", Toast.LENGTH_SHORT).show(); - downvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); - scoreTextView.setText(Integer.toString(mPostData.getScore())); + mDownvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + mScoreTextView.setText(Integer.toString(mPostData.getScore())); mPostData.setScore(mPostData.getScore()); } }, mPostData.getFullName(), RedditUtils.DIR_UNVOTE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java index 7b86e5b2..37055713 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java @@ -25,6 +25,8 @@ import com.bumptech.glide.RequestManager; import javax.inject.Inject; import javax.inject.Named; +import butterknife.BindView; +import butterknife.ButterKnife; import de.hdodenhof.circleimageview.CircleImageView; import retrofit2.Retrofit; @@ -36,6 +38,14 @@ public class ViewSubredditDetailActivity extends AppCompatActivity { private static final String FRAGMENT_OUT_STATE_KEY = "FOSK"; + @BindView(R.id.banner_image_view_view_subreddit_detail_activity) ImageView bannerImageView; + @BindView(R.id.icon_circle_image_view_view_subreddit_detail_activity) CircleImageView iconCircleImageView; + @BindView(R.id.subreddit_name_text_view_view_subreddit_detail_activity) TextView subredditNameTextView; + @BindView(R.id.subscriber_count_text_view_view_subreddit_detail_activity) TextView nSubscribersTextView; + @BindView(R.id.online_subscriber_count_text_view_view_subreddit_detail_activity) TextView nOnlineSubscribersTextView; + @BindView(R.id.description_text_view_view_subreddit_detail_activity) TextView descriptionTextView; + + private RequestManager glide; private Fragment mFragment; private SubredditViewModel mSubredditViewModel; @@ -48,6 +58,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_subreddit_detail); + ButterKnife.bind(this); ((Infinity) getApplication()).getmNetworkComponent().inject(this); @@ -95,13 +106,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity { } }); - final ImageView bannerImageView = findViewById(R.id.banner_image_view_view_subreddit_detail_activity); - final CircleImageView iconCircleImageView = findViewById(R.id.icon_circle_image_view_view_subreddit_detail_activity); - final TextView subredditNameTextView = findViewById(R.id.subreddit_name_text_view_view_subreddit_detail_activity); - final TextView nSubscribersTextView = findViewById(R.id.subscriber_count_text_view_view_subreddit_detail_activity); - final TextView nOnlineSubscribersTextView = findViewById(R.id.online_subscriber_count_text_view_view_subreddit_detail_activity); - final TextView descriptionTextView = findViewById(R.id.description_text_view_view_subreddit_detail_activity); - final RequestManager glide = Glide.with(ViewSubredditDetailActivity.this); + glide = Glide.with(ViewSubredditDetailActivity.this); String value = getIntent().getExtras().getString(EXTRA_SUBREDDIT_VALUE_KEY); boolean queryById = getIntent().getExtras().getBoolean(EXTRA_QUERY_BY_ID_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java index 46423d50..2163fa12 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java @@ -11,6 +11,7 @@ import android.content.pm.PackageManager; import android.graphics.PorterDuff; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.media.AudioManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -52,6 +53,9 @@ import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.util.Util; +import butterknife.BindView; +import butterknife.ButterKnife; + public class ViewVideoActivity extends AppCompatActivity { private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0; @@ -63,6 +67,9 @@ public class ViewVideoActivity extends AppCompatActivity { static final String SUBREDDIT_KEY = "SK"; static final String ID_KEY = "IK"; + @BindView(R.id.relative_layout_view_video_activity) RelativeLayout relativeLayout; + @BindView(R.id.player_view_view_video_activity) PlayerView videoPlayerView; + private Uri mVideoUri; private SimpleExoPlayer player; @@ -81,6 +88,8 @@ public class ViewVideoActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_video); + ButterKnife.bind(this); + setVolumeControlStream(AudioManager.STREAM_MUSIC); final ActionBar actionBar = getSupportActionBar(); final Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp); @@ -106,9 +115,6 @@ public class ViewVideoActivity extends AppCompatActivity { mDownloadUrl = intent.getExtras().getString(DOWNLOAD_URL_KEY); } - final RelativeLayout relativeLayout = findViewById(R.id.relative_layout_view_video_activity); - final PlayerView videoPlayerView = findViewById(R.id.player_view_view_video_activity); - final float pxHeight = getResources().getDisplayMetrics().heightPixels; int activityColorFrom = getResources().getColor(android.R.color.black); diff --git a/build.gradle b/build.gradle index d46059ee..a801c916 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.4' + classpath 'com.android.tools.build:gradle:3.2.1' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4e537a86..d210bb6a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 14 08:13:09 HKT 2018 +#Fri Oct 19 21:24:28 HKT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip