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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,29 @@ 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 TriviaQuestion getCurrentQuestion() {
|
public TriviaQuestion getCurrentQuestion() {
|
||||||
|
@ -64,6 +82,10 @@ public class TriviaGame implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDone() {
|
public boolean isDone() {
|
||||||
return (this.currentQuestion == questions.size());
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,24 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Time Elapsed -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/ResultText"
|
||||||
|
android:text="@string/ui_results_time_elapsed"
|
||||||
|
android:textColor="@color/colorAccentOrange" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_results_time_elapsed"
|
||||||
|
style="@style/ResultText"
|
||||||
|
tools:text="4" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Buttons -->
|
<!-- Buttons -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -23,8 +23,8 @@ 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>
|
||||||
|
@ -32,4 +32,5 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
|
|
||||||
<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>
|
||||||
|
|
|
@ -85,6 +85,9 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
<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>
|
||||||
|
|
|
@ -31,6 +31,11 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
<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>
|
||||||
|
|
Loading…
Reference in New Issue