-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add extensions add button clear data recommended
- Loading branch information
1 parent
0ba5ad5
commit 04a3287
Showing
22 changed files
with
584 additions
and
43 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
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
3 changes: 3 additions & 0 deletions
3
app/src/main/java/dev/brahmkshatriya/echo/extensions/InvalidExtensionListException.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,3 @@ | ||
package dev.brahmkshatriya.echo.extensions | ||
|
||
class InvalidExtensionListException(override val cause: Throwable) : Exception(cause) |
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
15 changes: 12 additions & 3 deletions
15
app/src/main/java/dev/brahmkshatriya/echo/extensions/plugger/LazyPluginRepo.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 |
---|---|---|
@@ -1,15 +1,24 @@ | ||
package dev.brahmkshatriya.echo.extensions.plugger | ||
|
||
import dev.brahmkshatriya.echo.common.models.Metadata | ||
import tel.jeelpa.plugger.PluginRepo | ||
import tel.jeelpa.plugger.utils.combineStates | ||
import tel.jeelpa.plugger.utils.mapState | ||
|
||
interface LazyPluginRepo<T, R> : PluginRepo<T, Lazy<Result<R>>> | ||
|
||
class LazyRepoComposer<TMetadata, TPlugin>( | ||
private vararg val repos: LazyPluginRepo<TMetadata, TPlugin> | ||
) : LazyPluginRepo<TMetadata, TPlugin> { | ||
class LazyRepoComposer<TPlugin>( | ||
private vararg val repos: LazyPluginRepo<Metadata, TPlugin> | ||
) : LazyPluginRepo<Metadata, TPlugin> { | ||
override fun getAllPlugins() = repos.map { it.getAllPlugins() } | ||
.reduce { a, b -> combineStates(a, b) { x, y -> x + y } } | ||
.mapState { list -> | ||
list.groupBy { it.getOrNull()?.first?.id }.map { entry -> | ||
entry.value.minBy { | ||
it.getOrNull()?.first?.importType?.ordinal ?: Int.MAX_VALUE | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun <T> catchLazy(function: () -> T) = lazy { runCatching { function() } } |
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
110 changes: 110 additions & 0 deletions
110
app/src/main/java/dev/brahmkshatriya/echo/ui/extension/ExtensionsAddListAdapter.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,110 @@ | ||
package dev.brahmkshatriya.echo.ui.extension | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import dev.brahmkshatriya.echo.R | ||
import dev.brahmkshatriya.echo.common.models.ImageHolder.Companion.toImageHolder | ||
import dev.brahmkshatriya.echo.databinding.ItemExtensionAddBinding | ||
import dev.brahmkshatriya.echo.databinding.ItemExtensionAddFooterBinding | ||
import dev.brahmkshatriya.echo.databinding.ItemExtensionAddHeaderBinding | ||
import dev.brahmkshatriya.echo.extensions.ExtensionAssetResponse | ||
import dev.brahmkshatriya.echo.utils.loadAsCircle | ||
|
||
class ExtensionsAddListAdapter( | ||
val map: List<Item>, | ||
val listener: Listener | ||
) : RecyclerView.Adapter<ExtensionsAddListAdapter.ViewHolder>() { | ||
|
||
data class Item( | ||
val item: ExtensionAssetResponse, | ||
val isChecked: Boolean, | ||
val isInstalled: Boolean | ||
) | ||
|
||
fun interface Listener { | ||
fun onChecked(item: ExtensionAssetResponse, isChecked: Boolean) | ||
} | ||
|
||
inner class ViewHolder(val binding: ItemExtensionAddBinding) : | ||
RecyclerView.ViewHolder(binding.root) | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
val binding = ItemExtensionAddBinding.inflate(inflater, parent, false) | ||
return ViewHolder(binding) | ||
} | ||
|
||
override fun getItemCount() = map.size | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
val (item, isChecked, isInstalled) = map[position] | ||
val binding = holder.binding | ||
binding.extensionName.text = if (!isInstalled) item.name | ||
else binding.root.context.getString(R.string.extension_installed, item.name) | ||
binding.extensionSubtitle.text = item.subtitle ?: item.id | ||
binding.itemExtension.apply { | ||
item.iconUrl?.toImageHolder().loadAsCircle(this, R.drawable.ic_extension) { | ||
setImageDrawable(it) | ||
} | ||
} | ||
binding.extensionSwitch.isChecked = isChecked | ||
binding.extensionSwitch.setOnCheckedChangeListener { _, checked -> | ||
listener.onChecked(item, checked) | ||
} | ||
binding.root.setOnClickListener { | ||
binding.extensionSwitch.isChecked = !binding.extensionSwitch.isChecked | ||
} | ||
binding.extensionSwitch.isClickable = false | ||
} | ||
|
||
class Header( | ||
val listener: Listener | ||
) : RecyclerView.Adapter<Header.ViewHolder>() { | ||
|
||
fun interface Listener { | ||
fun onClose() | ||
} | ||
|
||
class ViewHolder(val binding: ItemExtensionAddHeaderBinding) : | ||
RecyclerView.ViewHolder(binding.root) | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
val binding = ItemExtensionAddHeaderBinding.inflate(inflater, parent, false) | ||
return ViewHolder(binding) | ||
} | ||
|
||
override fun getItemCount() = 1 | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.binding.root.setOnClickListener { listener.onClose() } | ||
} | ||
|
||
} | ||
|
||
class Footer( | ||
val listener: Listener | ||
) : RecyclerView.Adapter<Footer.ViewHolder>() { | ||
|
||
fun interface Listener { | ||
fun onAdd() | ||
} | ||
|
||
class ViewHolder(val binding: ItemExtensionAddFooterBinding) : | ||
RecyclerView.ViewHolder(binding.root) | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
val binding = ItemExtensionAddFooterBinding.inflate(inflater, parent, false) | ||
return ViewHolder(binding) | ||
} | ||
|
||
override fun getItemCount() = 1 | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.binding.root.setOnClickListener { listener.onAdd() } | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.