Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bignerdranch.android.pomodo

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.bignerdranch.android.pomodo", appContext.packageName)
}
}
31 changes: 31 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PomoDo"
tools:targetApi="31">

<activity android:name=".SplashActivity"
android:theme="@style/Theme.PomoDo.Splash"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


<activity android:name=".MainActivity" />

</application>


</manifest>
Binary file added src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.bignerdranch.android.pomodo.Adapters

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import androidx.recyclerview.widget.RecyclerView
import com.bignerdranch.android.pomodo.AddNewTask
import com.bignerdranch.android.pomodo.DatabaseHandler
import com.bignerdranch.android.pomodo.MainActivity
import com.bignerdranch.android.pomodo.Model.ToDoModel
import com.bignerdranch.android.pomodo.R

class ToDoAdapter(private val db: DatabaseHandler, private val activity: MainActivity) :
RecyclerView.Adapter<ToDoAdapter.ViewHolder>() {

private var todoList: MutableList<ToDoModel> = mutableListOf() // Change to MutableList

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val itemView = LayoutInflater.from(parent.context)
.inflate(R.layout.task_layout, parent, false) // Ensure task_layout exists in res/layout
return ViewHolder(itemView)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
db.openDatabase()

val item = todoList[position]
holder.task.text = item.task
holder.task.isChecked = toBoolean(item.status)
holder.task.setOnCheckedChangeListener { _, isChecked ->
db.updateStatus(item.id, if (isChecked) 1 else 0)
}
}

private fun toBoolean(n: Int): Boolean {
return n != 0
}

override fun getItemCount(): Int {
return todoList.size
}

fun getContext(): Context {
return activity
}

fun setTasks(todoList: List<ToDoModel>) {
this.todoList = todoList.toMutableList() // Ensure it's a MutableList
notifyDataSetChanged()
}

fun deleteItem(position: Int) {
val item = todoList[position]
db.deleteTask(item.id)
todoList.removeAt(position) // Now you can modify todoList directly
notifyItemRemoved(position)
}

fun editItem(position: Int) {
val item = todoList[position]
val bundle = Bundle().apply {
putInt("id", item.id)
putString("task", item.task)
}
val fragment = AddNewTask().apply { arguments = bundle }
// Ensure MainActivity extends FragmentActivity to use supportFragmentManager
fragment.show(activity.supportFragmentManager, AddNewTask.TAG)
}

class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val task: CheckBox = view.findViewById(R.id.todoCheckBox) // Ensure todoCheckBox exists in task_layout.xml
}
}
102 changes: 102 additions & 0 deletions src/main/java/com/bignerdranch/android/pomodo/AddNewTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.bignerdranch.android.pomodo


import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.Button
import android.widget.EditText
import androidx.core.content.ContextCompat
import androidx.core.widget.addTextChangedListener
import com.bignerdranch.android.pomodo.Model.ToDoModel
import com.google.android.material.bottomsheet.BottomSheetDialogFragment


class AddNewTask : BottomSheetDialogFragment() {

private lateinit var newTaskText: EditText
private lateinit var newTaskSaveButton: Button
private lateinit var db: DatabaseHandler

companion object {
const val TAG = "ActionBottomDialog"

fun newInstance(): AddNewTask {
return AddNewTask()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.DialogStyle) // Ensuring DialogStyle is referenced correctly
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.new_task, container, false)
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
return view
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

newTaskText = view.findViewById(R.id.newTaskText)
newTaskSaveButton = view.findViewById(R.id.newTaskButton)

var isUpdate = false
val bundle = arguments
if (bundle != null) {
isUpdate = true
val task = bundle.getString("task")
newTaskText.setText(task)
task?.let {
if (it.isNotEmpty()) {
newTaskSaveButton.setTextColor(
ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark)
)
}
}
}

db = DatabaseHandler(requireActivity())
db.openDatabase()

// Enable or disable the save button based on text input
newTaskText.addTextChangedListener { text ->
if (text.isNullOrEmpty()) {
newTaskSaveButton.isEnabled = false
newTaskSaveButton.setTextColor(ContextCompat.getColor(requireContext(), R.color.gray))
} else {
newTaskSaveButton.isEnabled = true
newTaskSaveButton.setTextColor(ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark))
}
}

newTaskSaveButton.setOnClickListener {
val text = newTaskText.text.toString()
if (isUpdate) {
db.updateTask(bundle?.getInt("id") ?: 0, text)
} else {
val task = ToDoModel().apply {
this.task = text // Correctly setting task value
this.status = 0 // Correctly setting the status
}
db.insertTask(task)
}
dismiss()
}
}

override fun onDismiss(dialog: DialogInterface) {
val activity = activity
if (activity is DialogCloseListener) {
activity.handleDialogClose(dialog)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bignerdranch.android.pomodo

import android.content.DialogInterface

interface DialogCloseListener {
fun handleDialogClose(dialog: DialogInterface)
}

Loading