Skip to content

Commit

Permalink
Merge pull request #278 from natura-cosmeticos/fix/code-warnings
Browse files Browse the repository at this point in the history
[DSY-2540] - Fixes code bugs and warnings generated from Android Studio.
  • Loading branch information
gsleonel authored Jan 21, 2022
2 parents 45aed76 + 39c6124 commit 93f1221
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class Avatar : AbstractComposeView {
}
}

private fun init(attrs: AttributeSet? = null, defStyleAttr: Int = 0) {
private fun init(attrs: AttributeSet? = null) {
if (attrs != null) {
this.attrs = attrs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class BadgeDrawable(
val badgeWith = getDimenFromTheme(R.attr.badgeDotHeight).toInt()

context.resources.getDrawable(R.drawable.badge_dot, context.theme).apply {

setTint(getColorFromTheme(getBackgroundColorByAttr()))
setBounds(
bounds.right - badgeWith,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ class CheckBox : AppCompatCheckBox {
updateDrawable()
}

private lateinit var STATE_INDETERMINATE: IntArray
private lateinit var indeterminateState: IntArray

private fun init() {
updateDrawable()
}

private fun updateDrawable() {
var btnDrawable = R.drawable.checkbox_status_indeterminate
btnDrawable = when (state) {
val btnDrawable: Int = when (state) {
INDETERMINATE -> R.drawable.checkbox_status_indeterminate
UNCHECKED -> R.drawable.checkbox_status_unchecked
CHECKED -> R.drawable.checkbox_status_checked
Expand All @@ -40,9 +39,9 @@ class CheckBox : AppCompatCheckBox {
}

override fun onCreateDrawableState(extraSpace: Int): IntArray {
STATE_INDETERMINATE = intArrayOf(R.attr.state_indeterminate)
indeterminateState = intArrayOf(R.attr.state_indeterminate)
val drawableState = super.onCreateDrawableState(extraSpace + 1)
mergeDrawableStates(drawableState, STATE_INDETERMINATE)
mergeDrawableStates(drawableState, indeterminateState)
return drawableState
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.View
import android.widget.ImageView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.content.res.getIntOrThrow
import androidx.core.content.res.getResourceIdOrThrow
import androidx.core.content.res.getStringOrThrow
Expand Down Expand Up @@ -40,7 +41,7 @@ class IconButton @JvmOverloads constructor(
private var styleAttribute: Int = 0
private var enabledAttribute: Boolean = true

private lateinit var binding: IconButtonBinding
private var binding: IconButtonBinding

init {
try {
Expand Down Expand Up @@ -293,7 +294,7 @@ class IconButton @JvmOverloads constructor(
android.graphics.PorterDuff.Mode.SRC_IN
)
binding.iconButtonRippleBackground.background =
resources.getDrawable(rippleDrawableResourceAttribute, context.theme)
ResourcesCompat.getDrawable(context.resources, rippleDrawableResourceAttribute, context.theme)
}

private fun configureSize() {
Expand All @@ -315,7 +316,7 @@ class IconButton @JvmOverloads constructor(
private fun configureStyle() {
if (styleAttribute != Style.INHERIT.value) {
binding.iconButtonContainer.background =
resources.getDrawable(backgroundDrawableResourceAttribute, context.theme)
ResourcesCompat.getDrawable(context.resources, backgroundDrawableResourceAttribute, context.theme)
binding.iconButtonContainer.elevation = resources.getDimension(elevationResourceAttribute)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.View
import android.widget.RelativeLayout
import androidx.core.content.res.ResourcesCompat
import com.natura.android.R
import com.natura.android.divider.Divider
import com.natura.android.exceptions.MissingThemeException
Expand Down Expand Up @@ -72,7 +73,7 @@ class ListItem @JvmOverloads constructor(
}

fun enableSelectedState() {
this.background = resources.getDrawable(R.color.list_item_color_background_selected, context.theme)
this.background = ResourcesCompat.getDrawable(context.resources, R.color.list_item_color_background_selected, context.theme)
isViewSelected = true
}

Expand All @@ -98,7 +99,7 @@ class ListItem @JvmOverloads constructor(
return
}

this.background = resources.getDrawable(R.drawable.list_item_ripple_background, context.theme)
this.background = ResourcesCompat.getDrawable(context.resources, R.drawable.list_item_ripple_background, context.theme)
allowTouch(true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.natura.android.resources.getDrawableFromTheme

class Logo @JvmOverloads constructor(
context: Context,
private val attrs: AttributeSet? = null,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.widget.ProgressBar
import androidx.core.content.res.ResourcesCompat
import androidx.core.content.res.getResourceIdOrThrow
import com.natura.android.R
import com.natura.android.exceptions.MissingThemeException
Expand Down Expand Up @@ -94,7 +95,7 @@ class ProgressIndicator @JvmOverloads constructor(
private fun configureAppearance() {
if (layerAttribute) {
this.background =
context.resources.getDrawable(R.drawable.progress_indicator_layer, context.theme)
ResourcesCompat.getDrawable(context.resources, R.drawable.progress_indicator_layer, context.theme)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.content.res.getIntOrThrow
import androidx.core.content.res.getResourceIdOrThrow
import androidx.core.content.res.getStringOrThrow
Expand Down Expand Up @@ -191,15 +192,15 @@ class Shortcut @JvmOverloads constructor(
}

private fun setBackgroundContained() {
val background = resources.getDrawable(R.drawable.shortcut_background, null)
val backgroundWrap = DrawableCompat.wrap(background).mutate()
DrawableCompat.setTint(backgroundWrap, ContextCompat.getColor(context, backgroundColorResourceAttribute))
val background = ResourcesCompat.getDrawable(context.resources, R.drawable.shortcut_background, null)
val backgroundWrap = background?.let { DrawableCompat.wrap(it).mutate() }
backgroundWrap?.let { DrawableCompat.setTint(it, ContextCompat.getColor(context, backgroundColorResourceAttribute)) }

backgroundContainer.background = background
}

private fun setBackgroundOutlined() {
val background = resources.getDrawable(R.drawable.shortcut_background, null) as GradientDrawable
val background = ResourcesCompat.getDrawable(context.resources, R.drawable.shortcut_background, null) as GradientDrawable
background.setColor(ContextCompat.getColor(context, backgroundColorResourceAttribute))
background.setStroke(1, ContextCompat.getColor(context, iconColorResourceAttribute))

Expand Down
5 changes: 3 additions & 2 deletions designsystem/src/main/kotlin/com/natura/android/tag/Tag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.content.res.getResourceIdOrThrow
import androidx.core.content.res.getStringOrThrow
import androidx.core.graphics.drawable.DrawableCompat
Expand All @@ -29,7 +30,7 @@ class Tag @JvmOverloads constructor(
private var labelTextColorResourceAttribute = 0
private var tagAttributesArray: TypedArray

private lateinit var binding: TagBinding
private var binding: TagBinding

init {
try {
Expand Down Expand Up @@ -91,7 +92,7 @@ class Tag @JvmOverloads constructor(

private fun setBackground() {
val background: GradientDrawable =
resources.getDrawable(R.drawable.tag_background, null) as GradientDrawable
ResourcesCompat.getDrawable(context.resources, R.drawable.tag_background, null) as GradientDrawable
val backgroundWrap = DrawableCompat.wrap(background).mutate()

val cornerRadius = 50F
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ open class TextField @JvmOverloads constructor(

var stateLayout = LayoutStates(context)

private val SUCCESS_ICON = "EA15"
private val ERROR_ICON = "EA13"

private val inputLabel by lazy { findViewById<TextView>(R.id.text_field_input_label) }

private val inputBox by lazy { findViewById<LinearLayout>(R.id.text_field_input_box) }
Expand Down Expand Up @@ -570,5 +567,8 @@ open class TextField @JvmOverloads constructor(
const val MEDIUMX_PADDING_TOP = 18
const val MEDIUMX_PADDING_BOTTOM = 17
const val MULTILINE_TYPE = 131073

private const val SUCCESS_ICON = "EA15"
private const val ERROR_ICON = "EA13"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:parentTag="android.support.design.widget.NavigationView">
android:layout_gravity="start">

<ExpandableListView
android:id="@+id/navigation_menu"
Expand Down
2 changes: 1 addition & 1 deletion designsystem/src/main/res/layout/ds_expansion_panel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
android:layout_marginEnd="?spacingStandard"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="Collapse Arrow Icon"
android:tint="?colorOnBackground"
app:tint="?colorOnBackground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/ds_expansion_panel_title"
app:layout_constraintTop_toTopOf="@id/ds_expansion_panel_title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AppBarTopActivity : AppCompatActivity() {

setContentView(binding.root)

setSupportActionBar(layoutThreeActionsBinding.appBar.toolbar)
setSupportActionBar(layoutThreeActionsBinding.appBarWithThreeActions.toolbar)

supportActionBar?.setDisplayHomeAsUpEnabled(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import com.natura.android.sample.databinding.ActivityDialogBinding
import com.natura.android.sample.setChosenDefaultTheme

class DialogActivity : AppCompatActivity() {
lateinit var standardDialog: DialogStandard
lateinit var standardDialogVerticalButtons: DialogStandard
lateinit var standardDialogHeaderIconButtons: DialogStandard
lateinit var standardDialogMaxHeight: DialogStandard
lateinit var standardDialogCustomView: DialogStandard
lateinit var standardDialogWithDivider: DialogStandard
lateinit var standardDialogWithOutlinedButton: DialogStandard
lateinit var dialogNoDismissable: DialogStandard

lateinit var alertDialog: DialogAlert
private lateinit var standardDialog: DialogStandard
private lateinit var standardDialogVerticalButtons: DialogStandard
private lateinit var standardDialogHeaderIconButtons: DialogStandard
private lateinit var standardDialogMaxHeight: DialogStandard
private lateinit var standardDialogCustomView: DialogStandard
private lateinit var standardDialogWithDivider: DialogStandard
private lateinit var standardDialogWithOutlinedButton: DialogStandard
private lateinit var dialogNoDismissable: DialogStandard

private lateinit var alertDialog: DialogAlert
private lateinit var binding: ActivityDialogBinding

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/appbartop_button_action.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
app:layout_constraintTop_toTopOf="parent">

<com.natura.android.appbartop.StandardAppBarTop
android:id="@+id/appBar"
android:id="@+id/appBarWithButtonAction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?toolbarDefaultTheme"
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/appbartop_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
app:layout_constraintTop_toTopOf="parent">

<com.natura.android.appbartop.StandardAppBarTop
android:id="@+id/appBar"
android:id="@+id/appBarWithSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?toolbarDefaultTheme"
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/appbartop_threeactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
app:layout_constraintTop_toTopOf="parent">

<com.natura.android.appbartop.StandardAppBarTop
android:id="@+id/appBar"
android:id="@+id/appBarWithThreeActions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?toolbarDefaultTheme"
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/appbartop_title_center.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
app:layout_constraintTop_toTopOf="parent">

<com.natura.android.appbartop.StandardAppBarTop
android:id="@+id/appBarTitleCenter"
android:id="@+id/appBarWithTitleCenter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?toolbarDefaultTheme"
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/appbartop_title_long.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
app:layout_constraintTop_toTopOf="parent">

<com.natura.android.appbartop.StandardAppBarTop
android:id="@+id/appBar"
android:id="@+id/appBarWithTitleLong"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?toolbarDefaultTheme"
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/appbartop_twoactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
app:layout_constraintTop_toTopOf="parent">

<com.natura.android.appbartop.StandardAppBarTop
android:id="@+id/appBar"
android:id="@+id/appBarWithTwoActions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?toolbarDefaultTheme"
Expand Down
10 changes: 6 additions & 4 deletions tools/create_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ npm install markdown-to-document -g --only=prod

for file in $(
find . -path ./fastlane -prune -o \
-name 'README.md' -type f -print
-name 'README.md' -type f -print
find ./doc -iname "*.md" -type f -print
)

do
[[ $file = "./README.md" ]] && BASE_URL="https:\/\/github.com\/natura-cosmeticos\/natds-android\/blob\/master\/" || BASE_URL="https:\/\/github.com\/natura-cosmeticos\/natds-android\/blob\/master\/doc\/"
echo "Working on $file file now"
sed -i "s/](\(.*\).md)/]($BASE_URL\1.md)/g" "$file"
mdtodoc "$file" --dest ./doc/html --layout "page" --theme "github" --numbered-headings --code-copy --mermaid
done

for file in $(find ./doc/html -type f -print)
do
find ./doc/html -type f -print >tmp

while IFS= read -r -d '' file; do
sed -i "s/<a\(.*\)/<a target='_blank'\1/g" "$file"
done
done <tmp
2 changes: 1 addition & 1 deletion tools/finish_emulators.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
adb devices | grep emulator | cut -f1 | while read line; do adb -s "$line" emu kill; done
adb devices | grep emulator | cut -f1 | while read -r line; do adb -s "$line" emu kill; done
7 changes: 0 additions & 7 deletions tools/pipeline_build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion tools/update_icons.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

NATDS_ICON_VERSION="$(grep -o "iconsVersion\s=\s.*" build.gradle | awk '{ print $3 }' | tr -d \''"\')"
NATDS_ICON_VERSION="$(grep -o "iconsVersion\s=\s.*" build.gradle | awk '{ print $3 }' | tr -d \'''\''')"
# get commons from github
domain='https://raw.githubusercontent.com/natura-cosmeticos/natds-commons/@naturacosmeticos/natds-icons@'
path="/packages/natds-icons/dist/"
Expand Down

0 comments on commit 93f1221

Please sign in to comment.