Skip to content

Commit

Permalink
Implemented general loading method + committed ParametriIscrizioneApp…
Browse files Browse the repository at this point in the history
…ello
  • Loading branch information
WAPEETY committed Dec 15, 2023
1 parent 81a6a08 commit 383f00c
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 98 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions app/src/main/java/org/epic_guys/esse4/common/Common.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.epic_guys.esse4.common;

import android.view.View;
import android.widget.LinearLayout;

import org.epic_guys.esse4.R;
import org.epic_guys.esse4.models.Esito;
import org.epic_guys.esse4.models.RigaLibretto;
import org.jetbrains.annotations.NotNull;

public class Common {
// SOME EXAMS HAVE AN EMPTY GRADE (literally ""), LIKE "Tirocinio" and "B2 Inglese"... What should we do?
Expand All @@ -18,4 +23,14 @@ public static String stringifyGrade(RigaLibretto riga){
return riga.getEsito().getTipoGiudCod();
}
}

static public void startLoading(@NotNull View toHide,@NotNull View generalView, int loadingId){
toHide.setVisibility(View.INVISIBLE);
generalView.findViewById(loadingId).setVisibility(View.VISIBLE);
}

static public void stopLoading(@NotNull View toShow,View generalView, int loadingId){
toShow.setVisibility(View.VISIBLE);
generalView.findViewById(loadingId).setVisibility(View.INVISIBLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.epic_guys.esse4.API.API;
import org.epic_guys.esse4.API.services.LibrettoService;
import org.epic_guys.esse4.R;
import org.epic_guys.esse4.common.Common;
import org.epic_guys.esse4.models.Appello;
import org.epic_guys.esse4.views.ExamCardAdapter;

Expand Down Expand Up @@ -57,6 +58,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

Call<List<Appello>> appelli;

Common.startLoading(requireView().findViewById(R.id.recycler_view_appelli), requireView(), R.id.loading);

if (idRigaLibretto == -1) {
appelli = librettoService.getAppelli(
idCarriera,
Expand All @@ -74,7 +77,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
.thenAccept(appelliList -> {
Log.d("AppelliFragment", "Ricevuti appelli: " + appelliList.size());
appelliRecyclerView.setAdapter(new ExamCardAdapter(appelliList));

Common.stopLoading(requireView().findViewById(R.id.recycler_view_appelli), requireView(), R.id.loading);
})
.exceptionally(throwable -> {
Log.w("AppelliFragment", throwable.getMessage());
Expand Down
24 changes: 3 additions & 21 deletions app/src/main/java/org/epic_guys/esse4/fragments/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import de.adorsys.android.securestoragelibrary.SecurePreferences;
import org.epic_guys.esse4.API.API;
import org.epic_guys.esse4.R;
import org.epic_guys.esse4.common.Common;
import org.epic_guys.esse4.models.Carriera;
import org.epic_guys.esse4.models.Persona;
import java.util.concurrent.CompletableFuture;
Expand All @@ -35,26 +36,7 @@ private void launchLoginFragment() {
navController.navigate(R.id.loginFragment, null, navOptions);
}

private void hideFragment(){
LinearLayout l = requireView().findViewById(R.id.window);
l.setVisibility(View.INVISIBLE);
}

private void showFragment(){
LinearLayout l = requireView().findViewById(R.id.window);
l.setVisibility(View.VISIBLE);
}

private void startLoading(){
hideFragment();
requireView().findViewById(R.id.loading).setVisibility(View.VISIBLE);
}

private void stopLoading(){
showFragment();
requireView().findViewById(R.id.loading).setVisibility(View.INVISIBLE);
}


private void setProfilePicture() {
ImageView profilePicture = requireView().findViewById(R.id.profile_picture);
Expand Down Expand Up @@ -157,12 +139,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
startLoading();
Common.startLoading(requireView().findViewById(R.id.window), requireView(), R.id.loading);

basicDataFuture.thenAccept(personaCarrieraPair -> requireActivity().runOnUiThread(() -> {
Toast.makeText(getContext(), "Bentornat[ao] studente(?:ssa|)" /* + API.getLoggedPersona().getNome() */, Toast.LENGTH_SHORT).show();
setBasicInfo(personaCarrieraPair.first, personaCarrieraPair.second);
stopLoading();
Common.stopLoading(requireView().findViewById(R.id.window), requireView(), R.id.loading);
})).exceptionally(e -> {
Log.e("HomeFragment", e.toString());
requireActivity().runOnUiThread(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
super.onViewCreated(view, savedInstanceState);

List<SubjectCardView> exams = new ArrayList<>();
Common.startLoading(requireView().findViewById(R.id.exams),requireView(),R.id.loading);

long idCarriera = API.getCarriera().getIdCarriera();
LibrettoService librettoService = API.getService(LibrettoService.class);
Call<List<RigaLibretto>> righeLibretto = librettoService.righeLibretto(idCarriera);
API.enqueueResource(righeLibretto)
.thenAccept(righe -> {

for (RigaLibretto riga : righe) {
try {
View.OnClickListener onClickListener = v -> {
Expand All @@ -78,6 +80,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
SubjectCardAdapter adapter = new SubjectCardAdapter(getContext(), exams);
recyclerView.setAdapter(adapter);
Common.stopLoading(requireView().findViewById(R.id.exams),requireView(),R.id.loading);
});

//when back button is pressed, go back to home fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import org.epic_guys.esse4.API.API;
import org.epic_guys.esse4.API.services.PianiService;
import org.epic_guys.esse4.R;
import org.epic_guys.esse4.common.Common;
import org.epic_guys.esse4.models.ADPianoDiStudio;
import org.epic_guys.esse4.models.PianoDiStudio;
import org.epic_guys.esse4.models.RigaLibretto;
import org.epic_guys.esse4.models.TestataPianoDiStudio;
import org.epic_guys.esse4.views.SubjectCardAdapter;
import org.epic_guys.esse4.views.SubjectCardView;
Expand Down Expand Up @@ -58,14 +58,15 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

long idStudente = API.getCarriera().getIdStudente();

Common.startLoading(requireView().findViewById(R.id.exams),requireView(),R.id.loading);

PianiService pianiService = API.getService(PianiService.class);
Call<List<TestataPianoDiStudio>> testataPianoDiStudio = pianiService.testataPianoDiStudio(idStudente);
API.enqueueResource(testataPianoDiStudio).thenCompose(testate -> {
TestataPianoDiStudio testata = testate.get(0);
Call<PianoDiStudio> righePianoDiStudio = pianiService.righePianoDiStudio(idStudente, testata.getPianoId());
return API.enqueueResource(righePianoDiStudio);
}).thenAccept(righe -> {

for (ADPianoDiStudio riga : righe.getAttivita()) {
try {
Integer scePianoId = riga.getScePianoId();
Expand All @@ -80,6 +81,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
SubjectCardAdapter adapter = new SubjectCardAdapter(getContext(), exams);
recyclerView.setAdapter(adapter);
Common.stopLoading(requireView().findViewById(R.id.exams),requireView(),R.id.loading);
}).exceptionally(throwable -> {
throwable.printStackTrace();
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package org.epic_guys.esse4.models;

import com.google.gson.annotations.SerializedName;

/**
* ParametriIscrizioneAppello
*/
public class ParametriIscrizioneAppello {
@SerializedName("adsceId")
private long adsceId;

@SerializedName("tipoIscrStu")
private String tipoIscrStu = null;

@SerializedName("notaStu")
private String notaStu = null;

@SerializedName("appLogId")
private Integer appLogId = null;

@SerializedName("tagCod")
private String tagCod = null;

@SerializedName("attoreCod")
private String attoreCod = null;

@SerializedName("tipoSvolgimentoEsame")
private String tipoSvolgimentoEsame = null;

public ParametriIscrizioneAppello(long idRigaLibretto) {
this.adsceId = idRigaLibretto;
}


public ParametriIscrizioneAppello adsceId(Long adsceId) {
this.adsceId = adsceId;
return this;
}

/**
* id della riga di libretto da prenotare
* minimum: 1
* @return adsceId
**/

public long getAdsceId() {
return adsceId;
}

public void setAdsceId(Long adsceId) {
this.adsceId = adsceId;
}

public ParametriIscrizioneAppello tipoIscrStu(String tipoIscrStu) {
this.tipoIscrStu = tipoIscrStu;
return this;
}

/**
* tipo di iscrizione dello studente
* @return tipoIscrStu
**/
public String getTipoIscrStu() {
return tipoIscrStu;
}

public void setTipoIscrStu(String tipoIscrStu) {
this.tipoIscrStu = tipoIscrStu;
}

public ParametriIscrizioneAppello notaStu(String notaStu) {
this.notaStu = notaStu;
return this;
}

/**
* nota dello studente inserita in fase di prenotazione
* @return notaStu
**/
public String getNotaStu() {
return notaStu;
}

public void setNotaStu(String notaStu) {
this.notaStu = notaStu;
}

public ParametriIscrizioneAppello appLogId(Integer appLogId) {
this.appLogId = appLogId;
return this;
}

/**
* eventuale turno a cui prenotare lo studente, se vuoto viene assegnato dal sistema
* minimum: 1
* @return appLogId
**/
public Integer getAppLogId() {
return appLogId;
}

public void setAppLogId(Integer appLogId) {
this.appLogId = appLogId;
}

public ParametriIscrizioneAppello tagCod(String tagCod) {
this.tagCod = tagCod;
return this;
}

/**
* tag selezionato dallo studente in fase di prenotazione
* @return tagCod
**/

public String getTagCod() {
return tagCod;
}

public void setTagCod(String tagCod) {
this.tagCod = tagCod;
}

public ParametriIscrizioneAppello attoreCod(String attoreCod) {
this.attoreCod = attoreCod;
return this;
}

/**
* eventuale tipo di attore con cui si vuole effettuare la preotazione, valido solo se l&#39;utente che effettua la chiamata è un utente tecnico
* @return attoreCod
**/

public String getAttoreCod() {
return attoreCod;
}

public void setAttoreCod(String attoreCod) {
this.attoreCod = attoreCod;
}

public ParametriIscrizioneAppello tipoSvolgimentoEsame(String tipoSvolgimentoEsame) {
this.tipoSvolgimentoEsame = tipoSvolgimentoEsame;
return this;
}

/**
* tipo di svolgimento esame, se null viene imposato il default previsto nella tipi_gest_app, altrimenti viene inserito il valore richiesto. Lo studente può selezionare solo il default oppure un valore con richiesta_flg &#x3D; 1
* @return tipoSvolgimentoEsame
**/

public String getTipoSvolgimentoEsame() {
return tipoSvolgimentoEsame;
}

public void setTipoSvolgimentoEsame(String tipoSvolgimentoEsame) {
this.tipoSvolgimentoEsame = tipoSvolgimentoEsame;
}
}

28 changes: 17 additions & 11 deletions app/src/main/java/org/epic_guys/esse4/views/ExamCardAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static class MyViewHolder extends RecyclerView.ViewHolder {
private TextView exam_name;
private TextView date_data;
private TextView host_data;
private TextView cfu_data;
private TextView type_data;
private TextView sub_period_data;
private Button subscribe_button;

Expand All @@ -61,25 +61,31 @@ public MyViewHolder(@NonNull View itemView) {
exam_name = itemView.findViewById(R.id.exam_name);
date_data = itemView.findViewById(R.id.date_data);
host_data = itemView.findViewById(R.id.host_data);
cfu_data = itemView.findViewById(R.id.cfu_data);
type_data = itemView.findViewById(R.id.type_data);
sub_period_data = itemView.findViewById(R.id.sub_period_data);
subscribe_button = itemView.findViewById(R.id.btn_subscribe);
}

public void setContentView(Appello appello) {
exam_name.setText(appello.getDescrizioneAppello());
date_data.setText(appello.getDataOraEsame().format(Appello.getDateTimeFormatter()));
exam_name.setText(appello.getDescrizioneAttivitaDidattica());
try{
date_data.setText(appello.getDataOraEsame().format(Appello.getDateTimeFormatter()));
}
catch (Exception e){
Log.e("ExamCardAdapter", "setContentView: ", e);
}

type_data.setText(appello.getTipoEsame().getDescription());

host_data.setText(appello.getPresidenteNomeCognome());
sub_period_data.setText(appello.getDataInizioIscr() + " - " + appello.getDataFineIscr());


subscribe_button.setOnClickListener(v -> {
new ExamSubscribeDialogFragment(appello).show(
// findFragment restituisce AppelliFragment, creiamo il dialog in questo fragment
FragmentManager.findFragment(itemView).getChildFragmentManager(),
ExamSubscribeDialogFragment.TAG
);
});
subscribe_button.setOnClickListener(v -> new ExamSubscribeDialogFragment(appello).show(
// findFragment restituisce AppelliFragment, creiamo il dialog in questo fragment
FragmentManager.findFragment(itemView).getChildFragmentManager(),
ExamSubscribeDialogFragment.TAG
));
}
}
}
Loading

0 comments on commit 383f00c

Please sign in to comment.