mirror of https://github.com/tasks/tasks
Fix some inspections
parent
5fa35a001e
commit
0b456d177e
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
|
||||
package com.todoroo.astrid.sync;
|
||||
|
||||
public interface SyncResultCallback {
|
||||
|
||||
/** Provider started sync */
|
||||
void started();
|
||||
|
||||
/** Provider finished sync */
|
||||
void finished();
|
||||
}
|
@ -1,42 +1,19 @@
|
||||
package org.tasks.caldav;
|
||||
|
||||
import java.io.IOException;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class Response implements Function1<okhttp3.Response, Unit> {
|
||||
class Response implements Function1<okhttp3.Response, Unit> {
|
||||
|
||||
private final boolean parseBody;
|
||||
private okhttp3.Response response;
|
||||
private String body;
|
||||
|
||||
public Response() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public Response(boolean parseBody) {
|
||||
this.parseBody = parseBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unit invoke(okhttp3.Response response) {
|
||||
this.response = response;
|
||||
if (parseBody) {
|
||||
try {
|
||||
body = response.body().string();
|
||||
} catch (IOException e) {
|
||||
Timber.e(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public okhttp3.Response get() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
package org.tasks.sync;
|
||||
|
||||
import static java.util.concurrent.Executors.newSingleThreadExecutor;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.todoroo.astrid.sync.SyncResultCallback;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import javax.inject.Inject;
|
||||
import org.tasks.analytics.Tracker;
|
||||
import org.tasks.injection.ApplicationScope;
|
||||
import timber.log.Timber;
|
||||
|
||||
@ApplicationScope
|
||||
public class SyncExecutor {
|
||||
|
||||
private final ExecutorService executor =
|
||||
newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("sync-executor-%d").build());
|
||||
|
||||
private final Tracker tracker;
|
||||
|
||||
@Inject
|
||||
public SyncExecutor(Tracker tracker) {
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
public void execute(SyncResultCallback callback, Runnable command) {
|
||||
try {
|
||||
executor.execute(wrapWithExceptionHandling(callback, command));
|
||||
} catch (RejectedExecutionException e) {
|
||||
Timber.e(e);
|
||||
tracker.reportException(e);
|
||||
callback.finished();
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable wrapWithExceptionHandling(
|
||||
final SyncResultCallback callback, final Runnable command) {
|
||||
return () -> {
|
||||
try {
|
||||
command.run();
|
||||
} catch (Exception e) {
|
||||
Timber.e(e);
|
||||
tracker.reportException(e);
|
||||
executor.shutdownNow();
|
||||
callback.finished();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<string name="app_name" tools:ignore="PrivateResource">Tasks</string>
|
||||
<resources>
|
||||
<string name="app_name">Tasks</string>
|
||||
<string name="app_package">org.tasks</string>
|
||||
<string name="backup_api_key">AEdPqrEAAAAI49v5bBusi_bq1bgLBB1LIsepNV0eBrFkQrBZkw</string>
|
||||
</resources>
|
Loading…
Reference in New Issue