Skip to content

Commit

Permalink
[Android] virtual-device-app: Remove collapsing layout (project-chip#…
Browse files Browse the repository at this point in the history
…30948)

* virtual-device-app: Remove collapsing layout

Signed-off-by: Jaehoon You <[email protected]>
Signed-off-by: Charles Kim <[email protected]>

* virtual-device-app: Cleanup resources

Signed-off-by: Jaehoon You <[email protected]>
Signed-off-by: Charles Kim <[email protected]>

---------

Signed-off-by: Jaehoon You <[email protected]>
Signed-off-by: Charles Kim <[email protected]>
  • Loading branch information
Jaehoon-You authored Dec 19, 2023
1 parent 75113fc commit 9ba4242
Show file tree
Hide file tree
Showing 19 changed files with 394 additions and 745 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@
<item name="android:navigationBarColor">@color/color_background_secondary</item>
</style>

<style name="Theme.CollapsingToolbar" parent="Theme.App">
<item name="statusBarScrim">@android:color/transparent</item>
<item name="android:background">@color/action_bar_background_color_light</item>
<item name="colorControlNormal">@color/toolbar_button_color</item>
</style>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.fragment.app.activityViewModels
import com.matter.virtual.device.app.core.common.EventObserver
import com.matter.virtual.device.app.core.common.MatterSettings
import com.matter.virtual.device.app.core.ui.databinding.LayoutAppbarBinding
import kotlin.math.abs
import timber.log.Timber

abstract class BaseFragment<T : ViewDataBinding, V : BaseViewModel>(
Expand Down Expand Up @@ -50,16 +49,6 @@ abstract class BaseFragment<T : ViewDataBinding, V : BaseViewModel>(
(activity as AppCompatActivity).setSupportActionBar(layoutAppBarBinding.toolbar)
(activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(true)

layoutAppBarBinding.appBarLayout.addOnOffsetChangedListener { appBarLayout, verticalOffset ->
var ratio = 0F
if (abs(verticalOffset) != 0) {
ratio = abs(verticalOffset).toFloat() / appBarLayout.totalScrollRange.toFloat()
}

layoutAppBarBinding.collapseTitle.alpha = 1f - ratio * 2f + 0.1f
layoutAppBarBinding.toolbarTitle.alpha = (ratio - 0.5f) * 2f + 0.1f
}

layoutAppBarBinding.toolbarMoreMenuButton.setOnClickListener {
Timber.d("More")
showMoreMenuPopup(it)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,41 @@
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/appbar_layout_height"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
android:fitsSystemWindows="true"
app:elevation="0dp"
app:expanded="false"
app:layout_behavior="com.matter.virtual.device.app.core.ui.DisableAppBarLayoutBehavior">
app:elevation="0dp">

<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/Theme.CollapsingToolbar"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
android:layout_height="match_parent">

<TextView
android:id="@+id/collapse_title"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textAlignment="center"
android:textSize="@dimen/collapse_title_text_size" />
android:layout_height="match_parent">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="@android:color/transparent"
android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
android:contentInsetEnd="0dp"
android:contentInsetRight="0dp"
android:theme="@style/Theme.CollapsingToolbar"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:elevation="0dp"
app:layout_collapseMode="pin">

<androidx.constraintlayout.widget.ConstraintLayout
<TextView
android:id="@+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:textSize="@dimen/toolbar_title_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:textSize="@dimen/toolbar_title_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/toolbar_more_menu_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/toolbar_more_menu_button_margin_end"
android:scaleType="centerCrop"
android:tint="@color/toolbar_button_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/round_more_vert_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/toolbar_more_menu_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/toolbar_more_menu_button_margin_end"
android:scaleType="centerCrop"
android:tint="@color/toolbar_button_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/round_more_vert_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
</layout>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="appbar_layout_height">350dp</dimen>
<dimen name="collapse_title_text_size">25sp</dimen>
<dimen name="toolbar_title_text_size">17sp</dimen>
<dimen name="toolbar_more_menu_button_margin_end">20dp</dimen>

<dimen name="device_title_icon_width">60dp</dimen>
<dimen name="device_title_icon_height">60dp</dimen>
<dimen name="device_title_icon_margin_top">20dp</dimen>
<dimen name="device_title_text_margin_top">10sp</dimen>
<dimen name="device_title_text_size">24sp</dimen>

<dimen name="device_item_top_space_height">44dp</dimen>
<dimen name="device_item_margin_horizontal">12dp</dimen>
<dimen name="device_item_bottom_space_height">25dp</dimen>
<dimen name="device_item_padding_start">20dp</dimen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,20 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:id="@+id/door_lock_function_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/door_lock_lock_state_layout"
layout="@layout/layout_item_title_value_simple_button" />

<include
android:id="@+id/door_lock_lock_state_layout"
layout="@layout/layout_item_title_value_simple_button" />
<include
android:id="@+id/door_lock_send_alarm_layout"
layout="@layout/layout_item_title_value_simple_button" />

<include
android:id="@+id/door_lock_send_alarm_layout"
layout="@layout/layout_item_title_value_simple_button" />

<include
android:id="@+id/door_lock_battery_layout"
layout="@layout/layout_item_title_value_seekbar" />
</LinearLayout>
<include
android:id="@+id/door_lock_battery_layout"
layout="@layout/layout_item_title_value_seekbar" />

<!-- Bottom Space -->
<include layout="@layout/layout_space_bottom" />
<include layout="@layout/layout_bottom_space" />
<!-- Bottom Space -->
</LinearLayout>
</ScrollView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ class OnOffSwitchFragment :
override fun setupAppbar(): LayoutAppbarBinding = binding.appbar

override fun setupUi() {
/** title icon */
binding.onOffSwitchTitleLayout.titleIcon.setImageResource(matterSettings.device.deviceIconResId)

/** title text */
binding.onOffSwitchTitleLayout.titleText.text = getString(matterSettings.device.deviceNameResId)
binding.appbar.toolbarTitle.text = getString(matterSettings.device.deviceNameResId)

/** OnOff layout */
binding.onOffSwitchOnOffLayout.buttonData =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<androidx.coordinatorlayout.widget.CoordinatorLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
android:layout_height="match_parent">

<!-- appbar -->
<include
android:id="@+id/appbar"
layout="@layout/layout_appbar" />
<!-- appbar -->

<androidx.core.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
android:layout_marginTop="?attr/actionBarSize">

<ScrollView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<!-- title -->
<include
android:id="@+id/on_off_switch_title_layout"
layout="@layout/layout_title" />
<!-- title -->

<!-- Top Space -->
<include layout="@layout/layout_space_top" />
<!-- Top Space -->

<!-- On Off Button -->
<include
android:id="@+id/on_off_switch_on_off_layout"
layout="@layout/layout_item_value_on_off_button" />
<!-- On Off Button -->

<!-- Bottom Space -->
<include layout="@layout/layout_space_bottom" />
<!-- Bottom Space -->
</LinearLayout>
</ScrollView>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
android:layout_height="wrap_content"
android:orientation="vertical">

<include
android:id="@+id/on_off_switch_on_off_layout"
layout="@layout/layout_item_value_on_off_button" />

<!-- Bottom Space -->
<include layout="@layout/layout_bottom_space" />
<!-- Bottom Space -->
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.matter.virtual.device.app.core.common.MatterSettings
import com.matter.virtual.device.app.core.ui.SharedViewModel
import com.matter.virtual.device.app.feature.main.databinding.FragmentLoadingBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlin.math.abs
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
Expand Down Expand Up @@ -57,16 +56,6 @@ class LoadingFragment : Fragment() {
(activity as AppCompatActivity).setSupportActionBar(binding.toolbar)
(activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(true)

binding.appBarLayout.addOnOffsetChangedListener { appBarLayout, verticalOffset ->
var ratio = 0F
if (abs(verticalOffset) != 0) {
ratio = abs(verticalOffset).toFloat() / appBarLayout.totalScrollRange.toFloat()
}

binding.collapseTitle.alpha = 1f - ratio * 2f + 0.1f
binding.toolbarTitle.alpha = (ratio - 0.5f) * 2f + 0.1f
}

val args: LoadingFragmentArgs by navArgs()
this.matterSettings = Json.decodeFromString(args.setting)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.matter.virtual.device.app.core.ui.SharedViewModel
import com.matter.virtual.device.app.feature.main.databinding.FragmentMainBinding
import com.matter.virtual.device.app.feature.main.model.Menu
import dagger.hilt.android.AndroidEntryPoint
import kotlin.math.abs
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -55,16 +54,6 @@ class MainFragment : Fragment() {
(activity as AppCompatActivity).setSupportActionBar(binding.toolbar)
(activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(true)

binding.appBarLayout.addOnOffsetChangedListener { appBarLayout, verticalOffset ->
var ratio = 0F
if (abs(verticalOffset) != 0) {
ratio = abs(verticalOffset).toFloat() / appBarLayout.totalScrollRange.toFloat()
}

binding.collapseTitle.alpha = 1f - ratio * 2f + 0.1f
binding.toolbarTitle.alpha = (ratio - 0.5f) * 2f + 0.1f
}

viewModel.uiState.observe(viewLifecycleOwner) { uiState ->
Timber.d("uiState:$uiState")
when (uiState) {
Expand Down
Loading

0 comments on commit 9ba4242

Please sign in to comment.