Skip to content

Commit

Permalink
Merge branch 'unit_tests' of https://github.com/rohansen856/taskwarri…
Browse files Browse the repository at this point in the history
…or-flutter into unit_tests
  • Loading branch information
rohansen856 committed Dec 30, 2024
2 parents 097df66 + db66d55 commit bd11d04
Show file tree
Hide file tree
Showing 122 changed files with 6,068 additions and 299 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Getting Started

In order to use the mobile app, you would need the flood backend running on your local machine. There are several ways
you can do that and all these approaches can be found at [TaskWarrior-Flutter](https://github.com/CCExtractor/taskwarrior-flutter/wiki)
you can do that and all these approaches can be found at [Taskwarrior-Flutter](https://github.com/CCExtractor/taskwarrior-flutter/wiki)


## Steps
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TaskWarrior Mobile App
# Taskwarrior Mobile App


![Group 3](https://github.com/Pavel401/taskwarrior-flutter/assets/47685150/1ffb623b-b147-4176-9f7c-abda544b257c)
Expand Down Expand Up @@ -38,7 +38,7 @@

Taskwarrior is Free and Open Source Software that manages your TODO list from the command line.
It is flexible, fast, and unobtrusive. It does its job then gets out of your way. The CLI tool and other relevant documentation can be
found at [TaskWarrior](https://taskwarrior.org/download/).
found at [Taskwarrior](https://taskwarrior.org/download/).

This project aims to build an app for Taskwarrior. It is your task management app across all platforms. It helps you manage your tasks and filter them as per your needs.

Expand Down Expand Up @@ -253,4 +253,4 @@ Feel free to reach out if you encounter any issues.

[Mabud Alam](https://www.linkedin.com/in/mabud/)

Project Link: [TaskWarrior](https://github.com/CCExtractor/taskwarrior-flutter)
Project Link: [Taskwarrior](https://github.com/CCExtractor/taskwarrior-flutter)
18 changes: 9 additions & 9 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:label="TaskWarrior"
android:label="Taskwarrior"
android:name="${applicationName}"
android:icon="@mipmap/launcher_icon">
<activity
Expand Down Expand Up @@ -65,13 +65,13 @@


<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
</application>
</manifest>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ package com.ccextractor.taskwarriorflutter

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}
class MainActivity: FlutterActivity()
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
package com.ccextractor.taskwarriorflutter
import android.annotation.TargetApi
import android.appwidget.AppWidgetManager
import android.content.Context
import android.net.Uri
import android.widget.RemoteViews
import es.antonborri.home_widget.HomeWidgetBackgroundIntent
import es.antonborri.home_widget.HomeWidgetLaunchIntent
import es.antonborri.home_widget.HomeWidgetProvider
import es.antonborri.home_widget.HomeWidgetPlugin
import org.json.JSONException
import android.content.Intent
import android.widget.RemoteViewsService
import org.json.JSONObject
import org.json.JSONArray as OrgJSONArray
import android.os.Bundle
import android.app.PendingIntent
import android.appwidget.AppWidgetProvider
import android.os.Build


@TargetApi(Build.VERSION_CODES.CUPCAKE)
class TaskWarriorWidgetProvider : AppWidgetProvider() {

override fun onReceive(context: Context, intent: Intent) {
// val myaction = intent.action
if (intent.action == "TASK_ACTION") {
val extras = intent.extras
if(extras!=null){
val uuid = extras.getString("uuid")?:""
val add_task = extras.getString("launchedFor")
val host = if(add_task == "ADD_TASK"){context.getString(R.string.app_widget_add_clicked_uri)}else{context.getString(R.string.app_widget_card_clicked_uri)}
val launchIntent = Intent(context, MainActivity::class.java).apply {
action = context.getString(R.string.app_widget_launch_action)
data = Uri.parse("$host?uuid=$uuid")
flags = Intent. FLAG_ACTIVITY_NEW_TASK
context?.startActivity(this)
}
// HomeWidgetLaunchIntent.getActivity(context, MainActivity::class.java, Uri.parse("TaskWarrior://taskView?taskId=$uuid"))
}
}
super.onReceive(context, intent)
}
fun getLayoutId(context: Context) : Int{
val sharedPrefs = HomeWidgetPlugin.getData(context)
val theme = sharedPrefs.getString("themeMode", "")
val layoutId = if (theme.equals("dark")) {
R.layout.taskwarrior_layout_dark // Define a dark mode layout in your resources
} else {
R.layout.taskwarrior_layout
}
return layoutId
}
@TargetApi(Build.VERSION_CODES.DONUT)
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
appWidgetIds.forEach { widgetId ->
val sharedPrefs = HomeWidgetPlugin.getData(context)
val tasks = sharedPrefs.getString("tasks", "")
val intent = Intent(context, ListViewRemoteViewsService::class.java).apply {
putExtra("tasksJsonString", tasks)
data = Uri.parse(toUri(Intent.URI_INTENT_SCHEME))
}
val views = RemoteViews(context.packageName, getLayoutId(context)).apply {
val pendingIntent: PendingIntent = HomeWidgetLaunchIntent.getActivity(
context,
MainActivity::class.java
)
setOnClickPendingIntent(R.id.logo, pendingIntent)
val intent_for_add = Intent(context, TaskWarriorWidgetProvider::class.java).apply {
setAction("TASK_ACTION")
data=Uri.parse(toUri(Intent.URI_INTENT_SCHEME))
putExtra("launchedFor", "ADD_TASK")
}
val pendingIntentAdd: PendingIntent = PendingIntent.getBroadcast(
context,
0, // requestCode, can be any unique integer
intent_for_add,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT or Intent.FILL_IN_COMPONENT // Use appropriate flags
)
setOnClickPendingIntent(R.id.add_btn, pendingIntentAdd)
setRemoteAdapter(R.id.list_view, intent)
}

val clickPendingIntent: PendingIntent = Intent(
context,
TaskWarriorWidgetProvider::class.java
).run {
setAction("TASK_ACTION")
setIdentifier("uuid")
data = Uri.parse(toUri(Intent.URI_INTENT_SCHEME))

PendingIntent.getBroadcast(
context,
0,
this,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT or Intent.FILL_IN_COMPONENT
)
}

views.setPendingIntentTemplate(R.id.list_view, clickPendingIntent)
appWidgetManager.updateAppWidget(widgetId, views)
}
super.onUpdate(context, appWidgetManager, appWidgetIds)
}
}
class ListViewRemoteViewsFactory(
private val context: Context,
private val tasksJsonString: String?
) : RemoteViewsService.RemoteViewsFactory {

private val tasks = mutableListOf<Task>()

override fun onCreate() {}

override fun onDataSetChanged() {
if (tasksJsonString != null) {
try {
val jsonArray = OrgJSONArray(tasksJsonString as String)
for (i in 0 until jsonArray.length()) {
tasks.add(Task.fromJson(jsonArray.getJSONObject(i)))
}
} catch (e: JSONException) {
e.printStackTrace()
}
}
}

override fun onDestroy() {}

override fun getCount(): Int = tasks.size

fun getListItemLayoutId(): Int{
val sharedPrefs = HomeWidgetPlugin.getData(context)
val theme = sharedPrefs.getString("themeMode", "")
val layoutId = if (theme.equals("dark")) {
R.layout.listitem_layout_dark // Define a dark mode layout in your resources
} else {
R.layout.listitem_layout
}
return layoutId
}
fun getListItemLayoutIdForR1(): Int{
val sharedPrefs = HomeWidgetPlugin.getData(context)
val theme = sharedPrefs.getString("themeMode", "")
val layoutId = if (theme.equals("dark")) {
R.layout.no_tasks_found_li_dark // Define a dark mode layout in your resources
} else {
R.layout.no_tasks_found_li
}
return layoutId
}
fun getDotIdByPriority(p: String) : Int{
println("PRIORITY: "+p)
if(p.equals("L")) return R.drawable.low_priority_dot
if(p.equals("M")) return R.drawable.mid_priority_dot
if(p.equals("H")) return R.drawable.high_priority_dot
return R.drawable.no_priority_dot
}

override fun getViewAt(position: Int): RemoteViews {
val task = tasks[position]
if(task.uuid.equals("NO_TASK"))
return RemoteViews(context.packageName, getListItemLayoutIdForR1()).apply {
if(task.priority.equals("1"))
setTextViewText(R.id.tv, "No tasks added yet")
if(task.priority.equals("2"))
setTextViewText(R.id.tv, "Filters applied are hiding all tasks")
}
return RemoteViews(context.packageName, getListItemLayoutId()).apply {
setTextViewText(R.id.todo__title, task.title)
setImageViewResource(R.id.dot, getDotIdByPriority(task.priority))
val a = Intent().apply {

Bundle().also { extras ->
extras.putString("action", "show_task")
extras.putString("uuid", tasks[position].uuid)
putExtras(extras)
}

}
setOnClickFillInIntent(R.id.list_item_container,a)
}

}
override fun getLoadingView(): RemoteViews? = null

override fun getViewTypeCount(): Int = 1

override fun getItemId(position: Int): Long = position.toLong()

override fun hasStableIds(): Boolean = true
}
class ListViewRemoteViewsService : RemoteViewsService() {

override fun onGetViewFactory(intent: Intent): RemoteViewsFactory {
val tasksJsonString = intent.getStringExtra("tasksJsonString")
return ListViewRemoteViewsFactory(applicationContext, tasksJsonString)
}
}
data class Task(val title: String, val urgencyLevel: String,val uuid:String, val priority: String) {
companion object {
fun fromJson(json: JSONObject): Task {
val title = json.optString("description", "")
val urgencyLevel = json.optString("urgency", "")
val uuid = json.optString("uuid","")
val priority = json.optString("priority", "")
return Task(title, urgencyLevel, uuid, priority)
}
}
}
Loading

0 comments on commit bd11d04

Please sign in to comment.