Conversation
MVP 패턴을 이용하여 만든 게시판입니다.
yunjaena
left a comment
There was a problem hiding this comment.
수고하셨습니다 !! MVP 패턴을 왜 사용하는지를 좀 더 염두 하시고 짜시면 더 좋은 코드가 나올 것 같습니다.
| @@ -0,0 +1,5 @@ | |||
| package com.example.myapplication | |||
|
|
|||
| interface BasePresenter<T> { | |||
There was a problem hiding this comment.
BasePresenter는 말대로 Presenter들의 Base가 되는 interface입니다. 고로 Presenter에 필요한 View interface를 세팅을 해주는 역할과 같은 기초적인 메서드만 있어야 합니다.
| itemView.setOnClickListener { | ||
| val curPos : Int = adapterPosition | ||
| val item : Items = itemList.get(curPos) | ||
| Toast.makeText(parent.context,"제목:${item.title}\n작성자:${item.name}",Toast.LENGTH_SHORT).show() |
There was a problem hiding this comment.
해당 String 값을 String resource에 선언해보세요 :)
| @@ -0,0 +1,5 @@ | |||
| package com.example.myapplication | |||
|
|
|||
| class Items(val title: String, val name: String, val time: String) { | |||
There was a problem hiding this comment.
안에 내용이 없으면 괄호를 없애도 좋습니다. 또한 모델을 선언할꺼면 data class로 선언하면 좋습니다. 일반 class 와 data class의 차이를 찾아보세요 :)
| binding = DataBindingUtil.setContentView(this,R.layout.activity_main) | ||
|
|
||
| binding.addButton.setOnClickListener { | ||
| preseter.nextActivity(this) |
There was a problem hiding this comment.
presenter의 역할을 잘 이해를 못하는 것 같습니다. presenter에서는 Model에 있는 데이터를 가져와 달라고 요청을 하는 것인데 Activity이동은 Activity에서 처리 하면 될 것 같습니다.
|
|
||
| override fun onResume() { | ||
| super.onResume() | ||
| preseter.setData() |
There was a problem hiding this comment.
setData 가 정확히 어떤 역할을 하는 메서드인지 모르겠습니다.
| } | ||
|
|
||
| override fun showInfo(itemList: ArrayList<Items>) { | ||
| binding.itemRcy.layoutManager = LinearLayoutManager(MainActivity(),LinearLayoutManager.VERTICAL,false) |
There was a problem hiding this comment.
MainActivity()보다는 this 로 하는것이 좋아 보입니다
|
|
||
| interface Presenter : BasePresenter<View>{ | ||
| fun setData() | ||
| fun saveData(item:Items,context: Context) |
There was a problem hiding this comment.
Presenter에서는 View 관련된 것을 알면 좋지 않습니다. ex) Context
| val intent = Intent(context,MainActivity::class.java) | ||
| startActivity(context,intent,null) |
There was a problem hiding this comment.
| val intent = Intent(context,MainActivity::class.java) | |
| startActivity(context,intent,null) | |
| view.finishUpdateItem() |
// Activity
override fun finishUpdateItem(){
val intent = Intent(context,MainActivity::class.java)
startActivity(context,intent,null)
}| class write_board : AppCompatActivity() { | ||
|
|
||
| private lateinit var binding : ActivityWriteBoardBinding | ||
| val preseter : MainContract.Presenter = MainPresenter() |
There was a problem hiding this comment.
private 으로 선언해도 좋을 것 같습니다.
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_write_board) | ||
|
|
||
| val long_now = System.currentTimeMillis() |
There was a problem hiding this comment.
변수명은 _ 로 선언하지 않습니다. => val longNow
변수 명도 다른 사람들이 알아 볼 수 있도록 짜면 좋을 것 같습니다. val currentTime = System.currentTimeMills()
MVP 패턴을 이용하여 만든 게시판입니다.