Skip to content

Commit

Permalink
Feat: 태그 사용 회수 DB에 반영되는 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
linenive committed Jun 20, 2021
1 parent 2641c37 commit 205ac63
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ class AddArticleActivity : AppCompatActivity() {
tags[value.main_tag_name] = newTag
}
article[DB_MAIN_TAGS] = tags
pushDBTag()
}

// currentArticleRef.updateChildren(article)
Expand All @@ -367,6 +368,27 @@ class AddArticleActivity : AppCompatActivity() {
finish()
}

// 전체 Tag DB 에 Tag 변경사항 반영 (사용 횟수 증가)
private fun pushDBTag(){
var tagRef = Firebase.database.reference.child(DBKeys.DB_MAIN_TAGS)

for ((key, value) in tagRecyclerAdapter.data) {
tagRef.child(key)
.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
// DB 에 같은 값이 있음: 사용 회수 증가
if (snapshot.childrenCount > 0) {
// 사용 회수 의미적으로 증가(=감소)
tagRef.child(key).child(DBKeys.USED).setValue(
snapshot.child(DBKeys.USED).value.toString().toInt() - 1
)
}
}
override fun onCancelled(error: DatabaseError) {}
})
}
}

private fun updateImage(uri: String) {
if (isFirstImageUpdate) {
articleRef.child(articleId).child(ARTICLE_THUMBNAIL_IMAGE_URL).setValue(uri)
Expand Down

0 comments on commit 205ac63

Please sign in to comment.