diff options
Diffstat (limited to 'app/src/main/java/ml')
27 files changed, 874 insertions, 151 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java index 41023910..b3d50c2f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -13,6 +14,7 @@ import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; @@ -27,6 +29,11 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class AccountPostsActivity extends AppCompatActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { static final String EXTRA_USER_WHERE = "EUW"; @@ -56,6 +63,9 @@ public class AccountPostsActivity extends AppCompatActivity implements UserThing @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -108,6 +118,24 @@ public class AccountPostsActivity extends AppCompatActivity implements UserThing } } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + mUserWhere = getIntent().getExtras().getString(EXTRA_USER_WHERE); if(mUserWhere.equals(PostDataSource.USER_WHERE_UPVOTED)) { toolbar.setTitle(R.string.upvoted); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 5b557fd6..0c66bcf3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -39,4 +39,6 @@ public interface AppComponent { void inject(ViewMessageActivity viewMessageActivity); void inject(NotificationPreferenceFragment notificationPreferenceFragment); void inject(LinkResolverActivity linkResolverActivity); + void inject(SearchActivity searchActivity); + void inject(SettingsActivity settingsActivity); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java index 0065ea45..5b5cd0ab 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -15,6 +16,7 @@ import android.widget.EditText; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; @@ -32,6 +34,11 @@ import butterknife.ButterKnife; import retrofit2.Retrofit; import ru.noties.markwon.view.MarkwonView; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class CommentActivity extends AppCompatActivity { static final String EXTRA_COMMENT_PARENT_TEXT_KEY = "ECPTK"; @@ -64,6 +71,9 @@ public class CommentActivity extends AppCompatActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -83,6 +93,24 @@ public class CommentActivity extends AppCompatActivity { window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + if(savedInstanceState == null) { getCurrentAccount(); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index 347634aa..996ba720 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -282,9 +282,9 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie if(mPost.isArchived()) { ((PostDetailViewHolder) holder).mUpvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); ((PostDetailViewHolder) holder).mDownvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); } if(mPost.isCrosspost()) { @@ -476,8 +476,9 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie params.width = comment.getDepth() * 16; ((CommentViewHolder) holder).verticalBlock.setLayoutParams(params); - if(comment.getAuthor().equals(mAccountName)) { + if(!mPost.isArchived() && !mPost.isLocked() && comment.getAuthor().equals(mAccountName)) { ((CommentViewHolder) holder).moreButton.setVisibility(View.VISIBLE); + ((CommentViewHolder) holder).moreButton.setOnClickListener(view -> { ModifyCommentBottomSheetFragment modifyCommentBottomSheetFragment = new ModifyCommentBottomSheetFragment(); Bundle bundle = new Bundle(); @@ -513,6 +514,149 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie .setColorFilter(ContextCompat.getColor(mActivity, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); break; } + + if(mPost.isArchived()) { + ((CommentViewHolder) holder).replyButton + .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), + android.graphics.PorterDuff.Mode.SRC_IN); + ((CommentViewHolder) holder).upVoteButton + .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), + android.graphics.PorterDuff.Mode.SRC_IN); + ((CommentViewHolder) holder).downVoteButton + .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), + android.graphics.PorterDuff.Mode.SRC_IN); + } + + ((CommentViewHolder) holder).replyButton.setOnClickListener(view -> { + 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_reply_unavailable, Toast.LENGTH_SHORT).show(); + return; + } + + if(mPost.isLocked()) { + Toast.makeText(mActivity, R.string.locked_post_reply_unavailable, Toast.LENGTH_SHORT).show(); + return; + } + + Intent intent = new Intent(mActivity, CommentActivity.class); + intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, comment.getDepth() + 1); + intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, comment.getCommentContent()); + intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, comment.getFullName()); + intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, true); + + int parentPosition = mIsSingleCommentThreadMode ? holder.getAdapterPosition() - 2 : holder.getAdapterPosition() - 1; + intent.putExtra(CommentActivity.EXTRA_PARENT_POSITION_KEY, parentPosition); + mActivity.startActivityForResult(intent, CommentActivity.WRITE_COMMENT_REQUEST_CODE); + }); + + ((CommentViewHolder) holder).upVoteButton.setOnClickListener(view -> { + if(mPost.isArchived()) { + Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); + return; + } + + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + + int commentPosition = mIsSingleCommentThreadMode ? holder.getAdapterPosition() - 2 : holder.getAdapterPosition() - 1; + + int previousVoteType = mVisibleComments.get(commentPosition).getVoteType(); + String newVoteType; + + ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); + + if(previousVoteType != CommentData.VOTE_TYPE_UPVOTE) { + //Not upvoted before + mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_UPVOTE); + newVoteType = RedditUtils.DIR_UPVOTE; + ((CommentViewHolder) holder).upVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.backgroundColorPrimaryDark), android.graphics.PorterDuff.Mode.SRC_IN); + } else { + //Upvoted before + mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); + newVoteType = RedditUtils.DIR_UNVOTE; + ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); + } + + ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mVisibleComments.get(commentPosition).getScore() + mVisibleComments.get(commentPosition).getVoteType())); + + VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { + @Override + public void onVoteThingSuccess(int position) { + if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) { + mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_UPVOTE); + ((CommentViewHolder) holder).upVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.backgroundColorPrimaryDark), android.graphics.PorterDuff.Mode.SRC_IN); + } else { + mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); + ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); + } + + ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); + ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mVisibleComments.get(commentPosition).getScore() + mVisibleComments.get(commentPosition).getVoteType())); + } + + @Override + public void onVoteThingFail(int position) { } + }, mVisibleComments.get(commentPosition).getFullName(), newVoteType, holder.getAdapterPosition()); + }); + + ((CommentViewHolder) holder).downVoteButton.setOnClickListener(view -> { + if(mPost.isArchived()) { + Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); + return; + } + + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + + int commentPosition = mIsSingleCommentThreadMode ? holder.getAdapterPosition() - 2 : holder.getAdapterPosition() - 1; + + int previousVoteType = mVisibleComments.get(commentPosition).getVoteType(); + String newVoteType; + + ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); + + if(previousVoteType != CommentData.VOTE_TYPE_DOWNVOTE) { + //Not downvoted before + mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); + newVoteType = RedditUtils.DIR_DOWNVOTE; + ((CommentViewHolder) holder).downVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.colorAccent), android.graphics.PorterDuff.Mode.SRC_IN); + } else { + //Downvoted before + mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); + newVoteType = RedditUtils.DIR_UNVOTE; + ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); + } + + ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mVisibleComments.get(commentPosition).getScore() + mVisibleComments.get(commentPosition).getVoteType())); + + VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { + @Override + public void onVoteThingSuccess(int position1) { + if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) { + mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); + ((CommentViewHolder) holder).downVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.colorAccent), android.graphics.PorterDuff.Mode.SRC_IN); + } else { + mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); + ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); + } + + ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); + ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mVisibleComments.get(commentPosition).getScore() + mVisibleComments.get(commentPosition).getVoteType())); + } + + @Override + public void onVoteThingFail(int position1) { } + }, mVisibleComments.get(commentPosition).getFullName(), newVoteType, holder.getAdapterPosition()); + }); } else if(holder instanceof LoadMoreChildCommentsViewHolder) { CommentData placeholder; placeholder = mIsSingleCommentThreadMode ? mVisibleComments.get(holder.getAdapterPosition() - 2) @@ -776,8 +920,12 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie ((CommentViewHolder) holder).expandButton.setVisibility(View.GONE); ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); + ((CommentViewHolder) holder).replyButton.clearColorFilter(); ((CommentViewHolder) holder).itemView.setBackgroundColor( mActivity.getResources().getColor(R.color.cardViewBackgroundColor)); + } else if(holder instanceof PostDetailViewHolder) { + ((PostDetailViewHolder) holder).mUpvoteButton.clearColorFilter(); + ((PostDetailViewHolder) holder).mDownvoteButton.clearColorFilter(); } } @@ -863,13 +1011,13 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie }); mUpvoteButton.setOnClickListener(view -> { - if(mAccessToken == null) { - Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + if(mPost.isArchived()) { + Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); return; } - if(mPost.isArchived()) { - Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; } @@ -927,13 +1075,13 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie }); mDownvoteButton.setOnClickListener(view -> { - if(mAccessToken == null) { - Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + if(mPost.isArchived()) { + Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); return; } - if(mPost.isArchived()) { - Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); + if(mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); return; } @@ -1039,118 +1187,6 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie expandButton.setImageResource(R.drawable.ic_expand_less_black_20dp); } }); - - replyButton.setOnClickListener(view -> { - if(mAccessToken == null) { - Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); - return; - } - - CommentData comment = mIsSingleCommentThreadMode ? mVisibleComments.get(getAdapterPosition() - 2) : mVisibleComments.get(getAdapterPosition() - 1); - Intent intent = new Intent(mActivity, CommentActivity.class); - intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, comment.getDepth() + 1); - intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, comment.getCommentContent()); - intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, comment.getFullName()); - intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, true); - - int parentPosition = mIsSingleCommentThreadMode ? getAdapterPosition() - 2 : getAdapterPosition() - 1; - intent.putExtra(CommentActivity.EXTRA_PARENT_POSITION_KEY, parentPosition); - mActivity.startActivityForResult(intent, CommentActivity.WRITE_COMMENT_REQUEST_CODE); - }); - - upVoteButton.setOnClickListener(view -> { - if(mAccessToken == null) { - Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); - return; - } - - int commentPosition = mIsSingleCommentThreadMode ? getAdapterPosition() - 2 : getAdapterPosition() - 1; - - int previousVoteType = mVisibleComments.get(commentPosition).getVoteType(); - String newVoteType; - - downVoteButton.clearColorFilter(); - - if(previousVoteType != CommentData.VOTE_TYPE_UPVOTE) { - //Not upvoted before - mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_UPVOTE); - newVoteType = RedditUtils.DIR_UPVOTE; - upVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.backgroundColorPrimaryDark), android.graphics.PorterDuff.Mode.SRC_IN); - } else { - //Upvoted before - mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); - newVoteType = RedditUtils.DIR_UNVOTE; - upVoteButton.clearColorFilter(); - } - - scoreTextView.setText(Integer.toString(mVisibleComments.get(commentPosition).getScore() + mVisibleComments.get(commentPosition).getVoteType())); - - VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { - @Override - public void onVoteThingSuccess(int position) { - if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) { - mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_UPVOTE); - upVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.backgroundColorPrimaryDark), android.graphics.PorterDuff.Mode.SRC_IN); - } else { - mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); - upVoteButton.clearColorFilter(); - } - - downVoteButton.clearColorFilter(); - scoreTextView.setText(Integer.toString(mVisibleComments.get(commentPosition).getScore() + mVisibleComments.get(commentPosition).getVoteType())); - } - - @Override - public void onVoteThingFail(int position) { } - }, mVisibleComments.get(commentPosition).getFullName(), newVoteType, getAdapterPosition()); - }); - - downVoteButton.setOnClickListener(view -> { - if(mAccessToken == null) { - Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); - return; - } - - int commentPosition = mIsSingleCommentThreadMode ? getAdapterPosition() - 2 : getAdapterPosition() - 1; - - int previousVoteType = mVisibleComments.get(commentPosition).getVoteType(); - String newVoteType; - - upVoteButton.clearColorFilter(); - - if(previousVoteType != CommentData.VOTE_TYPE_DOWNVOTE) { - //Not downvoted before - mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); - newVoteType = RedditUtils.DIR_DOWNVOTE; - downVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.colorAccent), android.graphics.PorterDuff.Mode.SRC_IN); - } else { - //Downvoted before - mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); - newVoteType = RedditUtils.DIR_UNVOTE; - downVoteButton.clearColorFilter(); - } - - scoreTextView.setText(Integer.toString(mVisibleComments.get(commentPosition).getScore() + mVisibleComments.get(commentPosition).getVoteType())); - - VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { - @Override - public void onVoteThingSuccess(int position1) { - if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) { - mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); - downVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.colorAccent), android.graphics.PorterDuff.Mode.SRC_IN); - } else { - mVisibleComments.get(commentPosition).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); - downVoteButton.clearColorFilter(); - } - - upVoteButton.clearColorFilter(); - scoreTextView.setText(Integer.toString(mVisibleComments.get(commentPosition).getScore() + mVisibleComments.get(commentPosition).getVoteType())); - } - - @Override - public void onVoteThingFail(int position1) { } - }, mVisibleComments.get(commentPosition).getFullName(), newVoteType, getAdapterPosition()); - }); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java index 5739dfe6..c5606ae8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -15,6 +16,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; @@ -37,6 +39,11 @@ import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class EditCommentActivity extends AppCompatActivity { static final String EXTRA_CONTENT = "EC"; @@ -59,6 +66,9 @@ public class EditCommentActivity extends AppCompatActivity { @Named("oauth") Retrofit mOauthRetrofit; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -78,6 +88,24 @@ public class EditCommentActivity extends AppCompatActivity { window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java index e535b31d..882fe11c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -16,6 +17,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; @@ -38,6 +40,11 @@ import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class EditPostActivity extends AppCompatActivity { static final String EXTRA_TITLE = "ET"; @@ -58,6 +65,9 @@ public class EditPostActivity extends AppCompatActivity { @Named("oauth") Retrofit mOauthRetrofit; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -77,6 +87,24 @@ public class EditPostActivity extends AppCompatActivity { window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java index 7a5469b3..37142432 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -13,6 +14,7 @@ import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; @@ -26,6 +28,11 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class FilteredThingActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { @@ -59,6 +66,9 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -111,13 +121,31 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType } } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - name = getIntent().getExtras().getString(EXTRA_NAME); - postType = getIntent().getExtras().getInt(EXTRA_POST_TYPE); - int filter = getIntent().getExtras().getInt(EXTRA_FILTER); - String sortType = getIntent().getExtras().getString(EXTRA_SORT_TYPE); + name = getIntent().getStringExtra(EXTRA_NAME); + postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE); + int filter = getIntent().getIntExtra(EXTRA_FILTER, Post.TEXT_TYPE); + String sortType = getIntent().getStringExtra(EXTRA_SORT_TYPE); if(savedInstanceState != null) { mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java index f3d40d58..f13185d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java @@ -75,6 +75,7 @@ public class JSONUtils { static final String SHORT_NAME_KEY = "short_name"; static final String DESCRIPTION_HTML_KEY = "description_html"; static final String ARCHIVED_KEY = "archived"; + static final String LOCKEC_KEY = "locked"; static final String TEXT_EDITABLE_KEY = "text_editable"; static final String SUBJECT_KEY = "subject"; static final String CONTEXT_KEY = "context"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/LoginActivity.java index af4927d6..ebd5df13 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/LoginActivity.java @@ -2,8 +2,10 @@ package ml.docilealligator.infinityforreddit; import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.view.MenuItem; import android.webkit.CookieManager; @@ -13,6 +15,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import org.json.JSONException; import org.json.JSONObject; @@ -28,6 +31,11 @@ import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class LoginActivity extends AppCompatActivity { private String authCode; @@ -43,6 +51,9 @@ public class LoginActivity extends AppCompatActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -50,6 +61,24 @@ public class LoginActivity extends AppCompatActivity { ((Infinity) getApplication()).getAppComponent().inject(this); + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + getSupportActionBar().setDisplayHomeAsUpEnabled(true); WebView webView = findViewById(R.id.webview_login_activity); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index ada8dfcd..63a31ded 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -166,6 +166,7 @@ class ParsePost { boolean nsfw = data.getBoolean(JSONUtils.NSFW_KEY); boolean stickied = data.getBoolean(JSONUtils.STICKIED_KEY); boolean archived = data.getBoolean(JSONUtils.ARCHIVED_KEY); + boolean locked = data.getBoolean(JSONUtils.LOCKEC_KEY); String flair = null; if(!data.isNull(JSONUtils.LINK_FLAIR_TEXT_KEY)) { flair = data.getString(JSONUtils.LINK_FLAIR_TEXT_KEY); @@ -200,11 +201,11 @@ class ParsePost { data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0); return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, previewWidth, previewHeight, - score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, true, i); + score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, true, i); } else { return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, previewWidth, previewHeight, - score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, false, i); + score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, false, i); } } @@ -213,7 +214,7 @@ class ParsePost { String formattedPostTime, String title, String previewUrl, int previewWidth, int previewHeight, int score, int voteType, int gilded, String flair, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, - boolean isCrosspost, int i) throws JSONException { + boolean locked, boolean isCrosspost, int i) throws JSONException { Post post; boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY); @@ -226,7 +227,7 @@ class ParsePost { int postType = Post.TEXT_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, permalink, score, postType, voteType, gilded, flair, spoiler, nsfw, - stickied, archived, isCrosspost); + stickied, archived, locked, isCrosspost); if(data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -238,7 +239,7 @@ class ParsePost { int postType = Post.NO_PREVIEW_LINK_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, url, permalink, score, postType, - voteType, gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost); + voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, isCrosspost); if(data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -260,7 +261,7 @@ class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost, true); + gilded, flair, spoiler, nsfw, stickied, archived, locked, isCrosspost, true); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -277,7 +278,7 @@ class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost, false); + gilded, flair, spoiler, nsfw, stickied, archived, locked, isCrosspost, false); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(videoUrl); @@ -292,7 +293,7 @@ class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost, true); + gilded, flair, spoiler, nsfw, stickied, archived, locked, isCrosspost, true); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(videoUrl); @@ -305,7 +306,7 @@ class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, url, url, permalink, score, postType, - voteType, gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost); + voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -317,7 +318,7 @@ class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, permalink, score, postType, voteType, gilded, flair, spoiler, - nsfw, stickied, archived, isCrosspost); + nsfw, stickied, archived, locked, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -334,7 +335,7 @@ class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, gilded, - flair, spoiler, nsfw, stickied, archived, isCrosspost); + flair, spoiler, nsfw, stickied, archived, locked, isCrosspost); if(data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -354,7 +355,7 @@ class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, url, permalink, score, postType, - voteType, gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost); + voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); } else { @@ -364,7 +365,7 @@ class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, url, url, permalink, score, postType, voteType, - gilded, flair, spoiler, nsfw, stickied, archived, isCrosspost); + gilded, flair, spoiler, nsfw, stickied, archived, locked, isCrosspost); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java index 70413c41..855e85cd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java @@ -42,6 +42,7 @@ class Post implements Parcelable { private boolean nsfw; private boolean stickied; private boolean archived; + private boolean locked; private boolean isCrosspost; private boolean isDashVideo; private boolean isDownloadableGifOrVideo; @@ -49,7 +50,7 @@ class Post implements Parcelable { Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, String postTime, String title, String previewUrl, String permalink, int score, int postType, int voteType, int gilded, String flair, boolean spoiler, boolean nsfw, boolean stickied, - boolean archived, boolean isCrosspost, boolean isDashVideo) { + boolean archived, boolean locked, boolean isCrosspost, boolean isDashVideo) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; @@ -69,6 +70,7 @@ class Post implements Parcelable { this.nsfw = nsfw; this.stickied = stickied; this.archived = archived; + this.locked = locked; this.isCrosspost = isCrosspost; this.isDashVideo = isDashVideo; } @@ -76,7 +78,7 @@ class Post implements Parcelable { Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, String postTime, String title, String previewUrl, String url, String permalink, int score, int postType, int voteType, int gilded, String flair, boolean spoiler, boolean nsfw, boolean stickied, - boolean archived, boolean isCrosspost) { + boolean archived, boolean locked, boolean isCrosspost) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; @@ -97,12 +99,14 @@ class Post implements Parcelable { this.nsfw = nsfw; this.stickied = stickied; this.archived = archived; + this.locked = locked; this.isCrosspost = isCrosspost; } Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, String postTime, String title, String permalink, int score, int postType, int voteType, int gilded, - String flair, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean isCrosspost) { + String flair, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, + boolean isCrosspost) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; @@ -121,6 +125,7 @@ class Post implements Parcelable { this.nsfw = nsfw; this.stickied = stickied; this.archived = archived; + this.locked = locked; this.isCrosspost= isCrosspost; } @@ -152,6 +157,7 @@ class Post implements Parcelable { nsfw = in.readByte() != 0; stickied = in.readByte() != 0; archived = in.readByte() != 0; + locked = in.readByte() != 0; isCrosspost = in.readByte() != 0; isDashVideo = in.readByte() != 0; isDownloadableGifOrVideo = in.readByte() != 0; @@ -346,6 +352,10 @@ class Post implements Parcelable { return archived; } + boolean isLocked() { + return locked; + } + boolean isCrosspost() { return isCrosspost; } @@ -379,6 +389,7 @@ class Post implements Parcelable { parcel.writeByte((byte) (nsfw ? 1 : 0)); parcel.writeByte((byte) (stickied ? 1 : 0)); parcel.writeByte((byte) (archived ? 1 : 0)); + parcel.writeByte((byte) (locked ? 1 : 0)); parcel.writeByte((byte) (isCrosspost ? 1 : 0)); parcel.writeByte((byte) (isDashVideo ? 1 : 0)); parcel.writeByte((byte) (isDownloadableGifOrVideo ? 1 : 0)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java index 98287035..6e52811c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.net.Uri; import android.os.Build; @@ -19,6 +20,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; @@ -47,6 +49,11 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class PostImageActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -119,6 +126,9 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -138,6 +148,24 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -491,8 +519,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS mPostingSnackbar.dismiss(); if(submitImagePostEvent.postSuccess) { Intent intent = new Intent(PostImageActivity.this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, - mAccountName); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName); startActivity(intent); finish(); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java index a5ee9022..faa7769c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -15,6 +16,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; @@ -37,6 +39,11 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class PostLinkActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -95,6 +102,9 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -114,6 +124,24 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 8d00a010..9747542a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -351,9 +351,9 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo if(isArchived) { ((DataViewHolder) holder).upvoteButton - .setColorFilter(ContextCompat.getColor(mContext, R.color.voteUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + .setColorFilter(ContextCompat.getColor(mContext, R.color.voteAndReplyUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); ((DataViewHolder) holder).downvoteButton - .setColorFilter(ContextCompat.getColor(mContext, R.color.voteUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + .setColorFilter(ContextCompat.getColor(mContext, R.color.voteAndReplyUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); } if(post.isCrosspost()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java index bbdc016b..1d34d6fa 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -15,6 +16,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; @@ -37,6 +39,11 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class PostTextActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -95,6 +102,9 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -114,6 +124,24 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -122,6 +150,13 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); if(savedInstanceState != null) { + mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); + mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); + + if(!mNullAccessToken && mAccessToken == null) { + getCurrentAccount(); + } + subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE); subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); @@ -157,6 +192,8 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); } } else { + getCurrentAccount(); + isPosting = false; if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { @@ -237,6 +274,16 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh }); } + private void getCurrentAccount() { + new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { + if(account == null) { + mNullAccessToken = true; + } else { + mAccessToken = account.getAccessToken(); + } + }).execute(); + } + private void displaySubredditIcon() { if(iconUrl != null && !iconUrl.equals("")) { mGlide.load(iconUrl) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java index 1e9e5a02..c7cde780 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.net.Uri; import android.os.Build; @@ -18,6 +19,7 @@ import android.widget.VideoView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; @@ -42,6 +44,11 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class PostVideoActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -118,6 +125,9 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -137,6 +147,24 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RulesActivity.java index d33b63e8..4a30c1d6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RulesActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.AsyncTask; @@ -15,6 +16,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -39,11 +41,16 @@ import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class RulesActivity extends AppCompatActivity { static final String EXTRA_SUBREDDIT_NAME = "ESN"; - @BindView(R.id.appbar_rules_activity) AppBarLayout appBarLayout; + @BindView(R.id.appbar_layout_rules_activity) AppBarLayout appBarLayout; @BindView(R.id.toolbar_rules_activity) Toolbar toolbar; @BindView(R.id.progress_bar_rules_activity) ProgressBar progressBar; @BindView(R.id.recycler_view_rules_activity) RecyclerView recyclerView; @@ -57,6 +64,9 @@ public class RulesActivity extends AppCompatActivity { @Named("no_oauth") Retrofit mRetrofit; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -109,6 +119,24 @@ public class RulesActivity extends AppCompatActivity { } } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java index f6558013..b1627f0b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -17,6 +18,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; @@ -25,9 +27,16 @@ import com.ferfalk.simplesearchview.SimpleSearchView; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; +import javax.inject.Inject; + import butterknife.BindView; import butterknife.ButterKnife; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class SearchActivity extends AppCompatActivity { static final String EXTRA_QUERY = "EQ"; @@ -52,6 +61,9 @@ public class SearchActivity extends AppCompatActivity { private String subredditName; private boolean subredditIsUser; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -59,6 +71,8 @@ public class SearchActivity extends AppCompatActivity { ButterKnife.bind(this); + ((Infinity) getApplication()).getAppComponent().inject(this); + EventBus.getDefault().register(this); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -69,6 +83,24 @@ public class SearchActivity extends AppCompatActivity { window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); boolean searchOnlySubreddits = getIntent().getExtras().getBoolean(EXTRA_SEARCH_ONLY_SUBREDDITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java index 7d245f86..123aa509 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -14,6 +15,7 @@ import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -31,6 +33,11 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class SearchResultActivity extends AppCompatActivity implements SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, SearchUserAndSubredditSortTypeBottomSheetFragment.SearchUserAndSubredditSortTypeSelectionCallback { static final String EXTRA_QUERY = "QK"; @@ -46,7 +53,7 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos private String mQuery; private String mSubredditName; - @BindView(R.id.appbar_search_result_activity) AppBarLayout appBarLayout; + @BindView(R.id.appbar_layout_search_result_activity) AppBarLayout appBarLayout; @BindView(R.id.toolbar_search_result_activity) Toolbar toolbar; @BindView(R.id.tab_layout_search_result_activity) TabLayout tabLayout; @BindView(R.id.view_pager_search_result_activity) ViewPager viewPager; @@ -59,6 +66,9 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -108,6 +118,24 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos } } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchSubredditsResultActivity.java index a5059d59..c6bd9685 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchSubredditsResultActivity.java @@ -2,14 +2,25 @@ package ml.docilealligator.infinityforreddit; import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.os.Build; import android.os.Bundle; import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; +import com.google.android.material.appbar.AppBarLayout; + import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -18,6 +29,11 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class SearchSubredditsResultActivity extends AppCompatActivity { static final String EXTRA_QUERY = "EQ"; @@ -29,6 +45,7 @@ public class SearchSubredditsResultActivity extends AppCompatActivity { private static final String ACCOUNT_NAME_STATE = "ANS"; private static final String FRAGMENT_OUT_STATE = "FOS"; + @BindView(R.id.appbar_layout_search_subreddits_result_activity) AppBarLayout appBarLayout; @BindView(R.id.toolbar_search_subreddits_result_activity) Toolbar toolbar; private boolean mNullAccessToken = false; @@ -40,6 +57,9 @@ public class SearchSubredditsResultActivity extends AppCompatActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -51,6 +71,62 @@ public class SearchSubredditsResultActivity extends AppCompatActivity { EventBus.getDefault().register(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + Resources resources = getResources(); + + if(resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { + Window window = getWindow(); + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + + boolean lightNavBar = false; + if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + lightNavBar = true; + } + boolean finalLightNavBar = lightNavBar; + + View decorView = window.getDecorView(); + appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + @Override + void onStateChanged(AppBarLayout appBarLayout, State state) { + if(state == State.COLLAPSED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } else if(state == State.EXPANDED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } + } + }); + + int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (statusBarResourceId > 0) { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); + params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId); + toolbar.setLayoutParams(params); + } + } + } + + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java index 1ae29994..41c82e41 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -9,16 +10,24 @@ import android.view.Window; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import javax.inject.Inject; + import Settings.MainPreferenceFragment; import butterknife.BindView; import butterknife.ButterKnife; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class SettingsActivity extends AppCompatActivity implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback { @@ -26,6 +35,9 @@ public class SettingsActivity extends AppCompatActivity implements @BindView(R.id.toolbar_settings_activity) Toolbar toolbar; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -33,6 +45,8 @@ public class SettingsActivity extends AppCompatActivity implements ButterKnife.bind(this); + ((Infinity) getApplication()).getAppComponent().inject(this); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Window window = getWindow(); if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { @@ -41,6 +55,24 @@ public class SettingsActivity extends AppCompatActivity implements window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); if (savedInstanceState == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java index 2eae6426..ed9573fd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit; import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -16,6 +17,7 @@ import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; @@ -36,6 +38,11 @@ import butterknife.BindView; import butterknife.ButterKnife; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class SubredditSelectionActivity extends AppCompatActivity { static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS"; @@ -69,6 +76,9 @@ public class SubredditSelectionActivity extends AppCompatActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -121,6 +131,24 @@ public class SubredditSelectionActivity extends AppCompatActivity { } } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java index 1d70e9e9..305e6bee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -12,6 +13,7 @@ import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -36,6 +38,11 @@ import butterknife.BindView; import butterknife.ButterKnife; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class SubscribedThingListingActivity extends AppCompatActivity { private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS"; @@ -43,7 +50,7 @@ public class SubscribedThingListingActivity extends AppCompatActivity { private static final String ACCESS_TOKEN_STATE = "ATS"; private static final String ACCOUNT_NAME_STATE = "ANS"; - @BindView(R.id.appbar_subscribed_thing_listing_activity) AppBarLayout appBarLayout; + @BindView(R.id.appbar_layout_subscribed_thing_listing_activity) AppBarLayout appBarLayout; @BindView(R.id.toolbar_subscribed_thing_listing_activity) Toolbar toolbar; @BindView(R.id.tab_layout_subscribed_thing_listing_activity) TabLayout tabLayout; @BindView(R.id.view_pager_subscribed_thing_listing_activity) ViewPager viewPager; @@ -62,6 +69,9 @@ public class SubscribedThingListingActivity extends AppCompatActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -114,6 +124,24 @@ public class SubscribedThingListingActivity extends AppCompatActivity { } } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java index f2c9d277..8ca6ec16 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -17,6 +18,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.DividerItemDecoration; @@ -39,6 +41,11 @@ import butterknife.BindView; import butterknife.ButterKnife; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class ViewMessageActivity extends AppCompatActivity { static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; @@ -73,6 +80,9 @@ public class ViewMessageActivity extends AppCompatActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -132,6 +142,24 @@ public class ViewMessageActivity extends AppCompatActivity { } } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + toolbar.setTitle(R.string.inbox); setSupportActionBar(toolbar); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index e7d14b6f..ee39e267 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -20,6 +21,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.LinearLayoutManager; @@ -51,6 +53,10 @@ import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; import static ml.docilealligator.infinityforreddit.CommentActivity.EXTRA_COMMENT_DATA_KEY; import static ml.docilealligator.infinityforreddit.CommentActivity.WRITE_COMMENT_REQUEST_CODE; @@ -126,6 +132,9 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -186,6 +195,24 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo } } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + toolbar.setTitle(""); setSupportActionBar(toolbar); @@ -751,8 +778,18 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo refresh(true, true); return true; case R.id.action_comment_view_post_detail_activity: + if(mPost.isArchived()) { + showMessage(R.string.archived_post_reply_unavailable); + return true; + } + + if(mPost.isLocked()) { + showMessage(R.string.locked_post_comment_unavailable); + return true; + } + if(mAccessToken == null) { - Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show(); + showMessage(R.string.login_first); return true; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java index 94df7c6c..d37998e2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.AsyncTask; @@ -17,6 +18,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; @@ -46,6 +48,11 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class ViewSubredditDetailActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, PostTypeBottomSheetFragment.PostTypeSelectionCallback { @@ -106,6 +113,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -157,6 +167,24 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So } } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY); if(savedInstanceState == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java index cbb83cfd..e21789f3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.AsyncTask; @@ -17,6 +18,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; @@ -51,6 +53,11 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class ViewUserDetailActivity extends AppCompatActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { static final String EXTRA_USER_NAME_KEY = "EUNK"; @@ -114,6 +121,9 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -125,6 +135,24 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi EventBus.getDefault().register(this); + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + break; + case 2: + if(systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + } + username = getIntent().getStringExtra(EXTRA_USER_NAME_KEY); if (savedInstanceState == null) { |