From 67e02f3ae9bc1d6732b887577ded58ee98d0e4e7 Mon Sep 17 00:00:00 2001 From: Maxime Favier Date: Mon, 22 Jun 2020 23:01:15 +0200 Subject: [PATCH] - cours integration --- app/build.gradle | 4 +- .../favier/exam1radioamateur/DbPopulator.java | 29 +++++++ .../exam1radioamateur/MainActivity.java | 83 ++++++++++++++++++- .../exam1radioamateur/QuestionsDownload.java | 15 +++- .../res/drawable/ic_ondemand_video_24dp.xml | 9 ++ app/src/main/res/drawable/ic_school_24dp.xml | 9 ++ .../main/res/layout-small/activity_main.xml | 8 ++ app/src/main/res/layout/activity_main.xml | 19 +++-- app/src/main/res/menu/main_activity_menu.xml | 5 +- app/src/main/res/values/strings.xml | 7 +- 10 files changed, 175 insertions(+), 13 deletions(-) create mode 100644 app/src/main/res/drawable/ic_ondemand_video_24dp.xml create mode 100644 app/src/main/res/drawable/ic_school_24dp.xml diff --git a/app/build.gradle b/app/build.gradle index a5fb4ae..dedc8fa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "dev.favier.exam1radioamateur" minSdkVersion 22 targetSdkVersion 29 - versionCode 5 - versionName 'v0.5-beta' + versionCode 6 + versionName 'v0.6-beta' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/dev/favier/exam1radioamateur/DbPopulator.java b/app/src/main/java/dev/favier/exam1radioamateur/DbPopulator.java index 0f947fa..b309314 100644 --- a/app/src/main/java/dev/favier/exam1radioamateur/DbPopulator.java +++ b/app/src/main/java/dev/favier/exam1radioamateur/DbPopulator.java @@ -151,6 +151,35 @@ public boolean downloadJson() { return true; } + // en attente du https sur le site de f6kgl + /*public boolean downloadCoursHtml(){ + try { + Log.w("debug", "start download cours"); + URL url = new URL("http://f6kgl.free.fr/COURS.html"); + URLConnection connection = url.openConnection(); + connection.connect(); + + try (InputStream input = new BufferedInputStream(url.openStream(), 8192)) { + File file = new File(context.getFilesDir(), "COURS.html"); + try (OutputStream output = new FileOutputStream(file)) { + byte[] buffer = new byte[8192]; // or other buffer size + int read; + + while ((read = input.read(buffer)) != -1) { + output.write(buffer, 0, read); + } + output.flush(); + } + } + Log.w("debug", "downloaded cours"); + + } catch (IOException e) { + e.printStackTrace(); + return false; + } + return true; + }*/ + public boolean unzipImg() { Log.w("debug", "unzip start"); try { diff --git a/app/src/main/java/dev/favier/exam1radioamateur/MainActivity.java b/app/src/main/java/dev/favier/exam1radioamateur/MainActivity.java index 749b5d9..79c3842 100644 --- a/app/src/main/java/dev/favier/exam1radioamateur/MainActivity.java +++ b/app/src/main/java/dev/favier/exam1radioamateur/MainActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.net.Uri; import android.os.AsyncTask; import android.text.InputFilter; import android.util.Log; @@ -20,10 +21,12 @@ import com.google.gson.reflect.TypeToken; import org.json.JSONException; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; + public class MainActivity extends AppCompatActivity { TableRow legislationRow, techniqueRow; @@ -33,6 +36,7 @@ public class MainActivity extends AppCompatActivity { sanctionsCheckBox, messagesCheckBox, indicatifsCheckBox, entrainementCheckBox; CheckBox lignesCheckBox, etagesRFCheckBox, resistancesGroupesCheckBox, ampliCheckBox, transfoCheckBox, alternatifCheckBox, synoptiquesCheckBox, resistancesCouleursCheckBox, electriciteCheckBox, condoBobCheckBox; + CheckBox techniqueCheckBox, legislationCheckBox; EditText tempsEditText; Spinner nbrQSpinner; Switch showRespSwitch, malusSwitch, timerSwitch; @@ -103,6 +107,8 @@ private void setupControls() { resistancesCouleursCheckBox = findViewById(R.id.resistancesCouleursCheckBox); electriciteCheckBox = findViewById(R.id.electriciteCheckBox); condoBobCheckBox = findViewById(R.id.condoBobCheckBox); + techniqueCheckBox = findViewById(R.id.techniqueCheckBox); + legislationCheckBox = findViewById(R.id.legislationCheckBox); Log.w("debug", "setup controls"); // set minimum countdown @@ -193,6 +199,7 @@ private void setupControls() { } updateNbrofQSpinner(); + // shared preference writer final SharedPreferences.Editor sharedEditor = sharedPref.edit(); @@ -294,6 +301,43 @@ public void onClick(View v) { } }); + + // select all tech/legisl + legislationCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + codeQCheckBox.setChecked(isChecked); + emissionCheckBox.setChecked(isChecked); + adaptationCheckBox.setChecked(isChecked); + epellationCheckBox.setChecked(isChecked); + cemCheckBox.setChecked(isChecked); + antennesCheckBox.setChecked(isChecked); + sanctionsCheckBox.setChecked(isChecked); + messagesCheckBox.setChecked(isChecked); + indicatifsCheckBox.setChecked(isChecked); + entrainementCheckBox.setChecked(isChecked); + tempsEditText.setText("15"); + updateNbrofQSpinner(); + } + }); + techniqueCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + lignesCheckBox.setChecked(isChecked); + etagesRFCheckBox.setChecked(isChecked); + resistancesGroupesCheckBox.setChecked(isChecked); + ampliCheckBox.setChecked(isChecked); + transfoCheckBox.setChecked(isChecked); + alternatifCheckBox.setChecked(isChecked); + synoptiquesCheckBox.setChecked(isChecked); + resistancesCouleursCheckBox.setChecked(isChecked); + electriciteCheckBox.setChecked(isChecked); + condoBobCheckBox.setChecked(isChecked); + tempsEditText.setText("30"); + updateNbrofQSpinner(); + } + }); + // start exam button startButton.setOnClickListener(new View.OnClickListener() { @Override @@ -461,6 +505,10 @@ public void updateNbrofQSpinner(View view) { if (condoBobCheckBox.isChecked()) { themeRegistered++; } + legislationCheckBox.setChecked(codeQCheckBox.isChecked() && emissionCheckBox.isChecked() && adaptationCheckBox.isChecked() && epellationCheckBox.isChecked() && cemCheckBox.isChecked() + && antennesCheckBox.isChecked() && sanctionsCheckBox.isChecked() && messagesCheckBox.isChecked() && indicatifsCheckBox.isChecked() && entrainementCheckBox.isChecked()); + techniqueCheckBox.setChecked(lignesCheckBox.isChecked() && etagesRFCheckBox.isChecked() && resistancesGroupesCheckBox.isChecked() && ampliCheckBox.isChecked() && transfoCheckBox.isChecked() + && alternatifCheckBox.isChecked() && synoptiquesCheckBox.isChecked() && resistancesCouleursCheckBox.isChecked() && electriciteCheckBox.isChecked() && condoBobCheckBox.isChecked()); //Log.w("debug", String.valueOf(themeRegistered) + " themes sont cochés"); if (themeRegistered == 3) { @@ -470,13 +518,21 @@ public void updateNbrofQSpinner(View view) { themeRegistered = 4; } List spinnerArray = new ArrayList<>(); + int nearTwentyPos = 1; + int delta = 100; for (int i = 1; i < 6; i++) { spinnerArray.add(String.valueOf(i * themeRegistered)); + if (delta > Math.abs(20 - (i * themeRegistered))) { + nearTwentyPos = i - 1; + delta = Math.abs(20 - (i * themeRegistered)); + //Log.w("debug", String.valueOf(nearTwentyPos) + "set position"); + } } ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, spinnerArray); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); nbrQSpinner.setAdapter(adapter); - + //Log.w("DEBUG", String.valueOf(nearTwentyPos) + "position set"); + nbrQSpinner.setSelection(nearTwentyPos); } public void updateNbrofQSpinner() { @@ -542,6 +598,10 @@ public void updateNbrofQSpinner() { if (condoBobCheckBox.isChecked()) { themeRegistered++; } + legislationCheckBox.setChecked(codeQCheckBox.isChecked() && emissionCheckBox.isChecked() && adaptationCheckBox.isChecked() && epellationCheckBox.isChecked() && cemCheckBox.isChecked() + && antennesCheckBox.isChecked() && sanctionsCheckBox.isChecked() && messagesCheckBox.isChecked() && indicatifsCheckBox.isChecked() && entrainementCheckBox.isChecked()); + techniqueCheckBox.setChecked(lignesCheckBox.isChecked() && etagesRFCheckBox.isChecked() && resistancesGroupesCheckBox.isChecked() && ampliCheckBox.isChecked() && transfoCheckBox.isChecked() + && alternatifCheckBox.isChecked() && synoptiquesCheckBox.isChecked() && resistancesCouleursCheckBox.isChecked() && electriciteCheckBox.isChecked() && condoBobCheckBox.isChecked()); //Log.w("debug", String.valueOf(themeRegistered) + " themes sont cochés"); if (themeRegistered == 3) { @@ -551,13 +611,23 @@ public void updateNbrofQSpinner() { themeRegistered = 4; } List spinnerArray = new ArrayList<>(); + int nearTwentyPos = 1; + int delta = 100; for (int i = 1; i < 6; i++) { spinnerArray.add(String.valueOf(i * themeRegistered)); + if (delta > Math.abs(20 - (i * themeRegistered))) { + nearTwentyPos = i - 1; + delta = Math.abs(20 - (i * themeRegistered)); + //Log.w("debug", String.valueOf(nearTwentyPos) + "set position"); + } } + ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, spinnerArray); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); nbrQSpinner.setAdapter(adapter); + //Log.w("DEBUG", String.valueOf(nearTwentyPos) + "position set"); + nbrQSpinner.setSelection(nearTwentyPos); } @Override @@ -582,6 +652,17 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { Intent intent2 = new Intent(getBaseContext(), QuestionsDownload.class); startActivity(intent2); return true; + case R.id.gotoCoursItem: + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://f6kgl-f5kff.fr/formationf6gpx")); + startActivity(browserIntent); + /*File file = new File(getBaseContext().getFilesDir(), "COURS.html"); + Intent intent4 = new Intent(ACTION_VIEW); + intent4.setDataAndType(Uri.fromFile(file), "text/html");*/ + return true; + case R.id.gotoVideoItem: + Intent coursIntent3 = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/user/F6KGL")); + startActivity(coursIntent3); + return true; } return super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/dev/favier/exam1radioamateur/QuestionsDownload.java b/app/src/main/java/dev/favier/exam1radioamateur/QuestionsDownload.java index 541d34a..68ffd20 100644 --- a/app/src/main/java/dev/favier/exam1radioamateur/QuestionsDownload.java +++ b/app/src/main/java/dev/favier/exam1radioamateur/QuestionsDownload.java @@ -38,7 +38,7 @@ private void downloaderTasker() throws IOException, JSONException { AsyncTask.execute(new Runnable() { @Override public void run() { - final boolean a, b, c; + final boolean a, b, c, d; runOnUiThread(new Runnable() { @Override public void run() { @@ -78,8 +78,16 @@ public void run() { downloadStateTextView.setText(R.string.ajust); } }); + // en attente du https sur le site de f6kgl + /*runOnUiThread(new Runnable() { + @Override + public void run() { + downloadStateTextView.setText(R.string.downloadCours); + } + }); + d = dbPopulator.downloadCoursHtml();*/ - if (a && b && c) { + if (a && b && c /*&& d*/) { dbPopulator.setFirstRunFlag(); runOnUiThread(new Runnable() { @Override @@ -91,7 +99,8 @@ public void run() { runOnUiThread(new Runnable() { @Override public void run() { - downloadStateTextView.setText(getResources().getString(R.string.errorCode, a, b, c)); + // en attente du https sur le site de f6kgl + downloadStateTextView.setText(getResources().getString(R.string.errorCode, a, b, c/*, d*/)); allowBackQuit = true; if (!a && !b) { errrorInfotextView.setText(R.string.pbConnect); diff --git a/app/src/main/res/drawable/ic_ondemand_video_24dp.xml b/app/src/main/res/drawable/ic_ondemand_video_24dp.xml new file mode 100644 index 0000000..83609af --- /dev/null +++ b/app/src/main/res/drawable/ic_ondemand_video_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_school_24dp.xml b/app/src/main/res/drawable/ic_school_24dp.xml new file mode 100644 index 0000000..4669d7c --- /dev/null +++ b/app/src/main/res/drawable/ic_school_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout-small/activity_main.xml b/app/src/main/res/layout-small/activity_main.xml index aaa3149..526b13c 100644 --- a/app/src/main/res/layout-small/activity_main.xml +++ b/app/src/main/res/layout-small/activity_main.xml @@ -51,6 +51,10 @@ android:drawableEnd="@drawable/ic_book_24dp" android:layout_weight="1" android:drawableStart="@drawable/ic_arrow_drop_down_24dp"/> + + + android:drawableStart="@drawable/ic_arrow_drop_down_24dp" + android:layout_weight="1"/> + + android:drawableStart="@drawable/ic_arrow_drop_down_24dp" + android:layout_weight="1"/> + @@ -429,7 +438,7 @@ android:layout_height="wrap_content" android:inputType="number" android:id="@+id/tempsEditText" android:hint="@string/min" android:layout_weight="1" - android:autofillHints="" android:minEms="10"/> + android:autofillHints="" android:minEms="8"/> diff --git a/app/src/main/res/menu/main_activity_menu.xml b/app/src/main/res/menu/main_activity_menu.xml index 43bb161..59b493e 100644 --- a/app/src/main/res/menu/main_activity_menu.xml +++ b/app/src/main/res/menu/main_activity_menu.xml @@ -1,6 +1,9 @@ - + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 47b0cba..fd7744c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -126,15 +126,20 @@ Téléchargement des questions Téléchargement des images ~30Mo. Cela peut prendre beaucoup de temps… Téléchargement des question + Téléchargement du cours de F6KGL Décompression en cours Génération de la base de données Derniers ajustements Un erreur s\'est produite: code %1$b/%2$b/%3$b Verifiez votre connexion et redémarrez l\'application - Essayez de redémarrer l\'application et contactez le développeur si le problème persiste + Verifiez si il reste du stockage disponible (70Mo) puis essayez de redémarrer l\'application ou contactez le développeur si le problème persiste Arrêter l\'examen Oui Non + + Ouvrir le cours + Ouvrir les vidéos de F6KGL +