From 4c21eea852e08d0c65b3eb917b04404722d28f5d Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 9 Aug 2019 17:15:41 +0800 Subject: Display a toast to indicate the user to login before voting, replying and commeting. --- .../CommentAndPostRecyclerViewAdapter.java | 25 ++++++++++++++++++++++ .../CommentsListingRecyclerViewAdapter.java | 11 ++++++++++ .../infinityforreddit/MainActivity.java | 9 ++++---- .../infinityforreddit/PostRecyclerViewAdapter.java | 10 +++++++++ .../infinityforreddit/ViewPostDetailActivity.java | 5 +++++ app/src/main/res/layout/activity_main.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 57 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index 0360abe8..25005db0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -721,6 +721,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + if(mPost.isArchived()) { Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); return; @@ -780,6 +785,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + if(mPost.isArchived()) { Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); return; @@ -882,6 +892,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + Intent intent = new Intent(mActivity, CommentActivity.class); intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, mVisibleComments.get(getAdapterPosition() - 1).getDepth() + 1); intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mVisibleComments.get(getAdapterPosition() - 1).getCommentContent()); @@ -892,6 +907,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + int previousVoteType = mVisibleComments.get(getAdapterPosition() - 1).getVoteType(); String newVoteType; @@ -932,6 +952,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + int previousVoteType = mVisibleComments.get(getAdapterPosition() - 1).getVoteType(); String newVoteType; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java index e61cca11..6cd7d189 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java @@ -9,6 +9,7 @@ import android.widget.Button; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.cardview.widget.CardView; @@ -205,6 +206,11 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter { + if(mAccessToken == null) { + Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + int previousVoteType = getItem(getAdapterPosition()).getVoteType(); String newVoteType; @@ -245,6 +251,11 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter { + if(mAccessToken == null) { + Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + int previousVoteType = getItem(getAdapterPosition()).getVoteType(); String newVoteType; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index a2e19cdc..07e545b4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -68,6 +68,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe @BindView(R.id.all_drawer_items_linear_layout_main_activity) LinearLayout allDrawerItemsLinearLayout; @BindView(R.id.profile_linear_layout_main_activity) LinearLayout profileLinearLayout; @BindView(R.id.subscriptions_linear_layout_main_activity) LinearLayout subscriptionLinearLayout; + @BindView(R.id.divider_main_activity) View divider; @BindView(R.id.settings_linear_layout_main_activity) LinearLayout settingsLinearLayout; @BindView(R.id.account_recycler_view_main_activity) RecyclerView accountRecyclerView; @BindView(R.id.tab_layout_main_activity) TabLayout tabLayout; @@ -168,11 +169,6 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if(account == null) { mNullAccessToken = true; - mAccessToken = null; - mAccountName = null; - mProfileImageUrl = null; - mBannerImageUrl = null; - mKarma = 0; } else { mNullAccessToken = false; mAccessToken = account.getAccessToken(); @@ -303,6 +299,9 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe } else { mKarmaTextView.setText(R.string.press_here_to_login); mAccountNameTextView.setText(R.string.anonymous_account); + profileLinearLayout.setVisibility(View.GONE); + subscriptionLinearLayout.setVisibility(View.GONE); + divider.setVisibility(View.GONE); } if (mProfileImageUrl != null && !mProfileImageUrl.equals("")) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 3519633e..c669d14a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -452,6 +452,11 @@ class PostRecyclerViewAdapter extends PagedListAdapter { + if(mAccessToken == null) { + Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + if(isArchived) { Toast.makeText(mContext, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); return; @@ -511,6 +516,11 @@ class PostRecyclerViewAdapter extends PagedListAdapter { + if(mAccessToken == null) { + Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + if(isArchived) { Toast.makeText(mContext, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); return; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 40f6bc07..77be5762 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -415,6 +415,11 @@ public class ViewPostDetailActivity extends AppCompatActivity { refresh(); return true; case R.id.action_comment_view_post_detail_activity: + if(mAccessToken == null) { + Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show(); + return true; + } + Intent intent = new Intent(this, CommentActivity.class); intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mPost.getTitle()); intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName()); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ba4d146c..b1572144 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -91,6 +91,7 @@ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 32b68cbd..f76c1e66 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -177,4 +177,5 @@ Manage accounts Log out Press here to login + Login first -- cgit v1.2.3