Bind views using ButterKnife. Let volume controls adjust music stream in ViewVideoActivity.

This commit is contained in:
Alex Ning 2018-10-27 00:06:35 +08:00
parent ae81b23737
commit 86ea4c8982
9 changed files with 138 additions and 127 deletions

Binary file not shown.

View File

@ -64,5 +64,4 @@ dependencies {
annotationProcessor 'com.google.dagger:dagger-compiler:2.17'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}

View File

@ -31,6 +31,8 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;
import retrofit2.Retrofit;
@ -44,6 +46,11 @@ public class MainActivity extends AppCompatActivity {
private static final String FETCH_USER_INFO_STATE = "FUIS";
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
@BindView(R.id.subscribed_subreddit_recycler_view_main_activity) RecyclerView subscribedSubredditRecyclerView;
@BindView(R.id.subscriptions_label_main_activity) TextView subscriptionsLabelTextView;
@BindView(R.id.subscribed_user_recycler_view_main_activity) RecyclerView subscribedUserRecyclerView;
@BindView(R.id.following_label_main_activity) TextView followingLabelTextView;
private TextView mNameTextView;
private TextView mKarmaTextView;
private CircleImageView mProfileImageView;
@ -77,6 +84,7 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
((Infinity) getApplication()).getmNetworkComponent().inject(this);
@ -113,15 +121,11 @@ public class MainActivity extends AppCompatActivity {
mProfileImageView = header.findViewById(R.id.profile_image_view_nav_header_main);
mBannerImageView = header.findViewById(R.id.banner_image_view_nav_header_main);
RecyclerView subscribedSubredditRecyclerView = findViewById(R.id.subscribed_subreddit_recycler_view_main_activity);
subscribedSubredditRecyclerView.setLayoutManager(new LinearLayoutManager(this));
subscribedSubredditRecyclerView.setNestedScrollingEnabled(false);
final TextView subscriptionsLabelTextView = findViewById(R.id.subscriptions_label_main_activity);
RecyclerView subscribedUserRecyclerView = findViewById(R.id.subscribed_user_recycler_view_main_activity);
subscribedUserRecyclerView.setLayoutManager(new LinearLayoutManager(this));
subscribedUserRecyclerView.setNestedScrollingEnabled(false);
final TextView followingLabelTextView = findViewById(R.id.following_label_main_activity);
mName = getSharedPreferences(SharedPreferencesUtils.USER_INFO_FILE_KEY, Context.MODE_PRIVATE).getString(SharedPreferencesUtils.USER_KEY, "");
mProfileImageUrl = getSharedPreferences(SharedPreferencesUtils.USER_INFO_FILE_KEY, Context.MODE_PRIVATE).getString(SharedPreferencesUtils.PROFILE_IMAGE_URL_KEY, "");

View File

@ -52,6 +52,9 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import butterknife.BindView;
import butterknife.ButterKnife;
public class ViewImageActivity extends AppCompatActivity {
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@ -60,9 +63,10 @@ public class ViewImageActivity extends AppCompatActivity {
static final String IMAGE_URL_KEY = "IUK";
static final String FILE_NAME_KEY = "FNK";
private ProgressBar mProgressBar;
private GestureImageView mImageView;
private LinearLayout mLoadErrorLinearLayout;
@BindView(R.id.parent_relative_layout_view_image_activity) RelativeLayout mRelativeLayout;
@BindView(R.id.progress_bar_view_image_activity) ProgressBar mProgressBar;
@BindView(R.id.image_view_view_image_activity) GestureImageView mImageView;
@BindView(R.id.load_image_error_linear_layout_view_image_activity) LinearLayout mLoadErrorLinearLayout;
private boolean isActionBarHidden = false;
private boolean isDownloading = false;
@ -83,6 +87,8 @@ public class ViewImageActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_image);
ButterKnife.bind(this);
final ActionBar actionBar = getSupportActionBar();
final Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
actionBar.setHomeAsUpIndicator(upArrow);
@ -94,10 +100,10 @@ public class ViewImageActivity extends AppCompatActivity {
final Spannable text = new SpannableString(title);
setTitle(text);
final RelativeLayout relativeLayout = findViewById(R.id.parent_relative_layout_view_image_activity);
/*final RelativeLayout mRelativeLayout = findViewById(R.id.parent_relative_layout_view_image_activity);
mImageView = findViewById(R.id.image_view_view_image_activity);
mProgressBar = findViewById(R.id.progress_bar_view_image_activity);
mLoadErrorLinearLayout = findViewById(R.id.load_image_error_linear_layout_view_image_activity);
mLoadErrorLinearLayout = findViewById(R.id.load_image_error_linear_layout_view_image_activity);*/
mLoadErrorLinearLayout.setOnClickListener(new View.OnClickListener() {
@Override
@ -128,7 +134,7 @@ public class ViewImageActivity extends AppCompatActivity {
activityColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
relativeLayout.setBackgroundColor((int) valueAnimator.getAnimatedValue());
mRelativeLayout.setBackgroundColor((int) valueAnimator.getAnimatedValue());
}
});

View File

@ -41,6 +41,8 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;
import jp.wasabeef.glide.transformations.BlurTransformation;
import retrofit2.Retrofit;
@ -56,17 +58,35 @@ public class ViewPostDetailActivity extends AppCompatActivity {
private int mMoreCommentCount;
private PostData mPostData;
private CoordinatorLayout mCoordinatorLayout;
private ProgressBar mLoadImageProgressBar;
private ImageView mImageView;
private RelativeLayout mLoadWrapper;
private TextView mLoadImageErrorTextView;
private ProgressBar mCommentProgressbar;
private CardView mCommentCardView;
private MultiLevelRecyclerView mRecyclerView;
@BindView(R.id.coordinator_layout_view_post_detail) CoordinatorLayout mCoordinatorLayout;
@BindView(R.id.subreddit_icon_circle_image_view_view_post_detail) CircleImageView mSubredditIconCircleImageView;
@BindView(R.id.post_time_text_view_view_post_detail) TextView mPostTimeTextView;
@BindView(R.id.subreddit_text_view_view_post_detail) TextView mSubredditTextView;
@BindView(R.id.content_html_text_view_view_post_detail) HtmlTextView mContentTextView;
@BindView(R.id.type_text_view_view_post_detail) TextView mTypeTextView;
@BindView(R.id.gilded_image_view_view_post_detail) ImageView mGildedImageView;
@BindView(R.id.gilded_number_text_view_view_post_detail) TextView mGildedNumberTextView;
@BindView(R.id.crosspost_image_view_view_post_detail) ImageView mCrosspostImageView;
@BindView(R.id.nsfw_text_view_view_post_detail) TextView mNSFWTextView;
@BindView(R.id.image_view_wrapper_view_post_detail) RelativeLayout mRelativeLayout;
private LinearLayout mNoCommentWrapperLinearLayout;
private ImageView mNoCommentImageView;
@BindView(R.id.load_wrapper_view_post_detail) RelativeLayout mLoadWrapper;
@BindView(R.id.progress_bar_view_post_detail) ProgressBar mLoadImageProgressBar;
@BindView(R.id.load_image_error_text_view_view_post_detail) TextView mLoadImageErrorTextView;
@BindView(R.id.image_view_view_post_detail) ImageView mImageView;
@BindView(R.id.image_view_no_preview_link_view_post_detail) ImageView mNoPreviewLinkImageView;
@BindView(R.id.plus_button_view_post_detail) ImageView mUpvoteButton;
@BindView(R.id.score_text_view_view_post_detail) TextView mScoreTextView;
@BindView(R.id.minus_button_view_post_detail) ImageView mDownvoteButton;
@BindView(R.id.share_button_view_post_detail) ImageView mShareButton;
@BindView(R.id.comment_progress_bar_view_post_detail) ProgressBar mCommentProgressbar;
@BindView(R.id.comment_card_view_view_post_detail) CardView mCommentCardView;
@BindView(R.id.recycler_view_view_post_detail) MultiLevelRecyclerView mRecyclerView;
@BindView(R.id.no_comment_wrapper_linear_layout_view_post_detail) LinearLayout mNoCommentWrapperLinearLayout;
@BindView(R.id.no_comment_image_view_view_post_detail) ImageView mNoCommentImageView;
private LoadSubredditIconAsyncTask mLoadSubredditIconAsyncTask;
@ -83,6 +103,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_post_detail);
ButterKnife.bind(this);
((Infinity) getApplication()).getmNetworkComponent().inject(this);
@ -95,36 +116,6 @@ public class ViewPostDetailActivity extends AppCompatActivity {
TextView titleTextView = findViewById(R.id.title_text_view_view_post_detail);
titleTextView.setText(mPostData.getTitle());
mCoordinatorLayout = findViewById(R.id.coordinator_layout_view_post_detail);
final CircleImageView subredditIconCircleImageView = findViewById(R.id.subreddit_icon_circle_image_view_view_post_detail);
TextView postTimeTextView = findViewById(R.id.post_time_text_view_view_post_detail);
TextView subredditTextView = findViewById(R.id.subreddit_text_view_view_post_detail);
HtmlTextView contentTextView = findViewById(R.id.content_html_text_view_view_post_detail);
TextView typeTextView = findViewById(R.id.type_text_view_view_post_detail);
ImageView gildedImageView = findViewById(R.id.gilded_image_view_view_post_detail);
TextView gildedNumberTextView = findViewById(R.id.gilded_number_text_view_view_post_detail);
ImageView crosspostImageView = findViewById(R.id.crosspost_image_view_view_post_detail);
TextView nsfwTextView = findViewById(R.id.nsfw_text_view_view_post_detail);
RelativeLayout relativeLayout = findViewById(R.id.image_view_wrapper_view_post_detail);
mLoadWrapper = findViewById(R.id.load_wrapper_view_post_detail);
mLoadImageProgressBar = findViewById(R.id.progress_bar_view_post_detail);
mLoadImageErrorTextView = findViewById(R.id.load_image_error_text_view_view_post_detail);
mImageView = findViewById(R.id.image_view_view_post_detail);
ImageView noPreviewLinkImageView = findViewById(R.id.image_view_no_preview_link_view_post_detail);
final ImageView upvoteButton = findViewById(R.id.plus_button_view_post_detail);
final TextView scoreTextView = findViewById(R.id.score_text_view_view_post_detail);
final ImageView downvoteButton = findViewById(R.id.minus_button_view_post_detail);
ImageView shareButton = findViewById(R.id.share_button_view_post_detail);
mCommentProgressbar = findViewById(R.id.comment_progress_bar_view_post_detail);
mCommentCardView = findViewById(R.id.comment_card_view_view_post_detail);
mRecyclerView = findViewById(R.id.recycler_view_view_post_detail);
mNoCommentWrapperLinearLayout = findViewById(R.id.no_comment_wrapper_linear_layout_view_post_detail);
mNoCommentImageView = findViewById(R.id.no_comment_image_view_view_post_detail);
if(mPostData.getSubredditIconUrl() == null) {
mLoadSubredditIconAsyncTask = new LoadSubredditIconAsyncTask(
SubredditRoomDatabase.getDatabase(this).subredditDao(), mPostData.getSubredditNamePrefixed(),
@ -133,10 +124,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
public void loadIconSuccess(String iconImageUrl) {
if(!iconImageUrl.equals("")) {
Glide.with(ViewPostDetailActivity.this).load(iconImageUrl)
.into(subredditIconCircleImageView);
.into(mSubredditIconCircleImageView);
} else {
Glide.with(ViewPostDetailActivity.this).load(R.drawable.subreddit_default_icon)
.into(subredditIconCircleImageView);
.into(mSubredditIconCircleImageView);
}
mPostData.setSubredditIconUrl(iconImageUrl);
@ -144,12 +135,12 @@ public class ViewPostDetailActivity extends AppCompatActivity {
});
mLoadSubredditIconAsyncTask.execute();
} else if(!mPostData.getSubredditIconUrl().equals("")) {
Glide.with(this).load(mPostData.getSubredditIconUrl()).into(subredditIconCircleImageView);
Glide.with(this).load(mPostData.getSubredditIconUrl()).into(mSubredditIconCircleImageView);
} else {
Glide.with(this).load(R.drawable.subreddit_default_icon).into(subredditIconCircleImageView);
Glide.with(this).load(R.drawable.subreddit_default_icon).into(mSubredditIconCircleImageView);
}
subredditIconCircleImageView.setOnClickListener(new View.OnClickListener() {
mSubredditIconCircleImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ViewPostDetailActivity.this, ViewSubredditDetailActivity.class);
@ -165,30 +156,30 @@ public class ViewPostDetailActivity extends AppCompatActivity {
switch (mPostData.getVoteType()) {
case 1:
//Upvote
upvoteButton.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
mUpvoteButton.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
break;
case -1:
//Downvote
downvoteButton.setColorFilter(ContextCompat.getColor(this, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
mDownvoteButton.setColorFilter(ContextCompat.getColor(this, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
break;
}
if(mPostData.getPostType() != PostData.TEXT_TYPE && mPostData.getPostType() != PostData.NO_PREVIEW_LINK_TYPE) {
relativeLayout.setVisibility(View.VISIBLE);
mRelativeLayout.setVisibility(View.VISIBLE);
mImageView.setVisibility(View.VISIBLE);
loadImage();
}
if(mPostData.isCrosspost()) {
crosspostImageView.setVisibility(View.VISIBLE);
mCrosspostImageView.setVisibility(View.VISIBLE);
}
mRecyclerView.setNestedScrollingEnabled(false);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
subredditTextView.setText(mPostData.getSubredditNamePrefixed());
subredditTextView.setOnClickListener(new View.OnClickListener() {
mSubredditTextView.setText(mPostData.getSubredditNamePrefixed());
mSubredditTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ViewPostDetailActivity.this, ViewSubredditDetailActivity.class);
@ -201,22 +192,22 @@ public class ViewPostDetailActivity extends AppCompatActivity {
}
});
postTimeTextView.setText(mPostData.getPostTime());
mPostTimeTextView.setText(mPostData.getPostTime());
if(mPostData.getGilded() > 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);

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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