diff --git a/gradle.properties b/gradle.properties index 979420a..57853fc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,4 +27,4 @@ POM_SETTING_DEVELOPER_ID=opensrp POM_SETTING_DEVELOPER_NAME=OpenSRP Onadev POM_SETTING_NAME=Android Peer-to-Peer Sync POM_SETTING_ARTIFACT_ID=android-p2p-sync -POM_SETTING_PACKAGING=aar +POM_SETTING_PACKAGING=aar \ No newline at end of file diff --git a/p2p-sync/src/main/java/org/smartregister/p2p/sync/SyncSenderHandler.java b/p2p-sync/src/main/java/org/smartregister/p2p/sync/SyncSenderHandler.java index 1a26e9c..2c42d77 100644 --- a/p2p-sync/src/main/java/org/smartregister/p2p/sync/SyncSenderHandler.java +++ b/p2p-sync/src/main/java/org/smartregister/p2p/sync/SyncSenderHandler.java @@ -1,5 +1,7 @@ package org.smartregister.p2p.sync; +import android.os.Handler; +import android.os.Looper; import android.os.ParcelFileDescriptor; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -55,12 +57,15 @@ public class SyncSenderHandler { private PayloadRetry payloadRetry; private SyncPackageManifest syncPackageManifest; + private Handler uiHandler; + public SyncSenderHandler(@NonNull P2pModeSelectContract.SenderPresenter presenter, @NonNull TreeSet dataSyncOrder , @Nullable List receivedHistory) { this.presenter = presenter; this.dataSyncOrder = dataSyncOrder; this.receivedHistory = receivedHistory; this.batchSize = P2PLibrary.getInstance().getBatchSize(); + this.uiHandler = new Handler(Looper.getMainLooper()); } private void generateRecordsToSend() { @@ -261,12 +266,23 @@ public void run() { outputStream.flush(); outputStream.close(); - } catch (IOException e) { + } catch (final IOException e) { Timber.e(e, "Error occurred trying to read bytes into payload pipe"); - presenter.errorOccurredSync(e); + + uiHandler.post(new Runnable() { + @Override + public void run() { + presenter.errorOccurredSync(e); + } + }); } } else { - presenter.errorOccurredSync(new Exception("Could not find the payload pipe!")); + uiHandler.post(new Runnable() { + @Override + public void run() { + presenter.errorOccurredSync(new Exception("Could not find the payload pipe!")); + } + }); } } } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 56ab6e0..2f19613 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -3,6 +3,9 @@ xmlns:android="http://schemas.android.com/apk/res/android" package="org.smartregister.p2p.sample"> + + +