Skip to content

Commit

Permalink
📝 Notes pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbatovK committed Aug 4, 2022
1 parent 4f69ba1 commit 682a304
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.albatros.kplanner.R
import com.albatros.kplanner.databinding.ListFragmentBinding
import com.albatros.kplanner.domain.extensions.playFadeInAnimation
import com.albatros.kplanner.domain.extensions.playFadeOutAnimation
import com.albatros.kplanner.model.data.DiraNote
import com.albatros.kplanner.ui.activity.MainActivity
import com.albatros.kplanner.ui.adapter.note.NoteAdapter
Expand Down Expand Up @@ -127,6 +129,7 @@ class ListFragment : Fragment() {

binding.swipeRefreshLayout.setOnRefreshListener {
binding.swipeRefreshLayout.isRefreshing = false
binding.progressBar.playFadeInAnimation(500L)
viewModel.loadNextPage()
}

Expand All @@ -136,6 +139,7 @@ class ListFragment : Fragment() {
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)

viewModel.notes.observe(viewLifecycleOwner) {
binding.progressBar.playFadeOutAnimation(500L)
loaded.addAll(it)
(binding.notes.adapter as NoteAdapter)
.notifyItemRangeInserted((binding.notes.adapter as NoteAdapter).itemCount, it.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class ListViewModel(
viewModelScope.launch {
isLoading = true
_notes.value = notesUseCases.loadNotes(key * pageSize, ++key * pageSize)
if (!_notes.value.isNullOrEmpty())
isLoading = false
isLoading = false
}
}

Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
android:layout_marginTop="26dp"
android:background="@android:color/transparent"
android:elevation="0dp"

android:paddingStart="12dp"
android:paddingEnd="12dp"
android:theme="@style/Theme.KPlanner.AppBarOverlay"
Expand Down
24 changes: 22 additions & 2 deletions app/src/main/res/layout/list_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<com.omadahealth.github.swipyrefreshlayout.library.SwipyRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:paddingBottom="12dp"
android:layout_height="match_parent"
android:paddingBottom="12dp"
app:srl_direction="bottom">

<androidx.core.widget.NestedScrollView
Expand Down Expand Up @@ -41,7 +41,27 @@
android:paddingStart="8dp"
android:paddingTop="8dp"
android:paddingEnd="8dp"
android:paddingBottom="36dp" />
android:paddingBottom="20dp" />

<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text_hint"
android:paddingBottom="16dp"
android:text="Свайпните вниз, чтобы загрузить ешё"
style="@style/CardTextStyleTitle"
android:textColor="@color/dark_cyan"
android:textSize="14sp" />

<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:id="@+id/progress_bar"
android:indeterminate="true"
android:paddingBottom="72dp"
app:layout_constraintTop_toBottomOf="@id/text_hint" />

</LinearLayout>

Expand Down

0 comments on commit 682a304

Please sign in to comment.