Commit 0c67e41d by Paktalin

Refactoring. Generalized Vocabularies with Vocabulary interface

parent 977460e3
......@@ -25,7 +25,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -82,7 +82,7 @@ class MainActivity : AppCompatActivity() {
private fun setUpVocabularyAdapter() {
addProgressBar(supportFragmentManager, R.id.container_main)
FirestoreManager().extractVocabularyId({
// recyclerView.adapter = VocabularyAdapter(Vocabulary(), this@MainActivity)
// recyclerView.adapter = VocabularyAdapter(BasicVocabulary(), this@MainActivity)
recyclerView.layoutManager = LockableLayoutManager(this@MainActivity)
FirestoreManager().extractVocabulary { querySnapshot ->
run {
......
package com.paktalin.vocabularynotebook.vocabulary
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
open class BasicVocabulary(var wordList: MutableList<WordItem>): Vocabulary {
override fun addAll(words: MutableList<WordItem>) {
wordList.addAll(words)
}
override fun deleteWord(wordItem: WordItem) {
wordList.remove(wordItem)
}
override fun addWord(newWord: WordItem) {
wordList.add(0, newWord)
}
override fun updateWord(updatedWord: WordItem) {
wordList[wordList.indexOf(updatedWord)] = updatedWord
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ package com.paktalin.vocabularynotebook.vocabulary
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
class DisplayedVocabulary(override var wordList: MutableList<WordItem>): Vocabulary(wordList) {
class DisplayedVocabulary(wordList: MutableList<WordItem>): BasicVocabulary(wordList) {
var sort: Sort = Sort.BY_TIME
fun clear() {
......
......@@ -4,8 +4,8 @@ import com.paktalin.vocabularynotebook.firestoreitems.ModifiedLabel
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.utils.FirestoreManager
class ModifiedVocabulary : Vocabulary() {
override var wordList = mutableListOf<WordItem>()
class ModifiedVocabulary : Vocabulary {
var wordList = mutableListOf<WordItem>()
private val maxPermitted = 9
override fun addWord(newWord: WordItem) {
......@@ -22,7 +22,6 @@ class ModifiedVocabulary : Vocabulary() {
override fun addAll(words: MutableList<WordItem>) { }
fun add(wordItem: WordItem, modifiedLabel: ModifiedLabel) {
wordItem.modifiedLabel = modifiedLabel
wordList.add(wordItem)
......
......@@ -5,12 +5,11 @@ import com.google.firebase.firestore.QueryDocumentSnapshot
import com.google.firebase.firestore.QuerySnapshot
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
class VocabSet(override var wordList: MutableList<WordItem>) : Vocabulary() {
class VocabSet(var wordList: MutableList<WordItem>) : Vocabulary {
var fullVocabulary = Vocabulary(wordList)
var fullVocabulary = BasicVocabulary(wordList)
private var displayedVocabulary = DisplayedVocabulary(wordList)
var modifiedVocabulary = ModifiedVocabulary()
private val vocabs = setOf(fullVocabulary, displayedVocabulary, modifiedVocabulary)
companion object {
fun createFromSnapshot(querySnapshot: QuerySnapshot): VocabSet {
......@@ -29,19 +28,23 @@ class VocabSet(override var wordList: MutableList<WordItem>) : Vocabulary() {
}
override fun addAll(words: MutableList<WordItem>) {
vocabs.forEach { v -> v.addAll(words) }
listOf(fullVocabulary, displayedVocabulary, modifiedVocabulary)
.forEach { v -> v.addAll(words) }
}
override fun updateWord(updatedWord: WordItem) {
vocabs.forEach { v -> v.updateWord(updatedWord) }
listOf(fullVocabulary, displayedVocabulary, modifiedVocabulary)
.forEach { v -> v.updateWord(updatedWord) }
}
override fun deleteWord(wordItem: WordItem) {
vocabs.forEach { v -> v.deleteWord(wordItem) }
listOf(fullVocabulary, displayedVocabulary, modifiedVocabulary)
.forEach { v -> v.deleteWord(wordItem) }
}
override fun addWord(newWord: WordItem) {
vocabs.forEach { v -> v.addWord(newWord) }
listOf(fullVocabulary, displayedVocabulary, modifiedVocabulary)
.forEach { v -> v.addWord(newWord) }
}
fun sort(sort: Sort) {
......
......@@ -2,26 +2,13 @@ package com.paktalin.vocabularynotebook.vocabulary
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
open class Vocabulary() {
open lateinit var wordList: MutableList<WordItem>
interface Vocabulary {
constructor(wordList: MutableList<WordItem>): this() {
this.wordList = wordList
}
fun addAll(words: MutableList<WordItem>)
open fun addAll(words: MutableList<WordItem>) {
wordList.addAll(words)
}
fun deleteWord(wordItem: WordItem)
open fun deleteWord(wordItem: WordItem) {
wordList.remove(wordItem)
}
fun addWord(newWord: WordItem)
open fun addWord(newWord: WordItem) {
wordList.add(0, newWord)
}
open fun updateWord(updatedWord: WordItem) {
wordList[wordList.indexOf(updatedWord)] = updatedWord
}
fun updateWord(updatedWord: WordItem)
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment