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

Commit a543d19

Browse files
Merge pull request #126 from aerogear/sampleUiBetter
Improve sample.
2 parents b914d1c + 21857c7 commit a543d19

File tree

25 files changed

+546
-267
lines changed

25 files changed

+546
-267
lines changed

offix/src/main/java/org/aerogear/offix/ConflictResolutionHandler.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ConflictResolutionHandler {
3434
}
3535

3636
internal fun conflictPresent(parsedResponse: Optional<Response<Any>>?): Boolean {
37-
Log.d(TAG, "inside conflictPresent parsed response")
37+
Log.d(TAG, "inside conflictPresent parsed response $parsedResponse")
3838

3939
/*Check if the parsed response contains a conflict.
4040
The contract for conflicts is that the response will contain an error with the
@@ -44,12 +44,11 @@ class ConflictResolutionHandler {
4444
return false
4545
}
4646

47-
Log.d(TAG, "Thread:[" + Thread.currentThread().id + "]: onResponse -- found error")
48-
4947
if (!parsedResponse.get().errors()[0].toString().contains("conflictInfo")) {
5048
return false
5149
}
52-
return true
53-
}
5450

51+
Log.d("$TAG 300", "ConflictResolutionHandler")
52+
return true
53+
}
5554
}

offix/src/main/java/org/aerogear/offix/Offix.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ fun getMutation(storedmutation: org.aerogear.offix.persistence.Mutation): Mutati
182182

183183
//Make an object of mutation (done by reflection)
184184
val obj = constructor.newInstance(*jsonValues.toArray())
185-
186185
return obj as Mutation<Operation.Data, Operation.Data, Operation.Variables>
187186
}
188187

offix/src/main/java/org/aerogear/offix/interceptor/ConflictInterceptor.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ConflictInterceptor(private val conflictResolutionImpl: ConflictResolution
3737
queueCallback.addLast(callBack)
3838
}
3939
Log.d("$TAG 1", "${request.operation}")
40-
Log.d(TAG, "Size of OfflineCallback list ${queueCallback.size}")
40+
Log.d(TAG, "Size of queue callback list which stores all mutations ${queueCallback.size}")
4141

4242
/* Check is the network connection is there or not.
4343
*/
@@ -67,8 +67,7 @@ class ConflictInterceptor(private val conflictResolutionImpl: ConflictResolution
6767
*/
6868
if (Offline.requestList.isNotEmpty()) {
6969
chain.proceedAsync(request, dispatcher, OffixConflictCallback(conflictResolutionImpl))
70-
// Offline.requestList.remove(request)
71-
Log.d("$TAG 100", "If list is not empty: ${Offline.requestList.size}")
70+
Log.d("$TAG 100", "Net comes and requestList is not empty: ${Offline.requestList.size}")
7271
/* When user comes from offline to online, we wait for the user to perform any mutation.
7372
Now along with the mutation performed by the user, we fetch the mutation requests stored in the list and
7473
replicate them back to the server.
@@ -80,6 +79,7 @@ class ConflictInterceptor(private val conflictResolutionImpl: ConflictResolution
8079
chain.proceedAsync(it, dispatcher, OfflineCallback(it))
8180
}
8281

82+
Offline.requestList.clear()
8383
} else {
8484
Log.d("$TAG 200", "--------")
8585
chain.proceedAsync(request, dispatcher, OffixConflictCallback(conflictResolutionImpl))
@@ -144,9 +144,9 @@ class ConflictInterceptor(private val conflictResolutionImpl: ConflictResolution
144144
val userOfflineCallback = queueCallback.removeFirst()
145145
override fun onResponse(response: ApolloInterceptor.InterceptorResponse) {
146146
Log.d(TAG, "onResponse()")
147-
Log.d(TAG, "OfflineCallback: Size of OfflineCallback list ${queueCallback.size}")
147+
Log.d(TAG, "OfflineCallback: Size of OfflineCallback list--- ${queueCallback.size}")
148148
Offline.requestList.remove(request)
149-
Log.d(TAG, "SIZE OF Request LIST in OfflineCallback: ${Offline.requestList.size}")
149+
Log.d(TAG, "SIZE OF Request LIST in OfflineCallback ****: ${Offline.requestList.size}")
150150
userOfflineCallback.onResponse(response)
151151
}
152152

sample/server/db.sqlite

0 Bytes
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
query findUsers($fields: UserFilter!){
2+
findUsers(fields: $fields){
3+
id
4+
firstName
5+
lastName
6+
title
7+
email
8+
taskId
9+
creationmetadataId
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mutation updateUser($id: ID!, $input: UserInput!){
2+
updateUser(id: $id, input: $input){
3+
id
4+
firstName
5+
lastName
6+
title
7+
email
8+
taskId
9+
creationmetadataId
10+
}
11+
}

sample/src/main/java/org/aerogear/graphqlandroid/Utils.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory
1313
import com.apollographql.apollo.cache.normalized.sql.ApolloSqlHelper
1414
import com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCacheFactory
1515
import com.apollographql.apollo.subscription.WebSocketSubscriptionTransport
16-
import okhttp3.Interceptor
1716
import okhttp3.OkHttpClient
1817
import org.aerogear.offix.interceptor.ConflictInterceptor
19-
import java.nio.charset.Charset
2018

2119
object Utils {
2220

0 commit comments

Comments
 (0)