Skip to content

Commit

Permalink
Merge pull request #13 from Adaltino/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Adaltino authored Jun 29, 2023
2 parents db311b7 + 5cf6492 commit 134a4d0
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 1 deletion.
51 changes: 51 additions & 0 deletions app/src/main/java/tcc/timezen/database/DBTimezen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,57 @@ class DBTimezen(context: Context) :
db.close()
}

fun getFilterPlans(category: String, level: String): List<Plan> {
val db = readableDatabase
val plans = mutableListOf<Plan>()
val projection = arrayOf("pla_name", "pla_work", "pla_break", "pla_task", "Category.cat_name", "ImportanceLevel.lvl_name")

var selection: String? = null
var selectionArgs: Array<String>? = null
if (!category.isEmpty() && level.isEmpty()) {
selection = "Category.cat_name = ?"
selectionArgs = arrayOf(category)
} else if (category.isEmpty() && !level.isEmpty()) {
selection = "ImportanceLevel.lvl_name = ?"
selectionArgs = arrayOf(level)
} else if (!category.isEmpty() && !level.isEmpty()) {
selection = "Category.cat_name = ? AND ImportanceLevel.lvl_name = ?"
selectionArgs = arrayOf(category, level)
}

val join = "Plan " +
"LEFT JOIN Category ON Plan.pla_cat_id = Category.cat_id LEFT JOIN ImportanceLevel ON Plan.pla_lvl_id = ImportanceLevel.lvl_id"

val cursor = db.query(join, projection, selection, selectionArgs, null, null, null)
if (cursor.moveToFirst()) {
do {
val name = cursor.getColumnIndex("pla_name")
val workTime = cursor.getColumnIndex("pla_work")
val breakTime = cursor.getColumnIndex("pla_break")
val task = cursor.getColumnIndex("pla_task")
val catName = cursor.getColumnIndex("cat_name")
val lvlName = cursor.getColumnIndex("lvl_name")

val namePlan = cursor.getString(name)
val workPlan = cursor.getLong(workTime)
val breakPlan = cursor.getLong(breakTime)
val taskPlan = cursor.getInt(task)
val catPlan = cursor.getString(catName)
val lvlPlan = cursor.getString(lvlName)

plans.add(Plan(
namePlan,
PomodoroTimer(workPlan, breakPlan, taskPlan),
catPlan,
lvlPlan
))
} while (cursor.moveToNext())
}
cursor.close()
db.close()
return plans
}

fun reset() {
val db = writableDatabase
sqlDropTables.forEach {
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/tcc/timezen/fragments/ListPlanFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import tcc.timezen.R
import tcc.timezen.activities.FormPlanActivity
import tcc.timezen.database.DBTimezen
import tcc.timezen.databinding.FragmentListPlanBinding
Expand All @@ -19,6 +22,8 @@ class ListPlanFragment(
private lateinit var mBinding: FragmentListPlanBinding
private lateinit var dbTimezen: DBTimezen

private var isShowingFilter = false

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -30,6 +35,35 @@ class ListPlanFragment(
startActivity(intent)
}

dbTimezen = DBTimezen(requireContext())
val adapterCat = ArrayAdapter(requireContext(), R.layout.item_dropdown, dbTimezen.getCategoryNames())
val adapterLvl = ArrayAdapter(requireContext(), R.layout.item_dropdown, dbTimezen.getImportanceLevelNames())

mBinding.autoCompleteTextViewCategoryPlan.setAdapter(adapterCat)
mBinding.autoCompleteTextViewImportanceLevelPlan.setAdapter(adapterLvl)

mBinding.buttonFilter.setOnClickListener {
isShowingFilter = !isShowingFilter
if (isShowingFilter) {
mBinding.textInputLayoutCategoryPlan.visibility = View.VISIBLE
mBinding.textInputLayoutImportanceLevelPlan.visibility = View.VISIBLE

mBinding.buttonFilter.text = "OK"
} else {
val category = mBinding.autoCompleteTextViewCategoryPlan.text.toString()
val level = mBinding.autoCompleteTextViewImportanceLevelPlan.text.toString()

Toast.makeText(requireContext(), "${category}, ${level}", Toast.LENGTH_SHORT).show()

val newAdapter = PlanRecyclerViewAdapter(dbTimezen.getFilterPlans(category, level), itemViewClickListener)
mBinding.recyclerViewListPlan.adapter = newAdapter

mBinding.textInputLayoutCategoryPlan.visibility = View.GONE
mBinding.textInputLayoutImportanceLevelPlan.visibility = View.GONE
mBinding.buttonFilter.text = "Filtrar"
}
}

return mBinding.root
}

Expand All @@ -41,15 +75,18 @@ class ListPlanFragment(
if (dbTimezen.hasPlan()) {
mBinding.textViewTitleListPlan.visibility = View.GONE
mBinding.recyclerViewListPlan.visibility = View.VISIBLE
mBinding.buttonFilter.visibility = View.VISIBLE
mBinding.ivTzLogo.visibility = View.GONE

val adapter = PlanRecyclerViewAdapter(dbTimezen.getPlanList(), itemViewClickListener)
mBinding.recyclerViewListPlan.adapter = adapter

val layoutManager = LinearLayoutManager(requireContext())
mBinding.recyclerViewListPlan.layoutManager = layoutManager

} else {
mBinding.recyclerViewListPlan.visibility = View.GONE
mBinding.buttonFilter.visibility = View.GONE
mBinding.textViewTitleListPlan.visibility = View.VISIBLE
mBinding.ivTzLogo.visibility = View.VISIBLE
}
Expand Down
57 changes: 56 additions & 1 deletion app/src/main/res/layout/fragment_list_plan.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,67 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout_category_plan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_normal"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:hint="Categoria do Plano"
app:layout_constraintStart_toStartOf="parent"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">

<AutoCompleteTextView
android:id="@+id/autoCompleteTextView_category_plan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
tools:ignore="LabelFor" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout_importanceLevel_plan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_normal"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/textInputLayout_category_plan"
app:layout_constraintEnd_toEndOf="parent"
android:hint="Nível de Importância do Plano"
app:layout_constraintStart_toStartOf="parent"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">

<AutoCompleteTextView
android:id="@+id/autoCompleteTextView_importanceLevel_plan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
tools:ignore="LabelFor" />

</com.google.android.material.textfield.TextInputLayout>

<Button
android:id="@+id/button_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_normal"
android:text="Filtrar"
android:visibility="gone"
android:textSize="@dimen/font_larger"
android:backgroundTint="@color/blue_500"
app:layout_constraintTop_toBottomOf="@id/textInputLayout_importanceLevel_plan"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView_list_plan"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/button_filter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down

0 comments on commit 134a4d0

Please sign in to comment.