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

Implement discovering in sending mode and advertising in receiving mode #26

Merged
merged 20 commits into from
Mar 14, 2019
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
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
# Android P2P Sync [![Build Status](https://travis-ci.org/OpenSRP/android-p2p-sync.svg?branch=master)](https://travis-ci.org/OpenSRP/android-p2p-sync) [![Coverage Status](https://coveralls.io/repos/github/OpenSRP/android-p2p-sync/badge.svg?branch=master)](https://coveralls.io/github/OpenSRP/android-p2p-sync?branch=master)


This library wraps on the Google Nearby Connections API to provide a simple UI and interfaces to be used to easily share records between host applications
This library wraps on the Google Nearby Connections API to provide a simple UI and interfaces to be used to easily share records between host applications

## Getting started

Add the module to your project(Publishing is not yet supported :worried:


Initialise the library in the `onCreate` method of your `Application` class

```java

public class MyApplication extends Application {

@Override
public void onCreate() {
super.onCreate();
...

P2PLibrary.init(new P2PLibrary.ReceiverOptions("John Doe"));
}
}

```


To start the sending and receiving activity:

```java

...
startActivity(new Intent(this, P2pModeSelectActivity.class));
```
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableUnitTestBinaryResources=true
17 changes: 15 additions & 2 deletions p2p-sync/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ android {
versionName version

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
Expand All @@ -35,15 +34,29 @@ android {
}
}

testOptions.unitTests.includeAndroidResources = true

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation ('com.google.android.gms:play-services-nearby:16.0.0') {
exclude group: 'com.android.support', module: 'support-v4'
}
implementation ('com.google.android.gms:play-services-location:16.0.0') {
exclude group: 'com.android.support', module: 'support-v4'
}

implementation 'com.jakewharton.timber:timber:4.7.1'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation 'org.mockito:mockito-core:2.25.0'
testImplementation "org.robolectric:robolectric:4.2"
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
Expand Down Expand Up @@ -76,4 +89,4 @@ coveralls {
// Re-add the line below if coveralls still cannot shows "No source file found on the project: "p2p-sync"
// after adding some code files
//sourceDirs += ["src/main/java"]
}
}
16 changes: 15 additions & 1 deletion p2p-sync/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.smartregister.p2p" />
package="org.smartregister.p2p">

<!-- Required for Nearby Connections -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application>
<activity android:name=".activity.P2pModeSelectActivity"></activity>
</application>

</manifest>
66 changes: 66 additions & 0 deletions p2p-sync/src/main/java/org/smartregister/p2p/P2PLibrary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.smartregister.p2p;

import android.support.annotation.NonNull;

import timber.log.Timber;

/**
* Created by Ephraim Kigamba - ekigamba@ona.io on 08/03/2019
*/

public final class P2PLibrary {

private static P2PLibrary instance;
private BasicOptions basicOptions;

@NonNull
public static P2PLibrary getInstance() {
if (instance == null) {
throw new IllegalStateException(" Instance does not exist!!! Call P2PLibrary.init method"
+ "in the onCreate method of "
+ "your Application class ");
}

return instance;
}

public static void init(@NonNull BasicOptions basicOptions) {
instance = new P2PLibrary(basicOptions);
}

private P2PLibrary(@NonNull BasicOptions basicOptions) {
this.basicOptions = basicOptions;

// We should not override the host applications Timber trees
if (Timber.treeCount() == 0) {
Timber.plant(new Timber.DebugTree());
}
}

@NonNull
public String getUsername() {
return basicOptions.getUsername();
}

public static class ReceiverOptions extends BasicOptions {

public ReceiverOptions(@NonNull String advertisingName) {
super(advertisingName);
}

}

public static abstract class BasicOptions {

private String username;

public BasicOptions(@NonNull String username) {
this.username = username;
}

@NonNull
public String getUsername() {
return this.username;
}
}
}
Loading