Skip to content

Commit

Permalink
Improve chat_view.xml layout preview
Browse files Browse the repository at this point in the history
These changes were made specifically to preview chat_view.xml. Here are some key points:
- AppBarView and its sub-views were throwing NullPointException because of `Dependencies.localeProvider`
- Added dummy content for the `GvaChipGroup` view
  • Loading branch information
gugalo committed Nov 6, 2024
1 parent bf879e3 commit ac4fe4d
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 29 deletions.
9 changes: 9 additions & 0 deletions widgetssdk/src/main/java/com/glia/widgets/chat/GvaChip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ internal class GvaChipGroup @JvmOverloads constructor(
isSelectionRequired = false
isSingleLine = false
isSingleSelection = false

if (isInEditMode) {
// Add dummy content to show on Studio layout previews
setButtons(listOf(
GvaButton(text = "GVA Option 1"),
GvaButton(text = "GVA Option 2"),
GvaButton(text = "GVA Option 3")
))
}
}

internal fun updateTheme(theme: UiTheme?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.airbnb.lottie.LottieAnimationView
import com.airbnb.lottie.LottieProperty
import com.airbnb.lottie.model.KeyPath
import com.glia.widgets.di.Dependencies
import com.glia.widgets.locale.LocaleProvider
import com.glia.widgets.locale.LocaleString
import com.glia.widgets.locale.StringKeyPair
import com.google.android.material.button.MaterialButton
Expand Down Expand Up @@ -213,7 +214,7 @@ internal fun View.removeAccessibilityClickAction() {
}

private fun View.registerLocaleListener(@StringRes stringKey: Int, vararg values: StringKeyPair, listener: (String) -> Unit) {
val localeManager = Dependencies.localeProvider
val localeManager = if (isInEditMode) LocaleProvider(ResourceProvider(context)) else Dependencies.localeProvider
val disposable = localeManager.getLocaleObservable()
.startWithItem("stub")
.map { localeManager.getString(stringKey, values.toList()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import com.glia.widgets.R;
import com.glia.widgets.UiTheme;
import com.glia.widgets.di.Dependencies;
import com.glia.widgets.helper.Logger;
import com.glia.widgets.helper.ResourceProvider;
import com.glia.widgets.view.configuration.ButtonConfiguration;
import com.glia.widgets.view.configuration.TextConfiguration;
import com.google.android.material.button.MaterialButton;
Expand All @@ -17,6 +19,7 @@ public abstract class BaseConfigurableButton extends MaterialButton {
private final String TAG = BaseConfigurableButton.class.getSimpleName();

private ButtonConfiguration buttonConfiguration;
private final ResourceProvider resourceProvider;

public abstract ButtonConfiguration getButtonConfigurationFromTheme(UiTheme theme);

Expand All @@ -30,6 +33,12 @@ public BaseConfigurableButton(Context context, AttributeSet attrs) {

public BaseConfigurableButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
if (isInEditMode()) {
resourceProvider = new ResourceProvider(getContext());
} else {
resourceProvider = Dependencies.getResourceProvider();
}

createBuildTimeConfiguration();
updateView();
}
Expand Down Expand Up @@ -71,15 +80,15 @@ private void createBuildTimeConfiguration() {
.textColorHighlight(getHighlightColor())
.hintColor(getHintTextColors())
.textSize(getTextSize())
.build();
.build(resourceProvider);

buttonConfiguration = ButtonConfiguration
.builder()
.textConfiguration(textConfiguration)
.backgroundColor(getBackgroundTintList())
.strokeColor(getStrokeColor())
.strokeWidth(getStrokeWidth())
.build();
.build(resourceProvider);
}

@Deprecated
Expand All @@ -97,7 +106,7 @@ public void setTheme(UiTheme theme) {
builder.strokeColor(runTimeConfiguration.getStrokeColor());
if (runTimeConfiguration.getStrokeWidth() != null)
builder.strokeWidth(runTimeConfiguration.getStrokeWidth());
buttonConfiguration = builder.build();
buttonConfiguration = builder.build(resourceProvider);
updateView();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import androidx.annotation.Nullable;

import com.glia.widgets.R;
import com.glia.widgets.di.Dependencies;
import com.glia.widgets.helper.Logger;
import com.glia.widgets.helper.ResourceProvider;

Expand Down Expand Up @@ -143,13 +142,12 @@ public Builder textConfiguration(TextConfiguration textConfiguration) {
return this;
}

public ButtonConfiguration build() {
public ButtonConfiguration build(ResourceProvider resourceProvider) {
Logger.logDeprecatedClassUse(ButtonConfiguration.class.getSimpleName() + "." + TAG);
if (textConfiguration == null) {
ResourceProvider resourceProvider = Dependencies.getResourceProvider();
textConfiguration = new TextConfiguration.Builder()
.textColor(resourceProvider.getColorStateList(R.color.glia_base_light_color))
.build();
.build(resourceProvider);
}
return new ButtonConfiguration(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private TextConfiguration prepareDefaultTextConfiguration(ResourceProvider resou
return new TextConfiguration.Builder()
.textColor(resourceProvider.getColorStateList(textColor))
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_text_size))
.build();
.build(resourceProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.os.Parcelable;

import com.glia.widgets.R;
import com.glia.widgets.di.Dependencies;
import com.glia.widgets.helper.Logger;
import com.glia.widgets.helper.ResourceProvider;

Expand Down Expand Up @@ -152,9 +151,8 @@ public Builder allCaps(Boolean allCaps) {
return this;
}

public TextConfiguration build() {
public TextConfiguration build(ResourceProvider resourceProvider) {
Logger.logDeprecatedClassUse(TextConfiguration.class.getSimpleName() + "." + TAG);
ResourceProvider resourceProvider = Dependencies.getResourceProvider();
// Default configuration
if (this.textSize == 0) {
this.textSize = resourceProvider.getDimension(R.dimen.glia_survey_default_text_size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ private OptionButtonConfiguration prepareDefaultButtonConfiguration(ResourceProv
TextConfiguration normalText = new TextConfiguration.Builder()
.textColor(normalTextColor)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_text_size))
.build();
.build(resourceProvider);
TextConfiguration selectedText = new TextConfiguration.Builder()
.textColor(selectedTextColor)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_text_size))
.build();
.build(resourceProvider);
TextConfiguration highlightedText = new TextConfiguration.Builder()
.textColor(normalTextColor)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_text_size))
.build();
.build(resourceProvider);

LayerConfiguration normalLayer = new LayerConfiguration.Builder()
.backgroundColor(resourceProvider.getString(R.color.glia_base_light_color))
Expand Down Expand Up @@ -124,7 +124,7 @@ private TextConfiguration prepareDefaultTitleConfiguration(ResourceProvider reso
.textColor(normalTextColor)
.bold(true)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_title_text_size))
.build();
.build(resourceProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private TextConfiguration prepareDefaultTitleConfiguration(ResourceProvider reso
.textColor(color)
.bold(true)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_title_text_size))
.build();
.build(resourceProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ private OptionButtonConfiguration prepareDefaultButtonConfiguration(ResourceProv
TextConfiguration normalText = new TextConfiguration.Builder()
.textColor(normalTextColor)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_text_size))
.build();
.build(resourceProvider);
TextConfiguration selectedText = new TextConfiguration.Builder()
.textColor(selectedTextColor)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_text_size))
.build();
.build(resourceProvider);
TextConfiguration highlightedText = new TextConfiguration.Builder()
.textColor(normalTextColor)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_text_size))
.build();
.build(resourceProvider);

LayerConfiguration normalLayer = new LayerConfiguration.Builder()
.backgroundColor(resourceProvider.getString(R.color.glia_base_light_color))
Expand Down Expand Up @@ -125,7 +125,7 @@ private TextConfiguration prepareDefaultTitleConfiguration(ResourceProvider reso
.textColor(normalTextColor)
.bold(true)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_title_text_size))
.build();
.build(resourceProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private TextConfiguration prepareDefaultTextConfiguration(ResourceProvider resou
return new TextConfiguration.Builder()
.textColor(optionTextColor)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_text_size))
.build();
.build(resourceProvider);
}

private TextConfiguration prepareDefaultTitleConfiguration(ResourceProvider resourceProvider) {
Expand All @@ -109,7 +109,7 @@ private TextConfiguration prepareDefaultTitleConfiguration(ResourceProvider reso
.textColor(titleColor)
.bold(true)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_text_size))
.build();
.build(resourceProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,19 @@ private ButtonConfiguration prepareDefaultButtonConfiguration(ResourceProvider r
int backgroundColorId) {
ColorStateList buttonTexColor = resourceProvider.getColorStateList(R.color.glia_base_light_color);
TextConfiguration textConfiguration =
new TextConfiguration.Builder().textColor(buttonTexColor).build();
new TextConfiguration.Builder().textColor(buttonTexColor).build(resourceProvider);
return new ButtonConfiguration.Builder()
.backgroundColor(resourceProvider.getColorStateList(backgroundColorId))
.textConfiguration(textConfiguration)
.build();
.build(resourceProvider);
}

private TextConfiguration prepareDefaultTitleConfiguration(ResourceProvider resourceProvider) {
ColorStateList color = resourceProvider.getColorStateList(R.color.glia_base_dark_color);
return new TextConfiguration.Builder()
.textColor(color)
.textSize(resourceProvider.getDimension(R.dimen.glia_survey_default_survey_title_text_size))
.build();
.build(resourceProvider);
}

private LayerConfiguration prepareDefaultBackgroundConfiguration(ResourceProvider resourceProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.glia.widgets.R
import com.glia.widgets.UiTheme
import com.glia.widgets.databinding.AppBarBinding
import com.glia.widgets.di.Dependencies
import com.glia.widgets.helper.ResourceProvider
import com.glia.widgets.helper.Utils
import com.glia.widgets.helper.applyButtonTheme
import com.glia.widgets.helper.applyIconColorTheme
Expand All @@ -29,6 +30,7 @@ import com.glia.widgets.helper.setLocaleNavigationContentDescription
import com.glia.widgets.helper.setLocaleText
import com.glia.widgets.helper.setText
import com.glia.widgets.helper.setTintCompat
import com.glia.widgets.locale.LocaleProvider
import com.glia.widgets.locale.LocaleString
import com.glia.widgets.view.unifiedui.applyButtonTheme
import com.glia.widgets.view.unifiedui.applyColorTheme
Expand All @@ -49,7 +51,13 @@ internal class AppBarView @JvmOverloads constructor(

@DrawableRes
private var iconAppBarBackRes: Int? = null
private val localeProvider = Dependencies.localeProvider
private val localeProvider by lazy {
if (isInEditMode) {
LocaleProvider(ResourceProvider(context))
} else {
Dependencies.localeProvider
}
}

init {
setDefaults(attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import com.glia.widgets.R;
import com.glia.widgets.UiTheme;
import com.glia.widgets.di.Dependencies;
import com.glia.widgets.helper.ContextExtensions;
import com.glia.widgets.helper.ResourceProvider;
import com.glia.widgets.view.configuration.TextConfiguration;
import com.google.android.material.textview.MaterialTextView;

Expand All @@ -21,6 +23,7 @@
*/
public abstract class BaseConfigurableTextView extends MaterialTextView {
private TextConfiguration textConfiguration;
private final ResourceProvider resourceProvider;

public BaseConfigurableTextView(@NonNull Context context) {
this(context, null);
Expand All @@ -36,6 +39,12 @@ public BaseConfigurableTextView(@NonNull Context context, @Nullable AttributeSet

public BaseConfigurableTextView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
if (isInEditMode()) {
resourceProvider = new ResourceProvider(getContext());
} else {
resourceProvider = Dependencies.getResourceProvider();
}

createBuildTimeConfiguration();
updateView();
}
Expand All @@ -49,7 +58,7 @@ private void createBuildTimeConfiguration() {
.textColorHighlight(getHighlightColor())
.hintColor(getHintTextColors())
.textSize(ContextExtensions.pxToSp(getContext(), getTextSize()))
.build();
.build(resourceProvider);
}

public void setTheme(UiTheme theme) {
Expand All @@ -69,7 +78,7 @@ public void setTheme(UiTheme theme) {
if (runTimeConfiguration.getFontFamily() != textConfiguration.getFontFamily())
builder.fontFamily(runTimeConfiguration.getFontFamily());

textConfiguration = builder.build();
textConfiguration = builder.build(resourceProvider);
updateView();
}

Expand Down

0 comments on commit ac4fe4d

Please sign in to comment.