Skip to content

Commit

Permalink
- cours integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime-Favier committed Jun 22, 2020
1 parent 187521c commit 67e02f3
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/dev/favier/exam1radioamateur/DbPopulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
83 changes: 82 additions & 1 deletion app/src/main/java/dev/favier/exam1radioamateur/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -193,6 +199,7 @@ private void setupControls() {
}
updateNbrofQSpinner();


// shared preference writer
final SharedPreferences.Editor sharedEditor = sharedPref.edit();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -470,13 +518,21 @@ public void updateNbrofQSpinner(View view) {
themeRegistered = 4;
}
List<String> 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<String> adapter = new ArrayAdapter<String>(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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -551,13 +611,23 @@ public void updateNbrofQSpinner() {
themeRegistered = 4;
}
List<String> 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<String> adapter = new ArrayAdapter<String>(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
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_ondemand_video_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@android:color/white"
android:pathData="M21,3L3,3c-1.11,0 -2,0.89 -2,2v12c0,1.1 0.89,2 2,2h5v2h8v-2h5c1.1,0 1.99,-0.9 1.99,-2L23,5c0,-1.11 -0.9,-2 -2,-2zM21,17L3,17L3,5h18v12zM16,11l-7,4L9,7z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_school_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@android:color/white"
android:pathData="M5,13.18v4L12,21l7,-3.82v-4L12,17l-7,-3.82zM12,3L1,9l11,6 9,-4.91V17h2V9L12,3z"/>
</vector>
8 changes: 8 additions & 0 deletions app/src/main/res/layout-small/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
android:drawableEnd="@drawable/ic_book_24dp"
android:layout_weight="1"
android:drawableStart="@drawable/ic_arrow_drop_down_24dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/legislationCheckBox"
android:textSize="18sp" android:textColor="@color/colorSecondary"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
Expand Down Expand Up @@ -193,6 +197,10 @@
android:layout_weight="1"
android:drawableEnd="@drawable/ic_build_24dp"
android:drawableStart="@drawable/ic_arrow_drop_down_24dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/techniqueCheckBox"
android:textSize="18sp" android:textColor="@color/colorSecondary"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@
android:layout_height="wrap_content" android:id="@+id/legislationTextView"
android:textSize="24sp" android:textColor="@color/colorSecondary"
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"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/legislationCheckBox"
android:textSize="24sp" android:textColor="@color/colorSecondary"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
Expand Down Expand Up @@ -190,9 +194,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/techniqueTextView"
android:textSize="24sp" android:textColor="@color/colorSecondary"
android:layout_weight="1"
android:drawableEnd="@drawable/ic_build_24dp"
android:drawableStart="@drawable/ic_arrow_drop_down_24dp"/>
android:drawableStart="@drawable/ic_arrow_drop_down_24dp"
android:layout_weight="1"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/techniqueCheckBox"
android:textSize="24sp" android:textColor="@color/colorSecondary"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
Expand Down Expand Up @@ -386,6 +394,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/nbrQSpinner"
android:layout_weight="1" android:spinnerMode="dropdown"
android:foregroundTint="@color/colorText"
android:background="@color/colorAccent"/>
</TableRow>
<TableRow android:layout_width="match_parent" android:layout_height="match_parent">
Expand Down Expand Up @@ -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"/>
</TableRow>
</TableLayout>
</androidx.cardview.widget.CardView>
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/menu/main_activity_menu.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">

<item android:id="@+id/gotoCoursItem" android:icon="@drawable/ic_school_24dp" app:showAsAction="ifRoom"
android:title="@string/gotoCours" android:iconTint="@android:color/white"/>
<item android:id="@+id/gotoVideoItem" android:icon="@drawable/ic_ondemand_video_24dp" app:showAsAction="ifRoom"
android:title="@string/gotoVideo" android:iconTint="@android:color/white"/>
<item android:title="@string/syncroQ" android:id="@+id/sycroItem" app:showAsAction="never"/>
<item android:title="@string/remerciement" android:id="@+id/remerciementItem" app:showAsAction="never"/>
<item android:title="@string/opensource" android:id="@+id/opensourceItem" app:showAsAction="never"/>
Expand Down
Loading

0 comments on commit 67e02f3

Please sign in to comment.