Førkalenderfargeendring
This commit is contained in:
parent
3b2d19bd0b
commit
71bfb191bc
6 changed files with 1379 additions and 420 deletions
|
|
@ -54,6 +54,9 @@ public class AuthRepository {
|
||||||
// Lagre utvidet info i UserManager
|
// Lagre utvidet info i UserManager
|
||||||
UserManager.getInstance().setExtendedUserInfo(fName, lName, stilling, mobil);
|
UserManager.getInstance().setExtendedUserInfo(fName, lName, stilling, mobil);
|
||||||
|
|
||||||
|
// Lagre listen over skrivbare kalendere
|
||||||
|
UserManager.getInstance().setWriteableCalendars(response.body().writeableCalendars);
|
||||||
|
|
||||||
callback.onSuccess(role);
|
callback.onSuccess(role);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,12 @@ public class CreateEventFragment extends Fragment {
|
||||||
|
|
||||||
btnSave = view.findViewById(R.id.btn_save_event);
|
btnSave = view.findViewById(R.id.btn_save_event);
|
||||||
|
|
||||||
|
// Initialiser tid (neste hele time)
|
||||||
|
startCal.add(Calendar.HOUR_OF_DAY, 1);
|
||||||
|
startCal.set(Calendar.MINUTE, 0);
|
||||||
|
endCal.setTime(startCal.getTime());
|
||||||
|
endCal.add(Calendar.HOUR_OF_DAY, 1);
|
||||||
|
|
||||||
setupCalendarSpinner();
|
setupCalendarSpinner();
|
||||||
setupReminderChips();
|
setupReminderChips();
|
||||||
|
|
||||||
|
|
@ -90,12 +96,6 @@ public class CreateEventFragment extends Fragment {
|
||||||
eventToEdit = (CalendarEvent) getArguments().getSerializable("edit_event");
|
eventToEdit = (CalendarEvent) getArguments().getSerializable("edit_event");
|
||||||
prefillForm(eventToEdit);
|
prefillForm(eventToEdit);
|
||||||
btnSave.setText("Oppdater Hendelse");
|
btnSave.setText("Oppdater Hendelse");
|
||||||
} else {
|
|
||||||
// Ny event: Standard tid (neste time)
|
|
||||||
startCal.add(Calendar.HOUR_OF_DAY, 1);
|
|
||||||
startCal.set(Calendar.MINUTE, 0);
|
|
||||||
endCal.setTime(startCal.getTime());
|
|
||||||
endCal.add(Calendar.HOUR_OF_DAY, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRecurrenceSpinner();
|
updateRecurrenceSpinner();
|
||||||
|
|
@ -115,8 +115,8 @@ public class CreateEventFragment extends Fragment {
|
||||||
spinnerRecurrence.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
spinnerRecurrence.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
// Unngå å overskrive ved innlasting
|
// Unngå å overskrive ved innlasting hvis vi allerede har satt en verdi
|
||||||
if (eventToEdit != null && position == 0) return;
|
if (eventToEdit != null && position == 0 && selectedRRule != null) return;
|
||||||
|
|
||||||
String selected = parent.getItemAtPosition(position).toString();
|
String selected = parent.getItemAtPosition(position).toString();
|
||||||
if (selected.equals("Egendefinert...")) {
|
if (selected.equals("Egendefinert...")) {
|
||||||
|
|
@ -152,10 +152,8 @@ public class CreateEventFragment extends Fragment {
|
||||||
Date d = simpleFormat.parse(start);
|
Date d = simpleFormat.parse(start);
|
||||||
startCal.setTime(d);
|
startCal.setTime(d);
|
||||||
|
|
||||||
// Sluttdato
|
|
||||||
if (event.getRawEndDate() != null) {
|
if (event.getRawEndDate() != null) {
|
||||||
Date e = simpleFormat.parse(event.getRawEndDate());
|
Date e = simpleFormat.parse(event.getRawEndDate());
|
||||||
// Google sender sluttdato eksklusiv (dagen etter). Vi trekker fra 1 dag for visning.
|
|
||||||
Calendar c = Calendar.getInstance();
|
Calendar c = Calendar.getInstance();
|
||||||
c.setTime(e);
|
c.setTime(e);
|
||||||
c.add(Calendar.DAY_OF_MONTH, -1);
|
c.add(Calendar.DAY_OF_MONTH, -1);
|
||||||
|
|
@ -179,23 +177,15 @@ public class CreateEventFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Varsler - Finn tag i den rå beskrivelsen
|
// Varsler
|
||||||
if (event.getDescription() != null) {
|
List<Integer> existingReminders = event.getReminders();
|
||||||
Pattern p = Pattern.compile("#varsel:([\\d,]+)");
|
if (!existingReminders.isEmpty()) {
|
||||||
Matcher m = p.matcher(event.getDescription());
|
// Fjern alle sjekkmerker først (15 min er default checked)
|
||||||
if (m.find()) {
|
for (int i = 0; i < chipGroupReminders.getChildCount(); i++) {
|
||||||
String[] parts = m.group(1).split(",");
|
((Chip) chipGroupReminders.getChildAt(i)).setChecked(false);
|
||||||
// Fjern alle sjekkmerker først
|
}
|
||||||
for (int i = 0; i < chipGroupReminders.getChildCount(); i++) {
|
for (int min : existingReminders) {
|
||||||
((Chip) chipGroupReminders.getChildAt(i)).setChecked(false);
|
checkChipByMinutes(min);
|
||||||
}
|
|
||||||
// Sett nye
|
|
||||||
for (String part : parts) {
|
|
||||||
try {
|
|
||||||
int min = Integer.parseInt(part);
|
|
||||||
checkChipByMinutes(min);
|
|
||||||
} catch (NumberFormatException e) {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -214,13 +204,11 @@ public class CreateEventFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupCalendarSpinner() {
|
private void setupCalendarSpinner() {
|
||||||
String[] calendars = {
|
// HENT DYNAMISK LISTE FRA USERMANAGER
|
||||||
"Felles",
|
List<String> calendars = UserManager.getInstance().getWriteableCalendars();
|
||||||
"Administrasjonen",
|
|
||||||
"Serviceavdelingen",
|
if (calendars.isEmpty()) calendars.add("Felles");
|
||||||
"Automasjonsavdelingen",
|
|
||||||
"Prosjektavdelingen"
|
|
||||||
};
|
|
||||||
spinnerCalendar.setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, calendars));
|
spinnerCalendar.setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, calendars));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -236,7 +224,6 @@ public class CreateEventFragment extends Fragment {
|
||||||
addChip("2 dager", 2880);
|
addChip("2 dager", 2880);
|
||||||
addChip("1 uke", 10080);
|
addChip("1 uke", 10080);
|
||||||
|
|
||||||
// Marker 15 min som standard KUN for ny event
|
|
||||||
if (eventToEdit == null) checkChipByMinutes(15);
|
if (eventToEdit == null) checkChipByMinutes(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -474,15 +461,12 @@ public class CreateEventFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NY: Henter navnet på kalenderen direkte fra Spinneren
|
||||||
private String getCalendarSlug() {
|
private String getCalendarSlug() {
|
||||||
int pos = spinnerCalendar.getSelectedItemPosition();
|
if (spinnerCalendar.getSelectedItem() != null) {
|
||||||
switch (pos) {
|
return spinnerCalendar.getSelectedItem().toString();
|
||||||
case 1: return "Administrasjonen";
|
|
||||||
case 2: return "Serviceavdelingen";
|
|
||||||
case 3: return "Automasjonsavdelingen";
|
|
||||||
case 4: return "Prosjektavdelingen";
|
|
||||||
default: return "Felles"; // case 0
|
|
||||||
}
|
}
|
||||||
|
return "Felles";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void submitEvent() {
|
private void submitEvent() {
|
||||||
|
|
@ -508,14 +492,12 @@ public class CreateEventFragment extends Fragment {
|
||||||
selectedRRule
|
selectedRRule
|
||||||
);
|
);
|
||||||
|
|
||||||
// HVIS VI REDIGERER, SETT ID
|
|
||||||
if (eventToEdit != null) {
|
if (eventToEdit != null) {
|
||||||
req.id = eventToEdit.getId();
|
req.id = eventToEdit.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(getContext(), eventToEdit != null ? "Oppdaterer..." : "Oppretter...", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), eventToEdit != null ? "Oppdaterer..." : "Oppretter...", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
// Velg riktig API-kall (Create vs Update)
|
|
||||||
Call<JsonElement> call;
|
Call<JsonElement> call;
|
||||||
if (eventToEdit != null) {
|
if (eventToEdit != null) {
|
||||||
call = RetrofitClient.getApiService().updateCalendarEvent(req);
|
call = RetrofitClient.getApiService().updateCalendarEvent(req);
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,11 @@ package com.kbs.kbsintranett;
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
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.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
import androidx.activity.result.ActivityResultLauncher;
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
import androidx.activity.result.contract.ActivityResultContracts;
|
import androidx.activity.result.contract.ActivityResultContracts;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
@ -65,8 +63,11 @@ public class HomeFragment extends Fragment {
|
||||||
profileBtn.setOnClickListener(v -> Navigation.findNavController(view).navigate(R.id.navigation_profile));
|
profileBtn.setOnClickListener(v -> Navigation.findNavController(view).navigate(R.id.navigation_profile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NY LOGIKK: Vis knapp hvis brukeren har tilgang til minst én kalender
|
||||||
Button btnCreateEvent = view.findViewById(R.id.btn_create_event);
|
Button btnCreateEvent = view.findViewById(R.id.btn_create_event);
|
||||||
if (UserManager.getInstance().isEditorOrAbove()) {
|
List<String> writeable = UserManager.getInstance().getWriteableCalendars();
|
||||||
|
|
||||||
|
if (writeable != null && !writeable.isEmpty()) {
|
||||||
btnCreateEvent.setVisibility(View.VISIBLE);
|
btnCreateEvent.setVisibility(View.VISIBLE);
|
||||||
btnCreateEvent.setOnClickListener(v -> {
|
btnCreateEvent.setOnClickListener(v -> {
|
||||||
Navigation.findNavController(view).navigate(R.id.action_home_to_create_event);
|
Navigation.findNavController(view).navigate(R.id.action_home_to_create_event);
|
||||||
|
|
@ -160,7 +161,6 @@ public class HomeFragment extends Fragment {
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
List<CalendarEvent> errorList = new ArrayList<>();
|
List<CalendarEvent> errorList = new ArrayList<>();
|
||||||
// FIKSET HER: La til "" som 5. argument (location)
|
|
||||||
errorList.add(new CalendarEvent("Kunne ikke laste kalender", "Sjekk nettverk", "!", "OBS", ""));
|
errorList.add(new CalendarEvent("Kunne ikke laste kalender", "Sjekk nettverk", "!", "OBS", ""));
|
||||||
recyclerView.setAdapter(new CalendarAdapter(errorList, null));
|
recyclerView.setAdapter(new CalendarAdapter(errorList, null));
|
||||||
}
|
}
|
||||||
|
|
@ -212,5 +212,4 @@ public class HomeFragment extends Fragment {
|
||||||
.build();
|
.build();
|
||||||
WorkManager.getInstance(requireContext()).enqueue(notifRequest);
|
WorkManager.getInstance(requireContext()).enqueue(notifRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
package com.kbs.kbsintranett;
|
package com.kbs.kbsintranett;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class LoginResponse {
|
public class LoginResponse {
|
||||||
public boolean success;
|
public boolean success;
|
||||||
|
|
||||||
@SerializedName("full_cookie")
|
@SerializedName("full_cookie")
|
||||||
public String fullCookie;
|
public String fullCookie;
|
||||||
|
|
||||||
|
|
@ -14,19 +14,21 @@ public class LoginResponse {
|
||||||
@SerializedName("user_id")
|
@SerializedName("user_id")
|
||||||
public int userId;
|
public int userId;
|
||||||
|
|
||||||
// --- NYE FELTER ---
|
|
||||||
@SerializedName("first_name")
|
@SerializedName("first_name")
|
||||||
public String firstName;
|
public String firstName;
|
||||||
|
|
||||||
@SerializedName("last_name")
|
@SerializedName("last_name")
|
||||||
public String lastName;
|
public String lastName;
|
||||||
|
|
||||||
@SerializedName("stilling") // Sjekk at JSON-nøkkelen fra WP matcher dette
|
@SerializedName("stilling")
|
||||||
public String stilling;
|
public String stilling;
|
||||||
|
|
||||||
@SerializedName("mobiltelefon") // Sjekk at JSON-nøkkelen fra WP matcher dette
|
@SerializedName("mobiltelefon")
|
||||||
public String mobiltelefon;
|
public String mobiltelefon;
|
||||||
// ------------------
|
|
||||||
|
// NYTT FELT: Liste over kalendere brukeren kan skrive til
|
||||||
|
@SerializedName("writeable_calendars")
|
||||||
|
public List<String> writeableCalendars;
|
||||||
|
|
||||||
public String message;
|
public String message;
|
||||||
}
|
}
|
||||||
|
|
@ -2,13 +2,14 @@
|
||||||
package com.kbs.kbsintranett;
|
package com.kbs.kbsintranett;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UserManager fungerer som en global sesjon for appen.
|
* UserManager fungerer som en global sesjon for appen.
|
||||||
* Den holder på informasjon om innlogget bruker, rettigheter og autentiserings-cookie.
|
* Den holder på informasjon om innlogget bruker, rettigheter og autentiserings-cookie.
|
||||||
*/
|
*/
|
||||||
public class UserManager {
|
public class UserManager {
|
||||||
|
|
||||||
private static UserManager instance;
|
private static UserManager instance;
|
||||||
|
|
||||||
// Google Data
|
// Google Data
|
||||||
|
|
@ -22,15 +23,16 @@ public class UserManager {
|
||||||
private String userRole;
|
private String userRole;
|
||||||
private String currentCookie;
|
private String currentCookie;
|
||||||
|
|
||||||
// --- NYE FELTER ---
|
// Extended Info
|
||||||
private String firstName;
|
private String firstName;
|
||||||
private String lastName;
|
private String lastName;
|
||||||
private String stilling;
|
private String stilling;
|
||||||
private String mobiltelefon;
|
private String mobiltelefon;
|
||||||
|
|
||||||
private UserManager() {
|
// NYTT:
|
||||||
// Initielt er ingen logget inn
|
private List<String> writeableCalendars = new ArrayList<>();
|
||||||
}
|
|
||||||
|
private UserManager() {}
|
||||||
|
|
||||||
public static synchronized UserManager getInstance() {
|
public static synchronized UserManager getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
|
|
@ -39,9 +41,6 @@ public class UserManager {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Kalles når Google-innlogging er vellykket.
|
|
||||||
*/
|
|
||||||
public void setUserData(String name, String email, String token, @Nullable String photoUrl) {
|
public void setUserData(String name, String email, String token, @Nullable String photoUrl) {
|
||||||
this.userDisplayName = name;
|
this.userDisplayName = name;
|
||||||
this.userEmail = email;
|
this.userEmail = email;
|
||||||
|
|
@ -49,7 +48,6 @@ public class UserManager {
|
||||||
this.photoUrl = photoUrl;
|
this.photoUrl = photoUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- NY METODE FOR UTVIDET INFO ---
|
|
||||||
public void setExtendedUserInfo(String firstName, String lastName, String stilling, String mobiltelefon) {
|
public void setExtendedUserInfo(String firstName, String lastName, String stilling, String mobiltelefon) {
|
||||||
this.firstName = firstName;
|
this.firstName = firstName;
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
|
|
@ -57,19 +55,17 @@ public class UserManager {
|
||||||
this.mobiltelefon = mobiltelefon;
|
this.mobiltelefon = mobiltelefon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCookie(String cookie) {
|
public void setWriteableCalendars(List<String> calendars) {
|
||||||
this.currentCookie = cookie;
|
this.writeableCalendars = calendars != null ? calendars : new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserRole(String role) {
|
public List<String> getWriteableCalendars() {
|
||||||
this.userRole = role;
|
return writeableCalendars;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserId(int id) {
|
public void setCookie(String cookie) { this.currentCookie = cookie; }
|
||||||
this.userId = id;
|
public void setUserRole(String role) { this.userRole = role; }
|
||||||
}
|
public void setUserId(int id) { this.userId = id; }
|
||||||
|
|
||||||
// ---------------- GETTERS ----------------
|
|
||||||
|
|
||||||
public String getUserDisplayName() { return userDisplayName != null ? userDisplayName : ""; }
|
public String getUserDisplayName() { return userDisplayName != null ? userDisplayName : ""; }
|
||||||
public String getUserEmail() { return userEmail != null ? userEmail : ""; }
|
public String getUserEmail() { return userEmail != null ? userEmail : ""; }
|
||||||
|
|
@ -78,31 +74,17 @@ public class UserManager {
|
||||||
public String getCookie() { return currentCookie; }
|
public String getCookie() { return currentCookie; }
|
||||||
public String getUserRole() { return userRole != null ? userRole : "subscriber"; }
|
public String getUserRole() { return userRole != null ? userRole : "subscriber"; }
|
||||||
public int getUserId() { return userId; }
|
public int getUserId() { return userId; }
|
||||||
|
|
||||||
// --- NYE GETTERS ---
|
|
||||||
public String getFirstName() { return firstName != null ? firstName : ""; }
|
public String getFirstName() { return firstName != null ? firstName : ""; }
|
||||||
public String getLastName() { return lastName != null ? lastName : ""; }
|
public String getLastName() { return lastName != null ? lastName : ""; }
|
||||||
public String getStilling() { return stilling != null ? stilling : ""; }
|
public String getStilling() { return stilling != null ? stilling : ""; }
|
||||||
public String getMobiltelefon() { return mobiltelefon != null ? mobiltelefon : ""; }
|
public String getMobiltelefon() { return mobiltelefon != null ? mobiltelefon : ""; }
|
||||||
|
|
||||||
// ---------------- HJELPEMETODER ----------------
|
public boolean isLoggedIn() { return userEmail != null && !userEmail.isEmpty(); }
|
||||||
|
public boolean isAdmin() { return "administrator".equalsIgnoreCase(userRole); }
|
||||||
public boolean isLoggedIn() {
|
|
||||||
return userEmail != null && !userEmail.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAdmin() {
|
|
||||||
return "administrator".equalsIgnoreCase(userRole);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEditorOrAbove() {
|
public boolean isEditorOrAbove() {
|
||||||
if (userRole == null) return false;
|
return userRole != null && (userRole.equalsIgnoreCase("administrator") || userRole.equalsIgnoreCase("editor"));
|
||||||
return userRole.equalsIgnoreCase("administrator") || userRole.equalsIgnoreCase("editor");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Nullstiller alt. Kalles ved utlogging.
|
|
||||||
*/
|
|
||||||
public void logout() {
|
public void logout() {
|
||||||
userDisplayName = null;
|
userDisplayName = null;
|
||||||
userEmail = null;
|
userEmail = null;
|
||||||
|
|
@ -111,11 +93,10 @@ public class UserManager {
|
||||||
userRole = null;
|
userRole = null;
|
||||||
currentCookie = null;
|
currentCookie = null;
|
||||||
userId = 0;
|
userId = 0;
|
||||||
|
|
||||||
// Nullstill nye felter
|
|
||||||
firstName = null;
|
firstName = null;
|
||||||
lastName = null;
|
lastName = null;
|
||||||
stilling = null;
|
stilling = null;
|
||||||
mobiltelefon = null;
|
mobiltelefon = null;
|
||||||
|
writeableCalendars.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
1650
hele_prosjektet.txt
1650
hele_prosjektet.txt
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue