Added "Time Elapsed" field

This commit is contained in:
luca0N! 2021-03-17 16:16:37 -03:00
parent 49960dcd7b
commit 8b2bd0522c
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
6 changed files with 204 additions and 140 deletions

View File

@ -41,6 +41,8 @@ public class TriviaGameResultsActivity extends BaseActivity {
TextView textResultsWrong;
@BindView(R.id.text_results_total)
TextView textResultsTotal;
@BindView(R.id.text_results_time_elapsed)
TextView textResultsTimeElapsed;
@BindView(R.id.button_return_to_menu)
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));
textResultsWrong.setText(String.valueOf(game.getQuestionsCount() - correctTotal));
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());
}

View File

@ -27,43 +27,65 @@ import java.io.Serializable;
import java.util.List;
public class TriviaGame implements Serializable {
private int currentQuestion;
private final boolean[] results;
private final List<TriviaQuestion> questions;
private int currentQuestion;
private final boolean[] results;
private final List<TriviaQuestion> questions;
private final long startEpoch;
private long endEpoch = -1;
public TriviaGame(List<TriviaQuestion> questions) {
this.currentQuestion = 0;
this.questions = questions;
this.results = new boolean[questions.size()];
}
public TriviaGame(List<TriviaQuestion> questions) {
this.currentQuestion = 0;
this.questions = questions;
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() {
return this.currentQuestion + 1;
}
public TriviaQuestion getCurrentQuestion() {
return this.questions.get(currentQuestion);
}
public int getQuestionsCount() {
return this.questions.size();
}
public int getQuestionProgress() {
return this.currentQuestion + 1;
}
public boolean[] getResults() {
return this.results;
}
public int getQuestionsCount() {
return this.questions.size();
}
public boolean nextQuestion(String guess) {
TriviaQuestion question = getCurrentQuestion();
boolean answer = question.checkAnswer(guess);
public boolean[] getResults() {
return this.results;
}
results[currentQuestion] = answer;
currentQuestion++;
public boolean nextQuestion(String guess) {
TriviaQuestion question = getCurrentQuestion();
boolean answer = question.checkAnswer(guess);
return answer;
}
results[currentQuestion] = answer;
currentQuestion++;
public boolean isDone() {
return (this.currentQuestion == questions.size());
}
return answer;
}
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;
}
}

View File

@ -23,95 +23,113 @@ Contact us at <joguitos+pluck@luca0n.com>.
-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="io.github.trytonvanmeer.libretrivia.activities.TriviaGameResultsActivity">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="io.github.trytonvanmeer.libretrivia.activities.TriviaGameResultsActivity">
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:scaleType="fitXY"
android:src="@drawable/ic_clipboard_text"
android:tint="@color/colorTextSecondary" />
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:scaleType="fitXY"
android:src="@drawable/ic_clipboard_text"
android:tint="@color/colorTextSecondary" />
<!-- Total Answers -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<!-- Total Answers -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<TextView
style="@style/ResultText"
android:text="@string/ui_results_total"
android:textColor="@color/colorAccent" />
<TextView
style="@style/ResultText"
android:text="@string/ui_results_total"
android:textColor="@color/colorAccent" />
<TextView
android:id="@+id/text_results_total"
style="@style/ResultText"
tools:text="10" />
<TextView
android:id="@+id/text_results_total"
style="@style/ResultText"
tools:text="10" />
</LinearLayout>
</LinearLayout>
<!-- Correct Answers -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<!-- Correct Answers -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<TextView
style="@style/ResultText"
android:text="@string/ui_results_correct"
android:textColor="@color/colorAccentGreen" />
<TextView
style="@style/ResultText"
android:text="@string/ui_results_correct"
android:textColor="@color/colorAccentGreen" />
<TextView
android:id="@+id/text_results_correct"
style="@style/ResultText"
tools:text="6" />
<TextView
android:id="@+id/text_results_correct"
style="@style/ResultText"
tools:text="6" />
</LinearLayout>
</LinearLayout>
<!-- Wrong Answers-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<!-- Wrong Answers-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<TextView
style="@style/ResultText"
android:text="@string/ui_results_wrong"
android:textColor="@color/colorAccentRed" />
<TextView
style="@style/ResultText"
android:text="@string/ui_results_wrong"
android:textColor="@color/colorAccentRed" />
<TextView
android:id="@+id/text_results_wrong"
style="@style/ResultText"
tools:text="4" />
<TextView
android:id="@+id/text_results_wrong"
style="@style/ResultText"
tools:text="4" />
</LinearLayout>
</LinearLayout>
<!-- Buttons -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<!-- Time Elapsed -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<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" />
<TextView
style="@style/ResultText"
android:text="@string/ui_results_time_elapsed"
android:textColor="@color/colorAccentOrange" />
</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>
</ScrollView>

View File

@ -23,13 +23,14 @@ Contact us at <joguitos+pluck@luca0n.com>.
-->
<resources>
<color name="colorPrimary">#F44336</color>
<color name="colorPrimaryDark">#D32F2F</color>
<color name="colorPrimary">#14A210</color>
<color name="colorPrimaryDark">#0D7D0A</color>
<color name="colorAccent">#536DFE</color>
<color name="colorTextPrimary">#212121</color>
<color name="colorTextSecondary">#757575</color>
<color name="colorText">#FFFFFF</color>
<color name="colorAccentRed">#D50000</color>
<color name="colorAccentGreen">#00C853</color>
<color name="colorAccentGreen">#00C853</color>
<color name="colorAccentOrange">#E8681C</color>
</resources>

View File

@ -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_results_correct">Correct 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_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>

View File

@ -24,43 +24,48 @@ Contact us at <joguitos+pluck@luca0n.com>.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</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">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">18sp</item>
</style>
<style name="TextLabel">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">18sp</item>
</style>
<style name="Spinner">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">16dp</item>
</style>
<style name="Spinner">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">16dp</item>
</style>
<style name="Button" parent="Base.Widget.AppCompat.Button">
<item name="backgroundTint">@color/colorAccent</item>
<item name="android:textColor">@color/colorText</item>
<item name="android:textAlignment">center</item>
</style>
<style name="Button" parent="Base.Widget.AppCompat.Button">
<item name="backgroundTint">@color/colorAccent</item>
<item name="android:textColor">@color/colorText</item>
<item name="android:textAlignment">center</item>
</style>
<style name="AnswerButton" parent="Button">
<item name="android:width">300dp</item>
<item name="android:layout_marginBottom">16dp</item>
</style>
<style name="AnswerButton" parent="Button">
<item name="android:width">300dp</item>
<item name="android:layout_marginBottom">16dp</item>
</style>
<style name="ResultText">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:textAlignment">center</item>
<item name="android:textStyle">bold</item>
</style>
<style name="ResultText">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:textAlignment">center</item>
<item name="android:textStyle">bold</item>
</style>
</resources>