This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private lateinit var timerService: TimerService | |
| private var isTimerServiceBound: Boolean = false | |
| private val timerServiceConnection = object : ServiceConnection { | |
| override fun onServiceConnected(name: ComponentName?, binder: IBinder?) { | |
| timerService = (binder as TimerService.TimerBinder).service | |
| isTimerServiceBound = true | |
| } | |
| override fun onServiceDisconnected(p0: ComponentName?) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| startService(Intent(this, TimerService::class.java)) | |
| bindService( | |
| Intent(this, TimerService::class.java), | |
| timerServiceConnection, | |
| Context.BIND_AUTO_CREATE | |
| ) | |
| setContent { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun createChannel( | |
| context: Context, | |
| channelId = CHANNEL_ID, | |
| @StringRes channelName: Int, | |
| @StringRes channelDescription: Int, | |
| importanceLevel: Int = NotificationManager.IMPORTANCE_HIGH | |
| ) { | |
| val channel = NotificationChannel( | |
| context.getString(channelId), | |
| context.getString(channelName), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun createNotification( | |
| context: Context, | |
| title: String, | |
| content: String, | |
| ) { | |
| val builder = NotificationCompat.Builder(context, CHANNEL_ID) | |
| val notification = builder.setContentTitle(title).setContentText(content) | |
| .setSmallIcon(R.drawable.ic_launcher_foreground).build() | |
| NotificationManagerCompat.from(context).notify(id, notification) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private val trashIcon = ContextCompat.getDrawable(context, R.drawable.ic_baseline_delete_24) | |
| private val circleColor = ContextCompat.getColor(context, R.color.deleteRed) | |
| private val circlePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = circleColor } | |
| private val reverseSurfaceColor = ContextCompat.getColor(context, R.color.primaryTextColor) | |
| private val CIRCLE_ACCELERATION = 6f | |
| override fun onChildDraw( | |
| c: Canvas, | |
| recyclerView: RecyclerView, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ItemTouchHelper( | |
| OurSimpleCallbackImpl() | |
| ).attachToRecyclerView(binding.recyclerView) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build, Test and Compile | |
| on: | |
| push: | |
| branches: [ master ] | |
| jobs: | |
| Unit-Test: | |
| runs-on: ubuntu-latest | |
| # needs: Build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BackupWorkerManager(context: Context) { | |
| private var manager: WorkManager = WorkManager.getInstance(context) | |
| fun launchWorker(interval: Long) = | |
| manager.enqueue( | |
| PeriodicWorkRequestBuilder<BackupWorker>(interval, TimeUnit.DAYS) | |
| .setConstraints( | |
| Constraints.Builder() | |
| .setRequiredNetworkType(NetworkType.CONNECTED) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BackupWorkerManager(requireContext()).launchWorker(interval) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BackupWorker( | |
| context: Context, | |
| workerParams: WorkerParameters | |
| ) : CoroutineWorker(context, workerParams) { | |
| private val backup: BackupUserData = BackupUserData(applicationContext) | |
| override suspend fun doWork(): Result { | |
| return if (backup.doBackup()) Result.success() | |
| else Result.failure() |