Skip to content

Commit

Permalink
fix: pull to swipe 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Mar 12, 2024
1 parent 7ae947f commit 493b62e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 24 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ dependencies {

implementation(libs.android.gif.drawable)
implementation(libs.wsdl4j)

// Swipe
implementation(libs.swiperefreshlayout)
}

licenseReport {
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/com/easyhz/picly/view/album/AlbumFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
Expand All @@ -18,6 +19,11 @@ import com.easyhz.picly.util.PICLY
import com.easyhz.picly.util.toPICLY
import com.easyhz.picly.view.navigation.NavControllerManager
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch


@AndroidEntryPoint
class AlbumFragment: Fragment() {
Expand Down Expand Up @@ -51,6 +57,8 @@ class AlbumFragment: Fragment() {
observeAlbums()
onclickFab()
observeSearchText()
setRefresh()
refresh()
}

private fun setRecyclerView() {
Expand All @@ -71,6 +79,11 @@ class AlbumFragment: Fragment() {
updateNoResultMessage(albums.isEmpty(), getString(R.string.no_data_text))
albumAdapter.setAlbumList(albums)
albumAdapter.originalList = albums
CoroutineScope(Dispatchers.Main).launch {
delay(500)
binding.swipeRefresh.isRefreshing = false
binding.albumRecyclerView.smoothScrollToPosition(0)
}
}
}

Expand Down Expand Up @@ -103,4 +116,18 @@ class AlbumFragment: Fragment() {
visibility = if (isEmpty) View.VISIBLE else View.GONE
}
}

private fun setRefresh() {
binding.swipeRefresh.apply {
setProgressBackgroundColorSchemeColor(ContextCompat.getColor(requireContext(), R.color.collectionViewCellBackground))
setColorSchemeColors(ContextCompat.getColor(requireContext(), R.color.highlightBlue))
}

}

private fun refresh() {
binding.swipeRefresh.setOnRefreshListener {
viewModel.fetchAlbums()
}
}
}
52 changes: 28 additions & 24 deletions app/src/main/res/layout/fragment_album.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,37 @@
android:layout_height="match_parent"
android:background="@color/mainBackground"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/albumRecyclerView"
android:background="@color/mainBackground"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="5dp"
android:overScrollMode="never"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
tools:listitem="@layout/item_album"
/>

<TextView
android:id="@+id/noResultMessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/no_search_text"
android:textColor="@color/secondText"
android:gravity="center"
android:visibility="gone"
android:background="@color/mainBackground"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/albumRecyclerView"
android:background="@color/mainBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="5dp"
android:overScrollMode="never"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
tools:listitem="@layout/item_album"
/>

<TextView
android:id="@+id/noResultMessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/no_search_text"
android:textColor="@color/secondText"
android:gravity="center"
android:visibility="gone"
android:background="@color/mainBackground"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/addFab"
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ paging-runtime-ktx = "3.2.1"
play-services-auth = "21.0.0"
play-services-oss-licenses = "17.0.1"
shimmer = "0.5.0"
swiperefreshlayout = "1.2.0-alpha01"
viewpager2 = "1.0.0"
wsdl4j = "1.5.1"

Expand Down Expand Up @@ -64,6 +65,7 @@ paging-runtime-ktx = { module = "androidx.paging:paging-runtime-ktx", version.re
play-services-auth = { module = "com.google.android.gms:play-services-auth", version.ref = "play-services-auth" }
play-services-oss-licenses = { module = "com.google.android.gms:play-services-oss-licenses", version.ref = "play-services-oss-licenses" }
shimmer = { module = "com.facebook.shimmer:shimmer", version.ref = "shimmer" }
swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "swiperefreshlayout" }
viewpager2 = { module = "androidx.viewpager2:viewpager2", version.ref = "viewpager2" }
wsdl4j = { module = "wsdl4j:wsdl4j", version.ref = "wsdl4j" }

Expand Down

0 comments on commit 493b62e

Please sign in to comment.