Added i18n, and time units, v1.1.0

This commit is contained in:
xavis 2025-07-30 18:42:10 +02:00
parent 5e91df4529
commit b588ce2355
13 changed files with 58 additions and 31 deletions

View File

@ -60,3 +60,8 @@ expo.edgeToEdgeEnabled=true
android.packagingOptions.pickFirsts=**/libc++_shared.so
expo.sqlite.enableFTS=false
expo.sqlite.useSQLCipher=false
MYAPP_UPLOAD_STORE_FILE=taskeep.keystore
MYAPP_UPLOAD_STORE_PASSWORD=123?_Tk_?123
MYAPP_UPLOAD_KEY_ALIAS=taskeep
MYAPP_UPLOAD_KEY_PASSWORD=123?_Tk_?123

View File

@ -1,12 +1,13 @@
import { throttle } from '@/utils/throttle';
import * as Notifications from 'expo-notifications';
import React from 'react';
import type { WidgetTaskHandlerProps } from 'react-native-android-widget';
import i18n from '../../i18n';
import { Category, CategoryQuery } from '../../models/category';
import { Task, TaskQuery } from '../../models/task';
import { CategoryRepository } from '../../repositories/CategoryRepository';
import { TaskRepository } from '../../repositories/TaskRepository';
import { SQLiteDataService } from '../../services/data/sqliteDataService';
import { throttle } from '../../utils/throttle';
import { HelloWidget } from './hello';
@ -15,6 +16,7 @@ const categoryRepository = new CategoryRepository(new SQLiteDataService<Category
let tasks: Task[] = [];
let categories: Category[] = [];
let resizeInterval = -1;
Notifications.setNotificationHandler({
handleNotification: async () => ({
@ -66,8 +68,8 @@ const CheckTaskAndNotify = async (): Promise<{ newTasks: Task[], newCategories:
await Notifications.scheduleNotificationAsync({
identifier: `task-due-${task.id}`,
content: {
title: 'Task Reminder',
body: `${category?.icon} "${task.title}" is due!`,
title: i18n.t("task_reminder_title"),
body: `${category?.icon} "${task.title}" ${i18n.t("is_due")}`,
data: { taskId: task.id },
},
trigger: null
@ -78,35 +80,37 @@ const CheckTaskAndNotify = async (): Promise<{ newTasks: Task[], newCategories:
return { newTasks: tasks, newCategories: categories };
}
const throttledCheckTaskAndNotify = throttle(CheckTaskAndNotify, 1000); // Throttle to prevent too frequent calls
setInterval(async () => {
const { newTasks, newCategories } = await throttledCheckTaskAndNotify();
const { newTasks, newCategories } = await CheckTaskAndNotify();
console.log("Throttled task check and notify executed OUT");
console.log("New tasks:", newTasks);
console.log("New categories:", newCategories);
tasks = newTasks;
categories = newCategories;
}, 1000 * 60 * 30); // Check every 30 minutes
}, 1000 * 60); // Check every minute
let lastRender = 0;
export async function widgetTaskHandler(props: WidgetTaskHandlerProps) {
async function updateAndRenderWidget() {
const { newTasks, newCategories } = await throttledCheckTaskAndNotify();
tasks = newTasks;
categories = newCategories;
console.log("Throttled task check and notify executed IN");
console.log("New tasks:", newTasks);
console.log("New categories:", newCategories);
props.renderWidget(<HelloWidget tasks={tasks} categories={categories} />);
const throttledDraw = throttle(props.renderWidget, 1000);
async function updateAndRenderWidget(force = false) {
console.log("Updating widget with tasks and categories");
const { newTasks, newCategories } = await CheckTaskAndNotify();
throttledDraw(<HelloWidget tasks={newTasks} categories={newCategories} />);
if (lastRender > Date.now() - 1000 || force) {
lastRender = Date.now();
console.log("Rendering widget");
props.renderWidget(<HelloWidget tasks={newTasks} categories={newCategories} />);
}
}
switch (props.widgetAction) {
case 'WIDGET_ADDED':
case 'WIDGET_UPDATE':
case 'WIDGET_RESIZED':
// Not needed for now
updateAndRenderWidget();
break;
@ -117,7 +121,7 @@ export async function widgetTaskHandler(props: WidgetTaskHandlerProps) {
case 'WIDGET_CLICK':
switch (props.clickAction) {
case 'REFRESH':
await updateAndRenderWidget();
await updateAndRenderWidget(true);
break;
case 'UPDATE_TASK':
if (props.clickActionData && props.clickActionData.id) {
@ -126,7 +130,7 @@ export async function widgetTaskHandler(props: WidgetTaskHandlerProps) {
if (task) {
task.lastDone = Math.floor(Date.now() / 1000 / 60 / 60 / 24); // Set last done to today
await taskRepository.update(parseInt(taskId.toString()), { ...task, lastDone: new Date().getTime() });
await updateAndRenderWidget();
await updateAndRenderWidget(true);
}
}
break;

View File

@ -5,5 +5,3 @@ import "./i18n.js";
registerWidgetTaskHandler(widgetTaskHandler);
console.log(registerWidgetTaskHandler);

View File

@ -61,5 +61,7 @@
"Months": "أشهر",
"select_icon_and_enter_title": "اختر رمزًا وأدخل عنوانًا",
"Tasks": "المهام",
"Categories": "الفئات"
"Categories": "الفئات",
"task_reminder_title": "تذكير بالمهمة",
"is_due": "مستحقة!"
}

View File

@ -61,5 +61,7 @@
"Months": "Monate",
"select_icon_and_enter_title": "Wählen Sie ein Symbol und geben Sie einen Titel ein",
"Tasks": "Aufgaben",
"Categories": "Kategorien"
"Categories": "Kategorien",
"task_reminder_title": "Aufgabenerinnerung",
"is_due": "ist fällig!"
}

View File

@ -61,5 +61,7 @@
"Months": "Months",
"select_icon_and_enter_title": "Select an icon and enter a title",
"Tasks": "Tasks",
"Categories": "Categories"
"Categories": "Categories",
"task_reminder_title": "Task Reminder",
"is_due": "is due!"
}

View File

@ -61,5 +61,7 @@
"Months": "Meses",
"select_icon_and_enter_title": "Selecciona un ícono e ingresa un título",
"Tasks": "Tareas",
"Categories": "Categorías"
"Categories": "Categorías",
"task_reminder_title": "Recordatorio de Tarea",
"is_due": "está vencida!"
}

View File

@ -61,5 +61,7 @@
"Months": "Mois",
"select_icon_and_enter_title": "Sélectionnez une icône et entrez un titre",
"Tasks": "Tâches",
"Categories": "Catégories"
"Categories": "Catégories",
"task_reminder_title": "Rappel de Tâche",
"is_due": "est due!"
}

View File

@ -61,5 +61,7 @@
"Months": "Mesi",
"select_icon_and_enter_title": "Seleziona un'icona e inserisci un titolo",
"Tasks": "Attività",
"Categories": "Categorie"
"Categories": "Categorie",
"task_reminder_title": "Promemoria Attività",
"is_due": "è scaduta!"
}

View File

@ -61,5 +61,7 @@
"Months": "月",
"select_icon_and_enter_title": "アイコンを選択してタイトルを入力",
"Tasks": "タスク",
"Categories": "カテゴリ"
"Categories": "カテゴリ",
"task_reminder_title": "タスクリマインダー",
"is_due": "期限です!"
}

View File

@ -61,5 +61,7 @@
"Months": "Meses",
"select_icon_and_enter_title": "Selecione um ícone e insira um título",
"Tasks": "Tarefas",
"Categories": "Categorias"
"Categories": "Categorias",
"task_reminder_title": "Lembrete de Tarefa",
"is_due": "está vencida!"
}

View File

@ -61,5 +61,7 @@
"Months": "Месяцы",
"select_icon_and_enter_title": "Выберите значок и введите название",
"Tasks": "Задачи",
"Categories": "Категории"
"Categories": "Категории",
"task_reminder_title": "Напоминание о задаче",
"is_due": "просрочено!"
}

View File

@ -61,5 +61,7 @@
"Months": "月",
"select_icon_and_enter_title": "选择一个图标并输入标题",
"Tasks": "任务",
"Categories": "类别"
"Categories": "类别",
"task_reminder_title": "任务提醒",
"is_due": "已到期!"
}