Før håndbok
This commit is contained in:
parent
b74c8715ef
commit
e4affef594
7 changed files with 6012 additions and 74 deletions
|
|
@ -4,14 +4,12 @@ plugins {
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.kbs.kbsintranett"
|
namespace = "com.kbs.kbsintranett"
|
||||||
compileSdk {
|
compileSdk = 34
|
||||||
version = release(36)
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.kbs.kbsintranett"
|
applicationId = "com.kbs.kbsintranett"
|
||||||
minSdk = 28
|
minSdk = 28
|
||||||
targetSdk = 36
|
targetSdk = 34
|
||||||
versionCode = 1
|
versionCode = 1
|
||||||
versionName = "1.0"
|
versionName = "1.0"
|
||||||
|
|
||||||
|
|
@ -28,6 +26,7 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
// ENDRET: Oppgradert til Java 11 for å fikse build warnings
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
}
|
}
|
||||||
|
|
@ -47,8 +46,8 @@ dependencies {
|
||||||
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
|
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
|
||||||
implementation("com.google.code.gson:gson:2.10.1")
|
implementation("com.google.code.gson:gson:2.10.1")
|
||||||
|
|
||||||
// Navigation Component (KORRIGERT FOR KOTLIN DSL)
|
// Navigation Component
|
||||||
val navVersion = "2.8.5" // Oppdatert til en nyere, stabil versjon
|
val navVersion = "2.8.5"
|
||||||
implementation("androidx.navigation:navigation-fragment:$navVersion")
|
implementation("androidx.navigation:navigation-fragment:$navVersion")
|
||||||
implementation("androidx.navigation:navigation-ui:$navVersion")
|
implementation("androidx.navigation:navigation-ui:$navVersion")
|
||||||
|
|
||||||
|
|
@ -57,4 +56,7 @@ dependencies {
|
||||||
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
|
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
|
||||||
|
|
||||||
implementation("androidx.work:work-runtime:2.9.0")
|
implementation("androidx.work:work-runtime:2.9.0")
|
||||||
|
|
||||||
|
// Swipe Refresh Layout
|
||||||
|
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
package="com.kbs.kbsintranett">
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,12 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.navigation.Navigation;
|
import androidx.navigation.Navigation;
|
||||||
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
@ -33,20 +33,24 @@ public class FormsListFragment extends Fragment {
|
||||||
private LinearLayout formsContainer;
|
private LinearLayout formsContainer;
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
private TextView errorText;
|
private TextView errorText;
|
||||||
|
private SwipeRefreshLayout swipeRefreshLayout;
|
||||||
private static final Pattern TITLE_NUMBER_PATTERN = Pattern.compile("^(\\d+)[.\\s-]+\\s*(.*)");
|
private static final Pattern TITLE_NUMBER_PATTERN = Pattern.compile("^(\\d+)[.\\s-]+\\s*(.*)");
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_forms_list, container, false);
|
View view = inflater.inflate(R.layout.fragment_forms_list, container, false);
|
||||||
formsContainer = view.findViewById(R.id.forms_container);
|
|
||||||
|
|
||||||
|
formsContainer = view.findViewById(R.id.forms_container);
|
||||||
|
swipeRefreshLayout = view.findViewById(R.id.swipe_refresh);
|
||||||
|
|
||||||
|
// Opprett en ProgressBar manuelt for første gangs lasting
|
||||||
progressBar = new ProgressBar(getContext());
|
progressBar = new ProgressBar(getContext());
|
||||||
LinearLayout.LayoutParams progressParams = new LinearLayout.LayoutParams(
|
LinearLayout.LayoutParams progressParams = new LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
progressParams.gravity = Gravity.CENTER;
|
progressParams.gravity = Gravity.CENTER;
|
||||||
progressBar.setLayoutParams(progressParams);
|
progressBar.setLayoutParams(progressParams);
|
||||||
|
|
||||||
formsContainer.addView(progressBar);
|
formsContainer.addView(progressBar);
|
||||||
|
|
||||||
errorText = new TextView(getContext());
|
errorText = new TextView(getContext());
|
||||||
|
|
@ -55,29 +59,47 @@ public class FormsListFragment extends Fragment {
|
||||||
errorText.setPadding(20, 20, 20, 20);
|
errorText.setPadding(20, 20, 20, 20);
|
||||||
formsContainer.addView(errorText);
|
formsContainer.addView(errorText);
|
||||||
|
|
||||||
|
// Sett opp listener for swipe
|
||||||
|
swipeRefreshLayout.setOnRefreshListener(() -> {
|
||||||
|
fetchFormsList();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Hent data første gang
|
||||||
fetchFormsList();
|
fetchFormsList();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchFormsList() {
|
private void fetchFormsList() {
|
||||||
RetrofitClient.getApiService().getFormsListMap().enqueue(new Callback<Map<String, GravityForm>>() {
|
// Skjul feilmelding før ny henting
|
||||||
|
if (errorText != null) errorText.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
RetrofitClient.getApiService().getFormsList().enqueue(new Callback<List<GravityForm>>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<Map<String, GravityForm>> call, Response<Map<String, GravityForm>> response) {
|
public void onResponse(Call<List<GravityForm>> call, Response<List<GravityForm>> response) {
|
||||||
if (!isAdded()) return;
|
if (!isAdded()) return;
|
||||||
|
|
||||||
|
// Stopp lasting-indikatorer
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
|
|
||||||
if (response.isSuccessful() && response.body() != null) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
|
List<GravityForm> allForms = response.body();
|
||||||
List<GravityForm> activeForms = new ArrayList<>();
|
List<GravityForm> activeForms = new ArrayList<>();
|
||||||
|
|
||||||
for (GravityForm form : response.body().values()) {
|
for (GravityForm form : allForms) {
|
||||||
// 1. Sjekk om skjemaet er aktivt (Bruker nå metoden i GravityForm)
|
|
||||||
if (form.getIsActive()) {
|
if (form.getIsActive()) {
|
||||||
|
// NYTT: Hardkodet filtrering av skjemaer som ikke skal vises i listen
|
||||||
|
// ID 10 = HMS-bekreftelse (Skal ligge i Håndbok/separat flyt)
|
||||||
|
// ID 18 = Refusjon-vedlegg (Er et underskjema som brukes av ID 16)
|
||||||
|
if (form.id == 10 || form.id == 18) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
activeForms.add(form);
|
activeForms.add(form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Sorter basert på tallet i tittelen
|
|
||||||
Collections.sort(activeForms, new Comparator<GravityForm>() {
|
Collections.sort(activeForms, new Comparator<GravityForm>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(GravityForm f1, GravityForm f2) {
|
public int compare(GravityForm f1, GravityForm f2) {
|
||||||
|
|
@ -86,22 +108,25 @@ public class FormsListFragment extends Fragment {
|
||||||
return Integer.compare(num1, num2);
|
return Integer.compare(num1, num2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
populateList(activeForms);
|
populateList(activeForms);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String msg = "Kunne ikke hente skjemaer. Kode: " + response.code();
|
String msg = "Kunne ikke hente skjemaer. Kode: " + response.code();
|
||||||
if (response.code() == 401 || response.code() == 403) {
|
if (response.code() == 401 || response.code() == 403) {
|
||||||
msg += "\n(Mangler tilgang. Er du admin?)";
|
msg += "\n(Mangler tilgang. Prøv å logge ut og inn igjen.)";
|
||||||
}
|
}
|
||||||
showError(msg);
|
showError(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<Map<String, GravityForm>> call, Throwable t) {
|
public void onFailure(Call<List<GravityForm>> call, Throwable t) {
|
||||||
if (!isAdded()) return;
|
if (!isAdded()) return;
|
||||||
|
|
||||||
|
// Stopp lasting-indikatorer
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
|
|
||||||
showError("Nettverksfeil: " + t.getMessage());
|
showError("Nettverksfeil: " + t.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -116,7 +141,6 @@ public class FormsListFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (GravityForm form : forms) {
|
for (GravityForm form : forms) {
|
||||||
// FIX: form.id er allerede en int i GravityForm.java, så vi trenger ikke parse
|
|
||||||
int formId = form.id;
|
int formId = form.id;
|
||||||
String cleanTitle = cleanTitle(form.title);
|
String cleanTitle = cleanTitle(form.title);
|
||||||
addFormButton(formsContainer, cleanTitle, formId);
|
addFormButton(formsContainer, cleanTitle, formId);
|
||||||
|
|
@ -147,6 +171,7 @@ public class FormsListFragment extends Fragment {
|
||||||
private void showError(String message) {
|
private void showError(String message) {
|
||||||
if (formsContainer == null) return;
|
if (formsContainer == null) return;
|
||||||
formsContainer.removeAllViews();
|
formsContainer.removeAllViews();
|
||||||
|
|
||||||
TextView tv = new TextView(getContext());
|
TextView tv = new TextView(getContext());
|
||||||
tv.setText(message);
|
tv.setText(message);
|
||||||
tv.setTextColor(Color.RED);
|
tv.setTextColor(Color.RED);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// FILSTI: app\src\main\java\com\kbs\kbsintranett\WordPressApiService.java
|
||||||
package com.kbs.kbsintranett;
|
package com.kbs.kbsintranett;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
|
@ -16,12 +17,12 @@ import retrofit2.http.PartMap;
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
|
|
||||||
public interface WordPressApiService {
|
public interface WordPressApiService {
|
||||||
// 1. Hent nyheter - ENDRET: Lagt til &_embed for å få bilde og kategori
|
// 1. Hent nyheter
|
||||||
@GET("wp-json/wp/v2/posts?per_page=10&_embed")
|
@GET("wp-json/wp/v2/posts?per_page=10&_embed")
|
||||||
Call<List<WpPost>> getPosts();
|
Call<List<WpPost>> getPosts();
|
||||||
|
|
||||||
// 2. Hent et spesifikt skjema med ID
|
// 2. Hent et spesifikt skjema med ID (Oppdatert til custom endpoint for tilgang)
|
||||||
@GET("wp-json/gf/v2/forms/{id}")
|
@GET("wp-json/kbs/v1/forms/{id}")
|
||||||
Call<GravityForm> getForm(@Path("id") int formId);
|
Call<GravityForm> getForm(@Path("id") int formId);
|
||||||
|
|
||||||
// 3. SEND INN SKJEMA (JSON-data uten filer)
|
// 3. SEND INN SKJEMA (JSON-data uten filer)
|
||||||
|
|
@ -32,9 +33,9 @@ public interface WordPressApiService {
|
||||||
@POST("wp-json/kbs/v1/login")
|
@POST("wp-json/kbs/v1/login")
|
||||||
Call<LoginResponse> googleLogin(@Body LoginRequest request);
|
Call<LoginResponse> googleLogin(@Body LoginRequest request);
|
||||||
|
|
||||||
// 5. HENT LISTE AV SKJEMAER
|
// 5. HENT LISTE AV SKJEMAER (Oppdatert til custom endpoint og List)
|
||||||
@GET("wp-json/gf/v2/forms")
|
@GET("wp-json/kbs/v1/forms")
|
||||||
Call<Map<String, GravityForm>> getFormsListMap();
|
Call<List<GravityForm>> getFormsList();
|
||||||
|
|
||||||
// 6. SEND INN SKJEMA (MULTIPART - for filopplasting)
|
// 6. SEND INN SKJEMA (MULTIPART - for filopplasting)
|
||||||
@Multipart
|
@Multipart
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/main_layout" android:layout_width="match_parent"
|
android:id="@+id/main_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
|
|
@ -16,6 +17,11 @@
|
||||||
android:layout_marginBottom="20dp"
|
android:layout_marginBottom="20dp"
|
||||||
android:textColor="#333333"/>
|
android:textColor="#333333"/>
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swipe_refresh"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
@ -27,4 +33,6 @@
|
||||||
android:orientation="vertical" />
|
android:orientation="vertical" />
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
@ -2728,62 +2728,179 @@ package com.kbs.kbsintranett;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.navigation.Navigation;
|
import androidx.navigation.Navigation;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
public class FormsListFragment extends Fragment {
|
public class FormsListFragment extends Fragment {
|
||||||
|
|
||||||
|
private LinearLayout formsContainer;
|
||||||
|
private ProgressBar progressBar;
|
||||||
|
private TextView errorText;
|
||||||
|
|
||||||
|
private static final Pattern TITLE_NUMBER_PATTERN = Pattern.compile("^(\\d+)[.\\s-]+\\s*(.*)");
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_forms_list, container, false);
|
View view = inflater.inflate(R.layout.fragment_forms_list, container, false);
|
||||||
LinearLayout formsContainer = view.findViewById(R.id.forms_container);
|
formsContainer = view.findViewById(R.id.forms_container);
|
||||||
|
|
||||||
// Legger til knappene for de ulike skjemaene
|
progressBar = new ProgressBar(getContext());
|
||||||
addFormButton(formsContainer, "1. Ansatteopplysninger", 1);
|
LinearLayout.LayoutParams progressParams = new LinearLayout.LayoutParams(
|
||||||
addFormButton(formsContainer, "4. RUH (Rapport om uønsket hendelse)", 4);
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
addFormButton(formsContainer, "9. Sikkerhetskurs / Kompetansebevis", 9);
|
progressParams.gravity = Gravity.CENTER;
|
||||||
addFormButton(formsContainer, "10. HMS-bekreftelse", 10);
|
progressBar.setLayoutParams(progressParams);
|
||||||
addFormButton(formsContainer, "11. Egenmelding", 11);
|
formsContainer.addView(progressBar);
|
||||||
addFormButton(formsContainer, "12. Sjekkliste for firmabil", 12);
|
|
||||||
addFormButton(formsContainer, "14. SJA (Sikker Jobbanalyse)", 14);
|
errorText = new TextView(getContext());
|
||||||
addFormButton(formsContainer, "15. Fraværsvarsel", 15);
|
errorText.setTextColor(Color.RED);
|
||||||
addFormButton(formsContainer, "16. Refusjon utlegg", 16);
|
errorText.setVisibility(View.GONE);
|
||||||
addFormButton(formsContainer, "21. Forberedelse til medarbeidersamtale", 21);
|
errorText.setPadding(20, 20, 20, 20);
|
||||||
addFormButton(formsContainer, "22. Medarbeiderundersøkelse", 22);
|
formsContainer.addView(errorText);
|
||||||
|
|
||||||
|
fetchFormsList();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fetchFormsList() {
|
||||||
|
RetrofitClient.getApiService().getFormsListMap().enqueue(new Callback<Map<String, GravityForm>>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<Map<String, GravityForm>> call, Response<Map<String, GravityForm>> response) {
|
||||||
|
if (!isAdded()) return;
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
|
List<GravityForm> activeForms = new ArrayList<>();
|
||||||
|
|
||||||
|
for (GravityForm form : response.body().values()) {
|
||||||
|
// 1. Sjekk om skjemaet er aktivt (Bruker nå metoden i GravityForm)
|
||||||
|
if (form.getIsActive()) {
|
||||||
|
activeForms.add(form);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Sorter basert på tallet i tittelen
|
||||||
|
Collections.sort(activeForms, new Comparator<GravityForm>() {
|
||||||
|
@Override
|
||||||
|
public int compare(GravityForm f1, GravityForm f2) {
|
||||||
|
int num1 = extractNumber(f1.title);
|
||||||
|
int num2 = extractNumber(f2.title);
|
||||||
|
return Integer.compare(num1, num2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
populateList(activeForms);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
String msg = "Kunne ikke hente skjemaer. Kode: " + response.code();
|
||||||
|
if (response.code() == 401 || response.code() == 403) {
|
||||||
|
msg += "\n(Mangler tilgang. Er du admin?)";
|
||||||
|
}
|
||||||
|
showError(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<Map<String, GravityForm>> call, Throwable t) {
|
||||||
|
if (!isAdded()) return;
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
showError("Nettverksfeil: " + t.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateList(List<GravityForm> forms) {
|
||||||
|
formsContainer.removeAllViews();
|
||||||
|
|
||||||
|
if (forms.isEmpty()) {
|
||||||
|
showError("Ingen aktive skjemaer funnet.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (GravityForm form : forms) {
|
||||||
|
// FIX: form.id er allerede en int i GravityForm.java, så vi trenger ikke parse
|
||||||
|
int formId = form.id;
|
||||||
|
String cleanTitle = cleanTitle(form.title);
|
||||||
|
addFormButton(formsContainer, cleanTitle, formId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void addFormButton(LinearLayout container, String title, int formId) {
|
private void addFormButton(LinearLayout container, String title, int formId) {
|
||||||
Button btn = new Button(getContext());
|
Button btn = new Button(getContext());
|
||||||
btn.setText(title);
|
btn.setText(title);
|
||||||
btn.setBackgroundColor(Color.parseColor("#0069B3")); // KBS Blå
|
btn.setBackgroundColor(Color.parseColor("#0069B3"));
|
||||||
btn.setTextColor(Color.WHITE);
|
btn.setTextColor(Color.WHITE);
|
||||||
btn.setPadding(30, 30, 30, 30);
|
btn.setPadding(30, 30, 30, 30);
|
||||||
|
|
||||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
params.setMargins(0, 0, 0, 20); // Litt avstand mellom knappene
|
params.setMargins(0, 0, 0, 20);
|
||||||
btn.setLayoutParams(params);
|
btn.setLayoutParams(params);
|
||||||
|
|
||||||
btn.setOnClickListener(v -> {
|
btn.setOnClickListener(v -> {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt("formId", formId);
|
bundle.putInt("formId", formId);
|
||||||
// HER VAR FEILEN: Endret R.id.nav_forms til riktig action ID
|
|
||||||
Navigation.findNavController(v).navigate(R.id.action_formsListFragment_to_formsDetailFragment, bundle);
|
Navigation.findNavController(v).navigate(R.id.action_formsListFragment_to_formsDetailFragment, bundle);
|
||||||
});
|
});
|
||||||
|
|
||||||
container.addView(btn);
|
container.addView(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showError(String message) {
|
||||||
|
if (formsContainer == null) return;
|
||||||
|
formsContainer.removeAllViews();
|
||||||
|
TextView tv = new TextView(getContext());
|
||||||
|
tv.setText(message);
|
||||||
|
tv.setTextColor(Color.RED);
|
||||||
|
tv.setTextSize(16);
|
||||||
|
formsContainer.addView(tv);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int extractNumber(String title) {
|
||||||
|
if (title == null) return 9999;
|
||||||
|
Matcher m = TITLE_NUMBER_PATTERN.matcher(title.trim());
|
||||||
|
if (m.find()) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(m.group(1));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 9999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 9999;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String cleanTitle(String title) {
|
||||||
|
if (title == null) return "";
|
||||||
|
Matcher m = TITLE_NUMBER_PATTERN.matcher(title.trim());
|
||||||
|
if (m.find()) {
|
||||||
|
return m.group(2);
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
============================================================
|
============================================================
|
||||||
|
|
@ -2870,13 +2987,15 @@ public class GravityField {
|
||||||
@SerializedName("content")
|
@SerializedName("content")
|
||||||
public String content;
|
public String content;
|
||||||
|
|
||||||
|
// --- BRUKER ADAPTEREN HER ---
|
||||||
|
@JsonAdapter(InputsAdapter.class)
|
||||||
@SerializedName("inputs")
|
@SerializedName("inputs")
|
||||||
public List<GravityField> inputs;
|
public List<GravityField> inputs;
|
||||||
|
// ---------------------------
|
||||||
|
|
||||||
@SerializedName("isHidden")
|
@SerializedName("isHidden")
|
||||||
public boolean isHidden;
|
public boolean isHidden;
|
||||||
|
|
||||||
// NYTT: For å sjekke om feltet er Read Only (f.eks dato i refusjon)
|
|
||||||
@SerializedName("gwreadonly_enable")
|
@SerializedName("gwreadonly_enable")
|
||||||
public boolean readOnly;
|
public boolean readOnly;
|
||||||
|
|
||||||
|
|
@ -2891,33 +3010,20 @@ public class GravityField {
|
||||||
public String gpnfForm;
|
public String gpnfForm;
|
||||||
|
|
||||||
public static class Choice {
|
public static class Choice {
|
||||||
@SerializedName("text")
|
@SerializedName("text") public String text;
|
||||||
public String text;
|
@SerializedName("value") public String value;
|
||||||
|
|
||||||
@SerializedName("value")
|
|
||||||
public String value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConditionalLogic {
|
public static class ConditionalLogic {
|
||||||
@SerializedName("actionType")
|
@SerializedName("actionType") public String actionType;
|
||||||
public String actionType;
|
@SerializedName("logicType") public String logicType;
|
||||||
|
@SerializedName("rules") public List<Rule> rules;
|
||||||
@SerializedName("logicType")
|
|
||||||
public String logicType;
|
|
||||||
|
|
||||||
@SerializedName("rules")
|
|
||||||
public List<Rule> rules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Rule {
|
public static class Rule {
|
||||||
@SerializedName("fieldId")
|
@SerializedName("fieldId") public String fieldId;
|
||||||
public String fieldId;
|
@SerializedName("operator") public String operator;
|
||||||
|
@SerializedName("value") public String value;
|
||||||
@SerializedName("operator")
|
|
||||||
public String operator;
|
|
||||||
|
|
||||||
@SerializedName("value")
|
|
||||||
public String value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2939,11 +3045,19 @@ public class GravityForm {
|
||||||
@SerializedName("description")
|
@SerializedName("description")
|
||||||
public String description;
|
public String description;
|
||||||
|
|
||||||
|
// Endret til Object for å være robust mot både "1" (String) og 1 (Int) fra API
|
||||||
@SerializedName("is_active")
|
@SerializedName("is_active")
|
||||||
public String isActive; // "1" = Aktiv, "0" = Inaktiv
|
public Object isActive;
|
||||||
|
|
||||||
@SerializedName("fields")
|
@SerializedName("fields")
|
||||||
public List<GravityField> fields;
|
public List<GravityField> fields;
|
||||||
|
|
||||||
|
// Hjelpemetode for å sjekke om skjemaet er aktivt
|
||||||
|
public boolean getIsActive() {
|
||||||
|
if (isActive == null) return false;
|
||||||
|
String s = isActive.toString();
|
||||||
|
return "1".equals(s) || "true".equalsIgnoreCase(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
============================================================
|
============================================================
|
||||||
|
|
@ -3201,6 +3315,40 @@ public class HomeFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
============================================================
|
||||||
|
FILSTI: app\src\main\java\com\kbs\kbsintranett\InputsAdapter.java
|
||||||
|
============================================================
|
||||||
|
package com.kbs.kbsintranett;
|
||||||
|
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class InputsAdapter implements JsonDeserializer<List<GravityField>> {
|
||||||
|
@Override
|
||||||
|
public List<GravityField> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
if (json.isJsonNull()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
// Fikser krasjen: Hvis Gravity Forms sender "" i stedet for [], returner tom liste
|
||||||
|
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
if (json.isJsonArray()) {
|
||||||
|
List<GravityField> list = new ArrayList<>();
|
||||||
|
for (JsonElement e : json.getAsJsonArray()) {
|
||||||
|
list.add(context.deserialize(e, GravityField.class));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
============================================================
|
============================================================
|
||||||
FILSTI: app\src\main\java\com\kbs\kbsintranett\LoginFragment.java
|
FILSTI: app\src\main\java\com\kbs\kbsintranett\LoginFragment.java
|
||||||
============================================================
|
============================================================
|
||||||
|
|
|
||||||
5756
hele_prosjektet.txt.old
Normal file
5756
hele_prosjektet.txt.old
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue