Skip to content

Commit 34d3878

Browse files
author
Roman Choriev
authored
Merge pull request #3 from RedMadRobot/feature/strings_support_for_flipper
StringValue support for the flipper plugin
2 parents 27899b4 + 76637cf commit 34d3878

File tree

11 files changed

+157
-19
lines changed

11 files changed

+157
-19
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[Документация по разработке плагинов][plugin-development-doc]
66

7-
### [v 0.7.4][last-release]
7+
### v 0.7.5
88
### [Changelog][changelog]
99

1010
### [!]Важно. Библиотека находится в стадии разработки.
@@ -343,8 +343,6 @@ ServersPlugin(
343343

344344
[MIT][license]
345345

346-
347-
[last-release]:https://github.com/RedMadRobot/debug-panel-android/releases/tag/0.7.4
348346
[plugin-development-doc]:docs/plugin_development.md
349347
[changelog]: docs/changelog.md
350348
[license]: LICENSE

docs/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22

33

4+
## 0.7.5
5+
### Изменения
6+
* Добавлена поддержка строк для плагина Flipper.
7+
Теперь их можно указывать в качестве изменяемых значений.
8+
49
## 0.7.4
510
### Изменения
611
* Добавлена конфигурация для публикации в публичный Maven

gradle/publish.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ sonatype_repo=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2
66
license_name=MIT License
77
license_url=http://opensource.org/licenses/MIT
88

9-
lib_version=0.7.4
9+
lib_version=0.7.5

plugins/flipper-plugin/src/main/kotlin/com/redmadrobot/flipper_plugin/ui/recycler/FlipperFeaturesAdapter.kt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.recyclerview.widget.RecyclerView
77
import com.redmadrobot.flipper.config.FlipperValue
88
import com.redmadrobot.flipper_plugin.databinding.ItemFlipperFeatureBooleanBinding
99
import com.redmadrobot.flipper_plugin.databinding.ItemFlipperFeatureGroupBinding
10+
import com.redmadrobot.flipper_plugin.databinding.ItemFlipperFeatureStringBinding
1011
import com.redmadrobot.flipper_plugin.ui.data.FlipperItem
1112
import com.redmadrobot.flipper_plugin.ui.data.FlipperItem.Feature
1213
import com.redmadrobot.flipper_plugin.ui.data.FlipperItem.Group
@@ -26,6 +27,7 @@ internal class FlipperFeaturesAdapter(
2627
is Feature -> {
2728
when (item.value) {
2829
is FlipperValue.BooleanValue -> ViewType.BOOLEAN.ordinal
30+
is FlipperValue.StringValue -> ViewType.STRING.ordinal
2931
else -> error("FlipperValue ${item.value::class} not supported")
3032
}
3133
}
@@ -35,14 +37,14 @@ internal class FlipperFeaturesAdapter(
3537
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
3638
return when (ViewType.values()[viewType]) {
3739
ViewType.BOOLEAN -> {
38-
val featureBinding = ItemFlipperFeatureBooleanBinding.inflate(
40+
val binding = ItemFlipperFeatureBooleanBinding.inflate(
3941
LayoutInflater.from(parent.context),
4042
parent,
4143
false
4244
)
4345

4446
BooleanFeatureViewHolder(
45-
itemView = featureBinding.root,
47+
itemView = binding.root,
4648
onFeatureValueChanged = onFeatureValueChanged::invoke,
4749
)
4850
}
@@ -61,6 +63,19 @@ internal class FlipperFeaturesAdapter(
6163
)
6264
}
6365

66+
ViewType.STRING -> {
67+
val binding = ItemFlipperFeatureStringBinding.inflate(
68+
LayoutInflater.from(parent.context),
69+
parent,
70+
false
71+
)
72+
73+
StringFeatureViewHolder(
74+
itemView = binding.root,
75+
onFeatureValueChanged = onFeatureValueChanged::invoke,
76+
)
77+
}
78+
6479
else -> throw IllegalStateException("Can't create viewHolder for given viewType")
6580
}
6681
}
@@ -87,11 +102,24 @@ internal class FlipperFeaturesAdapter(
87102
description = booleanItem.description,
88103
)
89104
}
105+
106+
ViewType.STRING -> {
107+
val booleanItem = item as Feature
108+
val stringHolder = holder as StringFeatureViewHolder
109+
110+
stringHolder.bind(
111+
featureId = booleanItem.id,
112+
value = booleanItem.value as FlipperValue.StringValue,
113+
editable = booleanItem.editable,
114+
description = booleanItem.description,
115+
)
116+
}
90117
}
91118
}
92119

93120
private enum class ViewType {
94121
GROUP,
95122
BOOLEAN,
123+
STRING
96124
}
97125
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.redmadrobot.flipper_plugin.ui.recycler
2+
3+
import android.view.View
4+
import androidx.core.view.isVisible
5+
import androidx.recyclerview.widget.RecyclerView
6+
import com.redmadrobot.flipper.config.FlipperValue
7+
import com.redmadrobot.flipper_plugin.databinding.ItemFlipperFeatureStringBinding
8+
9+
internal class StringFeatureViewHolder(
10+
itemView: View,
11+
private val onFeatureValueChanged: (feature: String, value: FlipperValue) -> Unit,
12+
) : RecyclerView.ViewHolder(itemView) {
13+
14+
private val binding = ItemFlipperFeatureStringBinding.bind(itemView)
15+
16+
fun bind(
17+
featureId: String,
18+
value: FlipperValue.StringValue,
19+
description: String,
20+
editable: Boolean,
21+
) = with(binding) {
22+
23+
flipperPluginValue.apply {
24+
setText(value.value)
25+
isEnabled = editable
26+
clearFocus()
27+
}
28+
flipperPluginValueLabel.text = description
29+
30+
flipperPluginUpdate.setOnClickListener {
31+
onFeatureValueChanged(featureId, FlipperValue.StringValue(flipperPluginValue.text.toString()))
32+
flipperPluginValue.clearFocus()
33+
}
34+
35+
flipperPluginValue.setOnFocusChangeListener { _, hasFocus ->
36+
flipperPluginUpdate.isVisible = hasFocus
37+
}
38+
}
39+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
xmlns:app="http://schemas.android.com/apk/res-auto"
7+
android:layout_marginStart="8dp"
8+
android:layout_marginTop="2dp"
9+
android:layout_marginEnd="8dp"
10+
android:layout_marginBottom="4dp"
11+
android:paddingBottom="8dp">
12+
13+
<androidx.constraintlayout.widget.ConstraintLayout
14+
android:layout_width="match_parent"
15+
android:layout_height="match_parent"
16+
android:layout_marginStart="16dp"
17+
android:layout_marginTop="8dp"
18+
android:layout_marginEnd="16dp"
19+
android:layout_marginBottom="8dp"
20+
android:orientation="vertical">
21+
22+
<TextView
23+
android:id="@+id/flipper_plugin_value_label"
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
app:layout_constraintTop_toTopOf="parent"
27+
app:layout_constraintStart_toStartOf="parent"
28+
android:layout_marginTop="8dp"
29+
android:textColor="@color/black"
30+
tools:text="[Label]" />
31+
32+
<com.google.android.material.textfield.TextInputLayout
33+
app:layout_constraintTop_toBottomOf="@+id/flipper_plugin_value_label"
34+
android:id="@+id/flipper_plugin_value_container"
35+
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
36+
android:layout_width="match_parent"
37+
android:layout_height="wrap_content"
38+
android:layout_marginTop="16dp"
39+
android:hint="@string/flipper_plugin_value">
40+
41+
<com.google.android.material.textfield.TextInputEditText
42+
android:id="@+id/flipper_plugin_value"
43+
android:layout_width="match_parent"
44+
android:layout_height="wrap_content"
45+
android:textColor="@color/black" />
46+
</com.google.android.material.textfield.TextInputLayout>
47+
48+
<Button
49+
app:layout_constraintTop_toTopOf="parent"
50+
app:layout_constraintEnd_toEndOf="parent"
51+
android:id="@+id/flipper_plugin_update"
52+
android:layout_width="wrap_content"
53+
android:layout_height="wrap_content"
54+
android:layout_gravity="end"
55+
android:layout_marginEnd="16dp"
56+
android:minHeight="0dp"
57+
android:visibility="gone"
58+
android:text="@string/flipper_plugin_update" />
59+
</androidx.constraintlayout.widget.ConstraintLayout>
60+
61+
</com.google.android.material.card.MaterialCardView>

plugins/flipper-plugin/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
<string name="flipper_plugin_dialog_title_feature_toggles_reset">Сбросить все тоглы на состояние по-умолчанию?</string>
44
<string name="flipper_plugin_button_switch_source">Выбрать источник</string>
55
<string name="flipper_plugin_clear_changes">Сбросить изменения</string>
6+
<string name="flipper_plugin_update">Update</string>
7+
<string name="flipper_plugin_value">value</string>
68
</resources>

sample/build.gradle.kts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ dependencies {
5656
// debugImplementation(project(":plugins:app-settings-plugin"))
5757
// debugImplementation(project(":plugins:flipper-plugin"))
5858
// debugImplementation(project(":plugins:variable-plugin"))
59-
60-
debugImplementation("com.redmadrobot.debug:panel-core:0.7.4")
61-
debugImplementation("com.redmadrobot.debug:accounts-plugin:0.7.4")
62-
debugImplementation("com.redmadrobot.debug:servers-plugin:0.7.4")
63-
debugImplementation("com.redmadrobot.debug:app-settings-plugin:0.7.4")
64-
debugImplementation("com.redmadrobot.debug:flipper-plugin:0.7.4")
65-
debugImplementation("com.redmadrobot.debug:variable-plugin:0.7.4")
59+
//
60+
debugImplementation("com.redmadrobot.debug:panel-core:0.7.5")
61+
debugImplementation("com.redmadrobot.debug:accounts-plugin:0.7.5")
62+
debugImplementation("com.redmadrobot.debug:servers-plugin:0.7.5")
63+
debugImplementation("com.redmadrobot.debug:app-settings-plugin:0.7.5")
64+
debugImplementation("com.redmadrobot.debug:flipper-plugin:0.7.5")
65+
debugImplementation("com.redmadrobot.debug:variable-plugin:0.7.5")
6666

6767
//No-op dependency
6868
// releaseImplementation(project(":debug-panel-no-op"))
69-
releaseImplementation("com.redmadrobot.debug:panel-no-op:0.7.4")
69+
releaseImplementation("com.redmadrobot.debug:panel-no-op:0.7.5")
7070

7171
implementation("com.squareup.retrofit2:retrofit:2.7.1")
7272
}

sample/src/debug/kotlin/com/redmadrobot/debug_sample/debug_data/DebugFlipperFeaturesProvider.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ internal class DebugFlipperFeaturesProvider : DebugDataProvider<List<PluginToggl
3939
)
4040
)
4141

42+
toggles.add(
43+
PluginToggle(
44+
id = "id4",
45+
group = "True keen",
46+
value = FlipperValue.StringValue("Test string"),
47+
description = "String toggle",
48+
)
49+
)
50+
4251
val debugRandom = Random(282)
4352
(4..20).forEach { index ->
4453
toggles.add(

sample/src/main/kotlin/com/redmadrobot/debug_sample/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class MainActivity : AppCompatActivity() {
3535

3636
setContentView(R.layout.activity_main)
3737
setViews()
38-
3938
observeFeatureToggles()
4039

4140
DebugPanel.subscribeToEvents(this) { event ->
@@ -157,6 +156,7 @@ class MainActivity : AppCompatActivity() {
157156
"id1" to FlipperValue.BooleanValue(true),
158157
"id2" to FlipperValue.BooleanValue(false),
159158
"id3" to FlipperValue.BooleanValue(true),
159+
"id4" to FlipperValue.StringValue("String toggle"),
160160
)
161161
)
162162

0 commit comments

Comments
 (0)