Skip to content

Commit

Permalink
Merge pull request #10 from wagenknecht/voll_krass_bugfix
Browse files Browse the repository at this point in the history
added correct categorys and difficulties at the highscore
  • Loading branch information
wagenknecht authored Jun 29, 2022
2 parents a734be2 + 358e8aa commit b7d8baf
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
database = AppDatabase.getDatabase(getApplicationContext());
ArrayAdapter categoryAdapter = new ArrayAdapter<>(this, R.layout.spinner_selected_item, Category.values());
Category[] categories = Category.values();
ArrayAdapter categoryAdapter = new ArrayAdapter<>(this, R.layout.spinner_selected_item, categories);
categoryAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
selectCategorySpinner.setAdapter(categoryAdapter);
selectCategorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
Expand All @@ -66,6 +67,13 @@ public void onNothingSelected(AdapterView<?> adapterView) {
if (getIntent().getExtras() != null) {
score = (Integer) getIntent().getSerializableExtra("score");
category = (String) getIntent().getSerializableExtra("category");
for(int i=0;i<categories.length;i++){
if(categories[i].toString().equals(category)){
selectCategorySpinner.setSelection(i);
break;
}
}

// if (score>=DatabaseHighsore)
checkScore();
btnStart = findViewById(R.id.btnStart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
category = question.get(0).getCategory();
btnContinue = findViewById(R.id.btnContinue);
btnContinue.setVisibility(View.INVISIBLE);
setAnsweres();
setAnswers();
setQuestion();
number = 0;
}

//gets Triggert when a Button is clicked
public void answere(View view) {
public void answer(View view) {
//check if questions are all asked
if (number % questionsPerApiCall == 0) {
loadMoreQuestions();
Expand Down Expand Up @@ -101,12 +101,11 @@ public void setQuestion() {

}

public Button setAnsweres() {
public Button setAnswers() {
//select a Random button to be right
Random random = new Random();
int correct = random.nextInt(4);
correctAnswere = buttons.get(correct); //save CorrectAnswer to global string to compare result
//todo remove string correct, just for testing
correctAnswere.setText(question.get(number % questionsPerApiCall).getCorrect_answer());
int j = 0;
for (int i = 0; i < buttons.size(); i++) {
Expand All @@ -128,7 +127,7 @@ public void clickContinue(View view) {
} else {
buttons.forEach(a -> a.setClickable(true));
number++;
setAnsweres();
setAnswers();
setQuestion();
}
view.setVisibility(View.INVISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
database = AppDatabase.getDatabase(getApplicationContext());
ArrayAdapter categoryAdapter = new ArrayAdapter<>(this, R.layout.spinner_selected_item, Category.values());
Category[] categories= Category.values();
ArrayAdapter categoryAdapter = new ArrayAdapter<>(this, R.layout.spinner_selected_item, categories);
categoryAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
selectCategorySpinner.setAdapter(categoryAdapter);
selectCategorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
Expand All @@ -71,21 +72,40 @@ public void onNothingSelected(AdapterView<?> adapterView) {
}
});

btnEasy = findViewById(R.id.btnEasy);
btnMedium = findViewById(R.id.btnMedium);
btnHard = findViewById(R.id.btnHard);
btnMedium.setBackgroundColor(Color.GRAY);
btnHard.setBackgroundColor(Color.GRAY);


if (getIntent().getExtras() != null) {
score = (Integer) getIntent().getSerializableExtra("score");
category = (String) getIntent().getSerializableExtra("category");
difficulty = (String) getIntent().getSerializableExtra("difficulty");

switch(difficulty){
case "hard": hard(btnHard); break;
case "medium": medium(btnMedium); break;
case "easy": easy(btnEasy); break;
}

for(int i=0;i<categories.length;i++){
if(categories[i].toString().equals(category)){
selectCategorySpinner.setSelection(i);
break;
}
}




// if (score>=DatabaseHighsore)
checkScore();
Button btnStart = findViewById(R.id.btnStart);
btnStart.setText("Retry");
}

btnEasy = findViewById(R.id.btnEasy);
btnMedium = findViewById(R.id.btnMedium);
btnHard = findViewById(R.id.btnHard);
btnMedium.setBackgroundColor(Color.GRAY);
btnHard.setBackgroundColor(Color.GRAY);

List<Bestenliste> bestenliste1 = database.bestenlisteDao().getBestenlisteCategoryDifficultyEntry(selectCategorySpinner.getSelectedItem().toString(), "easy");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class QuizActivity extends AppCompatActivity {

private Button correctAnswere;
private Button correctAnswer;
private int score;
private List<Question> question;
private int number;
Expand All @@ -47,21 +47,21 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
difficulty = question.get(0).getDifficulty();
btnContinue = findViewById(R.id.btnContinue);
btnContinue.setVisibility(View.INVISIBLE);
setAnsweres();
setAnswers();
setQuestion();
number = 0;
}

//gets Triggert when a Button is clicked
public void answere(View view) {
//gets triggered when a Button is clicked
public void answer(View view) {
btnContinue.setVisibility(View.VISIBLE);
buttons.forEach(a -> {
a.setClickable(false);
a.setBackgroundColor(Color.GRAY);
});
correctAnswere.setBackgroundColor(Color.GREEN);
correctAnswer.setBackgroundColor(Color.GREEN);
//if question is correct
if (view.getId() == correctAnswere.getId()) {
if (view.getId() == correctAnswer.getId()) {
score = score + 1;
} else {
view.setBackgroundColor(Color.RED);
Expand All @@ -77,13 +77,12 @@ public void setQuestion() {
Number.setText("Question " + (number + 1) + "/10");
}

public Button setAnsweres() {
public Button setAnswers() {
//select a Random button to be right
Random random = new Random();
int correct = random.nextInt(4);
correctAnswere = buttons.get(correct); //save CorrectAnswer to global string to compare result
//todo remove string correct, just for testing
correctAnswere.setText(question.get(number).getCorrect_answer());
correctAnswer = buttons.get(correct); //save CorrectAnswer to global string to compare result
correctAnswer.setText(question.get(number).getCorrect_answer());
int j = 0;
for (int i = 0; i < buttons.size(); i++) {
if (i != correct) {
Expand All @@ -92,7 +91,7 @@ public Button setAnsweres() {
j++;
}
}
return correctAnswere;
return correctAnswer;
}

public void clickContinue(View view) {
Expand All @@ -106,7 +105,7 @@ public void clickContinue(View view) {
} else {
buttons.forEach(a -> a.setClickable(true));
number++;
setAnsweres();
setAnswers();
setQuestion();
view.setVisibility(View.INVISIBLE);
buttons.forEach(a -> a.setBackgroundColor(fetchcolorOnPrimary()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class OpenTrivialRestClient {
private static AsyncHttpClient client = new AsyncHttpClient();

public static void get(int amount, RequestParams params, AsyncHttpResponseHandler responseHandler) {
// TODO: Params does not seem to be needed. Investigate later.
client.get(getAbsoluteUrl(amount), params, responseHandler);
}

Expand Down
11 changes: 0 additions & 11 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,4 @@
android:text="Highscore Endless"
android:textSize="20sp" />

<Button
android:id="@+id/settingsBtn"
style="@style/blueButton"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="8dp"
android:layout_marginHorizontal="26dp"
android:text="Settings"
android:textSize="20sp"
android:onClick="clickSettings"/>

</LinearLayout>
8 changes: 4 additions & 4 deletions app/src/main/res/layout/quiz_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
android:layout_height="100sp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:onClick="answere"
android:onClick="answer"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/antwort4"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -77,7 +77,7 @@
android:layout_height="100sp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:onClick="answere"
android:onClick="answer"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/btnContinue"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -91,7 +91,7 @@
android:layout_height="100sp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:onClick="answere"
android:onClick="answer"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/btnContinue"
app:layout_constraintEnd_toStartOf="@+id/antwort4"
Expand All @@ -105,7 +105,7 @@
android:layout_height="100sp"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:onClick="answere"
android:onClick="answer"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/antwort3"
app:layout_constraintEnd_toStartOf="@+id/antwort2"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/quiz_endless_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
android:layout_height="100sp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:onClick="answere"
android:onClick="answer"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/antwort4"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -107,7 +107,7 @@
android:layout_height="100sp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:onClick="answere"
android:onClick="answer"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/btnContinue"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -121,7 +121,7 @@
android:layout_height="100sp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:onClick="answere"
android:onClick="answer"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/btnContinue"
app:layout_constraintEnd_toStartOf="@+id/antwort4"
Expand All @@ -135,7 +135,7 @@
android:layout_height="100sp"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:onClick="answere"
android:onClick="answer"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/antwort3"
app:layout_constraintEnd_toStartOf="@+id/antwort2"
Expand Down

0 comments on commit b7d8baf

Please sign in to comment.