Skip to content

Commit

Permalink
1.0 v beta
Browse files Browse the repository at this point in the history
  • Loading branch information
0developers committed Feb 7, 2024
1 parent 9b4fba8 commit d0ace2e
Show file tree
Hide file tree
Showing 27 changed files with 159 additions and 32 deletions.
Binary file modified .gradle/8.0/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/8.0/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified .gradle/8.0/checksums/sha1-checksums.bin
Binary file not shown.
Binary file modified .gradle/8.0/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.0/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.0/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.0/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.0/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
6 changes: 3 additions & 3 deletions .idea/navEditor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation "com.anggrayudi:storage:1.5.5"


}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />



<queries>
<package android:name="org.telegram.messenger" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/zerodev/todo/ApplyColorTextView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ApplyColorTextView {
textView.text = textWithColor
}
}
private fun parseAndApplyColor(inputText: String): SpannableStringBuilder {
fun parseAndApplyColor(inputText: String): SpannableStringBuilder {
val spannableStringBuilder = SpannableStringBuilder(inputText)

val regex = "\\[color:(#[0-9A-Fa-f]{6})](.*?)\\[/color]".toRegex()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.zerodev.todo.Notifications
package com.zerodev.todo.Data

data class NotifSoundData(val title: String, val path: String)
1 change: 0 additions & 1 deletion app/src/main/java/com/zerodev/todo/Data/NotifSounds.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.zerodev.todo.Data

import android.content.Context
import com.zerodev.todo.Notifications.NotifSoundData
import com.zerodev.todo.R

class NotifSounds (context : Context) {
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/com/zerodev/todo/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.zerodev.todo

import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.CountDownTimer
import android.os.Handler
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.google.gson.Gson
import com.zerodev.todo.databinding.ActivityMainBinding
Expand All @@ -23,6 +26,17 @@ class MainActivity : AppCompatActivity() {
}

override fun onFinish() {
val settingsPref =
applicationContext?.getSharedPreferences("settings", Context.MODE_PRIVATE)
if (settingsPref != null) {
if (!settingsPref.contains("notifSound") && !settingsPref.contains("notifImportance")) {
settingsPref.edit()
?.putInt("notifSound", 0)
?.putInt("notifImportance", 4)
?.apply()
}
}

val intent = Intent()
intent.setClass(applicationContext, ViewTasksActivity::class.java)
startActivity(intent)
Expand All @@ -31,6 +45,5 @@ class MainActivity : AppCompatActivity() {
}.start()



}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.net.Uri
import android.os.Build
import android.util.Log
import androidx.core.app.NotificationCompat
import com.zerodev.todo.ApplyColorTextView
import com.zerodev.todo.Data.NotifSounds
import com.zerodev.todo.MainActivity
import com.zerodev.todo.R
Expand Down Expand Up @@ -69,8 +70,14 @@ class NotificationReceiver : BroadcastReceiver() {
val notificationManager = context.getSystemService(
NotificationManager::class.java
)
// apply spannable
var textColor = ApplyColorTextView()
notificationManager.createNotificationChannel(notificationChannel)
val messageBody = "You got a task to do : $taskTitle"
val messageBody = "You Got a task to do : ${taskTitle?.let {
textColor.parseAndApplyColor(
it
)
}}"
val contentIntent = Intent(context, MainActivity::class.java)
val contentPendingIntent = PendingIntent.getActivity(
context,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/zerodev/todo/TaskAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TaskAdapter(private var tasks: MutableList<Task> , private val context: Co
""".trimIndent()

val detailDialog = AlertDialog.Builder(context)
.setTitle(task.title)
.setTitle(applyColor.parseAndApplyColor(task.title))
.setMessage(message)
.setPositiveButton("ok" , null)

Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/zerodev/todo/ViewTasksActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.zerodev.todo
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.PowerManager
import android.provider.Settings
Expand Down Expand Up @@ -83,6 +84,16 @@ class ViewTasksActivity : AppCompatActivity() {
}
}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
val builder = AlertDialog.Builder(this)
builder.setTitle("Warning")
builder.setMessage("The Remind Feature Won't work on this android version , we recommend you to use android 8+ for better experience")
builder.setPositiveButton("Ignore") { _, _ ->

}
builder.show()
}

val drawerLayout: DrawerLayout = binding.drawerLayout
val navView: NavigationView = binding.navView
val navController = findNavController(R.id.nav_host_fragment_content_view_tasks)
Expand All @@ -97,12 +108,16 @@ class ViewTasksActivity : AppCompatActivity() {
navView.setupWithNavController(navController)
}

/*
Todo: Need to work on this one
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.view_tasks, menu)
return true
}
*/

override fun onSupportNavigateUp(): Boolean {
val navController = findNavController(R.id.nav_host_fragment_content_view_tasks)
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
Expand Down
114 changes: 98 additions & 16 deletions app/src/main/java/com/zerodev/todo/ui/settings/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,35 @@ import android.content.DialogInterface
import android.content.SharedPreferences
import android.graphics.Color
import android.os.Bundle
import android.os.Environment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.anggrayudi.storage.SimpleStorageHelper
import com.google.android.material.snackbar.Snackbar
import com.zerodev.todo.Data.NotifSounds
import com.zerodev.todo.databinding.FragmentSettingsBinding
import java.io.File
import java.io.FileOutputStream
import java.io.IOException

class SettingsFragment : Fragment() {

private var _binding: FragmentSettingsBinding? = null
private var storageHelper: SimpleStorageHelper? = null
private val binding get() = _binding!!
var notifSounds = context?.let { NotifSounds(it) }
val notifImportance = arrayOf(
private val notifImportance = arrayOf(
"None",
"Min",
"Low",
"Default",
"High"
)

@SuppressLint("SetTextI18n")
override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -40,35 +48,62 @@ class SettingsFragment : Fragment() {
_binding = FragmentSettingsBinding.inflate(inflater, container, false)
val root: View = binding.root
val settingsPref = context?.getSharedPreferences("settings", Context.MODE_PRIVATE)
val notifSounds = context?.let { NotifSounds(it) }
val notifSoundArray = notifSounds?.soundArray
if (settingsPref != null) {
settingsViewModel.setSharedPref(settingsPref)
}
// set the sound title to the text view
if (settingsPref != null) {
binding.notifSoundtxt.text = " ${notifSounds?.soundArray?.get(settingsPref.getInt("notifSound" , 0))?.title}"
binding.notifSoundtxt.text =
" ${notifSoundArray?.get(settingsPref.getInt("notifSound", 0))?.title}"
}
// set the notif importance to textview
if (settingsPref != null) {
setNotifImportanceColors(settingsPref)
binding.notifImportancetxt.text = " ${notifImportance[settingsPref.getInt("notifImportance" , 0)]}"
binding.notifImportancetxt.text =
" ${notifImportance[settingsPref.getInt("notifImportance", 0)]}"
}
// backup list click
binding.backuplist.setOnClickListener {
/*
if (ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.WRITE_EXTERNAL_STORAGE
) != PackageManager.PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(
requireActivity(),
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
WRITE_EXTERNAL_STORAGE_REQUEST_CODE
)
} else {
saveToFile("it worked")
}
*/


}

// notif sound click listener
binding.notifSound.setOnClickListener {
//set notification sound
val soundTitles = notifSounds?.soundArray?.map { it.title }?.toTypedArray()
val soundTitles = notifSoundArray?.map { it.title }?.toTypedArray()
val builder = AlertDialog.Builder(context)
.setTitle("Choose a Sound")
.setTitle("Choose a Sound")
.setItems(soundTitles) { _, index ->
val selectedSound = notifSounds?.soundArray?.get(index)
// Handle the item click
settingsPref?.edit()?.putInt("notifSound" , index)
settingsPref?.edit()?.putInt("notifSound", index)
?.apply()
if (settingsPref != null) {
binding.notifSoundtxt.text = " ${notifSounds?.soundArray?.get(settingsPref.getInt("notifSound" , 0))?.title}"
binding.notifSoundtxt.text =
" ${notifSoundArray?.get(settingsPref.getInt("notifSound", 0))?.title}"
}
val snackbar = view?.let { it1 ->
Snackbar.make(it1,
Snackbar.make(
it1,
"Selected ${selectedSound?.title} ",
Snackbar.LENGTH_SHORT
)
Expand All @@ -87,17 +122,22 @@ class SettingsFragment : Fragment() {
if (settingsPref != null) {
AlertDialog.Builder(context)
.setTitle("Choose Notification Importance")
.setSingleChoiceItems(notifImportance, settingsPref.getInt("notifImportance" , 0)) { dialog, index ->
settingsPref?.edit()?.putInt("notifImportance" , index)
.setSingleChoiceItems(
notifImportance,
settingsPref.getInt("notifImportance", 0)
) { dialog, index ->
settingsPref?.edit()?.putInt("notifImportance", index)
?.apply()
val snackbar = view?.let { it1 ->
Snackbar.make(it1,
Snackbar.make(
it1,
"Selected ${notifImportance[index]} ",
Snackbar.LENGTH_SHORT
)
}
snackbar?.show()
binding.notifImportancetxt.text = " ${notifImportance[settingsPref.getInt("notifImportance" , 0)]}"
binding.notifImportancetxt.text =
" ${notifImportance[settingsPref.getInt("notifImportance", 0)]}"
setNotifImportanceColors(settingsPref)
dialog.dismiss()
}
Expand All @@ -111,14 +151,56 @@ class SettingsFragment : Fragment() {

return root
}
fun setNotifImportanceColors(settingsPref : SharedPreferences) {
when (settingsPref.getInt("notifImportance" , 0)) {

fun setNotifImportanceColors(settingsPref: SharedPreferences) {
when (settingsPref.getInt("notifImportance", 0)) {
0 -> binding.notifImportancetxt.setTextColor(Color.WHITE)
1 , 2 -> binding.notifImportancetxt.setTextColor(Color.YELLOW)
1, 2 -> binding.notifImportancetxt.setTextColor(Color.YELLOW)
3 -> binding.notifImportancetxt.setTextColor(Color.GREEN)
4 -> binding.notifImportancetxt.setTextColor(Color.RED)
}
}

private fun saveToFile(text: String) {
val directoryPath =
Environment.getExternalStorageDirectory().absolutePath + "/TodoList/Backup"
val fileName = "Backup.json"

val directory = File(directoryPath)

if (!directory.exists()) {
directory.mkdirs() // Create the directory if it doesn't exist
}

val file = File(directory, fileName)

try {
file.createNewFile()

val fileOutputStream = FileOutputStream(file)
fileOutputStream.write(text.toByteArray())
fileOutputStream.close()

// File saved successfully
Toast.makeText(requireContext(), "File saved successfully", Toast.LENGTH_SHORT).show()
} catch (e: IOException) {
e.printStackTrace()
// Handle the exception
Toast.makeText(requireContext(), "Error saving file", Toast.LENGTH_SHORT).show()
}
}

private fun checkPermission(): Boolean {
var permissionGranted = false
registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
permissionGranted = isGranted
}
return permissionGranted
}


override fun onDestroyView() {
super.onDestroyView()
_binding = null
Expand Down
Loading

0 comments on commit d0ace2e

Please sign in to comment.