Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhooon committed Jun 20, 2021
2 parents e28ee95 + 655e158 commit 7db896a
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 163 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class AddNewTagActivity:AppCompatActivity() {
lateinit var adapter: AddTagAdapter
lateinit var rootRef:DatabaseReference
lateinit var tagRef:DatabaseReference
// 처음 5명이 사용하기 전까지는 추천에 뜨지 않게 하기
val TAG_INIT_NUM = 5

//Firebase Auth를 initialize 해주는 코드
private val auth: FirebaseAuth by lazy {
Expand Down Expand Up @@ -102,35 +100,6 @@ class AddNewTagActivity:AppCompatActivity() {
setDataRecyclerView(null)
}

/*
private fun commitMainTag(mainTag: String): Boolean{
tagRef.orderByChild(DBKeys.TAG_ID)
.equalTo(mainTag).addListenerForSingleValueEvent(object:ValueEventListener{
override fun onDataChange(snapshot: DataSnapshot) {
if(snapshot.childrenCount>0){
// 있으면 tagNum만 늘어난다.
tagRef.child(mainTag).child(DBKeys.USED_NUM).setValue(
snapshot.child(mainTag).child(DBKeys.USED_NUM).value.toString().toInt() + 1
)
}else{
// 없으면 추가하고 false 반환
val newTag = mutableMapOf<String, Any>()
newTag[DBKeys.TAG_ID] = mainTag
newTag[DBKeys.USED_NUM] = TAG_INIT_NUM
tagRef.child(mainTag).updateChildren(newTag)
}
}
override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
})
return false
}
*/
private fun commitSubTag(mainTag: String): Boolean{
// 이미 DB에 있는 태그인지 확인한다

Expand All @@ -149,7 +118,7 @@ class AddNewTagActivity:AppCompatActivity() {
private fun initView() {
binding.apply {
// 새 태그 버튼: 검색 창에 있는 태그가 DB에 있으면 무시, 없으면 목록에 추가한다
// DB 에는 아직 추가하지 않음. 유저가 최종적으로 프로필에 적용했을 때 추가한다
// sub Tag 는 DB 에는 아직 추가하지 않음. 유저가 최종적으로 프로필에 적용했을 때 추가한다
addNewTagBtn.setOnClickListener {
// 입력 창에 아무 것도 없으면 무시
if(searchEditText.length() == 0){
Expand All @@ -164,7 +133,6 @@ class AddNewTagActivity:AppCompatActivity() {
Toast.makeText(this@AddNewTagActivity,
R.string.msg_exist_tag, Toast.LENGTH_SHORT).show()
return

}else{
// 없으면 목록에 추가한다
val newTag = mutableMapOf<String, Any>()
Expand Down Expand Up @@ -234,4 +202,8 @@ class AddNewTagActivity:AppCompatActivity() {
})
}
}
companion object{
// 처음 5명이 사용하기 전까지는 추천에 뜨지 않게 하기
const val TAG_INIT_NUM = 5
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import kr.ac.konkuk.koogle.DBKeys.Companion.USER_EMAIL
import kr.ac.konkuk.koogle.DBKeys.Companion.USER_ID
import kr.ac.konkuk.koogle.DBKeys.Companion.USER_NAME
import kr.ac.konkuk.koogle.DBKeys.Companion.USER_PROFILE_IMAGE_URL
import kr.ac.konkuk.koogle.Fragment.CommunityFragment
import kr.ac.konkuk.koogle.Model.ArticleModel
import kr.ac.konkuk.koogle.Model.Entity.SearchResultEntity
import kr.ac.konkuk.koogle.Model.TagModel
Expand Down Expand Up @@ -520,6 +521,11 @@ class ArticleActivity : AppCompatActivity() {
data: TagModel,
position: Int
) {
// 검색창으로 이동
val intent = Intent()
intent.putExtra("tag", view.text.toString())
setResult(CommunityFragment.REQUEST_ARTICLE, intent)
finish()
}
}
binding.tagRecyclerView.adapter = tagRecyclerAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kr.ac.konkuk.koogle.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.TextView
import android.widget.Toast
Expand Down Expand Up @@ -47,12 +48,32 @@ class EditProfileActivity : ProfileCommonActivity() {
initButton()
}

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

for ((key, value) in tagAdapter.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) {}
})
}
}

// 현재 상태를 user DB에 저장
// 기존의 데이터는 사라진다.
private fun saveTag(){
userTagRef = Firebase.database.reference
.child(DBKeys.DB_USER_TAG).child(firebaseUser.uid)

var j = tagAdapter.itemCount
val tags = mutableMapOf<String, Any>()
for(value in tagAdapter.data) {
Expand Down Expand Up @@ -101,6 +122,7 @@ class EditProfileActivity : ProfileCommonActivity() {
.start(this@EditProfileActivity);
}
profileEditButton.setOnClickListener {
pushDBTag()
saveTag()
finish()
}
Expand Down Expand Up @@ -213,19 +235,7 @@ class EditProfileActivity : ProfileCommonActivity() {
binding.tagRecyclerView.addItemDecoration(DividerItemDecoration(this, 1))

tagAdapter = TagAdapter(this, data, true)
// 서브태그들 클릭했을 때 이벤트 구현
/*
tagAdapter.subTagClickListener = object : TagAdapter.OnItemClickListener {
override fun onItemClick(
holder: TagAdapter.DefaultViewHolder,
view: EditText,
data: TagModel,
position: Int
) {
Log.d("jan", "Click")
view.isEnabled = true
}
}*/

binding.tagRecyclerView.adapter = tagAdapter
val simpleCallBack = object : ItemTouchHelper.SimpleCallback(
ItemTouchHelper.DOWN or ItemTouchHelper.UP,
Expand All @@ -236,7 +246,6 @@ class EditProfileActivity : ProfileCommonActivity() {
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder
): Boolean {
tagAdapter.moveItem(viewHolder.adapterPosition, target.adapterPosition)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class TagAdapter(val context: Context, val data: MutableList<TagModel>,

// 클릭 이벤트 설정
subTagText.setOnClickListener {
itemClickListener?.onItemClick(this, subTagText, data[adapterPosition], adapterPosition)
subTagClickListener?.onItemClick(this, subTagText, data[adapterPosition], adapterPosition)
}

return subTagText
Expand Down

0 comments on commit 7db896a

Please sign in to comment.