-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
1 parent
fb11bc0
commit 608a8b4
Showing
21 changed files
with
275 additions
and
363 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
app/src/main/java/org/imaginativeworld/simplemvvm/adapters/DemoPostPagedLoadStateAdapter.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,54 @@ | ||
package org.imaginativeworld.simplemvvm.adapters | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.core.view.isVisible | ||
import androidx.paging.LoadState | ||
import androidx.paging.LoadStateAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.imaginativeworld.simplemvvm.databinding.DemoLoadStateFooterViewItemBinding | ||
|
||
class DemoPostPagedLoadStateAdapter( | ||
private val retry: () -> Unit | ||
) : LoadStateAdapter<DemoPostPagedLoadStateAdapter.ItemViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState): ItemViewHolder { | ||
return ItemViewHolder.from(parent, retry) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ItemViewHolder, loadState: LoadState) { | ||
holder.bind(loadState) | ||
} | ||
|
||
class ItemViewHolder private constructor( | ||
private val binding: DemoLoadStateFooterViewItemBinding, | ||
retry: () -> Unit | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
|
||
init { | ||
binding.retryButton.setOnClickListener { retry.invoke() } | ||
} | ||
|
||
fun bind(loadState: LoadState) { | ||
if (loadState is LoadState.Error) { | ||
binding.errorMsg.text = loadState.error.localizedMessage | ||
} | ||
binding.progressBar.isVisible = loadState is LoadState.Loading | ||
binding.retryButton.isVisible = loadState is LoadState.Error | ||
binding.errorMsg.isVisible = loadState is LoadState.Error | ||
} | ||
|
||
companion object { | ||
fun from( | ||
parent: ViewGroup, | ||
retry: () -> Unit | ||
): ItemViewHolder { | ||
val layoutInflater = LayoutInflater.from(parent.context) | ||
val binding = | ||
DemoLoadStateFooterViewItemBinding.inflate(layoutInflater, parent, false) | ||
return ItemViewHolder(binding, retry) | ||
} | ||
} | ||
|
||
} | ||
} |
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
77 changes: 0 additions & 77 deletions
77
app/src/main/java/org/imaginativeworld/simplemvvm/datasource/PostPagedDataSource.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.