Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
vocabulary_notebook
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
98806c93
authored
Nov 10, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved fragment logic to ActivityUtil
parent
52b96bce
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
26 additions
and
34 deletions
.idea/misc.xml
app/src/main/java/com/paktalin/vocabularynotebook/ActivityUtil.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
app/src/main/res/layout/notebook_sheet.xml
.idea/misc.xml
View file @
98806c93
...
...
@@ -25,7 +25,7 @@
</value>
</option>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
8
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<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"
>
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ActivityUtil.kt
View file @
98806c93
package
com.paktalin.vocabularynotebook
import
android.content.Context
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v4.app.FragmentManager
import
android.text.TextUtils
...
...
@@ -9,7 +10,8 @@ import com.paktalin.vocabularynotebook.ui.ProgressFragment
val
progressFragment
:
Fragment
=
ProgressFragment
()
fun
addFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
,
containerId
:
Int
)
{
fun
addFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
,
containerId
:
Int
,
arguments
:
Bundle
?)
{
fragment
.
arguments
=
arguments
fragmentManager
.
beginTransaction
().
add
(
containerId
,
fragment
).
commitAllowingStateLoss
()
}
...
...
@@ -18,7 +20,7 @@ fun removeFragment(fragmentManager: FragmentManager, fragment: Fragment) {
}
fun
addProgressBar
(
fragmentManager
:
FragmentManager
,
containerId
:
Int
)
{
addFragment
(
fragmentManager
,
progressFragment
,
containerId
)
addFragment
(
fragmentManager
,
progressFragment
,
containerId
,
null
)
}
fun
removeProgressBar
(
fragmentManager
:
FragmentManager
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
98806c93
...
...
@@ -14,7 +14,7 @@ import com.paktalin.vocabularynotebook.ui.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.MainActivity
import
kotlinx.android.synthetic.main.word_item.view.*
class
VocabularyAdapter
(
private
val
v
ocabulary
:
Vocabulary
,
private
val
mainActivity
:
MainActivity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
class
VocabularyAdapter
(
private
val
displayedV
ocabulary
:
Vocabulary
,
private
val
mainActivity
:
MainActivity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
...
...
@@ -23,10 +23,10 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val mainActi
field
=
value
;
sort
()
}
private
var
words
Copy
:
MutableList
<
WordItem
>
=
mutableListOf
()
// stores all the words loaded from the db
private
var
vocabulary
Copy
:
MutableList
<
WordItem
>
=
mutableListOf
()
// stores all the words loaded from the db
init
{
wordsCopy
.
addAll
(
v
ocabulary
.
get
())
vocabularyCopy
.
addAll
(
displayedV
ocabulary
.
get
())
}
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
...
...
@@ -42,7 +42,7 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val mainActi
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
wordItem
=
v
ocabulary
.
getAt
(
position
)
val
wordItem
=
displayedV
ocabulary
.
getAt
(
position
)
holder
.
tvWord
.
text
=
wordItem
.
pojo
.
word
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
.
translation
holder
.
itemView
.
setOnClickListener
{
showPopupMenu
(
holder
.
itemView
,
position
)
}
...
...
@@ -50,7 +50,7 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val mainActi
}
override
fun
getItemCount
():
Int
{
return
v
ocabulary
.
size
()
return
displayedV
ocabulary
.
size
()
}
private
fun
showPopupMenu
(
v
:
View
,
position
:
Int
)
{
...
...
@@ -59,27 +59,27 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val mainActi
inflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
if
(
it
.
itemId
==
R
.
id
.
option_delete
)
{
deleteWord
(
position
)
}
if
(
it
.
itemId
==
R
.
id
.
option_edit
)
{
editWord
(
v
,
v
ocabulary
.
getAt
(
position
))
}
if
(
it
.
itemId
==
R
.
id
.
option_edit
)
{
editWord
(
v
,
displayedV
ocabulary
.
getAt
(
position
))
}
true
}
popup
.
show
()
}
private
fun
deleteWord
(
position
:
Int
)
{
v
ocabulary
.
deleteWord
(
position
)
displayedV
ocabulary
.
deleteWord
(
position
)
// update recyclerView
recyclerView
.
removeViewAt
(
position
)
this
.
notifyItemRemoved
(
position
)
this
.
notifyItemRangeChanged
(
position
,
v
ocabulary
.
size
())
this
.
notifyItemRangeChanged
(
position
,
displayedV
ocabulary
.
size
())
}
fun
addWord
(
newWord
:
WordItem
)
{
v
ocabulary
.
addWord
(
newWord
)
displayedV
ocabulary
.
addWord
(
newWord
)
this
.
sort
()
}
fun
updateWord
(
updatedWord
:
WordItem
)
{
v
ocabulary
.
updateWord
(
updatedWord
)
displayedV
ocabulary
.
updateWord
(
updatedWord
)
this
.
sort
()
}
...
...
@@ -89,7 +89,7 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val mainActi
}
private
fun
sort
()
{
v
ocabulary
.
sort
(
sortOrder
)
displayedV
ocabulary
.
sort
(
sortOrder
)
this
.
notifyDataSetChanged
()
}
...
...
@@ -101,11 +101,9 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val mainActi
}
else
container
.
id
=
18071999
// start EditWordFragment
val
editWordFragment
=
EditWordFragment
()
val
arguments
=
Bundle
()
arguments
.
putSerializable
(
"wordItem"
,
wordItem
)
editWordFragment
.
arguments
=
arguments
mainActivity
.
supportFragmentManager
.
beginTransaction
().
add
(
container
.
id
,
editWordFragment
).
commit
()
addFragment
(
mainActivity
.
supportFragmentManager
,
EditWordFragment
(),
container
.
id
,
arguments
)
}
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
...
...
@@ -115,11 +113,11 @@ class VocabularyAdapter(private val vocabulary: Vocabulary, private val mainActi
}
fun
filter
(
query
:
String
)
{
v
ocabulary
.
clear
()
displayedV
ocabulary
.
clear
()
if
(
query
.
isEmpty
())
vocabulary
.
addWords
(
words
Copy
)
displayedVocabulary
.
addWords
(
vocabulary
Copy
)
else
vocabulary
.
addWordsFittingQuery
(
words
Copy
,
query
.
toLowerCase
())
displayedVocabulary
.
addWordsFittingQuery
(
vocabulary
Copy
,
query
.
toLowerCase
())
notifyDataSetChanged
()
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
View file @
98806c93
...
...
@@ -33,7 +33,6 @@ class AddWordFragment : WordFragment() {
mainActivity
.
vocabularyFragment
.
addWord
(
wordItem
)
}
override
fun
updateButtons
()
{
super
.
updateButtons
()
if
(!
wordEmpty
||
!
translationEmpty
)
showClearButton
()
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
View file @
98806c93
...
...
@@ -12,6 +12,7 @@ import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import
com.paktalin.vocabularynotebook.removeFragment
import
com.paktalin.vocabularynotebook.shortToast
import
kotlinx.android.synthetic.main.fragment_new_word.*
import
kotlinx.android.synthetic.main.notebook_sheet.*
...
...
@@ -74,8 +75,8 @@ class EditWordFragment : WordFragment() {
private
fun
stop
()
{
// set onClickListener from AddWordFragment
mainActivity
.
btnSubmit
.
setOnClickListener
{
(
mainActivity
.
fragment
New
Word
as
AddWordFragment
).
submitWord
()
}
mainActivity
.
removeFragment
(
this
)
mainActivity
.
btnSubmit
.
setOnClickListener
{
(
mainActivity
.
fragment
Add
Word
as
AddWordFragment
).
submitWord
()
}
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
98806c93
...
...
@@ -10,7 +10,6 @@ import com.google.firebase.firestore.DocumentReference
import
kotlinx.android.synthetic.main.activity_main.*
import
android.view.WindowManager
import
android.app.Activity
import
android.support.v4.app.Fragment
import
android.view.Menu
import
android.view.MenuItem
import
android.view.View
...
...
@@ -21,7 +20,6 @@ import android.support.v7.widget.SearchView
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
class
MainActivity
:
AppCompatActivity
()
{
lateinit
var
vocabularyId
:
String
...
...
@@ -83,9 +81,7 @@ class MainActivity : AppCompatActivity() {
vocabularyFragment
=
VocabularyFragment
()
val
arguments
=
Bundle
()
arguments
.
putString
(
"vocabularyId"
,
vocabularyId
)
vocabularyFragment
.
arguments
=
arguments
supportFragmentManager
.
beginTransaction
().
add
(
R
.
id
.
fragment_container
,
vocabularyFragment
)
.
commitNowAllowingStateLoss
()
addFragment
(
supportFragmentManager
,
vocabularyFragment
,
R
.
id
.
container_vocabulary
,
arguments
)
}
else
{
Log
.
w
(
TAG
,
"There's no collection \"vocabularies\""
)
showToastNoWords
()
}
...
...
@@ -115,10 +111,6 @@ class MainActivity : AppCompatActivity() {
shortToast
(
this
,
getString
(
R
.
string
.
toast_no_words
))
}
fun
removeFragment
(
fragment
:
Fragment
)
{
supportFragmentManager
.
beginTransaction
().
remove
(
fragment
).
commitAllowingStateLoss
()
}
override
fun
onPause
()
{
super
.
onPause
()
hideKeyboard
()
...
...
app/src/main/res/layout/notebook_sheet.xml
View file @
98806c93
...
...
@@ -25,7 +25,7 @@
app:layout_constraintTop_toTopOf=
"parent"
>
<fragment
android:id=
"@+id/fragment
New
Word"
android:id=
"@+id/fragment
Add
Word"
android:name=
"com.paktalin.vocabularynotebook.ui.AddWordFragment"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
...
...
@@ -46,7 +46,7 @@
app:layout_constraintVertical_bias=
"0.0"
>
<LinearLayout
android:id=
"@+id/
fragment_container
"
android:id=
"@+id/
container_vocabulary
"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"@drawable/sheet_bottom"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment