You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class AllClinicalNoteDataSource(val patientId: Long, val viewModel: BaseViewModel) : PageKeyedDataSource<Int, ClinicalNote>() {
override fun loadInitial(params: LoadInitialParams<Int>, callback: LoadInitialCallback<Int, ClinicalNote>) {
viewModel.isLoadingLiveData.postValue(true)
var offset = 0
val dis = CommonRepository.instance.getAllClinicalNoteList(patientId, params.requestedLoadSize, offset)
.subscribe({
viewModel.isLoadingLiveData.postValue(false)
if (it.isSuccess) {
val resultList = it.data.clinicalNotes
offset += resultList?.size ?: 0
callback.onResult(resultList ?: listOf(), null, offset)
} else {
viewModel.errorLiveData.postValue(ErrorResponse(ErrorCode.ERR_UNKNOWN, it.message))
}
}, {
viewModel.isLoadingLiveData.postValue(false)
viewModel.errorLiveData.postValue(ErrorResponse(it))
})
}
override fun loadAfter(params: LoadParams<Int>, callback: LoadCallback<Int, ClinicalNote>) {
viewModel.isLoadingLiveData.postValue(true)
val currentOffset = params.key
val dis = CommonRepository.instance.getAllClinicalNoteList(patientId, params.requestedLoadSize, currentOffset)
.subscribe({
viewModel.isLoadingLiveData.postValue(false)
if (it.isSuccess) {
val resultList = it.data.clinicalNotes
val nextOffset = currentOffset + (resultList?.size ?: 0)
callback.onResult(resultList ?: listOf(), nextOffset)
} else {
viewModel.errorLiveData.postValue(ErrorResponse(ErrorCode.ERR_UNKNOWN, it.message))
}
}, {
viewModel.isLoadingLiveData.postValue(false)
viewModel.errorLiveData.postValue(ErrorResponse(it))
})
}
override fun loadBefore(params: LoadParams<Int>, callback: LoadCallback<Int, ClinicalNote>) {
// This is not necessary in our case as our data doesn't change. It's useful in cases where
// the data changes and we need to fetch our list starting from the middle.
}
}
AllClinicalNoteAdapter
class AllClinicalNoteAdapter : PagedListAdapter<ClinicalNote, AllClinicalNoteViewHolder>(AllClinicalNoteDiffUtilCallback()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AllClinicalNoteViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.adapter_item_all_clinical_note, parent, false)
return AllClinicalNoteViewHolder(view)
}
override fun onBindViewHolder(holder: AllClinicalNoteViewHolder, position: Int) {
val note = getItem(position)
if (note == null) { // this is the placeholder
holder.itemView.aiacc_full_name.text = "Loading"
holder.itemView.aiacc_date.text = "Loading"
holder.itemView.aiacc_title.text = "Loading"
} else {
/*val resources = holder.itemView.context.resources
val scoreString = resources.getString(R.string.score, item?.score)
val commentCountString = resources.getString(R.string.comments, item?.commentCount)*/
holder.itemView.aiacc_image_iv.loadCircleDoctorAvatar(note.imageURL)
holder.itemView.aiacc_full_name.text = note.fullName
holder.itemView.aiacc_date.text = note.dateCreated
holder.itemView.aiacc_title.text = note.title
}
}
}
AllClinicalNoteViewHolder
class AllClinicalNoteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
R.layout.adapter_item_all_clinical_note
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:cardElevation="2dp"
app:cardCornerRadius="10dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/aiacc_image_iv"
android:layout_width="40dp"
android:layout_height="40dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:src="@drawable/bg_circle_1"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/aiacc_start_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="68dp"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/aiacc_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Jan 19, 2019"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/aiacc_full_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="@style/BoldTextStyle"
android:textColor="@color/text_color_dark"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="@id/aiacc_start_guideline"
app:layout_constraintEnd_toStartOf="@id/aiacc_date"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/aiacc_title"
tools:text="Dr. Lam Hieu Long Chuyen Di Bat Trom Bat Cuop Ma Ko Chiu Kham Benh Ne Troi Oi La Troi Dat Oi O La La"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/aiacc_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
app:layout_constraintStart_toStartOf="@id/aiacc_start_guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/aiacc_full_name"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="Day la mot cai random content tao lao bi dao nhat he mat troi ne troi oi la troi dat oi"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
AllClinicalNoteDiffUtilCallback
class AllClinicalNoteDiffUtilCallback : DiffUtil.ItemCallback<ClinicalNote>() {
override fun areItemsTheSame(oldItem: ClinicalNote, newItem: ClinicalNote): Boolean {
return oldItem.clinicalNoteID == newItem.clinicalNoteID
}
// this usually the fields that are visually available to user
override fun areContentsTheSame(oldItem: ClinicalNote, newItem: ClinicalNote): Boolean {
return oldItem.imageURL == newItem.imageURL &&
oldItem.fullName == newItem.fullName &&
oldItem.dateCreated == newItem.dateCreated &&
oldItem.title == newItem.title
}
}