data classNotificationModel(varid:String,vartitleEng:String,vartitleBng:String?,varbodyEng:String,varbodyBng:String?,varlink:String?,varbutton:String?,varimage:String?,)
vallistOfAlarm=listOf(NotificationModel(id="1",titleEng="পরিবারের সকল সদস্যের নামে ঔষধ বুকমার্ক করুন।\n",titleBng="পরিবারের সকল সদস্যের নামে ঔষধ বুকমার্ক করুন।\n",bodyEng="পেশেন্ট এইড দিচ্ছে মাল্টি (একাধিক) প্রোফাইল তৈরি করার সুবিধা। পরিবারের সদস্যদের ঔষধ বুকমার্ক করে রাখুন তাদের নিজেদের নামে। সুবিধাটি রয়েছে শুধু প্রিমিয়াম ব্যবহার কারিদের জন্য। তাই দেরি না করে এখনি কিনে নিন।",bodyBng="পেশেন্ট এইড দিচ্ছে মাল্টি (একাধিক) প্রোফাইল তৈরি করার সুবিধা। পরিবারের সদস্যদের ঔষধ বুকমার্ক করে রাখুন তাদের নিজেদের নামে। সুবিধাটি রয়েছে শুধু প্রিমিয়াম ব্যবহার কারিদের জন্য। তাই দেরি না করে এখনি কিনে নিন।",link="",button="",image="",)}
classUserActivityTracker(context:Context){funsaveLastMessageIndex(index:Int){sharedPreferences.edit().putInt("last_message_index",index).apply()}fungetLastMessageIndex():Int{returnsharedPreferences.getInt("last_message_index",0)}funsetLastActivity(){valcurrentTime=System.currentTimeMillis()sharedPreferences.edit().putLong("last_activity_timestamp",currentTime).apply()}privatefungetLastActivityTime():Long{returnsharedPreferences.getLong("last_activity_timestamp",0L)}funisInActiveInLastFiveDays():Boolean{valcurrentTime=System.currentTimeMillis()valfiveDaysInMillis=Constants.INTERVAL_5_DAYS// 5 days in milliseconds vallastActivityTimestamp=getLastActivityTime()valisActiveInLastFiveDays=currentTime-lastActivityTimestamp>=fiveDaysInMillisreturnisActiveInLastFiveDays}}
classScheduledNotificationManager(appContext:Context,params:WorkerParameters,):CoroutineWorker(appContext,params){companionobject{constvalTAG="ScheduledNotificationManager"}overridesuspendfundoWork():Result{try{valtracker=UserActivityTracker(applicationContext)vallastMessageIndex=tracker.getLastMessageIndex()if(tracker.isInActiveInLastFiveDays()){// User has not been active in the last 5 daysLog.d(TAG,"User is not active in the last 5 days.")valnotifyUtil=PeriodicNotificationUtil()valnotifyManager=applicationContext.getSystemService(Context.NOTIFICATION_SERVICE)asNotificationManagernotifyUtil.sendNotification(applicationContext,listOfAlarm[lastMessageIndex],notifyManager)if(lastMessageIndex==listOfAlarm.size-1){tracker.saveLastMessageIndex(0)}else{tracker.saveLastMessageIndex(lastMessageIndex+1)}}else{// User has been active in the last 5 daysLog.d(TAG,"UserStatus: User is active in the last 5 days.")}}catch(e:Exception){e.printStackTrace()}returnResult.success()}}
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)