Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add daily goals funcionality #331

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Expand Up @@ -20,6 +20,9 @@ class Label(
@ColumnInfo(defaultValue = "")
var title: String,

@ColumnInfo(defaultValue = "0")
var timeDailyGoal: Int,

@ColumnInfo(defaultValue = "0")
var colorId: Int) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ interface LabelDao {
@Query("update Label SET colorId = :colorId WHERE title = :title")
suspend fun editLabelColor(title: String, colorId: Int)

@Query("update Label SET timeDailyGoal = :timeDailyGoal WHERE title = :title")
suspend fun editLabelGoal(title: String, timeDailyGoal: Int)

@Query("update Label SET `order` = :order WHERE title = :title")
suspend fun editLabelOrder(title: String, order: Int)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,23 @@ class AddEditLabelActivity : AppCompatActivity(), OnEditLabelListener {
viewModel.editLabelName(label, newLabel)
val crtLabel = preferenceHelper.currentSessionLabel
if (crtLabel.title == label) {
preferenceHelper.currentSessionLabel = Label(newLabel, crtLabel.colorId)
preferenceHelper.currentSessionLabel = Label(newLabel, crtLabel.colorId, crtLabel.timeDailyGoal)
}
}

override fun onEditColor(label: String, newColor: Int) {
viewModel.editLabelColor(label, newColor)
val crtLabel = preferenceHelper.currentSessionLabel
if (crtLabel.title != "" && crtLabel.title == label) {
preferenceHelper.currentSessionLabel = Label(label, newColor)
preferenceHelper.currentSessionLabel = Label(label, newColor, crtLabel.timeDailyGoal)
}
}

override fun onEditTimeGoal(label: String, newTimeGoal: Int) {
viewModel.editLabelGoal(label, newTimeGoal)
val crtLabel = preferenceHelper.currentSessionLabel
if (crtLabel.title != "" && crtLabel.title == label) {
preferenceHelper.currentSessionLabel = Label(label, crtLabel.colorId, newTimeGoal)
}
}

Expand All @@ -188,7 +196,9 @@ class AddEditLabelActivity : AppCompatActivity(), OnEditLabelListener {
if (label.archived && crtLabel.title != "" && crtLabel.title == label.title) {
currentSessionManager.currentSession.setLabel("")
preferenceHelper.currentSessionLabel = Label(
"", ThemeHelper.getColor(
"",
0,
ThemeHelper.getColor(
this,
ThemeHelper.COLOR_INDEX_UNLABELED
)
Expand Down Expand Up @@ -245,7 +255,9 @@ class AddEditLabelActivity : AppCompatActivity(), OnEditLabelListener {
// the label attached to the current session was deleted
if (label.title == preferenceHelper.currentSessionLabel.title) {
preferenceHelper.currentSessionLabel = Label(
"", ThemeHelper.getColor(
"",
0,
ThemeHelper.getColor(
this,
ThemeHelper.COLOR_INDEX_UNLABELED
)
Expand Down Expand Up @@ -276,14 +288,16 @@ class AddEditLabelActivity : AppCompatActivity(), OnEditLabelListener {

private fun addLabel() {
labelToAdd =
Label(addLabelView.text.toString().trim { it <= ' ' }, labelToAdd.colorId)
Label(addLabelView.text.toString().trim { it <= ' ' }, labelToAdd.timeDailyGoal, labelToAdd.colorId)
if (labelIsGoodToAdd(this, labels, labelToAdd.title, "")) {
labels.add(labelToAdd)
adapter.notifyItemInserted(labels.size)
recyclerView.scrollToPosition(labels.size - 1)
viewModel.addLabel(labelToAdd)
labelToAdd = Label(
"", ThemeHelper.getColor(
"",
0,
ThemeHelper.getColor(
this,
ThemeHelper.COLOR_INDEX_UNLABELED
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package com.apps.adrcotfas.goodtime.labels

import android.annotation.SuppressLint
import android.app.TimePickerDialog
import android.content.Context
import com.apps.adrcotfas.goodtime.labels.AddEditLabelActivity.Companion.labelIsGoodToAdd
import com.apps.adrcotfas.goodtime.main.ItemTouchHelperAdapter
Expand Down Expand Up @@ -40,6 +41,7 @@ class AddEditLabelsAdapter(

interface OnEditLabelListener {
fun onEditColor(label: String, newColor: Int)
fun onEditTimeGoal(label: String, newTimeGoal: Int)
fun onEditLabel(label: String, newLabel: String)
fun onDeleteLabel(label: Label, position: Int)
fun onLabelRearranged()
Expand Down Expand Up @@ -102,11 +104,13 @@ class AddEditLabelsAdapter(
val labelIcon: ImageView = itemView.findViewById(R.id.label_icon)
val imageLeft: ImageView = itemView.findViewById(R.id.image_left)
private val imageRight: ImageView = itemView.findViewById(R.id.image_right)
val labelTimeSet: ImageView = itemView.findViewById(R.id.label_time_set)
private val row: RelativeLayout = itemView.findViewById(R.id.dialog_edit_label_row)
val scrollIconContainer: FrameLayout = itemView.findViewById(R.id.scroll_icon_container)
private val imageLeftContainer: FrameLayout = itemView.findViewById(R.id.image_left_container)
private val labelIconContainer: FrameLayout = itemView.findViewById(R.id.label_icon_container)
private val imageRightContainer: FrameLayout = itemView.findViewById(R.id.image_right_container)
private val labelTimeSetContainer: FrameLayout = itemView.findViewById(R.id.label_time_set_container)
private val imageDeleteContainer: FrameLayout = itemView.findViewById(R.id.image_delete_container)

override fun onItemSelected() {
Expand All @@ -125,18 +129,13 @@ class AddEditLabelsAdapter(
text.onFocusChangeListener = OnFocusChangeListener { _: View?, hasFocus: Boolean ->

// shrink the textView when we're in edit mode and the delete button appears
val params = text.layoutParams as RelativeLayout.LayoutParams
params.addRule(
RelativeLayout.START_OF,
if (hasFocus) R.id.image_delete_container else R.id.image_right_container
)
text.layoutParams = params
val position = bindingAdapterPosition
val crtLabel = labels[position]
labelIcon.setColorFilter(ThemeHelper.getColor(context.get()!!, crtLabel.colorId))
imageLeftContainer.visibility = if (hasFocus) View.VISIBLE else View.INVISIBLE
labelIconContainer.visibility = if (hasFocus) View.INVISIBLE else View.VISIBLE
imageDeleteContainer.visibility = if (hasFocus) View.VISIBLE else View.INVISIBLE
labelTimeSetContainer.visibility = if (hasFocus) View.INVISIBLE else View.VISIBLE
imageRight.setImageDrawable(
ContextCompat.getDrawable(
context.get()!!, if (hasFocus) R.drawable.ic_done else R.drawable.ic_edit
Expand Down Expand Up @@ -224,6 +223,15 @@ class AddEditLabelsAdapter(
dialog.show()
}

// changing the time goal of a label
labelTimeSetContainer.setOnClickListener {
val crtLabel = labels[bindingAdapterPosition]
val dialog = TimePickerDialog(context.get()!!, { _, hour, minute ->
callback.onEditTimeGoal(crtLabel.title, hour * 60 + minute)
}, crtLabel.timeDailyGoal / 60, crtLabel.timeDailyGoal % 60, true)
dialog.show()
}

// the edit button
imageRightContainer.setOnClickListener {
ThemeHelper.requestFocusEditText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class LabelsViewModel @Inject constructor(
}
}

fun editLabelGoal(label: String, timeDailyGoal: Int) {
viewModelScope.launch(Dispatchers.IO) {
dao.editLabelGoal(label, timeDailyGoal)
}
}

fun editLabelOrder(label: String, newOrder: Int) {
viewModelScope.launch(Dispatchers.IO) {
dao.editLabelOrder(label, newOrder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class PreferenceHelper(val context: Context) {
private const val WORK_STREAK = "pref_WORK_STREAK"
private const val LAST_WORK_FINISHED_AT = "pref_last_work_finished_at"
private const val CURRENT_SESSION_LABEL = "pref_current_session_label"
private const val CURRENT_SESSION_GOAL = "pref_current_session_goal"
private const val CURRENT_SESSION_COLOR = "pref_current_session_color"
private const val INTRO_SNACKBAR_STEP = "pref_intro_snackbar_step"
private const val INTRO_ARCHIVE_LABEL = "pref_intro_archive_label"
Expand Down Expand Up @@ -192,13 +193,18 @@ class PreferenceHelper(val context: Context) {
.getString(
CURRENT_SESSION_LABEL, ""
)!!,
preferences.getInt(
CURRENT_SESSION_GOAL, 0
),
preferences.getInt(
CURRENT_SESSION_COLOR, 0
)
)
set(label) {
preferences.edit()
.putString(CURRENT_SESSION_LABEL, label.title).apply()
preferences.edit()
.putInt(CURRENT_SESSION_GOAL, label.timeDailyGoal).apply()
preferences.edit()
.putInt(CURRENT_SESSION_COLOR, label.colorId).apply()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ object Utils {
fun getInstanceTotalLabel(context: Context): Label {
return Label(
context.getString(R.string.label_all),
0, // TODO: Check if this 0 is a correct default value, or should I get something here
ThemeHelper.COLOR_INDEX_ALL_LABELS
)
}

fun getInstanceUnlabeledLabel(context: Context): Label {
return Label(
"unlabeled", ThemeHelper.getColor(
"unlabeled",
0,
ThemeHelper.getColor(
context,
ThemeHelper.COLOR_INDEX_UNLABELED
)
Expand All @@ -38,6 +41,7 @@ object Utils {
val randomColor = ThemeHelper.getPalette(context).indices.random()
return Label(
"",
0,
randomColor
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class SelectLabelDialog : DialogFragment() {
notifyLabelSelected(
Label(
mLabel,
0, // TODO: Check if this 0 placeholder is placed correctly, or should I somehow get value of the "Chip"
ThemeHelper.getIndexOfColor(requireContext(), color)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ class TimePickerDialogBuilder(context: Context) {
.setInputMode(MaterialTimePicker.INPUT_MODE_KEYBOARD)
.build()
}

fun buildDialog(hours: Int, minutes: Int): MaterialTimePicker {
return MaterialTimePicker.Builder()
.setHour(hours)
.setMinute(minutes)
.setTimeFormat(TimeFormat.CLOCK_24H)
.setInputMode(MaterialTimePicker.INPUT_MODE_CLOCK)
.build()
}
}
35 changes: 28 additions & 7 deletions app/src/main/res/layout/activity_add_edit_labels_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,37 @@
android:hint="@string/label_name"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/image_left_container"

android:layout_toStartOf="@id/image_right_container"

android:layout_toStartOf="@id/label_time_set_container"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:paddingBottom="12dp"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
style="@style/AddEditLabelRowEdit" />

style="@style/AddEditLabelRowEdit"/>
<FrameLayout
android:id="@+id/label_time_set_container"
android:layout_width="@dimen/menu_item_size"
android:layout_height="@dimen/menu_item_size"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/image_right_container"
android:focusable="false"
android:clickable="false"
android:visibility="visible">
<ImageView
android:id="@+id/label_time_set"
android:contentDescription="@string/dialog_time"
android:src="@drawable/ic_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<View
android:layout_width="@dimen/menu_item_ripple_size"
android:layout_height="@dimen/menu_item_ripple_size"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:duplicateParentState="true">
</View>
</FrameLayout>

<FrameLayout
android:id="@+id/image_delete_container"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/labels_list"
android:layout_width="69dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/bar_layout"
app:layout_constraintStart_toStartOf="parent" />

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/bar_layout"
android:layout_width="match_parent"
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/res/layout/activity_main_goal_labels_row.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/menu_item_size">

<FrameLayout
android:id="@+id/label_chip_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_centerVertical="true" >

<com.google.android.material.chip.Chip
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>

<FrameLayout
android:id="@+id/label_time_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="@id/label_chip_container"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true" >

<EditText
android:id="@+id/label_time_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="1:20" />
</FrameLayout>

</RelativeLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<string name="label_name">Label name</string>
<string name="label_already_exists">Label already exists</string>
<string name="label_select_color">Select color</string>
<string name="label_time">Pick daily time goal</string>
<string name="label_delete_title">Delete label?</string>
<string name="label_delete_message">Deleting this label will remove it from all finished sessions. The sessions will not be removed.</string>
<string name="label_dialog_select">Select label</string>
Expand Down Expand Up @@ -102,6 +103,7 @@
<string name="intro_get_started_description">"Stay focused, get rid of procrastination and improve your productivity."</string>

<string name="dialog_close">Close</string>
<string name="dialog_time">Goal Time</string>
<string name="dialog_delete">Delete</string>
<string name="edit">Edit</string>
<string name="upgrade">Upgrade</string>
Expand Down