Still prepare to support multiple themes.

This commit is contained in:
Alex Ning 2020-03-01 17:15:05 +08:00
parent 192d64f6bc
commit b1fe051023
7 changed files with 58 additions and 43 deletions

View File

@ -121,9 +121,6 @@ public abstract class BaseActivity extends AppCompatActivity {
public abstract SharedPreferences getSharedPreferences(); public abstract SharedPreferences getSharedPreferences();
protected boolean isLightStatusbar() {
return lightStatusbar;
}
protected boolean isChangeStatusBarIconColor() { protected boolean isChangeStatusBarIconColor() {
return changeStatusBarIconColor; return changeStatusBarIconColor;
} }
@ -136,7 +133,7 @@ public abstract class BaseActivity extends AppCompatActivity {
return systemVisibilityToolbarCollapsed; return systemVisibilityToolbarCollapsed;
} }
protected boolean isImmersiveInterface() { public boolean isImmersiveInterface() {
return immersiveInterface; return immersiveInterface;
} }
@ -163,7 +160,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}); });
} }
protected int getNavBarHeight() { public int getNavBarHeight() {
Resources resources = getResources(); Resources resources = getResources();
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) { if (navBarResourceId > 0) {

View File

@ -31,6 +31,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Activity.BaseActivity;
import ml.docilealligator.infinityforreddit.Adapter.CommentsListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.CommentsListingRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CommentViewModel; import ml.docilealligator.infinityforreddit.CommentViewModel;
@ -108,14 +109,15 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
Resources resources = getResources(); Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { mCommentRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) { if (navBarResourceId > 0) {
mCommentRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); mCommentRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
} }
} }
}
mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false); mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);

View File

@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Build; import android.os.Build;
@ -26,6 +27,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Activity.BaseActivity;
import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity; import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity;
import ml.docilealligator.infinityforreddit.Adapter.FollowedUsersRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.FollowedUsersRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.FragmentCommunicator;
@ -33,6 +35,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserViewModel; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserViewModel;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils; import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit; import retrofit2.Retrofit;
@ -57,6 +60,8 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
@Named("oauth") @Named("oauth")
Retrofit mOauthRetrofit; Retrofit mOauthRetrofit;
@Inject @Inject
SharedPreferences mSharedPreferences;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase; RedditDataRoomDatabase mRedditDataRoomDatabase;
SubscribedUserViewModel mSubscribedUserViewModel; SubscribedUserViewModel mSubscribedUserViewModel;
private Activity mActivity; private Activity mActivity;
@ -79,14 +84,15 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
Resources resources = getResources(); Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) { if (navBarResourceId > 0) {
mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
} }
} }
}
mGlide = Glide.with(this); mGlide = Glide.with(this);

View File

@ -11,6 +11,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Handler; import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -46,6 +47,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Activity.BaseActivity;
import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity; import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity;
import ml.docilealligator.infinityforreddit.Activity.MainActivity; import ml.docilealligator.infinityforreddit.Activity.MainActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
@ -195,17 +197,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
Resources resources = getResources(); Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 if ((activity instanceof BaseActivity && ((BaseActivity) activity).isImmersiveInterface())) {
&& (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT mPostRecyclerView.setPadding(0, 0, 0, ((BaseActivity) activity).getNavBarHeight());
|| resources.getBoolean(R.bool.isTablet)) } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) { if (navBarResourceId > 0) {
mPostRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); mPostRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
} }
} }
}
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && !resources.getBoolean(R.bool.isTablet)) { if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && !resources.getBoolean(R.bool.isTablet)) {
mLinearLayoutManager = new LinearLayoutManager(activity); mLinearLayoutManager = new LinearLayoutManager(activity);

View File

@ -31,6 +31,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Activity.BaseActivity;
import ml.docilealligator.infinityforreddit.Activity.SearchSubredditsResultActivity; import ml.docilealligator.infinityforreddit.Activity.SearchSubredditsResultActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.Adapter.SubredditListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.SubredditListingRecyclerViewAdapter;
@ -100,14 +101,15 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
Resources resources = getResources(); Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { mSubredditListingRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) { if (navBarResourceId > 0) {
mSubredditListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); mSubredditListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
} }
} }
}
mLinearLayoutManager = new LinearLayoutManager(getActivity()); mLinearLayoutManager = new LinearLayoutManager(getActivity());
mSubredditListingRecyclerView.setLayoutManager(mLinearLayoutManager); mSubredditListingRecyclerView.setLayoutManager(mLinearLayoutManager);

View File

@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Fragment;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Build; import android.os.Build;
@ -28,6 +29,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Activity.BaseActivity;
import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity; import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity;
import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity; import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity;
import ml.docilealligator.infinityforreddit.Adapter.SubscribedSubredditsRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.SubscribedSubredditsRecyclerViewAdapter;
@ -36,6 +38,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils; import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit; import retrofit2.Retrofit;
@ -63,6 +66,8 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
@Named("oauth") @Named("oauth")
Retrofit mOauthRetrofit; Retrofit mOauthRetrofit;
@Inject @Inject
SharedPreferences mSharedPreferences;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase; RedditDataRoomDatabase mRedditDataRoomDatabase;
private Activity mActivity; private Activity mActivity;
private RequestManager mGlide; private RequestManager mGlide;
@ -81,15 +86,16 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
((Infinity) mActivity.getApplication()).getAppComponent().inject(this); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) {
mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
Resources resources = getResources(); Resources resources = getResources();
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) { if (navBarResourceId > 0) {
mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
} }
} }
}
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);

View File

@ -30,6 +30,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Activity.BaseActivity;
import ml.docilealligator.infinityforreddit.Adapter.UserListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.UserListingRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
@ -97,14 +98,15 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
Resources resources = getResources(); Resources resources = getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) {
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { mUserListingRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) { if (navBarResourceId > 0) {
mUserListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); mUserListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
} }
} }
}
mLinearLayoutManager = new LinearLayoutManager(getActivity()); mLinearLayoutManager = new LinearLayoutManager(getActivity());
mUserListingRecyclerView.setLayoutManager(mLinearLayoutManager); mUserListingRecyclerView.setLayoutManager(mLinearLayoutManager);