Skip to content
Snippets Groups Projects
Commit 35c5045b authored by Kelvin's avatar Kelvin
Browse files

Named presets

parent 4930ea81
No related branches found
No related tags found
1 merge request!12Subscription Groups
package com.futo.platformplayer
class PresetImages {
companion object {
val images = mapOf<String, Int>(
Pair("xp_book", R.drawable.xp_book),
Pair("xp_forest", R.drawable.xp_forest),
Pair("xp_code", R.drawable.xp_code),
Pair("xp_controller", R.drawable.xp_controller),
Pair("xp_laptop", R.drawable.xp_laptop)
);
fun getPresetResIdByName(name: String): Int {
return images[name] ?: -1;
}
fun getPresetNameByResId(id: Int): String? {
return images.entries.find { it.value == id }?.key;
}
}
}
\ No newline at end of file
package com.futo.platformplayer.models package com.futo.platformplayer.models
import android.annotation.SuppressLint
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.widget.ImageView import android.widget.ImageView
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.futo.platformplayer.PresetImages
import com.futo.platformplayer.R import com.futo.platformplayer.R
import kotlinx.serialization.Contextual import kotlinx.serialization.Contextual
import kotlinx.serialization.Transient import kotlinx.serialization.Transient
...@@ -15,8 +17,10 @@ data class ImageVariable( ...@@ -15,8 +17,10 @@ data class ImageVariable(
val resId: Int? = null, val resId: Int? = null,
@Transient @Transient
@Contextual @Contextual
private val bitmap: Bitmap? = null) { private val bitmap: Bitmap? = null,
val presetName: String? = null) {
@SuppressLint("DiscouragedApi")
fun setImageView(imageView: ImageView, fallbackResId: Int = -1) { fun setImageView(imageView: ImageView, fallbackResId: Int = -1) {
if(bitmap != null) { if(bitmap != null) {
Glide.with(imageView) Glide.with(imageView)
...@@ -31,6 +35,9 @@ data class ImageVariable( ...@@ -31,6 +35,9 @@ data class ImageVariable(
.load(url) .load(url)
.placeholder(R.drawable.placeholder_channel_thumbnail) .placeholder(R.drawable.placeholder_channel_thumbnail)
.into(imageView); .into(imageView);
} else if(!presetName.isNullOrEmpty()) {
val resId = PresetImages.getPresetResIdByName(presetName);
imageView.setImageResource(resId);
} else if (fallbackResId != -1) { } else if (fallbackResId != -1) {
Glide.with(imageView) Glide.with(imageView)
.load(fallbackResId) .load(fallbackResId)
...@@ -52,6 +59,9 @@ data class ImageVariable( ...@@ -52,6 +59,9 @@ data class ImageVariable(
fun fromBitmap(bitmap: Bitmap): ImageVariable { fun fromBitmap(bitmap: Bitmap): ImageVariable {
return ImageVariable(null, null, bitmap); return ImageVariable(null, null, bitmap);
} }
fun fromPresetName(str: String): ImageVariable {
return ImageVariable(null, null, null, str);
}
fun fromFile(file: File): ImageVariable { fun fromFile(file: File): ImageVariable {
return ImageVariable.fromBitmap(BitmapFactory.decodeFile(file.absolutePath)); return ImageVariable.fromBitmap(BitmapFactory.decodeFile(file.absolutePath));
} }
......
...@@ -19,6 +19,7 @@ import androidx.recyclerview.widget.GridLayoutManager ...@@ -19,6 +19,7 @@ import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.futo.platformplayer.PresetImages
import com.futo.platformplayer.R import com.futo.platformplayer.R
import com.futo.platformplayer.UIDialogs import com.futo.platformplayer.UIDialogs
import com.futo.platformplayer.activities.IWithResultLauncher import com.futo.platformplayer.activities.IWithResultLauncher
...@@ -53,13 +54,8 @@ class ImageVariableOverlay: ConstraintLayout { ...@@ -53,13 +54,8 @@ class ImageVariableOverlay: ConstraintLayout {
private val _recyclerCreators: AnyAdapterView<SelectableCreatorBarViewHolder.Selectable, SelectableCreatorBarViewHolder>; private val _recyclerCreators: AnyAdapterView<SelectableCreatorBarViewHolder.Selectable, SelectableCreatorBarViewHolder>;
private val _creators: ArrayList<SelectableCreatorBarViewHolder.Selectable> = arrayListOf(); private val _creators: ArrayList<SelectableCreatorBarViewHolder.Selectable> = arrayListOf();
private val _presets: ArrayList<PresetImage> = arrayListOf( private val _presets: ArrayList<PresetImage> =
PresetImage(R.drawable.xp_book, false), ArrayList(PresetImages.images.map { PresetImage(it.value, it.key, false) });
PresetImage(R.drawable.xp_forest, false),
PresetImage(R.drawable.xp_laptop, false),
PresetImage(R.drawable.xp_controller, false),
PresetImage(R.drawable.xp_code, false),
);
private var _selected: ImageVariable? = null; private var _selected: ImageVariable? = null;
private var _selectedFile: String? = null; private var _selectedFile: String? = null;
...@@ -89,7 +85,7 @@ class ImageVariableOverlay: ConstraintLayout { ...@@ -89,7 +85,7 @@ class ImageVariableOverlay: ConstraintLayout {
_buttonSelect = findViewById(R.id.button_select); _buttonSelect = findViewById(R.id.button_select);
_recyclerPresets = findViewById<RecyclerView>(R.id.recycler_presets).asAny(_presets, RecyclerView.HORIZONTAL) { _recyclerPresets = findViewById<RecyclerView>(R.id.recycler_presets).asAny(_presets, RecyclerView.HORIZONTAL) {
it.onClick.subscribe { it.onClick.subscribe {
_selected = ImageVariable(null, it.id); _selected = ImageVariable.fromPresetName(it.name);
updateSelected(); updateSelected();
}; };
}; };
...@@ -153,8 +149,9 @@ class ImageVariableOverlay: ConstraintLayout { ...@@ -153,8 +149,9 @@ class ImageVariableOverlay: ConstraintLayout {
fun updateSelected() { fun updateSelected() {
val id = _selected?.resId; val id = _selected?.resId;
val name = _selected?.presetName;
val url = _selected?.url; val url = _selected?.url;
_presets.forEach { p -> p.active = p.id == id }; _presets.forEach { p -> p.active = p.name == name };
_recyclerPresets.notifyContentChanged(); _recyclerPresets.notifyContentChanged();
_creators.forEach { p -> p.active = p.channel.thumbnail == url }; _creators.forEach { p -> p.active = p.channel.thumbnail == url };
_recyclerCreators.notifyContentChanged(); _recyclerCreators.notifyContentChanged();
...@@ -199,7 +196,7 @@ class ImageVariableOverlay: ConstraintLayout { ...@@ -199,7 +196,7 @@ class ImageVariableOverlay: ConstraintLayout {
private val view = _view as LinearLayout; private val view = _view as LinearLayout;
private val imageView = ShapeableImageView(viewGroup.context); private val imageView = ShapeableImageView(viewGroup.context);
private var value: PresetImage = PresetImage(0, false); private var value: PresetImage = PresetImage(0, "", false);
val onClick = Event1<PresetImage>(); val onClick = Event1<PresetImage>();
init { init {
...@@ -233,5 +230,5 @@ class ImageVariableOverlay: ConstraintLayout { ...@@ -233,5 +230,5 @@ class ImageVariableOverlay: ConstraintLayout {
} }
} }
data class PresetImage(var id: Int, var active: Boolean); data class PresetImage(var id: Int, var name: String, var active: Boolean);
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment