-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 28_layout_onboarding_screen
# Conflicts: # uikit/src/main/res/values/dimens.xml
- Loading branch information
Showing
14 changed files
with
419 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
6 changes: 6 additions & 0 deletions
6
uikit/src/main/res/drawable/button_internal_background_disabled.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
6 changes: 6 additions & 0 deletions
6
uikit/src/main/res/drawable/button_internal_background_enabled.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
uikit_sample/src/main/java/com/davai/uikit_sample/ButtonViewExampleActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.