Skip to content

Commit

Permalink
#6 added bottom sheet dialog with draft layout
Browse files Browse the repository at this point in the history
  • Loading branch information
nikol412 committed Mar 3, 2021
1 parent a86d3cd commit 72a0a76
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 36 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,7 @@ dependencies {
//Coordinator layout
'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
implementation 'com.google.android.material:material:1.2.1'

//Material Dialogs Core
implementation 'com.afollestad.material-dialogs:core:3.3.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.example.timetracker.di.modules.AppModule
import com.example.timetracker.di.modules.DatabaseModule
import com.example.timetracker.ui.base.BaseViewModel
import com.example.timetracker.ui.fragment.home.HomeViewModel
import com.example.timetracker.ui.fragment.home.createTask.CreateTaskBottomSheetDialogFragment
import com.example.timetracker.ui.fragment.home.createTask.CreateTaskBottomSheetDialogViewModel
import dagger.BindsInstance
import dagger.Component
import dagger.android.support.AndroidSupportInjectionModule
Expand Down Expand Up @@ -39,4 +41,6 @@ interface AppComponent {

fun inject(homeVM: HomeViewModel)

fun inject(createTaskBottomSheetDialogViewModel: CreateTaskBottomSheetDialogViewModel)

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.example.timetracker.R
import com.example.timetracker.databinding.FragmentHomeBinding
import com.example.timetracker.ui.base.BaseFragment
import com.example.timetracker.ui.base.BaseViewModel
import com.example.timetracker.ui.fragment.home.createTask.CreateTaskBottomSheetDialogFragment

class HomeFragment : BaseFragment() {

Expand All @@ -21,6 +23,10 @@ class HomeFragment : BaseFragment() {
lateinit var binding: FragmentHomeBinding
lateinit var adapter: ItemsAdapter

val createTaskFragment by lazy {
CreateTaskBottomSheetDialogFragment()
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -35,4 +41,12 @@ class HomeFragment : BaseFragment() {

return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.fabCreateCard.setOnClickListener {
createTaskFragment.show(childFragmentManager, "bottomSheet")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,7 @@ class HomeViewModel : BaseViewModel() {
lateinit var userRepository: UserRepository

var homeLabel = MutableLiveData<String>()
var items = mutableListOf(
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20
).map { it.toString() }
var items = (1..20).map { it.toString() }.toMutableList()

init {
App.appComponent?.inject(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.timetracker.ui.fragment.home.createTask

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.viewModels
import com.example.timetracker.R
import com.example.timetracker.databinding.FragmentCreateTaskBinding
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

class CreateTaskBottomSheetDialogFragment : BottomSheetDialogFragment() {

private val viewModel: CreateTaskBottomSheetDialogViewModel by viewModels()

fun layoutRes(): Int = R.layout.fragment_create_task

lateinit var binding: FragmentCreateTaskBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = DataBindingUtil.inflate(inflater, layoutRes(), container, false)
binding.vm = viewModel
binding.lifecycleOwner = this

binding.buttonCreateTask.setOnClickListener {

this.dismiss()
}

return binding.root
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.timetracker.ui.fragment.home.createTask

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.timetracker.App
import com.example.timetracker.ui.base.BaseViewModel

class CreateTaskBottomSheetDialogViewModel: BaseViewModel() {

val taskName = MutableLiveData("")
val taskDescription = MutableLiveData("")
val taskDate = MutableLiveData("")

init {
App.appComponent?.inject(this)
}
}
52 changes: 52 additions & 0 deletions app/src/main/res/layout/fragment_create_task.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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">

<data>
<variable
name="vm"
type="com.example.timetracker.ui.fragment.home.createTask.CreateTaskBottomSheetDialogViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.button.MaterialButton
android:id="@+id/button_create_task"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@android:drawable/ic_popup_sync"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<EditText
android:id="@+id/edittext_task_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/button_create_task"
android:layout_marginTop="10dp"
android:background="@color/colorPrimaryDark"
android:text="@={vm.taskName}"/>

<TextView
android:id="@+id/textview_task_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/edittext_task_name"
android:layout_marginTop="10dp"
android:background="@color/colorPrimaryDark"
android:text="@={vm.taskDate}"/>

<EditText
android:id="@+id/edittext_task_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/textview_task_date"
android:layout_marginTop="10dp"
android:background="@color/colorPrimaryDark"
android:text="@={vm.taskDescription}"/>


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
42 changes: 29 additions & 13 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,45 @@
type="com.example.timetracker.ui.fragment.home.HomeViewModel" />
</data>

<LinearLayout
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include layout="@layout/toolbar_my_day" />
android:layout_height="match_parent">

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

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_recycler_view"
<include layout="@layout/toolbar_my_day" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="20"
tools:listitem="@layout/home_item_row" />
</LinearLayout>
android:orientation="vertical">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="20"
tools:listitem="@layout/home_item_row" />
</LinearLayout>

</LinearLayout>
</LinearLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_create_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:src="@drawable/md_btn_selected"
app:tint="@android:color/white"
android:layout_margin="24dp"
android:layout_gravity="bottom|end"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

</layout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand Down

0 comments on commit 72a0a76

Please sign in to comment.