Skip to content

Commit cd0adf9

Browse files
authored
Merge pull request #4 from freshbits/v2.1
Add Kotlin App
2 parents cc62ce8 + 4cb732c commit cd0adf9

File tree

30 files changed

+731
-14
lines changed

30 files changed

+731
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ local.properties
55
.DS_Store
66
build/
77
/captures
8-
repo/
8+
PathshareSDK/
99
*.iml

README.md

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Pathshare SDK for Android
22

3+
4+
![GitHub release](https://img.shields.io/github/release/freshbits/pathshare-sdk-android.svg?style=flat)
35
![Platform](https://img.shields.io/badge/platform-android-green.svg?style=flat)
46
![Language](https://img.shields.io/badge/language-java-brightgreen.svg?style=flat)
7+
![Language](https://img.shields.io/badge/language-kotlin-brightgreen.svg?style=flat)
58

69
**Pathshare** is a realtime location sharing platform. For more information please visit the [Pathshare Developer Page](https://pathsha.re/professional/developers).
710

@@ -26,11 +29,11 @@
2629

2730
The installation of the `PathshareSDK` is simple. Download the latest `pathshare-sdk-android-[version].zip` from [Releases](https://github.com/freshbits/pathshare-sdk-android/releases), unzip and copy the `repo` folder into the root of your project.
2831

29-
Next, reference the `repo` folder in your application `build.gradle` file:
32+
Next, reference the `PathareSDK` folder in your application `build.gradle` file:
3033

3134
```gradle
3235
repositories {
33-
maven { url "file://$projectDir/../repo" }
36+
maven { url "file://$projectDir/../PathshareSDK" }
3437
}
3538
3639
dependencies {
@@ -54,6 +57,7 @@ In order to initialize the `PathshareSDK`, create a file named `pathshare.xml` i
5457

5558
Next, add the following to the `onCreate` method of your `Application` class:
5659

60+
###### Java
5761
```java
5862
public class ExampleApplication extends Application {
5963
@Override
@@ -64,6 +68,17 @@ public class ExampleApplication extends Application {
6468
}
6569
}
6670
```
71+
###### Kotlin
72+
```kotlin
73+
class ExampleApplication: Application() {
74+
75+
override fun onCreate() {
76+
super.onCreate()
77+
78+
Pathshare.initialize(this, getString(R.string.pathshare_account_token), TrackingMode.SMART)
79+
}
80+
}
81+
```
6782

6883
Optionally, you can specify a tracking mode to configure the behavior of the location tracker. The following tracking modes are available:
6984

@@ -78,6 +93,7 @@ Tracking Mode | Description
7893

7994
Before creating a session, you need to set a username:
8095

96+
###### Java
8197
```java
8298
Pathshare.client().saveUser("Candice", "+12345678901", UserType.DRIVER, new ResponseListener() {
8399
@Override
@@ -92,6 +108,19 @@ Pathshare.client().saveUser("Candice", "+12345678901", UserType.DRIVER, new Resp
92108
});
93109
```
94110

111+
###### Kotlin
112+
```kotlin
113+
Pathshare.client().saveUser("SDK User Android", "+12345678901", UserType.DRIVER, object: ResponseListener {
114+
override fun onSuccess() {
115+
// ...
116+
}
117+
118+
override fun onError() {
119+
// ...
120+
}
121+
})
122+
```
123+
95124
There are different types of users for specific industries:
96125

97126
User Types | Description
@@ -104,18 +133,28 @@ User Types | Description
104133

105134
To create a session, use the session builder:
106135

136+
###### Java
107137
```java
108138
session = new Session.Builder()
109139
.setExpirationDate(expirationDate)
110140
.setName("Shopping")
111141
.build();
112142
```
113143

144+
###### Kotlin
145+
```kotlin
146+
session = Session.Builder()
147+
.setExpirationDate(expirationDate)
148+
.setName("Shopping")
149+
.build()
150+
```
151+
114152
A session needs an expiration date and a name. You can create multiple sessions at the same time, the SDK will manage them for you.
115153

116154

117155
Make sure to save the session after building:
118156

157+
###### Java
119158
```java
120159
session.save(new ResponseListener() { ... });
121160

@@ -124,10 +163,20 @@ session.isExpired() // => false
124163
session.getURL() // => https://pathsha.re/6d39d5
125164
```
126165

166+
###### Kotlin
167+
```kotlin
168+
session.save(object: ResponseListener { ... })
169+
170+
session.identifier // => 3fd919fe824d8e7b78e2c11c1570a6f168d2c...
171+
session.isExpired // => false
172+
session.url // => https://pathsha.re/6d39d5
173+
```
174+
127175
#### Expiration
128176

129177
In order to react to the expiration of the session, add an `ExpirationListener`:
130178

179+
###### Java
131180
```java
132181
session = new Session.Builder()
133182
// ...
@@ -140,10 +189,19 @@ session = new Session.Builder()
140189
.build();
141190
```
142191

192+
###### Kotlin
193+
```kotlin
194+
session = Session.Builder()
195+
// ...
196+
.setSessionExpirationListener { // ... }
197+
.build()
198+
```
199+
143200
#### Destination
144201

145202
Optionally, you can add a destination to the session. Sessions with destination will show the estimated time of arrival (ETA) for each user. The destination identifier is used to group sessions by destination.
146203

204+
###### Java
147205
```java
148206
Destination destination = new Destination.Builder()
149207
.setIdentifier("W2342")
@@ -157,24 +215,47 @@ session = new Session.Builder()
157215
.build();
158216
```
159217

218+
###### Kotlin
219+
```kotlin
220+
val destination = Destination.Builder()
221+
.setIdentifier("W2342")
222+
.setLatitude(47.378178)
223+
.setLongitude(8.539256)
224+
.build()
225+
226+
session = Session.Builder()
227+
// ...
228+
.setDestination(destination)
229+
.build()
230+
```
231+
160232
### Join Session
161233

162234
To join the session you created, call the `joinUser()` method on the session object:
163235

236+
###### Java
164237
```java
165238
session.join(new ResponseListener() { ... });
166239

167240
session.isUserJoined() // => true
168241
```
169242

243+
###### Kotlin
244+
```kotlin
245+
session.join(object: ResponseListener { ... })
246+
247+
session.isUserJoined // => true
248+
```
249+
170250
This call will add your Pathshare user to the session and you will be able to see his location on a map in realtime in the Pathshare Professional web interface.
171251

172252
### Invite customer
173253

174254
To invite a customer to the session, call the `inviteUser()` method on the session object:
175255

256+
###### Java
176257
```java
177-
session.inviteUser("Customer name", UserType.CLIENT, "customer@email.com", "+12345678901", new InvitationResponseListener() {
258+
session.inviteUser("Customer", UserType.CLIENT, "customer@email.com", "+12345678901", new InvitationResponseListener() {
178259
@Override
179260
public void onSuccess(URL url) {
180261
// ...
@@ -187,6 +268,20 @@ session.inviteUser("Customer name", UserType.CLIENT, "customer@email.com", "+123
187268
});
188269
```
189270

271+
###### Kotlin
272+
```kotlin
273+
session.inviteUser("Customer", UserType.CLIENT, "customer@me.com", "+12345678901", object: InvitationResponseListener {
274+
override fun onSuccess(url: URL?) {
275+
// ...
276+
Log.d("URL", url.toString()) // => https://m.pathsha.re/12s83a
277+
}
278+
279+
override fun onError() {
280+
// ...
281+
}
282+
})
283+
```
284+
190285
This call will create a customer user and return an invitation URL that can be sent to the customer using your preffered channel. The customer will then see the driver's location in realtime as well as the ETA in a white-labeled view with your corporate identity.
191286
192287
The customer will be able to enjoy the full realtime experience in the web browser of their smartphone:
@@ -197,14 +292,21 @@ The customer will be able to enjoy the full realtime experience in the web brows
197292
198293
In order to stop sending user location and remove the user from the session, call the `leaveUser()` method:
199294
295+
###### Java
200296
```java
201297
session.leave(new ResponseListener() { ... });
202298
```
203299
300+
###### Kotlin
301+
```kotlin
302+
session.leave(object: ResponseListener { ... })
303+
```
304+
204305
### Find Session
205306
206307
To find an existing session, use the `findSession()` method with the corresponding session identifier:
207308
309+
###### Java
208310
```java
209311
Pathshare.client().findSession(identifier, new SessionResponseListener() {
210312
@Override
@@ -218,3 +320,14 @@ Pathshare.client().findSession(identifier, new SessionResponseListener() {
218320
public void onError() { ... }
219321
}
220322
```
323+
324+
###### Kotlin
325+
```kotlin
326+
Pathshare.client().findSession(identifier, object: SessionResponseListener {
327+
override fun onSuccess(session: Session?) {
328+
session.sessionExpirationListener = SessionExpirationListener { ... }
329+
}
330+
331+
override fun onError() { ... }
332+
})
333+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
android {
5+
compileSdkVersion 27
6+
7+
defaultConfig {
8+
applicationId "ch.freshbits.pathshare.example"
9+
minSdkVersion 21
10+
targetSdkVersion 27
11+
versionCode 2_1_0
12+
versionName "2.1.0"
13+
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
}
16+
17+
lintOptions {
18+
abortOnError false
19+
}
20+
21+
buildTypes {
22+
debug {
23+
debuggable true
24+
zipAlignEnabled false
25+
minifyEnabled false
26+
}
27+
28+
release {
29+
debuggable false
30+
zipAlignEnabled true
31+
minifyEnabled false
32+
}
33+
}
34+
}
35+
36+
repositories {
37+
maven { url "file://$projectDir/../PathshareSDK" }
38+
}
39+
40+
dependencies {
41+
implementation fileTree(dir: 'libs', include: ['*.jar'])
42+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
43+
implementation 'com.android.support:appcompat-v7:27.1.1'
44+
implementation 'ch.freshbits.pathshare.sdk:pathshare-sdk:2.1.0'
45+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
46+
implementation 'com.android.support:design:27.1.1'
47+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="ch.freshbits.pathshare.example">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:name="ch.freshbits.pathshare.example.ExampleApplication"
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:theme="@style/AppTheme" >
13+
<activity
14+
android:name="ch.freshbits.pathshare.example.MainActivity"
15+
android:label="@string/app_name" >
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package ch.freshbits.pathshare.example
2+
3+
import android.app.Application
4+
import ch.freshbits.pathshare.sdk.Pathshare
5+
import ch.freshbits.pathshare.sdk.location.TrackingMode
6+
7+
class ExampleApplication: Application() {
8+
9+
override fun onCreate() {
10+
super.onCreate()
11+
12+
Pathshare.initialize(this, getString(R.string.pathshare_account_token), TrackingMode.SMART)
13+
}
14+
}

0 commit comments

Comments
 (0)