From 4e50c8b258c97dac291ddc55105b660f3617795a Mon Sep 17 00:00:00 2001 From: Prem Nirmal Date: Fri, 25 Mar 2022 14:51:24 +0000 Subject: [PATCH] Fix toolbar insets --- app/src/main/AndroidManifest.xml | 2 +- .../premnirmal/ticker/home/MainActivity.kt | 6 +++--- .../ticker/news/NewsFeedFragment.kt | 19 +++++++++++++++--- .../ticker/portfolio/search/SearchFragment.kt | 20 +++++++++++++++---- .../ticker/settings/SettingsFragment.kt | 18 +++++++++++++++-- .../ticker/widget/WidgetsFragment.kt | 19 ++++++++++++++++-- .../fragment_news_feed.xml | 4 ++-- .../layout-sw600dp-land/fragment_search.xml | 5 ++--- .../layout-sw600dp-land/fragment_widgets.xml | 6 ++++++ ...ivity_paranormal.xml => activity_main.xml} | 0 .../main/res/layout/fragment_news_feed.xml | 4 ++-- app/src/main/res/layout/fragment_search.xml | 5 ++--- app/src/main/res/layout/fragment_settings.xml | 7 +++++++ app/src/main/res/layout/fragment_widgets.xml | 6 ++++++ app/src/main/res/values-v31/styles.xml | 10 ++++++++++ app/src/main/res/values/styles.xml | 2 +- app/version.properties | 4 ++-- 17 files changed, 109 insertions(+), 28 deletions(-) rename app/src/main/res/layout/{activity_paranormal.xml => activity_main.xml} (100%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0f935f4e..c8541183 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,7 +34,7 @@ android:label="@string/app_name" android:launchMode="singleTask" android:windowSoftInputMode="adjustPan" - android:theme="@style/ParanormalActivityTheme"> + android:theme="@style/MainActivityTheme"> diff --git a/app/src/main/kotlin/com/github/premnirmal/ticker/home/MainActivity.kt b/app/src/main/kotlin/com/github/premnirmal/ticker/home/MainActivity.kt index 48a6866e..92fe280f 100644 --- a/app/src/main/kotlin/com/github/premnirmal/ticker/home/MainActivity.kt +++ b/app/src/main/kotlin/com/github/premnirmal/ticker/home/MainActivity.kt @@ -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 @@ -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) } diff --git a/app/src/main/kotlin/com/github/premnirmal/ticker/news/NewsFeedFragment.kt b/app/src/main/kotlin/com/github/premnirmal/ticker/news/NewsFeedFragment.kt index b6c8ed7a..b15b4713 100644 --- a/app/src/main/kotlin/com/github/premnirmal/ticker/news/NewsFeedFragment.kt +++ b/app/src/main/kotlin/com/github/premnirmal/ticker/news/NewsFeedFragment.kt @@ -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 @@ -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 { @@ -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 { + this.topMargin = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top + } + insets + } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + fake_status_bar.updateLayoutParams { + height = requireContext().getStatusBarHeight() + } + } adapter = NewsFeedAdapter(this) recycler_view.layoutManager = LinearLayoutManager(activity) recycler_view.addItemDecoration( diff --git a/app/src/main/kotlin/com/github/premnirmal/ticker/portfolio/search/SearchFragment.kt b/app/src/main/kotlin/com/github/premnirmal/ticker/portfolio/search/SearchFragment.kt index 988e444f..800eda12 100644 --- a/app/src/main/kotlin/com/github/premnirmal/ticker/portfolio/search/SearchFragment.kt +++ b/app/src/main/kotlin/com/github/premnirmal/ticker/portfolio/search/SearchFragment.kt @@ -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 @@ -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 @@ -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 { + this.topMargin = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top + } + insets + } + } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + fake_status_bar.updateLayoutParams { + height = requireContext().getStatusBarHeight() + } } adapter = SuggestionsAdapter(this) recycler_view.layoutManager = LinearLayoutManager(activity) diff --git a/app/src/main/kotlin/com/github/premnirmal/ticker/settings/SettingsFragment.kt b/app/src/main/kotlin/com/github/premnirmal/ticker/settings/SettingsFragment.kt index a68b9a23..73cb9a26 100644 --- a/app/src/main/kotlin/com/github/premnirmal/ticker/settings/SettingsFragment.kt +++ b/app/src/main/kotlin/com/github/premnirmal/ticker/settings/SettingsFragment.kt @@ -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 @@ -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 @@ -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 @@ -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 { + this.topMargin = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top + } + insets + } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + fake_status_bar.updateLayoutParams { + 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 diff --git a/app/src/main/kotlin/com/github/premnirmal/ticker/widget/WidgetsFragment.kt b/app/src/main/kotlin/com/github/premnirmal/ticker/widget/WidgetsFragment.kt index 8257282f..d54cea8b 100644 --- a/app/src/main/kotlin/com/github/premnirmal/ticker/widget/WidgetsFragment.kt +++ b/app/src/main/kotlin/com/github/premnirmal/ticker/widget/WidgetsFragment.kt @@ -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 @@ -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 { + this.topMargin = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top + } + insets + } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + fake_status_bar.updateLayoutParams { + height = requireContext().getStatusBarHeight() + } + } widgetDataList = widgetDataProvider.getAppWidgetIds() .map { widgetDataProvider.dataForWidgetId(it) diff --git a/app/src/main/res/layout-sw600dp-land/fragment_news_feed.xml b/app/src/main/res/layout-sw600dp-land/fragment_news_feed.xml index 688d07fa..6f8a859a 100644 --- a/app/src/main/res/layout-sw600dp-land/fragment_news_feed.xml +++ b/app/src/main/res/layout-sw600dp-land/fragment_news_feed.xml @@ -9,14 +9,14 @@ diff --git a/app/src/main/res/layout-sw600dp-land/fragment_search.xml b/app/src/main/res/layout-sw600dp-land/fragment_search.xml index 5660b30f..592c3263 100644 --- a/app/src/main/res/layout-sw600dp-land/fragment_search.xml +++ b/app/src/main/res/layout-sw600dp-land/fragment_search.xml @@ -10,14 +10,14 @@ @@ -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" diff --git a/app/src/main/res/layout-sw600dp-land/fragment_widgets.xml b/app/src/main/res/layout-sw600dp-land/fragment_widgets.xml index c994b228..d7c24953 100644 --- a/app/src/main/res/layout-sw600dp-land/fragment_widgets.xml +++ b/app/src/main/res/layout-sw600dp-land/fragment_widgets.xml @@ -14,6 +14,12 @@ android:elevation="0dp" app:elevation="0dp" > + diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index c36b3356..a7b6e128 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -9,14 +9,14 @@ @@ -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" diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index b59f3733..1dcb8291 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -17,6 +17,13 @@ app:elevation="0dp" > + + + + diff --git a/app/version.properties b/app/version.properties index cb15fafd..2a90aba3 100644 --- a/app/version.properties +++ b/app/version.properties @@ -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 \ No newline at end of file +versionName=3.9.774 +versionCode=300900774 \ No newline at end of file