diff --git a/app/src/main/java/core/notevault/sync/ApiClient.java b/app/src/main/java/core/notevault/sync/ApiClient.java index 1ba676f..f3ec62f 100644 --- a/app/src/main/java/core/notevault/sync/ApiClient.java +++ b/app/src/main/java/core/notevault/sync/ApiClient.java @@ -3,6 +3,7 @@ package core.notevault.sync; import android.content.Context; import android.content.SharedPreferences; import core.notevault.sync.auth.AuthInterceptor; +import core.notevault.sync.auth.TokenManager; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; @@ -16,9 +17,9 @@ public class ApiClient { HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); - SharedPreferences sharedPreferences = context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE); + TokenManager tokenManager = new TokenManager(context); OkHttpClient client = new OkHttpClient.Builder() - .addInterceptor(new AuthInterceptor(sharedPreferences)) + .addInterceptor(new AuthInterceptor(tokenManager)) .addInterceptor(loggingInterceptor) .build(); diff --git a/app/src/main/java/core/notevault/sync/SyncWorker.java b/app/src/main/java/core/notevault/sync/SyncWorker.java index 7caf926..eda9cfe 100644 --- a/app/src/main/java/core/notevault/sync/SyncWorker.java +++ b/app/src/main/java/core/notevault/sync/SyncWorker.java @@ -105,7 +105,7 @@ public class SyncWorker extends Worker{ Log.d("SyncWorker", "Process SyncResponse"); //Assign local Concert entries the provided Server ID List syncResponses = new ArrayList<>(); - for(SyncCreateResponse createResponse : syncResponse.getCreateResonses()) { + for(SyncCreateResponse createResponse : syncResponse.getCreateResponses()) { database.updateConcertServerUUID(createResponse.getServerObjectUUID(), createResponse.getDeviceSpecificObjectID()); syncResponses.add(new SyncResponse(createResponse.getServerObjectUUID(), SyncAction.TOBEUPLOADED, SyncObject.CONCERT)); } diff --git a/app/src/main/java/core/notevault/sync/auth/AuthInterceptor.java b/app/src/main/java/core/notevault/sync/auth/AuthInterceptor.java index 3f7d7ee..5f6cb6f 100644 --- a/app/src/main/java/core/notevault/sync/auth/AuthInterceptor.java +++ b/app/src/main/java/core/notevault/sync/auth/AuthInterceptor.java @@ -10,22 +10,17 @@ import okhttp3.Response; import java.io.IOException; public class AuthInterceptor implements Interceptor { - private SharedPreferences sharedPreferences; + private TokenManager tokenManager; - public AuthInterceptor(SharedPreferences sharedPreferences) { - this.sharedPreferences = sharedPreferences; - String token = sharedPreferences.getString("jwt_token", null); + public AuthInterceptor(TokenManager tokenManager) { + this.tokenManager = tokenManager; } @Override public Response intercept(Chain chain) throws IOException { Request originalRequest = chain.request(); - if(originalRequest.url().encodedPath().equals("/api/v1/auth/login")) { - return chain.proceed(originalRequest); - } - - String token = sharedPreferences.getString("jwt_token", null); + String token = tokenManager.getToken(); if (token == null) { return chain.proceed(originalRequest); } diff --git a/app/src/main/java/core/notevault/sync/synchronisation/SyncResponseModel.java b/app/src/main/java/core/notevault/sync/synchronisation/SyncResponseModel.java index 3cbf003..d678bc7 100644 --- a/app/src/main/java/core/notevault/sync/synchronisation/SyncResponseModel.java +++ b/app/src/main/java/core/notevault/sync/synchronisation/SyncResponseModel.java @@ -6,7 +6,7 @@ public class SyncResponseModel { private List toBeUploaded; private List toBeDownloaded; private List toBeDeleted; - private List createResonses; + private List createResponses; public List getToBeUploaded() { return toBeUploaded; @@ -32,11 +32,11 @@ public class SyncResponseModel { this.toBeDeleted = toBeDeleted; } - public List getCreateResonses() { - return createResonses; + public List getCreateResponses() { + return createResponses; } - public void setCreateResonses(List createResonses) { - this.createResonses = createResonses; + public void setCreateResponses(List createResponses) { + this.createResponses = createResponses; } }