-
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.
ref: Global refactoring, optimization
- Loading branch information
bulkabuka
committed
Apr 30, 2024
1 parent
7b19317
commit 9b14939
Showing
20 changed files
with
342 additions
and
434 deletions.
There are no files selected for viewing
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
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
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
78 changes: 78 additions & 0 deletions
78
app/src/main/java/org/leftbrained/uptaskapp/classes/Checks.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,78 @@ | ||
package org.leftbrained.uptaskapp.classes | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.widget.Toast | ||
import org.leftbrained.uptaskapp.R | ||
|
||
object Checks { | ||
fun dateCheck(dueDate: String, context: Context): Boolean { | ||
val dateRegex = Regex("[0-9]{4}-[0-9]{2}-[0-9]{2}") | ||
if (!dueDate.matches(dateRegex)) { | ||
Toast.makeText( | ||
context, | ||
"Date doesn't match the pattern", | ||
Toast.LENGTH_SHORT | ||
).show() | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
fun emptyCheck( | ||
name: String, | ||
desc: String, | ||
context: Context | ||
): Boolean { | ||
if (name == "" || desc == "") { | ||
Toast.makeText( | ||
context, | ||
"Empty values not allowed", | ||
Toast.LENGTH_SHORT | ||
).show() | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
fun priorityCheck(priority: Int, context: Context): Boolean { | ||
if (!priority.toString().matches(Regex("[0-5]"))) { | ||
Toast.makeText( | ||
context, | ||
"Priority must be between 0 and 5", | ||
Toast.LENGTH_SHORT | ||
).show() | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
fun tagCheck(tag: String, context: Context): Boolean { | ||
if (tag == "") { | ||
Toast.makeText( | ||
context, | ||
"Tag can't be empty", | ||
Toast.LENGTH_SHORT | ||
).show() | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
fun checkAuth( | ||
login: String, | ||
password: String, | ||
activity: Activity, | ||
context: Context | ||
): Boolean { | ||
if (login == "" || password == "") { | ||
Toast.makeText( | ||
activity, | ||
context.getString(R.string.please_fill_all_fields), | ||
Toast.LENGTH_SHORT | ||
).show() | ||
return false | ||
} | ||
return true | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
app/src/main/java/org/leftbrained/uptaskapp/classes/Logs.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,71 @@ | ||
package org.leftbrained.uptaskapp.classes | ||
|
||
import android.content.SharedPreferences | ||
import kotlinx.datetime.Clock | ||
import kotlinx.datetime.LocalDate | ||
import kotlinx.datetime.TimeZone | ||
import kotlinx.datetime.toLocalDateTime | ||
import org.leftbrained.uptaskapp.db.User | ||
import org.leftbrained.uptaskapp.db.UserTask | ||
|
||
class Logs(var sharedPref: SharedPreferences) { | ||
private var logsSet = sharedPref.getStringSet("logs", mutableSetOf())!! | ||
|
||
fun statusChangeLog( | ||
userId: Int, | ||
task: UserTask | ||
) { | ||
with(sharedPref.edit()) { | ||
val newLogs = logsSet.toMutableSet() | ||
newLogs.add( | ||
"${logsSet.size + 1} - ${ | ||
LocalDate.parse( | ||
Clock.System.now() | ||
.toLocalDateTime(TimeZone.currentSystemDefault()).date.toString() | ||
) | ||
} - $userId - ${if (task.isDone) "Done" else "Undone"} - ${task.id.value}" | ||
) | ||
putStringSet("logs", newLogs) | ||
apply() | ||
} | ||
} | ||
|
||
fun addTaskLog( | ||
userId: User, | ||
newTaskId: UserTask | ||
) { | ||
with(sharedPref.edit()) { | ||
val newLogs = logsSet.toMutableSet() | ||
newLogs.add( | ||
"${logsSet.size + 1} - ${ | ||
LocalDate.parse( | ||
Clock.System.now() | ||
.toLocalDateTime(TimeZone.currentSystemDefault()).date.toString() | ||
) | ||
} - ${userId.id.value} - Add - ${newTaskId.id.value}" | ||
) | ||
putStringSet("logs", newLogs) | ||
apply() | ||
} | ||
} | ||
|
||
fun deleteTaskLog( | ||
userId: Int, | ||
task: UserTask | ||
) { | ||
with(sharedPref.edit()) { | ||
val newLogs = logsSet.toMutableSet() | ||
newLogs.add( | ||
"${logsSet.size + 1} - ${ | ||
LocalDate.parse( | ||
Clock.System.now() | ||
.toLocalDateTime(TimeZone.currentSystemDefault()).date.toString() | ||
) | ||
} - $userId - Delete - ${task.id.value}" | ||
) | ||
putStringSet("logs", newLogs) | ||
apply() | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.