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
linenive committed Jun 20, 2021
2 parents 19f8ad0 + 451125d commit 3b5bba3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.DatabaseReference
Expand All @@ -17,25 +20,36 @@ import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
import kr.ac.konkuk.koogle.Adapter.CommentAdapter
import kr.ac.konkuk.koogle.Adapter.TagAdapter
import kr.ac.konkuk.koogle.DBKeys
import kr.ac.konkuk.koogle.DBKeys.Companion.DB_COMMENTS
import kr.ac.konkuk.koogle.DBKeys.Companion.DB_USERS
import kr.ac.konkuk.koogle.DBKeys.Companion.DB_USER_TAG
import kr.ac.konkuk.koogle.DBKeys.Companion.TAG_INDEX
import kr.ac.konkuk.koogle.Model.CommentModel
import kr.ac.konkuk.koogle.Model.TagModel
import kr.ac.konkuk.koogle.Model.UserModel
import kr.ac.konkuk.koogle.R
import kr.ac.konkuk.koogle.databinding.ActivityCheckProfileBinding

class CheckProfileActivity : ProfileCommonActivity() {
private val profileEditRequest = 1110
class CheckProfileActivity : AppCompatActivity() {
private val maxShowTag = 20 // 최대 허용 태그 개수

lateinit var binding: ActivityCheckProfileBinding

lateinit var userTagRef: DatabaseReference

lateinit var writerId: String

private lateinit var commentAdapter: CommentAdapter

private var userCommentList = mutableListOf<CommentModel>()

private val auth:FirebaseAuth by lazy {
Firebase.auth
}

private val firebaseUser= auth.currentUser!!

private val userRef: DatabaseReference by lazy {
Firebase.database.reference.child(DB_USERS)
}
Expand All @@ -48,6 +62,9 @@ class CheckProfileActivity : ProfileCommonActivity() {
currentWriterRef.child(DB_COMMENTS)
}

// 태그 리사이클러뷰 관련
lateinit var tagAdapter: TagAdapter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCheckProfileBinding.inflate(layoutInflater)
Expand Down Expand Up @@ -82,6 +99,33 @@ class CheckProfileActivity : ProfileCommonActivity() {
Log.i("CheckProfileActivity", "writerId: $writerId")
}

// DB 에서 유저 태그 데이터 받아옴
val tagData: ArrayList<TagModel> = arrayListOf()
userTagRef = Firebase.database.reference
.child(DB_USER_TAG).child(writerId)
userTagRef.orderByChild(TAG_INDEX)
.limitToFirst(maxShowTag).addListenerForSingleValueEvent(object:ValueEventListener{
override fun onDataChange(snapshot: DataSnapshot) {
for(s in snapshot.children){
val newSubTag = arrayListOf<String>()
for(st in s.child(DBKeys.SUB_TAGS).children){
newSubTag.add(st.key.toString())
}
tagData.add(
TagModel(
s.key.toString(), newSubTag,
s.child(DBKeys.TAG_VALUE).value.toString().toInt(),
s.child(DBKeys.TAG_TYPE).value.toString().toInt()
))
}
// 로딩 작업이 끝난 이후 RecyclerView 를 초기화하는 순서를 맞추기 위해 이곳에 넣음
initTagRecyclerView(tagData)
}
override fun onCancelled(error: DatabaseError) {
return
}
})

currentWriterRef.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
if (snapshot.exists()) {
Expand Down Expand Up @@ -128,14 +172,6 @@ class CheckProfileActivity : ProfileCommonActivity() {
})
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
// 리사이클러뷰 갱신
if(requestCode==profileEditRequest){
initRecyclerView()
}
}

private fun initCommentRecyclerView() {
binding.commentRecyclerView.layoutManager = LinearLayoutManager(this)
binding.commentRecyclerView.addItemDecoration(DividerItemDecoration(this, 1))
Expand All @@ -144,7 +180,7 @@ class CheckProfileActivity : ProfileCommonActivity() {
commentAdapter.submitList(userCommentList)
}

override fun initTagRecyclerView(data: ArrayList<TagModel>) {
private fun initTagRecyclerView(data: ArrayList<TagModel>) {
binding.tagRecyclerView.layoutManager = LinearLayoutManager(this)
// 구분선 넣기
//binding.tagRecyclerView.addItemDecoration(DividerItemDecoration(this, 1))
Expand Down Expand Up @@ -181,4 +217,5 @@ class CheckProfileActivity : ProfileCommonActivity() {
val itemTouchHelper = ItemTouchHelper(simpleCallBack)
itemTouchHelper.attachToRecyclerView(binding.tagRecyclerView)
}

}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_edit_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="@font/font"
android:text="@string/check"
android:text="저장"
android:layout_marginHorizontal="36dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down

0 comments on commit 3b5bba3

Please sign in to comment.