-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: manifest에 CommentDetailActivity 추가 * feat: BindingAdatper을 사용하여 접힐 때 애니메이션 적용 및 픽셀 변환 * feat: viewmodel 구현 및 click 마다 접히고 펴지는 로직 구현 * style: ktlint 적용 * refactor: binding adpater을 사용하여 가시성 변경
- Loading branch information
Showing
5 changed files
with
185 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 43 additions & 6 deletions
49
...src/main/java/com/zzang/chongdae/presentation/view/commentdetail/CommentDetailActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,61 @@ | ||
package com.zzang.chongdae.presentation.view.commentdetail | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.navigation.NavController | ||
import androidx.navigation.fragment.NavHostFragment | ||
import androidx.databinding.DataBindingUtil | ||
import com.zzang.chongdae.R | ||
import com.zzang.chongdae.databinding.ActivityCommentDetailBinding | ||
|
||
class CommentDetailActivity : AppCompatActivity() { | ||
private var _binding: ActivityCommentDetailBinding? = null | ||
private val binding get() = _binding!! | ||
private lateinit var navHostFragment: NavHostFragment | ||
private lateinit var navController: NavController | ||
|
||
private val offeringId by lazy { | ||
intent.getLongExtra( | ||
EXTRA_OFFERING_ID_KEY, | ||
EXTRA_DEFAULT_VALUE, | ||
) | ||
} | ||
|
||
private val offeringTitle by lazy { | ||
intent.getStringExtra(EXTRA_OFFERING_TITLE_KEY) ?: "" | ||
} | ||
|
||
private val viewModel: CommentDetailViewModel by viewModels { CommentDetailViewModel.getFactory(offeringId, offeringTitle) } | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
initBinding() | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
_binding = null | ||
} | ||
|
||
private fun initBinding() { | ||
_binding = ActivityCommentDetailBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
_binding = DataBindingUtil.setContentView(this, R.layout.activity_comment_detail) | ||
binding.vm = viewModel | ||
binding.lifecycleOwner = this | ||
} | ||
|
||
companion object { | ||
private const val EXTRA_DEFAULT_VALUE = -1L | ||
private const val EXTRA_OFFERING_ID_KEY = "offering_id_key" | ||
private const val EXTRA_OFFERING_TITLE_KEY = "offering_title_key" | ||
|
||
fun startActivity( | ||
context: Context, | ||
offeringId: Long, | ||
offeringTitle: String, | ||
) = Intent(context, CommentDetailActivity::class.java).run { | ||
putExtra(EXTRA_OFFERING_ID_KEY, offeringId) | ||
putExtra(EXTRA_OFFERING_TITLE_KEY, offeringTitle) | ||
context.startActivity(this) | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...rc/main/java/com/zzang/chongdae/presentation/view/commentdetail/CommentDetailViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.zzang.chongdae.presentation.view.commentdetail | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.lifecycle.viewmodel.CreationExtras | ||
|
||
class CommentDetailViewModel( | ||
private val offeringId: Long, | ||
private val offeringTitle: String, | ||
) : ViewModel() { | ||
private val _isCollapsibleViewVisible = MutableLiveData<Boolean>(false) | ||
val isCollapsibleViewVisible: LiveData<Boolean> get() = _isCollapsibleViewVisible | ||
|
||
fun toggleCollapsibleView() { | ||
_isCollapsibleViewVisible.value = _isCollapsibleViewVisible.value?.not() | ||
Log.d("CommentDetailViewModel", "toggleCollapsibleView: ${_isCollapsibleViewVisible.value}") | ||
} | ||
|
||
companion object { | ||
@Suppress("UNCHECKED_CAST") | ||
fun getFactory( | ||
offeringId: Long, | ||
offeringTitle: String, | ||
) = object : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create( | ||
modelClass: Class<T>, | ||
extras: CreationExtras, | ||
): T = CommentDetailViewModel(offeringId, offeringTitle) as T | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters