diff options
102 files changed, 962 insertions, 972 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java index 22483fad..8440fec7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java @@ -19,17 +19,13 @@ import okhttp3.Response; import okhttp3.Route; import retrofit2.Call; import retrofit2.Retrofit; -import retrofit2.converter.scalars.ScalarsConverterFactory; class AccessTokenAuthenticator implements Authenticator { private Retrofit mRetrofit; private RedditDataRoomDatabase mRedditDataRoomDatabase; - AccessTokenAuthenticator(RedditDataRoomDatabase accountRoomDatabase) { - mRetrofit = new Retrofit.Builder() - .baseUrl(RedditUtils.API_BASE_URI) - .addConverterFactory(ScalarsConverterFactory.create()) - .build(); + AccessTokenAuthenticator(Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) { + mRetrofit = retrofit; mRedditDataRoomDatabase = accountRoomDatabase; } 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 373a8655..2c7416a0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java @@ -1,15 +1,11 @@ package ml.docilealligator.infinityforreddit.Activity; 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.KeyEvent; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; @@ -27,7 +23,6 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; @@ -38,9 +33,9 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Post.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; public class AccountPostsActivity extends BaseActivity implements SortTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { @@ -84,45 +79,16 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect EventBus.getDefault().register(this); - Resources resources = getResources(); - - 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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; + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); } - boolean finalLightNavBar = lightNavBar; - - View decorView = window.getDecorView(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - 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 = getResources().getDimensionPixelSize(statusBarResourceId); - toolbar.setLayoutParams(params); + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); } } 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 7f3f0341..238ed3ce 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java @@ -1,14 +1,12 @@ package ml.docilealligator.infinityforreddit.Activity; 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.KeyEvent; import android.view.Menu; import android.view.MenuItem; -import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; @@ -32,7 +30,6 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; @@ -43,7 +40,6 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Post.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import retrofit2.Retrofit; public class AccountSavedThingActivity extends BaseActivity { @@ -92,44 +88,24 @@ public class AccountSavedThingActivity extends BaseActivity { Resources resources = getResources(); - 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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; + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); } - boolean finalLightNavBar = lightNavBar; - View decorView = window.getDecorView(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); } - 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 = getResources().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 = getResources().getDimensionPixelSize(statusBarResourceId); + toolbar.setLayoutParams(params); } setSupportActionBar(toolbar); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java index 0902a493..863322ce 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java @@ -2,21 +2,27 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.SharedPreferences; 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.View; +import android.view.ViewGroup; import android.view.Window; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; +import androidx.appcompat.widget.Toolbar; +import com.google.android.material.appbar.AppBarLayout; + +import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.TitleFontStyle; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; @@ -24,6 +30,13 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; public abstract class BaseActivity extends AppCompatActivity { + private boolean immersiveInterface; + private boolean lightStatusbar; + private boolean changeStatusBarIconColor = true; + private boolean transparentStatusBarAfterToolbarCollapsed; + private int systemVisibilityToolbarExpanded; + private int systemVisibilityToolbarCollapsed; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -31,10 +44,14 @@ public abstract class BaseActivity extends AppCompatActivity { SharedPreferences mSharedPreferences = getSharedPreferences(); boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + immersiveInterface = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && + mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true); switch (themeType) { case 0: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); getTheme().applyStyle(R.style.Theme_Purple, true); + lightStatusbar = !transparentStatusBarAfterToolbarCollapsed; + changeStatusBarIconColor = false; break; case 1: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); @@ -43,6 +60,7 @@ public abstract class BaseActivity extends AppCompatActivity { } else { getTheme().applyStyle(R.style.Theme_Default_NormalDark, true); } + changeStatusBarIconColor = false; break; case 2: if (systemDefault) { @@ -52,12 +70,15 @@ public abstract class BaseActivity extends AppCompatActivity { } if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { getTheme().applyStyle(R.style.Theme_Purple, true); + lightStatusbar = !transparentStatusBarAfterToolbarCollapsed; + changeStatusBarIconColor = false; } else { if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Default_AmoledDark, true); } else { getTheme().applyStyle(R.style.Theme_Default_NormalDark, true); } + changeStatusBarIconColor = false; } } @@ -70,17 +91,85 @@ public abstract class BaseActivity extends AppCompatActivity { getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + Window window = getWindow(); + View decorView = window.getDecorView(); 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); + if (lightStatusbar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + systemVisibilityToolbarExpanded = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + if (changeStatusBarIconColor) { + systemVisibilityToolbarCollapsed = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + } + } else { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + systemVisibilityToolbarExpanded = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + if (changeStatusBarIconColor) { + systemVisibilityToolbarCollapsed = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + } + } + window.setNavigationBarColor(Utils.getAttributeColor(this, R.attr.navBarColor)); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (lightStatusbar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + systemVisibilityToolbarExpanded = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + } + if (changeStatusBarIconColor) { + systemVisibilityToolbarCollapsed = 0; } - TypedValue typedValue = new TypedValue(); - getTheme().resolveAttribute(R.attr.navBarColor, typedValue, true); - int navBarColor = typedValue.data; - window.setNavigationBarColor(navBarColor); } } public abstract SharedPreferences getSharedPreferences(); + + protected boolean isChangeStatusBarIconColor() { + return changeStatusBarIconColor; + } + + protected int getSystemVisibilityToolbarExpanded() { + return systemVisibilityToolbarExpanded; + } + + protected int getSystemVisibilityToolbarCollapsed() { + return systemVisibilityToolbarCollapsed; + } + + public boolean isImmersiveInterface() { + return immersiveInterface; + } + + protected void adjustToolbar(Toolbar toolbar) { + 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); + } + } + + protected void addOnOffsetChangedListener(AppBarLayout appBarLayout) { + View decorView = getWindow().getDecorView(); + appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + @Override + public void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.State state) { + if (state == State.COLLAPSED) { + decorView.setSystemUiVisibility(getSystemVisibilityToolbarCollapsed()); + } else if (state == State.EXPANDED) { + decorView.setSystemUiVisibility(getSystemVisibilityToolbarExpanded()); + } + } + }); + } + + public int getNavBarHeight() { + Resources resources = getResources(); + int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (navBarResourceId > 0) { + return resources.getDimensionPixelSize(navBarResourceId); + } + return 0; + } + + public void setTransparentStatusBarAfterToolbarCollapsed(boolean transparentStatusBarAfterToolbarCollapsed) { + this.transparentStatusBarAfterToolbarCollapsed = transparentStatusBarAfterToolbarCollapsed; + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java index 84f68c4d..73cde34e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.text.Spanned; import android.text.style.SuperscriptSpan; @@ -23,6 +24,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; @@ -71,6 +73,8 @@ public class CommentActivity extends BaseActivity { @BindView(R.id.coordinator_layout_comment_activity) CoordinatorLayout coordinatorLayout; + @BindView(R.id.appbar_layout_comment_activity) + AppBarLayout appBarLayout; @BindView(R.id.toolbar_comment_activity) Toolbar toolbar; @BindView(R.id.comment_parent_markwon_view_comment_activity) @@ -106,6 +110,10 @@ public class CommentActivity extends BaseActivity { EventBus.getDefault().register(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + if (savedInstanceState == null) { getCurrentAccount(); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java index 7435e216..dcd3a734 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -16,6 +17,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.snackbar.Snackbar; import java.util.ArrayList; @@ -44,6 +46,8 @@ public class CreateMultiRedditActivity extends BaseActivity { private static final String SELECTED_OTHER_SUBREDDITS_STATE = "SOSS"; @BindView(R.id.coordinator_layout_create_multi_reddit_activity) CoordinatorLayout coordinatorLayout; + @BindView(R.id.appbar_layout_create_multi_reddit_activity) + AppBarLayout appBarLayout; @BindView(R.id.toolbar_create_multi_reddit_activity) Toolbar toolbar; @BindView(R.id.multi_reddit_name_edit_text_create_multi_reddit_activity) @@ -77,6 +81,10 @@ public class CreateMultiRedditActivity extends BaseActivity { ButterKnife.bind(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java index 7aff4cdf..657a0fc4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -14,6 +15,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; @@ -51,6 +53,8 @@ public class EditCommentActivity extends BaseActivity { @BindView(R.id.coordinator_layout_edit_comment_activity) CoordinatorLayout coordinatorLayout; + @BindView(R.id.appbar_layout_edit_comment_activity) + AppBarLayout appBarLayout; @BindView(R.id.toolbar_edit_comment_activity) Toolbar toolbar; @BindView(R.id.post_text_content_edit_text_edit_comment_activity) @@ -77,6 +81,10 @@ public class EditCommentActivity extends BaseActivity { EventBus.getDefault().register(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java index 6776c43e..a93a8b48 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -15,6 +16,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; @@ -48,6 +50,8 @@ public class EditPostActivity extends BaseActivity { @BindView(R.id.coordinator_layout_edit_post_activity) CoordinatorLayout coordinatorLayout; + @BindView(R.id.appbar_layout_edit_post_activity) + AppBarLayout appBarLayout; @BindView(R.id.toolbar_edit_post_activity) Toolbar toolbar; @BindView(R.id.post_title_text_view_edit_post_activity) @@ -76,6 +80,10 @@ public class EditPostActivity extends BaseActivity { EventBus.getDefault().register(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); 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 bb2e40f6..f2747ff8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java @@ -1,15 +1,11 @@ package ml.docilealligator.infinityforreddit.Activity; 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.KeyEvent; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; @@ -27,7 +23,6 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; @@ -42,9 +37,9 @@ import ml.docilealligator.infinityforreddit.Post.Post; import ml.docilealligator.infinityforreddit.Post.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { @@ -100,45 +95,16 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec EventBus.getDefault().register(this); - Resources resources = getResources(); - - 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); } - 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 = getResources().getDimensionPixelSize(statusBarResourceId); - toolbar.setLayoutParams(params); + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java index e5aa3668..89e19a2b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java @@ -5,6 +5,7 @@ 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; @@ -15,6 +16,8 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; +import com.google.android.material.appbar.AppBarLayout; + import org.json.JSONException; import org.json.JSONObject; @@ -43,6 +46,8 @@ public class LoginActivity extends BaseActivity { @BindView(R.id.toolbar_login_activity) Toolbar toolbar; + @BindView(R.id.appbar_layout_login_activity) + AppBarLayout appBarLayout; @BindView(R.id.webview_login_activity) WebView webView; @Inject @@ -66,6 +71,10 @@ public class LoginActivity extends BaseActivity { ButterKnife.bind(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); 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 2fd3c70c..af05d808 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -3,11 +3,8 @@ package ml.docilealligator.infinityforreddit.Activity; 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.util.TypedValue; import android.view.Gravity; import android.view.KeyEvent; import android.view.Menu; @@ -60,7 +57,6 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Account.AccountViewModel; import ml.docilealligator.infinityforreddit.Adapter.NavigationDrawerRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; @@ -196,61 +192,22 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb EventBus.getDefault().register(this); - getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - Resources resources = getResources(); - - 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); - - 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); - } - } - } - }); + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } - 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); - } + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - int navBarHeight = resources.getDimensionPixelSize(navBarResourceId); - linearLayoutBottomAppBar.setPadding(0, - (int) (6 * resources.getDisplayMetrics().density), 0, navBarHeight); - navDrawerRecyclerView.setPadding(0, 0, 0, navBarHeight); - } + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + linearLayoutBottomAppBar.setPadding(0, + (int) (6 * getResources().getDisplayMetrics().density), 0, navBarHeight); + navDrawerRecyclerView.setPadding(0, 0, 0, navBarHeight); } } } @@ -506,7 +463,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb case R.string.dark_theme: mSharedPreferences.edit().putString(SharedPreferencesUtils.THEME_KEY, "1").apply(); AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Default_AmoledDark, true); } else { getTheme().applyStyle(R.style.Theme_Default_NormalDark, true); @@ -1194,7 +1151,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb switch (viewPager.getCurrentItem()) { case 0: mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply(); - if(sortType.getTime() != null) { + if (sortType.getTime() != null) { mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply(); } @@ -1202,7 +1159,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb break; case 1: mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, sortType.getType().name()).apply(); - if(sortType.getTime() != null) { + if (sortType.getTime() != null) { mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, sortType.getTime().name()).apply(); } @@ -1210,7 +1167,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb break; case 2: mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, sortType.getType().name()).apply(); - if(sortType.getTime() != null) { + if (sortType.getTime() != null) { mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_ALL_POST, sortType.getTime().name()).apply(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java index 8ad32af2..4667ce9d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java @@ -2,13 +2,10 @@ package ml.docilealligator.infinityforreddit.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 android.widget.ImageView; @@ -36,7 +33,6 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Adapter.MultiRedditListingRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask; import ml.docilealligator.infinityforreddit.Infinity; @@ -45,7 +41,6 @@ import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditViewModel; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -96,49 +91,20 @@ public class MultiRedditListingActivity extends BaseActivity { ButterKnife.bind(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - Resources resources = getResources(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Window window = getWindow(); - 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); - - boolean lightNavBar = false; - if ((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - lightNavBar = true; - } - boolean finalLightNavBar = lightNavBar; + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(mAppBarLayout); + } - View decorView = window.getDecorView(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - mAppBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { - @Override - public void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.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) mToolbar.getLayoutParams(); - params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId); - mToolbar.setLayoutParams(params); - } + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(mToolbar); - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + mRecyclerView.setPadding(0, 0, 0, navBarHeight); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java index b5babcf2..69150291 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java @@ -26,6 +26,7 @@ import androidx.core.content.FileProvider; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; @@ -81,6 +82,8 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF @BindView(R.id.coordinator_layout_post_image_activity) CoordinatorLayout coordinatorLayout; + @BindView(R.id.appbar_layout_post_image_activity) + AppBarLayout appBarLayout; @BindView(R.id.toolbar_post_image_activity) Toolbar toolbar; @BindView(R.id.subreddit_icon_gif_image_view_post_image_activity) @@ -155,6 +158,10 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF EventBus.getDefault().register(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java index d2ed17f9..0f9b54fc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; +import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -19,6 +20,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; import com.libRG.CustomTextView; @@ -68,6 +70,8 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr @BindView(R.id.coordinator_layout_post_link_activity) CoordinatorLayout coordinatorLayout; + @BindView(R.id.appbar_layout_post_link_activity) + AppBarLayout appBarLayout; @BindView(R.id.toolbar_post_link_activity) Toolbar toolbar; @BindView(R.id.subreddit_icon_gif_image_view_post_link_activity) @@ -129,6 +133,10 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr EventBus.getDefault().register(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java index c2f5f9a0..988454e2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; +import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -19,6 +20,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; import com.libRG.CustomTextView; @@ -68,6 +70,8 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr @BindView(R.id.coordinator_layout_post_text_activity) CoordinatorLayout coordinatorLayout; + @BindView(R.id.appbar_layout_post_text_activity) + AppBarLayout appBarLayout; @BindView(R.id.toolbar_post_text_activity) Toolbar toolbar; @BindView(R.id.subreddit_icon_gif_image_view_search_activity) @@ -129,6 +133,10 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr EventBus.getDefault().register(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java index 7b887f20..33ce3006 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java @@ -31,6 +31,7 @@ import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.util.Util; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; @@ -83,6 +84,8 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF @BindView(R.id.coordinator_layout_post_video_activity) CoordinatorLayout coordinatorLayout; + @BindView(R.id.appbar_layout_post_video_activity) + AppBarLayout appBarLayout; @BindView(R.id.toolbar_post_video_activity) Toolbar toolbar; @BindView(R.id.subreddit_icon_gif_image_view_post_video_activity) @@ -163,6 +166,10 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF EventBus.getDefault().register(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); 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 18fd2ae2..57b15c4c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java @@ -1,14 +1,11 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.content.res.Resources; import android.os.AsyncTask; 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 android.widget.ProgressBar; @@ -35,14 +32,12 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Adapter.RulesRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.Utils.JSONUtils; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditAPI; import ml.docilealligator.infinityforreddit.Rule; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.JSONUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Call; import retrofit2.Callback; @@ -83,51 +78,20 @@ public class RulesActivity extends BaseActivity { 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) - && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { - 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; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Window window = getWindow(); - View decorView = window.getDecorView(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - 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); - } - } - } - }); + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } - 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); - } + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); - if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - recyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); - } + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + recyclerView.setPadding(0, 0, 0, navBarHeight); } } } 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 96685fec..ab2fad08 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -2,14 +2,11 @@ package ml.docilealligator.infinityforreddit.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.KeyEvent; import android.view.Menu; import android.view.MenuItem; -import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; @@ -31,7 +28,6 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; @@ -47,9 +43,9 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Post.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { @@ -94,42 +90,16 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - Resources resources = getResources(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Window window = getWindow(); - 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); - - 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); - } - } - } - }); + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } - 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); - } + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); } } 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 c68040ff..0b8a6b1e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java @@ -3,13 +3,9 @@ package ml.docilealligator.infinityforreddit.Activity; 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; @@ -26,14 +22,12 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; 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.Utils.SharedPreferencesUtils; public class SearchSubredditsResultActivity extends BaseActivity { @@ -71,42 +65,16 @@ public class SearchSubredditsResultActivity extends BaseActivity { EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - Resources resources = getResources(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Window window = getWindow(); - 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); + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } - 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 = getResources().getDimensionPixelSize(statusBarResourceId); - toolbar.setLayoutParams(params); - } + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); } } 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 c18ecf68..adaef84d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.view.MenuItem; @@ -10,6 +11,8 @@ import androidx.fragment.app.Fragment; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import com.google.android.material.appbar.AppBarLayout; + import javax.inject.Inject; import butterknife.BindView; @@ -25,6 +28,8 @@ public class SettingsActivity extends BaseActivity implements private static final String TITLE_STATE = "TS"; + @BindView(R.id.appbar_layout_settings_activity) + AppBarLayout appBarLayout; @BindView(R.id.toolbar_settings_activity) Toolbar toolbar; @@ -41,6 +46,10 @@ public class SettingsActivity extends BaseActivity implements ButterKnife.bind(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + setSupportActionBar(toolbar); if (savedInstanceState == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java index f326f320..2bf4e5dd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java @@ -2,14 +2,11 @@ package ml.docilealligator.infinityforreddit.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.Menu; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; @@ -36,7 +33,6 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Adapter.SubredditMultiselectionRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; @@ -44,7 +40,6 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubredditWithSelection; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import retrofit2.Retrofit; public class SubredditMultiselectionActivity extends BaseActivity { @@ -94,49 +89,20 @@ public class SubredditMultiselectionActivity extends BaseActivity { ButterKnife.bind(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - Resources resources = getResources(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Window window = getWindow(); - 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); - - 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(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - mAppBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { - @Override - public void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.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); - } - } - } - }); + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(mAppBarLayout); + } - int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); - if (statusBarResourceId > 0) { - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mToolbar.getLayoutParams(); - params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId); - mToolbar.setLayoutParams(params); - } + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(mToolbar); - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + mRecyclerView.setPadding(0, 0, 0, navBarHeight); } } } 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 1bd90df3..4abb5a42 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java @@ -3,14 +3,10 @@ package ml.docilealligator.infinityforreddit.Activity; 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.Menu; import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; @@ -31,7 +27,6 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; @@ -40,7 +35,6 @@ 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.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData; @@ -91,45 +85,16 @@ public class SubredditSelectionActivity extends BaseActivity { EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - Resources resources = getResources(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Window window = getWindow(); - 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); + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } - 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(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - 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 = getResources().getDimensionPixelSize(statusBarResourceId); - toolbar.setLayoutParams(params); - } + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); } } 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 1ed80213..506d47bf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java @@ -1,12 +1,9 @@ package ml.docilealligator.infinityforreddit.Activity; 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; @@ -32,7 +29,6 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; @@ -46,7 +42,6 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import retrofit2.Retrofit; public class SubscribedThingListingActivity extends BaseActivity { @@ -89,45 +84,16 @@ public class SubscribedThingListingActivity extends BaseActivity { EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - Resources resources = getResources(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Window window = getWindow(); - 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); - - boolean lightNavBar = false; - if ((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - lightNavBar = true; - } - boolean finalLightNavBar = lightNavBar; + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } - View decorView = window.getDecorView(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - 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 = getResources().getDimensionPixelSize(statusBarResourceId); - toolbar.setLayoutParams(params); - } + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java index 49b00060..5c641cff 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java @@ -31,10 +31,13 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import androidx.core.content.FileProvider; import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestManager; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.engine.GlideException; +import com.bumptech.glide.load.resource.gif.GifDrawable; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; @@ -47,12 +50,14 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.AsyncTask.SaveGIFToFileAsyncTask; +import ml.docilealligator.infinityforreddit.BuildConfig; import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.TitleFontStyle; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import pl.droidsonroids.gif.GifImageView; public class ViewGIFActivity extends AppCompatActivity { @@ -74,6 +79,7 @@ public class ViewGIFActivity extends AppCompatActivity { private boolean isDownloading = false; private Menu mMenu; private Swipe swipe; + private RequestManager glide; private String mImageUrl; private String mImageFileName; private float totalLengthY = 0.0f; @@ -107,6 +113,8 @@ public class ViewGIFActivity extends AppCompatActivity { actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor))); setTitle(""); + glide = Glide.with(this); + Intent intent = getIntent(); mImageUrl = intent.getStringExtra(IMAGE_URL_KEY); mImageFileName = intent.getStringExtra(FILE_NAME_KEY); @@ -316,7 +324,7 @@ public class ViewGIFActivity extends AppCompatActivity { } private void loadImage() { - Glide.with(this).load(mImageUrl).listener(new RequestListener<Drawable>() { + glide.load(mImageUrl).listener(new RequestListener<Drawable>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { mProgressBar.setVisibility(View.GONE); @@ -345,7 +353,7 @@ public class ViewGIFActivity extends AppCompatActivity { case android.R.id.home: finish(); return true; - case R.id.action_download_view_gif: + case R.id.action_download_view_gif_activity: if (isDownloading) { return false; } @@ -371,6 +379,44 @@ public class ViewGIFActivity extends AppCompatActivity { } return true; + case R.id.action_share_view_gif_activity: + Toast.makeText(ViewGIFActivity.this, R.string.save_gif_before_sharing, Toast.LENGTH_SHORT).show(); + glide.asGif().load(mImageUrl).listener(new RequestListener<GifDrawable>() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) { + return false; + } + + @Override + public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) { + if (getExternalCacheDir() != null) { + new SaveGIFToFileAsyncTask(resource, getExternalCacheDir().getPath(), + new SaveGIFToFileAsyncTask.SaveGIFToFileAsyncTaskListener() { + @Override + public void saveSuccess(File imageFile) { + Uri uri = FileProvider.getUriForFile(ViewGIFActivity.this, + BuildConfig.APPLICATION_ID + ".provider", imageFile); + Intent shareIntent = new Intent(); + shareIntent.setAction(Intent.ACTION_SEND); + shareIntent.putExtra(Intent.EXTRA_STREAM, uri); + shareIntent.setType("image/*"); + shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + startActivity(Intent.createChooser(shareIntent, getString(R.string.share))); + } + + @Override + public void saveFailed() { + + } + }).execute(); + } else { + Toast.makeText(ViewGIFActivity.this, + R.string.cannot_get_storage, Toast.LENGTH_SHORT).show(); + } + return false; + } + }).submit(); + return true; } return false; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java index c90f0d60..c58d0736 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java @@ -9,6 +9,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.graphics.Bitmap; import android.graphics.PorterDuff; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; @@ -31,16 +32,20 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import androidx.core.content.FileProvider; import com.alexvasilkov.gestures.GestureController; import com.alexvasilkov.gestures.State; import com.alexvasilkov.gestures.views.GestureImageView; import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestManager; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.target.Target; +import com.bumptech.glide.request.transition.Transition; import com.github.pwittchen.swipe.library.rx2.SimpleSwipeListener; import com.github.pwittchen.swipe.library.rx2.Swipe; @@ -50,6 +55,8 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.AsyncTask.SaveImageToFileAsyncTask; +import ml.docilealligator.infinityforreddit.BuildConfig; import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Infinity; @@ -82,6 +89,7 @@ public class ViewImageActivity extends AppCompatActivity { private float touchY = -1.0f; private float zoom = 1.0f; private boolean isSwiping = false; + private RequestManager glide; @Override protected void onCreate(Bundle savedInstanceState) { @@ -110,6 +118,8 @@ public class ViewImageActivity extends AppCompatActivity { actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor))); setTitle(""); + glide = Glide.with(this); + Intent intent = getIntent(); mImageUrl = intent.getStringExtra(IMAGE_URL_KEY); mImageFileName = intent.getStringExtra(FILE_NAME_KEY); @@ -333,7 +343,7 @@ public class ViewImageActivity extends AppCompatActivity { } private void loadImage() { - Glide.with(this).load(mImageUrl).listener(new RequestListener<Drawable>() { + glide.load(mImageUrl).listener(new RequestListener<Drawable>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { mProgressBar.setVisibility(View.GONE); @@ -352,7 +362,7 @@ public class ViewImageActivity extends AppCompatActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { mMenu = menu; - getMenuInflater().inflate(R.menu.view_image, menu); + getMenuInflater().inflate(R.menu.view_image_activity, menu); return true; } @@ -362,7 +372,7 @@ public class ViewImageActivity extends AppCompatActivity { case android.R.id.home: finish(); return true; - case R.id.action_download_view_image: + case R.id.action_download_view_image_activity: if (isDownloading) { return false; } @@ -388,6 +398,45 @@ public class ViewImageActivity extends AppCompatActivity { } return true; + case R.id.action_share_view_image_activity: + glide.asBitmap().load(mImageUrl).into(new CustomTarget<Bitmap>() { + + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { + if (getExternalCacheDir() != null) { + Toast.makeText(ViewImageActivity.this, R.string.save_image_before_sharing, Toast.LENGTH_SHORT).show(); + new SaveImageToFileAsyncTask(resource, getExternalCacheDir().getPath(), + new SaveImageToFileAsyncTask.SaveImageToFileAsyncTaskListener() { + @Override + public void saveSuccess(File imageFile) { + Uri uri = FileProvider.getUriForFile(ViewImageActivity.this, + BuildConfig.APPLICATION_ID + ".provider",imageFile); + Intent shareIntent = new Intent(); + shareIntent.setAction(Intent.ACTION_SEND); + shareIntent.putExtra(Intent.EXTRA_STREAM, uri); + shareIntent.setType("image/*"); + shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + startActivity(Intent.createChooser(shareIntent, getString(R.string.share))); + } + + @Override + public void saveFailed() { + Toast.makeText(ViewImageActivity.this, + R.string.cannot_save_image, Toast.LENGTH_SHORT).show(); + } + }).execute(); + } else { + Toast.makeText(ViewImageActivity.this, + R.string.cannot_get_storage, Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); + return true; } return false; 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 92450d0c..0468038a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java @@ -1,14 +1,12 @@ package ml.docilealligator.infinityforreddit.Activity; 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.Menu; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; @@ -38,7 +36,6 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Adapter.MessageRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; @@ -48,7 +45,6 @@ import ml.docilealligator.infinityforreddit.MessageViewModel; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -106,48 +102,21 @@ public class ViewMessageActivity extends BaseActivity { Resources resources = getResources(); - 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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; + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); } - boolean finalLightNavBar = lightNavBar; - View decorView = window.getDecorView(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - 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); - } - } - } - }); + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); - 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); - } - - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + mRecyclerView.setPadding(0, 0, 0, navBarHeight); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java index f002bb08..cfe2af6f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java @@ -2,14 +2,11 @@ package ml.docilealligator.infinityforreddit.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.Menu; import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.Toast; @@ -27,7 +24,6 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment; @@ -95,43 +91,16 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT Resources resources = getResources(); - 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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; + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); } - boolean finalLightNavBar = lightNavBar; - View decorView = window.getDecorView(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - 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 = getResources().getDimensionPixelSize(statusBarResourceId); - toolbar.setLayoutParams(params); + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); } } 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 1842a59d..9d77c73b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -2,15 +2,12 @@ package ml.docilealligator.infinityforreddit.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.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; @@ -52,7 +49,6 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Adapter.CommentAndPostRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; import ml.docilealligator.infinityforreddit.CommentData; @@ -202,55 +198,25 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mSlidrInterface = Slidr.attach(this); } - Resources resources = getResources(); - - 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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; + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); } - boolean finalLightNavBar = lightNavBar; - View decorView = window.getDecorView(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - 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); - } - } + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); + + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); + params.bottomMargin = navBarHeight; + fab.setLayoutParams(params); + mRecyclerView.setPadding(0, 0, 0, navBarHeight); + showToast = true; } - }); - - 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); - } - - 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); - mRecyclerView.setPadding(0, 0, 0, navBarHeight); - showToast = true; } } @@ -460,10 +426,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (mAccessToken != null) { if (mPost.isSaved()) { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_bookmark_black_24dp); + saveItem.setIcon(R.drawable.ic_bookmark_toolbar_24dp); } else { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_bookmark_border_black_24dp); + saveItem.setIcon(R.drawable.ic_bookmark_border_toolbar_24dp); } if (mPost.isHidden()) { @@ -601,10 +567,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (mAccessToken != null) { if (post.isSaved()) { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_bookmark_black_24dp); + saveItem.setIcon(R.drawable.ic_bookmark_toolbar_24dp); } else { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_bookmark_border_black_24dp); + saveItem.setIcon(R.drawable.ic_bookmark_border_toolbar_24dp); } if (post.isHidden()) { @@ -911,10 +877,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (mAccessToken != null) { if (post.isSaved()) { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_bookmark_black_24dp); + saveItem.setIcon(R.drawable.ic_bookmark_toolbar_24dp); } else { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_bookmark_border_black_24dp); + saveItem.setIcon(R.drawable.ic_bookmark_border_toolbar_24dp); } if (post.isHidden()) { @@ -1181,10 +1147,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (mMenu != null) { if (event.post.isSaved()) { mMenu.findItem(R.id.action_save_view_post_detail_activity).setIcon(getResources() - .getDrawable(R.drawable.ic_bookmark_black_24dp)); + .getDrawable(R.drawable.ic_bookmark_toolbar_24dp)); } else { mMenu.findItem(R.id.action_save_view_post_detail_activity).setIcon(getResources() - .getDrawable(R.drawable.ic_bookmark_border_black_24dp)); + .getDrawable(R.drawable.ic_bookmark_border_toolbar_24dp)); } } mAdapter.updatePost(mPost); @@ -1241,10 +1207,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS if (mAccessToken != null) { if (mPost.isSaved()) { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_bookmark_black_24dp); + saveItem.setIcon(R.drawable.ic_bookmark_toolbar_24dp); } else { saveItem.setVisible(true); - saveItem.setIcon(R.drawable.ic_bookmark_border_black_24dp); + saveItem.setIcon(R.drawable.ic_bookmark_border_toolbar_24dp); } if (mPost.isHidden()) { @@ -1324,13 +1290,13 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS case R.id.action_save_view_post_detail_activity: if (mPost != null && mAccessToken != null) { if (mPost.isSaved()) { - item.setIcon(R.drawable.ic_bookmark_border_black_24dp); + item.setIcon(R.drawable.ic_bookmark_border_toolbar_24dp); SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), new SaveThing.SaveThingListener() { @Override public void success() { mPost.setSaved(false); - item.setIcon(R.drawable.ic_bookmark_border_black_24dp); + item.setIcon(R.drawable.ic_bookmark_border_toolbar_24dp); showMessage(R.string.post_unsaved_success); EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } @@ -1338,19 +1304,19 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS @Override public void failed() { mPost.setSaved(true); - item.setIcon(R.drawable.ic_bookmark_black_24dp); + item.setIcon(R.drawable.ic_bookmark_toolbar_24dp); showMessage(R.string.post_unsaved_failed); EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } }); } else { - item.setIcon(R.drawable.ic_bookmark_black_24dp); + item.setIcon(R.drawable.ic_bookmark_toolbar_24dp); SaveThing.saveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(), new SaveThing.SaveThingListener() { @Override public void success() { mPost.setSaved(true); - item.setIcon(R.drawable.ic_bookmark_black_24dp); + item.setIcon(R.drawable.ic_bookmark_toolbar_24dp); showMessage(R.string.post_saved_success); EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } @@ -1358,7 +1324,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS @Override public void failed() { mPost.setSaved(false); - item.setIcon(R.drawable.ic_bookmark_border_black_24dp); + item.setIcon(R.drawable.ic_bookmark_border_toolbar_24dp); showMessage(R.string.post_saved_failed); EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java index cb11bbcc..35076de2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java @@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.content.res.Resources; import android.net.Uri; import android.os.Build; @@ -13,8 +12,6 @@ import android.text.util.Linkify; import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.TextView; @@ -46,7 +43,6 @@ import io.noties.markwon.recycler.table.TableEntry; import io.noties.markwon.recycler.table.TableEntryPlugin; import io.noties.markwon.simple.ext.SimpleExtPlugin; import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask; import ml.docilealligator.infinityforreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.Infinity; @@ -54,7 +50,6 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -89,54 +84,26 @@ public class ViewSidebarActivity extends BaseActivity { Resources resources = getResources(); - 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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; + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); } - boolean finalLightNavBar = lightNavBar; - View decorView = window.getDecorView(); - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { - @Override - public void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.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); - } - } + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); + + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + int px = (int) TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + 16, + resources.getDisplayMetrics() + ); + markdownRecyclerView.setPadding(px, px, px, navBarHeight); } - }); - - 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); - } - - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - int dp = 16; - int px = (int) TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_DIP, - dp, - resources.getDisplayMetrics() - ); - markdownRecyclerView.setPadding(px, px, px, resources.getDimensionPixelSize(navBarResourceId)); } } 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 99374dc5..b9640612 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -3,8 +3,6 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; -import android.content.res.Configuration; -import android.content.res.Resources; import android.os.Build; import android.os.Bundle; import android.view.Gravity; @@ -12,7 +10,6 @@ import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; @@ -45,7 +42,6 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsSubscribedToSubredditAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask; @@ -163,6 +159,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Override protected void onCreate(Bundle savedInstanceState) { ((Infinity) getApplication()).getAppComponent().inject(this); + setTransparentStatusBarAfterToolbarCollapsed(true); super.onCreate(savedInstanceState); @@ -172,44 +169,24 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - Resources resources = getResources(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Window window = getWindow(); - 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); - - boolean lightNavBar = false; - if ((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - lightNavBar = true; - } - boolean finalLightNavBar = lightNavBar; + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } - 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); - } - } - } - }); + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + adjustToolbar(toolbar); - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - int navBarHeight = resources.getDimensionPixelSize(navBarResourceId); + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); params.bottomMargin = navBarHeight; fab.setLayoutParams(params); linearLayoutBottomAppBar.setPadding(0, - (int) (6 * resources.getDisplayMetrics().density), 0, navBarHeight); + (int) (6 * getResources().getDisplayMetrics().density), 0, navBarHeight); showToast = true; } @@ -275,9 +252,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp subredditNameTextView.setText(title); toolbar.setTitle(title); - ViewGroup.MarginLayoutParams toolbarParams = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); - toolbarParams.topMargin = statusBarHeight; - toolbar.setLayoutParams(toolbarParams); + adjustToolbar(toolbar); setSupportActionBar(toolbar); glide = Glide.with(this); 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 35a98f69..a71b2c71 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; -import android.content.res.Configuration; import android.content.res.Resources; import android.os.AsyncTask; import android.os.Build; @@ -98,6 +97,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele ViewPager viewPager; @BindView(R.id.appbar_layout_view_user_detail) AppBarLayout appBarLayout; + @BindView(R.id.toolbar_view_user_detail_activity) + Toolbar toolbar; @BindView(R.id.tab_layout_view_user_detail_activity) TabLayout tabLayout; @BindView(R.id.collapsing_toolbar_layout_view_user_detail_activity) @@ -151,6 +152,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @Override protected void onCreate(Bundle savedInstanceState) { ((Infinity) getApplication()).getAppComponent().inject(this); + setTransparentStatusBarAfterToolbarCollapsed(true); super.onCreate(savedInstanceState); @@ -188,17 +190,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele Resources resources = getResources(); - //Get status bar height - int statusBarHeight = 0; - int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); - if (resourceId > 0) { - statusBarHeight = resources.getDimensionPixelSize(resourceId); - } - - Toolbar toolbar = findViewById(R.id.toolbar); - ViewGroup.MarginLayoutParams toolbarLayoutParams = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); - toolbarLayoutParams.topMargin = statusBarHeight; - toolbar.setLayoutParams(toolbarLayoutParams); + adjustToolbar(toolbar); String title = "u/" + username; userNameTextView.setText(title); @@ -213,42 +205,47 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele collapsedTabIndicatorColor = Utils.getAttributeColor(this, R.attr.tabLayoutWithCollapsedCollapsingToolbarTabIndicator); collapsedTabBackgroundColor = Utils.getAttributeColor(this, R.attr.tabLayoutWithCollapsedCollapsingToolbarTabBackground); - 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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; + if (isImmersiveInterface()) { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + showToast = 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); + if (isChangeStatusBarIconColor()) { + appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + @Override + public void onStateChanged(AppBarLayout appBarLayout, State state) { + if (state == State.COLLAPSED) { + decorView.setSystemUiVisibility(getSystemVisibilityToolbarCollapsed()); + tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); + tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); + tabLayout.setBackgroundColor(collapsedTabBackgroundColor); + } else if (state == State.EXPANDED) { + decorView.setSystemUiVisibility(getSystemVisibilityToolbarExpanded()); + tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor); + tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor); + tabLayout.setBackgroundColor(expandedTabBackgroundColor); } - tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); - tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); - tabLayout.setBackgroundColor(collapsedTabBackgroundColor); - } else if (state == State.EXPANDED) { - if (finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + }); + } else { + appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + @Override + public void onStateChanged(AppBarLayout appBarLayout, State state) { + if (state == State.COLLAPSED) { + tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); + tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); + tabLayout.setBackgroundColor(collapsedTabBackgroundColor); + } else if (state == State.EXPANDED) { + tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor); + tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor); + tabLayout.setBackgroundColor(expandedTabBackgroundColor); } - tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor); - tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor); - tabLayout.setBackgroundColor(expandedTabBackgroundColor); } - } - }); - - showToast = true; + }); + } } else { appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java index fc38edeb..935538e7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java @@ -385,7 +385,7 @@ public class ViewVideoActivity extends AppCompatActivity { case android.R.id.home: finish(); return true; - case R.id.action_download_view_video: + case R.id.action_download_view_video_activity: isDownloading = true; if (Build.VERSION.SDK_INT >= 23) { if (ContextCompat.checkSelfPermission(this, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 6c5a74d0..41dc90cf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -1502,7 +1502,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView MaterialCardView cardView; @BindView(R.id.icon_gif_image_view_item_post) AspectRatioGifImageView iconGifImageView; - @BindView(R.id.name_text_view_item_post) + @BindView(R.id.subreddit_name_text_view_item_post) TextView subredditTextView; @BindView(R.id.user_text_view_item_post) TextView userTextView; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java index 96389c00..a8619df8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -5,12 +5,15 @@ import android.content.SharedPreferences; import androidx.preference.PreferenceManager; +import java.util.concurrent.TimeUnit; + import javax.inject.Named; import javax.inject.Singleton; import dagger.Module; import dagger.Provides; import ml.docilealligator.infinityforreddit.Utils.RedditUtils; +import okhttp3.ConnectionPool; import okhttp3.OkHttpClient; import retrofit2.Retrofit; import retrofit2.converter.scalars.ScalarsConverterFactory; @@ -76,13 +79,13 @@ class AppModule { @Provides @Singleton - OkHttpClient provideOkHttpClient(RedditDataRoomDatabase accountRoomDatabase) { + OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) { OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder(); - okHttpClientBuilder.authenticator(new AccessTokenAuthenticator(accountRoomDatabase)); - /*.connectTimeout(30, TimeUnit.SECONDS) + okHttpClientBuilder.authenticator(new AccessTokenAuthenticator(retrofit, accountRoomDatabase)) + .connectTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) - .connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS));*/ + .connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS)); //.addInterceptor(new Okhttp3DebugInterceptor(mApplication)); return okHttpClientBuilder.build(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SaveGIFToFileAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SaveGIFToFileAsyncTask.java new file mode 100644 index 00000000..39452004 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SaveGIFToFileAsyncTask.java @@ -0,0 +1,57 @@ +package ml.docilealligator.infinityforreddit.AsyncTask; + +import android.os.AsyncTask; + +import com.bumptech.glide.load.resource.gif.GifDrawable; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; + +public class SaveGIFToFileAsyncTask extends AsyncTask<Void, Void, Void> { + private GifDrawable resource; + private String cacheDirPath; + private SaveGIFToFileAsyncTaskListener saveImageToFileAsyncTaskListener; + private boolean saveSuccess = true; + private File imageFile; + + public SaveGIFToFileAsyncTask(GifDrawable resource, String cacheDirPath, + SaveGIFToFileAsyncTaskListener saveImageToFileAsyncTaskListener) { + this.resource = resource; + this.cacheDirPath = cacheDirPath; + this.saveImageToFileAsyncTaskListener = saveImageToFileAsyncTaskListener; + } + + public interface SaveGIFToFileAsyncTaskListener { + void saveSuccess(File imageFile); + void saveFailed(); + } + + @Override + protected Void doInBackground(Void... voids) { + try { + imageFile = new File(cacheDirPath, "shared.gif"); + ByteBuffer byteBuffer = resource.getBuffer(); + OutputStream outputStream = new FileOutputStream(imageFile); + byte[] bytes = new byte[byteBuffer.capacity()]; + ((ByteBuffer) byteBuffer.duplicate().clear()).get(bytes); + outputStream.write(bytes, 0, bytes.length); + outputStream.close(); + } catch (IOException e) { + saveSuccess = false; + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + if (saveSuccess) { + saveImageToFileAsyncTaskListener.saveSuccess(imageFile); + } else { + saveImageToFileAsyncTaskListener.saveFailed(); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SaveImageToFileAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SaveImageToFileAsyncTask.java new file mode 100644 index 00000000..07164a46 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SaveImageToFileAsyncTask.java @@ -0,0 +1,55 @@ +package ml.docilealligator.infinityforreddit.AsyncTask; + +import android.graphics.Bitmap; +import android.os.AsyncTask; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +public class SaveImageToFileAsyncTask extends AsyncTask<Void, Void, Void> { + private Bitmap resource; + private String cacheDirPath; + private SaveImageToFileAsyncTaskListener saveImageToFileAsyncTaskListener; + private boolean saveSuccess = true; + private File imageFile; + + public SaveImageToFileAsyncTask(Bitmap resource, String cacheDirPath, + SaveImageToFileAsyncTaskListener saveImageToFileAsyncTaskListener) { + this.resource = resource; + this.cacheDirPath = cacheDirPath; + this.saveImageToFileAsyncTaskListener = saveImageToFileAsyncTaskListener; + } + + public interface SaveImageToFileAsyncTaskListener { + void saveSuccess(File imageFile); + void saveFailed(); + } + + @Override + protected Void doInBackground(Void... voids) { + try { + imageFile = new File(cacheDirPath, "shared.jpg"); + OutputStream outputStream = new FileOutputStream(imageFile); + + resource.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); + + outputStream.flush(); + outputStream.close(); + } catch (IOException e) { + saveSuccess = false; + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + if (saveSuccess) { + saveImageToFileAsyncTaskListener.saveSuccess(imageFile); + } else { + saveImageToFileAsyncTaskListener.saveFailed(); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java index cbef91ab..ee3cc947 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java @@ -31,6 +31,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.BaseActivity; import ml.docilealligator.infinityforreddit.Adapter.CommentsListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.CommentViewModel; @@ -108,12 +109,13 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni Resources resources = getResources(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - mCommentRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); - } + if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) { + 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"); + if (navBarResourceId > 0) { + mCommentRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java index e3ec8f91..2bd84344 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Fragment; import android.app.Activity; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -26,6 +27,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.BaseActivity; import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity; import ml.docilealligator.infinityforreddit.Adapter.FollowedUsersRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.FragmentCommunicator; @@ -33,6 +35,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserViewModel; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -57,6 +60,8 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo @Named("oauth") Retrofit mOauthRetrofit; @Inject + SharedPreferences mSharedPreferences; + @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; SubscribedUserViewModel mSubscribedUserViewModel; private Activity mActivity; @@ -79,12 +84,13 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo Resources resources = getResources(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); - } + 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)) { + int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (navBarResourceId > 0) { + mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } 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 66a70c74..2605ffa0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -11,6 +11,7 @@ import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; +import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -46,6 +47,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.BaseActivity; import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity; import ml.docilealligator.infinityforreddit.Activity.MainActivity; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; @@ -195,15 +197,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator { Resources resources = getResources(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 - && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT - || resources.getBoolean(R.bool.isTablet)) + if ((activity instanceof BaseActivity && ((BaseActivity) activity).isImmersiveInterface())) { + mPostRecyclerView.setPadding(0, 0, 0, ((BaseActivity) activity).getNavBarHeight()); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && 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) { - mPostRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); - } + int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (navBarResourceId > 0) { + mPostRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java index 91698cb6..9e16db19 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java @@ -31,6 +31,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.BaseActivity; import ml.docilealligator.infinityforreddit.Activity.SearchSubredditsResultActivity; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.Adapter.SubredditListingRecyclerViewAdapter; @@ -100,12 +101,13 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun Resources resources = getResources(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - mSubredditListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); - } + if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) { + 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"); + if (navBarResourceId > 0) { + mSubredditListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java index 076ac28c..a0d2af6c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Fragment; import android.app.Activity; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -28,6 +29,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.BaseActivity; import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity; import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity; import ml.docilealligator.infinityforreddit.Adapter.SubscribedSubredditsRecyclerViewAdapter; @@ -36,6 +38,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -63,6 +66,8 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra @Named("oauth") Retrofit mOauthRetrofit; @Inject + SharedPreferences mSharedPreferences; + @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; private Activity mActivity; private RequestManager mGlide; @@ -81,13 +86,14 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra ((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(); - if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); - } + int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (navBarResourceId > 0) { + mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java index 3baf7f8d..726e8c14 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java @@ -30,6 +30,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.BaseActivity; import ml.docilealligator.infinityforreddit.Adapter.UserListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; @@ -97,12 +98,13 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato Resources resources = getResources(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { - int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (navBarResourceId > 0) { - mUserListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); - } + if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) { + 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"); + if (navBarResourceId > 0) { + mUserListingRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); } } diff --git a/app/src/main/res/drawable/ic_add_menu_item_24dp.xml b/app/src/main/res/drawable/ic_add_menu_item_24dp.xml deleted file mode 100644 index b6814bc2..00000000 --- a/app/src/main/res/drawable/ic_add_menu_item_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ -<vector xmlns:android="http://schemas.android.com/apk/res/android" - android:width="24dp" - android:height="24dp" - android:viewportWidth="24" - android:viewportHeight="24"> - <path - android:fillColor="#FFFFFFFF" - android:pathData="M18,13h-5v5c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1v-5H6c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1h5V6c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v5h5c0.55,0 1,0.45 1,1s-0.45,1 -1,1z"/> -</vector> diff --git a/app/src/main/res/drawable-night/ic_add_menu_item_24dp.xml b/app/src/main/res/drawable/ic_add_toolbar_24dp.xml index ed95d188..133eda34 100644 --- a/app/src/main/res/drawable-night/ic_add_menu_item_24dp.xml +++ b/app/src/main/res/drawable/ic_add_toolbar_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24" android:viewportHeight="24"> <path - android:fillColor="#FF000000" + android:fillColor="?attr/toolbarPrimaryTextAndIconColor" android:pathData="M18,13h-5v5c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1v-5H6c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1h5V6c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v5h5c0.55,0 1,0.45 1,1s-0.45,1 -1,1z"/> </vector> diff --git a/app/src/main/res/drawable/ic_bookmark_border_black_24dp.xml b/app/src/main/res/drawable/ic_bookmark_border_toolbar_24dp.xml index 71382d27..3dfb41d7 100644 --- a/app/src/main/res/drawable/ic_bookmark_border_black_24dp.xml +++ b/app/src/main/res/drawable/ic_bookmark_border_toolbar_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24" android:viewportHeight="24"> <path - android:fillColor="#FFFFFFFF" + android:fillColor="?attr/toolbarPrimaryTextAndIconColor" android:pathData="M17,3L7,3c-1.1,0 -1.99,0.9 -1.99,2L5,21l7,-3 7,3L19,5c0,-1.1 -0.9,-2 -2,-2zM17,18l-5,-2.18L7,18L7,5h10v13z"/> </vector> diff --git a/app/src/main/res/drawable/ic_bookmark_black_24dp.xml b/app/src/main/res/drawable/ic_bookmark_toolbar_24dp.xml index a7ff3655..fededc94 100644 --- a/app/src/main/res/drawable/ic_bookmark_black_24dp.xml +++ b/app/src/main/res/drawable/ic_bookmark_toolbar_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24" android:viewportHeight="24"> <path - android:fillColor="#FFFFFFFF" + android:fillColor="?attr/toolbarPrimaryTextAndIconColor" android:pathData="M17,3H7c-1.1,0 -1.99,0.9 -1.99,2L5,21l7,-3 7,3V5c0,-1.1 -0.9,-2 -2,-2z"/> </vector> diff --git a/app/src/main/res/drawable/ic_check_circle_menu_item_24dp.xml b/app/src/main/res/drawable/ic_check_circle_toolbar_24dp.xml index 191a8e4c..e5b5df1d 100644 --- a/app/src/main/res/drawable/ic_check_circle_menu_item_24dp.xml +++ b/app/src/main/res/drawable/ic_check_circle_toolbar_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24" android:viewportHeight="24"> <path - android:fillColor="#FFFFFFFF" + android:fillColor="?attr/toolbarPrimaryTextAndIconColor" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM16.59,7.58L10,14.17l-2.59,-2.58L6,13l4,4 8,-8z"/> </vector> diff --git a/app/src/main/res/drawable/ic_comment_white_24dp.xml b/app/src/main/res/drawable/ic_comment_toolbar_24dp.xml index c7250d4b..d4920fc6 100644 --- a/app/src/main/res/drawable/ic_comment_white_24dp.xml +++ b/app/src/main/res/drawable/ic_comment_toolbar_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24" android:viewportHeight="24"> <path - android:fillColor="#FFFFFFFF" + android:fillColor="?attr/toolbarPrimaryTextAndIconColor" android:pathData="M21.99,4c0,-1.1 -0.89,-2 -1.99,-2L4,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h14l4,4 -0.01,-18zM20,4v13.17L18.83,16L4,16L4,4h16zM6,12h12v2L6,14zM6,9h12v2L6,11zM6,6h12v2L6,8z"/> </vector> diff --git a/app/src/main/res/drawable/ic_file_download_white_24dp.xml b/app/src/main/res/drawable/ic_file_download_toolbar_white_24dp.xml index b8e83614..8a9cfa3c 100644 --- a/app/src/main/res/drawable/ic_file_download_white_24dp.xml +++ b/app/src/main/res/drawable/ic_file_download_toolbar_white_24dp.xml @@ -1,5 +1,5 @@ -<vector android:height="24dp" android:tint="#FFFFFF" +<vector android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> - <path android:fillColor="#FF000000" android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/> + <path android:fillColor="#FFFFFFFF" android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/> </vector> diff --git a/app/src/main/res/drawable/ic_refresh_toolbar_24dp.xml b/app/src/main/res/drawable/ic_refresh_toolbar_24dp.xml new file mode 100644 index 00000000..0bddedb8 --- /dev/null +++ b/app/src/main/res/drawable/ic_refresh_toolbar_24dp.xml @@ -0,0 +1,5 @@ +<vector android:height="24dp" + android:viewportHeight="24.0" android:viewportWidth="24.0" + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="?attr/toolbarPrimaryTextAndIconColor" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/> +</vector> diff --git a/app/src/main/res/drawable/ic_refresh_white_24dp.xml b/app/src/main/res/drawable/ic_refresh_white_24dp.xml deleted file mode 100644 index cc2d1e04..00000000 --- a/app/src/main/res/drawable/ic_refresh_white_24dp.xml +++ /dev/null @@ -1,5 +0,0 @@ -<vector android:height="24dp" android:tint="#FFFFFF" - android:viewportHeight="24.0" android:viewportWidth="24.0" - android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> - <path android:fillColor="#FF000000" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/> -</vector> diff --git a/app/src/main/res/drawable/ic_search_toolbar_24dp.xml b/app/src/main/res/drawable/ic_search_toolbar_24dp.xml new file mode 100644 index 00000000..87dde9fb --- /dev/null +++ b/app/src/main/res/drawable/ic_search_toolbar_24dp.xml @@ -0,0 +1,5 @@ +<vector android:height="24dp" + android:viewportHeight="24.0" android:viewportWidth="24.0" + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="?attr/toolbarPrimaryTextAndIconColor" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/> +</vector> diff --git a/app/src/main/res/drawable/ic_search_white_24dp.xml b/app/src/main/res/drawable/ic_search_white_24dp.xml deleted file mode 100644 index be5ad99c..00000000 --- a/app/src/main/res/drawable/ic_search_white_24dp.xml +++ /dev/null @@ -1,5 +0,0 @@ -<vector android:height="24dp" android:tint="#FFFFFF" - android:viewportHeight="24.0" android:viewportWidth="24.0" - android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> - <path android:fillColor="#FF000000" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/> -</vector> diff --git a/app/src/main/res/drawable/ic_send_white_24dp.xml b/app/src/main/res/drawable/ic_send_toolbar_24dp.xml index 33efc5c9..fb547099 100644 --- a/app/src/main/res/drawable/ic_send_white_24dp.xml +++ b/app/src/main/res/drawable/ic_send_toolbar_24dp.xml @@ -1,5 +1,5 @@ -<vector android:height="24dp" android:tint="#FFFFFF" +<vector android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> - <path android:fillColor="#FF000000" android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/> + <path android:fillColor="?attr/toolbarPrimaryTextAndIconColor" android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/> </vector> diff --git a/app/src/main/res/drawable/ic_share_toolbar_white_24dp.xml b/app/src/main/res/drawable/ic_share_toolbar_white_24dp.xml new file mode 100644 index 00000000..cbe3d4aa --- /dev/null +++ b/app/src/main/res/drawable/ic_share_toolbar_white_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#FFFFFFFF" + android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92s2.92,-1.31 2.92,-2.92c0,-1.61 -1.31,-2.92 -2.92,-2.92zM18,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM6,13c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM18,20.02c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1z"/> +</vector> diff --git a/app/src/main/res/drawable/ic_outline_sort_24px.xml b/app/src/main/res/drawable/ic_sort_toolbar_24dp.xml index e795d2a2..8984e5aa 100644 --- a/app/src/main/res/drawable/ic_outline_sort_24px.xml +++ b/app/src/main/res/drawable/ic_sort_toolbar_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24" android:viewportHeight="24"> <path - android:fillColor="#FFFFFF" + android:fillColor="?attr/toolbarPrimaryTextAndIconColor" android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z"/> </vector> diff --git a/app/src/main/res/layout/activity_account_saved_thing.xml b/app/src/main/res/layout/activity_account_saved_thing.xml index 2c7e36ea..5da65dd9 100644 --- a/app/src/main/res/layout/activity_account_saved_thing.xml +++ b/app/src/main/res/layout/activity_account_saved_thing.xml @@ -40,12 +40,12 @@ android:background="?attr/toolbarAndTabBackgroundColor" app:layout_scrollFlags="scroll|enterAlways" app:tabGravity="fill" - app:tabIndicatorColor="@android:color/white" + app:tabIndicatorColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTabIndicator" app:tabIndicatorHeight="3dp" app:tabMode="fixed" app:tabRippleColor="?attr/colorControlHighlight" - app:tabSelectedTextColor="@android:color/white" - app:tabTextColor="@android:color/white" + app:tabSelectedTextColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTextColor" + app:tabTextColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTextColor" app:tabUnboundedRipple="false" /> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_comment.xml b/app/src/main/res/layout/activity_comment.xml index 45023334..c30536c1 100644 --- a/app/src/main/res/layout/activity_comment.xml +++ b/app/src/main/res/layout/activity_comment.xml @@ -9,17 +9,27 @@ tools:application=".CommentActivity"> <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_comment_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar_comment_activity" + <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:navigationIcon="?attr/homeAsUpIndicator" - app:popupTheme="@style/AppTheme.PopupOverlay" /> + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_comment_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_comment_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:navigationIcon="?attr/homeAsUpIndicator" + app:popupTheme="@style/AppTheme.PopupOverlay" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_create_multi_reddit.xml b/app/src/main/res/layout/activity_create_multi_reddit.xml index 62f492bc..1f056675 100644 --- a/app/src/main/res/layout/activity_create_multi_reddit.xml +++ b/app/src/main/res/layout/activity_create_multi_reddit.xml @@ -8,17 +8,27 @@ tools:context=".Activity.CreateMultiRedditActivity"> <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_create_multi_reddit_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar_create_multi_reddit_activity" + <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:popupTheme="@style/AppTheme.PopupOverlay" - app:navigationIcon="?attr/homeAsUpIndicator" /> + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_create_multi_reddit_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_create_multi_reddit_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_edit_comment.xml b/app/src/main/res/layout/activity_edit_comment.xml index 88547d89..5a2940f7 100644 --- a/app/src/main/res/layout/activity_edit_comment.xml +++ b/app/src/main/res/layout/activity_edit_comment.xml @@ -9,17 +9,27 @@ tools:context=".Activity.EditCommentActivity"> <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_edit_comment_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar_edit_comment_activity" + <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:popupTheme="@style/AppTheme.PopupOverlay" - app:navigationIcon="?attr/homeAsUpIndicator" /> + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_edit_comment_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_edit_comment_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_edit_post.xml b/app/src/main/res/layout/activity_edit_post.xml index 2c6d4757..b82c9e05 100644 --- a/app/src/main/res/layout/activity_edit_post.xml +++ b/app/src/main/res/layout/activity_edit_post.xml @@ -9,17 +9,27 @@ tools:context=".Activity.EditPostActivity"> <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_edit_post_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar_edit_post_activity" + <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:popupTheme="@style/AppTheme.PopupOverlay" - app:navigationIcon="?attr/homeAsUpIndicator" /> + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_edit_post_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_edit_post_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 2145e703..9fd051a5 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -8,17 +8,27 @@ tools:application="ml.docilealligator.infinityforreddit.Activity.LoginActivity"> <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_login_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar_login_activity" + <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:popupTheme="@style/AppTheme.PopupOverlay" - app:navigationIcon="?attr/homeAsUpIndicator" /> + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_login_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_login_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_post_image.xml b/app/src/main/res/layout/activity_post_image.xml index e4acbe5c..5a6bb303 100644 --- a/app/src/main/res/layout/activity_post_image.xml +++ b/app/src/main/res/layout/activity_post_image.xml @@ -9,17 +9,27 @@ tools:application=".PostImageActivity"> <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_post_image_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar_post_image_activity" + <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:popupTheme="@style/AppTheme.PopupOverlay" - app:navigationIcon="?attr/homeAsUpIndicator" /> + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_post_image_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_post_image_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_post_link.xml b/app/src/main/res/layout/activity_post_link.xml index 5a314141..07e94046 100644 --- a/app/src/main/res/layout/activity_post_link.xml +++ b/app/src/main/res/layout/activity_post_link.xml @@ -9,17 +9,27 @@ tools:application=".PostTextActivity"> <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_post_link_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar_post_link_activity" + <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:popupTheme="@style/AppTheme.PopupOverlay" - app:navigationIcon="?attr/homeAsUpIndicator" /> + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_post_link_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_post_link_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_post_text.xml b/app/src/main/res/layout/activity_post_text.xml index 619e2805..95069d20 100644 --- a/app/src/main/res/layout/activity_post_text.xml +++ b/app/src/main/res/layout/activity_post_text.xml @@ -9,17 +9,27 @@ tools:application=".PostTextActivity"> <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_post_text_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar_post_text_activity" + <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:popupTheme="@style/AppTheme.PopupOverlay" - app:navigationIcon="?attr/homeAsUpIndicator" /> + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_post_text_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_post_text_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_post_video.xml b/app/src/main/res/layout/activity_post_video.xml index b0a321f7..d8bd014d 100644 --- a/app/src/main/res/layout/activity_post_video.xml +++ b/app/src/main/res/layout/activity_post_video.xml @@ -9,17 +9,27 @@ tools:application=".PostImageActivity"> <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_post_video_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar_post_video_activity" + <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:popupTheme="@style/AppTheme.PopupOverlay" - app:navigationIcon="?attr/homeAsUpIndicator" /> + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_post_text_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_post_video_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_search_result.xml b/app/src/main/res/layout/activity_search_result.xml index 4ff4fbd9..ecf52a61 100644 --- a/app/src/main/res/layout/activity_search_result.xml +++ b/app/src/main/res/layout/activity_search_result.xml @@ -36,10 +36,10 @@ app:layout_scrollFlags="scroll|enterAlways" app:tabGravity="fill" app:tabMode="fixed" - app:tabIndicatorColor="@android:color/white" + app:tabIndicatorColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTabIndicator" app:tabIndicatorHeight="3dp" - app:tabSelectedTextColor="@android:color/white" - app:tabTextColor="@android:color/white" + app:tabSelectedTextColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTextColor" + app:tabTextColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTextColor" app:tabRippleColor="?attr/colorControlHighlight" app:tabUnboundedRipple="false"/> diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index be3f0f49..7e10c9ad 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -5,17 +5,27 @@ android:background="?attr/backgroundColor"> <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_settings_activity" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar_settings_activity" + <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:navigationIcon="?attr/homeAsUpIndicator" - app:popupTheme="@style/AppTheme.PopupOverlay" /> + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_post_text_activity"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_settings_activity" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:navigationIcon="?attr/homeAsUpIndicator" + app:popupTheme="@style/AppTheme.PopupOverlay" /> + + </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/activity_subscribed_thing_listing.xml b/app/src/main/res/layout/activity_subscribed_thing_listing.xml index 9cab7222..656d2b15 100644 --- a/app/src/main/res/layout/activity_subscribed_thing_listing.xml +++ b/app/src/main/res/layout/activity_subscribed_thing_listing.xml @@ -39,10 +39,10 @@ app:layout_scrollFlags="scroll|enterAlways" app:tabGravity="fill" app:tabMode="fixed" - app:tabIndicatorColor="@android:color/white" + app:tabIndicatorColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTabIndicator" app:tabIndicatorHeight="3dp" - app:tabSelectedTextColor="@android:color/white" - app:tabTextColor="@android:color/white" + app:tabSelectedTextColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTextColor" + app:tabTextColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTextColor" app:tabRippleColor="?attr/colorControlHighlight" app:tabUnboundedRipple="false" /> diff --git a/app/src/main/res/layout/activity_view_user_detail.xml b/app/src/main/res/layout/activity_view_user_detail.xml index 53e917de..d5ef9e43 100644 --- a/app/src/main/res/layout/activity_view_user_detail.xml +++ b/app/src/main/res/layout/activity_view_user_detail.xml @@ -28,7 +28,7 @@ app:titleEnabled="false" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" - app:toolbarId="@+id/toolbar"> + app:toolbarId="@+id/toolbar_view_user_detail_activity"> <RelativeLayout android:layout_width="match_parent" @@ -93,7 +93,7 @@ </RelativeLayout> <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar" + android:id="@+id/toolbar_view_user_detail_activity" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 88de7dcf..cc63287c 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -40,12 +40,12 @@ android:background="?attr/toolbarAndTabBackgroundColor" app:layout_scrollFlags="scroll|enterAlways" app:tabGravity="fill" - app:tabIndicatorColor="@android:color/white" + app:tabIndicatorColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTabIndicator" app:tabIndicatorHeight="3dp" app:tabMode="fixed" app:tabRippleColor="?attr/colorControlHighlight" - app:tabSelectedTextColor="@android:color/white" - app:tabTextColor="@android:color/white" + app:tabSelectedTextColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTextColor" + app:tabTextColor="?attr/tabLayoutWithCollapsedCollapsingToolbarTextColor" app:tabUnboundedRipple="false" /> </com.google.android.material.appbar.AppBarLayout> diff --git a/app/src/main/res/layout/item_post.xml b/app/src/main/res/layout/item_post.xml index 3acff256..335694e0 100644 --- a/app/src/main/res/layout/item_post.xml +++ b/app/src/main/res/layout/item_post.xml @@ -30,13 +30,13 @@ app:layout_constraintTop_toTopOf="parent"/> <TextView - android:id="@+id/name_text_view_item_post" + android:id="@+id/subreddit_name_text_view_item_post" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginStart="16dp" android:layout_marginEnd="8dp" - android:textColor="#E91E63" + android:textColor="?attr/subreddit" android:textSize="?attr/font_default" app:layout_constraintBottom_toTopOf="@id/user_text_view_item_post" app:layout_constraintStart_toEndOf="@id/icon_gif_image_view_item_post" @@ -56,7 +56,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toEndOf="@+id/icon_gif_image_view_item_post" app:layout_constraintEnd_toStartOf="@id/stickied_post_image_view_item_post" - app:layout_constraintTop_toBottomOf="@+id/name_text_view_item_post" + app:layout_constraintTop_toBottomOf="@+id/subreddit_name_text_view_item_post" app:layout_constraintHorizontal_bias="0" /> <ImageView @@ -67,7 +67,7 @@ android:tint="?attr/stickiedPost" android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintStart_toEndOf="@id/name_text_view_item_post" + app:layout_constraintStart_toEndOf="@id/subreddit_name_text_view_item_post" app:layout_constraintEnd_toStartOf="@+id/guideline2" app:layout_constraintTop_toTopOf="parent"/> diff --git a/app/src/main/res/menu/account_posts_activity.xml b/app/src/main/res/menu/account_posts_activity.xml index 72392f43..96174315 100644 --- a/app/src/main/res/menu/account_posts_activity.xml +++ b/app/src/main/res/menu/account_posts_activity.xml @@ -5,7 +5,6 @@ android:id="@+id/action_refresh_account_posts_activity" android:orderInCategory="1" android:title="@string/action_refresh" - android:icon="@drawable/ic_refresh_white_24dp" app:showAsAction="never" /> <item diff --git a/app/src/main/res/menu/account_saved_thing_activity.xml b/app/src/main/res/menu/account_saved_thing_activity.xml index 21628d7c..0ec48123 100644 --- a/app/src/main/res/menu/account_saved_thing_activity.xml +++ b/app/src/main/res/menu/account_saved_thing_activity.xml @@ -6,7 +6,6 @@ android:id="@+id/action_refresh_account_saved_thing_activity" android:orderInCategory="1" android:title="@string/action_refresh" - android:icon="@drawable/ic_refresh_white_24dp" app:showAsAction="never" /> <item diff --git a/app/src/main/res/menu/comment_activity.xml b/app/src/main/res/menu/comment_activity.xml index 640f6a43..bed5b858 100644 --- a/app/src/main/res/menu/comment_activity.xml +++ b/app/src/main/res/menu/comment_activity.xml @@ -5,6 +5,6 @@ android:id="@+id/action_send_comment_activity" android:orderInCategory="1" android:title="@string/action_send" - android:icon="@drawable/ic_send_white_24dp" + android:icon="@drawable/ic_send_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/create_multi_reddit_activity.xml b/app/src/main/res/menu/create_multi_reddit_activity.xml index c2ae2455..44b154d9 100644 --- a/app/src/main/res/menu/create_multi_reddit_activity.xml +++ b/app/src/main/res/menu/create_multi_reddit_activity.xml @@ -5,6 +5,6 @@ android:id="@+id/action_create_create_multi_reddit_activity" android:orderInCategory="1" android:title="@string/action_send" - android:icon="@drawable/ic_add_menu_item_24dp" + android:icon="@drawable/ic_add_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/edit_comment_activity.xml b/app/src/main/res/menu/edit_comment_activity.xml index e52e484b..97ef8af8 100644 --- a/app/src/main/res/menu/edit_comment_activity.xml +++ b/app/src/main/res/menu/edit_comment_activity.xml @@ -5,6 +5,6 @@ android:id="@+id/action_send_edit_comment_activity" android:orderInCategory="1" android:title="@string/action_send" - android:icon="@drawable/ic_send_white_24dp" + android:icon="@drawable/ic_send_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/edit_post_activity.xml b/app/src/main/res/menu/edit_post_activity.xml index 270d7664..86ed3845 100644 --- a/app/src/main/res/menu/edit_post_activity.xml +++ b/app/src/main/res/menu/edit_post_activity.xml @@ -5,6 +5,6 @@ android:id="@+id/action_send_edit_post_activity" android:orderInCategory="1" android:title="@string/action_send" - android:icon="@drawable/ic_send_white_24dp" + android:icon="@drawable/ic_send_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/filtered_posts_activity.xml b/app/src/main/res/menu/filtered_posts_activity.xml index 3cebab6c..6e826b5a 100644 --- a/app/src/main/res/menu/filtered_posts_activity.xml +++ b/app/src/main/res/menu/filtered_posts_activity.xml @@ -5,14 +5,14 @@ android:id="@+id/action_sort_filtered_thing_activity" android:orderInCategory="1" android:title="@string/action_sort" - android:icon="@drawable/ic_outline_sort_24px" + android:icon="@drawable/ic_sort_toolbar_24dp" app:showAsAction="ifRoom" /> <item android:id="@+id/action_refresh_filtered_thing_activity" android:orderInCategory="2" android:title="@string/action_refresh" - android:icon="@drawable/ic_search_white_24dp" + android:icon="@drawable/ic_search_toolbar_24dp" app:showAsAction="never" /> <item diff --git a/app/src/main/res/menu/main_activity.xml b/app/src/main/res/menu/main_activity.xml index b500d3a7..2e3062b1 100644 --- a/app/src/main/res/menu/main_activity.xml +++ b/app/src/main/res/menu/main_activity.xml @@ -8,14 +8,14 @@ android:id="@+id/action_search_main_activity" android:orderInCategory="1" android:title="@string/action_search" - android:icon="@drawable/ic_search_white_24dp" + android:icon="@drawable/ic_search_toolbar_24dp" app:showAsAction="ifRoom" /> <item android:id="@+id/action_sort_main_activity" android:orderInCategory="2" android:title="@string/action_sort" - android:icon="@drawable/ic_outline_sort_24px" + android:icon="@drawable/ic_sort_toolbar_24dp" app:showAsAction="ifRoom" /> <item diff --git a/app/src/main/res/menu/menu_search.xml b/app/src/main/res/menu/menu_search.xml index 7b3c998a..0e33b2dd 100644 --- a/app/src/main/res/menu/menu_search.xml +++ b/app/src/main/res/menu/menu_search.xml @@ -6,6 +6,6 @@ android:id="@+id/action_search_search_activity" android:orderInCategory="1" android:title="@string/action_search" - android:icon="@drawable/ic_search_white_24dp" + android:icon="@drawable/ic_search_toolbar_24dp" app:showAsAction="ifRoom" /> </menu> diff --git a/app/src/main/res/menu/post_image_activity.xml b/app/src/main/res/menu/post_image_activity.xml index 1525a802..19aed6e0 100644 --- a/app/src/main/res/menu/post_image_activity.xml +++ b/app/src/main/res/menu/post_image_activity.xml @@ -5,6 +5,6 @@ android:id="@+id/action_send_post_image_activity" android:orderInCategory="1" android:title="@string/action_send" - android:icon="@drawable/ic_send_white_24dp" + android:icon="@drawable/ic_send_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/post_link_activity.xml b/app/src/main/res/menu/post_link_activity.xml index 8b9f2e69..f9425806 100644 --- a/app/src/main/res/menu/post_link_activity.xml +++ b/app/src/main/res/menu/post_link_activity.xml @@ -5,6 +5,6 @@ android:id="@+id/action_send_post_link_activity" android:orderInCategory="1" android:title="@string/action_send" - android:icon="@drawable/ic_send_white_24dp" + android:icon="@drawable/ic_send_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/post_text_activity.xml b/app/src/main/res/menu/post_text_activity.xml index 94650918..23d9b6d6 100644 --- a/app/src/main/res/menu/post_text_activity.xml +++ b/app/src/main/res/menu/post_text_activity.xml @@ -5,6 +5,6 @@ android:id="@+id/action_send_post_text_activity" android:orderInCategory="1" android:title="@string/action_send" - android:icon="@drawable/ic_send_white_24dp" + android:icon="@drawable/ic_send_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/post_video_activity.xml b/app/src/main/res/menu/post_video_activity.xml index c1573cb8..3897c461 100644 --- a/app/src/main/res/menu/post_video_activity.xml +++ b/app/src/main/res/menu/post_video_activity.xml @@ -5,6 +5,6 @@ android:id="@+id/action_send_post_video_activity" android:orderInCategory="1" android:title="@string/action_send" - android:icon="@drawable/ic_send_white_24dp" + android:icon="@drawable/ic_send_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/search_activity.xml b/app/src/main/res/menu/search_activity.xml index 74cc4fb7..94119685 100644 --- a/app/src/main/res/menu/search_activity.xml +++ b/app/src/main/res/menu/search_activity.xml @@ -7,6 +7,6 @@ android:id="@+id/action_search_search_activity" android:orderInCategory="1" android:title="@string/action_search" - android:icon="@drawable/ic_search_white_24dp" + android:icon="@drawable/ic_search_toolbar_24dp" app:showAsAction="ifRoom" /> </menu> diff --git a/app/src/main/res/menu/search_result_activity.xml b/app/src/main/res/menu/search_result_activity.xml index b6c9dd3f..d503471f 100644 --- a/app/src/main/res/menu/search_result_activity.xml +++ b/app/src/main/res/menu/search_result_activity.xml @@ -5,14 +5,14 @@ android:id="@+id/action_sort_search_result_activity" android:orderInCategory="1" android:title="@string/action_sort" - android:icon="@drawable/ic_outline_sort_24px" + android:icon="@drawable/ic_sort_toolbar_24dp" app:showAsAction="ifRoom" /> <item android:id="@+id/action_search_search_result_activity" android:orderInCategory="2" android:title="@string/action_search" - android:icon="@drawable/ic_search_white_24dp" + android:icon="@drawable/ic_search_toolbar_24dp" app:showAsAction="ifRoom" /> <item diff --git a/app/src/main/res/menu/subreddit_multiselection_activity.xml b/app/src/main/res/menu/subreddit_multiselection_activity.xml index 0a9d4ff3..ea842fd3 100644 --- a/app/src/main/res/menu/subreddit_multiselection_activity.xml +++ b/app/src/main/res/menu/subreddit_multiselection_activity.xml @@ -5,13 +5,13 @@ android:id="@+id/action_save_subreddit_multiselection_activity" android:orderInCategory="1" android:title="@string/action_save" - android:icon="@drawable/ic_check_circle_menu_item_24dp" + android:icon="@drawable/ic_check_circle_toolbar_24dp" app:showAsAction="ifRoom" /> <item android:id="@+id/action_search_subreddit_multiselection_activity" android:orderInCategory="2" android:title="@string/action_search" - android:icon="@drawable/ic_search_white_24dp" + android:icon="@drawable/ic_search_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/subreddit_selection_activity.xml b/app/src/main/res/menu/subreddit_selection_activity.xml index f3a40a77..a55e1b97 100644 --- a/app/src/main/res/menu/subreddit_selection_activity.xml +++ b/app/src/main/res/menu/subreddit_selection_activity.xml @@ -5,6 +5,6 @@ android:id="@+id/action_search_subreddit_selection_activity" android:orderInCategory="1" android:title="@string/action_search" - android:icon="@drawable/ic_search_white_24dp" + android:icon="@drawable/ic_search_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/view_gif_activity.xml b/app/src/main/res/menu/view_gif_activity.xml index 493c9fdb..0dc5aba5 100644 --- a/app/src/main/res/menu/view_gif_activity.xml +++ b/app/src/main/res/menu/view_gif_activity.xml @@ -2,9 +2,16 @@ <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item - android:id="@+id/action_download_view_gif" + android:id="@+id/action_download_view_gif_activity" android:orderInCategory="1" android:title="@string/action_download" - android:icon="@drawable/ic_file_download_white_24dp" - app:showAsAction="always" /> + android:icon="@drawable/ic_file_download_toolbar_white_24dp" + app:showAsAction="ifRoom" /> + + <item + android:id="@+id/action_share_view_gif_activity" + android:orderInCategory="2" + android:title="@string/action_share" + android:icon="@drawable/ic_share_toolbar_white_24dp" + app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/view_image.xml b/app/src/main/res/menu/view_image.xml deleted file mode 100644 index 238334e1..00000000 --- a/app/src/main/res/menu/view_image.xml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<menu xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto"> - <item - android:id="@+id/action_download_view_image" - android:orderInCategory="1" - android:title="@string/action_download" - android:icon="@drawable/ic_file_download_white_24dp" - app:showAsAction="always" /> -</menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/view_image_activity.xml b/app/src/main/res/menu/view_image_activity.xml new file mode 100644 index 00000000..1f86092b --- /dev/null +++ b/app/src/main/res/menu/view_image_activity.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + <item + android:id="@+id/action_download_view_image_activity" + android:orderInCategory="1" + android:title="@string/action_download" + android:icon="@drawable/ic_file_download_toolbar_white_24dp" + app:showAsAction="ifRoom" /> + + <item + android:id="@+id/action_share_view_image_activity" + android:orderInCategory="2" + android:title="@string/action_share" + android:icon="@drawable/ic_share_toolbar_white_24dp" + app:showAsAction="ifRoom" /> +</menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/view_multi_reddit_detail_activity.xml b/app/src/main/res/menu/view_multi_reddit_detail_activity.xml index c8005d25..abaf8a6a 100644 --- a/app/src/main/res/menu/view_multi_reddit_detail_activity.xml +++ b/app/src/main/res/menu/view_multi_reddit_detail_activity.xml @@ -7,20 +7,19 @@ android:id="@+id/action_sort_view_multi_reddit_detail_activity" android:orderInCategory="1" android:title="@string/action_sort" - android:icon="@drawable/ic_outline_sort_24px" + android:icon="@drawable/ic_sort_toolbar_24dp" app:showAsAction="ifRoom" /> <item android:id="@+id/action_search_view_multi_reddit_detail_activity" android:orderInCategory="2" android:title="@string/action_search" - android:icon="@drawable/ic_search_white_24dp" + android:icon="@drawable/ic_search_toolbar_24dp" app:showAsAction="ifRoom" /> <item android:id="@+id/action_refresh_view_multi_reddit_detail_activity" android:orderInCategory="3" android:title="@string/action_refresh" - android:icon="@drawable/ic_refresh_white_24dp" app:showAsAction="never" /> <item diff --git a/app/src/main/res/menu/view_post_detail_activity.xml b/app/src/main/res/menu/view_post_detail_activity.xml index 56f5d12c..a9871051 100644 --- a/app/src/main/res/menu/view_post_detail_activity.xml +++ b/app/src/main/res/menu/view_post_detail_activity.xml @@ -5,7 +5,7 @@ android:id="@+id/action_comment_view_post_detail_activity" android:orderInCategory="1" android:title="@string/action_add_comment" - android:icon="@drawable/ic_comment_white_24dp" + android:icon="@drawable/ic_comment_toolbar_24dp" app:showAsAction="ifRoom" android:visible="false" /> diff --git a/app/src/main/res/menu/view_sidebar_activity.xml b/app/src/main/res/menu/view_sidebar_activity.xml index 3bb65dee..fa5d9123 100644 --- a/app/src/main/res/menu/view_sidebar_activity.xml +++ b/app/src/main/res/menu/view_sidebar_activity.xml @@ -5,6 +5,6 @@ android:id="@+id/action_refresh_view_sidebar_activity" android:orderInCategory="1" android:title="@string/action_refresh" - android:icon="@drawable/ic_refresh_white_24dp" + android:icon="@drawable/ic_refresh_toolbar_24dp" app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/menu/view_subreddit_detail_activity.xml b/app/src/main/res/menu/view_subreddit_detail_activity.xml index d019e052..eeef2439 100644 --- a/app/src/main/res/menu/view_subreddit_detail_activity.xml +++ b/app/src/main/res/menu/view_subreddit_detail_activity.xml @@ -7,20 +7,19 @@ android:id="@+id/action_sort_view_subreddit_detail_activity" android:orderInCategory="1" android:title="@string/action_sort" - android:icon="@drawable/ic_outline_sort_24px" + android:icon="@drawable/ic_sort_toolbar_24dp" app:showAsAction="ifRoom" /> <item android:id="@+id/action_search_view_subreddit_detail_activity" android:orderInCategory="2" android:title="@string/action_search" - android:icon="@drawable/ic_search_white_24dp" + android:icon="@drawable/ic_search_toolbar_24dp" app:showAsAction="ifRoom" /> <item android:id="@+id/action_refresh_view_subreddit_detail_activity" android:orderInCategory="3" android:title="@string/action_refresh" - android:icon="@drawable/ic_refresh_white_24dp" app:showAsAction="never" /> <item diff --git a/app/src/main/res/menu/view_user_detail_activity.xml b/app/src/main/res/menu/view_user_detail_activity.xml index 51d2f61e..fe991f16 100644 --- a/app/src/main/res/menu/view_user_detail_activity.xml +++ b/app/src/main/res/menu/view_user_detail_activity.xml @@ -6,19 +6,18 @@ android:id="@+id/action_sort_view_user_detail_activity" android:orderInCategory="1" android:title="@string/action_search" - android:icon="@drawable/ic_outline_sort_24px" + android:icon="@drawable/ic_sort_toolbar_24dp" app:showAsAction="ifRoom" /> <item android:id="@+id/action_search_view_user_detail_activity" android:orderInCategory="2" android:title="@string/action_search" - android:icon="@drawable/ic_search_white_24dp" + android:icon="@drawable/ic_search_toolbar_24dp" app:showAsAction="ifRoom" /> <item android:id="@+id/action_refresh_view_user_detail_activity" android:orderInCategory="3" android:title="@string/action_refresh" - android:icon="@drawable/ic_refresh_white_24dp" app:showAsAction="never" /> <item diff --git a/app/src/main/res/menu/view_video.xml b/app/src/main/res/menu/view_video.xml index ef64a9dd..fa54098f 100644 --- a/app/src/main/res/menu/view_video.xml +++ b/app/src/main/res/menu/view_video.xml @@ -2,9 +2,9 @@ <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item - android:id="@+id/action_download_view_video" + android:id="@+id/action_download_view_video_activity" android:orderInCategory="1" android:title="@string/action_download" - android:icon="@drawable/ic_file_download_white_24dp" - app:showAsAction="always" /> + android:icon="@drawable/ic_file_download_toolbar_white_24dp" + app:showAsAction="ifRoom" /> </menu>
\ No newline at end of file diff --git a/app/src/main/res/values/attr.xml b/app/src/main/res/values/attr.xml index 03dfb30f..5d6dc3c1 100644 --- a/app/src/main/res/values/attr.xml +++ b/app/src/main/res/values/attr.xml @@ -37,6 +37,7 @@ <attr name="backgroundColor" format="color"/> <attr name="roundedBottomSheetPrimaryBackground" format="color"/> <attr name="cardViewBackgroundColor" format="color"/> + <attr name="toolbarPrimaryTextAndIconColor" format="color" /> <attr name="toolbarAndTabBackgroundColor" format="color"/> <attr name="circularProgressBarBackground" format="color"/> <attr name="tabLayoutWithExpandedCollapsingToolbarTabBackground" format="color"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ccb251e4..41b3dde0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,6 +48,7 @@ <string name="action_view_side_bar">View Sidebar</string> <string name="action_save">Save</string> <string name="action_delete_multi_reddit">Delete Multireddit</string> + <string name="action_share">Share</string> <string name="parse_json_response_error">Error occurred when parsing the JSON response</string> <string name="retrieve_token_error">Error Retrieving the token</string> @@ -451,4 +452,10 @@ <string name="enable_nsfw">Enable NSFW</string> <string name="disable_nsfw">Disable NSFW</string> + + <string name="cannot_save_image">Cannot save the image</string> + <string name="cannot_save_gif">Cannot save the gif</string> + <string name="cannot_get_storage">Cannot access the app storage</string> + <string name="save_image_before_sharing">Saving the image. Please wait.</string> + <string name="save_gif_before_sharing">Saving the gif. Please wait.</string> </resources> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index dc7024a9..2ae6c7cf 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -38,10 +38,14 @@ <item name="android:windowTranslucentNavigation">true</item> </style> - <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> + <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.DayNight.ActionBar"> + <item name="android:textColorPrimary">?attr/toolbarPrimaryTextAndIconColor</item> + </style> <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.DayNight" /> + <style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> + <style name="CustomTabLayout" parent="Widget.Design.TabLayout"> <item name="tabIndicatorColor">@android:color/white</item> <item name="tabIndicatorHeight">3dp</item> @@ -228,6 +232,7 @@ <item name="backgroundColor">@color/backgroundColor</item> <item name="roundedBottomSheetPrimaryBackground">@color/roundedBottomSheetPrimaryBackground</item> <item name="cardViewBackgroundColor">#FFFFFF</item> + <item name="toolbarPrimaryTextAndIconColor">#3C4043</item> <item name="toolbarAndTabBackgroundColor">@color/colorPrimary</item> <item name="circularProgressBarBackground">#FFFFFF</item> <item name="tabLayoutWithExpandedCollapsingToolbarTabBackground">#FFFFFF</item> @@ -279,6 +284,7 @@ <item name="backgroundColor">@color/backgroundColor</item> <item name="roundedBottomSheetPrimaryBackground">@color/roundedBottomSheetPrimaryBackground</item> <item name="cardViewBackgroundColor">#242424</item> + <item name="toolbarPrimaryTextAndIconColor">#FFFFFF</item> <item name="toolbarAndTabBackgroundColor">#282828</item> <item name="circularProgressBarBackground">@color/colorPrimary</item> <item name="tabLayoutWithExpandedCollapsingToolbarTabBackground">@color/backgroundColor</item> @@ -330,6 +336,7 @@ <item name="backgroundColor">#000000</item> <item name="roundedBottomSheetPrimaryBackground">#000000</item> <item name="cardViewBackgroundColor">#000000</item> + <item name="toolbarPrimaryTextAndIconColor">#FFFFFF</item> <item name="toolbarAndTabBackgroundColor">#000000</item> <item name="circularProgressBarBackground">#000000</item> <item name="tabLayoutWithExpandedCollapsingToolbarTabBackground">@color/backgroundColor</item> @@ -372,23 +379,24 @@ </style> <style name="Theme.Purple"> - <item name="colorPrimary">#9C27B0</item> - <item name="colorPrimaryDark">#7B1FA2</item> - <item name="colorAccent">#03A9F4</item> - <item name="colorPrimaryLightTheme">#9C27B0</item> + <item name="colorPrimary">#00C3E9</item> + <item name="colorPrimaryDark">#009EBA</item> + <item name="colorAccent">#EE2502</item> + <item name="colorPrimaryLightTheme">?attr/colorPrimary</item> <item name="primaryTextColor">#000000</item> <item name="secondaryTextColor">#8A000000</item> <item name="backgroundColor">@color/backgroundColor</item> <item name="roundedBottomSheetPrimaryBackground">@color/roundedBottomSheetPrimaryBackground</item> <item name="cardViewBackgroundColor">#FFFFFF</item> - <item name="toolbarAndTabBackgroundColor">#9C27B0</item> + <item name="toolbarPrimaryTextAndIconColor">#FF3C4043</item> + <item name="toolbarAndTabBackgroundColor">?attr/colorPrimary</item> <item name="circularProgressBarBackground">#FFFFFF</item> <item name="tabLayoutWithExpandedCollapsingToolbarTabBackground">#FFFFFF</item> - <item name="tabLayoutWithExpandedCollapsingToolbarTextColor">#9C27B0</item> - <item name="tabLayoutWithExpandedCollapsingToolbarTabIndicator">#9C27B0</item> - <item name="tabLayoutWithCollapsedCollapsingToolbarTabBackground">#9C27B0</item> - <item name="tabLayoutWithCollapsedCollapsingToolbarTextColor">#FFFFFF</item> - <item name="tabLayoutWithCollapsedCollapsingToolbarTabIndicator">#FFFFFF</item> + <item name="tabLayoutWithExpandedCollapsingToolbarTextColor">?attr/colorPrimary</item> + <item name="tabLayoutWithExpandedCollapsingToolbarTabIndicator">?attr/colorPrimary</item> + <item name="tabLayoutWithCollapsedCollapsingToolbarTabBackground">?attr/colorPrimary</item> + <item name="tabLayoutWithCollapsedCollapsingToolbarTextColor">?attr/toolbarPrimaryTextAndIconColor</item> + <item name="tabLayoutWithCollapsedCollapsingToolbarTabIndicator">?attr/toolbarPrimaryTextAndIconColor</item> <item name="navBarColor">@color/backgroundColor</item> <item name="upvoted">#E91E63</item> <item name="downvoted">#007DDE</item> @@ -407,7 +415,7 @@ <item name="authorFlairTextColor">#EE02C4</item> <item name="submitter">#EE8A02</item> <item name="moderator">#00BA81</item> - <item name="notificationIconColor">#9C27B0</item> + <item name="notificationIconColor">?attr/colorPrimary</item> <item name="singleCommentThreadBackgroundColor">#B3E5F9</item> <item name="unreadMessageBackgroundColor">#B3E5F9</item> <item name="dividerColor">#E0E0E0</item> diff --git a/app/src/main/res/xml/file_paths.xml b/app/src/main/res/xml/file_paths.xml index 79f4cf3f..25648473 100644 --- a/app/src/main/res/xml/file_paths.xml +++ b/app/src/main/res/xml/file_paths.xml @@ -1,5 +1,4 @@ <?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> - <external-path name="image_temp" - path="Android/data/ml.docilealligator.infinityforreddit/files/Pictures" /> + <external-path name="external_app_storage" path="." /> </paths>
\ No newline at end of file |