Skip to content

Commit

Permalink
Fix toolbar insets
Browse files Browse the repository at this point in the history
  • Loading branch information
premnirmal committed Mar 25, 2022
1 parent 5872d44 commit 4e50c8b
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
android:label="@string/app_name"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan"
android:theme="@style/ParanormalActivityTheme">
android:theme="@style/MainActivityTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.github.premnirmal.ticker.widget.WidgetsFragment
import com.github.premnirmal.tickerwidget.BuildConfig
import com.github.premnirmal.tickerwidget.R
import com.google.android.material.bottomnavigation.BottomNavigationView
import kotlinx.android.synthetic.main.activity_paranormal.bottom_navigation
import kotlinx.android.synthetic.main.activity_main.bottom_navigation
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -50,12 +50,12 @@ class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemSelect

private var currentChild: ChildFragment? = null
private var rateDialogShown = false
override val simpleName: String = "ParanormalActivity"
override val simpleName: String = "MainActivity"

override fun onCreate(savedInstanceState: Bundle?) {
Injector.appComponent.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_paranormal)
setContentView(R.layout.activity_main)
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility or (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
savedInstanceState?.let { rateDialogShown = it.getBoolean(DIALOG_SHOWN, false) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.github.premnirmal.ticker.news

import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.premnirmal.ticker.CustomTabs
Expand All @@ -18,6 +22,7 @@ import com.github.premnirmal.tickerwidget.R.dimen
import kotlinx.android.synthetic.main.fragment_news_feed.fake_status_bar
import kotlinx.android.synthetic.main.fragment_news_feed.recycler_view
import kotlinx.android.synthetic.main.fragment_news_feed.swipe_container
import kotlinx.android.synthetic.main.fragment_news_feed.toolbar
import kotlinx.android.synthetic.main.fragment_news_feed.view_flipper

class NewsFeedFragment : BaseFragment(), ChildFragment, NewsFeedAdapter.NewsClickListener {
Expand Down Expand Up @@ -47,9 +52,17 @@ class NewsFeedFragment : BaseFragment(), ChildFragment, NewsFeedAdapter.NewsClic
savedInstanceState: Bundle?
) {
super.onViewCreated(view, savedInstanceState)
fake_status_bar.visibility = View.VISIBLE
fake_status_bar.layoutParams.height = requireContext().getStatusBarHeight()
fake_status_bar.requestLayout()
ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
this.topMargin = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top
}
insets
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
fake_status_bar.updateLayoutParams<ViewGroup.LayoutParams> {
height = requireContext().getStatusBarHeight()
}
}
adapter = NewsFeedAdapter(this)
recycler_view.layoutManager = LinearLayoutManager(activity)
recycler_view.addItemDecoration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.premnirmal.ticker.portfolio.search
import android.appwidget.AppWidgetManager
import android.content.Intent
import android.graphics.PorterDuff
import android.os.Build
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
Expand All @@ -11,6 +12,9 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.DividerItemDecoration
Expand Down Expand Up @@ -85,11 +89,19 @@ class SearchFragment : BaseFragment(), ChildFragment, SuggestionClickListener, T
toolbar.navigationIcon?.setTint(ContextCompat.getColor(requireContext(), R.color.icon_tint))
toolbar.navigationIcon?.setTintMode(PorterDuff.Mode.SRC_IN)
toolbar.setNavigationOnClickListener { requireActivity().finish() }
fake_status_bar.visibility = View.GONE
} else {
fake_status_bar.visibility = View.VISIBLE
fake_status_bar.layoutParams.height = requireContext().getStatusBarHeight()
fake_status_bar.requestLayout()
// Inset toolbar from window top inset
ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
this.topMargin = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top
}
insets
}
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
fake_status_bar.updateLayoutParams<ViewGroup.LayoutParams> {
height = requireContext().getStatusBarHeight()
}
}
adapter = SuggestionsAdapter(this)
recycler_view.layoutManager = LinearLayoutManager(activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import android.view.ViewGroup
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.TimePicker
Expand All @@ -25,6 +25,9 @@ import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.lifecycle.lifecycleScope
import androidx.preference.CheckBoxPreference
import androidx.preference.ListPreference
Expand All @@ -45,6 +48,7 @@ import com.github.premnirmal.ticker.showDialog
import com.github.premnirmal.ticker.widget.WidgetDataProvider
import com.github.premnirmal.tickerwidget.BuildConfig
import com.github.premnirmal.tickerwidget.R
import kotlinx.android.synthetic.main.fragment_settings.fake_status_bar
import kotlinx.android.synthetic.main.fragment_settings.toolbar
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -100,7 +104,17 @@ class SettingsFragment : PreferenceFragmentCompat(), ChildFragment,
savedInstanceState: Bundle?
) {
super.onViewCreated(view, savedInstanceState)
(toolbar.layoutParams as MarginLayoutParams).topMargin = requireContext().getStatusBarHeight()
ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
this.topMargin = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top
}
insets
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
fake_status_bar.updateLayoutParams<ViewGroup.LayoutParams> {
height = requireContext().getStatusBarHeight()
}
}
if (resources.getBoolean(R.bool.isTablet)) {
listView.layoutParams.width = resources.getDimensionPixelSize(R.dimen.tablet_width)
(listView.layoutParams as FrameLayout.LayoutParams).gravity = Gravity.CENTER_HORIZONTAL or Gravity.TOP
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package com.github.premnirmal.ticker.widget

import android.appwidget.AppWidgetManager
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.BaseAdapter
import android.widget.TextView
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import com.github.premnirmal.ticker.base.BaseFragment
import com.github.premnirmal.ticker.components.Injector
import com.github.premnirmal.ticker.getStatusBarHeight
import com.github.premnirmal.ticker.home.ChildFragment
import com.github.premnirmal.ticker.settings.WidgetSettingsFragment
import com.github.premnirmal.tickerwidget.R
import kotlinx.android.synthetic.main.fragment_widgets.fake_status_bar
import kotlinx.android.synthetic.main.fragment_widgets.toolbar
import kotlinx.android.synthetic.main.fragment_widgets.widget_selection_spinner
import javax.inject.Inject
Expand Down Expand Up @@ -49,7 +53,18 @@ class WidgetsFragment : BaseFragment(), ChildFragment, OnItemSelectedListener {
savedInstanceState: Bundle?
) {
super.onViewCreated(view, savedInstanceState)
(toolbar.layoutParams as MarginLayoutParams).topMargin = requireContext().getStatusBarHeight()
// Inset toolbar from window top inset
ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
this.topMargin = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top
}
insets
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
fake_status_bar.updateLayoutParams<ViewGroup.LayoutParams> {
height = requireContext().getStatusBarHeight()
}
}
widgetDataList = widgetDataProvider.getAppWidgetIds()
.map {
widgetDataProvider.dataForWidgetId(it)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout-sw600dp-land/fragment_news_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:background="@color/bg_toolbar"
android:elevation="0dp"
app:elevation="0dp"
>

<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="0dp"
android:id="@+id/fake_status_bar"
android:background="@color/bg_toolbar"
/>
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout-sw600dp-land/fragment_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:background="@color/bg_toolbar"
android:elevation="0dp"
app:elevation="0dp"
>

<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="0dp"
android:id="@+id/fake_status_bar"
android:background="@color/bg_toolbar"
/>
Expand All @@ -41,7 +41,6 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/tablet_margin_horizontal"
android:layout_marginEnd="@dimen/tablet_margin_horizontal"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:elevation="0dp"
android:hint="@string/enter_a_symbol"
android:imeOptions="actionDone"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout-sw600dp-land/fragment_widgets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
android:elevation="0dp"
app:elevation="0dp"
>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/fake_status_bar"
android:background="@color/bg_toolbar"
/>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_news_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:background="@color/bg_toolbar"
android:elevation="0dp"
app:elevation="0dp"
>

<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="0dp"
android:id="@+id/fake_status_bar"
android:background="@color/bg_toolbar"
/>
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/fragment_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:background="@color/bg_toolbar"
android:elevation="0dp"
app:elevation="0dp"
>

<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="0dp"
android:id="@+id/fake_status_bar"
android:background="@color/bg_toolbar"
/>
Expand All @@ -38,7 +38,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginRight="5dp"
android:elevation="0dp"
android:hint="@string/enter_a_symbol"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
app:elevation="0dp"
>

<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/fake_status_bar"
android:background="@color/bg_toolbar"
/>

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/fragment_widgets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
android:elevation="0dp"
app:elevation="0dp"
>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/fake_status_bar"
android:background="@color/bg_toolbar"
/>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/values-v31/styles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="StocksWidget.App.Theme" parent="AppTheme">
<!-- v21 specific -->
<item name="android:statusBarColor">@color/transparent</item>
<item name="android:navigationBarColor">@color/nav_bar_bg</item>
<!-- v23 specific -->
<item name="android:windowLightStatusBar">true</item>
<!-- v27 specific -->
<item name="android:navigationBarDividerColor">@color/transparent</item>
<item name="android:windowLightNavigationBar">true</item>
</style>
<style name="Widget.Container" parent="android:Widget">
<item name="android:padding">?attr/appWidgetPadding</item>
<item name="android:background">@drawable/app_widget_background</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

<style name="SplashTheme" parent="TranslucentTheme"/>

<style name="ParanormalActivityTheme" parent="StocksWidget.App.Theme">
<style name="MainActivityTheme" parent="StocksWidget.App.Theme">
<item name="android:navigationBarColor">@color/nav_bar_bg_2</item>
</style>

Expand Down
4 changes: 2 additions & 2 deletions app/version.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# this file is purely for f-droid because it cannot infer the version name/code from the git tag
versionName=3.9.773
versionCode=300900773
versionName=3.9.774
versionCode=300900774

0 comments on commit 4e50c8b

Please sign in to comment.