Skip to content

Commit

Permalink
Iscrizione agli appelli
Browse files Browse the repository at this point in the history
  • Loading branch information
alvi-se committed Dec 15, 2023
1 parent 383f00c commit c11849d
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 24 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/org/epic_guys/esse4/API/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public class API {
private Jwt jwt;
private Persona loggedPersona;
private Carriera carrieraStudente;
public static final String BASE_URL = "https://esse3.unive.it/e3rest/api/";
// public static final String BASE_URL = "https://esse3.unive.it/e3rest/api/";
public static final String BASE_URL = "https://unive.esse3.pp.cineca.it/e3rest/api/";


private Jwt getJwt() {
return jwt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.epic_guys.esse4.models.ApiResource;
import org.epic_guys.esse4.models.Appello;
import org.epic_guys.esse4.models.AppelloLibretto;
import org.epic_guys.esse4.models.RigaLibretto;
import retrofit2.Call;
import retrofit2.http.GET;
Expand All @@ -24,23 +25,23 @@ enum Condizioni {


@GET(BASE_URL + "/libretti/{matId}/appelli")
Call<List<Appello>> getAppelli(@Path("matId") long idCarriera);
Call<List<AppelloLibretto>> getAppelli(@Path("matId") long idCarriera);

@GET(BASE_URL + "/libretti/{matId}/appelli")
Call<List<Appello>> getAppelli(
Call<List<AppelloLibretto>> getAppelli(
@Path("matId") long idCarriera,
@Query("q") Condizioni condizioni
);

@GET(BASE_URL + "/libretti/{matId}/righe/{adsceId}/appelli")
Call<List<Appello>> getAppelliPerRigaLibretto(
Call<List<AppelloLibretto>> getAppelliPerRigaLibretto(
@Path("matId") long idCarriera,
@Path("adsceId") long idRigaLibretto,
@Query("q") Condizioni condizioni
);

@GET(BASE_URL + "/libretti/{matId}/righe/{adsceId}/appelli")
Call<List<Appello>> getAppelliPerRigaLibretto(
Call<List<AppelloLibretto>> getAppelliPerRigaLibretto(
@Path("matId") long idCarriera,
@Path("adsceId") long idRigaLibretto
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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.models.AppelloLibretto;
import org.epic_guys.esse4.views.ExamCardAdapter;

import java.util.List;
Expand Down Expand Up @@ -56,7 +57,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
long idRigaLibretto = args.getIdRigaLibretto();
LibrettoService librettoService = API.getService(LibrettoService.class);

Call<List<Appello>> appelli;
Call<List<AppelloLibretto>> appelli;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,106 @@
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import org.epic_guys.esse4.API.API;
import org.epic_guys.esse4.API.services.CalendarioEsamiService;
import org.epic_guys.esse4.R;
import org.epic_guys.esse4.models.Appello;
import org.epic_guys.esse4.models.AppelloLibretto;
import org.epic_guys.esse4.models.ParametriIscrizioneAppello;

import java.util.concurrent.CompletableFuture;

import retrofit2.Call;

public class ExamSubscribeDialogFragment extends DialogFragment {

private Appello appello;
private final AppelloLibretto appello;

public ExamSubscribeDialogFragment(Appello appello) {
public ExamSubscribeDialogFragment(AppelloLibretto appello) {
super();
this.appello = appello;

this.setCancelable(false);
}

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
View view = requireActivity().getLayoutInflater().inflate(
R.layout.fragment_exam_subscribe_dialog,
null
);

Spinner examType = view.findViewById(R.id.spinner_exam_type);
EditText examNotes = view.findViewById(R.id.edit_text_notes_for_professor);
examType.setAdapter(
new ArrayAdapter<>(
requireContext(),
android.R.layout.simple_spinner_item,
Appello.TipoIscrCodEnum.values()
)
);

return new AlertDialog.Builder(requireContext())
.setTitle(appello.getDescrizioneAttivitaDidattica())
.setMessage("Sei sicuro di volerti iscrivere all'appello?")
.setPositiveButton("Iscriviti", (dialog, which) -> {
// TODO iscrizione
Toast.makeText(getContext(), "Test iscrizione", Toast.LENGTH_SHORT).show();
.setMessage(appello.getDescrizioneAppello())
.setView(view)
.setPositiveButton(R.string.subscribe, (dialog, which) -> {
Log.d(TAG, appello.getIdRigaLibretto().toString());
ParametriIscrizioneAppello parametri = new ParametriIscrizioneAppello(
appello.getIdRigaLibretto()
);
// Tipo esame DA IMPLEMENTARE
// parametri.setTipoIscrStu((Appello.TipoIscrCodEnum) examType.getSelectedItem());
// Note per docente
// if (!examNotes.getText().toString().isEmpty()) {
// parametri.setNotaStu(examNotes.getText().toString());
// }

subscribe(parametri)
.thenAccept(aVoid -> {
Log.d(TAG, "Iscrizione effettuata");
requireActivity().runOnUiThread(() -> {
Toast.makeText(getContext(), "Iscrizione effettuata", Toast.LENGTH_SHORT).show();
});
})
.exceptionally(throwable -> {
Log.w(TAG, Log.getStackTraceString(throwable));
requireActivity().runOnUiThread(() -> {
Toast.makeText(getContext(), "Errore durante l'iscrizione", Toast.LENGTH_SHORT).show();
});
return null;
});
})
.setNegativeButton("Annulla", (dialog, which) -> {})
.setNegativeButton(R.string.cancel, (dialog, which) -> {})
.create();
}


public CompletableFuture<Void> subscribe(ParametriIscrizioneAppello parametriIscrizioneAppello) {
CalendarioEsamiService service = API.getService(CalendarioEsamiService.class);
Call<Void> call = service.postIscrizioneAppello(
appello.getCdsId(),
appello.getAdId(),
appello.getAppelloId(),
parametriIscrizioneAppello
);

Log.d(TAG, "Iscrizione appello: " + appello.getCodiceAttivitaDidattica());
return API.enqueueResource(call);
}


public static String TAG = "ExamSubscribeDialogFragment";
}
65 changes: 65 additions & 0 deletions app/src/main/java/org/epic_guys/esse4/models/AppelloLibretto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.epic_guys.esse4.models;

import com.google.gson.annotations.SerializedName;

/**
* AppelloLibretto
*/
public class AppelloLibretto extends Appello {
@SerializedName("matId")
private Long matId = null;

@SerializedName("adsceId")
private Long adsceId = null;

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

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

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

/**
* Id della testata del libretto
* @return matId
**/
public Long getIdCarriera() {
return matId;
}

/**
* Id della riga del libretto
* @return adsceId
**/
public Long getIdRigaLibretto() {
return adsceId;
}

/**
* codice dell&#39;attività didattica del libretto
* @return adStuCod
**/
public String getAdStuCod() {
return adStuCod;
}

/**
* descrizione dell&#39;attività didattica del libretto
* @return adStuDes
**/
public String getAdStuDes() {
return adStuDes;
}

/**
* Stato dell\\&#39;attività didattica (codice)
* @return staSceCod
**/
public String getStaSceCod() {
return staSceCod;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ParametriIscrizioneAppello {
private long adsceId;

@SerializedName("tipoIscrStu")
private String tipoIscrStu = null;
private Appello.TipoIscrCodEnum tipoIscrStu = null;

@SerializedName("notaStu")
private String notaStu = null;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void setAdsceId(Long adsceId) {
this.adsceId = adsceId;
}

public ParametriIscrizioneAppello tipoIscrStu(String tipoIscrStu) {
public ParametriIscrizioneAppello tipoIscrStu(Appello.TipoIscrCodEnum tipoIscrStu) {
this.tipoIscrStu = tipoIscrStu;
return this;
}
Expand All @@ -60,11 +60,11 @@ public ParametriIscrizioneAppello tipoIscrStu(String tipoIscrStu) {
* tipo di iscrizione dello studente
* @return tipoIscrStu
**/
public String getTipoIscrStu() {
public Appello.TipoIscrCodEnum getTipoIscrStu() {
return tipoIscrStu;
}

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

Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/org/epic_guys/esse4/views/ExamCardAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
import org.epic_guys.esse4.R;
import org.epic_guys.esse4.fragments.ExamSubscribeDialogFragment;
import org.epic_guys.esse4.models.Appello;
import org.epic_guys.esse4.models.AppelloLibretto;

import java.util.List;

public class ExamCardAdapter extends RecyclerView.Adapter<ExamCardAdapter.MyViewHolder> {

@NonNull
private List<Appello> appelli;
private List<AppelloLibretto> appelli;

public ExamCardAdapter(@NonNull List<Appello> appelli) {
public ExamCardAdapter(@NonNull List<AppelloLibretto> appelli) {
this.appelli = appelli;
}

Expand All @@ -36,7 +37,7 @@ public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)

@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
Appello appello = appelli.get(position);
AppelloLibretto appello = appelli.get(position);
holder.setContentView(appello);
}

Expand Down Expand Up @@ -66,7 +67,7 @@ public MyViewHolder(@NonNull View itemView) {
subscribe_button = itemView.findViewById(R.id.btn_subscribe);
}

public void setContentView(Appello appello) {
public void setContentView(AppelloLibretto appello) {
exam_name.setText(appello.getDescrizioneAttivitaDidattica());
try{
date_data.setText(appello.getDataOraEsame().format(Appello.getDateTimeFormatter()));
Expand All @@ -75,7 +76,8 @@ public void setContentView(Appello appello) {
Log.e("ExamCardAdapter", "setContentView: ", e);
}

type_data.setText(appello.getTipoEsame().getDescription());
// FIXME - appello.getTipoEsame() può essere null
// type_data.setText(appello.getTipoEsame().getDescription());

host_data.setText(appello.getPresidenteNomeCognome());
sub_period_data.setText(appello.getDataInizioIscr() + " - " + appello.getDataFineIscr());
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/exam_card_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
android:id="@+id/btn_subscribe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/exam_subscribe" />
android:text="@string/subscribe" />

</LinearLayout>

Expand Down
46 changes: 46 additions & 0 deletions app/src/main/res/layout/fragment_exam_subscribe_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/edit_text_notes_for_professor"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ems="10"
android:gravity="start|top"
android:inputType="textMultiLine"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6" />

<Spinner
android:id="@+id/spinner_exam_type"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/exam_type_label"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/exam_notes_for_professor_label"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner_exam_type" />
</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings_it.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
<string name="sub_label">Iscritto</string>
<string name="sub_period_label">Iscrizione:</string>
<string name="study_plan_label">Piano di Studi</string>
<string name="exam_subscribe">Iscriviti</string>
<string name="subscribe">Iscriviti</string>
<string name="cancel">Annulla</string>
<string name="room_label">Aula:</string>
<string name="type_label">Tipo:</string>
<string name="exam_type_label">Tipo esame</string>
<string name="exam_notes_for_professor_label">Note per il docente</string>
</resources>

0 comments on commit c11849d

Please sign in to comment.