Added "Time Elapsed" field
This commit is contained in:
parent
49960dcd7b
commit
8b2bd0522c
|
@ -41,6 +41,8 @@ public class TriviaGameResultsActivity extends BaseActivity {
|
||||||
TextView textResultsWrong;
|
TextView textResultsWrong;
|
||||||
@BindView(R.id.text_results_total)
|
@BindView(R.id.text_results_total)
|
||||||
TextView textResultsTotal;
|
TextView textResultsTotal;
|
||||||
|
@BindView(R.id.text_results_time_elapsed)
|
||||||
|
TextView textResultsTimeElapsed;
|
||||||
@BindView(R.id.button_return_to_menu)
|
@BindView(R.id.button_return_to_menu)
|
||||||
Button buttonReturnToMenu;
|
Button buttonReturnToMenu;
|
||||||
|
|
||||||
|
@ -61,9 +63,22 @@ public class TriviaGameResultsActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the difference between startEpoch and endEpoch
|
||||||
|
float timeDifference = (game.getEndEpoch() - game.getStartEpoch())/1000F;
|
||||||
|
|
||||||
textResultsCorrect.setText(String.valueOf(correctTotal));
|
textResultsCorrect.setText(String.valueOf(correctTotal));
|
||||||
textResultsWrong.setText(String.valueOf(game.getQuestionsCount() - correctTotal));
|
textResultsWrong.setText(String.valueOf(game.getQuestionsCount() - correctTotal));
|
||||||
textResultsTotal.setText(String.valueOf(game.getQuestionsCount()));
|
textResultsTotal.setText(String.valueOf(game.getQuestionsCount()));
|
||||||
|
if (timeDifference < 60000L)
|
||||||
|
// Use the "n seconds" string since the time difference was less than 60 seconds.
|
||||||
|
textResultsTimeElapsed.setText(
|
||||||
|
String.format(getString(R.string.ui_results_time_elapsed_format_seconds), timeDifference)
|
||||||
|
);
|
||||||
|
else
|
||||||
|
// Use the "n minutes" string since the time difference was equal to or more than 60 seconds.
|
||||||
|
textResultsTimeElapsed.setText(
|
||||||
|
String.format(getString(R.string.ui_results_time_elapsed_format_minutes), timeDifference / 60F)
|
||||||
|
);
|
||||||
|
|
||||||
buttonReturnToMenu.setOnClickListener(v -> finish());
|
buttonReturnToMenu.setOnClickListener(v -> finish());
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,43 +27,65 @@ import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TriviaGame implements Serializable {
|
public class TriviaGame implements Serializable {
|
||||||
private int currentQuestion;
|
private int currentQuestion;
|
||||||
private final boolean[] results;
|
private final boolean[] results;
|
||||||
private final List<TriviaQuestion> questions;
|
private final List<TriviaQuestion> questions;
|
||||||
|
private final long startEpoch;
|
||||||
|
private long endEpoch = -1;
|
||||||
|
|
||||||
public TriviaGame(List<TriviaQuestion> questions) {
|
public TriviaGame(List<TriviaQuestion> questions) {
|
||||||
this.currentQuestion = 0;
|
this.currentQuestion = 0;
|
||||||
this.questions = questions;
|
this.questions = questions;
|
||||||
this.results = new boolean[questions.size()];
|
this.results = new boolean[questions.size()];
|
||||||
}
|
this.startEpoch = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
public TriviaQuestion getCurrentQuestion() {
|
/**
|
||||||
return this.questions.get(currentQuestion);
|
* @return The time this trivia game started in a UNIX timestamp format.
|
||||||
}
|
* @since 2021-03-17
|
||||||
|
*/
|
||||||
|
public long getStartEpoch(){
|
||||||
|
return this.startEpoch;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return The time this trivia game ended in a UNIX timestamp format. If the player is still playing the game, the return will be equal to -1.
|
||||||
|
* @since 2021-03-17
|
||||||
|
*/
|
||||||
|
public long getEndEpoch(){
|
||||||
|
return this.endEpoch;
|
||||||
|
}
|
||||||
|
|
||||||
public int getQuestionProgress() {
|
public TriviaQuestion getCurrentQuestion() {
|
||||||
return this.currentQuestion + 1;
|
return this.questions.get(currentQuestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getQuestionsCount() {
|
public int getQuestionProgress() {
|
||||||
return this.questions.size();
|
return this.currentQuestion + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean[] getResults() {
|
public int getQuestionsCount() {
|
||||||
return this.results;
|
return this.questions.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean nextQuestion(String guess) {
|
public boolean[] getResults() {
|
||||||
TriviaQuestion question = getCurrentQuestion();
|
return this.results;
|
||||||
boolean answer = question.checkAnswer(guess);
|
}
|
||||||
|
|
||||||
results[currentQuestion] = answer;
|
public boolean nextQuestion(String guess) {
|
||||||
currentQuestion++;
|
TriviaQuestion question = getCurrentQuestion();
|
||||||
|
boolean answer = question.checkAnswer(guess);
|
||||||
|
|
||||||
return answer;
|
results[currentQuestion] = answer;
|
||||||
}
|
currentQuestion++;
|
||||||
|
|
||||||
public boolean isDone() {
|
return answer;
|
||||||
return (this.currentQuestion == questions.size());
|
}
|
||||||
}
|
|
||||||
|
public boolean isDone() {
|
||||||
|
boolean isDone = this.currentQuestion == questions.size();
|
||||||
|
// Check isDone and set the trivia game end epoch if the endEpoch field was not yet changed if it's true.
|
||||||
|
if (isDone && endEpoch == -1)
|
||||||
|
this.endEpoch = System.currentTimeMillis();
|
||||||
|
return isDone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,95 +23,113 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:fillViewport="true">
|
android:fillViewport="true">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context="io.github.trytonvanmeer.libretrivia.activities.TriviaGameResultsActivity">
|
tools:context="io.github.trytonvanmeer.libretrivia.activities.TriviaGameResultsActivity">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="250dp"
|
android:layout_width="250dp"
|
||||||
android:layout_height="250dp"
|
android:layout_height="250dp"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:scaleType="fitXY"
|
android:scaleType="fitXY"
|
||||||
android:src="@drawable/ic_clipboard_text"
|
android:src="@drawable/ic_clipboard_text"
|
||||||
android:tint="@color/colorTextSecondary" />
|
android:tint="@color/colorTextSecondary" />
|
||||||
|
|
||||||
<!-- Total Answers -->
|
<!-- Total Answers -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="16dp">
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/ResultText"
|
style="@style/ResultText"
|
||||||
android:text="@string/ui_results_total"
|
android:text="@string/ui_results_total"
|
||||||
android:textColor="@color/colorAccent" />
|
android:textColor="@color/colorAccent" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_results_total"
|
android:id="@+id/text_results_total"
|
||||||
style="@style/ResultText"
|
style="@style/ResultText"
|
||||||
tools:text="10" />
|
tools:text="10" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Correct Answers -->
|
<!-- Correct Answers -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="16dp">
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/ResultText"
|
style="@style/ResultText"
|
||||||
android:text="@string/ui_results_correct"
|
android:text="@string/ui_results_correct"
|
||||||
android:textColor="@color/colorAccentGreen" />
|
android:textColor="@color/colorAccentGreen" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_results_correct"
|
android:id="@+id/text_results_correct"
|
||||||
style="@style/ResultText"
|
style="@style/ResultText"
|
||||||
tools:text="6" />
|
tools:text="6" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Wrong Answers-->
|
<!-- Wrong Answers-->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="16dp">
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/ResultText"
|
style="@style/ResultText"
|
||||||
android:text="@string/ui_results_wrong"
|
android:text="@string/ui_results_wrong"
|
||||||
android:textColor="@color/colorAccentRed" />
|
android:textColor="@color/colorAccentRed" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_results_wrong"
|
android:id="@+id/text_results_wrong"
|
||||||
style="@style/ResultText"
|
style="@style/ResultText"
|
||||||
tools:text="4" />
|
tools:text="4" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Buttons -->
|
<!-- Time Elapsed -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center">
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
<Button
|
<TextView
|
||||||
android:id="@+id/button_return_to_menu"
|
style="@style/ResultText"
|
||||||
style="@style/Button"
|
android:text="@string/ui_results_time_elapsed"
|
||||||
android:layout_width="wrap_content"
|
android:textColor="@color/colorAccentOrange" />
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:text="@string/ui_return_to_menu" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
<TextView
|
||||||
|
android:id="@+id/text_results_time_elapsed"
|
||||||
|
style="@style/ResultText"
|
||||||
|
tools:text="4" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Buttons -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_return_to_menu"
|
||||||
|
style="@style/Button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/ui_return_to_menu" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
|
@ -23,13 +23,14 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<color name="colorPrimary">#F44336</color>
|
<color name="colorPrimary">#14A210</color>
|
||||||
<color name="colorPrimaryDark">#D32F2F</color>
|
<color name="colorPrimaryDark">#0D7D0A</color>
|
||||||
<color name="colorAccent">#536DFE</color>
|
<color name="colorAccent">#536DFE</color>
|
||||||
<color name="colorTextPrimary">#212121</color>
|
<color name="colorTextPrimary">#212121</color>
|
||||||
<color name="colorTextSecondary">#757575</color>
|
<color name="colorTextSecondary">#757575</color>
|
||||||
<color name="colorText">#FFFFFF</color>
|
<color name="colorText">#FFFFFF</color>
|
||||||
|
|
||||||
<color name="colorAccentRed">#D50000</color>
|
<color name="colorAccentRed">#D50000</color>
|
||||||
<color name="colorAccentGreen">#00C853</color>
|
<color name="colorAccentGreen">#00C853</color>
|
||||||
|
<color name="colorAccentOrange">#E8681C</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -84,7 +84,10 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
<string name="ui_quit_game_msg">Are you sure you want to quit this game?</string>
|
<string name="ui_quit_game_msg">Are you sure you want to quit this game?</string>
|
||||||
<string name="ui_results_correct">Correct Answers</string>
|
<string name="ui_results_correct">Correct Answers</string>
|
||||||
<string name="ui_results_wrong">Wrong Answers</string>
|
<string name="ui_results_wrong">Wrong Answers</string>
|
||||||
<string name="ui_results_total">Total Questions</string>
|
<string name="ui_results_total">Total Questions</string>
|
||||||
|
<string name="ui_results_time_elapsed">Time Elapsed</string>
|
||||||
|
<string name="ui_results_time_elapsed_format_seconds">%.1f seconds</string>
|
||||||
|
<string name="ui_results_time_elapsed_format_minutes">%.1f minutes</string>
|
||||||
<string name="ui_return_to_menu">Return To Menu</string>
|
<string name="ui_return_to_menu">Return To Menu</string>
|
||||||
<string name="ui_source">Source</string>
|
<string name="ui_source">Source</string>
|
||||||
<string name="ui_source_about">This value specifies where the game should retrieve trivia data. By default, the game gathers trivia data from a server, but you can load trivia files with the "File" source option.</string>
|
<string name="ui_source_about">This value specifies where the game should retrieve trivia data. By default, the game gathers trivia data from a server, but you can load trivia files with the "File" source option.</string>
|
||||||
|
|
|
@ -24,43 +24,48 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<!-- Base application theme. -->
|
<!-- Base application theme. -->
|
||||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||||
<!-- Customize your theme here. -->
|
<!-- Customize your theme here. -->
|
||||||
<item name="colorPrimary">@color/colorPrimary</item>
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
<item name="colorAccent">@color/colorAccent</item>
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
</style>
|
</style>
|
||||||
|
<style name="AppTheme.Dark" parent="Theme.AppCompat">
|
||||||
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="TextLabel">
|
<style name="TextLabel">
|
||||||
<item name="android:layout_width">match_parent</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
<item name="android:layout_height">wrap_content</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
<item name="android:textSize">18sp</item>
|
<item name="android:textSize">18sp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Spinner">
|
<style name="Spinner">
|
||||||
<item name="android:layout_width">match_parent</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
<item name="android:layout_height">wrap_content</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
<item name="android:layout_marginBottom">16dp</item>
|
<item name="android:layout_marginBottom">16dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Button" parent="Base.Widget.AppCompat.Button">
|
<style name="Button" parent="Base.Widget.AppCompat.Button">
|
||||||
<item name="backgroundTint">@color/colorAccent</item>
|
<item name="backgroundTint">@color/colorAccent</item>
|
||||||
<item name="android:textColor">@color/colorText</item>
|
<item name="android:textColor">@color/colorText</item>
|
||||||
<item name="android:textAlignment">center</item>
|
<item name="android:textAlignment">center</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AnswerButton" parent="Button">
|
<style name="AnswerButton" parent="Button">
|
||||||
<item name="android:width">300dp</item>
|
<item name="android:width">300dp</item>
|
||||||
<item name="android:layout_marginBottom">16dp</item>
|
<item name="android:layout_marginBottom">16dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="ResultText">
|
<style name="ResultText">
|
||||||
<item name="android:layout_width">0dp</item>
|
<item name="android:layout_width">0dp</item>
|
||||||
<item name="android:layout_height">wrap_content</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
<item name="android:layout_weight">1</item>
|
<item name="android:layout_weight">1</item>
|
||||||
<item name="android:textAlignment">center</item>
|
<item name="android:textAlignment">center</item>
|
||||||
<item name="android:textStyle">bold</item>
|
<item name="android:textStyle">bold</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue