Skip to content

Commit

Permalink
[fragment/library] Update layout (W600dp & W1240dp)
Browse files Browse the repository at this point in the history
  • Loading branch information
1552980358 committed Jun 4, 2023
1 parent 8a40661 commit f2f322c
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LibraryFragment: BaseMultiLayoutFragment<FragmentLibraryBinding, LibraryLa
* @param savedInstanceState [android.os.Bundle]
**/
override fun onSetupLayoutAdapter(layoutAdapter: LibraryLayoutAdapter, savedInstanceState: Bundle?) {
layoutAdapter.setupSlidingPane(resources)
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package projekt.cloud.piece.cloudy.ui.fragment.library

import android.content.res.Resources
import android.view.ViewGroup.MarginLayoutParams
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.doOnLayout
import androidx.core.view.updateLayoutParams
import androidx.slidingpanelayout.widget.SlidingPaneLayout
import com.google.android.material.card.MaterialCardView
import projekt.cloud.piece.cloudy.R
import projekt.cloud.piece.cloudy.base.BaseLayoutAdapter
import projekt.cloud.piece.cloudy.base.LayoutAdapterBuilder
import projekt.cloud.piece.cloudy.base.LayoutAdapterConstructor
Expand All @@ -8,6 +16,7 @@ import projekt.cloud.piece.cloudy.util.PixelDensity
import projekt.cloud.piece.cloudy.util.PixelDensity.COMPAT
import projekt.cloud.piece.cloudy.util.PixelDensity.EXPANDED
import projekt.cloud.piece.cloudy.util.PixelDensity.MEDIUM
import projekt.cloud.piece.cloudy.util.WindowInsetUtil.applySystemBarsInsets

typealias LibraryLayoutAdapterBuilder =
LayoutAdapterBuilder<FragmentLibraryBinding, LibraryLayoutAdapter>
Expand All @@ -20,6 +29,7 @@ private typealias LibraryLayoutAdapterConstructor =
* @typeParam [FragmentLibraryBinding]
* @param binding [FragmentLibraryBinding]
*
* @abstractImpl [LibraryLayoutAdapter.LargeScreenCommonImpl]
* @impl [LibraryLayoutAdapter.CompatImpl], [LibraryLayoutAdapter.W600dpImpl], [LibraryLayoutAdapter.W1240dpImpl]
**/
abstract class LibraryLayoutAdapter(
Expand Down Expand Up @@ -50,25 +60,102 @@ abstract class LibraryLayoutAdapter(

}

/**
* [LibraryLayoutAdapter.setupWindowInsets]
*
* @impl [LargeScreenCommonImpl.setupWindowInsets]
**/
open fun setupWindowInsets() = Unit

/**
* [LibraryLayoutAdapter.setupSlidingPane]
* @param resources [android.content.res.Resources]
*
* @impl [W600dpImpl.setupSlidingPane]
**/
open fun setupSlidingPane(resources: Resources) = Unit

/**
* [LibraryLayoutAdapter.CompatImpl]
* @extends [LibraryLayoutAdapter]
* @param binding [FragmentLibraryBinding]
**/
private class CompatImpl(binding: FragmentLibraryBinding): LibraryLayoutAdapter(binding)

/**
* [LibraryLayoutAdapter.LargeScreenCommonImpl]
* @abstractExtends [LibraryLayoutAdapter]
* @param binding [FragmentLibraryBinding]
**/
private abstract class LargeScreenCommonImpl(
binding: FragmentLibraryBinding
): LibraryLayoutAdapter(binding) {

/**
* [LargeScreenCommonImpl.layoutRoot]
* @type [androidx.constraintlayout.widget.ConstraintLayout]
* @layout [R.layout.fragment_library]
* @id [R.id.constraint_layout_root]
**/
private val layoutRoot: ConstraintLayout
get() = binding.constraintLayoutRoot

/**
* [LibraryLayoutAdapter.setupWindowInsets]
**/
override fun setupWindowInsets() {
layoutRoot.applySystemBarsInsets()
}

}

/**
* [LibraryLayoutAdapter.W600dpImpl]
* @extends [LibraryLayoutAdapter]
* @extends [LargeScreenCommonImpl]
* @param binding [FragmentLibraryBinding]
**/
private class W600dpImpl(binding: FragmentLibraryBinding): LibraryLayoutAdapter(binding)
private class W600dpImpl(binding: FragmentLibraryBinding): LargeScreenCommonImpl(binding) {

/**
* [W600dpImpl.slidingPane]
* @type [androidx.slidingpanelayout.widget.SlidingPaneLayout]
* @layout [R.layout.fragment_library]
* @id [R.id.sliding_pane_layout]
**/
private val slidingPane: SlidingPaneLayout
get() = binding.slidingPaneLayout!!

/**
* [W600dpImpl.detailCard]
* @type [com.google.android.material.card.MaterialCardView]
* @layout [R.layout.fragment_library]
* @id [R.id.material_card_view_detail]
**/
private val detailCard: MaterialCardView
get() = binding.materialCardViewDetail!!

/**
* [LibraryLayoutAdapter.setupSlidingPane]
* @param resources [android.content.res.Resources]
**/
override fun setupSlidingPane(resources: Resources) {
slidingPane.doOnLayout {
if (!slidingPane.isSlideable) {
// Set spacing
detailCard.updateLayoutParams<MarginLayoutParams> {
marginStart = resources.getDimensionPixelSize(R.dimen.md_spec_spacing_24)
}
}
}
}

}

/**
* [LibraryLayoutAdapter.W1240dpImpl]
* @extends [LibraryLayoutAdapter]
* @extends [LargeScreenCommonImpl]
* @param binding [FragmentLibraryBinding]
**/
private class W1240dpImpl(binding: FragmentLibraryBinding): LibraryLayoutAdapter(binding)
private class W1240dpImpl(binding: FragmentLibraryBinding): LargeScreenCommonImpl(binding)

}
45 changes: 45 additions & 0 deletions app/src/main/res/layout-w1240dp/fragment_library.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/constraint_layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.card.MaterialCardView
android:id="@+id/material_card_view_list"
android:layout_width="@dimen/md_spec_layout_fixed_pane_360"
android:layout_height="@dimen/constraint"
android:layout_marginVertical="@dimen/md_spec_spacing_8"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/material_card_view_detail">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container_view_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="projekt.cloud.piece.cloudy.ui.fragment.library.pager.PagerLibraryFragment" />

</com.google.android.material.card.MaterialCardView>

<com.google.android.material.card.MaterialCardView
android:id="@+id/material_card_view_detail"
android:layout_width="@dimen/constraint"
android:layout_height="@dimen/constraint"
android:layout_marginHorizontal="@dimen/md_spec_spacing_24"
android:layout_marginVertical="@dimen/md_spec_spacing_8"
app:layout_constraintStart_toEndOf="@id/material_card_view_list"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container_view_detail"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</com.google.android.material.card.MaterialCardView>

</androidx.constraintlayout.widget.ConstraintLayout>
58 changes: 58 additions & 0 deletions app/src/main/res/layout-w600dp/fragment_library.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/constraint_layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.slidingpanelayout.widget.SlidingPaneLayout
android:id="@+id/sliding_pane_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginVertical="@dimen/md_spec_spacing_8"
android:layout_marginEnd="@dimen/md_spec_spacing_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">

<com.google.android.material.card.MaterialCardView
android:layout_width="@dimen/md_spec_layout_fixed_pane_360"
android:layout_height="match_parent"
android:layout_gravity="start">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container_view_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="projekt.cloud.piece.cloudy.ui.fragment.library.pager.PagerLibraryFragment" />

</com.google.android.material.card.MaterialCardView>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="@dimen/library_body_pane_size"
android:layout_height="match_parent"
android:layout_weight="1">

<com.google.android.material.card.MaterialCardView
android:id="@+id/material_card_view_detail"
android:layout_width="@dimen/constraint"
android:layout_height="@dimen/constraint"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container_view_detail"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</com.google.android.material.card.MaterialCardView>

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.slidingpanelayout.widget.SlidingPaneLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
<dimen name="main_container_mini_player_height">56dp</dimen>
<dimen name="main_container_mini_player_peek">136dp</dimen>
<dimen name="main_container_mini_player_trailing">@dimen/md_spec_trailing_24</dimen>

<dimen name="library_body_pane_size">432dp</dimen>

</resources>

0 comments on commit f2f322c

Please sign in to comment.