diff --git a/README.md b/README.md
index 0e5c6e2..f696d4d 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,8 @@
# Pluck
+Pluck is a trivia game for Android. It is forked from [LibreTrivia](https://github.comhttps://github.com/tryton-vanmeer/LibreTrivia/).
+
+## License
+
+This game is licensed under the GNU General Public License version 3 or (at your option) any later version. Read [LICENSE](./LICENSE) for more details.
+
diff --git a/app/build.gradle b/app/build.gradle
index 948b738..7d026a6 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,15 +1,14 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 28
- buildToolsVersion '28.0.3'
+ compileSdkVersion 29
defaultConfig {
- applicationId "io.github.trytonvanmeer.libretrivia"
+ applicationId "com.luca0n.joguitos.pluck"
minSdkVersion 19
- targetSdkVersion 28
- versionCode 3
- versionName "0.3"
+ targetSdkVersion 29
+ versionCode 1
+ versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@@ -28,7 +27,7 @@ android {
}
ext {
- butterknife = '9.0.0-rc2'
+ butterknife = '10.2.3'
}
dependencies {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 6bfe14d..b7037a1 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,11 +1,11 @@
+ package="com.luca0n.joguitos.pluck">
-
\ No newline at end of file
+
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/PluckApplication.java b/app/src/main/java/com/luca0n/joguitos/pluck/PluckApplication.java
new file mode 100644
index 0000000..c886f10
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/PluckApplication.java
@@ -0,0 +1,43 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck;
+
+import android.annotation.SuppressLint;
+import android.app.Application;
+import android.content.Context;
+
+public class PluckApplication extends Application {
+ @SuppressLint("StaticFieldLeak")
+ private static Context context;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ PluckApplication.context = getApplicationContext();
+ }
+
+ public static Context getAppContext() {
+ return PluckApplication.context;
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/activities/BaseActivity.java b/app/src/main/java/com/luca0n/joguitos/pluck/activities/BaseActivity.java
new file mode 100644
index 0000000..dc57b9f
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/activities/BaseActivity.java
@@ -0,0 +1,82 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.activities;
+
+import android.annotation.SuppressLint;
+import android.content.Intent;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+
+import com.mikepenz.aboutlibraries.Libs;
+import com.mikepenz.aboutlibraries.LibsBuilder;
+
+import androidx.appcompat.app.AppCompatActivity;
+import com.luca0n.joguitos.pluck.R;
+import com.luca0n.joguitos.pluck.settings.SettingsActivity;
+
+@SuppressLint("Registered")
+public class BaseActivity extends AppCompatActivity {
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.app_menu, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.settings:
+ onSettings();
+ return true;
+ case R.id.about:
+ onAbout();
+ return true;
+ case android.R.id.home:
+ onBackPressed();
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ private void onSettings() {
+ Intent intent = new Intent(this, SettingsActivity.class);
+ startActivity(intent);
+ }
+
+ private void onAbout() {
+ String appName = getResources().getString(R.string.app_name);
+ String appDescription = getResources().getString(R.string.app_description);
+
+ new LibsBuilder()
+ .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
+ .withAboutIconShown(true)
+ .withAboutAppName(appName)
+ .withAboutVersionShownName(true)
+ .withAboutDescription(appDescription)
+ .start(this);
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/activities/MainActivity.java b/app/src/main/java/com/luca0n/joguitos/pluck/activities/MainActivity.java
new file mode 100644
index 0000000..a29015a
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/activities/MainActivity.java
@@ -0,0 +1,90 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.activities;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.Spinner;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import com.luca0n.joguitos.pluck.R;
+import com.luca0n.joguitos.pluck.trivia.TriviaCategory;
+import com.luca0n.joguitos.pluck.trivia.TriviaDifficulty;
+import com.luca0n.joguitos.pluck.trivia.TriviaQuery;
+
+public class MainActivity extends BaseActivity {
+
+ @BindView(R.id.button_play)
+ Button buttonPlay;
+ @BindView(R.id.spinner_number)
+ Spinner spinnerNumber;
+ @BindView(R.id.spinner_category)
+ Spinner spinnerCategory;
+ @BindView(R.id.spinner_difficulty)
+ Spinner spinnerDifficulty;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ ButterKnife.bind(this);
+
+ buttonPlay.setOnClickListener(v -> {
+ int amount = (int) spinnerNumber.getSelectedItem();
+ TriviaCategory category = (TriviaCategory) spinnerCategory.getSelectedItem();
+ TriviaDifficulty difficulty = (TriviaDifficulty) spinnerDifficulty.getSelectedItem();
+
+ TriviaQuery query = new TriviaQuery.Builder(amount)
+ .category(category)
+ .difficulty(difficulty)
+ .build();
+
+ Intent intent = new Intent(getApplicationContext(), TriviaGameActivity.class);
+ intent.putExtra(TriviaGameActivity.EXTRA_TRIVIA_QUERY, query);
+ startActivity(intent);
+ });
+
+
+ Integer[] numbers = new Integer[50];
+ for (int i = 0; i < 50; ) {
+ numbers[i] = ++i;
+ }
+ spinnerNumber.setAdapter(
+ new ArrayAdapter<>(
+ this, android.R.layout.simple_list_item_1, numbers)
+ );
+ spinnerNumber.setSelection(9);
+
+ spinnerCategory.setAdapter(
+ new ArrayAdapter<>(
+ this, android.R.layout.simple_list_item_1, TriviaCategory.values()));
+
+ spinnerDifficulty.setAdapter(
+ new ArrayAdapter<>(
+ this, android.R.layout.simple_list_item_1, TriviaDifficulty.values()));
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameActivity.java b/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameActivity.java
new file mode 100644
index 0000000..0367f7a
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameActivity.java
@@ -0,0 +1,250 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.activities;
+
+import android.app.AlertDialog;
+import android.content.Intent;
+import android.content.res.ColorStateList;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
+import android.os.AsyncTask;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.View;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import java.io.IOException;
+
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentTransaction;
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import com.luca0n.joguitos.pluck.R;
+import com.luca0n.joguitos.pluck.exceptions.NoTriviaResultsException;
+import com.luca0n.joguitos.pluck.fragments.TriviaGameErrorFragment;
+import com.luca0n.joguitos.pluck.fragments.TriviaQuestionFragment;
+import com.luca0n.joguitos.pluck.interfaces.IDownloadTriviaQuestionReceiver;
+import com.luca0n.joguitos.pluck.trivia.TriviaGame;
+import com.luca0n.joguitos.pluck.trivia.TriviaQuery;
+import com.luca0n.joguitos.pluck.trivia.TriviaQuestion;
+import com.luca0n.joguitos.pluck.util.ApiUtil;
+import com.luca0n.joguitos.pluck.util.SoundUtil;
+
+public class TriviaGameActivity extends BaseActivity
+ implements IDownloadTriviaQuestionReceiver {
+ static final String EXTRA_TRIVIA_QUERY = "extra_trivia_query";
+ private final String STATE_TRIVIA_GAME = "state_trivia_game";
+
+ private TriviaGame game;
+
+ @BindView(R.id.progress_bar)
+ ProgressBar progressBar;
+ @BindView(R.id.trivia_status_bar)
+ LinearLayout triviaStatusBar;
+ @BindView(R.id.text_question_category)
+ TextView textViewQuestionCategory;
+ @BindView(R.id.text_question_difficulty)
+ TextView textViewQuestionDifficulty;
+ @BindView(R.id.text_question_progress)
+ TextView textViewQuestionProgress;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_trivia_game);
+ ButterKnife.bind(this);
+
+ if (savedInstanceState != null) {
+ this.game = (TriviaGame) savedInstanceState.getSerializable(STATE_TRIVIA_GAME);
+ } else {
+ Bundle bundle = getIntent().getExtras();
+ assert bundle != null;
+ TriviaQuery query = (TriviaQuery) bundle.get(EXTRA_TRIVIA_QUERY);
+
+ progressBar.setVisibility(View.VISIBLE);
+
+ DownloadTriviaQuestionsTask task = new DownloadTriviaQuestionsTask();
+ task.setReceiver(this);
+ task.execute(query);
+ }
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putSerializable(STATE_TRIVIA_GAME, this.game);
+ }
+
+ @Override
+ public void onBackPressed() {
+ Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.frame_trivia_game);
+
+ if (fragment instanceof TriviaGameErrorFragment) {
+ super.onBackPressed();
+ } else {
+ new AlertDialog.Builder(this)
+ .setTitle(R.string.ui_quit_game)
+ .setMessage(R.string.ui_quit_game_msg)
+ .setPositiveButton(android.R.string.yes, (dialog, which) ->
+ TriviaGameActivity.super.onBackPressed())
+ .setNegativeButton(android.R.string.no, (dialog, which) -> {
+ })
+ .show();
+ }
+ }
+
+ public void onTriviaQuestionsDownloaded(String json) {
+ if (json == null) {
+ onNetworkError();
+ return;
+ } else {
+ try {
+ this.game = new TriviaGame(ApiUtil.jsonToQuestionArray(json));
+ } catch (NoTriviaResultsException e) {
+ onNoTriviaResults();
+ return;
+ }
+ }
+
+ // Setup game layout
+ progressBar.setVisibility(View.GONE);
+ triviaStatusBar.setVisibility(View.VISIBLE);
+ updateStatusBar();
+ updateTriviaQuestion();
+ }
+
+ private void updateStatusBar() {
+ String progress = getResources().getString(R.string.ui_question_progress,
+ game.getQuestionProgress(), game.getQuestionsCount());
+
+ String category = (game.getCurrentQuestion().getCategory() != null)
+ ? game.getCurrentQuestion().getCategory().toString() : "";
+
+ String difficulty = game.getCurrentQuestion().getDifficulty().toString();
+
+ textViewQuestionProgress.setText(progress);
+ textViewQuestionCategory.setText(category);
+ textViewQuestionDifficulty.setText(difficulty);
+ }
+
+ private void updateTriviaQuestion() {
+ Fragment fragment = TriviaQuestionFragment.newInstance();
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.frame_trivia_game, fragment)
+ .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
+ .commit();
+ }
+
+ private void onNetworkError() {
+ String msg = getResources().getString(R.string.error_network);
+ Fragment errorFragment = TriviaGameErrorFragment.newInstance(msg);
+
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ ft.replace(R.id.frame_trivia_game, errorFragment);
+ ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
+ ft.commit();
+ }
+
+ private void onNoTriviaResults() {
+ String msg = getResources().getString(R.string.error_no_trivia_results);
+ Fragment errorFragment = TriviaGameErrorFragment.newInstance(msg);
+
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ ft.replace(R.id.frame_trivia_game, errorFragment);
+ ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
+ ft.commit();
+ }
+
+ public TriviaQuestion getCurrentQuestion() {
+ return this.game.getCurrentQuestion();
+ }
+
+ public void onAnswerClick(Button answer, Button correctAnswer) {
+ boolean guess = game.nextQuestion(answer.getText().toString());
+
+ final int green = getResources().getColor(R.color.colorAccentGreen);
+ int color = guess ? green
+ : getResources().getColor(R.color.colorAccentRed);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ ColorStateList stateList = ColorStateList.valueOf(color);
+ answer.setBackgroundTintList(stateList);
+
+ if (!guess) {
+ final ColorStateList greenStateList = ColorStateList.valueOf(green);
+ correctAnswer.setBackgroundTintList(greenStateList);
+ }
+ } else {
+ answer.getBackground().getCurrent().setColorFilter(
+ new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
+
+ if (!guess)
+ correctAnswer.getBackground().getCurrent().setColorFilter(
+ new PorterDuffColorFilter(green, PorterDuff.Mode.MULTIPLY));
+ }
+
+ SoundUtil.playSound(this, guess ?
+ SoundUtil.SOUND_ANSWER_CORRECT : SoundUtil.SOUND_ANSWER_WRONG);
+
+ new Handler().postDelayed(() -> {
+ if (game.isDone()) {
+ Intent intent = new Intent(getApplicationContext(), TriviaGameResultsActivity.class);
+ intent.putExtra(TriviaGameResultsActivity.EXTRA_TRIVIA_GAME, game);
+ startActivity(intent);
+ finish();
+ } else {
+ updateStatusBar();
+ updateTriviaQuestion();
+ }
+ }, 500);
+ }
+
+ private static class DownloadTriviaQuestionsTask extends AsyncTask {
+ private IDownloadTriviaQuestionReceiver receiver;
+
+ @Override
+ protected String doInBackground(TriviaQuery... query) {
+ String json;
+ try {
+ json = ApiUtil.GET(query[0]);
+ } catch (IOException e) {
+ return null;
+ }
+ return json;
+ }
+
+ @Override
+ protected void onPostExecute(String json) {
+ receiver.onTriviaQuestionsDownloaded(json);
+ }
+
+ private void setReceiver(IDownloadTriviaQuestionReceiver receiver) {
+ this.receiver = receiver;
+ }
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameResultsActivity.java b/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameResultsActivity.java
new file mode 100644
index 0000000..219c5a2
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameResultsActivity.java
@@ -0,0 +1,70 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.activities;
+
+import android.os.Bundle;
+import android.widget.Button;
+import android.widget.TextView;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import com.luca0n.joguitos.pluck.R;
+import com.luca0n.joguitos.pluck.trivia.TriviaGame;
+
+public class TriviaGameResultsActivity extends BaseActivity {
+ static final String EXTRA_TRIVIA_GAME = "extra_trivia_game";
+
+ @BindView(R.id.text_results_correct)
+ TextView textResultsCorrect;
+ @BindView(R.id.text_results_wrong)
+ TextView textResultsWrong;
+ @BindView(R.id.text_results_total)
+ TextView textResultsTotal;
+ @BindView(R.id.button_return_to_menu)
+ Button buttonReturnToMenu;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_trivia_game_results);
+ ButterKnife.bind(this);
+
+ Bundle bundle = getIntent().getExtras();
+ TriviaGame game = (TriviaGame) bundle.get(EXTRA_TRIVIA_GAME);
+
+ int correctTotal = 0;
+
+ for (boolean result : game.getResults()) {
+ if (result) {
+ correctTotal++;
+ }
+ }
+
+ textResultsCorrect.setText(String.valueOf(correctTotal));
+ textResultsWrong.setText(String.valueOf(game.getQuestionsCount() - correctTotal));
+ textResultsTotal.setText(String.valueOf(game.getQuestionsCount()));
+
+ buttonReturnToMenu.setOnClickListener(v -> finish());
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/exceptions/NoTriviaResultsException.java b/app/src/main/java/com/luca0n/joguitos/pluck/exceptions/NoTriviaResultsException.java
new file mode 100644
index 0000000..2ff6e4c
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/exceptions/NoTriviaResultsException.java
@@ -0,0 +1,27 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.exceptions;
+
+public class NoTriviaResultsException extends Exception {
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/fragments/TriviaGameErrorFragment.java b/app/src/main/java/com/luca0n/joguitos/pluck/fragments/TriviaGameErrorFragment.java
new file mode 100644
index 0000000..0a97f83
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/fragments/TriviaGameErrorFragment.java
@@ -0,0 +1,69 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.fragments;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import com.luca0n.joguitos.pluck.R;
+
+public class TriviaGameErrorFragment extends Fragment {
+ private final static String ARG_ERROR_MSG = "arg_error_msg";
+
+ @BindView(R.id.text_error_msg)
+ TextView textView;
+
+ public TriviaGameErrorFragment() {
+ }
+
+ public static TriviaGameErrorFragment newInstance(String msg) {
+ Bundle args = new Bundle();
+ args.putString(ARG_ERROR_MSG, msg);
+
+ TriviaGameErrorFragment fragment = new TriviaGameErrorFragment();
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_trivia_game_error, container, false);
+ ButterKnife.bind(this, view);
+
+ Bundle args;
+ if ((args = getArguments()) != null) {
+ textView.setText(args.getString(ARG_ERROR_MSG));
+ }
+
+ return view;
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/fragments/TriviaQuestionFragment.java b/app/src/main/java/com/luca0n/joguitos/pluck/fragments/TriviaQuestionFragment.java
new file mode 100644
index 0000000..eaa02fa
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/fragments/TriviaQuestionFragment.java
@@ -0,0 +1,140 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.fragments;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.TextView;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+import butterknife.BindViews;
+import butterknife.ButterKnife;
+import com.luca0n.joguitos.pluck.R;
+import com.luca0n.joguitos.pluck.activities.TriviaGameActivity;
+import com.luca0n.joguitos.pluck.trivia.TriviaQuestion;
+import com.luca0n.joguitos.pluck.trivia.TriviaQuestionMultiple;
+
+
+public class TriviaQuestionFragment extends Fragment {
+
+ private static final int buttonAnswerOneID = R.id.button_answer_one;
+ private static final int buttonAnswerTwoID = R.id.button_answer_two;
+ private static final int buttonAnswerThreeID = R.id.button_answer_three;
+ private static final int buttonAnswerFourID = R.id.button_answer_four;
+
+ @BindViews({
+ buttonAnswerOneID,
+ buttonAnswerTwoID,
+ buttonAnswerThreeID,
+ buttonAnswerFourID
+ })
+ Button[] buttonAnswers;
+
+ Button buttonAnswerCorrect;
+
+ Button buttonAnswerTrue;
+ Button buttonAnswerFalse;
+
+ public TriviaQuestionFragment() {
+ }
+
+ public static TriviaQuestionFragment newInstance() {
+ return new TriviaQuestionFragment();
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ TriviaQuestion question = ((TriviaGameActivity) getActivity()).getCurrentQuestion();
+ View view;
+
+ if (question instanceof TriviaQuestionMultiple) {
+ view = inflater.inflate(R.layout.fragment_trivia_question_multiple, container, false);
+ ButterKnife.bind(this, view);
+ } else {
+ view = inflater.inflate(R.layout.fragment_trivia_question_boolean, container, false);
+ this.buttonAnswerTrue = view.findViewById(R.id.button_answer_true);
+ this.buttonAnswerFalse = view.findViewById(R.id.button_answer_false);
+ }
+
+ TextView textViewQuestion = view.findViewById(R.id.text_trivia_question);
+ textViewQuestion.setText(question.getQuestion());
+ setupButtons();
+
+ return view;
+ }
+
+ private void setupButtons() {
+ AnswerButtonListener listener = new AnswerButtonListener();
+ TriviaQuestion question = ((TriviaGameActivity) getActivity()).getCurrentQuestion();
+
+ if (question instanceof TriviaQuestionMultiple) {
+ List answers = Arrays.asList((
+ (TriviaQuestionMultiple) question).getAnswerList());
+ Collections.shuffle(answers);
+
+ for (int i = 0; i < buttonAnswers.length; i++) {
+ buttonAnswers[i].setText(answers.get(i));
+ buttonAnswers[i].setOnClickListener(listener);
+ if (question.checkAnswer(answers.get(i))) {
+ buttonAnswerCorrect = buttonAnswers[i];
+ }
+ }
+ } else {
+ buttonAnswerTrue.setOnClickListener(listener);
+ buttonAnswerFalse.setOnClickListener(listener);
+ }
+ }
+
+ private void disableButtons() {
+ TriviaQuestion question = ((TriviaGameActivity) getActivity()).getCurrentQuestion();
+ if (question instanceof TriviaQuestionMultiple) {
+ buttonAnswers[0].setEnabled(false);
+ buttonAnswers[1].setEnabled(false);
+ buttonAnswers[2].setEnabled(false);
+ buttonAnswers[3].setEnabled(false);
+ } else {
+ buttonAnswerTrue.setEnabled(false);
+ buttonAnswerFalse.setEnabled(false);
+ }
+ }
+
+ private class AnswerButtonListener implements View.OnClickListener {
+ @Override
+ public void onClick(View v) {
+ disableButtons();
+ ((TriviaGameActivity) getActivity()).onAnswerClick((Button) v, buttonAnswerCorrect);
+ }
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/interfaces/IDownloadTriviaQuestionReceiver.java b/app/src/main/java/com/luca0n/joguitos/pluck/interfaces/IDownloadTriviaQuestionReceiver.java
new file mode 100644
index 0000000..1b60d12
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/interfaces/IDownloadTriviaQuestionReceiver.java
@@ -0,0 +1,28 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.interfaces;
+
+public interface IDownloadTriviaQuestionReceiver {
+ void onTriviaQuestionsDownloaded(String json);
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/settings/SettingsActivity.java b/app/src/main/java/com/luca0n/joguitos/pluck/settings/SettingsActivity.java
new file mode 100644
index 0000000..5cc8c8a
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/settings/SettingsActivity.java
@@ -0,0 +1,60 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.settings;
+
+import android.os.Bundle;
+import android.view.MenuItem;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AppCompatActivity;
+
+public class SettingsActivity extends AppCompatActivity {
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setTitle(null);
+ }
+
+ getFragmentManager()
+ .beginTransaction()
+ .replace(android.R.id.content, new SettingsFragment())
+ .commit();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/settings/SettingsFragment.java b/app/src/main/java/com/luca0n/joguitos/pluck/settings/SettingsFragment.java
new file mode 100644
index 0000000..6c23564
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/settings/SettingsFragment.java
@@ -0,0 +1,38 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.settings;
+
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+
+import androidx.annotation.Nullable;
+import com.luca0n.joguitos.pluck.R;
+
+public class SettingsFragment extends PreferenceFragment {
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.preferences);
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaCategory.java b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaCategory.java
new file mode 100644
index 0000000..c1b2ce3
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaCategory.java
@@ -0,0 +1,125 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.trivia;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.luca0n.joguitos.pluck.PluckApplication;
+import com.luca0n.joguitos.pluck.R;
+
+/*
+ Categories that a Trivia Question can fall into
+ */
+public enum TriviaCategory {
+ ANY(-1, "Any", R.string.ui_any),
+
+ GENERAL_KNOWLEDGE(9, "General Knowledge",
+ R.string.category_general_knowledge),
+ ENTERTAINMENT_BOOKS(10, "Entertainment: Books",
+ R.string.category_entertainment_books),
+ ENTERTAINMENT_FILM(11, "Entertainment: Film",
+ R.string.category_entertainment_film),
+ ENTERTAINMENT_MUSIC(12, "Entertainment: Music",
+ R.string.category_entertainment_music),
+ ENTERTAINMENT_MUSICALS_THEATRES(13, "Entertainment: Musicals & Theatres",
+ R.string.category_entertainment_musicals_theatres),
+ ENTERTAINMENT_TELEVISION(14, "Entertainment: Television",
+ R.string.category_entertainment_television),
+ ENTERTAINMENT_VIDEO_GAMES(15, "Entertainment: Video Games",
+ R.string.category_entertainment_video_games),
+ ENTERTAINMENT_BOARD_GAMES(16, "Entertainment: Board Games",
+ R.string.category_entertainment_board_games),
+ ENTERTAINMENT_JAPANESE_ANIME_MANGA(31, "Entertainment: Japanese Anime & Manga",
+ R.string.category_entertainment_japanese_anime_manga),
+ ENTERTAINMENT_CARTOON_ANIMATIONS(32, "Entertainment: Cartoons & Animation",
+ R.string.category_entertainment_cartoon_animations),
+ ENTERTAINMENT_COMICS(29, "Entertainment: Comics",
+ R.string.category_entertainment_comics),
+ SCIENCE_NATURE(17, "Science & Nature",
+ R.string.category_science_nature),
+ SCIENCE_COMPUTERS(18, "Science: Computers",
+ R.string.category_science_computers),
+ SCIENCE_MATHEMATICS(19, "Science: Mathematics",
+ R.string.category_science_mathematics),
+ SCIENCE_GADGETS(30, "Science: Gadgets",
+ R.string.category_science_gadgets),
+ MYTHOLOGY(20, "Mythology",
+ R.string.category_mythology),
+ SPORTS(21, "Sports",
+ R.string.category_sports),
+ GEOGRAPHY(22, "Geography",
+ R.string.category_geography),
+ HISTORY(23, "History",
+ R.string.category_history),
+ POLITICS(24, "Politics",
+ R.string.category_politics),
+ ART(25, "Art",
+ R.string.category_art),
+ CELEBRITIES(26, "Celebrities",
+ R.string.category_celebrities),
+ ANIMALS(27, "Animals",
+ R.string.category_animals),
+ VEHICLES(28, "Vehicles",
+ R.string.category_vehicles);
+
+ // The id of the category in the opentdb api
+ // see
+ private final int ID;
+ // The name of the category in the JSON response
+ private final String name;
+ // The display name of the category
+ private final int displayName;
+
+ private static final Map lookup = new HashMap<>();
+
+ static {
+ for (TriviaCategory category : TriviaCategory.values()) {
+ lookup.put(category.getName(), category);
+ }
+ }
+
+ TriviaCategory(int ID, String name, int displayName) {
+ this.ID = ID;
+ this.name = name;
+ this.displayName = displayName;
+ }
+
+ public int getID() {
+ return this.ID;
+ }
+
+ private String getName() {
+ return this.name;
+ }
+
+ public static TriviaCategory get(String name) {
+ return lookup.get(name);
+ }
+
+ @Override
+ public String toString() {
+ return PluckApplication.getAppContext().getResources().getString(this.displayName);
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaDifficulty.java b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaDifficulty.java
new file mode 100644
index 0000000..38339aa
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaDifficulty.java
@@ -0,0 +1,69 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.trivia;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.luca0n.joguitos.pluck.PluckApplication;
+import com.luca0n.joguitos.pluck.R;
+
+public enum TriviaDifficulty {
+ ANY("any", R.string.ui_any),
+
+ EASY("easy", R.string.difficulty_easy),
+ MEDIUM("medium", R.string.difficulty_medium),
+ HARD("hard", R.string.difficulty_hard);
+
+ // Name of difficulty used in queries
+ private final String name;
+ // Display name of the difficulty
+ private final int displayName;
+
+ private static final Map lookup = new HashMap<>();
+
+ static {
+ for (TriviaDifficulty difficulty : TriviaDifficulty.values()) {
+ lookup.put(difficulty.getName(), difficulty);
+ }
+ }
+
+ TriviaDifficulty(String name, int displayName) {
+ this.name = name;
+ this.displayName = displayName;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public static TriviaDifficulty get(String name) {
+ return lookup.get(name);
+ }
+
+ @Override
+ public String toString() {
+ return PluckApplication.getAppContext().getResources().getString(this.displayName);
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaGame.java b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaGame.java
new file mode 100644
index 0000000..c9fbbf0
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaGame.java
@@ -0,0 +1,69 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.trivia;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class TriviaGame implements Serializable {
+ private int currentQuestion;
+ private final boolean[] results;
+ private final List questions;
+
+ public TriviaGame(List questions) {
+ this.currentQuestion = 0;
+ this.questions = questions;
+ this.results = new boolean[questions.size()];
+ }
+
+ public TriviaQuestion getCurrentQuestion() {
+ return this.questions.get(currentQuestion);
+ }
+
+ public int getQuestionProgress() {
+ return this.currentQuestion + 1;
+ }
+
+ public int getQuestionsCount() {
+ return this.questions.size();
+ }
+
+ public boolean[] getResults() {
+ return this.results;
+ }
+
+ public boolean nextQuestion(String guess) {
+ TriviaQuestion question = getCurrentQuestion();
+ boolean answer = question.checkAnswer(guess);
+
+ results[currentQuestion] = answer;
+ currentQuestion++;
+
+ return answer;
+ }
+
+ public boolean isDone() {
+ return (this.currentQuestion == questions.size());
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuery.java b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuery.java
new file mode 100644
index 0000000..e1261bd
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuery.java
@@ -0,0 +1,101 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.trivia;
+
+import java.io.Serializable;
+
+public class TriviaQuery implements Serializable {
+ private static final String BASE = "https://opentdb.com/api.php?";
+ private static final int DEFAULT_AMOUNT = 10;
+
+ private final int amount;
+ private final TriviaCategory category;
+ private final TriviaDifficulty difficulty;
+ private final TriviaType type;
+
+ private TriviaQuery(Builder builder) {
+ this.amount = builder.amount;
+ this.category = builder.category;
+ this.difficulty = builder.difficulty;
+ this.type = builder.type;
+ }
+
+ public static class Builder {
+ private final int amount;
+ private TriviaCategory category;
+ private TriviaDifficulty difficulty;
+ private TriviaType type;
+
+ public Builder() {
+ this.amount = DEFAULT_AMOUNT;
+ }
+
+ public Builder(int amount) {
+ if (amount > 50) {
+ this.amount = 50;
+ } else {
+ this.amount = amount;
+ }
+ }
+
+ public Builder category(TriviaCategory category) {
+ this.category = category;
+ return this;
+ }
+
+ public Builder difficulty(TriviaDifficulty difficulty) {
+ this.difficulty = difficulty;
+ return this;
+ }
+
+ public Builder type(TriviaType type) {
+ this.type = type;
+ return this;
+ }
+
+ public TriviaQuery build() {
+ return new TriviaQuery(this);
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder url = new StringBuilder();
+
+ url.append(BASE);
+ url.append("amount=").append(this.amount);
+
+ if (this.category != null & this.category != TriviaCategory.ANY) {
+ url.append("&category=").append(this.category.getID());
+ }
+ if (this.difficulty != null & this.difficulty != TriviaDifficulty.ANY) {
+ url.append("&difficulty=").append(this.difficulty.getName());
+ }
+ if (this.type != null & this.type != TriviaType.ANY) {
+ url.append("&type=").append(this.type.getName());
+ }
+
+ return url.toString();
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuestion.java b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuestion.java
new file mode 100644
index 0000000..ef4ad52
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuestion.java
@@ -0,0 +1,54 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.trivia;
+
+import java.io.Serializable;
+
+public abstract class TriviaQuestion implements Serializable {
+ private final TriviaCategory category;
+ private final TriviaDifficulty difficulty;
+
+ private final String question;
+
+ TriviaQuestion(TriviaCategory category, TriviaDifficulty difficulty, String question) {
+ this.category = category;
+ this.difficulty = difficulty;
+
+ this.question = question;
+ }
+
+ public TriviaCategory getCategory() {
+ return this.category;
+ }
+
+ public TriviaDifficulty getDifficulty() {
+ return this.difficulty;
+ }
+
+ public String getQuestion() {
+ return this.question;
+ }
+
+ public abstract boolean checkAnswer(String guess);
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuestionBoolean.java b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuestionBoolean.java
new file mode 100644
index 0000000..d7c232f
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuestionBoolean.java
@@ -0,0 +1,57 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.trivia;
+
+import android.text.Html;
+
+import com.google.gson.JsonObject;
+
+public class TriviaQuestionBoolean extends TriviaQuestion {
+
+ private final Boolean correctAnswer;
+
+ public TriviaQuestionBoolean(TriviaCategory category, TriviaDifficulty difficulty,
+ String question, boolean correctAnswer) {
+ super(category, difficulty, question);
+ this.correctAnswer = correctAnswer;
+ }
+
+ @Override
+ public boolean checkAnswer(String guess) {
+ return this.correctAnswer.equals(Boolean.valueOf(guess));
+ }
+
+ public boolean checkAnswer(Boolean guess) {
+ return checkAnswer(guess.toString());
+ }
+
+ public static TriviaQuestionBoolean fromJson(JsonObject json) {
+ TriviaCategory category = TriviaCategory.get(json.get("category").getAsString());
+ TriviaDifficulty difficulty = TriviaDifficulty.get(json.get("difficulty").getAsString());
+ String question = Html.fromHtml(json.get("question").getAsString()).toString();
+ Boolean correctAnswer = json.get("correct_answer").getAsBoolean();
+
+ return new TriviaQuestionBoolean(category, difficulty, question, correctAnswer);
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuestionMultiple.java b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuestionMultiple.java
new file mode 100644
index 0000000..29468e2
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaQuestionMultiple.java
@@ -0,0 +1,71 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.trivia;
+
+import android.text.Html;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+
+public class TriviaQuestionMultiple extends TriviaQuestion {
+ private final String correctAnswer;
+ private final String[] incorrectAnswers;
+
+ public TriviaQuestionMultiple(TriviaCategory category, TriviaDifficulty difficulty,
+ String question, String correctAnswer, String[] incorrectAnswers) {
+ super(category, difficulty, question);
+
+ this.correctAnswer = correctAnswer;
+ this.incorrectAnswers = incorrectAnswers;
+ }
+
+ public String[] getAnswerList() {
+ return new String[]{correctAnswer,
+ incorrectAnswers[0],
+ incorrectAnswers[1],
+ incorrectAnswers[2]};
+ }
+
+ @Override
+ public boolean checkAnswer(String guess) {
+ return this.correctAnswer.equals(guess);
+ }
+
+ public static TriviaQuestionMultiple fromJson(JsonObject json) {
+ TriviaCategory category = TriviaCategory.get(json.get("category").getAsString());
+ TriviaDifficulty difficulty = TriviaDifficulty.get(json.get("difficulty").getAsString());
+ String question = Html.fromHtml(json.get("question").getAsString()).toString();
+ String correctAnswer = Html.fromHtml(json.get("correct_answer").getAsString()).toString();
+
+ JsonArray incorrectAnswersJson = json.get("incorrect_answers").getAsJsonArray();
+ String[] incorrectAnswers = new String[]{
+ Html.fromHtml(incorrectAnswersJson.get(0).getAsString()).toString(),
+ Html.fromHtml(incorrectAnswersJson.get(1).getAsString()).toString(),
+ Html.fromHtml(incorrectAnswersJson.get(2).getAsString()).toString()
+ };
+
+ return new TriviaQuestionMultiple(
+ category, difficulty, question, correctAnswer, incorrectAnswers);
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaType.java b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaType.java
new file mode 100644
index 0000000..7840174
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/trivia/TriviaType.java
@@ -0,0 +1,68 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.trivia;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.luca0n.joguitos.pluck.PluckApplication;
+import com.luca0n.joguitos.pluck.R;
+
+public enum TriviaType {
+ ANY("any", R.string.ui_any),
+
+ MULTIPLE("multiple", R.string.question_type_multiple),
+ BOOLEAN("boolean", R.string.question_type_boolean);
+
+ // Name of type used in queries
+ private final String name;
+ // Display name of the type
+ private final int displayName;
+
+ private static final Map lookup = new HashMap<>();
+
+ static {
+ for (TriviaType type : TriviaType.values()) {
+ lookup.put(type.getName(), type);
+ }
+ }
+
+ TriviaType(String name, int displayName) {
+ this.name = name;
+ this.displayName = displayName;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public static TriviaType get(String name) {
+ return lookup.get(name);
+ }
+
+ @Override
+ public String toString() {
+ return PluckApplication.getAppContext().getResources().getString(this.displayName);
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/util/ApiUtil.java b/app/src/main/java/com/luca0n/joguitos/pluck/util/ApiUtil.java
new file mode 100644
index 0000000..1d6c8ce
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/util/ApiUtil.java
@@ -0,0 +1,105 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.util;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+
+import com.luca0n.joguitos.pluck.exceptions.NoTriviaResultsException;
+import com.luca0n.joguitos.pluck.trivia.TriviaQuery;
+import com.luca0n.joguitos.pluck.trivia.TriviaQuestion;
+import com.luca0n.joguitos.pluck.trivia.TriviaQuestionBoolean;
+import com.luca0n.joguitos.pluck.trivia.TriviaQuestionMultiple;
+import com.luca0n.joguitos.pluck.trivia.TriviaType;
+
+public class ApiUtil {
+
+ private static String readStream(InputStream in) throws IOException {
+ StringBuilder builder = new StringBuilder();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in), 1000);
+
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ builder.append(line);
+ }
+
+ in.close();
+ return builder.toString();
+ }
+
+ private static String GET(String query) throws IOException {
+ String response;
+
+ URL url = new URL(query);
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+ try {
+ InputStream in = new BufferedInputStream(connection.getInputStream());
+ response = readStream(in);
+ } finally {
+ connection.disconnect();
+ }
+
+ return response;
+ }
+
+ public static String GET(TriviaQuery query) throws IOException {
+ return GET(query.toString());
+ }
+
+ public static ArrayList jsonToQuestionArray(String json) throws NoTriviaResultsException {
+ JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
+
+ if (jsonObject.get("response_code").getAsInt() == 1) {
+ throw new NoTriviaResultsException();
+ }
+
+ JsonArray jsonArray = jsonObject.getAsJsonArray("results");
+
+ ArrayList questions = new ArrayList<>();
+
+ for (JsonElement element : jsonArray) {
+ JsonObject object = element.getAsJsonObject();
+ TriviaType type = TriviaType.get(object.get("type").getAsString());
+
+ if (type == TriviaType.MULTIPLE) {
+ questions.add(TriviaQuestionMultiple.fromJson(object));
+ } else {
+ questions.add(TriviaQuestionBoolean.fromJson(object));
+ }
+ }
+
+ return questions;
+ }
+}
diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/util/SoundUtil.java b/app/src/main/java/com/luca0n/joguitos/pluck/util/SoundUtil.java
new file mode 100644
index 0000000..c31bae2
--- /dev/null
+++ b/app/src/main/java/com/luca0n/joguitos/pluck/util/SoundUtil.java
@@ -0,0 +1,48 @@
+/*
+Pluck: an open source trivia game for Android
+
+Copyright (C) 2021 Joguitos do luca0N!
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+
+This game is a fork of LibreTrivia, and its source code is available at
+.
+
+Contact us at .
+*/
+
+package com.luca0n.joguitos.pluck.util;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.media.MediaPlayer;
+import android.preference.PreferenceManager;
+
+import com.luca0n.joguitos.pluck.R;
+
+public class SoundUtil {
+ public static final int SOUND_ANSWER_CORRECT = R.raw.sound_answer_correct;
+ public static final int SOUND_ANSWER_WRONG = R.raw.sound_answer_wrong;
+
+ public static void playSound(Context context, int sound) {
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ String key_sound = context.getResources().getString(R.string.pref_sound_answer);
+ boolean pref_sound = preferences.getBoolean(key_sound, true);
+
+ if (pref_sound) {
+ final MediaPlayer player = MediaPlayer.create(context, sound);
+ player.setVolume(0.25f, 0.25f);
+ player.start();
+ }
+ }
+}
diff --git a/app/src/main/java/com/luca0n/pluck/PluckApplication.java b/app/src/main/java/com/luca0n/pluck/PluckApplication.java
new file mode 100644
index 0000000..17c2051
--- /dev/null
+++ b/app/src/main/java/com/luca0n/pluck/PluckApplication.java
@@ -0,0 +1,38 @@
+/*
+
+
+Copyright (C)
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see .
+ */
+package com.luca0n.pluck;
+
+import android.annotation.SuppressLint;
+import android.app.Application;
+import android.content.Context;
+
+
+public class PluckApplication extends Application {
+ @SuppressLint("StaticFieldLeak")
+ private static Context context;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ PluckApplication.context = getApplicationContext();
+ }
+
+ public static Context getAppContext() {
+ return PluckApplication.context;
+ }
+}
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/BaseActivity.java b/app/src/main/java/com/luca0n/pluck/activities/BaseActivity.java
similarity index 90%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/BaseActivity.java
rename to app/src/main/java/com/luca0n/pluck/activities/BaseActivity.java
index 23a88e3..1f240fe 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/BaseActivity.java
+++ b/app/src/main/java/com/luca0n/pluck/activities/BaseActivity.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.activities;
+package com.luca0n.pluck.activities;
import android.annotation.SuppressLint;
import android.content.Intent;
@@ -10,8 +10,8 @@ import com.mikepenz.aboutlibraries.Libs;
import com.mikepenz.aboutlibraries.LibsBuilder;
import androidx.appcompat.app.AppCompatActivity;
-import io.github.trytonvanmeer.libretrivia.R;
-import io.github.trytonvanmeer.libretrivia.settings.SettingsActivity;
+import com.luca0n.pluck.R;
+import com.luca0n.pluck.settings.SettingsActivity;
@SuppressLint("Registered")
public class BaseActivity extends AppCompatActivity {
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/MainActivity.java b/app/src/main/java/com/luca0n/pluck/activities/MainActivity.java
similarity index 87%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/MainActivity.java
rename to app/src/main/java/com/luca0n/pluck/activities/MainActivity.java
index b93a71b..7b87a71 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/MainActivity.java
+++ b/app/src/main/java/com/luca0n/pluck/activities/MainActivity.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.activities;
+package com.luca0n.pluck.activities;
import android.content.Intent;
import android.os.Bundle;
@@ -8,10 +8,10 @@ import android.widget.Spinner;
import butterknife.BindView;
import butterknife.ButterKnife;
-import io.github.trytonvanmeer.libretrivia.R;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaCategory;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaDifficulty;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaQuery;
+import com.luca0n.pluck.R;
+import com.luca0n.pluck.trivia.TriviaCategory;
+import com.luca0n.pluck.trivia.TriviaDifficulty;
+import com.luca0n.pluck.trivia.TriviaQuery;
public class MainActivity extends BaseActivity {
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/TriviaGameActivity.java b/app/src/main/java/com/luca0n/pluck/activities/TriviaGameActivity.java
similarity index 91%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/TriviaGameActivity.java
rename to app/src/main/java/com/luca0n/pluck/activities/TriviaGameActivity.java
index 779b792..981047c 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/TriviaGameActivity.java
+++ b/app/src/main/java/com/luca0n/pluck/activities/TriviaGameActivity.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.activities;
+package com.luca0n.pluck.activities;
import android.app.AlertDialog;
import android.content.Intent;
@@ -21,16 +21,16 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import butterknife.BindView;
import butterknife.ButterKnife;
-import io.github.trytonvanmeer.libretrivia.R;
-import io.github.trytonvanmeer.libretrivia.exceptions.NoTriviaResultsException;
-import io.github.trytonvanmeer.libretrivia.fragments.TriviaGameErrorFragment;
-import io.github.trytonvanmeer.libretrivia.fragments.TriviaQuestionFragment;
-import io.github.trytonvanmeer.libretrivia.interfaces.IDownloadTriviaQuestionReceiver;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaGame;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaQuery;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaQuestion;
-import io.github.trytonvanmeer.libretrivia.util.ApiUtil;
-import io.github.trytonvanmeer.libretrivia.util.SoundUtil;
+import com.luca0n.pluck.R;
+import com.luca0n.pluck.exceptions.NoTriviaResultsException;
+import com.luca0n.pluck.fragments.TriviaGameErrorFragment;
+import com.luca0n.pluck.fragments.TriviaQuestionFragment;
+import com.luca0n.pluck.interfaces.IDownloadTriviaQuestionReceiver;
+import com.luca0n.pluck.trivia.TriviaGame;
+import com.luca0n.pluck.trivia.TriviaQuery;
+import com.luca0n.pluck.trivia.TriviaQuestion;
+import com.luca0n.pluck.util.ApiUtil;
+import com.luca0n.pluck.util.SoundUtil;
public class TriviaGameActivity extends BaseActivity
implements IDownloadTriviaQuestionReceiver {
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/TriviaGameResultsActivity.java b/app/src/main/java/com/luca0n/pluck/activities/TriviaGameResultsActivity.java
similarity index 89%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/TriviaGameResultsActivity.java
rename to app/src/main/java/com/luca0n/pluck/activities/TriviaGameResultsActivity.java
index 6f33c18..cb2be57 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/activities/TriviaGameResultsActivity.java
+++ b/app/src/main/java/com/luca0n/pluck/activities/TriviaGameResultsActivity.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.activities;
+package com.luca0n.pluck.activities;
import android.os.Bundle;
import android.widget.Button;
@@ -6,8 +6,8 @@ import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
-import io.github.trytonvanmeer.libretrivia.R;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaGame;
+import com.luca0n.pluck.R;
+import com.luca0n.pluck.trivia.TriviaGame;
public class TriviaGameResultsActivity extends BaseActivity {
static final String EXTRA_TRIVIA_GAME = "extra_trivia_game";
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/exceptions/NoTriviaResultsException.java b/app/src/main/java/com/luca0n/pluck/exceptions/NoTriviaResultsException.java
similarity index 52%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/exceptions/NoTriviaResultsException.java
rename to app/src/main/java/com/luca0n/pluck/exceptions/NoTriviaResultsException.java
index 58dafff..4445249 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/exceptions/NoTriviaResultsException.java
+++ b/app/src/main/java/com/luca0n/pluck/exceptions/NoTriviaResultsException.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.exceptions;
+package com.luca0n.pluck.exceptions;
public class NoTriviaResultsException extends Exception {
}
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/fragments/TriviaGameErrorFragment.java b/app/src/main/java/com/luca0n/pluck/fragments/TriviaGameErrorFragment.java
similarity index 92%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/fragments/TriviaGameErrorFragment.java
rename to app/src/main/java/com/luca0n/pluck/fragments/TriviaGameErrorFragment.java
index 036c9ec..8573aa8 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/fragments/TriviaGameErrorFragment.java
+++ b/app/src/main/java/com/luca0n/pluck/fragments/TriviaGameErrorFragment.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.fragments;
+package com.luca0n.pluck.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -10,7 +10,7 @@ import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import butterknife.BindView;
import butterknife.ButterKnife;
-import io.github.trytonvanmeer.libretrivia.R;
+import com.luca0n.pluck.R;
public class TriviaGameErrorFragment extends Fragment {
private final static String ARG_ERROR_MSG = "arg_error_msg";
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/fragments/TriviaQuestionFragment.java b/app/src/main/java/com/luca0n/pluck/fragments/TriviaQuestionFragment.java
similarity index 92%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/fragments/TriviaQuestionFragment.java
rename to app/src/main/java/com/luca0n/pluck/fragments/TriviaQuestionFragment.java
index 470c364..36d1fcc 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/fragments/TriviaQuestionFragment.java
+++ b/app/src/main/java/com/luca0n/pluck/fragments/TriviaQuestionFragment.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.fragments;
+package com.luca0n.pluck.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -16,10 +16,10 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import butterknife.BindViews;
import butterknife.ButterKnife;
-import io.github.trytonvanmeer.libretrivia.R;
-import io.github.trytonvanmeer.libretrivia.activities.TriviaGameActivity;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaQuestion;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaQuestionMultiple;
+import com.luca0n.pluck.R;
+import com.luca0n.pluck.activities.TriviaGameActivity;
+import com.luca0n.pluck.trivia.TriviaQuestion;
+import com.luca0n.pluck.trivia.TriviaQuestionMultiple;
public class TriviaQuestionFragment extends Fragment {
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/interfaces/IDownloadTriviaQuestionReceiver.java b/app/src/main/java/com/luca0n/pluck/interfaces/IDownloadTriviaQuestionReceiver.java
similarity index 65%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/interfaces/IDownloadTriviaQuestionReceiver.java
rename to app/src/main/java/com/luca0n/pluck/interfaces/IDownloadTriviaQuestionReceiver.java
index 4be0ee9..2d75269 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/interfaces/IDownloadTriviaQuestionReceiver.java
+++ b/app/src/main/java/com/luca0n/pluck/interfaces/IDownloadTriviaQuestionReceiver.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.interfaces;
+package com.luca0n.pluck.interfaces;
public interface IDownloadTriviaQuestionReceiver {
void onTriviaQuestionsDownloaded(String json);
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/settings/SettingsActivity.java b/app/src/main/java/com/luca0n/pluck/settings/SettingsActivity.java
similarity index 95%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/settings/SettingsActivity.java
rename to app/src/main/java/com/luca0n/pluck/settings/SettingsActivity.java
index fff1083..1ebd730 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/settings/SettingsActivity.java
+++ b/app/src/main/java/com/luca0n/pluck/settings/SettingsActivity.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.settings;
+package com.luca0n.pluck.settings;
import android.os.Bundle;
import android.view.MenuItem;
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/settings/SettingsFragment.java b/app/src/main/java/com/luca0n/pluck/settings/SettingsFragment.java
similarity index 78%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/settings/SettingsFragment.java
rename to app/src/main/java/com/luca0n/pluck/settings/SettingsFragment.java
index fa04ca5..539dd23 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/settings/SettingsFragment.java
+++ b/app/src/main/java/com/luca0n/pluck/settings/SettingsFragment.java
@@ -1,10 +1,10 @@
-package io.github.trytonvanmeer.libretrivia.settings;
+package com.luca0n.pluck.settings;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import androidx.annotation.Nullable;
-import io.github.trytonvanmeer.libretrivia.R;
+import com.luca0n.pluck.R;
public class SettingsFragment extends PreferenceFragment {
@Override
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaCategory.java b/app/src/main/java/com/luca0n/pluck/trivia/TriviaCategory.java
similarity index 92%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaCategory.java
rename to app/src/main/java/com/luca0n/pluck/trivia/TriviaCategory.java
index 65003de..a473fdb 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaCategory.java
+++ b/app/src/main/java/com/luca0n/pluck/trivia/TriviaCategory.java
@@ -1,10 +1,10 @@
-package io.github.trytonvanmeer.libretrivia.trivia;
+package com.luca0n.pluck.trivia;
import java.util.HashMap;
import java.util.Map;
-import io.github.trytonvanmeer.libretrivia.LibreTriviaApplication;
-import io.github.trytonvanmeer.libretrivia.R;
+import com.luca0n.pluck.PluckApplication;
+import com.luca0n.pluck.R;
/*
Categories that a Trivia Question can fall into
@@ -97,6 +97,6 @@ public enum TriviaCategory {
@Override
public String toString() {
- return LibreTriviaApplication.getAppContext().getResources().getString(this.displayName);
+ return PluckApplication.getAppContext().getResources().getString(this.displayName);
}
}
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaDifficulty.java b/app/src/main/java/com/luca0n/pluck/trivia/TriviaDifficulty.java
similarity index 78%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaDifficulty.java
rename to app/src/main/java/com/luca0n/pluck/trivia/TriviaDifficulty.java
index b2c4084..5f3d770 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaDifficulty.java
+++ b/app/src/main/java/com/luca0n/pluck/trivia/TriviaDifficulty.java
@@ -1,10 +1,10 @@
-package io.github.trytonvanmeer.libretrivia.trivia;
+package com.luca0n.pluck.trivia;
import java.util.HashMap;
import java.util.Map;
-import io.github.trytonvanmeer.libretrivia.LibreTriviaApplication;
-import io.github.trytonvanmeer.libretrivia.R;
+import com.luca0n.pluck.PluckApplication;
+import com.luca0n.pluck.R;
public enum TriviaDifficulty {
ANY("any", R.string.ui_any),
@@ -41,6 +41,6 @@ public enum TriviaDifficulty {
@Override
public String toString() {
- return LibreTriviaApplication.getAppContext().getResources().getString(this.displayName);
+ return PluckApplication.getAppContext().getResources().getString(this.displayName);
}
}
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaGame.java b/app/src/main/java/com/luca0n/pluck/trivia/TriviaGame.java
similarity index 95%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaGame.java
rename to app/src/main/java/com/luca0n/pluck/trivia/TriviaGame.java
index f69f78b..ad36ce0 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaGame.java
+++ b/app/src/main/java/com/luca0n/pluck/trivia/TriviaGame.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.trivia;
+package com.luca0n.pluck.trivia;
import java.io.Serializable;
import java.util.List;
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuery.java b/app/src/main/java/com/luca0n/pluck/trivia/TriviaQuery.java
similarity index 97%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuery.java
rename to app/src/main/java/com/luca0n/pluck/trivia/TriviaQuery.java
index fed6828..b78b8b8 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuery.java
+++ b/app/src/main/java/com/luca0n/pluck/trivia/TriviaQuery.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.trivia;
+package com.luca0n.pluck.trivia;
import java.io.Serializable;
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuestion.java b/app/src/main/java/com/luca0n/pluck/trivia/TriviaQuestion.java
similarity index 93%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuestion.java
rename to app/src/main/java/com/luca0n/pluck/trivia/TriviaQuestion.java
index b708006..904cf09 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuestion.java
+++ b/app/src/main/java/com/luca0n/pluck/trivia/TriviaQuestion.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.trivia;
+package com.luca0n.pluck.trivia;
import java.io.Serializable;
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuestionBoolean.java b/app/src/main/java/com/luca0n/pluck/trivia/TriviaQuestionBoolean.java
similarity index 95%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuestionBoolean.java
rename to app/src/main/java/com/luca0n/pluck/trivia/TriviaQuestionBoolean.java
index 6a70516..f6a0f9c 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuestionBoolean.java
+++ b/app/src/main/java/com/luca0n/pluck/trivia/TriviaQuestionBoolean.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.trivia;
+package com.luca0n.pluck.trivia;
import android.text.Html;
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuestionMultiple.java b/app/src/main/java/com/luca0n/pluck/trivia/TriviaQuestionMultiple.java
similarity index 97%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuestionMultiple.java
rename to app/src/main/java/com/luca0n/pluck/trivia/TriviaQuestionMultiple.java
index 7674790..2ecd158 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaQuestionMultiple.java
+++ b/app/src/main/java/com/luca0n/pluck/trivia/TriviaQuestionMultiple.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.trivia;
+package com.luca0n.pluck.trivia;
import android.text.Html;
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaType.java b/app/src/main/java/com/luca0n/pluck/trivia/TriviaType.java
similarity index 77%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaType.java
rename to app/src/main/java/com/luca0n/pluck/trivia/TriviaType.java
index 8f8f76f..4aa49d3 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/trivia/TriviaType.java
+++ b/app/src/main/java/com/luca0n/pluck/trivia/TriviaType.java
@@ -1,10 +1,10 @@
-package io.github.trytonvanmeer.libretrivia.trivia;
+package com.luca0n.pluck.trivia;
import java.util.HashMap;
import java.util.Map;
-import io.github.trytonvanmeer.libretrivia.LibreTriviaApplication;
-import io.github.trytonvanmeer.libretrivia.R;
+import com.luca0n.pluck.PluckApplication;
+import com.luca0n.pluck.R;
public enum TriviaType {
ANY("any", R.string.ui_any),
@@ -40,6 +40,6 @@ public enum TriviaType {
@Override
public String toString() {
- return LibreTriviaApplication.getAppContext().getResources().getString(this.displayName);
+ return PluckApplication.getAppContext().getResources().getString(this.displayName);
}
}
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/util/ApiUtil.java b/app/src/main/java/com/luca0n/pluck/util/ApiUtil.java
similarity index 82%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/util/ApiUtil.java
rename to app/src/main/java/com/luca0n/pluck/util/ApiUtil.java
index a6e4374..86bf3fc 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/util/ApiUtil.java
+++ b/app/src/main/java/com/luca0n/pluck/util/ApiUtil.java
@@ -1,4 +1,4 @@
-package io.github.trytonvanmeer.libretrivia.util;
+package com.luca0n.pluck.util;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
@@ -14,12 +14,12 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
-import io.github.trytonvanmeer.libretrivia.exceptions.NoTriviaResultsException;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaQuery;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaQuestion;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaQuestionBoolean;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaQuestionMultiple;
-import io.github.trytonvanmeer.libretrivia.trivia.TriviaType;
+import com.luca0n.pluck.exceptions.NoTriviaResultsException;
+import com.luca0n.pluck.trivia.TriviaQuery;
+import com.luca0n.pluck.trivia.TriviaQuestion;
+import com.luca0n.pluck.trivia.TriviaQuestionBoolean;
+import com.luca0n.pluck.trivia.TriviaQuestionMultiple;
+import com.luca0n.pluck.trivia.TriviaType;
public class ApiUtil {
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/util/SoundUtil.java b/app/src/main/java/com/luca0n/pluck/util/SoundUtil.java
similarity index 89%
rename from app/src/main/java/io/github/trytonvanmeer/libretrivia/util/SoundUtil.java
rename to app/src/main/java/com/luca0n/pluck/util/SoundUtil.java
index 07e393f..042e784 100644
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/util/SoundUtil.java
+++ b/app/src/main/java/com/luca0n/pluck/util/SoundUtil.java
@@ -1,11 +1,11 @@
-package io.github.trytonvanmeer.libretrivia.util;
+package com.luca0n.pluck.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.preference.PreferenceManager;
-import io.github.trytonvanmeer.libretrivia.R;
+import com.luca0n.pluck.R;
public class SoundUtil {
public static final int SOUND_ANSWER_CORRECT = R.raw.sound_answer_correct;
diff --git a/app/src/main/java/io/github/trytonvanmeer/libretrivia/LibreTriviaApplication.java b/app/src/main/java/io/github/trytonvanmeer/libretrivia/LibreTriviaApplication.java
deleted file mode 100644
index 02f6085..0000000
--- a/app/src/main/java/io/github/trytonvanmeer/libretrivia/LibreTriviaApplication.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package io.github.trytonvanmeer.libretrivia;
-
-import android.annotation.SuppressLint;
-import android.app.Application;
-import android.content.Context;
-
-
-public class LibreTriviaApplication extends Application {
- @SuppressLint("StaticFieldLeak")
- private static Context context;
-
- @Override
- public void onCreate() {
- super.onCreate();
- LibreTriviaApplication.context = getApplicationContext();
- }
-
- public static Context getAppContext() {
- return LibreTriviaApplication.context;
- }
-}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 20db57f..83ed3eb 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,4 +1,27 @@
+
+
+
+
-
\ No newline at end of file
+
diff --git a/app/src/main/res/layout/activity_trivia_game_results.xml b/app/src/main/res/layout/activity_trivia_game_results.xml
index 1806161..0d774c0 100644
--- a/app/src/main/res/layout/activity_trivia_game_results.xml
+++ b/app/src/main/res/layout/activity_trivia_game_results.xml
@@ -1,4 +1,27 @@
+
+
-
\ No newline at end of file
+
diff --git a/app/src/main/res/layout/fragment_trivia_game_error.xml b/app/src/main/res/layout/fragment_trivia_game_error.xml
index e82fcdd..ee5dfbe 100644
--- a/app/src/main/res/layout/fragment_trivia_game_error.xml
+++ b/app/src/main/res/layout/fragment_trivia_game_error.xml
@@ -1,3 +1,27 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
+
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 1ec3d4c..0e2f27a 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -1,3 +1,26 @@
+
+
Ein Open-Source-Trivia-Spiel
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 8f88c0e..cde2a67 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,4 +1,27 @@
+
+
#F44336
#D32F2F
diff --git a/app/src/main/res/values/pref_keys.xml b/app/src/main/res/values/pref_keys.xml
index 776c47b..c41bef4 100644
--- a/app/src/main/res/values/pref_keys.xml
+++ b/app/src/main/res/values/pref_keys.xml
@@ -1,4 +1,28 @@
+
+
+
pref_key_category_sound
pref_sound_answer
-
\ No newline at end of file
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 59ccd25..1b0b814 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,5 +1,29 @@
+
+
+
- LibreTrivia
+ Pluck
An open source trivia game.
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 247a02d..cefde13 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -1,3 +1,27 @@
+
+
+
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index 00975f9..70f0942 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -1,4 +1,27 @@
+
+
-
\ No newline at end of file
+
diff --git a/build.gradle b/build.gradle
index d6e9c47..a047bbd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,7 +8,7 @@ buildscript {
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.2.1'
+ classpath 'com.android.tools.build:gradle:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index d76b502..442d913 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists