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();
|
||||
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) {
|
||||
registerReceiver(authFailedReceiver, new IntentFilter(RetrofitClient.ACTION_AUTH_FAILED), Context.RECEIVER_NOT_EXPORTED);
|
||||
registerReceiver(authFailedReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
|
||||
} else {
|
||||
registerReceiver(authFailedReceiver, new IntentFilter(RetrofitClient.ACTION_AUTH_FAILED));
|
||||
registerReceiver(authFailedReceiver, filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -136,8 +138,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
private void setupTaskReminders() {
|
||||
// ENDRET: 12 timer er mer responsivt enn 2 dager
|
||||
PeriodicWorkRequest taskCheck = new PeriodicWorkRequest.Builder(
|
||||
TaskReminderWorker.class, 2, TimeUnit.DAYS).build();
|
||||
TaskReminderWorker.class, 12, TimeUnit.HOURS).build();
|
||||
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
|
||||
"TaskReminder", ExistingPeriodicWorkPolicy.KEEP, taskCheck);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public class RetrofitClient {
|
|||
|
||||
public static WordPressApiService getApiService() {
|
||||
if (retrofit == null) {
|
||||
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
if (BuildConfig.DEBUG) {
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
|
||||
|
|
@ -31,29 +32,38 @@ public class RetrofitClient {
|
|||
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
.addInterceptor(logging)
|
||||
.addInterceptor(chain -> {
|
||||
Request originalRequest = chain.request();
|
||||
Request.Builder builder = originalRequest.newBuilder();
|
||||
String dynamicCookie = UserManager.getInstance().getCookie();
|
||||
if (dynamicCookie != null && !dynamicCookie.isEmpty()) {
|
||||
builder.header("Cookie", dynamicCookie);
|
||||
}
|
||||
return chain.proceed(builder.build());
|
||||
})
|
||||
.addInterceptor(chain -> {
|
||||
Request request = chain.request();
|
||||
Response response = chain.proceed(request);
|
||||
.addInterceptor(new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request originalRequest = chain.request();
|
||||
Request.Builder builder = originalRequest.newBuilder();
|
||||
|
||||
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);
|
||||
// Bruker den ekte dynamiske cookien fra UserManager
|
||||
String dynamicCookie = UserManager.getInstance().getCookie();
|
||||
if (dynamicCookie != null && !dynamicCookie.isEmpty()) {
|
||||
builder.header("Cookie", dynamicCookie);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue