Skip to content

Commit

Permalink
virtual-device-app: Add LoadingFragment for commissioning establish s…
Browse files Browse the repository at this point in the history
…tarted event

Signed-off-by: Jaehoon You <jaehoon.you@samsung.com>
  • Loading branch information
Jaehoon-You committed Aug 1, 2023
1 parent e059202 commit 28a6f36
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ object DeepLink {
)
.build()
}

fun getDeepLinkRequestForLoadingFragment(setting: String): NavDeepLinkRequest {
return NavDeepLinkRequest.Builder.fromUri(
"android-app://com.matter.virtual.device.app.feature.main/loadingFragment/${setting}"
.toUri()
)
.build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.matter.virtual.device.app.feature.main

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.matter.virtual.device.app.core.common.MatterSettings
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.json.Json
import timber.log.Timber

@AndroidEntryPoint
class LoadingFragment : Fragment() {

private lateinit var binding: FragmentLoadingBinding

private lateinit var matterSettings: MatterSettings
private lateinit var onBackPressedCallback: OnBackPressedCallback

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
Timber.d("Hit")
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_loading, container, false)
binding.lifecycleOwner = viewLifecycleOwner

return binding.root
}

@OptIn(ExperimentalSerializationApi::class)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Timber.d("Hit")
super.onViewCreated(view, savedInstanceState)

(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)
}

override fun onResume() {
Timber.d("Hit")
super.onResume()
}

override fun onAttach(context: Context) {
Timber.d("Hit")
super.onAttach(context)

onBackPressedCallback =
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
Timber.d("handleOnBackPressed()")
findNavController().popBackStack()
}
}

requireActivity().onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}

override fun onDetach() {
Timber.d("Hit")
super.onDetach()
onBackPressedCallback.remove()
}

override fun onDestroy() {
Timber.d("Hit")
super.onDestroy()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?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">

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

<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:background="@android:color/transparent"
android:fitsSystemWindows="true"
app:elevation="0dp"
app:expanded="false"
app:layout_behavior="com.matter.virtual.device.app.core.common.ui.DisableAppBarLayoutBehavior">

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

<TextView
android:id="@+id/collapse_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/title_loading"
android:textAlignment="center"
android:textSize="@dimen/collapse_title_text_size" />

<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
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:text="@string/title_loading"
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.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

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

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/menu_item_side_space"
android:layout_marginTop="20dp"
android:layout_marginEnd="@dimen/menu_item_side_space"
android:background="@drawable/menu_item_bg">

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/loading_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
app:indicatorColor="@color/colorControlActivated"
android:indeterminate="true"
app:layout_constraintBottom_toTopOf="@+id/loading_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/loading_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="@string/description_loading"
android:textAlignment="center"
android:textSize="17sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loading_progress" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@
android:name="com.matter.virtual.device.app.feature.main.MainFragment"
android:label="MainFragment"
tools:layout="@layout/fragment_main" />

<fragment
android:id="@+id/loadingFragment"
android:name="com.matter.virtual.device.app.feature.main.LoadingFragment"
android:label="LoadingFragment"
tools:layout="@layout/fragment_loading">
<argument
android:name="setting"
app:argType="string" />
<deepLink app:uri="android-app://com.matter.virtual.device.app.feature.main/loadingFragment/{setting}" />
</fragment>
</navigation>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title_main" translatable="false">Matter Virtual Device</string>
<string name="title_loading" translatable="false">Loading</string>
<string name="description_loading">Commissioning in process.</string>
</resources>

0 comments on commit 28a6f36

Please sign in to comment.