-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
122 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ package com.xwilarg.yousei | |
|
||
enum class LearningType { | ||
HIRAGANA, | ||
KANJI | ||
KANJI, | ||
VOCABULARY | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.xwilarg.yousei | ||
|
||
data class VocabularyInfo ( | ||
val word: String, | ||
val meaning: Array<String>, | ||
val reading: String | ||
) |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/com/xwilarg/yousei/VocabularyLearning.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.xwilarg.yousei; | ||
|
||
import com.google.gson.Gson | ||
import kotlin.random.Random | ||
|
||
class VocabularyLearning : ILearning { | ||
|
||
constructor(content: String) { | ||
words = Gson().fromJson(content, Array<VocabularyInfo>::class.java) | ||
} | ||
|
||
override fun getQuestion() : Pair<String, String> { | ||
currentWord = words[Random.nextInt(0, words.size)] | ||
return Pair(currentWord.word, currentWord.reading) | ||
} | ||
|
||
override fun checkAnswer(myAnswer: String) : Pair<IsCorrect, String> { | ||
var isCorrect = false | ||
var closestAnswer : String? = null | ||
if (!myAnswer.isNullOrBlank()) { | ||
for (m in currentWord .meaning) { | ||
if (myAnswer == m) { | ||
return Pair(IsCorrect.YES, m) | ||
} | ||
if (closestAnswer == null && (myAnswer.contains(m) || m.contains(myAnswer))) { | ||
closestAnswer = m | ||
} | ||
} | ||
} | ||
if (closestAnswer != null) { | ||
return Pair(IsCorrect.PARTIAL, closestAnswer) | ||
} | ||
return Pair(IsCorrect.NO, currentWord.meaning[0]) | ||
} | ||
|
||
override fun getCurrent(): String { | ||
return currentWord.word | ||
} | ||
|
||
override fun getRandomChoices(): ArrayList<String> { | ||
var choices = arrayListOf<String>() | ||
choices.add(currentWord.meaning[0]) | ||
while (choices.size < 4) { | ||
var randomChoice = words[Random.nextInt(0, words.size)].meaning[0] | ||
if (!choices.contains(randomChoice)) { | ||
choices.add(randomChoice) | ||
} | ||
} | ||
choices.shuffle() | ||
return choices | ||
} | ||
|
||
lateinit var words: Array<VocabularyInfo> | ||
lateinit var currentWord: VocabularyInfo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.