Før feilsøking 3
This commit is contained in:
parent
6728516359
commit
0d55b851a9
2 changed files with 35 additions and 22 deletions
|
|
@ -109,10 +109,12 @@ public class MainActivity extends AppCompatActivity {
|
||||||
checkExactAlarmPermission();
|
checkExactAlarmPermission();
|
||||||
checkLoginState();
|
checkLoginState();
|
||||||
|
|
||||||
|
// FIKSET: Registrering med flagg for å unngå feil ved commit/API 34
|
||||||
|
IntentFilter filter = new IntentFilter(RetrofitClient.ACTION_AUTH_FAILED);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
registerReceiver(authFailedReceiver, new IntentFilter(RetrofitClient.ACTION_AUTH_FAILED), Context.RECEIVER_NOT_EXPORTED);
|
registerReceiver(authFailedReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
|
||||||
} else {
|
} else {
|
||||||
registerReceiver(authFailedReceiver, new IntentFilter(RetrofitClient.ACTION_AUTH_FAILED));
|
registerReceiver(authFailedReceiver, filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,8 +138,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupTaskReminders() {
|
private void setupTaskReminders() {
|
||||||
|
// ENDRET: 12 timer er mer responsivt enn 2 dager
|
||||||
PeriodicWorkRequest taskCheck = new PeriodicWorkRequest.Builder(
|
PeriodicWorkRequest taskCheck = new PeriodicWorkRequest.Builder(
|
||||||
TaskReminderWorker.class, 2, TimeUnit.DAYS).build();
|
TaskReminderWorker.class, 12, TimeUnit.HOURS).build();
|
||||||
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
|
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
|
||||||
"TaskReminder", ExistingPeriodicWorkPolicy.KEEP, taskCheck);
|
"TaskReminder", ExistingPeriodicWorkPolicy.KEEP, taskCheck);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ public class RetrofitClient {
|
||||||
|
|
||||||
public static WordPressApiService getApiService() {
|
public static WordPressApiService getApiService() {
|
||||||
if (retrofit == null) {
|
if (retrofit == null) {
|
||||||
|
|
||||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
|
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
|
||||||
|
|
@ -31,29 +32,38 @@ public class RetrofitClient {
|
||||||
|
|
||||||
OkHttpClient client = new OkHttpClient.Builder()
|
OkHttpClient client = new OkHttpClient.Builder()
|
||||||
.addInterceptor(logging)
|
.addInterceptor(logging)
|
||||||
.addInterceptor(chain -> {
|
.addInterceptor(new Interceptor() {
|
||||||
Request originalRequest = chain.request();
|
@Override
|
||||||
Request.Builder builder = originalRequest.newBuilder();
|
public Response intercept(Chain chain) throws IOException {
|
||||||
String dynamicCookie = UserManager.getInstance().getCookie();
|
Request originalRequest = chain.request();
|
||||||
if (dynamicCookie != null && !dynamicCookie.isEmpty()) {
|
Request.Builder builder = originalRequest.newBuilder();
|
||||||
builder.header("Cookie", dynamicCookie);
|
|
||||||
}
|
|
||||||
return chain.proceed(builder.build());
|
|
||||||
})
|
|
||||||
.addInterceptor(chain -> {
|
|
||||||
Request request = chain.request();
|
|
||||||
Response response = chain.proceed(request);
|
|
||||||
|
|
||||||
if (response.code() == 401 || response.code() == 403) {
|
// Bruker den ekte dynamiske cookien fra UserManager
|
||||||
if (!request.url().toString().contains("kbs/v1/login")) {
|
String dynamicCookie = UserManager.getInstance().getCookie();
|
||||||
Intent intent = new Intent(ACTION_AUTH_FAILED);
|
if (dynamicCookie != null && !dynamicCookie.isEmpty()) {
|
||||||
intent.setPackage("com.kbs.kbsintranett");
|
builder.header("Cookie", dynamicCookie);
|
||||||
if (KbsApplication.getContext() != null) {
|
}
|
||||||
KbsApplication.getContext().sendBroadcast(intent);
|
|
||||||
|
return chain.proceed(builder.build());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.addInterceptor(new Interceptor() {
|
||||||
|
@Override
|
||||||
|
public Response intercept(Chain chain) throws IOException {
|
||||||
|
Request request = chain.request();
|
||||||
|
Response response = chain.proceed(request);
|
||||||
|
|
||||||
|
if (response.code() == 401 || response.code() == 403) {
|
||||||
|
if (!request.url().toString().contains("kbs/v1/login")) {
|
||||||
|
Intent intent = new Intent(ACTION_AUTH_FAILED);
|
||||||
|
intent.setPackage("com.kbs.kbsintranett");
|
||||||
|
if (KbsApplication.getContext() != null) {
|
||||||
|
KbsApplication.getContext().sendBroadcast(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
return response;
|
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue