aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-11 04:32:41 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-11 04:32:41 +0000
commitc2f2fc1b39b5ccfe147062cb3be8f2236e705f48 (patch)
treebdec59d9fc981a134b3567841e497b1afdfab165
parent413a18f6d39bf274369d7a1ee3279e20d3a608a7 (diff)
downloadinfinity-for-reddit-c2f2fc1b39b5ccfe147062cb3be8f2236e705f48.tar
infinity-for-reddit-c2f2fc1b39b5ccfe147062cb3be8f2236e705f48.tar.gz
infinity-for-reddit-c2f2fc1b39b5ccfe147062cb3be8f2236e705f48.tar.bz2
infinity-for-reddit-c2f2fc1b39b5ccfe147062cb3be8f2236e705f48.tar.lz
infinity-for-reddit-c2f2fc1b39b5ccfe147062cb3be8f2236e705f48.tar.xz
infinity-for-reddit-c2f2fc1b39b5ccfe147062cb3be8f2236e705f48.tar.zst
infinity-for-reddit-c2f2fc1b39b5ccfe147062cb3be8f2236e705f48.zip
Transparent navigation bar and status bar in ViewPostDetailActivity (All these changes including in other activities are only available for Android version >= 8.1).
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java41
-rw-r--r--app/src/main/res/layout/activity_view_post_detail.xml21
2 files changed, 57 insertions, 5 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 77be5762..ae0ee53b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -2,11 +2,17 @@ package ml.docilealligator.infinityforreddit;
import android.content.Context;
import android.content.Intent;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.os.Build;
import android.os.Bundle;
import android.util.Log;
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;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
@@ -24,6 +30,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.evernote.android.state.State;
+import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.snackbar.Snackbar;
import com.livefront.bridge.Bridge;
@@ -84,6 +91,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
private LoadSubredditIconAsyncTask mLoadSubredditIconAsyncTask;
@BindView(R.id.coordinator_layout_view_post_detail) CoordinatorLayout mCoordinatorLayout;
+ @BindView(R.id.appbar_layout_view_post_detail_activity) AppBarLayout appBarLayout;
@BindView(R.id.toolbar_view_post_detail_activity) Toolbar toolbar;
@BindView(R.id.progress_bar_view_post_detail_activity) ProgressBar mProgressBar;
@BindView(R.id.recycler_view_view_post_detail) RecyclerView mRecyclerView;
@@ -113,6 +121,39 @@ public class ViewPostDetailActivity extends AppCompatActivity {
((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);
+
+ View decorView = window.getDecorView();
+ appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
+ @Override
+ void onStateChanged(AppBarLayout appBarLayout, State state) {
+ if (state == State.COLLAPSED) {
+ decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
+ } else if (state == State.EXPANDED) {
+ 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 navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
+ if (navBarResourceId > 0) {
+ mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
+ }
+ }
+
toolbar.setTitle("");
setSupportActionBar(toolbar);
diff --git a/app/src/main/res/layout/activity_view_post_detail.xml b/app/src/main/res/layout/activity_view_post_detail.xml
index 3fef4769..3a010dc3 100644
--- a/app/src/main/res/layout/activity_view_post_detail.xml
+++ b/app/src/main/res/layout/activity_view_post_detail.xml
@@ -8,16 +8,26 @@
tools:application=".ViewPostDetailActivity">
<com.google.android.material.appbar.AppBarLayout
+ android:id="@+id/appbar_layout_view_post_detail_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
- <androidx.appcompat.widget.Toolbar
- android:id="@+id/toolbar_view_post_detail_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_view_post_detail_activity">
+
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar_view_post_detail_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>
@@ -32,6 +42,7 @@
android:id="@+id/recycler_view_view_post_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<LinearLayout