Commit 4dd28661 authored by vunguyencuong's avatar vunguyencuong

Loading manage home

parent 4a198700
package com.tuya.appsdk.sample.viettelhome.adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.tuya.appsdk.sample.R
import com.tuya.appsdk.sample.viettelhome.home.Home
import com.tuya.appsdk.sample.viettelhome.home.SelectedHomeListener
import org.w3c.dom.Text
class SmartHomeAdapter(private val smartHomes : List<Home>) : RecyclerView.Adapter<SmartHomeAdapter.ViewHolder>() {
class ViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView) {
val imgHome : ImageView = itemView.findViewById(R.id.img_home_red)
val tvNameHome : TextView = itemView.findViewById(R.id.tv_name_smart_home)
val imgShareNetwork : ImageView = itemView.findViewById(R.id.img_share_network)
// init {
// itemView.setOnClickListener(this)
// }
// override fun onClick(p0: View?) {
// listenerClick.
// }
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_home,parent,false)
return ViewHolder(view)
}
override fun getItemCount(): Int {
return smartHomes.size
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.tvNameHome.text = smartHomes[position].getName()
}
// interface OnItemClickListener {
// fun onItemClick(position: Int)
// }
}
\ No newline at end of file
......@@ -6,7 +6,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
......@@ -16,7 +15,7 @@ import com.tuya.appsdk.sample.databinding.FragmentDeviceBinding
import com.tuya.appsdk.sample.viettelhome.adapter.RoomPagerAdapter
import com.tuya.appsdk.sample.viettelhome.room.RoomFragment
class DeviceFragment : Fragment() {
class DeviceFragment : Fragment(), SelectedHomeListener {
private lateinit var bindind : FragmentDeviceBinding
......@@ -29,15 +28,23 @@ class DeviceFragment : Fragment() {
): View? {
// Inflate the layout for this fragment
bindind = FragmentDeviceBinding.inflate(layoutInflater)
setupTablayout()
setupDiaglogHome()
return bindind.root
}
fun setupDiaglogHome(){
bindind.linearBtnSmartHome.setOnClickListener {
val bottomSheetDialogFilter = ListHomeFragment(this)
bottomSheetDialogFilter.show(childFragmentManager, "bottom_sheet_dialog_home")
}
}
fun setupTablayout(){
val viewPager : ViewPager2 = bindind.viewpager2
val tabLayout : TabLayout = bindind.tbLayout
val roomAdapter = RoomPagerAdapter(childFragmentManager,lifecycle)
// roomAdapter.addFragment(RoomFragment(),"Tất cả các thiết bị")
// roomAdapter.addFragment(RoomFragment(),"Phòng khách")
// roomAdapter.addFragment(RoomFragment(),"Phòng ngủ")
// roomAdapter.addFragment(RoomFragment(),"Phòng bếp")
// roomAdapter.addFragment(RoomFragment(),"Phòng vệ sinh")
roomAdapter.addFragment(RoomFragment.newInstance())
roomAdapter.addFragment(RoomFragment.newInstance())
roomAdapter.addFragment(RoomFragment.newInstance())
......@@ -66,8 +73,10 @@ class DeviceFragment : Fragment() {
}
})
}
override fun onSelectedHome(name: String) {
return bindind.root
}
......
package com.tuya.appsdk.sample.viettelhome.home
class Home(private var name : String) {
fun setName(nameHome : String){
name = nameHome
}
fun getName() : String {
return name
}
}
\ No newline at end of file
......@@ -25,6 +25,12 @@ class HomeManageFragment : Fragment() {
savedInstanceState: Bundle?
): View? {
binding = FragmentHomeManageBinding.inflate(layoutInflater)
setupNavigation()
return binding.root
}
fun setupNavigation(){
val bottomNavigationView = binding.bottomNavigation
homePageFragment = HomePageFragment()
deviceFragment = DeviceFragment()
......@@ -47,8 +53,6 @@ class HomeManageFragment : Fragment() {
requireActivity().supportFragmentManager.beginTransaction().replace(R.id.container, selectedFragment!!).commit()
true
}
return binding.root
}
}
\ No newline at end of file
package com.tuya.appsdk.sample.viettelhome.home
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.tuya.appsdk.sample.R
import com.tuya.appsdk.sample.databinding.FragmentListDeviceItemBinding
import com.tuya.appsdk.sample.databinding.FragmentListHomeBinding
import com.tuya.appsdk.sample.databinding.FragmentRoomBinding
import com.tuya.appsdk.sample.viettelhome.adapter.DeviceAdapter
import com.tuya.appsdk.sample.viettelhome.device.Device
import kotlin.math.log
import com.tuya.appsdk.sample.viettelhome.adapter.SmartHomeAdapter
class RoomFragment : Fragment() {
class ListHomeFragment(private var onSelectedHome : SelectedHomeListener) : BottomSheetDialogFragment() {
private lateinit var binding : FragmentRoomBinding
val img = R.drawable.img_plug.toString()
private val demoList = listOf(
Device(img.toInt(),"Ổ cắm thông minh 1", "Phòng khách",1),
Device(img.toInt(),"Ổ cắm thông minh 2", "Phòng khách",0),
Device(img.toInt(),"Ổ cắm thông minh 3", "Phòng khách",0),
Device(img.toInt(),"Ổ cắm thông minh 4", "Phòng khách",1),
Device(img.toInt(),"Ổ cắm thông minh 5", "Phòng khách",1),
private lateinit var binding: FragmentListHomeBinding
)
private val demoListHome = listOf(
Home("Smart Home"),
Home("Smart Home 1"),
Home("Smart Home 2")
)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentRoomBinding.inflate(inflater)
binding = FragmentListHomeBinding.inflate(inflater)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// binding.layoutListDevice.recycleListDeviceItem.apply {
// adapter = DeviceAdapter(demoList)
// }
binding.recycleListDeviceItem.apply {
Log.d("check", "onViewCreated: done")
adapter = DeviceAdapter(demoList)
val bottomSheet = dialog?.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
bottomSheet?.background = ColorDrawable(Color.TRANSPARENT)
binding.recyclerListHome.apply {
layoutManager = LinearLayoutManager(context)
adapter = SmartHomeAdapter(demoListHome)
}
}
}
\ No newline at end of file
package com.tuya.appsdk.sample.viettelhome.home
interface SelectedHomeListener {
fun onSelectedHome(name : String)
}
\ No newline at end of file
......@@ -30,7 +30,6 @@ class LoginFragment : Fragment() {
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentLoginBinding.inflate(layoutInflater)
initView()
enterPhoneNumber()
......
......@@ -7,30 +7,47 @@ import android.view.View
import android.view.ViewGroup
import com.tuya.appsdk.sample.R
import com.tuya.appsdk.sample.databinding.FragmentRoomBinding
import com.tuya.appsdk.sample.viettelhome.adapter.DeviceAdapter
import com.tuya.appsdk.sample.viettelhome.device.Device
class RoomFragment : Fragment() {
companion object{
fun newInstance(): RoomFragment {
val args = Bundle()
val fragment =RoomFragment ()
val fragment = RoomFragment ()
fragment.arguments = args
return fragment
}
}
private lateinit var binding : FragmentRoomBinding
val img = R.drawable.img_plug.toString()
private val demoList = listOf(
Device(img.toInt(),"Ổ cắm thông minh 1", "Phòng khách",1),
Device(img.toInt(),"Ổ cắm thông minh 2", "Phòng khách",0),
Device(img.toInt(),"Ổ cắm thông minh 3", "Phòng khách",0),
Device(img.toInt(),"Ổ cắm thông minh 4", "Phòng khách",1),
Device(img.toInt(),"Ổ cắm thông minh 5", "Phòng khách",1),
)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentRoomBinding.inflate(layoutInflater)
binding = FragmentRoomBinding.inflate(inflater)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.layoutListDevice.recycleListDeviceItem.apply {
adapter = DeviceAdapter(demoList)
}
return binding.root
}
......
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white"/>
<corners android:topLeftRadius="24dp" android:topRightRadius="24dp"/>
</shape>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:pathData="M8.347,0.128C8.147,-0.043 7.853,-0.043 7.653,0.128L0.186,6.528L0,6.688V6.933V14C0,14.884 1.116,16 2,16H5.867C6.161,16 6.4,15.761 6.4,15.467V12.267C6.4,11.383 7.116,10.667 8,10.667C8.884,10.667 9.6,11.383 9.6,12.267V15.467C9.6,15.761 9.839,16 10.133,16H14C14.884,16 16,14.884 16,14V6.933V6.688L15.814,6.528L8.347,0.128ZM11,12.267C11,10.794 9.473,9.5 8,9.5C6.527,9.5 5,10.794 5,12.267V14.5H2C1.705,14.5 1.5,14.295 1.5,14V7.5L8,2L14.5,7.5V14C14.5,14.295 14.295,14.5 14,14.5H11V12.267Z"
android:fillType="evenOdd">
<aapt:attr name="android:fillColor">
<gradient
android:startX="8"
android:startY="-0"
android:endX="21.7"
android:endY="5.208"
android:type="linear">
<item android:offset="0" android:color="#FFF8214B"/>
<item android:offset="1" android:color="#FFBE0A45"/>
</gradient>
</aapt:attr>
</path>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="14dp"
android:height="16dp"
android:viewportWidth="14"
android:viewportHeight="16">
<path
android:pathData="M10.858,10.287C10.477,10.287 10.1,10.363 9.749,10.511C9.399,10.66 9.081,10.877 8.816,11.151L5.524,9.038C5.781,8.371 5.781,7.633 5.524,6.967L8.816,4.853C9.279,5.327 9.893,5.625 10.551,5.696C11.21,5.767 11.873,5.607 12.426,5.244C12.98,4.88 13.39,4.336 13.587,3.703C13.783,3.07 13.753,2.389 13.503,1.776C13.252,1.163 12.796,0.656 12.213,0.342C11.63,0.027 10.956,-0.074 10.306,0.054C9.656,0.182 9.071,0.532 8.651,1.044C8.23,1.556 8.001,2.199 8.002,2.861C8.003,3.215 8.069,3.566 8.195,3.896L4.903,6.01C4.507,5.603 3.998,5.323 3.442,5.207C2.886,5.09 2.307,5.142 1.781,5.356C1.255,5.57 0.804,5.936 0.487,6.407C0.169,6.879 0,7.434 0,8.002C0,8.571 0.169,9.126 0.487,9.597C0.804,10.069 1.255,10.435 1.781,10.649C2.307,10.862 2.886,10.915 3.442,10.798C3.998,10.682 4.507,10.402 4.903,9.995L8.195,12.108C8.069,12.439 8.003,12.79 8.002,13.144C8.002,13.709 8.17,14.261 8.484,14.731C8.797,15.2 9.244,15.566 9.765,15.783C10.287,15.999 10.862,16.055 11.416,15.945C11.97,15.835 12.479,15.563 12.878,15.163C13.278,14.764 13.55,14.255 13.66,13.701C13.77,13.147 13.714,12.573 13.497,12.051C13.281,11.529 12.915,11.083 12.445,10.769C11.976,10.455 11.423,10.287 10.858,10.287ZM10.858,1.147C11.198,1.147 11.529,1.248 11.811,1.436C12.092,1.624 12.312,1.892 12.442,2.205C12.572,2.518 12.606,2.863 12.539,3.195C12.473,3.528 12.31,3.833 12.07,4.073C11.831,4.312 11.525,4.476 11.193,4.542C10.86,4.608 10.516,4.574 10.203,4.444C9.89,4.315 9.622,4.095 9.434,3.813C9.245,3.531 9.145,3.2 9.145,2.861C9.147,2.407 9.328,1.972 9.649,1.651C9.97,1.33 10.405,1.149 10.858,1.147ZM2.861,9.716C2.522,9.716 2.191,9.616 1.909,9.427C1.627,9.239 1.407,8.971 1.278,8.658C1.148,8.345 1.114,8 1.18,7.668C1.246,7.336 1.409,7.03 1.649,6.79C1.889,6.551 2.194,6.388 2.526,6.321C2.859,6.255 3.204,6.289 3.517,6.419C3.83,6.549 4.097,6.768 4.286,7.05C4.474,7.332 4.575,7.663 4.575,8.002C4.573,8.456 4.392,8.891 4.071,9.212C3.75,9.533 3.315,9.714 2.861,9.716ZM10.858,14.858C10.52,14.858 10.188,14.757 9.906,14.569C9.625,14.38 9.405,14.113 9.275,13.8C9.145,13.486 9.112,13.142 9.178,12.809C9.244,12.477 9.407,12.172 9.647,11.932C9.886,11.692 10.192,11.529 10.524,11.463C10.857,11.397 11.201,11.431 11.514,11.56C11.828,11.69 12.095,11.91 12.283,12.192C12.472,12.473 12.572,12.805 12.572,13.144C12.57,13.598 12.389,14.032 12.068,14.353C11.747,14.674 11.313,14.856 10.858,14.858Z">
<aapt:attr name="android:fillColor">
<gradient
android:startX="6.857"
android:startY="-0"
android:endX="19.007"
android:endY="3.959"
android:type="linear">
<item android:offset="0" android:color="#FFF8214B"/>
<item android:offset="1" android:color="#FFBE0A45"/>
</gradient>
</aapt:attr>
</path>
</vector>
......@@ -60,7 +60,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="#F5F5F5"
android:layout_marginStart="20dp"
android:layout_marginStart="26dp"
android:layout_marginTop="8dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
......
......@@ -51,18 +51,17 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"/>
<!-- <androidx.recyclerview.widget.RecyclerView-->
<!-- android:id="@+id/recycle_list_device_item"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:layout_constraintTop_toBottomOf="@id/tv_detail_list_item"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- android:layout_marginTop="16dp"-->
<!-- android:layout_marginStart="16dp"-->
<!-- android:layout_marginEnd="16dp"-->
<!-- app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"-->
<!-- android:orientation="vertical"-->
<!-- tools:listitem="@layout/item_device"-->
<!-- android:background="@color/red"/>-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycle_list_device_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tv_detail_list_item"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="vertical"
tools:listitem="@layout/item_device" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".viettelhome.home.ListHomeFragment"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_list_home"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="@drawable/bg_background_radius_top_24"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="48dp"
app:layout_constraintTop_toBottomOf="@id/recycler_list_home"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="#F5F5F5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quản lý nhà"
android:textColor="#EC0D3A"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_gravity="center"
android:padding="10dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -7,39 +7,26 @@
tools:context=".viettelhome.room.RoomFragment"
android:background="#F5F5F5">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycle_list_device_item"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="vertical"
tools:listitem="@layout/item_device" />
android:layout_marginEnd="16dp">
<!-- <LinearLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="0dp"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- android:layout_marginTop="16dp"-->
<!-- android:layout_marginStart="16dp"-->
<!-- android:layout_marginEnd="16dp">-->
<include
android:id="@+id/layout_list_device"
android:layout_height="300dp"
android:layout_width="match_parent"
layout= "@layout/fragment_list_device_item" />
<!-- <include-->
<!-- android:id="@+id/layout_list_device"-->
<!-- android:layout_height="300dp"-->
<!-- android:layout_width="match_parent"-->
<!-- layout= "@layout/fragment_list_device_item"-->
<!-- />-->
<!-- </LinearLayout>-->
</LinearLayout>
<!-- <ImageView-->
<!-- android:id="@+id/img_bg_device_in_room"-->
......
......@@ -8,7 +8,7 @@
android:id="@+id/img_device"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_plug"
android:background="@drawable/img_plug"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="8dp"/>
......@@ -42,7 +42,7 @@
android:id="@+id/img_status_device"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_online_status"
android:background="@drawable/ic_online_status"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@id/tv_status_device"
app:layout_constraintBottom_toBottomOf="parent"
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/img_home_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_home_red"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="24dp"
android:layout_marginTop="18dp"
/>
<TextView
android:id="@+id/tv_name_smart_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Smart Home"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/black"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/img_home_red"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"/>
<ImageView
android:id="@+id/img_share_network"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_share_network"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="18dp"
android:layout_marginEnd="24dp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#CECECE"
app:layout_constraintTop_toBottomOf="@id/tv_name_smart_home"
android:layout_marginTop="16dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_name_smart_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#4E4E4E"
android:textStyle="bold" />
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment