Skip to content

Commit

Permalink
complete plans section
Browse files Browse the repository at this point in the history
  • Loading branch information
subhajit4980 committed Apr 3, 2023
1 parent f951c04 commit 53d864b
Show file tree
Hide file tree
Showing 26 changed files with 322 additions and 825 deletions.
112 changes: 72 additions & 40 deletions app/src/main/java/com/example/HealthyMode/Adapter/Adapter_todo.kt
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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ class FoodNameAdapter(val foodlist:ArrayList<Nutrient>):
}
}

// override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
// with(holder){
// with(foodlist[position]){
// binding.text = this.name
// binding.tvExp.text = this.exp
// }
// }
// holder.apply {
// binding.food_name.text=foodlist[position].foodName
// cal.text=foodlist[position].calories
//
// }
//
// }
private val touchHelper=object :ItemTouchHelper.SimpleCallback(
0,ItemTouchHelper.RIGHT or ItemTouchHelper.LEFT
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import com.example.HealthyMode.Repository.TodoRepository
import com.example.HealthyMode.TodoDatabase.TodoDatabase
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.Source
import dagger.hilt.android.HiltAndroidApp
Expand All @@ -25,7 +23,4 @@ class HMApplicaton : Application() {
notificationManager.createNotificationChannel(channel)
}
}

private val database by lazy { TodoDatabase.getDatabase(this@HMApplicaton) }
val repository by lazy { TodoRepository(database.todoDao()) }
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class MyService : Service(), SensorEventListener {
.setOngoing(true)
.setSilent(true)
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager!!.notify(1, notification!!.build())
startForeground(1, notification!!.build())
notificationManager.notify(1, notification.build())
startForeground(1, notification.build())
}

private fun stop() {
Expand Down
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>>
}
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()
}
}

10 changes: 6 additions & 4 deletions app/src/main/java/com/example/HealthyMode/TodoDatabase/Todo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import kotlinx.android.parcel.Parcelize

@Parcelize
@Entity(tableName = "TODO")
data class Todo (
@PrimaryKey(autoGenerate = true)
data class Todo(
@ColumnInfo(name="status")
val status:Int,
val status:Boolean,
@ColumnInfo(name="Desc")
val Desc:String,
@ColumnInfo(name="Start_date")
Expand All @@ -23,5 +22,8 @@ data class Todo (
@ColumnInfo(name="End_time")
val End_time:String,
@ColumnInfo(name="reminder")
val reminder: String
val reminder: String,
@ColumnInfo(name="time")
val time: Long,
@PrimaryKey(autoGenerate = true) val id:Int=0
):Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import androidx.room.*

@Dao
interface TodoDao {
@Query("SELECT * from Todo")
@Query("SELECT * from Todo ORDER BY time ASC,status DESC")
fun getTodo():LiveData<List<Todo>>

@Insert
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertTodo(todo: Todo)
@Delete
suspend fun deleteTodo(todo: Todo)
@Update
suspend fun updateTodo(todo: Todo)
@Query("SELECT * from Todo WHERE id= :id")
suspend fun getTodoById(id: Int): Todo?

}
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!!
}
}
}
11 changes: 6 additions & 5 deletions app/src/main/java/com/example/HealthyMode/UI/Home/Home_screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.DocumentReference
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
import dagger.hilt.android.AndroidEntryPoint
import net.yslibrary.android.keyboardvisibilityevent.KeyboardVisibilityEvent
import java.util.*

@AndroidEntryPoint
@Suppress("UNREACHABLE_CODE")
class Home_screen : AppCompatActivity() {
@RequiresApi(VERSION_CODES.TIRAMISU)
Expand All @@ -55,13 +56,14 @@ class Home_screen : AppCompatActivity() {
super.onCreate(savedInstanceState)
binding = ActivityHomeScreenBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.buttonnav.visibility = View.VISIBLE
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
checkpermission()
binding.buttonnav.visibility = View.VISIBLE
val Home_fragment = Home_fragment()
val plansFragment = Plans_fragment()
val ProfileFragment = profile_fragment()
val Weight = AddWeight()
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
val Stats=Stats()
userDitails.collection("Weight track").get().addOnSuccessListener { snapshot ->
if (snapshot.isEmpty) {
binding.buttonnav.visibility = View.GONE
Expand All @@ -83,13 +85,12 @@ class Home_screen : AppCompatActivity() {
}
binding.buttonnav.visibility = View.VISIBLE
buttonnav=binding.buttonnav
// Plans_fragment().hide(buttonnav)
binding.buttonnav.setOnNavigationItemSelectedListener {
when (it.itemId) {
R.id.home_t -> makeCurrentFrag(Home_fragment)
R.id.plan -> makeCurrentFrag(plansFragment)
R.id.profile -> makeCurrentFrag(ProfileFragment)
R.id.stats -> makeCurrentFrag(Stats())
R.id.stats -> makeCurrentFrag(Stats)

}
true
Expand Down
Loading

0 comments on commit 53d864b

Please sign in to comment.