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

Adapted service GeneratorService to be a job. #91

Merged
merged 1 commit into from
Nov 5, 2022
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
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<service
android:name="org.secuso.privacyfriendlysudoku.controller.GeneratorService"
android:enabled="true"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false" />
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import android.app.IntentService;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.Nullable;
import androidx.core.app.JobIntentService;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import android.util.Log;
Expand Down Expand Up @@ -49,7 +51,7 @@
*
* @author Christopher Beckmann
*/
public class GeneratorService extends IntentService {
public class GeneratorService extends JobIntentService {

private static final String TAG = GeneratorService.class.getSimpleName();
public static final String ACTION_GENERATE = TAG + " ACTION_GENERATE";
Expand All @@ -64,11 +66,11 @@ public class GeneratorService extends IntentService {
//private Handler mHandler = new Handler();


public GeneratorService() {
super("Generator Service");
}
//public GeneratorService() {
// super("Generator Service");
//}

public GeneratorService(String name) { super(name); }
//public GeneratorService(String name) { super(name); }


private void buildGenerationList() {
Expand Down Expand Up @@ -120,12 +122,11 @@ private void generateLevels() {
// if we start this service multiple times while we are already generating...
// we ignore this call and just keep generating
buildGenerationList();

// generate from the list
if(generationList.size() > 0) {

// generate 1 level and wait for it to be done.
Pair<GameType, GameDifficulty> dataPair = generationList.get(0);
Pair<GameType, GameDifficulty> dataPair = generationList.remove(0);
GameType type = dataPair.first;
GameDifficulty diff = dataPair.second;

Expand Down Expand Up @@ -275,8 +276,13 @@ private void showNotification(GameType gameType, GameDifficulty gameDifficulty)
builder.setSmallIcon(R.drawable.splash_icon);
startForeground(50, builder.build());
}

static void enqueueWork(Context context, Intent intent) {
enqueueWork(context, GeneratorService.class, 1000, intent);
}

@Override
protected void onHandleIntent(@Nullable Intent intent) {
protected void onHandleWork(@Nullable Intent intent) {
if (intent != null) {

String action = intent.getAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ public void checkAndRestock() {
Intent i = new Intent(context, GeneratorService.class);
i.setAction(GeneratorService.ACTION_GENERATE);
//i.putExtra(ProtocolService.EXTRA_PROTOCOL, current.componentName().flattenToString());
context.startService(i);
//context.startService(i);
GeneratorService.enqueueWork(context, i);

//new AsyncGenerationTask().execute();
}
Expand Down