Skip to content

Commit

Permalink
#6 added design for bottom nav dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nikol412 committed Mar 3, 2021
1 parent 72a0a76 commit 838b2ed
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.timetracker.ui.fragment.home.createTask

import android.app.DatePickerDialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -9,6 +10,7 @@ import androidx.fragment.app.viewModels
import com.example.timetracker.R
import com.example.timetracker.databinding.FragmentCreateTaskBinding
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import java.util.*

class CreateTaskBottomSheetDialogFragment : BottomSheetDialogFragment() {

Expand All @@ -18,6 +20,25 @@ class CreateTaskBottomSheetDialogFragment : BottomSheetDialogFragment() {

lateinit var binding: FragmentCreateTaskBinding

private val datePicker by lazy {
val calendar = Calendar.getInstance()
val datePicker = DatePickerDialog(
requireContext(),
dateListener,
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)
)
datePicker.datePicker.minDate = Calendar.getInstance().timeInMillis

return@lazy datePicker
}

val dateListener =
DatePickerDialog.OnDateSetListener { _, year, month, dayOfMonth ->
viewModel.taskDate.value = "$dayOfMonth/$month/$year"
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -27,11 +48,24 @@ class CreateTaskBottomSheetDialogFragment : BottomSheetDialogFragment() {
binding.vm = viewModel
binding.lifecycleOwner = this

binding.buttonCreateTask.setOnClickListener {

this.dismiss()
}
subscribeViewModelVariables()

return binding.root
}

fun subscribeViewModelVariables() {
viewModel.event.observe(viewLifecycleOwner, { event ->
when (event) {
CreateTaskEvent.ADD_TASK -> this.dismiss()
CreateTaskEvent.DATE -> showDatePicker()
}
})
}


private fun showDatePicker() {
datePicker.show()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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.common.live.SingleLiveEvent
import com.example.timetracker.ui.base.BaseViewModel

class CreateTaskBottomSheetDialogViewModel: BaseViewModel() {
Expand All @@ -11,7 +12,21 @@ class CreateTaskBottomSheetDialogViewModel: BaseViewModel() {
val taskDescription = MutableLiveData("")
val taskDate = MutableLiveData("")

val event = SingleLiveEvent<CreateTaskEvent>()

init {
App.appComponent?.inject(this)
}

fun onCreateTaskClick() {
event.value = CreateTaskEvent.ADD_TASK
}

fun onDateClick() {
event.value = CreateTaskEvent.DATE
}
}

enum class CreateTaskEvent {
ADD_TASK, DATE
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_add.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
20 changes: 14 additions & 6 deletions app/src/main/res/layout/fragment_create_task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_marginHorizontal="16dp"
android:paddingBottom="40dp">

<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"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/ic_add"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
app:layout_constraintEnd_toEndOf="parent"
android:onClick="@{() -> vm.onCreateTaskClick()}"/>

<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:maxLines="1"
android:background="@color/colorPrimaryDark"
android:text="@={vm.taskName}"/>

Expand All @@ -36,14 +40,18 @@
app:layout_constraintTop_toBottomOf="@+id/edittext_task_name"
android:layout_marginTop="10dp"
android:background="@color/colorPrimaryDark"
android:text="@={vm.taskDate}"/>
android:text="@={vm.taskDate}"
android:maxLines="1"
android:onClick="@{() -> vm.onDateClick()}"/>

<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:lines="4"
android:maxLines="10"
android:background="@color/colorPrimaryDark"
android:text="@={vm.taskDescription}"/>

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_marginBottom="?actionBarSize">

<LinearLayout
android:layout_width="match_parent"
Expand Down
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.MaterialComponents.NoActionBar">
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand Down

0 comments on commit 838b2ed

Please sign in to comment.