-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
22 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/polzzak_android/presentation/common/item/LoadMoreLoadingSpinnerItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.polzzak_android.presentation.common.item | ||
|
||
import android.view.animation.Animation | ||
import android.view.animation.LinearInterpolator | ||
import android.view.animation.RotateAnimation | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import com.polzzak_android.R | ||
import com.polzzak_android.databinding.ItemLoadMoreLoadingBinding | ||
import com.polzzak_android.presentation.common.util.BindableItem | ||
import com.polzzak_android.presentation.common.util.toPx | ||
|
||
class LoadMoreLoadingSpinnerItem( | ||
private val marginTopDp: Int = DEFAULT_VERTICAL_MARGIN_DP, | ||
private val marginBottomDp: Int = DEFAULT_VERTICAL_MARGIN_DP | ||
) : | ||
BindableItem<ItemLoadMoreLoadingBinding>() { | ||
override val layoutRes: Int = R.layout.item_load_more_loading | ||
|
||
override fun areItemsTheSame(other: BindableItem<*>): Boolean = | ||
other is LoadMoreLoadingSpinnerItem | ||
|
||
override fun areContentsTheSame(other: BindableItem<*>): Boolean = | ||
other is LoadMoreLoadingSpinnerItem && this.marginTopDp == other.marginTopDp && | ||
this.marginBottomDp == other.marginBottomDp | ||
|
||
override fun bind(binding: ItemLoadMoreLoadingBinding, position: Int) { | ||
val context = binding.root.context | ||
(binding.ivSpinner.layoutParams as? ConstraintLayout.LayoutParams)?.let { lp -> | ||
binding.ivSpinner.layoutParams = lp.apply { | ||
topMargin = marginTopDp.toPx(context) | ||
bottomMargin = marginBottomDp.toPx(context) | ||
} | ||
} | ||
val rotateAnimation = RotateAnimation( | ||
0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, | ||
Animation.RELATIVE_TO_SELF, 0.5f | ||
).apply { | ||
duration = 1000 | ||
interpolator = LinearInterpolator() | ||
repeatCount = Animation.INFINITE | ||
} | ||
binding.ivSpinner.startAnimation(rotateAnimation) | ||
|
||
} | ||
|
||
companion object { | ||
private const val DEFAULT_VERTICAL_MARGIN_DP = 24 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<ImageView | ||
android:id="@+id/ivSpinner" | ||
android:layout_width="36dp" | ||
android:layout_height="36dp" | ||
android:src="@drawable/ic_refresh_loading_spinner" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |