Skip to content

Commit

Permalink
Merge pull request #3 from RedMadRobot/feature/strings_support_for_fl…
Browse files Browse the repository at this point in the history
…ipper

StringValue support for the flipper plugin
  • Loading branch information
Roman Choriev authored Dec 29, 2022
2 parents 27899b4 + 76637cf commit 34d3878
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 19 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

### [v 0.7.4][last-release]
### v 0.7.5
### [Changelog][changelog]

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

[MIT][license]


[last-release]:https://github.com/RedMadRobot/debug-panel-android/releases/tag/0.7.4
[plugin-development-doc]:docs/plugin_development.md
[changelog]: docs/changelog.md
[license]: LICENSE
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog


## 0.7.5
### Изменения
* Добавлена поддержка строк для плагина Flipper.
Теперь их можно указывать в качестве изменяемых значений.

## 0.7.4
### Изменения
* Добавлена конфигурация для публикации в публичный Maven
Expand Down
2 changes: 1 addition & 1 deletion gradle/publish.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ sonatype_repo=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2
license_name=MIT License
license_url=http://opensource.org/licenses/MIT

lib_version=0.7.4
lib_version=0.7.5
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.redmadrobot.flipper.config.FlipperValue
import com.redmadrobot.flipper_plugin.databinding.ItemFlipperFeatureBooleanBinding
import com.redmadrobot.flipper_plugin.databinding.ItemFlipperFeatureGroupBinding
import com.redmadrobot.flipper_plugin.databinding.ItemFlipperFeatureStringBinding
import com.redmadrobot.flipper_plugin.ui.data.FlipperItem
import com.redmadrobot.flipper_plugin.ui.data.FlipperItem.Feature
import com.redmadrobot.flipper_plugin.ui.data.FlipperItem.Group
Expand All @@ -26,6 +27,7 @@ internal class FlipperFeaturesAdapter(
is Feature -> {
when (item.value) {
is FlipperValue.BooleanValue -> ViewType.BOOLEAN.ordinal
is FlipperValue.StringValue -> ViewType.STRING.ordinal
else -> error("FlipperValue ${item.value::class} not supported")
}
}
Expand All @@ -35,14 +37,14 @@ internal class FlipperFeaturesAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (ViewType.values()[viewType]) {
ViewType.BOOLEAN -> {
val featureBinding = ItemFlipperFeatureBooleanBinding.inflate(
val binding = ItemFlipperFeatureBooleanBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)

BooleanFeatureViewHolder(
itemView = featureBinding.root,
itemView = binding.root,
onFeatureValueChanged = onFeatureValueChanged::invoke,
)
}
Expand All @@ -61,6 +63,19 @@ internal class FlipperFeaturesAdapter(
)
}

ViewType.STRING -> {
val binding = ItemFlipperFeatureStringBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)

StringFeatureViewHolder(
itemView = binding.root,
onFeatureValueChanged = onFeatureValueChanged::invoke,
)
}

else -> throw IllegalStateException("Can't create viewHolder for given viewType")
}
}
Expand All @@ -87,11 +102,24 @@ internal class FlipperFeaturesAdapter(
description = booleanItem.description,
)
}

ViewType.STRING -> {
val booleanItem = item as Feature
val stringHolder = holder as StringFeatureViewHolder

stringHolder.bind(
featureId = booleanItem.id,
value = booleanItem.value as FlipperValue.StringValue,
editable = booleanItem.editable,
description = booleanItem.description,
)
}
}
}

private enum class ViewType {
GROUP,
BOOLEAN,
STRING
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.redmadrobot.flipper_plugin.ui.recycler

import android.view.View
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.redmadrobot.flipper.config.FlipperValue
import com.redmadrobot.flipper_plugin.databinding.ItemFlipperFeatureStringBinding

internal class StringFeatureViewHolder(
itemView: View,
private val onFeatureValueChanged: (feature: String, value: FlipperValue) -> Unit,
) : RecyclerView.ViewHolder(itemView) {

private val binding = ItemFlipperFeatureStringBinding.bind(itemView)

fun bind(
featureId: String,
value: FlipperValue.StringValue,
description: String,
editable: Boolean,
) = with(binding) {

flipperPluginValue.apply {
setText(value.value)
isEnabled = editable
clearFocus()
}
flipperPluginValueLabel.text = description

flipperPluginUpdate.setOnClickListener {
onFeatureValueChanged(featureId, FlipperValue.StringValue(flipperPluginValue.text.toString()))
flipperPluginValue.clearFocus()
}

flipperPluginValue.setOnFocusChangeListener { _, hasFocus ->
flipperPluginUpdate.isVisible = hasFocus
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginStart="8dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:paddingBottom="8dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:orientation="vertical">

<TextView
android:id="@+id/flipper_plugin_value_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="8dp"
android:textColor="@color/black"
tools:text="[Label]" />

<com.google.android.material.textfield.TextInputLayout
app:layout_constraintTop_toBottomOf="@+id/flipper_plugin_value_label"
android:id="@+id/flipper_plugin_value_container"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="@string/flipper_plugin_value">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/flipper_plugin_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black" />
</com.google.android.material.textfield.TextInputLayout>

<Button
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/flipper_plugin_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="16dp"
android:minHeight="0dp"
android:visibility="gone"
android:text="@string/flipper_plugin_update" />
</androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.material.card.MaterialCardView>
2 changes: 2 additions & 0 deletions plugins/flipper-plugin/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<string name="flipper_plugin_dialog_title_feature_toggles_reset">Сбросить все тоглы на состояние по-умолчанию?</string>
<string name="flipper_plugin_button_switch_source">Выбрать источник</string>
<string name="flipper_plugin_clear_changes">Сбросить изменения</string>
<string name="flipper_plugin_update">Update</string>
<string name="flipper_plugin_value">value</string>
</resources>
16 changes: 8 additions & 8 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ dependencies {
// debugImplementation(project(":plugins:app-settings-plugin"))
// debugImplementation(project(":plugins:flipper-plugin"))
// debugImplementation(project(":plugins:variable-plugin"))

debugImplementation("com.redmadrobot.debug:panel-core:0.7.4")
debugImplementation("com.redmadrobot.debug:accounts-plugin:0.7.4")
debugImplementation("com.redmadrobot.debug:servers-plugin:0.7.4")
debugImplementation("com.redmadrobot.debug:app-settings-plugin:0.7.4")
debugImplementation("com.redmadrobot.debug:flipper-plugin:0.7.4")
debugImplementation("com.redmadrobot.debug:variable-plugin:0.7.4")
//
debugImplementation("com.redmadrobot.debug:panel-core:0.7.5")
debugImplementation("com.redmadrobot.debug:accounts-plugin:0.7.5")
debugImplementation("com.redmadrobot.debug:servers-plugin:0.7.5")
debugImplementation("com.redmadrobot.debug:app-settings-plugin:0.7.5")
debugImplementation("com.redmadrobot.debug:flipper-plugin:0.7.5")
debugImplementation("com.redmadrobot.debug:variable-plugin:0.7.5")

//No-op dependency
// releaseImplementation(project(":debug-panel-no-op"))
releaseImplementation("com.redmadrobot.debug:panel-no-op:0.7.4")
releaseImplementation("com.redmadrobot.debug:panel-no-op:0.7.5")

implementation("com.squareup.retrofit2:retrofit:2.7.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ internal class DebugFlipperFeaturesProvider : DebugDataProvider<List<PluginToggl
)
)

toggles.add(
PluginToggle(
id = "id4",
group = "True keen",
value = FlipperValue.StringValue("Test string"),
description = "String toggle",
)
)

val debugRandom = Random(282)
(4..20).forEach { index ->
toggles.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class MainActivity : AppCompatActivity() {

setContentView(R.layout.activity_main)
setViews()

observeFeatureToggles()

DebugPanel.subscribeToEvents(this) { event ->
Expand Down Expand Up @@ -157,6 +156,7 @@ class MainActivity : AppCompatActivity() {
"id1" to FlipperValue.BooleanValue(true),
"id2" to FlipperValue.BooleanValue(false),
"id3" to FlipperValue.BooleanValue(true),
"id4" to FlipperValue.StringValue("String toggle"),
)
)

Expand Down
4 changes: 0 additions & 4 deletions version.properties

This file was deleted.

0 comments on commit 34d3878

Please sign in to comment.