diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/ExifEraserActivity.kt b/app/src/main/kotlin/com/none/tom/exiferaser/ExifEraserActivity.kt index 2281e0c7..b1ff72d8 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/ExifEraserActivity.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/ExifEraserActivity.kt @@ -27,11 +27,16 @@ import android.os.Build import android.os.Bundle import android.util.TypedValue import android.view.View +import android.widget.FrameLayout import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.os.bundleOf import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment +import androidx.navigation.ui.setupActionBarWithNavController import androidx.window.core.layout.WindowSizeClass import androidx.window.core.layout.WindowWidthSizeClass import androidx.window.layout.WindowMetricsCalculator @@ -63,43 +68,63 @@ class ExifEraserActivity : AppCompatActivity() { installSplashScreen() enableEdgeToEdge() super.onCreate(savedInstanceState) - val binding = ActivityExifEraserBinding.inflate(layoutInflater) - setContentView(binding.root) - computeWindowSizeClasses() - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) { - (supportFragmentManager.findFragmentById(R.id.nav_controller) as NavHostFragment) - .navController - .addOnDestinationChangedListener { _, destination, _ -> - if (windowSizeClass.windowWidthSizeClass != WindowWidthSizeClass.EXPANDED) { - val tv = TypedValue() - if (destination.id == R.id.fragment_main) { - theme.resolveAttribute( - com.google.android.material.R.attr.colorSurfaceContainer, - tv, - true - ) - } else { - theme.resolveAttribute( - com.google.android.material.R.attr.colorSurface, - tv, - true - ) - } - window.navigationBarColor = tv.data + with(ActivityExifEraserBinding.inflate(layoutInflater)) { + setContentView(root) + computeWindowSizeClasses() + val navController = findNavController() + navController.addOnDestinationChangedListener { _, navDestination, _ -> + if (navDestination.id == R.id.fragment_main) { + toolbar.setLogo(R.drawable.ic_logo) + } else { + toolbar.logo = null + } + } + setSupportActionBar(toolbar) + setupActionBarWithNavController(navController) + ViewCompat.setOnApplyWindowInsetsListener(root) { _, windowInsetsCompat -> + val insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.statusBars()) + root.setLayoutParams( + (root.layoutParams as FrameLayout.LayoutParams).apply { topMargin = insets.top } + ) + windowInsetsCompat + } + root.addView( + object : View(this@ExifEraserActivity) { + override fun onConfigurationChanged(newConfig: Configuration?) { + super.onConfigurationChanged(newConfig) + computeWindowSizeClasses() } } + ) } - binding.layout.addView( - object : View(this) { - override fun onConfigurationChanged(newConfig: Configuration?) { - super.onConfigurationChanged(newConfig) - computeWindowSizeClasses() + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) { + findNavController().addOnDestinationChangedListener { _, destination, _ -> + if (windowSizeClass.windowWidthSizeClass != WindowWidthSizeClass.EXPANDED) { + val tv = TypedValue() + if (destination.id == R.id.fragment_main) { + theme.resolveAttribute( + com.google.android.material.R.attr.colorSurfaceContainer, + tv, + true + ) + } else { + theme.resolveAttribute( + com.google.android.material.R.attr.colorSurface, + tv, + true + ) + } + window.navigationBarColor = tv.data } } - ) + } handleSupportedIntent() } + override fun onSupportNavigateUp(): Boolean { + return findNavController().navigateUp() || super.onSupportNavigateUp() + } + private fun computeWindowSizeClasses() { val metrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(this) val widthDp = metrics.bounds.width() / resources.displayMetrics.density @@ -128,16 +153,13 @@ class ExifEraserActivity : AppCompatActivity() { uris.addAll(clipData.supportedImageUrisToList()) } if (uris.isNotEmpty()) { - (supportFragmentManager.findFragmentById(R.id.nav_controller) as NavHostFragment) - .navController - .navigate( - R.id.global_to_main, - bundleOf(NAV_ARG_IMAGE_SELECTION to uris.toTypedArray()) - ) + findNavController().navigate( + R.id.global_to_main, + bundleOf(NAV_ARG_IMAGE_SELECTION to uris.toTypedArray()) + ) } } else if (shortcutIntentActions.contains(intent.action)) { - (supportFragmentManager.findFragmentById(R.id.nav_controller) as NavHostFragment) - .navController + findNavController() .createDeepLink() .setGraph(R.navigation.nav_graph) .setDestination(R.id.fragment_main) @@ -146,4 +168,9 @@ class ExifEraserActivity : AppCompatActivity() { .startActivities() } } + + private fun findNavController(): NavController { + return (supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment) + .navController + } } diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/core/ui/BaseFragment.kt b/app/src/main/kotlin/com/none/tom/exiferaser/core/ui/BaseFragment.kt index dd8841f1..2669e421 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/core/ui/BaseFragment.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/core/ui/BaseFragment.kt @@ -23,14 +23,9 @@ package com.none.tom.exiferaser.core.ui import android.os.Bundle import android.view.View import androidx.annotation.LayoutRes -import androidx.annotation.StringRes -import androidx.appcompat.app.AppCompatActivity -import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment -import androidx.navigation.fragment.findNavController import androidx.viewbinding.ViewBinding import com.none.tom.exiferaser.ExifEraserActivity -import com.none.tom.exiferaser.R abstract class BaseFragment( @LayoutRes layoutRes: Int @@ -51,17 +46,4 @@ abstract class BaseFragment( abstract fun bindLayout(view: View): B protected fun getWindowSizeClass() = (requireActivity() as ExifEraserActivity).windowSizeClass - - protected fun setupToolbar(toolbar: Toolbar, @StringRes titleRes: Int) { - (requireActivity() as? AppCompatActivity)?.setSupportActionBar(toolbar) - toolbar.setTitle(titleRes) - requireParentFragment() - .childFragmentManager - .backStackEntryCount - .takeIf { count -> count > 0 } - ?.let { - toolbar.setNavigationIcon(R.drawable.ic_arrow_back) - toolbar.setNavigationOnClickListener { findNavController().navigateUp() } - } - } } diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/help/ui/HelpFragment.kt b/app/src/main/kotlin/com/none/tom/exiferaser/help/ui/HelpFragment.kt index 5c24559d..c544f1b7 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/help/ui/HelpFragment.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/help/ui/HelpFragment.kt @@ -51,18 +51,14 @@ class HelpFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsetsCompat -> - val insets = windowInsetsCompat.getInsets( - WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars() - ) + val insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.navigationBars()) view.setLayoutParams( (view.layoutParams as FrameLayout.LayoutParams).apply { - topMargin = insets.top bottomMargin = insets.bottom } ) WindowInsetsCompat.CONSUMED } - setupToolbar(binding.includeToolbar.toolbar, R.string.help) binding.helpAndFeedback.apply { layoutManager = LinearLayoutManager(context) adapter = HelpAdapter(listener = this@HelpFragment) diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessing/ui/ImageProcessingFragment.kt b/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessing/ui/ImageProcessingFragment.kt index 68c9265c..f9f5bca8 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessing/ui/ImageProcessingFragment.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessing/ui/ImageProcessingFragment.kt @@ -73,12 +73,9 @@ class ImageProcessingFragment : BaseFragment( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsetsCompat -> - val insets = windowInsetsCompat.getInsets( - WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars() - ) + val insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.navigationBars()) view.setLayoutParams( (view.layoutParams as FrameLayout.LayoutParams).apply { - topMargin = insets.top bottomMargin = insets.bottom } ) @@ -107,7 +104,6 @@ class ImageProcessingFragment : BaseFragment( } } requireActivity().addMenuProvider(menuProvider, viewLifecycleOwner) - setupToolbar(binding.toolbarInclude.toolbar, R.string.summary) setupResponsiveLayout() binding.details.setOnClickListener { viewModel.handleImageProcessingDetails() } lifecycleScope.launch { diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessingDetails/ui/ImageProcessingDetailsFragment.kt b/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessingDetails/ui/ImageProcessingDetailsFragment.kt index fb069fc1..9bd5a5ec 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessingDetails/ui/ImageProcessingDetailsFragment.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessingDetails/ui/ImageProcessingDetailsFragment.kt @@ -26,7 +26,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.FrameLayout -import android.widget.LinearLayout import androidx.activity.result.contract.ActivityResultContracts import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat @@ -100,14 +99,7 @@ class ImageProcessingDetailsFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsetsCompat -> - val insets = windowInsetsCompat.getInsets( - WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars() - ) - binding.toolbar.setLayoutParams( - (binding.toolbar.layoutParams as LinearLayout.LayoutParams).apply { - topMargin = insets.top - } - ) + val insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.navigationBars()) view.setLayoutParams( (view.layoutParams as FrameLayout.LayoutParams).apply { bottomMargin = insets.bottom @@ -115,7 +107,6 @@ class ImageProcessingDetailsFragment : ) WindowInsetsCompat.CONSUMED } - setupToolbar(binding.toolbar, R.string.details) binding.details.apply { layoutManager = LinearLayoutManager(requireContext()) adapter = ImageProcessingDetailsAdapter(listener = this@ImageProcessingDetailsFragment) diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/main/ui/MainFragment.kt b/app/src/main/kotlin/com/none/tom/exiferaser/main/ui/MainFragment.kt index 27166521..30c8ea2d 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/main/ui/MainFragment.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/main/ui/MainFragment.kt @@ -31,13 +31,10 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View -import android.widget.FrameLayout import androidx.activity.result.PickVisualMediaRequest import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatDelegate import androidx.core.view.MenuProvider -import androidx.core.view.ViewCompat -import androidx.core.view.WindowInsetsCompat import androidx.core.view.doOnLayout import androidx.core.view.isVisible import androidx.draganddrop.DropHelper @@ -116,15 +113,6 @@ class MainFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsetsCompat -> - val insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.statusBars()) - view.setLayoutParams( - (view.layoutParams as FrameLayout.LayoutParams).apply { - topMargin = insets.top - } - ) - windowInsetsCompat - } setupResponsiveAppBarLayout() setupResponsiveTitleLayout() setupResponsiveImageSourceLayout() @@ -452,7 +440,6 @@ class MainFragment : } private fun setupResponsiveAppBarLayout() { - setupToolbar(binding.toolbar, R.string.app_name) val menuProvider = object : MenuProvider { override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/settings/ui/SettingsFragment.kt b/app/src/main/kotlin/com/none/tom/exiferaser/settings/ui/SettingsFragment.kt index ef5d0474..a5d4aa26 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/settings/ui/SettingsFragment.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/settings/ui/SettingsFragment.kt @@ -76,18 +76,14 @@ class SettingsFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsetsCompat -> - val insets = windowInsetsCompat.getInsets( - WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars() - ) + val insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.navigationBars()) view.setLayoutParams( (view.layoutParams as FrameLayout.LayoutParams).apply { - topMargin = insets.top bottomMargin = insets.bottom } ) WindowInsetsCompat.CONSUMED } - setupToolbar(binding.toolbarInclude.toolbar, R.string.settings) binding.preferences.apply { layoutManager = LinearLayoutManager(context) adapter = SettingsAdapter(listener = this@SettingsFragment) diff --git a/app/src/main/res/layout-sw600dp/fragment_image_processing.xml b/app/src/main/res/layout-sw600dp/fragment_image_processing.xml index 9644083f..edb338f3 100644 --- a/app/src/main/res/layout-sw600dp/fragment_image_processing.xml +++ b/app/src/main/res/layout-sw600dp/fragment_image_processing.xml @@ -6,10 +6,6 @@ android:layout_height="match_parent" android:transitionGroup="true"> - - - - + app:layout_constraintTop_toTopOf="parent" /> - - + + - + diff --git a/app/src/main/res/layout/fragment_help.xml b/app/src/main/res/layout/fragment_help.xml index c9132832..6d240917 100644 --- a/app/src/main/res/layout/fragment_help.xml +++ b/app/src/main/res/layout/fragment_help.xml @@ -1,17 +1,6 @@ - - - - - - + android:transitionGroup="true" /> diff --git a/app/src/main/res/layout/fragment_image_processing.xml b/app/src/main/res/layout/fragment_image_processing.xml index 2ffb3af9..51c0d021 100644 --- a/app/src/main/res/layout/fragment_image_processing.xml +++ b/app/src/main/res/layout/fragment_image_processing.xml @@ -6,10 +6,6 @@ android:layout_height="match_parent" android:transitionGroup="true"> - - - - - - - - + android:transitionName="@string/shared_element_details" /> diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml index 01746858..6469c5e4 100644 --- a/app/src/main/res/layout/fragment_main.xml +++ b/app/src/main/res/layout/fragment_main.xml @@ -7,13 +7,6 @@ android:orientation="vertical" android:transitionGroup="true"> - - + app:layout_constraintTop_toTopOf="parent" /> - - - - - - + android:transitionGroup="true" /> diff --git a/app/src/main/res/layout/toolbar.xml b/app/src/main/res/layout/toolbar.xml deleted file mode 100644 index 0e334017..00000000 --- a/app/src/main/res/layout/toolbar.xml +++ /dev/null @@ -1,6 +0,0 @@ - -