From 1ce96509356c98f04377ac6aa94f54c8d51aa0d0 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 12 Aug 2019 10:08:49 +0800 Subject: Transparent nav bar in FilteredPostsActivity. --- .../infinityforreddit/FilteredPostsActivity.java | 51 ++++++++++++++++++++++ .../SubscribedSubredditsListingFragment.java | 1 + 2 files changed, 52 insertions(+) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java index 18d57300..0ee3a216 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java @@ -1,14 +1,23 @@ package ml.docilealligator.infinityforreddit; +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 androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; +import com.google.android.material.appbar.AppBarLayout; + import javax.inject.Inject; import butterknife.BindView; @@ -27,6 +36,7 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType private static final String ACCESS_TOKEN_STATE = "ATS"; private static final String FRAGMENT_OUT_STATE = "FOS"; + @BindView(R.id.appbar_layout_filtered_posts_activity) AppBarLayout appBarLayout; @BindView(R.id.toolbar_filtered_posts_activity) Toolbar toolbar; private boolean mNullAccessToken = false; @@ -53,6 +63,47 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType ((Infinity) getApplication()).getAppComponent().inject(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))) { + 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); + } + appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + @Override + void onStateChanged(AppBarLayout appBarLayout, State state) { + if (state == State.COLLAPSED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } else if (state == State.EXPANDED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } + } + }); + + int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (statusBarResourceId > 0) { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); + params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId); + toolbar.setLayoutParams(params); + } + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java index 15da8748..d43eb602 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java @@ -104,6 +104,7 @@ public class SubscribedSubredditsListingFragment extends Fragment { } else { mLinearLayout.setVisibility(View.GONE); mRecyclerView.setVisibility(View.VISIBLE); + mGlide.clear(mImageView); } adapter.addUser(accountName, getArguments().getString(EXTRA_ACCOUNT_PROFILE_IMAGE_URL)); -- cgit v1.2.3