From 0036bb11d8e8afb7bea775d822ea0b2ed763b130 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 5 Oct 2019 23:47:47 +0800 Subject: Disabling immersive mode (content shown under status bar and nav bar) is now available. --- .../Activity/AccountPostsActivity.java | 4 +- .../Activity/AccountSavedThingActivity.java | 4 +- .../Activity/FilteredThingActivity.java | 4 +- .../infinityforreddit/Activity/MainActivity.java | 86 ++++++++++++---------- .../infinityforreddit/Activity/RulesActivity.java | 4 +- .../Activity/SearchResultActivity.java | 4 +- .../Activity/SearchSubredditsResultActivity.java | 4 +- .../Activity/SettingsActivity.java | 9 +-- .../Activity/SubredditSelectionActivity.java | 4 +- .../Activity/SubscribedThingListingActivity.java | 4 +- .../Activity/ViewMessageActivity.java | 4 +- .../Activity/ViewPostDetailActivity.java | 3 +- .../Activity/ViewSubredditDetailActivity.java | 4 +- .../Activity/ViewUserDetailActivity.java | 4 +- .../infinityforreddit/Fragment/PostFragment.java | 5 +- .../Settings/MainPreferenceFragment.java | 13 ++++ .../infinityforreddit/SharedPreferencesUtils.java | 1 + app/src/main/res/layout/item_comment.xml | 3 +- app/src/main/res/values-night/colors.xml | 2 - app/src/main/res/values-v27/colors.xml | 4 + app/src/main/res/values/colors.xml | 2 +- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/main_preferences.xml | 6 ++ 23 files changed, 118 insertions(+), 61 deletions(-) create mode 100644 app/src/main/res/values-v27/colors.xml (limited to 'app/src/main') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java index a60975a5..56e03233 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java @@ -37,6 +37,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; public class AccountPostsActivity extends BaseActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { @@ -83,7 +84,8 @@ public class AccountPostsActivity extends BaseActivity implements UserThingSortT if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT - || resources.getBoolean(R.bool.isTablet))) { + || resources.getBoolean(R.bool.isTablet)) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java index bfb90405..1cc7e09f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java @@ -42,6 +42,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import retrofit2.Retrofit; public class AccountSavedThingActivity extends BaseActivity { @@ -92,7 +93,8 @@ public class AccountSavedThingActivity extends BaseActivity { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT - || resources.getBoolean(R.bool.isTablet))) { + || resources.getBoolean(R.bool.isTablet)) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java index 4206c08c..28e6dd20 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java @@ -39,6 +39,7 @@ import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; public class FilteredThingActivity extends BaseActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { @@ -95,7 +96,8 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeBotto if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT - || resources.getBoolean(R.bool.isTablet))) { + || resources.getBoolean(R.bool.isTablet)) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 48687a42..f48fc2b1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -7,6 +7,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; +import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -66,8 +67,8 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchToAnonymousAccountAsyncTask; -import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; +import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchMyInfo; import ml.docilealligator.infinityforreddit.FetchSubscribedThing; @@ -206,50 +207,61 @@ public class MainActivity extends BaseActivity implements SortTypeBottomSheetFra getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - Resources resources = getResources(); + 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) { + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + TypedValue typedValue = new TypedValue(); + getTheme().resolveAttribute(R.attr.navBarColor, typedValue, true); + int navBarColor = typedValue.data; + window.setNavigationBarColor(navBarColor); - 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); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + Resources resources = getResources(); - boolean lightNavBar = false; - if ((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - lightNavBar = true; - } - boolean finalLightNavBar = lightNavBar; + if ((resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); - View decorView = window.getDecorView(); - appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { - @Override - public 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); + 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 + public 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 = resources.getDimensionPixelSize(statusBarResourceId); - toolbar.setLayoutParams(params); - } + int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (statusBarResourceId > 0) { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); + params.topMargin = resources.getDimensionPixelSize(statusBarResourceId); + toolbar.setLayoutParams(params); + } - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - int navBarHeight = resources.getDimensionPixelSize(navBarResourceId); - CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); - params.bottomMargin = navBarHeight; - fab.setLayoutParams(params); + int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (navBarResourceId > 0) { + int navBarHeight = resources.getDimensionPixelSize(navBarResourceId); + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); + params.bottomMargin = navBarHeight; + fab.setLayoutParams(params); - nestedScrollView.setPadding(0, 0, 0, navBarHeight); + nestedScrollView.setPadding(0, 0, 0, navBarHeight); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java index aa5a5af2..32ff2a6f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java @@ -42,6 +42,7 @@ import ml.docilealligator.infinityforreddit.JSONUtils; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditAPI; import ml.docilealligator.infinityforreddit.Rule; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils; import retrofit2.Call; import retrofit2.Callback; @@ -85,7 +86,8 @@ public class RulesActivity extends BaseActivity { 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)) { + if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java index 49f565ec..9d2c8ca2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -44,6 +44,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; public class SearchResultActivity extends BaseActivity implements SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, SearchUserAndSubredditSortTypeBottomSheetFragment.SearchUserAndSubredditSortTypeSelectionCallback { @@ -89,7 +90,8 @@ public class SearchResultActivity extends BaseActivity implements SearchPostSort 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)) { + if ((resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java index eff35025..0b4cc900 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java @@ -33,6 +33,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; public class SearchSubredditsResultActivity extends BaseActivity { @@ -73,7 +74,8 @@ public class SearchSubredditsResultActivity extends BaseActivity { 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)) { + if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java index 106ba653..8d5e07a7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java @@ -1,13 +1,8 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.MenuItem; -import android.view.View; -import android.view.Window; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; @@ -45,7 +40,7 @@ public class SettingsActivity extends BaseActivity implements ButterKnife.bind(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + /*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) { window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); @@ -54,7 +49,7 @@ public class SettingsActivity extends BaseActivity implements getTheme().resolveAttribute(R.attr.navBarColor, typedValue, true); int navBarColor = typedValue.data; window.setNavigationBarColor(navBarColor); - } + }*/ setSupportActionBar(toolbar); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java index de79b647..160fa136 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java @@ -40,6 +40,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListing import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData; @@ -93,7 +94,8 @@ public class SubredditSelectionActivity extends BaseActivity { 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)) { + if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java index 5152bed5..7892ba32 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java @@ -41,6 +41,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListing import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData; @@ -89,7 +90,8 @@ public class SubscribedThingListingActivity extends BaseActivity { 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)) { + if ((resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java index 474ebbc7..1de46790 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java @@ -48,6 +48,7 @@ import ml.docilealligator.infinityforreddit.MessageViewModel; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import retrofit2.Retrofit; public class ViewMessageActivity extends BaseActivity { @@ -106,7 +107,8 @@ public class ViewMessageActivity extends BaseActivity { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT - || resources.getBoolean(R.bool.isTablet))) { + || resources.getBoolean(R.bool.isTablet)) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index bb835b49..12b4f908 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -175,7 +175,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT - || resources.getBoolean(R.bool.isTablet))) { + || resources.getBoolean(R.bool.isTablet)) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index 89726f06..2a64eab3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -56,6 +56,7 @@ import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.ReadMessage; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditDao; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel; @@ -148,7 +149,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp 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)) { + if ((resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java index e67bdd6f..fa86fb67 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -62,6 +62,7 @@ import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.ReadMessage; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserDao; import ml.docilealligator.infinityforreddit.User.UserDao; import ml.docilealligator.infinityforreddit.User.UserData; @@ -212,7 +213,8 @@ public class ViewUserDetailActivity extends BaseActivity implements UserThingSor if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT - || resources.getBoolean(R.bool.isTablet))) { + || resources.getBoolean(R.bool.isTablet)) + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index 0432b82e..83dce165 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -157,7 +157,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { Resources resources = getResources(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 + && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT + || resources.getBoolean(R.bool.isTablet)) + && 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"); if (navBarResourceId > 0) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java index c5403979..9e366424 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java @@ -46,6 +46,7 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { ((Infinity) activity.getApplication()).getAppComponent().inject(this); SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY); + SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY); SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY); SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY); @@ -61,6 +62,18 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { }); } + if(immersiveInterfaceSwitch != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + immersiveInterfaceSwitch.setVisible(true); + immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new RecreateActivityEvent()); + return true; + }); + } else { + immersiveInterfaceSwitch.setVisible(false); + } + } + if (nsfwSwitch != null) { nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java index 662f0e1e..69c717b0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java @@ -28,4 +28,5 @@ public class SharedPreferencesUtils { public static final String TITLE_FONT_SIZE_KEY = "title_font_size"; public static final String CONTENT_FONT_SIZE_KEY = "content_font_size"; public static final String AMOLED_DARK_KEY = "amoled_dark"; + public static final String IMMERSIVE_INTERFACE_KEY = "immersive_interface"; } diff --git a/app/src/main/res/layout/item_comment.xml b/app/src/main/res/layout/item_comment.xml index fc42b046..9bbccf54 100644 --- a/app/src/main/res/layout/item_comment.xml +++ b/app/src/main/res/layout/item_comment.xml @@ -95,7 +95,8 @@ android:layout_height="wrap_content" android:layout_marginStart="8dp" android:gravity="center" - android:textSize="?attr/font_default" + android:textSize="?attr/font_12" + android:textStyle="bold" app:layout_constraintStart_toEndOf="@+id/up_vote_button_item_post_comment" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent"/> diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index a6e767f1..6be140e4 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -24,8 +24,6 @@ #242424 - @color/roundedBottomSheetPrimaryBackground - #3C3C3C #FFFFFF diff --git a/app/src/main/res/values-v27/colors.xml b/app/src/main/res/values-v27/colors.xml new file mode 100644 index 00000000..2b3e3ce3 --- /dev/null +++ b/app/src/main/res/values-v27/colors.xml @@ -0,0 +1,4 @@ + + + @color/roundedBottomSheetPrimaryBackground + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 2f6087dd..9aa277b0 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -24,7 +24,7 @@ #FFFFFF - @color/roundedBottomSheetPrimaryBackground + @android:color/black #E91E63 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 236b1c4f..24407978 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -274,6 +274,7 @@ Dark Theme Device default Amoled Dark + Immersive Interface Lazy Mode Interval Font Size Title Font Size diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index 7bd2d85e..5f3925f4 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -20,6 +20,12 @@ app:key="amoled_dark" app:title="@string/settings_amoled_dark_title" /> + +