Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

충남대 Android_정기주 2주차 과제 Step1 #31

Open
wants to merge 7 commits into
base: ddangcong80
Choose a base branch
from

Conversation

ddangcong80
Copy link

과제 수행 시 어려웠던 점

  • MVVM 패턴을 가능한 사용하도록 노력했는데 처음 사용해보다보니 model, view, viewmodel 각각에 대해 어떻게 역할을 부여해야 할지 어려웠던 것 같습니다. 또한 MVVM 패턴을 이해하기 위해서 Livedata와 같은 개념도 익숙하지 않아서 제 코드를 완벽히 이해하면서 작성했다고 말하기 어려울 것 같습니다.

중점적으로 리뷰해주셨으면 하는 부분

  • 우선 MVVM 패턴을 코드에 잘 적용했는지 궁금합니다. 예시로 더미데이터를 삽입하는 기능 구현을 할 때 코드의 흐름을 어떻게 짜야 MVVM 패턴에 맞게 한 것인지 궁금합니다.

Copy link

@InyoungAum InyoungAum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

Comment on lines 23 to 67
fun insertPlaceDummyData(context: Context, name: String, address: String, category: String) {
val dbHelper = PlaceDBHelper(context)
val db: SQLiteDatabase = dbHelper.writableDatabase
val values = ContentValues()
for (i: Int in 1..15) {
values.put(PlaceContract.PlaceEntry.COLUMN_PLACE_NAME, name + i)
values.put(PlaceContract.PlaceEntry.COLUMN_PLACE_ADDRESS, address + i)
values.put(PlaceContract.PlaceEntry.COLUMN_PLACE_CATEGORY, category)
db.insert(PlaceContract.PlaceEntry.TABLE_NAME, null, values)
}
db.close()
}

fun getAllPlaces(context: Context): List<String> {
val dbHelper = PlaceDBHelper(context)
val db: SQLiteDatabase = dbHelper.readableDatabase
val cursor: Cursor = db.query(
PlaceContract.PlaceEntry.TABLE_NAME,
null,
null,
null,
null,
null,
null
)

val places = mutableListOf<String>()
while (cursor.moveToNext()) {
val name =
cursor.getString(cursor.getColumnIndexOrThrow(PlaceContract.PlaceEntry.COLUMN_PLACE_NAME))
val address =
cursor.getString(cursor.getColumnIndexOrThrow(PlaceContract.PlaceEntry.COLUMN_PLACE_ADDRESS))
val category =
cursor.getString(cursor.getColumnIndexOrThrow(PlaceContract.PlaceEntry.COLUMN_PLACE_CATEGORY))
places.add("Name: $name, Address: $address, Category: $category")
}
cursor.close()
db.close()

for (place in places) {
Log.d("ddangcong80", place)
}

return places
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 함수들은 Repository class로 빼서 들고 있으면 좋을 것 같습니다.

Comment on lines 15 to 21
private var _searchText = MutableLiveData<String>()
val searchText: LiveData<String>
get() = _searchText

fun clearSearchText() {
_searchText.value = ""
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

searchText는 LiveData일 필요가 없을 것 같습니다.
데이터 변경이 일어나면 viewModel에 TextWatcher 를 통해서 바로바로 검색이 가능 할 것 같거든요
대신 list를 이후 step에서 livedata로 사용해보시길 바랍니다.

import campus.tech.kakao.map.model.PlaceContract
import campus.tech.kakao.map.model.PlaceDBHelper

class SearchViewModel : ViewModel() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

완벽하게 mvvm 아키텍쳐를 사용하기 위해서는
databinding을 꼭 사용해주어야 하는데요

https://hanyeop.tistory.com/377

요 블로그가 조금 도움이 될 것 같습니다.

다만 이번 학습의 범위를 넘어간다면 이 정도로도 괜찮을 듯 싶습니다.

}

fun getAllPlaces(context: Context): List<String> {
val dbHelper = PlaceDBHelper(context)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor cursor = null;
try{
	cursor = database.rawQuery(strSQL, null);
	if (cursor != null) {
	    // do action
	}
} catch(Exception e) {
    // exception
} finally {
	if(cursor != null) cursor.close();
}

이런 형태의 예외처리가 들어가도 좋을 것 같습니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants