Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate JobIntentService to WorkManager #1776

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@
<!-- services -->

<service
android:name=".notifications.RecurringTransactionIntentService"
android:name=".notifications.ScheduledTransactionWorker"
android:permission="android.permission.BIND_JOB_SERVICE" />
<service
android:name=".widget.AccountBillsWidgetService"
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/money/manager/ex/MmexApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.money.manager.ex;

import static timber.log.Timber.plant;

import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
Expand Down Expand Up @@ -132,10 +134,10 @@ public void onCreate() {

// Loggers
if (BuildConfig.DEBUG) {
Timber.plant(new DebugTree());
plant(new DebugTree());
} else {
Timber.plant(new ScreenTree());
Timber.plant(new SysLogTree());
plant(new ScreenTree());
plant(new SysLogTree());
}

initializeDependencyInjection();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012-2018 The Android Money Manager Ex Project Team
* Copyright (C) 2012-2024 The Android Money Manager Ex Project Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -34,8 +34,6 @@ public void onReceive(Context context, Intent intent) {
.getBoolean(context.getString(PreferenceConstants.PREF_REPEATING_TRANSACTION_NOTIFICATIONS), true);
if (!notify) return;

Intent myIntent = new Intent(context, RecurringTransactionIntentService.class);
RecurringTransactionIntentService.enqueueWork(context, myIntent);
ScheduledTransactionWorker.enqueueWork(context);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012-2018 The Android Money Manager Ex Project Team
* Copyright (C) 2012-2024 The Android Money Manager Ex Project Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -18,32 +18,39 @@
package com.money.manager.ex.notifications;

import android.content.Context;
import android.content.Intent;
import androidx.core.app.JobIntentService;

import androidx.annotation.NonNull;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import androidx.work.WorkRequest;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

/**
* Background service that triggers notifications about recurring transactions.
*
* Updated to JobIntentService as per
* https://android.jlelse.eu/keep-those-background-services-working-when-targeting-android-oreo-sdk-26-cbf6cc2bdb7f
* Updated to work manager as per
* https://developer.android.com/reference/androidx/work/WorkManager
*/
public class RecurringTransactionIntentService
extends JobIntentService {

public static int JOB_ID = 1001;
public class ScheduledTransactionWorker
extends Worker {

// public RecurringTransactionIntentService() {
// super("com.money.manager.ex.notifications.RecurringTransactionIntentService");
// }
public ScheduledTransactionWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}

@NonNull
@Override
protected void onHandleWork(Intent intent) {
// start repeating transaction
public Result doWork() {
RecurringTransactionNotifications notifications = new RecurringTransactionNotifications(getApplicationContext());
notifications.notifyRepeatingTransaction();
return Result.success();
}

public static void enqueueWork(Context context, Intent intent) {
enqueueWork(context, RecurringTransactionIntentService.class, JOB_ID, intent);
}
public static void enqueueWork(Context context) {
WorkRequest recurringTransactionWorkRequest = new OneTimeWorkRequest.Builder(ScheduledTransactionWorker.class)
.build();

WorkManager.getInstance(context).enqueue(recurringTransactionWorkRequest);
}
}
Loading