Skip to content
This repository was archived by the owner on Mar 24, 2021. It is now read-only.

Commit f526051

Browse files
Merge pull request #130 from aerogear/Lavanyagaur22-patch-1
Update docs 2
2 parents 4455dec + c784e27 commit f526051

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ See [sample](https://github.com/aerogear/offix-android/tree/master/sample) for e
5656
## Features in Development
5757

5858
1. Adding Offline Support when the app is in background.
59-
2. Provide UI bindings in app. (For the time being, we are using subscriptions to provide them)
59+
2. Provide UI bindings in app. (For the time being, you can use subscriptions to have UI bindings.)
6060

6161
## Contributing
6262

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ See [sample](https://github.com/aerogear/offix-android/tree/master/sample) for e
5656
## Features in Development
5757

5858
1. Adding Offline Support when the app is in background.
59-
2. Provide UI bindings in app. (For the time being, we are using subscriptions to provide them)
59+
2. Provide UI bindings in app. (For the time being, you can use subscriptions to have UI bindings)
6060

6161
## Contributing
6262

docs/conflict_resolution.md

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
### Steps to support Conflict Resolution in your app:
44

5-
- Create a class, let say `UserConflictResolutionHandler` which extends ConfliceResolutionInterface provided by the library.
5+
- Create a class, let say `UserConflictResolutionHandler` which implements `ConfliceResolutionInterface` provided by the library.
66
- Override the `resolveConflict()` method of the interface in your class.
77
- You get the **`server state`** and the **`client state`** data associated with that mutation in which conflict occurred.
88
- You also get the **`operation type`** of the conflicted mutation. Run a switch case on the operation type to detect which type of mutation is it in which conflict occured and accordingly create an object of that mutation while resolving conflicts.
99
- You can resolve conflicts based on your business logic and again make a call to the server.
1010

11+
#### The [conflict protocol/structure](https://offix.dev/#/ref-conflict-server?id=structure-of-the-conflict-error) is descibed on [offix.dev](https://offix.dev/)
12+
13+
1114
### Code:
15+
#### The sample app contains conflict resolution based on the version strategy. However, the user can use their own markers to resolve conflicts.
16+
1217

1318
```kotlin
1419
/*
1520
UserConflictResolutionHandler extends ConflictResolutionInterface.
1621
Here the user provides the custom implementation of resolving conflicts.
1722
*/
1823
class UserConflictResolutionHandler(val context: Context) : ConflictResolutionInterface {
19-
val TAG = javaClass.simpleName
2024

2125
/*User get the server state and the client state.
2226
This function resolves the conflicts based on the user business logic.
@@ -27,6 +31,7 @@ class UserConflictResolutionHandler(val context: Context) : ConflictResolutionIn
2731
operationType: String
2832
) {
2933
/*Version based approach of Conflict Resolution, for instance.
34+
You can resolve them based on your logics.
3035
*/
3136
val serverMap = serverState
3237
val containsVersion = serverMap.containsKey("version")
@@ -37,42 +42,39 @@ class UserConflictResolutionHandler(val context: Context) : ConflictResolutionIn
3742
/* You can run a switch case on the operation type to detect which type of mutation is it in which conflict occured
3843
and accordingly create an object of that mutation, resolve conflict and make a server call with it.
3944
*/
40-
when (operationType) {
41-
/*
42-
According to the schema structure, used a version based approach of resolving conflicts.
43-
If operationType is "UpdateTaskMutation" perform the following steps to resolve conflicts.
44-
*/
45+
when (operationType) {
4546
"UpdateTaskMutation" -> {
46-
47-
val input = TaskInput.builder().title(clientState["title"].toString()).version(versionAfterConflict)
47+
/*
48+
1. Get the necessary fields from the clientState.
49+
2. Create an object of mutation.
50+
3. Again make a call to the server.
51+
*/
52+
val input = TaskInput.builder().title(clientState["title"].toString()).version(versionAfterConflict)
4853
.description(clientState["description"].toString()).status("test").build()
4954

50-
var mutation = UpdateTaskMutation.builder().id(clientState["id"].toString()).input(input).build()
55+
var mutation = UpdateTaskMutation.builder().id(clientState["id"].toString()).input(input).build()
5156

52-
val mutationCall = Utils.getApolloClient(context)?.mutate(mutation)
57+
val mutationCall = apolloclient.mutate(mutation)
5358

54-
val callback = object : ApolloCall.Callback<UpdateTaskMutation.Data>() {
55-
override fun onFailure(e: ApolloException) {
59+
val callback = object : ApolloCall.Callback<UpdateTaskMutation.Data>() {
60+
override fun onFailure(e: ApolloException) {
5661
e.printStackTrace()
5762
}
58-
59-
override fun onResponse(response: Response<UpdateTaskMutation.Data>) {
60-
Log.e("onResponse() updateTask", "${response.data()?.updateTask()?.title()}")
63+
64+
override fun onResponse(response: Response<UpdateTaskMutation.Data>) {
6165
val result = response.data()?.updateTask()
6266
//In case of conflicts, data returned from the server is null.
6367
result?.let {
64-
Log.e(TAG, "onResponse-UpdateTask- $it")
68+
//Perform UI Bindings here.
6569
}
6670
}
6771
}
68-
mutationCall?.enqueue(callback)
69-
}
70-
72+
73+
mutationCall?.enqueue(callback)
74+
}
7175
"UpdateUserMutation" -> {
72-
/* Similar for UpdateUserMutation
73-
1. Get all the fields from the clientState.
74-
2. Create an object of mutation.
75-
3. Again make a call to the server.
76+
/*
77+
Resolve conflicts and make a call to the server.
7678
*/
7779
}
7880
}

docs/gettingstarted.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- npm run start
1313
- This will start your server.
1414

15+
1516
## 2. Android Setup
1617

1718
- Clone [this](https://github.com/aerogear/offix-android.git) repository.
@@ -36,3 +37,6 @@ For **maven**, add the following dependency: <br/>
3637
<type>pom</type>
3738
</dependency>
3839
```
40+
41+
42+
#### Note: The library works with the offix-sever that is node.js based and [conflict protocol](https://offix.dev/#/ref-conflict-server?id=structure-of-the-conflict-error) is descibed on [offix.dev](https://offix.dev/)

docs/test_offline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
- Create any mutation. (Procedure shown on previous page)
44
- If your network is connected, then you will get a successful reponse from the server in ApolloCalback's `onResponse()` method. You can perfrom UI Bindings here according to your needs.
5-
- If your network is not connected, a toast will be shown regarding the same and your mutation would be successfully stored in an offline store.
5+
- If your network is not connected, your mutation will be successfully stored in an offline store.
66
- Once your network connection is regained, the mutations done when you were offline will try to replicate back to the server till all the offline mutations successfully hit the server and you get a response back from them.
77
- To get the most recent data in your application, **refresh** your app once after the network comes back by swiping down on the screen.

0 commit comments

Comments
 (0)