Compare commits

..

3 Commits

Author SHA1 Message Date
Faiz Hashmi cb50054201 Chnages for lab 1 month ago
Faiz Hashmi 0bf40f3995 Chnages for lab 1 month ago
Faiz Hashmi 81b6117161 qLine Lab integration started. 2 months ago

@ -45,5 +45,4 @@ flutter {
dependencies {
implementation 'androidx.lifecycle:lifecycle-service:2.8.7'
implementation 'androidx.core:core-ktx:1.13.1'
}

@ -5,12 +5,6 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- Android 12+ (API 31+) exact alarm permissions -->
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<!-- Android 14+ (API 34+) - USE_EXACT_ALARM is for apps that need exact alarms as core functionality -->
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<!-- Foreground service types for Android 14+ -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<queries>
<intent>
@ -30,30 +24,14 @@
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<!-- Receiver for scheduled restart alarm -->
<receiver
android:name=".RestartAlarmReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.example.hmg_qline.SCHEDULED_RESTART" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service
android:name=".BootForegroundService"
android:exported="true"
android:foregroundServiceType="specialUse">
<!-- Android 14+ requires property declaration for FOREGROUND_SERVICE_TYPE_SPECIAL_USE -->
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="App auto-start and scheduled restart" />
</service>
android:exported="true" />
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"

@ -1,225 +0,0 @@
package com.example.hmg_qline.hmg_qline
import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.Settings
import android.util.Log
import java.util.Calendar
/**
* Utility class for scheduling app restart alarms.
* Handles Android version-specific alarm scheduling with proper backward compatibility.
*
* Android Version Compatibility:
* - Android 14+ (API 34): Uses USE_EXACT_ALARM or SCHEDULE_EXACT_ALARM with permission check
* - Android 12-13 (API 31-33): Uses SCHEDULE_EXACT_ALARM with permission check
* - Android 6-11 (API 23-30): Uses setExactAndAllowWhileIdle
* - Android < 6 (API < 23): Uses setExact
*/
object AlarmScheduler {
private const val TAG = "AlarmScheduler"
private const val RESTART_ALARM_REQUEST_CODE = 1001
/**
* Schedule a daily restart alarm at the specified time.
*
* @param context Application context
* @param hour Hour of day (0-23), default is 0 (midnight)
* @param minute Minute (0-59), default is 15
*/
fun scheduleRestartAlarm(context: Context, hour: Int = 0, minute: Int = 15) {
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val intent = Intent(context, RestartAlarmReceiver::class.java).apply {
action = RestartAlarmReceiver.ACTION_SCHEDULED_RESTART
}
val pendingIntent = PendingIntent.getBroadcast(
context,
RESTART_ALARM_REQUEST_CODE,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
// Calculate next alarm time
val calendar = Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, hour)
set(Calendar.MINUTE, minute)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
// If the time has already passed today, schedule for tomorrow
if (timeInMillis <= System.currentTimeMillis()) {
add(Calendar.DAY_OF_YEAR, 1)
}
}
// Cancel any existing alarm first
alarmManager.cancel(pendingIntent)
Log.d(TAG, "Scheduling restart alarm for: ${calendar.time}")
Log.d(TAG, "Android SDK Version: ${Build.VERSION.SDK_INT}")
// Schedule based on Android version
when {
// Android 14+ (API 34+)
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> {
scheduleForAndroid14Plus(context, alarmManager, pendingIntent, calendar.timeInMillis)
}
// Android 12-13 (API 31-33)
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
scheduleForAndroid12To13(context, alarmManager, pendingIntent, calendar.timeInMillis)
}
// Android 6-11 (API 23-30)
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
alarmManager.setExactAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
calendar.timeInMillis,
pendingIntent
)
Log.d(TAG, "Alarm scheduled using setExactAndAllowWhileIdle (API 23-30)")
}
// Android < 6 (API < 23)
else -> {
alarmManager.setExact(
AlarmManager.RTC_WAKEUP,
calendar.timeInMillis,
pendingIntent
)
Log.d(TAG, "Alarm scheduled using setExact (API < 23)")
}
}
}
/**
* Schedule alarm for Android 14+ (API 34+)
* Android 14 requires special handling for exact alarms.
*/
private fun scheduleForAndroid14Plus(
context: Context,
alarmManager: AlarmManager,
pendingIntent: PendingIntent,
triggerTime: Long
) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (alarmManager.canScheduleExactAlarms()) {
alarmManager.setExactAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
triggerTime,
pendingIntent
)
Log.d(TAG, "Alarm scheduled using setExactAndAllowWhileIdle (API 34+)")
} else {
// Fallback to inexact alarm if permission not granted
alarmManager.setAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
triggerTime,
pendingIntent
)
Log.w(TAG, "Exact alarm permission not granted, using setAndAllowWhileIdle (API 34+)")
}
}
} catch (e: SecurityException) {
Log.e(TAG, "SecurityException scheduling alarm: ${e.message}")
// Fallback to inexact alarm
alarmManager.setAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
triggerTime,
pendingIntent
)
}
}
/**
* Schedule alarm for Android 12-13 (API 31-33)
*/
private fun scheduleForAndroid12To13(
context: Context,
alarmManager: AlarmManager,
pendingIntent: PendingIntent,
triggerTime: Long
) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (alarmManager.canScheduleExactAlarms()) {
alarmManager.setExactAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
triggerTime,
pendingIntent
)
Log.d(TAG, "Alarm scheduled using setExactAndAllowWhileIdle (API 31-33)")
} else {
alarmManager.setAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
triggerTime,
pendingIntent
)
Log.w(TAG, "Exact alarm permission not granted, using setAndAllowWhileIdle (API 31-33)")
}
}
} catch (e: SecurityException) {
Log.e(TAG, "SecurityException scheduling alarm: ${e.message}")
alarmManager.setAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
triggerTime,
pendingIntent
)
}
}
/**
* Cancel the scheduled restart alarm.
*/
fun cancelRestartAlarm(context: Context) {
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val intent = Intent(context, RestartAlarmReceiver::class.java).apply {
action = RestartAlarmReceiver.ACTION_SCHEDULED_RESTART
}
val pendingIntent = PendingIntent.getBroadcast(
context,
RESTART_ALARM_REQUEST_CODE,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
alarmManager.cancel(pendingIntent)
Log.d(TAG, "Restart alarm cancelled")
}
/**
* Check if the app can schedule exact alarms.
* Returns true for Android < 12 (always allowed) or if permission is granted on Android 12+.
*/
fun canScheduleExactAlarms(context: Context): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarmManager.canScheduleExactAlarms()
} else {
true // Always allowed on older versions
}
}
/**
* Open system settings to request exact alarm permission (Android 12+).
*/
fun requestExactAlarmPermission(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
try {
val intent = Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
} catch (e: Exception) {
Log.e(TAG, "Error opening exact alarm settings: ${e.message}")
}
}
}
}

@ -4,128 +4,46 @@ import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Build
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.ServiceCompat
import androidx.lifecycle.LifecycleService
/**
* Foreground service that launches the app after device boot or scheduled restart.
* Compatible with Android 14+ (API 34+) and older versions.
*
* Android 14+ requires:
* - Explicit foreground service type in manifest and code
* - FOREGROUND_SERVICE_SPECIAL_USE permission
*/
class BootForegroundService : LifecycleService() {
companion object {
private const val TAG = "BootForegroundService"
private const val CHANNEL_ID = "boot_service_channel"
private const val NOTIFICATION_ID = 1
}
override fun onCreate() {
super.onCreate()
Log.d(TAG, "Service created - Android SDK: ${Build.VERSION.SDK_INT}")
startForegroundServiceCompat()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
val source = intent?.getStringExtra("source") ?: "unknown"
Log.d(TAG, "Service started from source: $source")
// Launch the main activity
launchMainActivity(source)
// Stop the service after launching the app
stopSelf()
return START_NOT_STICKY
startForegroundService()
}
/**
* Start foreground service with Android version compatibility.
* Android 14+ requires explicit foreground service type.
*/
private fun startForegroundServiceCompat() {
private fun startForegroundService() {
val channelId = "boot_service_channel"
createNotificationChannel()
val notification: Notification = NotificationCompat.Builder(this, CHANNEL_ID)
val notification: Notification = NotificationCompat.Builder(this, channelId)
.setContentTitle("QLine App")
.setContentText("Starting QLine...")
.setContentText("Monitoring QLine activity...")
.setSmallIcon(R.mipmap.ic_launcher)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setAutoCancel(true)
.build()
// Use ServiceCompat for Android 14+ compatibility
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
// Android 14+ (API 34+) requires explicit foreground service type
ServiceCompat.startForeground(
this,
NOTIFICATION_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
)
Log.d(TAG, "Foreground service started with SPECIAL_USE type (API 34+)")
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// Android 10-13 (API 29-33)
startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_NONE)
Log.d(TAG, "Foreground service started with NONE type (API 29-33)")
} else {
// Android 8-9 (API 26-28)
startForeground(NOTIFICATION_ID, notification)
Log.d(TAG, "Foreground service started (API 26-28)")
}
}
/**
* Launch the main activity.
*/
private fun launchMainActivity(source: String) {
try {
Log.d(TAG, "Launching MainActivity from source: $source")
val intent = Intent(this, MainActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra("launched_from_boot", source == "boot_completed")
putExtra("launched_from_scheduled_restart", source == "scheduled_restart")
}
startActivity(intent)
startForeground(1, notification)
Log.d(TAG, "MainActivity launched successfully")
} catch (e: Exception) {
Log.e(TAG, "Error launching MainActivity: ${e.message}")
// Only launch MainActivity if this service is started by the system (e.g. on boot)
val intent = Intent(this, MainActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
startActivity(intent)
stopSelf() // Stop the service after initialization
}
/**
* Create notification channel for Android 8.0+ (API 26+).
*/
private fun createNotificationChannel() {
val channelId = "boot_service_channel"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
CHANNEL_ID,
channelId,
"Boot Service Channel",
NotificationManager.IMPORTANCE_LOW // Use LOW to avoid sound/vibration
).apply {
description = "Used to start QLine app after device boot"
setShowBadge(false)
}
NotificationManager.IMPORTANCE_HIGH
)
val manager = getSystemService(NotificationManager::class.java)
manager?.createNotificationChannel(channel)
Log.d(TAG, "Notification channel created")
}
}
override fun onDestroy() {
super.onDestroy()
Log.d(TAG, "Service destroyed")
}
}

@ -6,58 +6,17 @@ import android.content.Intent
import android.os.Build
import android.util.Log
/**
* BroadcastReceiver that handles device boot events.
* Starts the app automatically after device boot and schedules daily restart alarm.
* Compatible with Android 14+ (API 34+) and older versions.
*/
class BootBroadcastReceiver : BroadcastReceiver() {
companion object {
private const val TAG = "BootBroadcastReceiver"
}
override fun onReceive(context: Context, intent: Intent) {
Log.d(TAG, "Received intent: ${intent.action}")
Log.d("BootReceiver", "Received intent: ${intent.action}")
if (intent.action == Intent.ACTION_BOOT_COMPLETED ||
intent.action == "android.intent.action.QUICKBOOT_POWERON" ||
intent.action == "com.htc.intent.action.QUICKBOOT_POWERON"
) {
Log.d(TAG, "Boot completed detected - Android SDK: ${Build.VERSION.SDK_INT}")
// Schedule the daily restart alarm first
scheduleRestartAlarm(context)
// Then start the foreground service to launch the app
startAppViaForegroundService(context)
}
}
/**
* Schedule daily restart alarm at 00:15.
* This ensures the alarm is set even if the app wasn't running before reboot.
*/
private fun scheduleRestartAlarm(context: Context) {
try {
Log.d(TAG, "Scheduling daily restart alarm after boot")
AlarmScheduler.scheduleRestartAlarm(context, 0, 15) // 00:15 (12:15 AM)
Log.d(TAG, "Daily restart alarm scheduled successfully")
} catch (e: Exception) {
Log.e(TAG, "Error scheduling restart alarm after boot: ${e.message}")
}
}
/**
* Start the app via foreground service.
* Uses different approach based on Android version for compatibility.
*/
private fun startAppViaForegroundService(context: Context) {
try {
Log.d(TAG, "Starting BootForegroundService")
val serviceIntent = Intent(context, BootForegroundService::class.java).apply {
putExtra("source", "boot_completed")
}
Log.d("BootReceiver", "Starting BootForegroundService.")
val serviceIntent = Intent(context, BootForegroundService::class.java)
// Use foreground service for Android 8.0+ (API 26+)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -65,30 +24,6 @@ class BootBroadcastReceiver : BroadcastReceiver() {
} else {
context.startService(serviceIntent)
}
Log.d(TAG, "BootForegroundService started successfully")
} catch (e: Exception) {
Log.e(TAG, "Error starting foreground service: ${e.message}")
// Fallback: try direct activity launch
tryDirectActivityLaunch(context)
}
}
/**
* Fallback method to launch activity directly if service fails.
*/
private fun tryDirectActivityLaunch(context: Context) {
try {
Log.d(TAG, "Attempting direct activity launch as fallback")
val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)?.apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra("launched_from_boot", true)
}
context.startActivity(launchIntent)
Log.d(TAG, "Direct activity launch successful")
} catch (fallbackError: Exception) {
Log.e(TAG, "Direct activity launch also failed: ${fallbackError.message}")
}
}
}

@ -1,8 +1,5 @@
package com.example.hmg_qline.hmg_qline
import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Handler
@ -16,168 +13,85 @@ import java.io.File
class MainActivity : FlutterActivity() {
private val CHANNEL = "com.example.hmg_qline/foreground"
companion object {
private const val TAG = "MainActivity"
}
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
Log.d(TAG, "MethodChannel call received: ${call.method}")
Log.d("MainActivity", "MethodChannel call received: ${call.method}")
when (call.method) {
"reopenApp" -> {
Log.d(TAG, "reopenApp called, bringing app to foreground")
Log.d("MainActivity", "reopenApp called, bringing app to foreground")
moveTaskToBack(false)
result.success("App brought to foreground")
}
"restartApp" -> {
Log.d(TAG, "Restarting application")
Log.d("MainActivity", "Restarting application")
restartApplication()
result.success("App restart initiated")
}
"restartDevice" -> {
Log.d(TAG, "Attempting device restart")
Log.d("MainActivity", "Attempting device restart")
restartDevice(result)
}
"runShellScript" -> {
Log.d(TAG, "Executing shell restart command")
Log.d("MainActivity", "Executing shell restart command")
executeShellRestart(result)
}
"clearAudioCache" -> {
Log.d(TAG, "Clearing audio cache")
Log.d("MainActivity", "Clearing audio cache")
clearAudioResources()
result.success("Audio cache cleared")
}
"clearAllResources" -> {
Log.d(TAG, "Clearing all native resources")
Log.d("MainActivity", "Clearing all native resources")
clearAllNativeResources()
result.success("All resources cleared")
}
// === NEW: Alarm Scheduling Methods for Android 14+ compatibility ===
"scheduleRestartAlarm" -> {
val hour = call.argument<Int>("hour") ?: 0
val minute = call.argument<Int>("minute") ?: 15
Log.d(TAG, "Scheduling restart alarm for $hour:$minute")
scheduleRestartAlarm(hour, minute)
result.success("Restart alarm scheduled for $hour:$minute")
}
"cancelRestartAlarm" -> {
Log.d(TAG, "Cancelling restart alarm")
AlarmScheduler.cancelRestartAlarm(this)
result.success("Restart alarm cancelled")
}
"canScheduleExactAlarms" -> {
val canSchedule = AlarmScheduler.canScheduleExactAlarms(this)
Log.d(TAG, "Can schedule exact alarms: $canSchedule")
result.success(canSchedule)
}
"requestExactAlarmPermission" -> {
Log.d(TAG, "Requesting exact alarm permission")
AlarmScheduler.requestExactAlarmPermission(this)
result.success("Permission request initiated")
}
else -> {
Log.w(TAG, "Method not implemented: ${call.method}")
Log.w("MainActivity", "Method not implemented: ${call.method}")
result.notImplemented()
}
}
}
}
/**
* Schedule daily restart alarm at specified time.
* Compatible with Android 14+ and older versions.
*/
private fun scheduleRestartAlarm(hour: Int, minute: Int) {
try {
AlarmScheduler.scheduleRestartAlarm(this, hour, minute)
Log.d(TAG, "Restart alarm scheduled successfully for $hour:$minute")
} catch (e: Exception) {
Log.e(TAG, "Error scheduling restart alarm: ${e.message}")
}
}
private fun restartApplication() {
try {
Log.d(TAG, "Initiating app restart")
Log.d("MainActivity", "Initiating app restart")
// Get the launch intent
val intent = packageManager.getLaunchIntentForPackage(packageName)
// Clear resources before restart
clearAllNativeResources()
if (intent != null) {
// Configure intent for clean restart
intent.apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra("restarted", true)
}
// Use AlarmManager for reliable restart (works better on Android 14+)
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
val pendingIntent = PendingIntent.getActivity(
this,
0,
intent,
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
)
// Schedule restart in 500ms
alarmManager.set(
AlarmManager.RTC,
System.currentTimeMillis() + 500,
pendingIntent
)
Log.d(TAG, "Restart scheduled via AlarmManager")
// Now safely exit the app
Handler(Looper.getMainLooper()).postDelayed({
finishAffinity()
android.os.Process.killProcess(android.os.Process.myPid())
}, 100)
} else {
Log.e(TAG, "Could not create restart intent")
}
} catch (e: Exception) {
Log.e(TAG, "Error during restart: ${e.message}")
// Fallback: try simple restart
fallbackRestart()
}
}
/**
* Fallback restart method if AlarmManager approach fails
*/
private fun fallbackRestart() {
try {
Log.d(TAG, "Attempting fallback restart")
// Create restart intent
val intent = packageManager.getLaunchIntentForPackage(packageName)?.apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
putExtra("restarted", true)
}
if (intent != null) {
startActivity(intent)
finishAffinity()
Runtime.getRuntime().exit(0)
// Use a shorter delay for faster restart
Handler(Looper.getMainLooper()).postDelayed({
startActivity(intent)
finishAffinity()
// Remove exitProcess() call if present
// android.os.Process.killProcess(android.os.Process.myPid())
}, 100) // Reduced delay
Log.d("MainActivity", "App restart initiated")
} else {
Log.e("MainActivity", "Could not create restart intent")
}
} catch (e: Exception) {
Log.e(TAG, "Fallback restart also failed: ${e.message}")
Log.e("MainActivity", "Error during restart: ${e.message}")
// Fallback - don't exit, just log the error
}
}
@ -323,43 +237,25 @@ class MainActivity : FlutterActivity() {
// Log if app was restarted
if (intent.getBooleanExtra("restarted", false)) {
Log.d(TAG, "App restarted successfully")
Log.d("MainActivity", "App restarted successfully")
}
// Log if launched from boot
if (intent.getBooleanExtra("launched_from_boot", false)) {
Log.d(TAG, "App launched from boot")
Log.d("MainActivity", "App launched from boot")
// Give system time to settle after boot
Thread.sleep(2000)
}
// Schedule daily restart alarm at 00:15 (12:15 AM)
// This ensures the alarm is always set when app starts
initializeRestartAlarm()
}
/**
* Initialize the daily restart alarm.
* Called on app start to ensure alarm is always scheduled.
*/
private fun initializeRestartAlarm() {
try {
Log.d(TAG, "Initializing daily restart alarm")
AlarmScheduler.scheduleRestartAlarm(this, 0, 15) // 00:15 (12:15 AM)
Log.d(TAG, "Daily restart alarm initialized for 00:15")
} catch (e: Exception) {
Log.e(TAG, "Error initializing restart alarm: ${e.message}")
}
}
override fun onResume() {
super.onResume()
Log.d(TAG, "Activity resumed")
Log.d("MainActivity", "Activity resumed")
}
override fun onPause() {
super.onPause()
Log.d(TAG, "Activity paused - cleaning up resources")
Log.d("MainActivity", "Activity paused - cleaning up resources")
// Light cleanup when app goes to background
System.gc()
@ -367,7 +263,7 @@ class MainActivity : FlutterActivity() {
override fun onDestroy() {
super.onDestroy()
Log.d(TAG, "Activity destroyed")
Log.d("MainActivity", "Activity destroyed")
// Final cleanup
clearAllNativeResources()

@ -1,82 +0,0 @@
package com.example.hmg_qline.hmg_qline
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
/**
* BroadcastReceiver for handling scheduled app restart alarms.
* This is triggered by AlarmManager at the scheduled time (e.g., 12:15 AM).
* Compatible with Android 14+ (API 34+) and older versions.
*/
class RestartAlarmReceiver : BroadcastReceiver() {
companion object {
private const val TAG = "RestartAlarmReceiver"
const val ACTION_SCHEDULED_RESTART = "com.example.hmg_qline.SCHEDULED_RESTART"
}
override fun onReceive(context: Context, intent: Intent) {
Log.d(TAG, "Received intent: ${intent.action}")
when (intent.action) {
ACTION_SCHEDULED_RESTART -> {
Log.d(TAG, "Scheduled restart triggered")
launchApp(context)
// Re-schedule the alarm for the next day
rescheduleAlarm(context)
}
Intent.ACTION_BOOT_COMPLETED,
"android.intent.action.QUICKBOOT_POWERON",
"com.htc.intent.action.QUICKBOOT_POWERON" -> {
Log.d(TAG, "Boot completed - re-scheduling daily restart alarm")
rescheduleAlarm(context)
}
}
}
private fun launchApp(context: Context) {
try {
Log.d(TAG, "Launching app via foreground service")
val serviceIntent = Intent(context, BootForegroundService::class.java).apply {
putExtra("source", "scheduled_restart")
}
// Use foreground service for Android 8.0+ (API 26+)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(serviceIntent)
} else {
context.startService(serviceIntent)
}
Log.d(TAG, "App launch initiated successfully")
} catch (e: Exception) {
Log.e(TAG, "Error launching app: ${e.message}")
// Fallback: try direct activity launch
try {
val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)?.apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
context.startActivity(launchIntent)
} catch (fallbackError: Exception) {
Log.e(TAG, "Fallback launch also failed: ${fallbackError.message}")
}
}
}
private fun rescheduleAlarm(context: Context) {
try {
// Re-schedule for the next day at 00:15
AlarmScheduler.scheduleRestartAlarm(context, 0, 15)
Log.d(TAG, "Alarm rescheduled for next day at 00:15")
} catch (e: Exception) {
Log.e(TAG, "Error rescheduling alarm: ${e.message}")
}
}
}

@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '2.1.0'
ext.kotlin_version = '1.9.10'
repositories {
google()
mavenCentral()

@ -19,7 +19,7 @@ pluginManagement {
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.7.0" apply false
id "org.jetbrains.kotlin.android" version "2.1.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

@ -0,0 +1,4 @@
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.8333 3.99984C15.8333 3.26346 16.4303 2.6665 17.1667 2.6665H29.1667C29.903 2.6665 30.5 3.26346 30.5 3.99984C30.5 4.73622 29.903 5.33317 29.1667 5.33317L29.1667 23.3332C29.1667 26.6469 26.4804 29.3332 23.1667 29.3332C19.853 29.3332 17.1667 26.6469 17.1667 23.3332L17.1667 9.33405C17.1667 9.33376 17.1667 9.33434 17.1667 9.33405C17.1667 9.33376 17.1667 9.33259 17.1667 9.33229V5.33317C16.4303 5.33317 15.8333 4.73622 15.8333 3.99984ZM19.8333 7.99984V5.33317H26.5L26.5 13.0676C26.1378 13.317 25.8055 13.5125 25.4733 13.6324C25.0059 13.8012 24.5708 13.8095 24.0425 13.4925C22.6945 12.6837 21.4241 12.879 20.3715 13.4052C20.1897 13.4961 20.0098 13.5996 19.8333 13.7111V10.6665H22.5C23.2364 10.6665 23.8333 10.0695 23.8333 9.33317C23.8333 8.59679 23.2364 7.99984 22.5 7.99984H19.8333Z" fill="#2E3039"/>
<path d="M7.14104 12.6116C7.52794 12.2404 8.13873 12.2404 8.52562 12.6116L8.53329 12.6193C8.69353 12.7817 9.1478 13.2422 9.40228 13.5185C9.91854 14.0791 10.6087 14.8721 11.3012 15.7994C11.9917 16.7239 12.6985 17.8007 13.2361 18.9287C13.7693 20.0478 14.1667 21.2805 14.1667 22.4998C14.1667 24.7601 13.4124 26.4319 12.1558 27.5235C10.9246 28.5931 9.33325 28.9998 7.83333 28.9998C6.33342 28.9998 4.74203 28.5931 3.51084 27.5235C2.25425 26.4319 1.5 24.7601 1.5 22.4998C1.5 21.2805 1.89732 20.0478 2.4306 18.9287C2.96813 17.8007 3.67498 16.7239 4.36544 15.7994C5.05795 14.8721 5.74813 14.0791 6.26439 13.5185C6.51888 13.2422 6.97318 12.7817 7.1334 12.6193L7.14104 12.6116Z" fill="#2E3039"/>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

@ -2,12 +2,11 @@ import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:hmg_qline/services/logger_service.dart';
import 'package:hmg_qline/utilities/api_exception.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
import 'package:hmg_qline/utilities/api_exception.dart';
typedef FactoryConstructor<U> = U Function(dynamic);
@ -37,9 +36,6 @@ class ApiClientImp implements ApiClient {
var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: headers0, retryTimes: retryTimes);
try {
if (!kReleaseMode) {
log("responseBody:${response.body}");
}
if (!kReleaseMode) {
log("statusCode:${response.statusCode}");
}
@ -99,9 +95,9 @@ class ApiClientImp implements ApiClient {
loggerService.logInfo("------Payload------");
loggerService.logInfo(jsonDecode(requestBody).toString());
loggerService.logInfo("------Response------");
loggerService.logInfo(jsonDecode(response.body).toString());
log(jsonDecode(response.body).toString());
// loggerService.logInfo(jsonDecode(response.body).toString());
}
if (response.statusCode >= 200 && response.statusCode < 500) {
var jsonData = jsonDecode(response.body);
if (jsonData["StatusMessage"] != null && jsonData["StatusMessage"] == "Unauthorized user attempt to access API") {

@ -8,11 +8,11 @@ bool useTestIP = false;
bool isNeedToBreakVoiceForArabic = true;
bool isSpeechCompleted = true;
bool isAndroid14 = true;
class AppStrings {
static String timeRemainingText = "Time Remaining";
static String namazTimeText = "Namaz Time";
static String poweredBy = "Powered By";
static String appName = "QLine";
static String fontNamePoppins = "Poppins";
@ -157,6 +157,7 @@ class AppAssets {
static String newVitalSignIcon = "assets/images/vitalsign_icon.svg";
static String newDoctorIcon = "assets/images/doctor_icon.svg";
static String textBgLeaf = "assets/new_design_icons/text_bg_leaf.svg";
static String labIcon = "assets/new_design_icons/lab_icon.svg";
}
class AppConstants {
@ -167,8 +168,9 @@ class AppConstants {
static String apiKey = 'EE17D21C7943485D9780223CCE55DCE5';
static String testIP = '12.4.5.1'; // projectID.QlineType.ScreenType.AnyNumber (1 to 10)
static int thresholdForListUI = 5;
static double currentBuildVersion = 9.3;
static double currentBuildVersion = 9.2;
static double clearLogsHoursThreshold = 48;
// Maximum log file size in bytes before rotation/clearing. Default 2 MB.
static int maxLogFileSizeBytes = 2 * 1024 * 1024;
}
@ -178,7 +180,8 @@ class ApiConstants {
static String baseUrlUat = 'https://ms.hmg.com/nscapi'; // UAT
static String baseUrlDev = 'https://ms.hmg.com/nscapi2'; // DEV
static String baseUrl = baseUrlLive;
// static String baseUrl = baseUrlLive;
static String baseUrl = baseUrlDev;
static String baseUrlHub = '$baseUrl/PatientCallingHub';
static String baseUrlApi = '$baseUrl/api';
static String baseUrlApiGen = '$baseUrl/api/Gen';
@ -235,13 +238,7 @@ class MockJsonRepo {
static TicketData ticket = TicketData(
id: 189805,
patientID: 4292695,
laBQGroupID: null,
queueNo: 'FMC W-T-4',
counterBatchNo: null,
calledBy: null,
calledOn: null,
servedOn: null,
patientName: null,
queueNo: 'W-T-4',
mobileNo: '0598544522',
patientEmail: 'munira.ali@hotmail.com',
preferredLang: 2,
@ -250,22 +247,17 @@ class MockJsonRepo {
postVoiceText: 'Call for Vital Signs',
patientGender: 2,
roomNo: 'D 12',
isActive: null,
createdBy: null,
editedBy: null,
editedOn: DateTime.parse('2025-08-18 15:09:03.633'),
createdOn: DateTime.parse('2025-08-18 15:06:07.363'),
doctorNameN: null,
callTypeEnum: CallTypeEnum.doctor,
queueNoM: 'FMC W-T-4',
callNoStr: 'FMC W-T-4',
queueNoM: 'W-T-4',
callNoStr: 'W_T-4',
isQueue: false,
isToneReq: false,
isVoiceReq: false,
orientationType: 0,
isTurnOn: false,
concurrentCallDelaySec: 0,
crTypeAckIP: null,
voiceLanguageText: 'English',
vitalSignText: 'علامة حيوية',
doctorText: 'الطبيب',
@ -281,9 +273,6 @@ class MockJsonRepo {
queueNoText: 'رقم الانتظار',
callForText: 'التوجه الى',
);
}
// RAW DATA:

@ -1,17 +1,17 @@
import 'dart:async';
import 'dart:developer';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hmg_qline/view_models/screen_config_view_model.dart';
import 'package:provider/provider.dart';
import 'package:hmg_qline/config/dependency_injection.dart';
import 'package:hmg_qline/config/routes.dart';
import 'package:hmg_qline/constants/app_constants.dart';
import 'package:hmg_qline/services/crash_handler_service.dart';
import 'package:hmg_qline/view_models/queuing_view_model.dart';
import 'package:hmg_qline/view_models/screen_config_view_model.dart';
import 'package:hmg_qline/views/view_helpers/size_config.dart';
import 'package:provider/provider.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
import 'package:hmg_qline/services/crash_handler_service.dart';
void main() {
runZonedGuarded(() async {
@ -43,11 +43,13 @@ class MyApp extends StatelessWidget {
return LayoutBuilder(
builder: (context, constraints) {
return OrientationBuilder(builder: (context, orientation) {
log("orientationorientation: ${orientation.toString()}");
SizeConfig().init(constraints, orientation);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
if (!isAndroid14) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
}
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
log("orientationorientation: ${orientation.toString()}");
return MultiProvider(
providers: [
ChangeNotifierProvider<ScreenConfigViewModel>(

@ -1,5 +1,3 @@
import 'dart:developer';
class GenericRespModel {
GenericRespModel({
this.data,
@ -14,7 +12,6 @@ class GenericRespModel {
String? message;
factory GenericRespModel.fromJson(Map<String, dynamic> json) {
log("jsonjsonjosn: $json");
if (json.containsKey('StatusMessage')) {
if ((json['StatusMessage'] as String).contains('Internal server error')) {
// Utils.showToast("${json['StatusMessage']}");

@ -1,5 +1,4 @@
import 'dart:ui';
import 'package:hmg_qline/constants/app_constants.dart';
import 'package:hmg_qline/models/kiosk_language_config_model.dart';
import 'package:hmg_qline/models/kiosk_queue_model.dart';
@ -26,7 +25,8 @@ class GlobalConfigurationsModel {
int? priorityWhatsApp;
int? priorityEmail;
String ticketNoText = "Ticket Number";
String postVoiceText = "Please Visit Counter";
String pleaseVisitCounterTextEn = "Please Visit Counter";
String pleaseVisitCounterTextAr = "Please Visit Counter";
int? roomNo;
bool? isRoomNoRequired;
@ -38,12 +38,12 @@ class GlobalConfigurationsModel {
String? counterTextArb;
String? queueNoTextArb;
String? callForTextArb;
String? currentServeTextEng;
String? currentServeTextEng = "Current Serving";
String? currentServeTextArb;
String maxText = "";
String minText = "";
String nextPrayerTextEng = "Next Prayer";
String nextPrayerTextArb = "الصلا<EFBFBD><EFBFBD> القادمة";
String nextPrayerTextArb = "الصلاة القادمة";
String weatherText = "Weather";
String? fajarTextEng;
String? dhuhrTextEng;
@ -69,8 +69,6 @@ class GlobalConfigurationsModel {
bool isWeatherReq = false;
bool isPrayerTimeReq = false;
bool isRssFeedReq = false;
bool globalClinicPrefixReq = false;
bool clinicPrefixReq = true;
QTypeEnum qTypeEnum = QTypeEnum.appointment;
ScreenTypeEnum screenTypeEnum = ScreenTypeEnum.waitingAreaScreen;
int? projectID;
@ -80,7 +78,6 @@ class GlobalConfigurationsModel {
List<KioskQueueModel>? kioskQueueList;
List<KioskLanguageConfigModel>? kioskLanguageConfigList;
// Indicates whether the screen belongs to Takhasusi main (based on its IP)
bool isFromTakhasusiMain = false;
String vitalSignTextEng = "Vital Sign";
@ -105,6 +102,12 @@ class GlobalConfigurationsModel {
String callForVaccinationTextArb = "الرجاء التوجّه إلى غرفة التطعيم";
String callForNebulizationTextArb = "الرجاء التوجّه إلى غرفة البخاخة";
static String defaultIfNullOrEmpty(dynamic value, String def) {
if (value == null) return def;
if (value is String && value.trim().isEmpty) return def;
return value.toString();
}
GlobalConfigurationsModel({
this.id,
this.configType,
@ -125,7 +128,8 @@ class GlobalConfigurationsModel {
this.priorityWhatsApp,
this.priorityEmail,
this.ticketNoText = "Ticket Number",
this.postVoiceText = "Please Visit Counter",
this.pleaseVisitCounterTextEn = "Please Visit Counter",
this.pleaseVisitCounterTextAr = "يرجى زيارة الكاونتر",
this.roomTextEng,
this.roomNo,
this.isRoomNoRequired = true,
@ -135,7 +139,7 @@ class GlobalConfigurationsModel {
this.counterTextArb,
this.queueNoTextArb,
this.callForTextArb,
this.currentServeTextEng,
this.currentServeTextEng = "Current Serving",
this.currentServeTextArb,
this.maxText = "",
this.minText = "",
@ -166,8 +170,6 @@ class GlobalConfigurationsModel {
this.isWeatherReq = false,
this.isPrayerTimeReq = false,
this.isRssFeedReq = false,
this.globalClinicPrefixReq = false,
this.clinicPrefixReq = true,
this.qTypeEnum = QTypeEnum.appointment,
this.screenTypeEnum = ScreenTypeEnum.waitingAreaScreen,
this.projectID,
@ -200,76 +202,73 @@ class GlobalConfigurationsModel {
});
GlobalConfigurationsModel.fromJson({required Map<String, dynamic> json, int qType = 1, int screenType = 1}) {
id = json['id'];
configType = json['configType'];
description = json['description'];
counterStart = json['counterStart'];
counterEnd = json['counterEnd'];
id = json['id'] ?? 0;
configType = json['configType'] ?? 0;
description = defaultIfNullOrEmpty(json['description'], "");
counterStart = json['counterStart'] ?? 0;
counterEnd = json['counterEnd'] ?? 0;
concurrentCallDelaySec = json['concurrentCallDelaySec'] ?? 1;
voiceType = json['voiceType'];
voiceTypeText = json['voiceTypeText'];
screenLanguageEnum = (json['screenLanguage'] as int).toLanguageEnum();
screenLanguageText = json['screenLanguageText'];
// textDirection = json['textDirection'] == 2 ? TextDirection.rtl : TextDirection.ltr;
textDirection = TextDirection.rtl;
voiceType = json['voiceType'] ?? 0;
voiceTypeText = defaultIfNullOrEmpty(json['voiceTypeText'], "");
screenLanguageEnum = ((json['screenLanguage'] ?? 1) as int).toLanguageEnum();
screenLanguageText = defaultIfNullOrEmpty(json['screenLanguageText'], "English");
textDirection = json['textDirection'] == 2 ? TextDirection.rtl : TextDirection.ltr;
voiceLanguageEnum = ((json['voiceLanguage'] ?? 1) as int).toLanguageEnum();
voiceLanguageText = defaultIfNullOrEmpty(json['voiceLanguageText'], "English");
screenMaxDisplayPatients = json['screenMaxDisplayPatients'] ?? 16;
// screenMaxDisplayPatients = 15;
voiceLanguageEnum = (json['voiceLanguage'] as int).toLanguageEnum();
voiceLanguageText = json['voiceLanguageText'];
isNotiReq = json['isNotiReq'];
prioritySMS = json['prioritySMS'];
priorityWhatsApp = json['priorityWhatsApp'];
priorityEmail = json['priorityEmail'];
ticketNoText = json['ticketNoText'] ?? "Ticket Number";
postVoiceText = json['pleaseVisitCounterText'] ?? "Please Visit Counter";
roomNo = json['roomNo'];
isNotiReq = json['isNotiReq'] ?? false;
prioritySMS = json['prioritySMS'] ?? 0;
priorityWhatsApp = json['priorityWhatsApp'] ?? 0;
priorityEmail = json['priorityEmail'] ?? 0;
ticketNoText = defaultIfNullOrEmpty(json['ticketNoText'], "Ticket Number");
pleaseVisitCounterTextEn = defaultIfNullOrEmpty(json['pleaseVisitCounterText'], "Please Visit Counter");
pleaseVisitCounterTextAr = defaultIfNullOrEmpty(json['pleaseVisitCounterTextAr'], "يرجى زيارة الكاونتر");
roomNo = json['roomNo'] ?? 0;
isRoomNoRequired = json['isRoomNoReq'] ?? true;
queueNoTextEng = json['queueNoText'];
callForTextEng = json['callForText'];
counterTextEng = json['counterText'];
roomTextEng = json['roomText'];
queueNoTextArb = json['queueNoTextAr'] ?? "الرقم";
callForTextArb = json['callForTextAr'] ?? "التوجه إلى";
counterTextArb = json['counterTextAr'] ?? "";
roomTextArb = json['roomTextAr'] ?? "الغرفة";
currentServeTextEng = json['currentServeText'];
currentServeTextArb = json['currentServeTextAr'] ?? "يتم خدمة";
maxText = json['maxText'] ?? "";
minText = json['minText'] ?? "";
nextPrayerTextEng = json['nextPrayerText'] ?? "Next Prayer";
nextPrayerTextArb = json['nextPrayerTextArb'] ?? "الصلاة القادمة";
weatherText = json['weatherText'] ?? "Weather";
fajarTextEng = json['fajarText'];
dhuhrTextEng = json['dhuhrText'];
asarTextEng = json['asarText'];
maghribTextEng = json['maghribText'];
ishaTextEng = json['ishaText'];
fajarTextArb = json['fajarTextAr'] ?? AppStrings.prayersArray[0];
dhuhrTextArb = json['dhuhrTextAr'] ?? AppStrings.prayersArray[1];
asarTextArb = json['asarTextAr'] ?? AppStrings.prayersArray[2];
maghribTextArb = json['maghribTextAr'] ?? AppStrings.prayersArray[3];
ishaTextArb = json['ishaTextAr'] ?? AppStrings.prayersArray[4];
isActive = json['isActive'];
createdBy = json['createdBy'];
createdOn = json['createdOn'];
queueNoTextEng = defaultIfNullOrEmpty(json['queueNoText'], "Queue Number");
callForTextEng = defaultIfNullOrEmpty(json['callForText'], "Please Proceed");
counterTextEng = defaultIfNullOrEmpty(json['counterText'], "Counter");
roomTextEng = defaultIfNullOrEmpty(json['roomText'], "Room");
queueNoTextArb = defaultIfNullOrEmpty(json['queueNoTextAr'], "الرقم");
callForTextArb = defaultIfNullOrEmpty(json['callForTextAr'], "التوجه إلى");
counterTextArb = defaultIfNullOrEmpty(json['counterTextAr'], "الكاونتر");
roomTextArb = defaultIfNullOrEmpty(json['roomTextAr'], "الغرفة");
currentServeTextEng = defaultIfNullOrEmpty(json['currentServeText'], "Current Serving");
currentServeTextArb = defaultIfNullOrEmpty(json['currentServeTextAr'], "يتم خدمة");
maxText = defaultIfNullOrEmpty(json['maxText'], "");
minText = defaultIfNullOrEmpty(json['minText'], "");
nextPrayerTextEng = defaultIfNullOrEmpty(json['nextPrayerText'], "Next Prayer");
nextPrayerTextArb = defaultIfNullOrEmpty(json['nextPrayerTextArb'], "الصلاة القادمة");
weatherText = defaultIfNullOrEmpty(json['weatherText'], "Weather");
fajarTextEng = defaultIfNullOrEmpty(json['fajarText'], "Fajr");
dhuhrTextEng = defaultIfNullOrEmpty(json['dhuhrText'], "Dhuhr");
asarTextEng = defaultIfNullOrEmpty(json['asarText'], "Asar");
maghribTextEng = defaultIfNullOrEmpty(json['maghribText'], "Maghrib");
ishaTextEng = defaultIfNullOrEmpty(json['ishaText'], "Isha");
fajarTextArb = defaultIfNullOrEmpty(json['fajarTextAr'], AppStrings.prayersArray[0]);
dhuhrTextArb = defaultIfNullOrEmpty(json['dhuhrTextAr'], AppStrings.prayersArray[1]);
asarTextArb = defaultIfNullOrEmpty(json['asarTextAr'], AppStrings.prayersArray[2]);
maghribTextArb = defaultIfNullOrEmpty(json['maghribTextAr'], AppStrings.prayersArray[3]);
ishaTextArb = defaultIfNullOrEmpty(json['ishaTextAr'], AppStrings.prayersArray[4]);
isActive = json['isActive'] ?? true;
createdBy = json['createdBy'] ?? 0;
createdOn = defaultIfNullOrEmpty(json['createdOn'], "");
editedBy = json['editedBy'];
editedOn = json['editedOn'];
isToneReq = json['isToneReq'] ?? false;
isVoiceReq = json['isVoiceReq'] ?? false;
orientationTypeEnum = ((json['orientationType'] ?? 1) as int).toScreenOrientationEnum();
isTurnOn = json['isTurnOn'];
waitingAreaType = json['waitingAreaType'];
gender = json['gender'];
isTurnOn = json['isTurnOn'] ?? true;
waitingAreaType = json['waitingAreaType'] ?? 0;
gender = json['gender'] ?? 0;
isWeatherReq = json['isWeatherReq'] ?? false;
isPrayerTimeReq = json['isPrayerTimeReq'] ?? false;
isRssFeedReq = json['isRssFeedReq'] ?? false;
globalClinicPrefixReq = json['globalClinicPrefixReq'] ?? false;
clinicPrefixReq = json['clinicPrefixReq'] ?? true;
qTypeEnum = ((json['qType'] ?? qType) as int).toQTypeEnum();
screenTypeEnum = ((json['screenType'] ?? screenType) as int).toScreenTypeEnum();
projectID = json['projectID'];
projectLatitude = json['projectLatitude'] == 0 ? 0.0 : json['projectLatitude'];
projectLongitude = json['projectLongitude'] == 0 ? 0.0 : json['projectLongitude'];
projectID = json['projectID'] ?? 0;
projectLatitude = json['projectLatitude']?.toDouble() ?? 0.0;
projectLongitude = json['projectLongitude']?.toDouble() ?? 0.0;
cityKey = json['cityKey'] ?? 0;
if (json['kioskQueue'] != null) {
kioskQueueList = List<KioskQueueModel>.from(json['kioskQueue'].map((kioskQueueJson) => KioskQueueModel.fromJson(kioskQueueJson)));
@ -277,38 +276,35 @@ class GlobalConfigurationsModel {
kioskQueueList = [];
}
if (json['kioskConfig'] != null) {
kioskLanguageConfigList =
List<KioskLanguageConfigModel>.from(json['kioskConfig'].map((kioskQueueJson) => KioskLanguageConfigModel.fromJson(kioskQueueJson)));
kioskLanguageConfigList = List<KioskLanguageConfigModel>.from(json['kioskConfig'].map((kioskQueueJson) => KioskLanguageConfigModel.fromJson(kioskQueueJson)));
} else {
kioskLanguageConfigList = [];
}
// Default to false; actual value (based on device IP) is set in ViewModel after loading config
isFromTakhasusiMain = false;
vitalSignTextEng = json['vitalSignText'] ?? "Vital Sign";
doctorTextEng = json['doctorText'] ?? "Doctor";
procedureTextEng = json['procedureText'] ?? "Procedure";
vaccinationTextEng = json['vaccinationText'] ?? "Vaccination";
nebulizationTextEng = json['nebulizationText'] ?? "Nebulization";
callForVitalSignTextEng = json['callForVitalSignText'] ?? "Call for Vital Sign";
callForDoctorTextEng = json['callForDoctorText'] ?? "Call for Doctor";
callForProcedureTextEng = json['callForProcedureText'] ?? "Call for Procedure";
callForVaccinationTextEng = json['callForVaccinationText'] ?? "Call for Vaccination";
callForNebulizationTextEng = json['callForNebulizationText'] ?? "Call for Nebulization";
vitalSignTextArb = json['vitalSignTextAr'] ?? "غرفة العلامات الحيوية";
doctorTextArb = json['doctorTextAr'] ?? " غرفة الطبيب";
procedureTextArb = json['procedureTextAr'] ?? "غرفة الإجراء";
vaccinationTextArb = json['vaccinationTextAr'] ?? "غرفة التطعيم";
nebulizationTextArb = json['nebulizationTextAr'] ?? "غرفة البخاخة";
callForVitalSignTextArb = json['callForVitalSignTextAr'] ?? " غرفة استدعاء للعلامات الحيوية";
callForDoctorTextArb = json['callForDoctorTextAr'] ?? "الرجاء التوجّه إلى غرفة الطبيب";
callForProcedureTextArb = json['callForProcedureTextAr'] ?? "الرجاء التوجّه إلى غرفة الإجراء";
callForVaccinationTextArb = json['callForVaccinationTextAr'] ?? "الرجاء لتوجّه إلى غرفة التطعيم";
callForNebulizationTextArb = json['callForNebulizationTextAr'] ?? "الرجاء التوجّه إلى غرفة البخاخة";
vitalSignTextEng = defaultIfNullOrEmpty(json['vitalSignText'], "Vital Sign");
doctorTextEng = defaultIfNullOrEmpty(json['doctorText'], "Doctor");
procedureTextEng = defaultIfNullOrEmpty(json['procedureText'], "Procedure");
vaccinationTextEng = defaultIfNullOrEmpty(json['vaccinationText'], "Vaccination");
nebulizationTextEng = defaultIfNullOrEmpty(json['nebulizationText'], "Nebulization");
callForVitalSignTextEng = defaultIfNullOrEmpty(json['callForVitalSignText'], "Call for Vital Sign");
callForDoctorTextEng = defaultIfNullOrEmpty(json['callForDoctorText'], "Call for Doctor");
callForProcedureTextEng = defaultIfNullOrEmpty(json['callForProcedureText'], "Call for Procedure");
callForVaccinationTextEng = defaultIfNullOrEmpty(json['callForVaccinationText'], "Call for Vaccination");
callForNebulizationTextEng = defaultIfNullOrEmpty(json['callForNebulizationText'], "Call for Nebulization");
vitalSignTextArb = defaultIfNullOrEmpty(json['vitalSignTextAr'], "العلامات الحيوية");
doctorTextArb = defaultIfNullOrEmpty(json['doctorTextAr'], "الطبيب");
procedureTextArb = defaultIfNullOrEmpty(json['procedureTextAr'], "الإجراء");
vaccinationTextArb = defaultIfNullOrEmpty(json['vaccinationTextAr'], "التطعيم");
nebulizationTextArb = defaultIfNullOrEmpty(json['nebulizationTextAr'], "البخاخة");
callForVitalSignTextArb = defaultIfNullOrEmpty(json['callForVitalSignTextAr'], "الرجاء التوجّه إلى غرفة العلامات الحيوية");
callForDoctorTextArb = defaultIfNullOrEmpty(json['callForDoctorTextAr'], "الرجاء التوجّه إلى غرفة الطبيب");
callForProcedureTextArb = defaultIfNullOrEmpty(json['callForProcedureTextAr'], "الرجاء التوجّه إلى غرفة الإجراء");
callForVaccinationTextArb = defaultIfNullOrEmpty(json['callForVaccinationTextAr'], "الرجاء التوجّه إلى غرفة التطعيم");
callForNebulizationTextArb = defaultIfNullOrEmpty(json['callForNebulizationTextAr'], "الرجاء التوجّه إلى غرفة البخاخة");
}
@override
String toString() {
return 'GlobalConfigurationsModel{id: $id, isFromTakhasusiMain: $isFromTakhasusiMain, configType: $configType, description: $description, counterStart: $counterStart, counterEnd: $counterEnd, concurrentCallDelaySec: $concurrentCallDelaySec, voiceType: $voiceType, voiceTypeText: $voiceTypeText, screenLanguageEnum: $screenLanguageEnum, screenLanguageText: $screenLanguageText, textDirection: $textDirection, voiceLanguageEnum: $voiceLanguageEnum, voiceLanguageText: $voiceLanguageText, screenMaxDisplayPatients: $screenMaxDisplayPatients, isNotiReq: $isNotiReq, prioritySMS: $prioritySMS, priorityWhatsApp: $priorityWhatsApp, priorityEmail: $priorityEmail, ticketNoText: $ticketNoText, postVoiceText: $postVoiceText, roomText: $roomTextEng, roomNo: $roomNo, isRoomNoRequired: $isRoomNoRequired, counterText: $counterTextEng, queueNoText: $queueNoTextEng, callForText: $callForTextEng, currentServeTextArb: $currentServeTextArb,, currentServeTextEng: $currentServeTextEng, maxText: $maxText, minText: $minText, nextPrayerTextEng: $nextPrayerTextEng, nextPrayerTextArb: $nextPrayerTextArb, weatherText: $weatherText, fajarText: $fajarTextEng, dhuhrText: $dhuhrTextEng, asarText: $asarTextEng, maghribText: $maghribTextEng, ishaText: $ishaTextEng, isActive: $isActive, createdBy: $createdBy, createdOn: $createdOn, editedBy: $editedBy, editedOn: $editedOn, isToneReq: $isToneReq, isVoiceReq: $isVoiceReq, orientationTypeEnum: $orientationTypeEnum, isTurnOn: $isTurnOn, waitingAreaType: $waitingAreaType, gender: $gender, isWeatherReq: $isWeatherReq, isPrayerTimeReq: $isPrayerTimeReq, isRssFeedReq: $isRssFeedReq, globalClinicPrefixReq: $globalClinicPrefixReq, clinicPrefixReq: $clinicPrefixReq, qTypeEnum: $qTypeEnum, screenTypeEnum: $screenTypeEnum, projectID: $projectID, projectLatitude: $projectLatitude, projectLongitude: $projectLongitude, cityKey: $cityKey, kioskQueueList: $kioskQueueList, kioskLanguageConfigList: $kioskLanguageConfigList, vitalSignText: $vitalSignTextEng, doctorText: $doctorTextEng, procedureText: $procedureTextEng, vaccinationText: $vaccinationTextEng, nebulizationText: $nebulizationTextEng, callForVitalSignText: $callForVitalSignTextEng, callForDoctorText: $callForDoctorTextEng, callForProcedureText: $callForProcedureTextEng, callForVaccinationText: $callForVaccinationTextEng, callForNebulizationText: $callForNebulizationTextEng, vitalSignTextArb: $vitalSignTextArb, doctorTextArb: $doctorTextArb, procedureTextArb: $procedureTextArb, vaccinationTextArb: $vaccinationTextArb, nebulizationTextArb: $nebulizationTextArb, callForVitalSignTextArb: $callForVitalSignTextArb, callForDoctorTextArb: $callForDoctorTextArb, callForProcedureTextArb: $callForProcedureTextArb, callForVaccinationTextArb: $callForVaccinationTextArb, callForNebulizationTextArb: $callForNebulizationTextArb}';
return 'GlobalConfigurationsModel{id: $id, isFromTakhasusiMain: $isFromTakhasusiMain, configType: $configType, description: $description, counterStart: $counterStart, counterEnd: $counterEnd, concurrentCallDelaySec: $concurrentCallDelaySec, voiceType: $voiceType, voiceTypeText: $voiceTypeText, screenLanguageEnum: $screenLanguageEnum, screenLanguageText: $screenLanguageText, textDirection: $textDirection, voiceLanguageEnum: $voiceLanguageEnum, voiceLanguageText: $voiceLanguageText, screenMaxDisplayPatients: $screenMaxDisplayPatients, isNotiReq: $isNotiReq, prioritySMS: $prioritySMS, priorityWhatsApp: $priorityWhatsApp, priorityEmail: $priorityEmail, ticketNoText: $ticketNoText, pleaseVisitCounterTextEn: $pleaseVisitCounterTextEn,pleaseVisitCounterTextAr: $pleaseVisitCounterTextAr, roomText: $roomTextEng, roomNo: $roomNo, isRoomNoRequired: $isRoomNoRequired, counterText: $counterTextEng, queueNoText: $queueNoTextEng, callForText: $callForTextEng, currentServeTextArb: $currentServeTextArb,, currentServeTextEng: $currentServeTextEng, maxText: $maxText, minText: $minText, nextPrayerTextEng: $nextPrayerTextEng, nextPrayerTextArb: $nextPrayerTextArb, weatherText: $weatherText, fajarText: $fajarTextEng, dhuhrText: $dhuhrTextEng, asarText: $asarTextEng, maghribText: $maghribTextEng, ishaText: $ishaTextEng, isActive: $isActive, createdBy: $createdBy, createdOn: $createdOn, editedBy: $editedBy, editedOn: $editedOn, isToneReq: $isToneReq, isVoiceReq: $isVoiceReq, orientationTypeEnum: $orientationTypeEnum, isTurnOn: $isTurnOn, waitingAreaType: $waitingAreaType, gender: $gender, isWeatherReq: $isWeatherReq, isPrayerTimeReq: $isPrayerTimeReq, isRssFeedReq: $isRssFeedReq, qTypeEnum: $qTypeEnum, screenTypeEnum: $screenTypeEnum, projectID: $projectID, projectLatitude: $projectLatitude, projectLongitude: $projectLongitude, cityKey: $cityKey, kioskQueueList: $kioskQueueList, kioskLanguageConfigList: $kioskLanguageConfigList, vitalSignText: $vitalSignTextEng, doctorText: $doctorTextEng, procedureText: $procedureTextEng, vaccinationText: $vaccinationTextEng, nebulizationText: $nebulizationTextEng, callForVitalSignText: $callForVitalSignTextEng, callForDoctorText: $callForDoctorTextEng, callForProcedureText: $callForProcedureTextEng, callForVaccinationText: $callForVaccinationTextEng, callForNebulizationText: $callForNebulizationTextEng, vitalSignTextArb: $vitalSignTextArb, doctorTextArb: $doctorTextArb, procedureTextArb: $procedureTextArb, vaccinationTextArb: $vaccinationTextArb, nebulizationTextArb: $nebulizationTextArb, callForVitalSignTextArb: $callForVitalSignTextArb, callForDoctorTextArb: $callForDoctorTextArb, callForProcedureTextArb: $callForProcedureTextArb, callForVaccinationTextArb: $callForVaccinationTextArb, callForNebulizationTextArb: $callForNebulizationTextArb}';
}
}

@ -11,104 +11,105 @@ class TicketDetailsModel {
TicketDetailsModel({this.qTypeEnum, this.screenTypeEnum, this.connectionID, this.ticketModel});
TicketDetailsModel.fromJson(Map<String, dynamic> json) {
qTypeEnum = json['qType'] != null ? (json['qType'] as int).toQTypeEnum() : null;
screenTypeEnum = json['screenType'] != null ? (json['screenType'] as int).toScreenTypeEnum() : null;
connectionID = json['connectionID'];
qTypeEnum = json['qType'] != null ? (json['qType'] as int).toQTypeEnum() : QTypeEnum.appointment;
screenTypeEnum = json['screenType'] != null ? (json['screenType'] as int).toScreenTypeEnum() : ScreenTypeEnum.waitingAreaScreen;
connectionID = json['connectionID'] ?? '';
ticketModel = json['data'] != null
? TicketData.fromJson(
json['data'],
qTypeEnum: json['qType'] != null ? (json['qType'] as int).toQTypeEnum() : null,
qTypeEnum: qTypeEnum,
)
: null;
: TicketData(); // Use default empty TicketData if null
}
}
class TicketData {
int? id;
int? patientID;
int? laBQGroupID;
String? queueNo;
int? counterBatchNo;
int? calledBy;
String? calledOn;
String? servedOn;
String? patientName;
String? mobileNo;
String? patientEmail;
int? preferredLang;
LanguageEnum voiceLanguageEnum = LanguageEnum.english;
String ticketNoText = "Ticket Number";
String postVoiceText = "Please Visit Counter";
int? patientGender;
String? roomNo;
bool? isActive;
int? createdBy;
int? editedBy;
int id;
int patientID;
int laBQGroupID;
String queueNo;
int counterBatchNo;
int calledBy;
String calledOn;
String servedOn;
String patientName;
String mobileNo;
String patientEmail;
int preferredLang;
LanguageEnum voiceLanguageEnum;
String ticketNoText;
String postVoiceText;
int patientGender;
String roomNo;
bool isActive;
int createdBy;
int editedBy;
DateTime? editedOn;
DateTime? createdOn;
// New fields
String? doctorNameN;
CallTypeEnum callTypeEnum = CallTypeEnum.vitalSign;
String? queueNoM;
String? callNoStr;
bool? isQueue;
bool? isToneReq;
bool? isVoiceReq;
int? orientationType;
bool? isTurnOn;
int? concurrentCallDelaySec;
String? crTypeAckIP;
int voiceLanguage = 1;
String voiceLanguageText = "English";
String vitalSignText = "Vital Sign";
String doctorText = "Doctor";
String procedureText = "Procedure";
String vaccinationText = "Vaccination";
String nebulizationText = "Nebulization";
String callForVitalSignText = "Call for Vital Sign";
String callForDoctorText = "Call for Doctor";
String callForProcedureText = "Call for Procedure";
String callForVaccinationText = "Call for Vaccination";
String callForNebulizationText = "Call for Nebulization";
String roomText = "Room";
String queueNoText = "Counter";
String callForText = "Call For";
String doctorNameN;
CallTypeEnum callTypeEnum;
String queueNoM;
String callNoStr;
bool isQueue;
bool isToneReq;
bool isVoiceReq;
int orientationType;
bool isTurnOn;
int concurrentCallDelaySec;
String crTypeAckIP;
int voiceLanguage;
String voiceLanguageText;
String vitalSignText;
String doctorText;
String procedureText;
String vaccinationText;
String nebulizationText;
String callForVitalSignText;
String callForDoctorText;
String callForProcedureText;
String callForVaccinationText;
String callForNebulizationText;
String roomText;
String queueNoText;
String callForText;
TicketData({
this.id,
this.patientID,
this.laBQGroupID,
this.queueNo,
this.counterBatchNo,
this.calledBy,
this.calledOn,
this.servedOn,
this.patientName,
this.mobileNo,
this.patientEmail,
this.preferredLang,
this.id = 0,
this.patientID = 0,
this.laBQGroupID = 0,
this.queueNo = "",
this.counterBatchNo = 0,
this.calledBy = 0,
this.calledOn = "",
this.servedOn = "",
this.patientName = "",
this.mobileNo = "",
this.patientEmail = "",
this.preferredLang = 1,
this.voiceLanguageEnum = LanguageEnum.english,
this.ticketNoText = "Ticket Number",
this.postVoiceText = "Please Visit Counter",
this.patientGender,
this.roomNo,
this.isActive,
this.createdBy,
this.createdOn,
this.editedBy,
this.editedOn,
this.doctorNameN,
this.callTypeEnum = CallTypeEnum.vitalSign,
this.queueNoM,
this.callNoStr,
this.isQueue,
this.isToneReq,
this.isVoiceReq,
this.orientationType,
this.isTurnOn,
this.concurrentCallDelaySec,
this.crTypeAckIP,
this.patientGender = 1,
this.roomNo = "",
this.isActive = true,
this.createdBy = 0,
this.createdOn, // will fallback in fromJson (see below)
this.editedBy = 0,
this.editedOn, // will fallback in fromJson (see below)
this.doctorNameN = "",
this.callTypeEnum = CallTypeEnum.none,
this.queueNoM = "",
this.callNoStr = "",
this.isQueue = false,
this.isToneReq = false,
this.isVoiceReq = false,
this.orientationType = 1,
this.isTurnOn = true,
this.concurrentCallDelaySec = 1,
this.crTypeAckIP = "",
this.voiceLanguage = 1,
this.voiceLanguageText = "English",
this.vitalSignText = "Vital Sign",
this.doctorText = "Doctor",
@ -125,63 +126,61 @@ class TicketData {
this.callForText = "Call For",
});
TicketData.fromJson(Map<String, dynamic> json, {QTypeEnum? qTypeEnum}) {
id = json['id'];
patientID = json['patientID'];
laBQGroupID = json['laB_QGroupID'];
queueNo = json['queueNoM'];
counterBatchNo = json['counterBatchNo'];
calledBy = json['calledBy'];
calledOn = json['calledOn'];
servedOn = json['servedOn'];
patientName = json['patientName'];
mobileNo = json['mobileNo'];
patientEmail = json['patientEmail'];
preferredLang = (json['preferredLang'] != null && json['preferredLang'].toString().trim() != "") ? int.parse(json['preferredLang'].toString()) : 1;
voiceLanguageEnum = (json['preferredLang'] != null && json['preferredLang'].toString().trim() != "") ? (int.parse(json['preferredLang'].toString())).toLanguageEnum() : LanguageEnum.english;
ticketNoText = json['ticketNoText'] ?? "Ticket Number";
postVoiceText = json['pleaseVisitCounterText'] ?? "Please Visit Counter";
patientGender = json['patientGender'] ?? 1;
roomNo = json['roomNo']?.toString();
if (qTypeEnum != null && qTypeEnum == QTypeEnum.general) {
roomNo = json['counterNo']?.toString();
}
isActive = json['isActive'];
createdBy = json['createdBy'];
editedBy = json['editedBy'];
editedOn = json['editedOn'] != null ? (json['editedOn'] as String).toDateTime() : DateTime.now();
createdOn = json['createdOn'] != null ? (json['createdOn'] as String).toDateTime() : DateTime.now();
doctorNameN = json['doctorNameN'];
callTypeEnum = ((json['callType'] ?? 1) as int).toCallTypeEnum();
queueNoM = json['queueNoM'];
callNoStr = json['callNoStr'];
isQueue = json['isQueue'];
isToneReq = json['isToneReq'];
isVoiceReq = json['isVoiceReq'];
orientationType = json['orientationType'];
isTurnOn = json['isTurnOn'];
concurrentCallDelaySec = json['concurrentCallDelaySec'];
crTypeAckIP = json['crTypeAckIP'];
voiceLanguage = json['voiceLanguage'] ?? 1;
voiceLanguageText = json['voiceLanguageText'] ?? "English";
vitalSignText = json['vitalSignText'];
doctorText = json['doctorText'];
procedureText = json['procedureText'];
vaccinationText = json['vaccinationText'];
nebulizationText = json['nebulizationText'];
callForVitalSignText = json['callForVitalSignText'];
callForDoctorText = json['callForDoctorText'];
callForProcedureText = json['callForProcedureText'];
callForVaccinationText = json['callForVaccinationText'];
callForNebulizationText = json['callForNebulizationText'];
roomText = json['roomText'];
queueNoText = json['queueNoText'];
callForText = json['callForText'];
}
TicketData.fromJson(Map<String, dynamic> json, {QTypeEnum? qTypeEnum})
: id = json['id'] ?? 0,
patientID = json['patientID'] ?? 0,
laBQGroupID = json['laB_QGroupID'] ?? 0,
queueNo = json['queueNo'] ?? "",
counterBatchNo = json['counterBatchNo'] ?? 0,
calledBy = json['calledBy'] ?? 0,
calledOn = json['calledOn'] ?? "",
servedOn = json['servedOn'] ?? "",
patientName = json['patientName'] ?? "",
mobileNo = json['mobileNo'] ?? "",
patientEmail = json['patientEmail'] ?? "",
preferredLang = (json['preferredLang'] != null && json['preferredLang'].toString().trim() != "") ? int.parse(json['preferredLang'].toString()) : 1,
voiceLanguageEnum = (json['preferredLang'] != null && json['preferredLang'].toString().trim() != "") ? (int.parse(json['preferredLang'].toString())).toLanguageEnum() : LanguageEnum.english,
ticketNoText = json['ticketNoText'] ?? "Ticket Number",
postVoiceText = json['pleaseVisitCounterText'] ?? "Please Visit Counter",
patientGender = json['patientGender'] ?? 1,
roomNo = (() {
if (qTypeEnum != null && qTypeEnum == QTypeEnum.general) {
return json['counterNo']?.toString() ?? "";
}
return json['roomNo']?.toString() ?? "";
})(),
isActive = json['isActive'] ?? true,
createdBy = json['createdBy'] ?? 0,
editedBy = json['editedBy'] ?? 0,
createdOn = json['createdOn'] != null ? (json['createdOn'] as String).toDateTime() : DateTime.now(),
editedOn = json['editedOn'] != null ? (json['editedOn'] as String).toDateTime() : DateTime.now(),
doctorNameN = json['doctorNameN'] ?? "",
callTypeEnum = ((json['callType'] ?? 0) as int).toCallTypeEnum(),
queueNoM = json['queueNoM'] ?? "",
callNoStr = json['callNoStr'] ?? "",
isQueue = json['isQueue'] ?? false,
isToneReq = json['isToneReq'] ?? false,
isVoiceReq = json['isVoiceReq'] ?? false,
orientationType = json['orientationType'] ?? 1,
isTurnOn = json['isTurnOn'] ?? true,
concurrentCallDelaySec = json['concurrentCallDelaySec'] ?? 1,
crTypeAckIP = json['crTypeAckIP'] ?? "",
voiceLanguage = json['voiceLanguage'] ?? 1,
voiceLanguageText = json['voiceLanguageText'] ?? "English",
vitalSignText = json['vitalSignText'] ?? "Vital Sign",
doctorText = json['doctorText'] ?? "Doctor",
procedureText = json['procedureText'] ?? "Procedure",
vaccinationText = json['vaccinationText'] ?? "Vaccination",
nebulizationText = json['nebulizationText'] ?? "Nebulization",
callForVitalSignText = json['callForVitalSignText'] ?? "Call for Vital Sign",
callForDoctorText = json['callForDoctorText'] ?? "Call for Doctor",
callForProcedureText = json['callForProcedureText'] ?? "Call for Procedure",
callForVaccinationText = json['callForVaccinationText'] ?? "Call for Vaccination",
callForNebulizationText = json['callForNebulizationText'] ?? "Call for Nebulization",
roomText = json['roomText'] ?? "Room",
queueNoText = json['queueNoText'] ?? "Counter",
callForText = json['callForText'] ?? "Call For";
@override
String toString() {
return 'TicketData{id: $id, patientID: $patientID, laBQGroupID: $laBQGroupID, queueNo: $queueNo, counterBatchNo: $counterBatchNo, calledBy: $calledBy, calledOn: $calledOn, servedOn: $servedOn, patientName: $patientName, mobileNo: $mobileNo, patientEmail: $patientEmail, preferredLang: $preferredLang, voiceLanguageEnum: $voiceLanguageEnum, ticketNoText: $ticketNoText, postVoiceText: $postVoiceText, patientGender: $patientGender, roomNo: $roomNo, isActive: $isActive, createdBy: $createdBy, editedBy: $editedBy, editedOn: $editedOn, createdOn: $createdOn, doctorNameN: $doctorNameN, callTypeEnum: $callTypeEnum, queueNoM: $queueNoM, callNoStr: $callNoStr, isQueue: $isQueue, isToneReq: $isToneReq, isVoiceReq: $isVoiceReq, orientationType: $orientationType, isTurnOn: $isTurnOn, concurrentCallDelaySec: $concurrentCallDelaySec, crTypeAckIP: $crTypeAckIP, voiceLanguage: $voiceLanguage, voiceLanguageText: $voiceLanguageText, vitalSignText: $vitalSignText, doctorText: $doctorText, procedureText: $procedureText, vaccinationText: $vaccinationText, nebulizationText: $nebulizationText, callForVitalSignText: $callForVitalSignText, callForDoctorText: $callForDoctorText, callForProcedureText: $callForProcedureText, callForVaccinationText: $callForVaccinationText, callForNebulizationText: $callForNebulizationText, roomText: $roomText, queueNoText: $queueNoText, callForText: $callForText}';
}
String toString() => 'TicketData{id: $id, patientID: $patientID, laBQGroupID: $laBQGroupID, queueNo: $queueNo, ...}';
}

@ -1,5 +1,3 @@
import 'dart:developer';
import 'package:hmg_qline/api/api_client.dart';
import 'package:hmg_qline/constants/app_constants.dart';
import 'package:hmg_qline/models/generic_response_model.dart';
@ -39,7 +37,7 @@ class ScreenDetailsRepoImp implements ScreenDetailsRepo {
@override
Future<GlobalConfigurationsModel?> getGlobalScreenConfigurations({required String ipAddress}) async {
// try {
try {
var params = {
"ipAddress": ipAddress.toString(),
"apiKey": AppConstants.apiKey.toString(),
@ -49,24 +47,18 @@ class ScreenDetailsRepoImp implements ScreenDetailsRepo {
ApiConstants.commonConfigGet,
params,
);
List<GlobalConfigurationsModel> globalConfigurationsModel =
List.generate(genericModel.data.length, (index) => GlobalConfigurationsModel.fromJson(json: genericModel.data[index]));
List<GlobalConfigurationsModel> globalConfigurationsModel = List.generate(genericModel.data.length, (index) => GlobalConfigurationsModel.fromJson(json: genericModel.data[index]));
if (globalConfigurationsModel.isNotEmpty) {
loggerService.logToFile(
message: globalConfigurationsModel.toString(),
type: LogTypeEnum.data,
source: "getGlobalScreenConfigurations-> screen_details_repo.dart");
loggerService.logToFile(message: globalConfigurationsModel.toString(), type: LogTypeEnum.data, source: "getGlobalScreenConfigurations-> screen_details_repo.dart");
return globalConfigurationsModel.first;
}
return null;
// } catch (e) {
// log("record:");
// log(e.toString());
// loggerService.logError(e.toString());
// loggerService.logToFile(message: e.toString(), source: "getGlobalScreenConfigurations-> screen_details_repo.dart", type: LogTypeEnum.error);
// InfoComponents.showToast(e.toString());
// return null;
// }
} catch (e) {
loggerService.logError(e.toString());
loggerService.logToFile(message: e.toString(), source: "getGlobalScreenConfigurations-> screen_details_repo.dart", type: LogTypeEnum.error);
InfoComponents.showToast(e.toString());
return null;
}
}
@override
@ -113,8 +105,7 @@ class ScreenDetailsRepoImp implements ScreenDetailsRepo {
);
genericRespModel.data = KioskPatientTicket.fromJson(genericRespModel.data);
loggerService.logToFile(
message: genericRespModel.toString(), source: "createTicketFromKiosk-> screen_details_repo.dart", type: LogTypeEnum.data);
loggerService.logToFile(message: genericRespModel.toString(), source: "createTicketFromKiosk-> screen_details_repo.dart", type: LogTypeEnum.data);
return genericRespModel;
} catch (e) {
@ -151,11 +142,9 @@ class ScreenDetailsRepoImp implements ScreenDetailsRepo {
body,
);
List<WeathersWidgetModel> weathersWidgetModel =
List.generate(genericRespModel.data.length, (index) => WeathersWidgetModel.fromJson(genericRespModel.data[index]));
List<WeathersWidgetModel> weathersWidgetModel = List.generate(genericRespModel.data.length, (index) => WeathersWidgetModel.fromJson(genericRespModel.data[index]));
if (weathersWidgetModel.isNotEmpty) {
loggerService.logToFile(
message: weathersWidgetModel.toString(), source: "getWeatherDetailsByCity-> screen_details_repo.dart", type: LogTypeEnum.data);
loggerService.logToFile(message: weathersWidgetModel.toString(), source: "getWeatherDetailsByCity-> screen_details_repo.dart", type: LogTypeEnum.data);
return weathersWidgetModel.first;
}
return constantWeathersWidgetModel;
@ -177,11 +166,9 @@ class ScreenDetailsRepoImp implements ScreenDetailsRepo {
body,
);
List<PrayersWidgetModel> prayersWidgetModel =
List.generate(genericRespModel.data.length, (index) => PrayersWidgetModel.fromJson(genericRespModel.data[index]));
List<PrayersWidgetModel> prayersWidgetModel = List.generate(genericRespModel.data.length, (index) => PrayersWidgetModel.fromJson(genericRespModel.data[index]));
if (prayersWidgetModel.isNotEmpty) {
loggerService.logToFile(
message: prayersWidgetModel.toString(), source: "getPrayerDetailsByLatLong-> screen_details_repo.dart", type: LogTypeEnum.data);
loggerService.logToFile(message: prayersWidgetModel.toString(), source: "getPrayerDetailsByLatLong-> screen_details_repo.dart", type: LogTypeEnum.data);
return prayersWidgetModel.first;
}
@ -206,8 +193,7 @@ class ScreenDetailsRepoImp implements ScreenDetailsRepo {
List<RssFeedModel> rssFeedModel = List.generate(genericRespModel.data.length, (index) => RssFeedModel.fromJson(genericRespModel.data[index]));
if (rssFeedModel.isNotEmpty) {
loggerService.logToFile(
message: rssFeedModel.toString(), source: "getRssFeedDetailsByLanguageID-> screen_details_repo.dart", type: LogTypeEnum.data);
loggerService.logToFile(message: rssFeedModel.toString(), source: "getRssFeedDetailsByLanguageID-> screen_details_repo.dart", type: LogTypeEnum.data);
return rssFeedModel.first;
}
@ -243,8 +229,7 @@ class ScreenDetailsRepoImp implements ScreenDetailsRepo {
}
@override
Future<GenericRespModel?> acknowledgeTicketForAppointment(
{required int ticketId, required String ipAddress, required CallTypeEnum callTypeEnum}) async {
Future<GenericRespModel?> acknowledgeTicketForAppointment({required int ticketId, required String ipAddress, required CallTypeEnum callTypeEnum}) async {
try {
var params = {
"id": ticketId.toString(),

@ -1,5 +1,4 @@
import 'dart:developer';
import 'package:flutter_tts/flutter_tts.dart';
import 'package:hmg_qline/constants/app_constants.dart';
import 'package:hmg_qline/models/global_config_model.dart';
@ -7,6 +6,7 @@ import 'package:hmg_qline/models/ticket_model.dart';
import 'package:hmg_qline/services/logger_service.dart';
import 'package:hmg_qline/utilities/enums.dart';
import 'package:hmg_qline/utilities/extensions.dart';
import 'package:logger/logger.dart';
abstract class TextToSpeechService {
Future<void> speechText({
@ -15,6 +15,8 @@ abstract class TextToSpeechService {
bool isMute = false,
});
// Future<void> speechTextTest(TicketData ticket);
void listenToTextToSpeechEvents({required Function() onVoiceCompleted});
}
@ -28,6 +30,122 @@ class TextToSpeechServiceImp implements TextToSpeechService {
double pitch = 0.6;
Map<String, String> arabicVoice = {"name": "ar-xa-x-ard-local", "locale": "ar"};
@override
// Future<void> speechTextTest(TicketData ticket) async {
// const ttsGoogleEngine = 'com.google.android.tts';
// LanguageEnum langEnum = ticket.voiceLanguageEnum;
// List engines = await textToSpeechInstance.getEngines;
// if (engines.contains(ttsGoogleEngine)) {
// await textToSpeechInstance.setEngine(ttsGoogleEngine);
// }
//
// textToSpeechInstance.setVolume(1.0);
//
// // final voices = await textToSpeechInstance.getVoices;
// // log ("voices:: $voices");
//
// await textToSpeechInstance.setVoice(arabicVoice);
//
// if (langEnum == LanguageEnum.arabic) {
// try {
// await textToSpeechInstance.setLanguage(LanguageEnum.arabic.enumToString());
// } catch (e) {
// log("error setting language english: ${e.toString()}");
// }
// } else if (langEnum == LanguageEnum.english) {
// try {
// await textToSpeechInstance.setLanguage(LanguageEnum.english.enumToString());
// } catch (e) {
// log("error setting language english: ${e.toString()}");
// }
// }
// String preVoice = ticket.ticketNoText;
// String postVoice = ticket.postVoiceText;
// if (preVoice.isNotEmpty) {
// preVoice = '$preVoice..';
// }
// String ticketNo = ticket.queueNo!.trim().toString();
//
// log("areLanguagesInstalled: ${await textToSpeechInstance.areLanguagesInstalled(["en", "ar"])}");
//
// log("lang: $langEnum");
// log("preVoice: $preVoice");
// log("postVoice: $postVoice");
// log("ticketNo: $ticketNo");
//
// String patientAlpha = "";
// String patientNumeric = "";
// String clinicName = "";
//
// bool isClinicNameAdded = (ticket.queueNo != ticket.callNoStr);
//
// if (isClinicNameAdded) {
// var queueNo = "";
// var clinic = ticketNo.split(" ");
// if (clinic.length > 1) {
// clinicName = clinic[0];
// queueNo = clinic[1];
// } else {
// queueNo = ticketNo;
// }
//
// var queueNoArray = queueNo.split("-");
// if (queueNoArray.length > 2) {
// patientAlpha = "${queueNoArray[0]} .. ${queueNoArray[1]}";
// patientNumeric = queueNoArray[2];
// } else {
// patientAlpha = queueNoArray[0];
// patientNumeric = queueNoArray[1];
// }
// } else {
// var queueNoArray = ticketNo.split("-");
// if (queueNoArray.length > 2) {
// patientAlpha = "${queueNoArray[0]} .. ${queueNoArray[1]}";
// patientNumeric = queueNoArray[2];
// } else {
// patientAlpha = queueNoArray[0];
// patientNumeric = queueNoArray[1];
// }
// }
//
// patientAlpha = patientAlpha.split('').join(' .. ');
// String roomNo = "";
//
// log("I will now all this:{ $preVoice .. $clinicName .. $patientAlpha .. $patientNumeric .. $postVoice $roomNo } ");
//
// if (langEnum == LanguageEnum.english) {
// await textToSpeechInstance.speak("$preVoice .. $clinicName .. $patientAlpha .. $patientNumeric .. $postVoice $roomNo");
// return;
// }
//
// if (isNeedToBreakVoiceForArabic) {
// await textToSpeechInstance.awaitSpeakCompletion(true);
//
// isSpeechCompleted = false;
// if (preVoice.isNotEmpty) {
// await textToSpeechInstance.speak("$preVoice ");
// }
// try {
// await textToSpeechInstance.setLanguage(LanguageEnum.english.enumToString());
// } catch (e) {
// log("error setting language english: ${e.toString()}");
// }
// await textToSpeechInstance.speak("$patientAlpha .. $patientNumeric");
//
// try {
// await textToSpeechInstance.setLanguage(langEnum.enumToString());
// } catch (e) {
// log("error setting language langEnum: ${e.toString()}");
// }
//
// await textToSpeechInstance.speak("$postVoice $roomNo").whenComplete(() {
// isSpeechCompleted = true;
// });
// } else {
// await textToSpeechInstance.speak("$preVoice .. $clinicName .. $patientAlpha .. $patientNumeric .. $postVoice $roomNo");
// }
// }
@override
Future<void> speechText({
required TicketDetailsModel ticket,
@ -51,16 +169,7 @@ class TextToSpeechServiceImp implements TextToSpeechService {
textToSpeechInstance.setVolume(1.0);
}
if (isAndroid14) {
if (langEnum == LanguageEnum.arabic) {
textToSpeechInstance.setSpeechRate(0.5);
} else {
textToSpeechInstance.setSpeechRate(0.4);
}
textToSpeechInstance.setPitch(0.9);
} else {
textToSpeechInstance.setSpeechRate(0.4);
}
textToSpeechInstance.setSpeechRate(0.4);
if (langEnum == LanguageEnum.arabic) {
try {
await textToSpeechInstance.setLanguage(LanguageEnum.arabic.enumToString());
@ -82,9 +191,7 @@ class TextToSpeechServiceImp implements TextToSpeechService {
postVoice = ticket.ticketModel!.postVoiceText;
}
String roomNo = '';
if (globalConfigurationsModel.qTypeEnum != QTypeEnum.appointment &&
ticket.ticketModel!.roomNo != null &&
ticket.ticketModel!.roomNo!.isNotEmpty) {
if (globalConfigurationsModel.qTypeEnum != QTypeEnum.appointment && ticket.ticketModel!.roomNo != null && ticket.ticketModel!.roomNo!.isNotEmpty) {
roomNo = ".. ${ticket.ticketModel!.roomNo.toString()}";
}

@ -166,6 +166,7 @@ extension LanguageEnumToString on LanguageEnum {
extension XCallType on CallTypeEnum {
Color getColorByCallType() {
log("getColorByCallType: $this");
if (this == CallTypeEnum.vitalSign) {
return AppColors.newVitalSignColor;
} else if (this == CallTypeEnum.doctor) {
@ -176,9 +177,10 @@ extension XCallType on CallTypeEnum {
return AppColors.vaccinationColor;
} else if (this == CallTypeEnum.nebulization) {
return AppColors.nebulizationColor;
} else {
return Colors.black54;
} else if (this == CallTypeEnum.none) {
return AppColors.newDoctorColor;
}
return AppColors.newDoctorColor;
}
String getMessageByCallTypeForEnglish(GlobalConfigurationsModel globalConfig, {bool isListView = false}) {
@ -194,7 +196,7 @@ extension XCallType on CallTypeEnum {
case CallTypeEnum.nebulization:
return !isListView ? globalConfig.callForNebulizationTextEng : globalConfig.nebulizationTextEng;
case CallTypeEnum.none:
return !isListView ? globalConfig.callForVitalSignTextEng : globalConfig.vitalSignTextEng;
return !isListView ? (globalConfig.pleaseVisitCounterTextEn ?? '') : (globalConfig.counterTextEng ?? '');
}
}
@ -211,11 +213,15 @@ extension XCallType on CallTypeEnum {
case CallTypeEnum.nebulization:
return !isListView ? globalConfig.callForNebulizationTextArb : globalConfig.nebulizationTextArb;
case CallTypeEnum.none:
return !isListView ? globalConfig.callForVitalSignTextArb : globalConfig.vitalSignTextArb;
return !isListView ? (globalConfig.pleaseVisitCounterTextAr ?? '') : (globalConfig.counterTextArb ?? '');
}
}
SvgPicture getIconByCallType(double height, {double? width, BoxFit fit = BoxFit.contain}) {
Widget getIconByCallType(double height, QTypeEnum qType, {double? width, BoxFit fit = BoxFit.contain}) {
if (this == CallTypeEnum.vitalSign) {
return const SizedBox.shrink();
}
String iconPath = "";
if (this == CallTypeEnum.vitalSign) {
iconPath = AppAssets.newVitalSignIcon;
@ -229,6 +235,10 @@ extension XCallType on CallTypeEnum {
iconPath = AppAssets.nebulizationIcon;
}
if (qType == QTypeEnum.lab) {
iconPath = AppAssets.labIcon;
}
return SvgPicture.asset(
iconPath.isEmpty ? "assets/images/wait.svg" : iconPath,
height: height,
@ -251,7 +261,7 @@ extension XCallType on CallTypeEnum {
case CallTypeEnum.nebulization:
return 5;
case CallTypeEnum.none:
return 1;
return 0;
}
}
@ -268,7 +278,7 @@ extension XCallType on CallTypeEnum {
case CallTypeEnum.nebulization:
return AppColors.gradientBorderComboForVitalSigns;
case CallTypeEnum.none:
return AppColors.gradientBorderComboForVitalSigns;
return AppColors.gradientBorderComboForDoctor;
}
}
@ -284,8 +294,8 @@ extension XCallType on CallTypeEnum {
return ticket.callForVaccinationText;
case CallTypeEnum.nebulization:
return ticket.callForNebulizationText;
default:
return ticket.callForVitalSignText;
case CallTypeEnum.none:
return '';
}
}
}
@ -297,7 +307,7 @@ extension XCallTypeInt on int {
if (this == 3) return CallTypeEnum.procedure;
if (this == 4) return CallTypeEnum.vaccination;
if (this == 5) return CallTypeEnum.nebulization;
return CallTypeEnum.vitalSign;
return CallTypeEnum.none;
}
}

@ -12,19 +12,6 @@ abstract class NativeMethodChannelService {
Future<void> clearAllResources();
Future<void> smartRestart({bool forceRestart = false, bool cleanupFirst = true});
/// Schedule daily restart alarm at specified time.
/// Works on Android 14+ and older versions.
Future<void> scheduleRestartAlarm({int hour = 0, int minute = 15});
/// Cancel the scheduled restart alarm.
Future<void> cancelRestartAlarm();
/// Check if the app can schedule exact alarms (Android 12+).
Future<bool> canScheduleExactAlarms();
/// Request permission to schedule exact alarms (Android 12+).
Future<void> requestExactAlarmPermission();
}
class NativeMethodChannelServiceImp implements NativeMethodChannelService {
@ -105,85 +92,4 @@ class NativeMethodChannelServiceImp implements NativeMethodChannelService {
loggerService.logError("Primary restart failed, trying fallback methods: $primaryError");
}
}
// === NEW: Alarm Scheduling Methods for Android 14+ compatibility ===
/// Schedule daily restart alarm at specified time.
/// Default is 00:15 (12:15 AM).
/// Works on Android 14+ and older versions.
@override
Future<void> scheduleRestartAlarm({int hour = 0, int minute = 15}) async {
try {
loggerService.logInfo("Scheduling restart alarm for $hour:$minute");
// First check if we can schedule exact alarms
final canSchedule = await canScheduleExactAlarms();
if (!canSchedule) {
loggerService.logInfo("Exact alarm permission not granted. Requesting permission...");
await requestExactAlarmPermission();
}
await _platform.invokeMethod('scheduleRestartAlarm', {
'hour': hour,
'minute': minute,
});
loggerService.logInfo("Restart alarm scheduled successfully for $hour:$minute");
} catch (e) {
loggerService.logError("Error scheduling restart alarm: $e");
loggerService.logToFile(
message: "Error scheduling restart alarm: $e",
source: "scheduleRestartAlarm -> native_method_handler.dart",
type: LogTypeEnum.error,
);
}
}
/// Cancel the scheduled restart alarm.
@override
Future<void> cancelRestartAlarm() async {
try {
loggerService.logInfo("Cancelling restart alarm");
await _platform.invokeMethod('cancelRestartAlarm');
loggerService.logInfo("Restart alarm cancelled successfully");
} catch (e) {
loggerService.logError("Error cancelling restart alarm: $e");
loggerService.logToFile(
message: "Error cancelling restart alarm: $e",
source: "cancelRestartAlarm -> native_method_handler.dart",
type: LogTypeEnum.error,
);
}
}
/// Check if the app can schedule exact alarms.
/// Returns true on Android < 12 (always allowed) or if permission is granted on Android 12+.
@override
Future<bool> canScheduleExactAlarms() async {
try {
final result = await _platform.invokeMethod('canScheduleExactAlarms');
loggerService.logInfo("Can schedule exact alarms: $result");
return result ?? false;
} catch (e) {
loggerService.logError("Error checking exact alarm permission: $e");
return false;
}
}
/// Request permission to schedule exact alarms (Android 12+).
/// Opens system settings for the user to grant permission.
@override
Future<void> requestExactAlarmPermission() async {
try {
loggerService.logInfo("Requesting exact alarm permission");
await _platform.invokeMethod('requestExactAlarmPermission');
loggerService.logInfo("Exact alarm permission request initiated");
} catch (e) {
loggerService.logError("Error requesting exact alarm permission: $e");
loggerService.logToFile(
message: "Error requesting exact alarm permission: $e",
source: "requestExactAlarmPermission -> native_method_handler.dart",
type: LogTypeEnum.error,
);
}
}
}

@ -94,8 +94,8 @@ class QueuingViewModel extends ChangeNotifier {
loggerService.logToFile(message: response.toString(), source: "onHubTicketCall -> queueing_view_model.dart ", type: LogTypeEnum.data);
log("onHubTicketCall: $response");
log("isCallingInProgress: $isCallingInProgress");
log("isCallingInProgress: $isCallingInProgress");
if (response != null && response.isNotEmpty) {
TicketDetailsModel ticketDetailsModel = TicketDetailsModel.fromJson(response.first as Map<String, dynamic>);
addNewTicket(ticketDetailsModel);
@ -215,7 +215,9 @@ class QueuingViewModel extends ChangeNotifier {
callTypeEnum: ticketData.callTypeEnum,
);
} else {
screenConfigViewModel.acknowledgeTicket(ticketQueueID: ticketData.id ?? 0);
screenConfigViewModel.acknowledgeTicket(ticketQueueID: ticketData.id ?? 0,
ipAddress: screenConfigViewModel.currentScreenIP,
);
}
log("globalConfigurationsModel: ${globalConfigurationsModel.toString()}");

@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:developer';
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:hmg_qline/config/dependency_injection.dart';
@ -50,19 +49,16 @@ class ScreenConfigViewModel extends ChangeNotifier {
}
Future<void> onAppResumed() async {
loggerService.logToFile(
message: "[didChangeAppLifecycleState] : [onAppResumed]", source: "onAppResumed -> screen_config_view_model.dart", type: LogTypeEnum.data);
loggerService.logToFile(message: "[didChangeAppLifecycleState] : [onAppResumed]", source: "onAppResumed -> screen_config_view_model.dart", type: LogTypeEnum.data);
}
Future<void> onAppPaused() async {
loggerService.logToFile(
message: "[didChangeAppLifecycleState] : [onAppPaused]", source: "onAppPaused -> screen_config_view_model.dart", type: LogTypeEnum.data);
loggerService.logToFile(message: "[didChangeAppLifecycleState] : [onAppPaused]", source: "onAppPaused -> screen_config_view_model.dart", type: LogTypeEnum.data);
// nativeMethodChannelService.restartApp();
}
Future<void> onAppDetached() async {
loggerService.logToFile(
message: "[didChangeAppLifecycleState] : [onAppDetached]", source: "onAppDetached -> screen_config_view_model.dart", type: LogTypeEnum.data);
loggerService.logToFile(message: "[didChangeAppLifecycleState] : [onAppDetached]", source: "onAppDetached -> screen_config_view_model.dart", type: LogTypeEnum.data);
// nativeMethodChannelService.restartApp();
}
@ -233,9 +229,7 @@ class ScreenConfigViewModel extends ChangeNotifier {
Future<void> getWeatherDetailsFromServer() async {
int testCityKey = 297030;
WeathersWidgetModel? response = await screenDetailsRepo.getWeatherDetailsByCity(
cityId:
((globalConfigurationsModel.cityKey == null || globalConfigurationsModel.cityKey == 0) ? testCityKey : globalConfigurationsModel.cityKey)
.toString(),
cityId: ((globalConfigurationsModel.cityKey == null || globalConfigurationsModel.cityKey == 0) ? testCityKey : globalConfigurationsModel.cityKey).toString(),
);
if (response == null) {
@ -342,7 +336,7 @@ class ScreenConfigViewModel extends ChangeNotifier {
DateTime now = DateTime.now();
log("counterValue: $counter");
if (globalConfigurationsModel.id == null || state == ViewState.error) {
if (globalConfigurationsModel.id == null) {
await getGlobalConfigurationsByIP();
}
@ -399,9 +393,7 @@ class ScreenConfigViewModel extends ChangeNotifier {
Future<void> getLastTimeLogsClearedFromCache() async {
lastTimeLogsCleared = await cacheService.getLastTimeLogsCleared();
if (lastTimeLogsCleared == null) {
await cacheService
.setLastTimeLogsCleared(lastTimeCleared: DateTime.now().millisecondsSinceEpoch)
.whenComplete(() => lastTimeLogsCleared = DateTime.now());
await cacheService.setLastTimeLogsCleared(lastTimeCleared: DateTime.now().millisecondsSinceEpoch).whenComplete(() => lastTimeLogsCleared = DateTime.now());
}
}
@ -485,9 +477,9 @@ class ScreenConfigViewModel extends ChangeNotifier {
}
}
Future<void> acknowledgeTicket({required int ticketQueueID}) async {
Future<void> acknowledgeTicket({required int ticketQueueID, required String ipAddress}) async {
GenericRespModel? response = await screenDetailsRepo.acknowledgeTicket(
ipAddress: currentScreenIP,
ipAddress: ipAddress,
ticketQueueID: ticketQueueID,
qTypeEnum: globalConfigurationsModel.qTypeEnum,
);
@ -499,8 +491,7 @@ class ScreenConfigViewModel extends ChangeNotifier {
}
}
Future<void> acknowledgeTicketForAppointmentOnly(
{required int ticketQueueID, required String ipAddress, required CallTypeEnum callTypeEnum}) async {
Future<void> acknowledgeTicketForAppointmentOnly({required int ticketQueueID, required String ipAddress, required CallTypeEnum callTypeEnum}) async {
GenericRespModel? response = await screenDetailsRepo.acknowledgeTicketForAppointment(
ticketId: ticketQueueID,
ipAddress: ipAddress,

@ -1,9 +1,6 @@
import 'dart:async'; // Add this import
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:hmg_qline/models/ticket_model.dart';
import 'package:hmg_qline/view_models/queuing_view_model.dart';
import 'package:hmg_qline/view_models/screen_config_view_model.dart';
import 'package:hmg_qline/views/common_widgets/app_general_widgets.dart';
import 'package:hmg_qline/views/common_widgets/date_display_widget.dart';
@ -312,16 +309,11 @@ class _AppFooterState extends State<AppFooter> {
Padding(
padding: EdgeInsets.only(top: SizeConfig.getHeightMultiplier()! * 0.1),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
InkWell(
onTap: () {
// context.read<QueuingViewModel>().addNewTicket(TicketDetailsModel(ticketModel: MockJsonRepo.ticket));
},
child: AppText(
AppStrings.poweredBy,
fontSize: SizeConfig.getWidthMultiplier()! * 1.5,
fontWeight: FontWeight.w400,
color: AppColors.darkGreyTextColor,
),
AppText(
AppStrings.poweredBy,
fontSize: SizeConfig.getWidthMultiplier()! * 1.5,
fontWeight: FontWeight.w400,
color: AppColors.darkGreyTextColor,
),
AppText(
"v${screenConfigVM.currentScreenIP.replaceAll(".", "-")}(${AppConstants.currentBuildVersion})",

@ -1,3 +1,5 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hmg_qline/constants/app_constants.dart';
@ -128,7 +130,7 @@ Widget counterNoText({required int counterNo, required bool isRoomNoRequired, re
fontFamily: AppStrings.fontNamePoppins,
textAlign: TextAlign.center,
fontWeight: FontWeight.bold,
color: isRoomNoRequired ? Colors.black : Colors.transparent,
color: isRoomNoRequired ? AppColors.greyTextColor : Colors.transparent,
fontSize: SizeConfig.getWidthMultiplier() * 8,
);
}

@ -1,14 +1,19 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hmg_qline/config/dependency_injection.dart';
import 'package:hmg_qline/constants/app_constants.dart';
import 'package:hmg_qline/models/global_config_model.dart';
import 'package:hmg_qline/utilities/enums.dart';
import 'package:hmg_qline/utilities/native_method_handler.dart';
import 'package:hmg_qline/view_models/queuing_view_model.dart';
import 'package:hmg_qline/view_models/screen_config_view_model.dart';
import 'package:hmg_qline/views/common_widgets/app_general_widgets.dart';
import 'package:hmg_qline/views/view_helpers/size_config.dart';
import 'package:provider/provider.dart';
import 'package:hmg_qline/constants/app_constants.dart';
import 'package:hmg_qline/views/common_widgets/app_texts_widget.dart';
import 'package:hmg_qline/views/view_helpers/size_config.dart';
class AppHeader extends StatelessWidget implements PreferredSizeWidget {
const AppHeader({super.key});
@ -29,10 +34,8 @@ class AppHeader extends StatelessWidget implements PreferredSizeWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: () async {
final nativeMethodChannelService = getIt.get<NativeMethodChannelService>();
await nativeMethodChannelService.smartRestart(forceRestart: true, cleanupFirst: true);
onTap: () {
// getIt.get<QueuingViewModel>().triggerOOM();
},
child: engArabicTextWithSeparatorWidget(

@ -3,10 +3,12 @@ import 'package:flutter/material.dart';
import 'package:hmg_qline/models/global_config_model.dart';
import 'package:hmg_qline/models/ticket_model.dart';
import 'package:hmg_qline/utilities/enums.dart';
import 'package:hmg_qline/view_models/screen_config_view_model.dart';
import 'package:hmg_qline/views/common_widgets/app_general_widgets.dart';
import 'package:hmg_qline/views/main_queue_screen/components/ticket_item_calling_card.dart';
import 'package:hmg_qline/views/main_queue_screen/components/ticket_item_normal_card.dart';
import 'package:hmg_qline/views/view_helpers/size_config.dart';
import 'package:provider/provider.dart';
class PriorityTickets extends StatelessWidget {
final List<TicketDetailsModel> tickets;
@ -93,7 +95,10 @@ class PriorityTickets extends StatelessWidget {
}
Widget _buildPrimaryTicket(BuildContext context, TicketDetailsModel ticket, {bool isFullWidth = false, bool isHalf = false}) {
final screenConfigViewModel = context.read<ScreenConfigViewModel>();
Widget primaryCallingCard = QueueItemCallingCard(
qTypeEnum: screenConfigViewModel.currentQTypeEnum,
isGradientRequired: true,
isBorderRequired: true,
isSingleTicket: isFullWidth,
@ -103,7 +108,8 @@ class PriorityTickets extends StatelessWidget {
roomNo: ticket.ticketModel?.roomNo ?? '',
roomText: _getRoomText(),
roomTextAr: _getRoomTextAr(),
callTypeEnum: ticket.ticketModel?.callTypeEnum ?? CallTypeEnum.vitalSign,
isClinicAdded: false,
callTypeEnum: ticket.ticketModel?.callTypeEnum ?? CallTypeEnum.none,
textDirection: globalConfigurationsModel.textDirection,
screenTypeEnum: globalConfigurationsModel.screenTypeEnum,
langTypeEnum: globalConfigurationsModel.screenLanguageEnum,
@ -130,7 +136,7 @@ class PriorityTickets extends StatelessWidget {
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.6, // 60% of screen width
minHeight: SizeConfig.getHeightMultiplier() * 2.5, // Minimum height
minHeight: SizeConfig.getHeightMultiplier() * 2, // Minimum height
),
child: Transform.scale(
scale: _getTicketScale() + 0.2,
@ -144,12 +150,15 @@ class PriorityTickets extends StatelessWidget {
}
Widget _buildSecondaryTicket(BuildContext context, TicketDetailsModel ticket, {EdgeInsets? margin, bool isHalf = false}) {
final screenConfigViewModel = context.read<ScreenConfigViewModel>();
Widget secondaryCallingCard = QueueItemNormalCard(
qTypeEnum: screenConfigViewModel.currentQTypeEnum,
ticketNo: ticket.ticketModel?.queueNo ?? '',
roomNo: ticket.ticketModel?.roomNo ?? '',
roomText: _getRoomText(),
roomTextAr: _getRoomTextAr(),
callTypeEnum: ticket.ticketModel?.callTypeEnum ?? CallTypeEnum.vitalSign,
isClinicAdded: false,
callTypeEnum: ticket.ticketModel?.callTypeEnum ?? CallTypeEnum.none,
textDirection: globalConfigurationsModel.textDirection,
screenTypeEnum: globalConfigurationsModel.screenTypeEnum,
langTypeEnum: globalConfigurationsModel.screenLanguageEnum,
@ -185,7 +194,7 @@ class PriorityTickets extends StatelessWidget {
// Helper methods to reduce repetition
double _getTicketScale() {
return globalConfigurationsModel.screenTypeEnum == ScreenTypeEnum.roomLevelScreen
? 2.0
? 1.5
: globalConfigurationsModel.isFromTakhasusiMain
? 0.8
: 1.2;

@ -48,62 +48,62 @@ class PriorityTicketsWithSideSection extends StatelessWidget {
),
),
),
if (globalConfigurationsModel.qTypeEnum == QTypeEnum.appointment) ...[
Expanded(
flex: 8,
child: SizedBox(
height: SizeConfig.getHeightMultiplier() * 0.25,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ticketModel.callTypeEnum.getIconByCallType(SizeConfig.getHeightMultiplier() * 0.2),
],
),
// if (globalConfigurationsModel.qTypeEnum == QTypeEnum.appointment) ...[
Expanded(
flex: 8,
child: SizedBox(
height: SizeConfig.getHeightMultiplier() * 0.25,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ticketModel.callTypeEnum.getIconByCallType(SizeConfig.getHeightMultiplier() * 0.2, globalConfigurationsModel.qTypeEnum),
],
),
Expanded(
flex: 9,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
),
Expanded(
flex: 9,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
flex: 3,
child: AppText(
callMessageAr,
color: ticketModel.callTypeEnum.getColorByCallType(),
fontSize: SizeConfig.getWidthMultiplier() * 1.8,
fontWeight: FontWeight.bold,
fontFamily: AppStrings.fontNameGesTwo,
fontHeight: 1,
textOverflow: TextOverflow.clip,
maxLines: 1,
),
),
SizedBox(width: SizeConfig.getWidthMultiplier()),
if (callMessageEng.isNotEmpty) ...[
Expanded(
flex: 3,
flex: 2,
child: AppText(
callMessageAr,
"($callMessageEng)",
color: ticketModel.callTypeEnum.getColorByCallType(),
fontSize: SizeConfig.getWidthMultiplier() * 1.8,
fontWeight: FontWeight.bold,
fontFamily: AppStrings.fontNameGesTwo,
fontFamily: AppStrings.fontNamePoppins,
fontHeight: 1,
textOverflow: TextOverflow.clip,
maxLines: 1,
),
),
SizedBox(width: SizeConfig.getWidthMultiplier()),
if (callMessageEng.isNotEmpty) ...[
Expanded(
flex: 3,
child: AppText(
"($callMessageEng)",
color: ticketModel.callTypeEnum.getColorByCallType(),
fontSize: SizeConfig.getWidthMultiplier() * 1.8,
fontFamily: AppStrings.fontNamePoppins,
fontHeight: 1,
),
),
]
],
),
]
],
),
],
),
),
],
),
),
],
),
// ],
Expanded(
flex: 2,
child: Center(
@ -124,8 +124,6 @@ class PriorityTicketsWithSideSection extends StatelessWidget {
);
}
@override
Widget build(BuildContext context) {
List<TicketDetailsModel> priorityTickets = [];
@ -170,7 +168,7 @@ class PriorityTicketsWithSideSection extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 4,
flex: 3,
child: engArabicTextWithSeparatorWidget(
englishText: globalConfigurationsModel.queueNoTextEng ?? "",
arabicText: globalConfigurationsModel.queueNoTextArb ?? "",

@ -1,5 +1,3 @@
import 'dart:developer';
import 'package:blinking_text/blinking_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
@ -16,6 +14,7 @@ class QueueItemCallingCard extends StatelessWidget {
final String roomNo;
final bool blink;
final double scale;
final bool isClinicAdded;
final bool isGradientRequired;
final bool isBorderRequired;
final TextDirection textDirection;
@ -25,10 +24,12 @@ class QueueItemCallingCard extends StatelessWidget {
final CallTypeEnum callTypeEnum;
final ScreenTypeEnum screenTypeEnum;
final LanguageEnum langTypeEnum;
final QTypeEnum qTypeEnum;
final bool isSingleTicket;
const QueueItemCallingCard({
super.key,
required this.isClinicAdded,
required this.ticketNo,
required this.roomNo,
required this.scale,
@ -39,22 +40,28 @@ class QueueItemCallingCard extends StatelessWidget {
required this.callTypeEnum,
required this.screenTypeEnum,
required this.langTypeEnum,
required this.qTypeEnum,
this.isGradientRequired = false,
this.isBorderRequired = false,
this.isSingleTicket = false,
this.blink = false,
});
bool shouldReduceSize(String ticketNo) {
// Use regex to check if ticket starts with exactly 3 letters followed by " W-"
final hasClinicPrefix = RegExp(r'^[A-Za-z]{3} W-').hasMatch(ticketNo);
return hasClinicPrefix;
String getFormattedTicket(String ticketNo, bool isClinicAdded) {
if (isClinicAdded) {
var formattedString = ticketNo.split(" ");
if (formattedString.length > 1) {
return "${formattedString[0]} ${formattedString[1]}";
} else {
return ticketNo;
}
}
return ticketNo;
}
@override
Widget build(BuildContext context) {
final text = "${callTypeEnum.getMessageByCallTypeForEnglish(globalConfigurationsModel, isListView: false)} | $roomText $roomNo";
final text = callTypeEnum.getMessageByCallTypeForEnglish(globalConfigurationsModel, isListView: false) + (qTypeEnum == QTypeEnum.appointment ? ("| $roomText $roomNo") : "");
return Stack(
children: [
customShadowSmoothContainerWithBackground(
@ -77,7 +84,7 @@ class QueueItemCallingCard extends StatelessWidget {
left: textDirection == TextDirection.rtl ? SizeConfig.getWidthMultiplier() * 3.5 : 0,
right: textDirection == TextDirection.ltr ? SizeConfig.getWidthMultiplier() * 3.5 : 0,
),
child: callTypeEnum.getIconByCallType(SizeConfig.getHeightMultiplier() * 0.5),
child: callTypeEnum.getIconByCallType(SizeConfig.getHeightMultiplier() * 0.5, qTypeEnum),
),
SizedBox(height: SizeConfig.getHeightMultiplier()! * 0.15),
IntrinsicWidth(
@ -102,8 +109,8 @@ class QueueItemCallingCard extends StatelessWidget {
top: SizeConfig.getHeightMultiplier() * 0.25,
),
child: AppText(
ticketNo,
fontSize: shouldReduceSize(ticketNo) ? SizeConfig.getWidthMultiplier() * 6 : SizeConfig.getWidthMultiplier() * 7.4,
getFormattedTicket(ticketNo, isClinicAdded),
fontSize: SizeConfig.getWidthMultiplier() * 7.4,
letterSpacing: -1,
fontHeight: 0.5,
color: AppColors.greyTextColor,

@ -11,18 +11,21 @@ import 'package:hmg_qline/views/view_helpers/size_config.dart';
class QueueItemNormalCard extends StatelessWidget {
final String ticketNo;
final String roomNo;
final bool isClinicAdded;
final TextDirection textDirection;
final String roomText;
final String roomTextAr;
final GlobalConfigurationsModel globalConfigurationsModel;
final CallTypeEnum callTypeEnum;
final ScreenTypeEnum screenTypeEnum;
final QTypeEnum qTypeEnum;
final LanguageEnum langTypeEnum;
final double? height;
final double? width;
const QueueItemNormalCard({
super.key,
required this.isClinicAdded,
required this.ticketNo,
required this.roomNo,
required this.textDirection,
@ -32,20 +35,27 @@ class QueueItemNormalCard extends StatelessWidget {
required this.callTypeEnum,
required this.screenTypeEnum,
required this.langTypeEnum,
required this.qTypeEnum,
this.height,
this.width,
});
bool shouldReduceSize(String ticketNo) {
// Use regex to check if ticket starts with exactly 3 letters followed by " W-"
final hasClinicPrefix = RegExp(r'^[A-Za-z]{3} W-').hasMatch(ticketNo);
return hasClinicPrefix;
String getFormattedTicket(String ticketNo, bool isClinicAdded) {
if (isClinicAdded) {
var formattedString = ticketNo.split(" ");
if (formattedString.length > 1) {
return "${formattedString[0]} ${formattedString[1]}";
} else {
return ticketNo;
}
}
return ticketNo;
}
@override
Widget build(BuildContext context) {
final text = "${callTypeEnum.getMessageByCallTypeForEnglish(globalConfigurationsModel, isListView: false)} | $roomText $roomNo";
final text = callTypeEnum.getMessageByCallTypeForEnglish(globalConfigurationsModel, isListView: false) + (qTypeEnum == QTypeEnum.appointment ? ("| $roomText $roomNo") : "");
return Stack(
children: [
customShadowSmoothContainer(
@ -66,8 +76,8 @@ class QueueItemNormalCard extends StatelessWidget {
flex: 3,
child: Center(
child: AppText(
ticketNo,
fontSize: shouldReduceSize(ticketNo) ? SizeConfig.getWidthMultiplier() * 2.5 : SizeConfig.getWidthMultiplier() * 5,
getFormattedTicket(ticketNo, isClinicAdded),
fontSize: SizeConfig.getWidthMultiplier() * 5,
letterSpacing: -1,
fontHeight: 0.5,
color: AppColors.greyTextColor,
@ -80,12 +90,12 @@ class QueueItemNormalCard extends StatelessWidget {
flex: 3,
child: Row(
children: [
callTypeEnum.getIconByCallType(SizeConfig.getHeightMultiplier() * 0.35),
callTypeEnum.getIconByCallType(SizeConfig.getHeightMultiplier() * 0.35, qTypeEnum),
],
),
),
Flexible(
flex: 4,
flex: 2,
child: Center(
child: AppText(
textAlign: TextAlign.center,
@ -108,7 +118,7 @@ class QueueItemNormalCard extends StatelessWidget {
padding: EdgeInsets.all(SizeConfig.getHeightMultiplier() * 0.05),
color: callTypeEnum.getColorByCallType(),
child: engArabicTextWithSeparatorWidget(
fontSize: SizeConfig.getWidthMultiplier()! * 1.8,
fontSize: qTypeEnum != QTypeEnum.appointment ? SizeConfig.getWidthMultiplier()! * 1.9 : SizeConfig.getWidthMultiplier()! * 1.8,
englishText: roomNo.extractNumbersIfLong(),
arabicText: roomTextAr,
color: AppColors.whiteColor,

@ -69,7 +69,7 @@ class _MainQueueScreenState extends State<MainQueueScreen> {
// counterNo: 0,
// roomText: '',
// );
log("screenConfigViewModel: ${screenConfigViewModel.currentScreenIP}");
if (screenConfigViewModel.currentQTypeEnum == QTypeEnum.general) {
text = AppStrings.awaitingQueueNumberEng;
}
@ -192,9 +192,7 @@ class _MainQueueScreenState extends State<MainQueueScreen> {
// context.read<ScreenConfigViewModel>().createAutoTickets(numOfTicketsToCreate: 20);
// context.read<QueuingViewModel>().testSpeech();
return RotatedBox(
quarterTurns: globalConfigurationsModel.isFromTakhasusiMain
? screenOrientationEnum.getTurnsByOrientationForOlderVersions()
: screenOrientationEnum.getTurnsByOrientation(),
quarterTurns: globalConfigurationsModel.isFromTakhasusiMain ? screenOrientationEnum.getTurnsByOrientationForOlderVersions() : screenOrientationEnum.getTurnsByOrientation(),
child: AppScaffold(
backgroundColor: AppColors.backgroundColor,
appBar: const AppHeader(),
@ -206,3 +204,4 @@ class _MainQueueScreenState extends State<MainQueueScreen> {
);
}
}

Loading…
Cancel
Save