ScheduleAndCalendar

patient
Clogon 2023-07-08 16:55:39 +03:00
parent 353453b58e
commit 6b493a4ebb
17 changed files with 440 additions and 97 deletions

1
.idea/.name 100644
View File

@ -0,0 +1 @@
Rehabilitation

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="17" />
<bytecodeTargetLevel target="11" />
</component>
</project>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

6
.idea/vcs.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,6 +1,8 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}
android {
@ -36,7 +38,9 @@ android {
}
dependencies {
implementation 'androidx.room:room-ktx:2.5.2'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
kapt 'androidx.room:room-compiler:2.5.2'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'

View File

@ -1,4 +1,24 @@
package com.example.rehabilitation.Baza
class TaskItem {
import android.content.Context
import androidx.core.content.ContextCompat
import com.example.rehabilitation.R
import java.time.LocalDate
import java.time.LocalTime
import java.util.*
class TaskItem(
var name:String,
var desc:String,
var dueTime: LocalTime?,
var completedDate:LocalDate?,
var id: UUID = UUID.randomUUID(),
) {
fun isCompleted() = completedDate !=null
fun imageResource(): Int = if(isCompleted()) R.drawable.check_24 else R.drawable.unchecked_24
fun imageColor(context:Context): Int = if(isCompleted()) purple(context) else black(context)
private fun purple(context:Context) = ContextCompat.getColor(context,R.color.purple_500)
private fun black(context:Context) = ContextCompat.getColor(context,R.color.black)
}

View File

@ -1,4 +1,25 @@
package com.example.rehabilitation.Baza
class TaskItemAdapter {
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.rehabilitation.databinding.TaskItemBinding
class TaskItemAdapter(
private val taskItems: List<TaskItem>,
private val clickListener: TaskItemClickListener
):RecyclerView.Adapter<TaskItemViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TaskItemViewHolder {
val from = LayoutInflater.from(parent.context)
val binding = TaskItemBinding.inflate(from,parent,false)
return TaskItemViewHolder(parent.context, binding, clickListener)
}
override fun getItemCount(): Int = taskItems.size
override fun onBindViewHolder(holder: TaskItemViewHolder, position: Int) {
holder.bindTaskItem(taskItems[position])
}
}

View File

@ -1,4 +1,7 @@
package com.example.rehabilitation.Baza
interface TaskItemClickListener {
fun editTaskItem(taskitem:TaskItem)
fun completeTaskItem(taskitem:TaskItem)
}

View File

@ -1,4 +1,41 @@
package com.example.rehabilitation.Baza
class TaskItemViewHolder {
import android.content.Context
import android.graphics.Paint
import androidx.recyclerview.widget.RecyclerView
import com.example.rehabilitation.databinding.TaskItemBinding
import java.time.format.DateTimeFormatter
class TaskItemViewHolder(
private val context: Context,
private val binding: TaskItemBinding,
private val clickListener: TaskItemClickListener
):RecyclerView.ViewHolder(binding.root) {
private val timeFormat = DateTimeFormatter.ofPattern("HH:mm")
fun bindTaskItem(taskItem:TaskItem){
binding.txtName.text = taskItem.name
//binding.txtDesc.text = taskItem.desc
if(taskItem.isCompleted()){
binding.txtName.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG
binding.txtTime.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG
}
binding.btnComplete.setBackgroundResource(taskItem.imageResource())
binding.btnComplete.setColorFilter(taskItem.imageColor(context))
binding.btnComplete.setOnClickListener{
clickListener.completeTaskItem(taskItem)
}
binding.taskCellContainers.setOnClickListener{
clickListener.editTaskItem(taskItem)
}
if(taskItem.dueTime != null){
binding.txtTime.text = timeFormat.format(taskItem.dueTime)
}
else{
binding.txtTime.text = ""
}
}
}

View File

@ -1,4 +1,44 @@
package com.example.rehabilitation.Baza
class TaskViewModel {
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import java.time.LocalDate
import java.time.LocalTime
import java.util.UUID
class TaskViewModel:ViewModel() {
var taskItems = MutableLiveData<MutableList<TaskItem>>()
init{
taskItems.value = mutableListOf()
}
//Добавление
fun addTaskItem(newTask:TaskItem){
val list = taskItems.value
list!!.add(newTask)
taskItems.postValue(list!!)
}
//Обновление
fun updateTaskItem(id: UUID, name:String, desc:String, dueTime: LocalTime?){
val list = taskItems.value
val task = list!!.find{it.id == id}!!
task.name = name
task.desc = desc
task.dueTime = dueTime
taskItems.postValue(list!!)
}
//Вывод
fun setCompleted(taskItem:TaskItem){
val list = taskItems.value
val task = list!!.find{it.id == taskItem.id}!!
if(task.completedDate == null){
task.completedDate = LocalDate.now()
}
taskItems.postValue(list!!)
}
}

View File

@ -1,4 +1,14 @@
package com.example.rehabilitation.db
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
@Dao
interface Dao {
@Insert
fun insertItem(item:Item)
@Query("SELECT * FROM items")
fun getAllItems(): Flow<List<Item>>
}

View File

@ -1,3 +1,16 @@
package com.example.rehabilitation.db
data class Item()
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "items")
data class Item(
@PrimaryKey(autoGenerate = true)
var id:Int? = null,
@ColumnInfo(name = "name")
var name:String,
@ColumnInfo(name = "price")
var price:String,
)

View File

@ -1,4 +1,20 @@
package com.example.rehabilitation.db
class MainDB {
import androidx.room.Room
import androidx.room.RoomDatabase
import android.content.Context
import androidx.room.Database
@Database(entities = [Item::class], version = 1)
abstract class MainDB: RoomDatabase() {
abstract fun getDao(): Dao
companion object{
fun getDB(context: Context):MainDB{
return Room.databaseBuilder(
context.applicationContext,
MainDB::class.java,
"tests.db"
).build()
}
}
}

View File

@ -5,12 +5,19 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.rehabilitation.R
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.rehabilitation.Baza.TaskItem
import com.example.rehabilitation.Baza.TaskItemAdapter
import com.example.rehabilitation.Baza.TaskItemClickListener
import com.example.rehabilitation.Baza.TaskViewModel
import com.example.rehabilitation.databinding.FragmentSceduleBinding
class SceduleFragment : Fragment() {
class SceduleFragment(var taskItem: TaskItem?) : Fragment(), TaskItemClickListener {
private lateinit var binding: FragmentSceduleBinding
private lateinit var taskViewModel: TaskViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
@ -19,7 +26,84 @@ class SceduleFragment : Fragment() {
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
//Закрытие карточки определенного дня
binding.btnExitCardSport.setOnClickListener {
binding.CLCardSport.visibility = View.GONE
binding.CLListSport.visibility = View.VISIBLE
binding.txtNameCard.setText("")
binding.txtDescCard.setText("")
}
if(taskItem != null){
binding.CLCardSport.visibility = View.VISIBLE
binding.CLListSport.visibility = View.GONE
binding.txtNameCard.text = taskItem!!.name
binding.txtDescCard.text = taskItem!!.desc
}
else{
binding.CLCardSport.visibility = View.GONE
binding.CLListSport.visibility = View.VISIBLE
}
taskViewModel = ViewModelProvider(requireActivity()).get(TaskViewModel::class.java)
binding.btnSave.setOnClickListener {
saveAction()
}
setRecycleView()
}
private fun setRecycleView() {
taskViewModel.taskItems.observe(requireActivity()){
binding.todoListRecycleView.apply {
layoutManager = LinearLayoutManager(activity?.applicationContext)
adapter = TaskItemAdapter(it,this@SceduleFragment)
}
}
}
private fun saveAction() {
val name = binding.edName.text.toString()
val desc = binding.edDesc.text.toString()
if(taskItem == null){
val newTask = TaskItem(name,desc,null,null)
taskViewModel.addTaskItem(newTask)
}
else{
taskViewModel.updateTaskItem(taskItem!!.id,name,desc,null)
}
binding.edName.setText("")
binding.edDesc.setText("")
}
override fun onResume() {
super.onResume()
}
override fun onDestroy() {
super.onDestroy()
}
companion object {
fun newInstance() = SceduleFragment()
fun newInstance() = SceduleFragment(null)
}
override fun editTaskItem(taskitem: TaskItem) {
binding.CLCardSport.visibility = View.VISIBLE
binding.CLListSport.visibility = View.GONE
binding.txtNameCard.setText(taskitem.name)
binding.txtDescCard.setText(taskitem.desc)
}
override fun completeTaskItem(taskitem: TaskItem) {
taskItem?.let { taskViewModel.setCompleted(it) }
}
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M16.59,7.58L10,14.17l-3.59,-3.58L5,12l5,5 8,-8zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
</vector>

View File

@ -1,110 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.User.SceduleFragment">
<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/CLListSport"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:visibility="visible">
<EditText
android:id="@+id/edDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/btnSave"
app:layout_constraintEnd_toEndOf="@+id/edName"
app:layout_constraintStart_toStartOf="@+id/edName" />
<EditText
android:id="@+id/edName"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/edDesc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:id="@+id/btnSave"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button" />
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/button7"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/todoListRecycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="@+id/edName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button17"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/button12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/CLCardSport"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<Button
android:id="@+id/button16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/button18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/txtTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="32dp"
android:gravity="center"
android:text="Название"
android:textColor="#000000"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btnExitCardSport"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/txtNameCard"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="24dp"
android:text="1111"
android:textColor="#000000"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtTitle" />
<Button
android:id="@+id/button15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/txtDescCard"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="32dp"
android:text="22222"
android:textColor="#000000"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/txtNameCard"
app:layout_constraintStart_toStartOf="@+id/txtNameCard"
app:layout_constraintTop_toBottomOf="@+id/txtNameCard" />
<Button
android:id="@+id/button19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/btnExitCardSport"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/door_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/button13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</androidx.cardview.widget.CardView>
<Button
android:id="@+id/button11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="409dp"
android:layout_height="729dp"
android:visibility="gone"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,6 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/taskCellContainers"
android:layout_width="match_parent"
android:layout_height="90dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/btnComplete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:background="@drawable/unchecked_24"
android:backgroundTint="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txtName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/btnComplete"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txtTime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="@+id/txtName"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/txtName"
app:layout_constraintTop_toBottomOf="@+id/txtName" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>