Skip to content

Commit

Permalink
Chronomètre
Browse files Browse the repository at this point in the history
v1.6.1 prete
  • Loading branch information
nico2che committed Sep 28, 2016
1 parent 77c829d commit c394f48
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 19 deletions.
40 changes: 31 additions & 9 deletions app/src/main/java/com/aerophile/app/VolDetailFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
Expand All @@ -15,6 +16,7 @@
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
Expand All @@ -27,12 +29,19 @@
import com.aerophile.app.modeles.Vol;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.NonConfigurationInstance;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.api.BackgroundExecutor;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;

/**
Expand Down Expand Up @@ -64,6 +73,7 @@ public class VolDetailFragment extends Fragment implements TimePickerDialog.OnTi
private String bouton;
private Handler horlogeDecollage;
private Handler horlogeAtterrissage;
private Handler timeDecollage;

RafraichirListener rListener;

Expand Down Expand Up @@ -95,6 +105,9 @@ public void setRafraichirListe(RafraichirListener listener) {
@ViewById
Button buttonHeureAtterrissage;

@ViewById
Chronometer chronometre;

@ViewById
AutoCompleteTextView inputPilote;

Expand Down Expand Up @@ -139,7 +152,8 @@ public void onDestroyView(){
public void initialisation() {
Log.d("AEROBUG", "Fragment initialisation: " + idVol);
horlogeAtterrissage = new Handler();
horlogeDecollage = new Handler();
horlogeDecollage = new Handler();
timeDecollage = new Handler();
JourneeDAO journeeCourante = new JourneeDAO(getContext());
journeeCourante.open();
Journee journee = journeeCourante.getJourneeEnCours();
Expand Down Expand Up @@ -188,6 +202,7 @@ public void initialisation() {

// On cache les informations d'atterrissage
buttonAtterrissage.setVisibility(View.INVISIBLE);
toggleChronometre(false);
textHeureAtterrissage.setVisibility(View.INVISIBLE);
buttonHeureAtterrissage.setVisibility(View.INVISIBLE);
buttonSupprimerVol.setVisibility(View.INVISIBLE);
Expand Down Expand Up @@ -250,11 +265,8 @@ public void onNothingSelected(AdapterView<?> parent) {
buttonSupprimerVol.setVisibility(View.VISIBLE);

// En cours ? Sinon on désactive l'atterrissage
if(vol.getEnCours() == 0) {
buttonAtterrissage.setEnabled(false);
} else {
buttonAtterrissage.setEnabled(true);
}
buttonAtterrissage.setEnabled(vol.getEnCours() != 0);
toggleChronometre(vol.getEnCours() != 0);

// On initialise l'heure de décollage
String horaireDecollage = vol.getDateDecollage();
Expand Down Expand Up @@ -430,15 +442,25 @@ void buttonDecollage() {
vol.setNombrePassagers(inputPassagers.getText().toString().equals("") ? 0 : Integer.parseInt(inputPassagers.getText().toString()));
vol.setVitesseVent(inputVent.getText().toString());
vol.setCommentaires(inputCommentaires.getText().toString());
vol.setTimeDecollage(String.valueOf(SystemClock.elapsedRealtime()));
// On enregistre le vol
idVol = rListener.onNouveauVolListe(vol);
// On relance avec le vol
initialisation();
}
}

void toggleChronometre() {

void toggleChronometre(boolean actif) {
if(actif) {
chronometre.setVisibility(View.VISIBLE);
if(vol.getTimeDecollage() != null) {
chronometre.setBase(Long.valueOf(vol.getTimeDecollage()));
chronometre.start();
}
} else {
chronometre.setVisibility(View.INVISIBLE);
chronometre.stop();
}
}

@Click
Expand All @@ -460,7 +482,7 @@ void buttonAtterrissage() {
rListener.onRafraichirListe(0);
idVol = 0;
getActivity().getSupportFragmentManager().popBackStack();
// initialisation();
initialisation();
} else {
Toast.makeText(getContext(), getString(R.string.vol_champs_erreur), Toast.LENGTH_SHORT).show();
}
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/com/aerophile/app/VolListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,6 @@ public void onItemSelected(long id) {
Bundle arguments = new Bundle();
arguments.putLong(VolDetailFragment.ARG_ITEM_ID, id);

if(saving) {
arguments.putBoolean(VolDetailFragment.ARG_CHANGEMENT, changeHeure);
arguments.putInt(VolDetailFragment.ARG_DECOLLAGE_HEURE, heureDecollage);
arguments.putInt(VolDetailFragment.ARG_DECOLLAGE_MINUTE, minuteDecollage);
arguments.putString(VolDetailFragment.ARG_PILOTE, pilote);
arguments.putInt(VolDetailFragment.ARG_PASSAGERS, nombrePassagers);
arguments.putString(VolDetailFragment.ARG_VENT, vent);
arguments.putString(VolDetailFragment.ARG_COMMENTAIRE, commentaire);
}
saving = false;

fragment = new VolDetailFragment_();
fragment.setArguments(arguments);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout-land/fragment_vol_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ tools:context="com.aerophile.app.VolListActivity"
android:layout_column="2"
/>

<Chronometer
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chronometre"
android:format="@string/vol_chronometre"
android:layout_row="7"
android:layout_column="2"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout-v23/fragment_vol_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ tools:context="com.aerophile.app.VolListActivity"
android:layout_column="2"
/>

<Chronometer
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chronometre"
android:format="@string/vol_chronometre"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:layout_row="7"
android:layout_column="2" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -200,6 +209,7 @@ tools:context="com.aerophile.app.VolListActivity"
android:layout_column="2"
android:layout_marginRight="10dp"/>


</GridLayout>

</LinearLayout>
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/fragment_vol_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ tools:context="com.aerophile.app.VolListActivity"
android:layout_column="2"
/>

<Chronometer
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chronometre"
android:format="@string/vol_chronometre"
android:layout_row="10"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:layout_column="2" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,7 @@
<string name="vol_supprimer_confirmation">Do you really want to delete this flight? This action can not be undone</string>
<string name="vol_vent_erreur">The wind speed must be entered before changing flight</string>
<string name="vol_vols_erreur">All flights must land before ending the day</string>
<string name="vol_chronometre">Flight duration: %s</string>
<string name="envoie_mail_date_envoie_ko">Unsent report</string>
<string name="envoie_mail_date_envoie_ok">Report already sent : %s</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-sw600dp-port/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<string name="vol_immatriculation_ballon">Ballon : %s</string>
<string name="vol_stats">%1$d vols (%3$s) - %2$d passagers</string>
<string name="vol_chronometre">Durée: %s</string>

<string name="apercu_passagers">Passagers</string>
<string name="apercu_vent">Vent</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ Cette action ne peut être annulée</string>
<string name="vol_pilote_erreur">Le pilote doit être renseigné avant de changer de vol</string>
<string name="vol_passagers_erreur">Le nombre de passager doit être renseigné avant de changer de vol</string>
<string name="vol_vent_erreur">La vitesse du vent doit être renseignée avant de changer de vol</string>
<string name="vol_chronometre">Durée du vol: %s</string>


<!-- ApercuActivity -->
<string name="apercu_titre">Aperçu de la journée du %s</string>
Expand Down

0 comments on commit c394f48

Please sign in to comment.