add all the things

This commit is contained in:
Wyatt J. Miller 2021-11-16 22:04:40 -05:00
commit 1c659c995a
68 changed files with 2679 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx

View File

@ -0,0 +1,138 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

22
.idea/gradle.xml Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$USER_HOME$/.sdkman/candidates/gradle/current" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

25
.idea/jarRepositories.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>

9
.idea/misc.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

1
app/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

45
app/build.gradle Normal file
View File

@ -0,0 +1,45 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.wyattjmiller.studyhelper"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.android.volley:volley:1.1.1'
implementation 'androidx.room:room-runtime:2.2.5'
annotationProcessor 'androidx.room:room-compiler:2.2.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

21
app/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,24 @@
package com.wyattjmiller.studyhelper
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.wyattjmiller.studyhelper", appContext.packageName)
}
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wyattjmiller.studyhelper">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".ImportActivity"
android:label="Import"
android:parentActivityName=".SubjectActivity"/>
<activity
android:name=".SettingsActivity"
android:label="@string/settings"
android:parentActivityName=".SubjectActivity" />
<activity
android:name=".QuestionEditActivity"
android:parentActivityName=".QuestionActivity" />
<activity
android:name=".QuestionActivity"
android:launchMode="singleTop"
android:parentActivityName=".SubjectActivity" />
<activity android:name=".SubjectActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,99 @@
package com.wyattjmiller.studyhelper;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.VolleyError;
import java.util.List;
public class ImportActivity extends AppCompatActivity {
private LinearLayout mSubjectLayoutContainer;
private StudyFetcher mStudyFetcher;
private ProgressBar mLoadingProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_import);
mSubjectLayoutContainer = findViewById(R.id.subjectLayout);
// Show progress bar
mLoadingProgressBar = findViewById(R.id.loadingProgressBar);
mLoadingProgressBar.setVisibility(View.VISIBLE);
mStudyFetcher = new StudyFetcher(this);
mStudyFetcher.fetchSubjects(mFetchListener);
}
private StudyFetcher.OnStudyDataReceivedListener mFetchListener = new StudyFetcher.OnStudyDataReceivedListener() {
@Override
public void onSubjectsReceived(List<Subject> subjects) {
// Hide progress bar
mLoadingProgressBar.setVisibility(View.GONE);
// Create a checkbox for each subject
for (Subject subject: subjects) {
CheckBox checkBox = new CheckBox(getApplicationContext());
checkBox.setTextSize(24);
checkBox.setText(subject.getText());
checkBox.setTag(subject);
mSubjectLayoutContainer.addView(checkBox);
}
}
@Override
public void onQuestionsReceived(List<Question> questions) {
if (questions.size() > 0) {
StudyDatabase studyDb = StudyDatabase.getInstance(getApplicationContext());
// Add the questions to the database
for (Question question : questions) {
studyDb.addQuestion(question);
}
String subject = questions.get(0).getSubject();
Toast.makeText(getApplicationContext(), subject + " imported successfully",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "Error loading subjects. Try again later.",
Toast.LENGTH_LONG).show();
mLoadingProgressBar.setVisibility(View.GONE);
Log.d("RESP", error.toString());
}
};
public void importButtonClick(View view) {
StudyDatabase dbHelper = StudyDatabase.getInstance(getApplicationContext());
// Determine which subjects were selected
int numCheckBoxes = mSubjectLayoutContainer.getChildCount();
for (int i = 0; i < numCheckBoxes; i++) {
CheckBox checkBox = (CheckBox) mSubjectLayoutContainer.getChildAt(i);
if (checkBox.isChecked()) {
Subject subject = (Subject) checkBox.getTag();
// Add subject to the database
if (dbHelper.addSubject(subject)) {
mStudyFetcher.fetchQuestions(subject, mFetchListener);
} else {
Toast.makeText(this, subject.getText() + " is already imported.",
Toast.LENGTH_SHORT).show();
}
}
}
}
}

View File

@ -0,0 +1,30 @@
package com.wyattjmiller.studyhelper
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
@Entity(
tableName = "questions",
foreignKeys = [ForeignKey(
entity = Subject::class,
parentColumns = ["text"],
childColumns = ["subject"]
)]
)
class Question {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
var id: Long = 0
@ColumnInfo(name = "text")
var text: String? = null
@ColumnInfo(name = "answer")
var answer: String? = null
@ColumnInfo(name = "subject")
var subject: String? = null
}

View File

@ -0,0 +1,240 @@
package com.wyattjmiller.studyhelper
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
open class QuestionActivity : AppCompatActivity() {
private lateinit var mStudyDb: StudyDatabase
private lateinit var mSubject: String
private lateinit var mQuestionList: MutableList<Question>
private lateinit var mAnswerLabel: TextView
private lateinit var mAnswerText: TextView
private lateinit var mAnswerButton: Button
private lateinit var mQuestionText: TextView
private lateinit var mShowQuestionsLayout: ViewGroup
private lateinit var mNoQuestionsLayout: ViewGroup
private lateinit var mDeletedQuestion: Question
private var mCurrentQuestionIndex = 0
private val REQUEST_CODE_NEW_QUESTION = 0
private val REQUEST_CODE_UPDATE_QUESTION = 1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_question)
// Hosting activity provides the subject of the questions to display
val intent = intent
mSubject = intent.getStringExtra(EXTRA_SUBJECT)
// Load all questions for this subject
mStudyDb = StudyDatabase.getInstance(applicationContext)
mQuestionList = mStudyDb.getQuestions(mSubject)
mQuestionText = findViewById(R.id.questionText)
mAnswerLabel = findViewById(R.id.answerLabel)
mAnswerText = findViewById(R.id.answerText)
mAnswerButton = findViewById(R.id.answerButton)
mShowQuestionsLayout = findViewById(R.id.showQuestionsLayout)
mNoQuestionsLayout = findViewById(R.id.noQuestionsLayout)
// Show first question
showQuestion(0)
}
override fun onStart() {
super.onStart()
// Are there questions to display?
if (mQuestionList!!.size == 0) {
updateAppBarTitle()
displayQuestion(false)
} else {
displayQuestion(true)
toggleAnswerVisibility()
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate menu for the app bar
val inflater = menuInflater
inflater.inflate(R.menu.question_menu, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Determine which app bar item was chosen
return when (item.itemId) {
R.id.previous -> {
showQuestion(mCurrentQuestionIndex - 1)
true
}
R.id.next -> {
showQuestion(mCurrentQuestionIndex + 1)
true
}
R.id.add -> {
addQuestion()
true
}
R.id.edit -> {
editQuestion()
true
}
R.id.delete -> {
deleteQuestion()
true
}
else -> super.onOptionsItemSelected(item)
}
}
fun addQuestionButtonClick(view: View?) {
addQuestion()
}
fun answerButtonClick(view: View?) {
toggleAnswerVisibility()
}
private fun displayQuestion(display: Boolean) {
// Show or hide the appropriate screen
if (display) {
mShowQuestionsLayout!!.visibility = View.VISIBLE
mNoQuestionsLayout!!.visibility = View.GONE
} else {
mShowQuestionsLayout!!.visibility = View.GONE
mNoQuestionsLayout!!.visibility = View.VISIBLE
}
}
private fun updateAppBarTitle() {
// Display subject and number of questions in app bar
val actionBar = supportActionBar
if (actionBar != null) {
val title = resources.getString(
R.string.question_number,
mSubject, mCurrentQuestionIndex + 1, mQuestionList!!.size
)
setTitle(title)
}
}
private fun addQuestion() {
val intent = Intent(this, QuestionEditActivity::class.java)
intent.putExtra(QuestionEditActivity.EXTRA_SUBJECT, mSubject)
startActivityForResult(intent, REQUEST_CODE_NEW_QUESTION)
}
private fun editQuestion() {
if (mCurrentQuestionIndex >= 0) {
val intent = Intent(this, QuestionEditActivity::class.java)
intent.putExtra(Intent.EXTRA_SUBJECT, mSubject)
val questionId = mQuestionList[mCurrentQuestionIndex].id
intent.putExtra(QuestionEditActivity.EXTRA_QUESTION_ID, questionId)
startActivityForResult(intent, REQUEST_CODE_UPDATE_QUESTION)
}
}
private fun deleteQuestion() {
mDeletedQuestion = mQuestionList[mCurrentQuestionIndex]
mStudyDb.deleteQuestion(mDeletedQuestion.id)
if (mCurrentQuestionIndex >= 0) {
val questionId = mQuestionList[mCurrentQuestionIndex].id
mStudyDb.deleteQuestion(questionId)
mQuestionList.removeAt(mCurrentQuestionIndex)
if (mQuestionList.size == 0) {
// No questions left to show
mCurrentQuestionIndex = -1
updateAppBarTitle()
displayQuestion(false)
} else {
showQuestion(mCurrentQuestionIndex)
}
val snackbar = Snackbar.make(findViewById(R.id.coordinatorLayout), R.string.question_deleted, Snackbar.LENGTH_LONG)
snackbar.setAction(R.string.undo) {
mStudyDb.addQuestion(mDeletedQuestion)
mQuestionList.add(mDeletedQuestion)
showQuestion(mQuestionList.size - 1)
displayQuestion(true)
}
snackbar.show()
}
}
private fun showQuestion(questionIndex: Int) {
// Show question at the given index
var questionIndex = questionIndex
if (mQuestionList!!.size > 0) {
if (questionIndex < 0) {
questionIndex = mQuestionList!!.size - 1
} else if (questionIndex >= mQuestionList!!.size) {
questionIndex = 0
}
mCurrentQuestionIndex = questionIndex
updateAppBarTitle()
val question = mQuestionList!![mCurrentQuestionIndex]
mQuestionText!!.text = question.text
mAnswerText!!.text = question.answer
} else {
// No questions yet
mCurrentQuestionIndex = -1
}
}
private fun toggleAnswerVisibility() {
if (mAnswerText!!.visibility == View.VISIBLE) {
mAnswerButton!!.setText(R.string.show_answer)
mAnswerText!!.visibility = View.INVISIBLE
mAnswerLabel!!.visibility = View.INVISIBLE
} else {
mAnswerButton!!.setText(R.string.hide_answer)
mAnswerText!!.visibility = View.VISIBLE
mAnswerLabel!!.visibility = View.VISIBLE
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_NEW_QUESTION) {
// Get added question
val questionId = data!!.getLongExtra(QuestionEditActivity.EXTRA_QUESTION_ID, -1)
val newQuestion = mStudyDb.getQuestion(questionId)
// Add newly created question to the question list and show it
mQuestionList.add(newQuestion)
showQuestion(mQuestionList.size - 1)
Toast.makeText(this, R.string.question_added, Toast.LENGTH_SHORT).show()
} else if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_UPDATE_QUESTION) {
// Get updated question
val questionId = data!!.getLongExtra(QuestionEditActivity.EXTRA_QUESTION_ID, -1)
val updatedQuestion = mStudyDb.getQuestion(questionId)
// Replace current question in question list with updated question
val currentQuestion = mQuestionList[mCurrentQuestionIndex]
currentQuestion.text = updatedQuestion.text
currentQuestion.answer = updatedQuestion.answer
showQuestion(mCurrentQuestionIndex)
Toast.makeText(this, R.string.question_updated, Toast.LENGTH_SHORT).show()
}
}
companion object {
const val EXTRA_SUBJECT = "com.wyattjmiller.studyhelper.subject"
}
}

View File

@ -0,0 +1,21 @@
package com.wyattjmiller.studyhelper
import androidx.room.*
@Dao
interface QuestionDao {
@Query("SELECT * FROM questions WHERE id = :id")
fun getQuestion(id: Long): Question?
@Query("SELECT * FROM questions WHERE subject = :subject")
fun getQuestions(subject: String?): List<Question?>?
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertQuestion(question: Question?): Long
@Update
fun updateQuestion(question: Question?)
@Delete
fun deleteQuestion(question: Question?)
}

View File

@ -0,0 +1,66 @@
package com.wyattjmiller.studyhelper
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
class QuestionEditActivity : AppCompatActivity() {
private lateinit var mQuestionText: EditText
private lateinit var mAnswerText: EditText
private lateinit var mStudyDb: StudyDatabase
private lateinit var mQuestion: Question
private var mQuestionId: Long = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_question_edit)
mQuestionText = findViewById(R.id.questionText)
mAnswerText = findViewById(R.id.answerText)
mStudyDb = StudyDatabase.getInstance(applicationContext)
// Get question ID from QuestionActivity
val intent = intent
mQuestionId = intent.getLongExtra(EXTRA_QUESTION_ID, -1)
val actionBar = supportActionBar
if (mQuestionId == -1L) {
// Add new question
mQuestion = Question()
setTitle(R.string.add_question)
} else {
// Update existing question
mQuestion = mStudyDb.getQuestion(mQuestionId)
mQuestionText.setText(mQuestion.text)
mAnswerText.setText(mQuestion.answer)
setTitle(R.string.update_question)
}
val subject = intent.getStringExtra(EXTRA_SUBJECT)
mQuestion!!.subject = subject
}
fun saveButtonClick(view: View?) {
mQuestion!!.text = mQuestionText!!.text.toString()
mQuestion!!.answer = mAnswerText!!.text.toString()
if (mQuestionId == -1L) {
// New question
mStudyDb!!.addQuestion(mQuestion)
} else {
// Existing question
mStudyDb!!.updateQuestion(mQuestion)
}
// Send back question ID
val intent = Intent()
intent.putExtra(EXTRA_QUESTION_ID, mQuestion!!.id)
setResult(RESULT_OK, intent)
finish()
}
companion object {
const val EXTRA_QUESTION_ID = "com.zybooks.studyhelper.question_id"
const val EXTRA_SUBJECT = "com.zybooks.studyhelper.subject"
}
}

View File

@ -0,0 +1,11 @@
package com.wyattjmiller.studyhelper
import com.android.volley.VolleyError
interface ReceivedListener {
interface OnStudyDataReceivedListener {
fun onSubjectsReceived(subjects: List<Subject>?)
fun onQuestionsReceived(questions: List<Question>?)
fun onErrorResponse(error: VolleyError?)
}
}

View File

@ -0,0 +1,17 @@
package com.wyattjmiller.studyhelper;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
}

View File

@ -0,0 +1,50 @@
package com.wyattjmiller.studyhelper;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
public class SettingsFragment extends PreferenceFragment {
public static String PREFERENCE_THEME = "pref_theme";
public static String PREFERENCE_SUBJECT_ORDER = "pref_subject_order";
public static String PREFERENCE_DEFAULT_QUESTION = "pref_default_question";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
// Access the default shared prefs
SharedPreferences sharedPrefs =
PreferenceManager.getDefaultSharedPreferences(getActivity());
setPrefSummarySubjectOrder(sharedPrefs);
setPrefSummaryDefaultQuestion(sharedPrefs);
}
// Set the summary to the currently selected subject order
private void setPrefSummarySubjectOrder(SharedPreferences sharedPrefs) {
String order = sharedPrefs.getString(PREFERENCE_SUBJECT_ORDER, "1");
String[] subjectOrders = getResources().getStringArray(R.array.pref_subject_order);
Preference subjectOrderPref = findPreference(PREFERENCE_SUBJECT_ORDER);
subjectOrderPref.setSummary(subjectOrders[Integer.parseInt(order)]);
}
// Set the summary to the default question
private void setPrefSummaryDefaultQuestion(SharedPreferences sharedPrefs) {
String defaultQuestion = sharedPrefs.getString(PREFERENCE_DEFAULT_QUESTION, "");
defaultQuestion = defaultQuestion.trim();
Preference questionPref = findPreference(PREFERENCE_DEFAULT_QUESTION);
if (defaultQuestion.length() == 0) {
questionPref.setSummary(getResources().getString(R.string.pref_none));
}
else {
questionPref.setSummary(defaultQuestion);
}
}
}

View File

@ -0,0 +1,229 @@
package com.wyattjmiller.studyhelper;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Build;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
public class StudyDatabase extends SQLiteOpenHelper {
private static final int VERSION = 1;
private static final String DATABASE_NAME = "study.db";
private static StudyDatabase mStudyDb;
public enum SubjectSortOrder { ALPHABETIC, UPDATE_DESC, UPDATE_ASC };
public static StudyDatabase getInstance(Context context) {
if (mStudyDb == null) {
mStudyDb = new StudyDatabase(context);
}
return mStudyDb;
}
private StudyDatabase(Context context) {
super(context, DATABASE_NAME, null, VERSION);
}
private static final class SubjectTable {
private static final String TABLE = "subjects";
private static final String COL_TEXT = "text";
private static final String COL_UPDATE_TIME = "updated";
}
private static final class QuestionTable {
private static final String TABLE = "questions";
private static final String COL_ID = "_id";
private static final String COL_TEXT = "text";
private static final String COL_ANSWER = "answer";
private static final String COL_SUBJECT = "subject";
}
@Override
public void onCreate(SQLiteDatabase db) {
// Create subjects table
db.execSQL("create table " + SubjectTable.TABLE + " (" +
SubjectTable.COL_TEXT + " primary key, " +
SubjectTable.COL_UPDATE_TIME + " int)");
// Create questions table with foreign key that cascade deletes
db.execSQL("create table " + QuestionTable.TABLE + " (" +
QuestionTable.COL_ID + " integer primary key autoincrement, " +
QuestionTable.COL_TEXT + ", " +
QuestionTable.COL_ANSWER + ", " +
QuestionTable.COL_SUBJECT + ", " +
"foreign key(" + QuestionTable.COL_SUBJECT + ") references " +
SubjectTable.TABLE + "(" + SubjectTable.COL_TEXT + ") on delete cascade)");
// Add some subjects
String[] subjects = { "History", "Math", "Computing" };
for (String sub: subjects) {
Subject subject = new Subject(sub);
ContentValues values = new ContentValues();
values.put(SubjectTable.COL_TEXT, subject.getText());
values.put(SubjectTable.COL_UPDATE_TIME, subject.getUpdateTime());
db.insert(SubjectTable.TABLE, null, values);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists " + SubjectTable.TABLE);
db.execSQL("drop table if exists " + QuestionTable.TABLE);
onCreate(db);
}
@Override
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
if (!db.isReadOnly()) {
// Enable foreign key constraints
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
db.execSQL("pragma foreign_keys = on;");
} else {
db.setForeignKeyConstraintsEnabled(true);
}
}
}
public List<Subject> getSubjects(SubjectSortOrder order) {
List<Subject> subjects = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
String orderBy;
switch (order) {
case ALPHABETIC:
orderBy = SubjectTable.COL_TEXT + " collate nocase";
break;
case UPDATE_DESC:
orderBy = SubjectTable.COL_UPDATE_TIME + " desc";
break;
default:
orderBy = SubjectTable.COL_UPDATE_TIME + " asc";
break;
}
String sql = "select * from " + SubjectTable.TABLE + " order by " + orderBy;
Cursor cursor = db.rawQuery(sql, null);
if (cursor.moveToFirst()) {
do {
Subject subject = new Subject();
subject.setText(cursor.getString(0));
subject.setUpdateTime(cursor.getLong(1));
subjects.add(subject);
} while (cursor.moveToNext());
}
cursor.close();
return subjects;
}
public boolean addSubject(Subject subject) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(SubjectTable.COL_TEXT, subject.getText());
values.put(SubjectTable.COL_UPDATE_TIME, subject.getUpdateTime());
long id = db.insert(SubjectTable.TABLE, null, values);
return id != -1;
}
public void updateSubject(Subject subject) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(SubjectTable.COL_TEXT, subject.getText());
values.put(SubjectTable.COL_UPDATE_TIME, subject.getUpdateTime());
db.update(SubjectTable.TABLE, values,
SubjectTable.COL_TEXT + " = ?", new String[] { subject.getText() });
}
public void deleteSubject(Subject subject) {
SQLiteDatabase db = getWritableDatabase();
db.delete(SubjectTable.TABLE,
SubjectTable.COL_TEXT + " = ?", new String[] { subject.getText() });
}
public List<Question> getQuestions(String subject) {
List<Question> questions = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
String sql = "select * from " + QuestionTable.TABLE +
" where " + QuestionTable.COL_SUBJECT + " = ?";
Cursor cursor = db.rawQuery(sql, new String[] { subject });
if (cursor.moveToFirst()) {
do {
Question question = new Question();
question.setId(cursor.getInt(0));
question.setText(cursor.getString(1));
question.setAnswer(cursor.getString(2));
question.setSubject(cursor.getString(3));
questions.add(question);
} while (cursor.moveToNext());
}
cursor.close();
return questions;
}
public Question getQuestion(long questionId) {
Question question = null;
SQLiteDatabase db = this.getReadableDatabase();
String sql = "select * from " + QuestionTable.TABLE +
" where " + QuestionTable.COL_ID + " = ?";
Cursor cursor = db.rawQuery(sql, new String[] { Float.toString(questionId) });
if (cursor.moveToFirst()) {
question = new Question();
question.setId(cursor.getInt(0));
question.setText(cursor.getString(1));
question.setAnswer(cursor.getString(2));
question.setSubject(cursor.getString(3));
}
return question;
}
public void addQuestion(Question question) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(QuestionTable.COL_TEXT, question.getText());
values.put(QuestionTable.COL_ANSWER, question.getAnswer());
values.put(QuestionTable.COL_SUBJECT, question.getSubject());
long questionId = db.insert(QuestionTable.TABLE, null, values);
question.setId(questionId);
// Change update time in subjects table
updateSubject(new Subject(question.getSubject()));
}
public void updateQuestion(Question question) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(QuestionTable.COL_ID, question.getId());
values.put(QuestionTable.COL_TEXT, question.getText());
values.put(QuestionTable.COL_ANSWER, question.getAnswer());
values.put(QuestionTable.COL_SUBJECT, question.getSubject());
db.update(QuestionTable.TABLE, values,
QuestionTable.COL_ID + " = " + question.getId(), null);
// Change update time in subjects table
updateSubject(new Subject(question.getSubject()));
}
public void deleteQuestion(long questionId) {
SQLiteDatabase db = getWritableDatabase();
db.delete(QuestionTable.TABLE,
QuestionTable.COL_ID + " = " + questionId, null);
}
}

View File

@ -0,0 +1,138 @@
package com.wyattjmiller.studyhelper;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class StudyFetcher {
public interface OnStudyDataReceivedListener {
void onSubjectsReceived(List<Subject> subjects);
void onQuestionsReceived(List<Question> questions);
void onErrorResponse(VolleyError error);
}
private final String WEBAPI_BASE_URL = "https://wp.zybooks.com/study-helper.php";
private final String TAG = "StudyFetcher";
private RequestQueue mRequestQueue;
public StudyFetcher(Context context) {
mRequestQueue = Volley.newRequestQueue(context);
}
public void fetchSubjects(final OnStudyDataReceivedListener listener) {
String url = Uri.parse(WEBAPI_BASE_URL).buildUpon()
.appendQueryParameter("type", "subjects").build().toString();
// Request all subjects
JsonObjectRequest request = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
List<Subject> subjects = parseJsonSubjects(response);
listener.onSubjectsReceived(subjects);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
listener.onErrorResponse(error);
}
});
mRequestQueue.add(request);
}
private List<Subject> parseJsonSubjects(JSONObject json) {
List<Subject> subjects = new ArrayList<Subject>();
// Create a list of subjects
try {
JSONArray subjectArray = json.getJSONArray("subjects");
for (int i = 0; i < subjectArray.length(); i++) {
JSONObject subjectObj = subjectArray.getJSONObject(i);
Subject subject = new Subject();
subject.setText(subjectObj.getString("subject"));
subject.setUpdateTime(subjectObj.getLong("updatetime"));
subjects.add(subject);
}
}
catch(Exception e){
Log.e(TAG, "One or more fields not found in the JSON data");
}
return subjects;
}
public void fetchQuestions(Subject subject, final OnStudyDataReceivedListener listener) {
String url = Uri.parse(WEBAPI_BASE_URL).buildUpon()
.appendQueryParameter("type", "questions")
.appendQueryParameter("subject", subject.getText())
.build().toString();
// Request questions for this subject
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
List<Question> questions = parseJsonQuestions(response);
listener.onQuestionsReceived(questions);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
listener.onErrorResponse(error);
}
});
mRequestQueue.add(jsObjRequest);
}
private List<Question> parseJsonQuestions(JSONObject json) {
List<Question> questions = new ArrayList<Question>();
// Create a list of questions
try {
String subject = json.getString("subject");
JSONArray questionArray = json.getJSONArray("questions");
for (int i = 0; i < questionArray.length(); i++) {
JSONObject questionObj = questionArray.getJSONObject(i);
Question question = new Question();
question.setText(questionObj.getString("question"));
question.setAnswer(questionObj.getString("answer"));
question.setSubject(subject);
questions.add(question);
}
}
catch(Exception e) {
Log.e(TAG, "One or more fields not found in the JSON data");
}
return questions;
}
}

View File

@ -0,0 +1,24 @@
package com.wyattjmiller.studyhelper
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "subjects")
class Subject {
@PrimaryKey
@ColumnInfo(name = "text")
var text = ""
@ColumnInfo(name = "updated")
var updateTime: Long
constructor() {
updateTime = System.currentTimeMillis()
}
constructor(text: String) {
this.text = text
updateTime = System.currentTimeMillis()
}
}

View File

@ -0,0 +1,254 @@
package com.wyattjmiller.studyhelper
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Color
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.*
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
class SubjectActivity : AppCompatActivity(), SubjectDialogFragment.OnSubjectEnteredListener {
private lateinit var mStudyDb: StudyDatabase
private lateinit var mSubjectAdapter: SubjectAdapter
private lateinit var mRecyclerView: RecyclerView
private lateinit var mSubjectColors: IntArray
private lateinit var mSelectedSubject: Subject
private lateinit var mActionMode: ActionMode
private lateinit var mSharedPrefs: SharedPreferences
private var mDarkTheme = false
private var mSelectedSubjectPosition = RecyclerView.NO_POSITION
override fun onCreate(savedInstanceState: Bundle?) {
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mDarkTheme = mSharedPrefs!!.getBoolean(SettingsFragment.PREFERENCE_THEME, false);
if (mDarkTheme) {
setTheme(R.style.DarkTheme);
}
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_subject)
mSubjectColors = resources.getIntArray(R.array.subjectColors)
// Singleton
mStudyDb = StudyDatabase.getInstance(applicationContext)
mRecyclerView = findViewById(R.id.subjectRecyclerView)
// Create 2 grid layout columns
val gridLayoutManager: RecyclerView.LayoutManager = GridLayoutManager(applicationContext, 2)
mRecyclerView.setLayoutManager(gridLayoutManager)
// Shows the available subjects
mSubjectAdapter = SubjectAdapter(loadSubjects())
mRecyclerView.setAdapter(mSubjectAdapter)
}
override fun onResume() {
super.onResume()
// If theme changed, recreate the activity so theme is applied
val darkTheme = mSharedPrefs!!.getBoolean(SettingsFragment.PREFERENCE_THEME, false)
if (darkTheme != mDarkTheme) {
recreate()
}
// Load subjects here in case settings changed
mSubjectAdapter = SubjectAdapter(loadSubjects())
mRecyclerView.adapter = mSubjectAdapter
}
private fun loadSubjects(): MutableList<Subject> {
val order = mSharedPrefs!!.getString(SettingsFragment.PREFERENCE_SUBJECT_ORDER, "1")
return when (order!!.toInt()) {
0 -> mStudyDb.getSubjects(StudyDatabase.SubjectSortOrder.ALPHABETIC)
1 -> mStudyDb.getSubjects(StudyDatabase.SubjectSortOrder.UPDATE_DESC)
else -> mStudyDb.getSubjects(StudyDatabase.SubjectSortOrder.UPDATE_ASC)
}
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
val inflater = menuInflater
inflater.inflate(R.menu.subject_menu, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle item selection
return when (item.itemId) {
R.id.settings -> {
val intent = Intent(this@SubjectActivity, SettingsActivity::class.java)
startActivity(intent)
true
}
R.id.import_questions -> {
val intent = Intent(this@SubjectActivity, ImportActivity::class.java)
startActivity(intent)
true
}
else -> super.onOptionsItemSelected(item)
}
}
override fun onSubjectEntered(subject: String) {
// Returns subject entered in the SubjectDialogFragment dialog
if (subject.isNotEmpty()) {
val sub = Subject(subject)
if (mStudyDb!!.addSubject(sub)) {
mSubjectAdapter.addSubject(sub)
Toast.makeText(this, "Added $subject", Toast.LENGTH_SHORT).show()
} else {
val message = resources.getString(R.string.subject_exists, subject)
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
}
}
fun addSubjectClick(view: View?) {
// Prompt user to type new subject
val manager = supportFragmentManager
val dialog = SubjectDialogFragment()
dialog.show(manager, "subjectDialog")
}
private inner class SubjectHolder(inflater: LayoutInflater, parent: ViewGroup?) : RecyclerView.ViewHolder(inflater.inflate(R.layout.recycler_view_items, parent, false)), View.OnClickListener, View.OnLongClickListener {
private var mSubject: Subject? = null
private val mTextView: TextView
fun bind(subject: Subject, position: Int) {
mSubject = subject
mTextView.text = subject.text
if (mSelectedSubjectPosition == position) {
// Make selected subject stand out
mTextView.setBackgroundColor(Color.RED)
} else {
// Make the background color dependent on the length of the subject string
val colorIndex = subject.text!!.length % mSubjectColors.size
mTextView.setBackgroundColor(mSubjectColors[colorIndex])
}
}
override fun onClick(view: View) {
// Start QuestionActivity, indicating what subject was clicked
val intent = Intent(this@SubjectActivity, QuestionActivity::class.java)
intent.putExtra(QuestionActivity.EXTRA_SUBJECT, mSubject!!.text)
startActivity(intent)
}
override fun onLongClick(view: View?): Boolean {
if (mActionMode != null) {
return false
}
mSelectedSubject = mSubject!!
mSelectedSubjectPosition = adapterPosition
// Re-bind the selected item
mSubjectAdapter.notifyItemChanged(mSelectedSubjectPosition)
// Show the CAB
mActionMode = this@SubjectActivity.startActionMode(mActionModeCallback)!!
return true
}
private val mActionModeCallback: ActionMode.Callback = object : ActionMode.Callback {
override fun onCreateActionMode(mode: ActionMode, menu: Menu?): Boolean {
// Provide context menu for CAB
val inflater = mode.menuInflater
inflater.inflate(R.menu.context_menu, menu)
return true
}
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean {
return false
}
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
// Process action item selection
return when (item.getItemId()) {
R.id.delete -> {
// Delete from the database and remove from the RecyclerView
mStudyDb.deleteSubject(mSelectedSubject)
mSubjectAdapter.removeSubject(mSelectedSubject)
// Close the CAB
mode.finish()
true
}
else -> false
}
}
override fun onDestroyActionMode(mode: ActionMode) {
mActionMode = null
// CAB closing, need to deselect item if not deleted
mSubjectAdapter.notifyItemChanged(mSelectedSubjectPosition)
mSelectedSubjectPosition = RecyclerView.NO_POSITION
}
}
init {
itemView.setOnClickListener(this)
itemView.setOnLongClickListener(this)
mTextView = itemView.findViewById(R.id.subjectTextView)
}
}
private inner class SubjectAdapter(private val mSubjectList: MutableList<Subject>) : RecyclerView.Adapter<SubjectHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubjectHolder {
val layoutInflater = LayoutInflater.from(applicationContext)
return SubjectHolder(layoutInflater, parent)
}
override fun onBindViewHolder(holder: SubjectHolder, position: Int) {
holder.bind(mSubjectList[position], position)
}
override fun getItemCount(): Int {
return mSubjectList.size
}
fun onSubjectEntered(subject: String) {
// Returns subject entered in the SubjectDialogFragment dialog
if (subject.isNotEmpty()) {
val sub = Subject(subject)
if (mStudyDb.addSubject(sub)) {
mSubjectAdapter.addSubject(sub)
// Toast.makeText(this, subject, Toast.LENGTH_SHORT).show()
Toast.makeText(this@SubjectActivity, subject, Toast.LENGTH_LONG).show()
} else {
val message = resources.getString(R.string.subject_exists, subject)
Toast.makeText(this@SubjectActivity, message, Toast.LENGTH_SHORT).show()
}
}
}
fun removeSubject(subject: Subject?) {
// Find subject in the list
val index = mSubjectList.indexOf(subject)
if (index >= 0) {
// Remove the subject
mSubjectList.removeAt(index)
// Notify adapter of subject removal
notifyItemRemoved(index)
}
}
fun addSubject(subject: Subject?) {
// Add the new subject at the beginning of the list
mSubjectList.add(0, subject!!)
// Notify the adapter that item was added to the beginning of the list
notifyItemInserted(0)
// Scroll to the top
mRecyclerView.scrollToPosition(0)
}
}
}

View File

@ -0,0 +1,24 @@
package com.wyattjmiller.studyhelper
import androidx.room.*
@Dao
interface SubjectDao {
@get:Query("SELECT * FROM subjects ORDER BY text")
val subjects: List<Subject?>?
@get:Query("SELECT * FROM subjects ORDER BY updated DESC")
val subjectsNewerFirst: List<Subject?>?
@get:Query("SELECT * FROM subjects ORDER BY updated ASC")
val subjectsOlderFirst: List<Subject?>?
@Insert(onConflict = OnConflictStrategy.FAIL)
fun insertSubject(subject: Subject?)
@Update
fun updateSubject(subject: Subject?)
@Delete
fun deleteSubject(subject: Subject?)
}

View File

@ -0,0 +1,45 @@
package com.wyattjmiller.studyhelper;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.InputType;
import android.widget.EditText;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
public class SubjectDialogFragment extends DialogFragment {
// Host activity must implement
public interface OnSubjectEnteredListener {
void onSubjectEntered(String subject);
}
private OnSubjectEnteredListener mListener;
@Override
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
final EditText subjectEditText = new EditText(getActivity());
subjectEditText.setInputType(InputType.TYPE_CLASS_TEXT);
subjectEditText.setMaxLines(1);
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.subject)
.setView(subjectEditText)
.setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String subject = subjectEditText.getText().toString();
mListener.onSubjectEntered(subject.trim());
}
})
.setNegativeButton(R.string.cancel, null)
.create();
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
mListener = (OnSubjectEnteredListener) context;
}
}

View File

@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
</vector>

View File

@ -0,0 +1,11 @@
<!-- drawable/delete.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>

View File

@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM17,13l-5,5 -5,-5h3V9h4v4h3z"/>
</vector>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"/>
</vector>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
</vector>

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
tools:context=".ImportActivity">
<TextView
android:id="@+id/selectSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select_subject"
android:textSize="30sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ProgressBar
android:id="@+id/loadingProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/selectSubject"
app:layout_constraintBottom_toTopOf="@id/importButton">
<LinearLayout
android:id="@+id/subjectLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Content added dynamically -->
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/importButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/import_questions"
android:onClick="importButtonClick"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/noQuestionsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:context=".QuestionActivity">
<TextView
android:id="@+id/noQuestionLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_questions"
android:textSize="20sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@+id/addQuestionButton" />
<Button
android:id="@+id/addQuestionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_question"
android:onClick="addQuestionButtonClick"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/showQuestionsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
tools:context=".QuestionActivity">
<TextView
android:id="@+id/questionLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/question_label"
style="@style/QALabel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:id="@+id/questionText"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:textSize="30sp"
tools:text="question"
app:layout_constraintTop_toTopOf="@id/questionLabel"
app:layout_constraintBottom_toTopOf="@+id/answerButton"
app:layout_constraintLeft_toRightOf="@id/questionLabel"
app:layout_constraintRight_toRightOf="parent"/>
<Button
android:id="@+id/answerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:text="@string/show_answer"
android:onClick="answerButtonClick"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<TextView
android:id="@+id/answerLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/answer_label"
style="@style/QALabel"
app:layout_constraintTop_toBottomOf="@+id/answerButton"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:id="@+id/answerText"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:textSize="30sp"
tools:text="answer"
app:layout_constraintTop_toTopOf="@id/answerLabel"
app:layout_constraintLeft_toRightOf="@id/answerLabel"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
tools:context=".QuestionEditActivity">
<TextView
android:id="@+id/questionLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/question_label"
android:labelFor="@+id/questionText"
style="@style/QALabel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<EditText
android:id="@+id/questionText"
android:layout_width="0dp"
android:layout_height="0dp"
android:hint="@string/question_hint"
android:importantForAutofill="no"
android:inputType="text"
style="@style/QAEditText"
app:layout_constraintTop_toTopOf="@id/questionLabel"
app:layout_constraintBottom_toTopOf="@+id/answerText"
app:layout_constraintLeft_toRightOf="@id/questionLabel"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/answerLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/answer_label"
android:labelFor="@+id/answerText"
style="@style/QALabel"
app:layout_constraintTop_toTopOf="@+id/answerText"
app:layout_constraintLeft_toLeftOf="parent" />
<EditText
android:id="@+id/answerText"
android:layout_width="0dp"
android:layout_height="0dp"
android:hint="@string/answer_hint"
android:importantForAutofill="no"
android:inputType="text"
style="@style/QAEditText"
app:layout_constraintTop_toBottomOf="@+id/questionText"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/answerLabel"
app:layout_constraintRight_toRightOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="saveButtonClick"
app:srcCompat="@drawable/check"
android:layout_margin="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SettingsActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SubjectActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/subjectRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/addSubjectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="addSubjectClick"
android:layout_gravity="end|bottom"
app:srcCompat="@drawable/add"
android:layout_margin="16dp" />
</FrameLayout>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardview1"
android:layout_width="match_parent"
android:layout_height="150dp"
card_view:cardCornerRadius="5dp"
card_view:cardUseCompatPadding="true">
<TextView
android:id="@+id/subjectTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@color/colorSubject"
android:padding="10dp"
android:layout_gravity="center"
android:gravity="center" />
</androidx.cardview.widget.CardView>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/delete"
android:title="@string/delete"
android:icon="@drawable/delete"
app:showAsAction="ifRoom">
</item>
</menu>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/previous"
android:icon="@drawable/previous"
android:title="@string/previous"
app:showAsAction="ifRoom"/>
<item android:id="@+id/next"
android:icon="@drawable/next"
android:title="@string/next"
app:showAsAction="ifRoom"/>
<item android:id="@+id/add"
android:title="@string/add"
app:showAsAction="never"/>
<item android:id="@+id/edit"
android:title="@string/edit"
app:showAsAction="never"/>
<item android:id="@+id/delete"
android:title="@string/delete"
app:showAsAction="never"/>
</menu>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/settings"
android:icon="@drawable/settings"
android:title="@string/settings"
app:showAsAction="ifRoom"/>
<item android:id="@+id/import_questions"
android:icon="@drawable/import_questions"
android:title="@string/import_questions"
app:showAsAction="ifRoom"/>
</menu>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#0277BD</color>
<color name="colorPrimaryDark">#01579B</color>
<color name="colorAccent">#42A5F5</color>
<color name="colorSubject">#EEEEEE</color>
<!-- Dark theme colors -->
<color name="colorBackgroundDark">#000</color>
<color name="colorAppBar">#023</color>
<color name="colorText">#BBB</color>
<color name="colorTextSecondary">#999</color>
<color name="colorButton">#555</color>
<array name="subjectColors">
<item>#1A237E</item>
<item>#880E4F</item>
<item>#006064</item>
<item>#F57F17</item>
<item>#BF360C</item>
<item>#01579B</item>
<item>#33691E</item>
<item>#4A148C</item>
<item>#B71C1C</item>
</array>
</resources>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Study Helper</string>
<string name="question_label">Q</string>
<string name="question_hint">Question</string>
<string name="answer_label">A</string>
<string name="answer_hint">Answer</string>
<string name="show_answer">Show Answer</string>
<string name="hide_answer">Hide Answer</string>
<string name="previous">Previous</string>
<string name="next">Next</string>
<string name="add">Add</string>
<string name="delete">Delete</string>
<string name="edit">Edit</string>
<string name="update">Update</string>
<string name="question_deleted">Question deleted.</string>
<string name="question_added">Question added.</string>
<string name="question_updated">Question updated.</string>
<string name="create">Create</string>
<string name="subject">New subject?</string>
<string name="cancel">Cancel</string>
<string name="update_question">Update Question</string>
<string name="add_question">Add Question</string>
<string name="no_questions">No questions exist for this subject.</string>
<string name="subject_exists">The subject "%1$s" already exists.</string>
<string name="question_number">%1$s (%2$d of %3$d)</string>
<string name="import_questions">Import</string>
<string name="select_subject">Select a subject:</string>
<string name="undo">Undo</string>
<string name="settings">Settings</string>
<string name="pref_title_theme">Dark theme</string>
<string name="pref_description_theme">Turn on dark theme</string>
<string name="pref_title_default_question">Default question</string>
<string name="pref_title_subject_order">Subject order</string>
<string name="pref_none">None</string>
<string-array name="pref_subject_order">
<item>Alphabetic</item>
<item>Most recent first</item>
<item>Oldest first</item>
</string-array>
<string-array name="pref_subject_order_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>

View File

@ -0,0 +1,32 @@
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Dark theme -->
<style name="DarkTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorAppBar</item>
<item name="colorPrimaryDark">@color/colorBackgroundDark</item>
<item name="colorAccent">@color/colorPrimaryDark</item>
<item name="android:colorBackground">@color/colorBackgroundDark</item>
<item name="android:textColor">@color/colorText</item>
<item name="android:textColorSecondary">@color/colorTextSecondary</item>
<item name="android:editTextColor">@color/colorText</item>
<item name="colorButtonNormal">@color/colorButton</item>
</style>
<style name="QALabel">
<item name="android:textSize">60sp</item>
<item name="android:textColor">@color/colorPrimaryDark</item>
</style>
<style name="QAEditText">
<item name="android:gravity">top</item>
<item name="android:textSize">30sp</item>
<item name="android:layout_marginTop">20dp</item>
<item name="android:layout_marginBottom">20dp</item>
<item name="android:layout_marginLeft">20dp</item>
</style>
</resources>

View File

@ -0,0 +1,26 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
android:defaultValue="false"
android:key="pref_theme"
android:title="@string/pref_title_theme"
android:summary="@string/pref_description_theme" />
<ListPreference
android:defaultValue="1"
android:entries="@array/pref_subject_order"
android:entryValues="@array/pref_subject_order_values"
android:key="pref_subject_order"
android:negativeButtonText="@null"
android:positiveButtonText="@null"
android:title="@string/pref_title_subject_order" />
<EditTextPreference
android:key="pref_default_question"
android:inputType="text"
android:maxLines="1"
android:selectAllOnFocus="true"
android:title="@string/pref_title_default_question" />
</PreferenceScreen>

View File

@ -0,0 +1,17 @@
package com.wyattjmiller.studyhelper
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

26
build.gradle Normal file
View File

@ -0,0 +1,26 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.10"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

21
gradle.properties Normal file
View File

@ -0,0 +1,21 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
#Thu Oct 29 14:21:57 EDT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

172
gradlew vendored Normal file
View File

@ -0,0 +1,172 @@
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

84
gradlew.bat vendored Normal file
View File

@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

2
settings.gradle Normal file
View File

@ -0,0 +1,2 @@
include ':app'
rootProject.name = "StudyHelper"