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
af51e854
authored
Apr 21, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added submit and cancel functionality to TagFragment
parent
ef2ddec9
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
61 additions
and
20 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/TagFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/WordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/selection_tracker/MySelectionTracker.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
app/src/main/res/layout/fragment_tag.xml
app/src/main/res/values-ru/strings.xml
app/src/main/res/values/strings.xml
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/AddWordFragment.kt
View file @
af51e854
...
...
@@ -32,7 +32,7 @@ class AddWordFragment : WordFragment() {
translationEmpty
=
translation
.
text
.
isEmpty
()
})
}
override
fun
cancel
Editing
()
{
override
fun
cancel
()
{
clearFields
()
gone
(
mainActivity
.
btnSubmitLayout
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
View file @
af51e854
...
...
@@ -20,7 +20,7 @@ class EditWordFragment : WordFragment() {
private
lateinit
var
wordPojo
:
WordPojo
private
var
container
:
ViewGroup
?
=
null
override
fun
cancel
Editing
()
{
override
fun
cancel
()
{
stop
()
showPreviousViews
()
}
...
...
@@ -73,7 +73,7 @@ class EditWordFragment : WordFragment() {
private
fun
stop
()
{
// set onClickListener from AddWordFragment
mainActivity
.
btnSubmitWord
.
setOnClickListener
{
(
mainActivity
.
fragmentAddWord
as
AddWordFragment
).
submit
Word
()
}
mainActivity
.
btnSubmitWord
.
setOnClickListener
{
(
mainActivity
.
fragmentAddWord
as
AddWordFragment
).
submit
()
}
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
gone
(
mainActivity
.
btnSubmitLayout
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/TagFragment.kt
View file @
af51e854
...
...
@@ -6,10 +6,41 @@ import android.view.View
import
android.view.ViewGroup
import
androidx.fragment.app.Fragment
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.removeTagFragment
import
com.paktalin.vocabularynotebook.utils.shortToast
import
kotlinx.android.synthetic.main.fragment_tag.*
class
TagFragment
:
Fragment
()
{
private
lateinit
var
mainActivity
:
MainActivity
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_tag
,
container
,
false
)
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
btnSubmitTag
.
setOnClickListener
{
submit
()
}
btnCancelTag
.
setOnClickListener
{
cancel
()
}
}
private
fun
submit
()
{
tag_et
.
text
.
toString
().
let
{
if
(
it
.
isBlank
())
shortToast
(
mainActivity
,
mainActivity
.
getString
(
R
.
string
.
toast_tag_cannot_be_empty
))
else
mainActivity
.
vocabularyAdapter
.
addTagToSelected
(
it
)
}
}
private
fun
cancel
()
{
mainActivity
.
vocabularyAdapter
.
selectionTracker
.
clearSelection
()
removeTagFragment
(
mainActivity
.
supportFragmentManager
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
TagFragment
::
class
.
simpleName
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/WordFragment.kt
View file @
af51e854
...
...
@@ -21,13 +21,13 @@ abstract class WordFragment : Fragment() {
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
mainActivity
.
btnSubmitWord
.
setOnClickListener
{
submit
Word
()
}
mainActivity
.
btnCancelWord
.
setOnClickListener
{
cancel
Editing
()
}
mainActivity
.
btnSubmitWord
.
setOnClickListener
{
submit
()
}
mainActivity
.
btnCancelWord
.
setOnClickListener
{
cancel
()
}
btnClear
.
setOnClickListener
{
clearFields
()
}
}
fun
submit
Word
()
{
fun
submit
()
{
gone
(
mainActivity
.
btnSubmitLayout
)
save
(
word
.
text
.
toString
(),
translation
.
text
.
toString
())
return
...
...
@@ -38,6 +38,6 @@ abstract class WordFragment : Fragment() {
translation
.
text
.
clear
()
}
protected
abstract
fun
cancel
Editing
()
protected
abstract
fun
cancel
()
protected
abstract
fun
save
(
word
:
String
,
translation
:
String
)
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
af51e854
...
...
@@ -132,6 +132,10 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
return
vocabulary
.
getModified
()
}
fun
addTagToSelected
(
tag
:
String
)
{
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/selection_tracker/MySelectionTracker.kt
View file @
af51e854
...
...
@@ -37,6 +37,10 @@ class MySelectionTracker {
return
false
}
fun
clearSelection
()
{
tracker
?.
clearSelection
()
}
companion
object
{
private
val
TAG
=
"VN/"
+
MySelectionTracker
::
class
.
simpleName
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
View file @
af51e854
...
...
@@ -15,12 +15,11 @@ import org.apache.commons.lang3.StringUtils
val
progressFragment
=
ProgressFragment
()
val
tagFragment
=
TagFragment
()
fun
addFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
,
containerId
:
Int
,
arguments
:
Bundle
?
=
null
,
tag
:
String
?
=
null
)
{
fragment
.
arguments
=
arguments
// remove progressFragment if it exists
if
(
fragmentManager
.
findFragmentById
(
fragment
.
id
)
!=
null
)
removeFragment
(
fragmentManager
,
fragment
)
fragmentManager
.
beginTransaction
().
add
(
containerId
,
fragment
,
tag
).
commitAllowingStateLoss
()
fun
addFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
,
containerId
:
Int
,
arg
:
Bundle
?
=
null
,
tag
:
String
?
=
null
)
{
if
(!
fragment
.
isAdded
)
fragmentManager
.
beginTransaction
()
.
add
(
containerId
,
fragment
.
apply
{
arguments
=
arg
},
tag
)
.
commitAllowingStateLoss
()
}
fun
removeFragment
(
fragmentManager
:
FragmentManager
,
fragment
:
Fragment
)
{
...
...
@@ -32,8 +31,7 @@ fun addProgressBar(fragmentManager: FragmentManager, containerId: Int) {
}
fun
addTagFragment
(
fragmentManager
:
FragmentManager
,
containerId
:
Int
)
{
if
(
fragmentManager
.
findFragmentById
(
tagFragment
.
id
)
==
null
)
addFragment
(
fragmentManager
,
tagFragment
,
containerId
)
addFragment
(
fragmentManager
,
tagFragment
,
containerId
)
}
fun
removeTagFragment
(
fragmentManager
:
FragmentManager
)
{
...
...
@@ -53,7 +51,7 @@ fun fieldsNotEmpty(username: String, password: String, context: Context): Boolea
}
fun
validUsername
(
username
:
String
,
context
:
Context
):
Boolean
{
return
if
(
isEmail
(
username
)
||
return
if
(
isEmail
(
username
)
||
StringUtils
.
containsOnly
(
username
.
toLowerCase
(),
"abcdefghijklmnopqrstuvwxyz0123456789-_."
))
true
else
{
...
...
app/src/main/res/layout/fragment_tag.xml
View file @
af51e854
...
...
@@ -20,7 +20,7 @@
tools:ignore=
"ContentDescription"
/>
<AutoCompleteTextView
android:id=
"@+id/tag"
android:id=
"@+id/tag
_et
"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
...
...
app/src/main/res/values-ru/strings.xml
View file @
af51e854
...
...
@@ -20,6 +20,7 @@
<string
name=
"toast_successful_sign_up"
>
Поздравляем! Теперь вы можете использовать словарь с любого устройства
</string>
<string
name=
"toast_enter_username_password"
>
Пожалуйста, введите логин и пароль
</string>
<string
name=
"toast_invalid_username"
>
Пожалуйста, придумайте логин, используя символы a–z, цифры 0–9 и символы -_.
</string>
<string
name=
"
add
_tag"
>
Добавить тег
</string>
<string
name=
"
enter
_tag"
>
Добавить тег
</string>
<string
name=
"toast_select_words_to_tag"
>
Выберите слова для тега
</string>
<string
name=
"toast_tag_cannot_be_empty"
>
Пожалуйста, введите тег
</string>
</resources>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
af51e854
...
...
@@ -13,7 +13,7 @@
<string
name=
"log_out"
>
Log out
</string>
<string
name=
"sign_up"
>
Sign Up
</string>
<string
name=
"log_in"
>
Log In
</string>
<string
name=
"
add
_tag"
>
Add tag
</string>
<string
name=
"
enter
_tag"
>
Add tag
</string>
<!--Toast messages-->
<string
name=
"toast_empty_vocabulary"
>
Your vocabulary is empty. Add your fist word!
</string>
...
...
@@ -22,5 +22,5 @@
<string
name=
"toast_enter_username_password"
>
Please, enter username and password
</string>
<string
name=
"toast_invalid_username"
>
Please, create a username using letters a–z, numbers 0–9 and characters -_.
</string>
<string
name=
"toast_select_words_to_tag"
>
Select words to tag
</string>
<string
name=
"
enter_tag"
>
Enter
tag
</string>
<string
name=
"
toast_tag_cannot_be_empty"
>
Please, enter the
tag
</string>
</resources>
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