Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
5 changes: 4 additions & 1 deletion app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ lib/
│ ├── cabinetdb.dart
│ └── profiledb.dart
├── home/
│ ├── addMenu.dart
│ ├── add_menu.dart
│ └── home.dart
├── models/
│ ├── cabinet.dart
│ └── profile.dart
├── profile/
│ └── profile.dart
├── services/
│ ├── alarm_service.dart
│ └── notification_service.dart
├── dose.dart
└── main.dart
5 changes: 5 additions & 0 deletions app/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ android {
ndkVersion = flutter.ndkVersion

compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
Expand Down Expand Up @@ -42,3 +43,7 @@ android {
flutter {
source = "../.."
}

dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
}
43 changes: 23 additions & 20 deletions app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
android:label="app"
android:label="Dose"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">

<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
Expand All @@ -25,21 +30,19 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->

<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.

In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>

<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
</application>
</manifest>
24 changes: 24 additions & 0 deletions app/lib/db/cabinetdb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ class DatabaseHelper {

DatabaseHelper._init();

Future<int> update(Cabinet cabinet) async {
final db = await instance.database;
return db.update(
'cabinet',
cabinet.toMap(),
where: 'id = ?',
whereArgs: [cabinet.id],
);
}

Future<Cabinet?> readMedicine(int id) async {
final db = await instance.database;
final maps = await db.query(
'cabinet',
where: 'id = ?',
whereArgs: [id],
);

if (maps.isNotEmpty) {
return Cabinet.fromMap(maps.first);
}
return null;
}

Future<Database> get database async {
if (_database != null) return _database!;
_database = await _initDB('dose.db');
Expand Down
26 changes: 25 additions & 1 deletion app/lib/dose.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import 'package:flutter/material.dart';
import 'package:app/home/home.dart';
import 'package:app/analytics/analytics.dart';
import 'package:app/profile/profile.dart';
import 'package:app/home/addMenu.dart';
import 'package:app/home/add_menu.dart';
import 'dart:async';
import 'package:alarm/alarm.dart';
import 'package:app/services/alarm_ring.dart';

class Dose extends StatefulWidget {
const Dose({super.key});
Expand Down Expand Up @@ -43,6 +46,27 @@ class _DoseState extends State<Dose> {
}
}

StreamSubscription<AlarmSettings>? ringSubscription;

@override
void initState() {
super.initState();
ringSubscription = Alarm.ringStream.stream.listen((alarmSettings) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AlarmRingScreen(alarmSettings: alarmSettings),
),
);
});
}

@override
void dispose() {
ringSubscription?.cancel();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
19 changes: 15 additions & 4 deletions app/lib/home/addMenu.dart → app/lib/home/add_menu.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:app/models/cabinet.dart';
import 'package:flutter/material.dart';
import 'package:app/models/cabinet.dart';
import 'package:app/db/cabinetdb.dart';
import 'package:app/services/notification_service.dart';
import 'package:app/services/alarm_service.dart';

class AddMedicineMenu extends StatefulWidget {
final VoidCallback onSave;
Expand Down Expand Up @@ -49,12 +51,21 @@ class _AddMedicineMenuState extends State<AddMedicineMenu> {
priority: _priority,
);

await DatabaseHelper.instance.create(medicine);
int newId = await DatabaseHelper.instance.create(medicine);

await AlarmService().scheduleMedicineAlarm(newId, medicine);
await NotificationHelper().scheduleMedicineNotification(
newId,
medicine.name,
timeString
);

widget.onSave();

if (mounted) {
Navigator.pop(context);
}

}
}

Expand Down Expand Up @@ -129,7 +140,7 @@ class _AddMedicineMenuState extends State<AddMedicineMenu> {
const SizedBox(width: 12),
Expanded(
child: DropdownButtonFormField<int>(
value: _cycle,
initialValue: _cycle,
decoration: const InputDecoration(
labelText: "Cycle",
border: OutlineInputBorder(),
Expand Down Expand Up @@ -177,7 +188,7 @@ class _AddMedicineMenuState extends State<AddMedicineMenu> {
const SizedBox(height: 16),

DropdownButtonFormField<int>(
value: _priority,
initialValue: _priority,
decoration: const InputDecoration(
labelText: "Priority",
border: OutlineInputBorder(),
Expand Down
Loading