Skip to content

Commit

Permalink
Merge branch 'develop' into 28_layout_onboarding_screen
Browse files Browse the repository at this point in the history
# Conflicts:
#	uikit/src/main/res/values/dimens.xml
  • Loading branch information
GoetzDeBouville committed May 14, 2024
2 parents 5dfcf38 + cf4d431 commit a2cf387
Show file tree
Hide file tree
Showing 14 changed files with 419 additions and 8 deletions.
175 changes: 175 additions & 0 deletions uikit/src/main/java/com/davai/uikit/ButtonView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package com.davai.uikit

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.widget.FrameLayout
import android.widget.ProgressBar
import android.widget.TextView

class ButtonView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {
private var buttonText: String
private var buttonEnabled: Boolean
private var buttonLoading: Boolean
private val frame: View
private val textView: TextView
private val progressBar: ProgressBar
private var buttonViewType: Int

init {
val typedArray = context.obtainStyledAttributes(
attrs,
R.styleable.PrimaryButtonView,
defStyleAttr,
defStyleRes
)
buttonText = typedArray.getString(R.styleable.PrimaryButtonView_button_text) ?: ""
buttonEnabled = typedArray.getBoolean(R.styleable.PrimaryButtonView_button_enabled, true)
buttonLoading = typedArray.getBoolean(R.styleable.PrimaryButtonView_button_loading, false)
buttonViewType = typedArray.getInt(R.styleable.PrimaryButtonView_button_view_type, 1)
typedArray.recycle()
LayoutInflater.from(context).inflate(R.layout.button_view, this)
frame = findViewById<View>(R.id.frame)
textView = findViewById<TextView>(R.id.text_view)
progressBar = findViewById<ProgressBar>(R.id.progress_bar)
setButtonViewType(ButtonViewType.getButtonViewType(buttonViewType))
}

fun setButtonText(text: String) {
buttonText = text
when (buttonViewType) {
1 -> {
if (progressBar.visibility != View.VISIBLE) {
textView.text = text
}
}

2 -> {
if (progressBar.visibility != View.VISIBLE && textView.isEnabled) {
textView.text = text
}
}
}
}

fun setButtonEnabled(isEnabled: Boolean) {
buttonEnabled = isEnabled
textView.isEnabled = isEnabled
if (buttonViewType == 2) {
if (textView.isEnabled) {
textView.text = buttonText
} else {
textView.text = ""
}
}
}

fun setLoading(loading: Boolean) {
buttonLoading = loading
if (loading) {
textView.text = ""
progressBar.visibility = View.VISIBLE
} else {
textView.text = buttonText
progressBar.visibility = View.GONE
}
}

override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
return when (ev?.action) {
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_UP -> {
return buttonEnabled && !buttonLoading
}

else -> {
false
}
}
}

override fun onTouchEvent(event: MotionEvent?): Boolean {
return when (event?.action) {
MotionEvent.ACTION_DOWN -> {
when (buttonViewType) {
1 -> {
frame.visibility = View.VISIBLE
}

2 -> {
textView.setTextColor(
resources.getColor(
R.color.text_caption_dark,
context.theme
)
)
}
}
true
}

MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_UP -> {
when (buttonViewType) {
1 -> {
frame.visibility = View.INVISIBLE
}

2 -> {
textView.setTextColor(resources.getColor(R.color.text_base, context.theme))
}
}
performClick()
true
}

else -> {
super.onTouchEvent(event)
}
}
}

fun setButtonViewType(type: ButtonViewType) {
when (type) {
ButtonViewType.PRIMARY -> {
buttonViewType = 1
}

ButtonViewType.SECONDARY -> {
buttonViewType = 2
frame.visibility = View.GONE
textView.setTextAppearance(R.style.Text_Base_Button_Bold)
textView.setTextColor(resources.getColor(R.color.text_base, context.theme))
textView.setBackgroundColor(
resources.getColor(
android.R.color.transparent,
context.theme
)
)
}
}
setButtonText(buttonText)
setButtonEnabled(buttonEnabled)
setLoading(buttonLoading)
}

enum class ButtonViewType {
PRIMARY,
SECONDARY;

companion object {
fun getButtonViewType(typeInt: Int): ButtonViewType =
if (typeInt == 1) {
PRIMARY
} else {
SECONDARY
}

}
}
}
5 changes: 5 additions & 0 deletions uikit/src/main/res/drawable/button_background_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_internal_background_enabled" android:state_enabled="true" />
<item android:drawable="@drawable/button_internal_background_disabled" android:state_enabled="false" />
</selector>
6 changes: 6 additions & 0 deletions uikit/src/main/res/drawable/button_external_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/tertiary_focused" />
<corners android:radius="@dimen/card_radius_16" />
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/tertiary_light_light" />
<corners android:radius="@dimen/card_radius_12" />
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/tertiary_base" />
<corners android:radius="@dimen/card_radius_12" />
</shape>
37 changes: 37 additions & 0 deletions uikit/src/main/res/layout/button_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:clickable="true">

<View
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="@dimen/button_height_frame"
android:layout_gravity="center"
android:background="@drawable/button_external_background"
android:visibility="invisible" />

<TextView
android:id="@+id/text_view"
style="@style/Text.Base.Button.Regular"
android:layout_width="match_parent"
android:layout_height="@dimen/button_height"
android:layout_gravity="center"
android:layout_margin="@dimen/frame"
android:background="@drawable/button_background_selector"
android:ellipsize="end"
android:gravity="center"
android:lines="1"
android:textColor="@color/text_light"
tools:text="[Зарегистрироваться]" />

<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="@dimen/progress_bar"
android:layout_height="@dimen/progress_bar"
android:layout_gravity="center"
android:visibility="gone" />

</FrameLayout>
1 change: 1 addition & 0 deletions uikit/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<color name="tertiary_hover">#434242</color>
<color name="tertiary_focused">#585757</color>
<color name="tertiary_light">#979696</color>
<color name="tertiary_light_light">#DDDDDD</color>

<!-- Icons -->
<color name="icon_primary">#3A3A3A</color>
Expand Down
16 changes: 16 additions & 0 deletions uikit/src/main/res/values/custom_attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,20 @@
<declare-styleable name="MovieCardView">
<attr name="movie_title" format="string" />
</declare-styleable>

<declare-styleable name="PrimaryButtonView">
<attr name="button_text" format="string" />
<attr name="button_enabled" format="boolean" />
<attr name="button_loading" format="boolean" />
<attr name="button_view_type" format="enum">
<enum name="primary" value="1" />
<enum name="secondary" value="2" />
</attr>
</declare-styleable>

<declare-styleable name="SecondaryButtonView">
<attr name="button_text_sec" format="string" />
<attr name="button_enabled_sec" format="boolean" />
<attr name="button_loading_sec" format="boolean" />
</declare-styleable>
</resources>
8 changes: 5 additions & 3 deletions uikit/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<dimen name="footer_item_height_114">114dp</dimen>
<dimen name="session_card_height">240dp</dimen>

<dimen name="elevation_4">4dp</dimen>
<dimen name="elevation_8">8dp</dimen>

<dimen name="padding_4">4dp</dimen>
<dimen name="padding_8">8dp</dimen>
<dimen name="padding_12">12dp</dimen>
Expand All @@ -24,4 +21,9 @@
<dimen name="margin_32">32dp</dimen>
<dimen name="margin_40">40dp</dimen>
<dimen name="margin_72">72dp</dimen>

<dimen name="progress_bar">20dp</dimen>
<dimen name="frame">4dp</dimen>
<dimen name="button_height">48dp</dimen>
<dimen name="button_height_frame">56dp</dimen>
</resources>
3 changes: 3 additions & 0 deletions uikit_sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<activity
android:name=".MoovieCardViewExampleActivity"
android:exported="false" />
<activity
android:name=".ButtonViewExampleActivity"
android:exported="false" />
<activity
android:name=".SessionExample"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.davai.uikit_sample

import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import com.davai.uikit.ButtonView

class ButtonViewExampleActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_button_view_example)

val button1 = findViewById<ButtonView>(R.id.button_1)
val button5 = findViewById<ButtonView>(R.id.button_5)
val button6 = findViewById<ButtonView>(R.id.button_6)
val buttonSec2 = findViewById<ButtonView>(R.id.button_sec_2)
val buttonSec3 = findViewById<ButtonView>(R.id.button_sec_3)
val buttonSec4 = findViewById<ButtonView>(R.id.button_sec_4)

button5.setButtonText("Какой-то текст")
button5.setButtonEnabled(false)
button6.setLoading(true)
button6.setButtonText("Какой-то текст")

buttonSec2.setButtonText("Текст из кода")
buttonSec2.setButtonViewType(ButtonView.ButtonViewType.SECONDARY)
buttonSec3.setButtonText("Текст из кода")
buttonSec3.setButtonEnabled(false)
buttonSec3.setButtonText("Текст из кода 2")
buttonSec4.setLoading(true)
buttonSec4.setButtonText("не должно быть видно")

button1.setOnClickListener {
startActivity(
Intent(
this@ButtonViewExampleActivity,
MovieSelectionExampleActivity::class.java
)
)
}

button5.setOnClickListener {
startActivity(
Intent(
this@ButtonViewExampleActivity,
MovieSelectionExampleActivity::class.java
)
)
}

button5.setOnClickListener {
startActivity(
Intent(
this@ButtonViewExampleActivity,
MovieSelectionExampleActivity::class.java
)
)
}

buttonSec2.setOnClickListener {
startActivity(
Intent(
this@ButtonViewExampleActivity,
MovieSelectionExampleActivity::class.java
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ class MainActivity : AppCompatActivity() {
)
.show()

btnToDvButton -> Toast.makeText(
this@MainActivity,
"ToDvButton",
Toast.LENGTH_SHORT
btnToDvButton -> startActivity(
Intent(
this@MainActivity,
ButtonViewExampleActivity::class.java
)
)
.show()

btnToDvFilm -> startActivity(
Intent(
Expand Down
Loading

0 comments on commit a2cf387

Please sign in to comment.