diff --git a/app/build.gradle b/app/build.gradle index bc893d3..22b677c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } \ No newline at end of file diff --git a/app/src/main/java/com/example/timetracker/di/components/AppComponent.kt b/app/src/main/java/com/example/timetracker/di/components/AppComponent.kt index fc0595d..a7c5afa 100644 --- a/app/src/main/java/com/example/timetracker/di/components/AppComponent.kt +++ b/app/src/main/java/com/example/timetracker/di/components/AppComponent.kt @@ -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 @@ -39,4 +41,6 @@ interface AppComponent { fun inject(homeVM: HomeViewModel) + fun inject(createTaskBottomSheetDialogViewModel: CreateTaskBottomSheetDialogViewModel) + } \ No newline at end of file diff --git a/app/src/main/java/com/example/timetracker/ui/fragment/home/HomeFragment.kt b/app/src/main/java/com/example/timetracker/ui/fragment/home/HomeFragment.kt index a541c79..36bdcf2 100644 --- a/app/src/main/java/com/example/timetracker/ui/fragment/home/HomeFragment.kt +++ b/app/src/main/java/com/example/timetracker/ui/fragment/home/HomeFragment.kt @@ -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() { @@ -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?, @@ -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") + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/timetracker/ui/fragment/home/HomeViewModel.kt b/app/src/main/java/com/example/timetracker/ui/fragment/home/HomeViewModel.kt index 5983fc2..96334b5 100644 --- a/app/src/main/java/com/example/timetracker/ui/fragment/home/HomeViewModel.kt +++ b/app/src/main/java/com/example/timetracker/ui/fragment/home/HomeViewModel.kt @@ -13,28 +13,7 @@ class HomeViewModel : BaseViewModel() { lateinit var userRepository: UserRepository var homeLabel = MutableLiveData() - 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) diff --git a/app/src/main/java/com/example/timetracker/ui/fragment/home/createTask/CreateTaskBottomSheetDialogFragment.kt b/app/src/main/java/com/example/timetracker/ui/fragment/home/createTask/CreateTaskBottomSheetDialogFragment.kt new file mode 100644 index 0000000..07c11b3 --- /dev/null +++ b/app/src/main/java/com/example/timetracker/ui/fragment/home/createTask/CreateTaskBottomSheetDialogFragment.kt @@ -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 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/timetracker/ui/fragment/home/createTask/CreateTaskBottomSheetDialogViewModel.kt b/app/src/main/java/com/example/timetracker/ui/fragment/home/createTask/CreateTaskBottomSheetDialogViewModel.kt new file mode 100644 index 0000000..8e04b61 --- /dev/null +++ b/app/src/main/java/com/example/timetracker/ui/fragment/home/createTask/CreateTaskBottomSheetDialogViewModel.kt @@ -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) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_create_task.xml b/app/src/main/res/layout/fragment_create_task.xml new file mode 100644 index 0000000..c77d247 --- /dev/null +++ b/app/src/main/res/layout/fragment_create_task.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index e022a7e..47fc982 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -10,29 +10,45 @@ type="com.example.timetracker.ui.fragment.home.HomeViewModel" /> - - - + android:layout_height="match_parent"> - + + - + android:orientation="vertical"> + + + - + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 4e557e4..f2c7792 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,6 +1,6 @@ -