'With pet' project is comprehensive dog app for pet owner.
WithPet provide trail path, pet shop, ownerless dog's information.
Technical Name | Value |
---|---|
Language | Kotlin |
Pattern | MVVM |
Rest Api | Retrofit2 |
DI | Koin |
Reactive | Rxjava, LiveData |
BaaS (Backend as a Service) | Firebase |
In order to request Api on client need to put JWT token on 'Authorization' of http header. Client get JWT token at login and save JWT state at REDUX.
MVVM pattern has benefit to seperate business, presentation logic from UI. It clearly separates the business and UI, making it easier to test and easier to maintain.
View is responsible for the layout structure on shown screen. Also it can perform related UI logic.
The ViewModel implements data and commands in the View, and notifies the View of changes in state through change notification events. And the view that receives the status change notification will decide whether to apply the change or not.
class HosCommentViewModel(val hospitalCommentRepository: HospitalCommentRepository) : BaseViewModel() {
private val _isPutComment = MutableLiveData<Boolean>()
val isPutComment: LiveData<Boolean>
get() = _isPutComment
fun putHospitalComment(hospitalUid : String, review : HospitalReviewDTO) {
addDisposable(
hospitalCommentRepository.putHospitalComment(hospitalUid , review)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {t: Boolean ->
_isPutComment.postValue(t)
}
)
hospitalCommentRepository.putHospitalComment(hospitalUid , review)
}
fun putHospitalStar(hospitalUid : String , starPoint: Int) {
hospitalCommentRepository.putHospitalStar(hospitalUid , starPoint)
}
}
Model is a non-visual class that holds the data you want to use. Examples include data transfer objects (DTOs), plain old Java objects (POJOs), or entity objects. Typically used with services or repositories that access data or need caching.
override fun getHospitalSearchData(searchValue: String): Observable<ArrayList<HospitalSearchDTO>> {
return Observable.create {
emitter ->
firestore.collection(COLECT_HOSPITAL).orderBy(COLECT_HOSPITAL_NAME).startAt(searchValue).endAt(searchValue+'\uf8ff').get().addOnCompleteListener {
task: Task<QuerySnapshot> ->
if(task.isSuccessful) {
list.clear()
for(snapshot in task.result?.documents!!){
list.add(snapshot.toObject(HospitalSearchDTO::class.java)!!)
}
emitter.onNext(list)
}
}
}
}