-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f951c04
commit 53d864b
Showing
26 changed files
with
322 additions
and
825 deletions.
There are no files selected for viewing
112 changes: 72 additions & 40 deletions
112
app/src/main/java/com/example/HealthyMode/Adapter/Adapter_todo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,72 @@ | ||
//package com.example.HealthyMode.Adapter | ||
// | ||
//import android.view.LayoutInflater | ||
//import android.view.ViewGroup | ||
//import androidx.paging.PagingDataAdapter | ||
//import androidx.recyclerview.widget.DiffUtil | ||
//import androidx.recyclerview.widget.RecyclerView | ||
//import com.example.HealthyMode.TodoDatabase.Todo | ||
//import com.example.HealthyMode.databinding.TodoItemBinding | ||
// | ||
//class Adapter_todo: PagingDataAdapter<Todo, Adapter_todo.MainViewHolder>(DIFF_CALLBACK) { | ||
// | ||
// companion object { | ||
// val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Todo>() { | ||
// override fun areItemsTheSame(oldItem: Todo, newItem: Todo): Boolean = | ||
// oldItem.id == newItem.id | ||
// | ||
// override fun areContentsTheSame(oldItem: Todo, newItem: Todo): Boolean = | ||
// oldItem == newItem | ||
// } | ||
// } | ||
// inner class MainViewHolder(val binding: TodoItemBinding) : RecyclerView.ViewHolder(binding.root) | ||
// | ||
// override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainViewHolder { | ||
// return MainViewHolder( | ||
// TodoItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
// ) | ||
// } | ||
// override fun onBindViewHolder(holder: MainViewHolder, position: Int) { | ||
// val item = getItem(position) | ||
// | ||
// holder.binding.apply { | ||
// desc.text=item!!.Desc.toString() | ||
// sd.text=item.Start_date.toString() | ||
// st.text=item.Start_time.toString() | ||
// ed.text=item.End_date.toString() | ||
// et.text=item.End_time.toString() | ||
// } | ||
// } | ||
//} | ||
package com.codinginflow.mvvmtodo.ui.tasks | ||
|
||
import android.graphics.Paint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import android.widget.CheckBox | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.example.HealthyMode.TodoDatabase.Todo | ||
import com.example.HealthyMode.databinding.TodoItemBinding | ||
|
||
class Adapter_todo(private val listener: OnItemClickListener) : | ||
ListAdapter<Todo, Adapter_todo.TasksViewHolder>(DiffUtill()) { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TasksViewHolder { | ||
val binding = TodoItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return TasksViewHolder(binding) | ||
} | ||
override fun onBindViewHolder(holder: TasksViewHolder, position: Int) { | ||
val currentItem = getItem(position) | ||
holder.bind(currentItem) | ||
} | ||
inner class TasksViewHolder(private val binding: TodoItemBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
init { | ||
binding.apply { | ||
status.setOnClickListener { | ||
val position = adapterPosition | ||
if (position != RecyclerView.NO_POSITION) { | ||
val task = getItem(position) | ||
listener.onCheckBoxClick(task, status.isChecked) | ||
check(status,desc) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun bind(task: Todo) { | ||
binding.apply { | ||
status.isChecked=task.status | ||
desc.text = task.Desc | ||
sd.text=task.Start_date | ||
st.text=task.Start_time | ||
ed.text=task.End_date | ||
et.text=task.End_time | ||
check(status,desc) | ||
} | ||
} | ||
} | ||
private fun check(status:CheckBox,desc:TextView) | ||
{ | ||
if (status.isChecked) { | ||
desc.paintFlags = | ||
desc.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG | ||
} else { | ||
desc.paintFlags = | ||
desc.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() | ||
} | ||
} | ||
interface OnItemClickListener { | ||
fun onCheckBoxClick(task: Todo, isChecked: Boolean) | ||
} | ||
|
||
class DiffUtill : DiffUtil.ItemCallback<Todo>() { | ||
override fun areItemsTheSame(oldItem: Todo, newItem: Todo) = | ||
oldItem.id == newItem.id | ||
override fun areContentsTheSame(oldItem: Todo, newItem: Todo) = | ||
oldItem == newItem | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
app/src/main/java/com/example/HealthyMode/Repository/TodoRepository.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/example/HealthyMode/TodoDatabase/Repository/TodoRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.HealthyMode.TodoDatabase.Repository | ||
|
||
import androidx.lifecycle.LiveData | ||
import com.example.HealthyMode.TodoDatabase.Todo | ||
interface TodoRepository{ | ||
suspend fun insertTodo(todo: Todo) | ||
suspend fun deleteTodo(todo:Todo) | ||
suspend fun updateTodo(todo:Todo) | ||
suspend fun getTodoById(id:Int):Todo? | ||
fun getList(): LiveData<List<Todo>> | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/example/HealthyMode/TodoDatabase/Repository/TodoRepositoryImp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example.HealthyMode.TodoDatabase.Repository | ||
|
||
import androidx.lifecycle.LiveData | ||
import com.example.HealthyMode.TodoDatabase.Todo | ||
import com.example.HealthyMode.TodoDatabase.TodoDao | ||
|
||
class TodoRepositoryImp(val todoDao: TodoDao):TodoRepository{ | ||
override suspend fun insertTodo(todo: Todo) { | ||
todoDao.insertTodo(todo) | ||
} | ||
|
||
override suspend fun deleteTodo(todo: Todo) { | ||
todoDao.deleteTodo(todo) | ||
} | ||
|
||
override suspend fun updateTodo(todo: Todo) { | ||
todoDao.updateTodo(todo) | ||
} | ||
|
||
override suspend fun getTodoById(id: Int): Todo? { | ||
return todoDao.getTodoById(id) | ||
} | ||
|
||
override fun getList(): LiveData<List<Todo>> { | ||
return todoDao.getTodo() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
app/src/main/java/com/example/HealthyMode/TodoDatabase/TodoDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,9 @@ | ||
package com.example.HealthyMode.TodoDatabase | ||
|
||
import android.content.Context | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
|
||
@Database(entities = [Todo::class], version = 3) | ||
abstract class TodoDatabase:RoomDatabase() { | ||
abstract fun todoDao():TodoDao | ||
|
||
companion object{ | ||
@Volatile | ||
private var INSTANCE:TodoDatabase?=null | ||
fun getDatabase(context: Context):TodoDatabase{ | ||
if (INSTANCE==null) | ||
{ | ||
synchronized(this){ | ||
INSTANCE=Room.databaseBuilder( | ||
context,TodoDatabase::class.java,"TODO" | ||
).createFromAsset("Todo.db").build() | ||
} | ||
} | ||
return INSTANCE!! | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.