Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 067b863

Browse files
committed
documented class
1 parent d52455c commit 067b863

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loadingbutton/src/main/java/com/droidbond/loadingbutton/LoadingButton.kt

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ import android.widget.ImageView
2222
import android.widget.ProgressBar
2323
import android.widget.TextView
2424

25-
25+
/**
26+
* This class is a compound view includes a button, loader , success view and error view
27+
*
28+
* Use this class in your xml descriptor and edit attrs
29+
*
30+
* @param context The Context
31+
* @param attrs the AttributeSet
32+
* @param defStyleAttr the default Style
33+
*/
2634
class LoadingButton @JvmOverloads constructor(
2735
@NonNull context: Context, @Nullable attrs: AttributeSet? = null, defStyleAttr: Int = 0
2836
) : FrameLayout(context, attrs, defStyleAttr) {
@@ -40,6 +48,9 @@ class LoadingButton @JvmOverloads constructor(
4048
initView()
4149
}
4250

51+
/**
52+
* Hides loader and shows text on button
53+
*/
4354
fun hideLoading() {
4455
view.setBackgroundResource(bg)
4556
progressBar.visibility = View.INVISIBLE
@@ -48,6 +59,9 @@ class LoadingButton @JvmOverloads constructor(
4859
Log.d(TAG, "stopLoading: ")
4960
}
5061

62+
/**
63+
* Hides text, loader and shows success icon
64+
*/
5165
fun showSuccess() {
5266
tvText.visibility = View.INVISIBLE
5367
view.setBackgroundResource(bg)
@@ -60,6 +74,9 @@ class LoadingButton @JvmOverloads constructor(
6074
img.setImageResource(R.drawable.ic_done_white_24dp)
6175
}
6276

77+
/**
78+
* Hides text, loader and shows error icon with a red background
79+
*/
6380
fun showError() {
6481
tvText.visibility = View.INVISIBLE
6582

@@ -74,6 +91,9 @@ class LoadingButton @JvmOverloads constructor(
7491
img.setImageResource(R.drawable.ic_warning)
7592
}
7693

94+
/**
95+
* Shows loading animation
96+
*/
7797
fun showLoading() {
7898
view.setBackgroundResource(bg)
7999
progressBar.visibility = View.VISIBLE
@@ -82,6 +102,10 @@ class LoadingButton @JvmOverloads constructor(
82102
Log.d(TAG, "startLoading: ")
83103
}
84104

105+
/**
106+
* Function isLoading() return type Boolean
107+
* @return the state of loader.
108+
*/
85109
fun isLoading(): Boolean {
86110
return progressBar.isShown
87111
}
@@ -95,14 +119,25 @@ class LoadingButton @JvmOverloads constructor(
95119

96120
addView(view)
97121

122+
updateView()
123+
updateLoader()
124+
updatedText()
125+
126+
array.recycle()
127+
}
128+
129+
private fun updateView() {
130+
98131
view.apply {
99132
val customBg = array.getResourceId(R.styleable.app_background, 0)
100133
if (customBg != 0) {
101134
setBackgroundResource(customBg)
102135
bg = customBg
103136
}
104137
}
138+
}
105139

140+
private fun updateLoader() {
106141
progressBar.apply {
107142

108143
var pbSize: Int = array.getInteger(R.styleable.app_progressBarSize, 32)
@@ -117,7 +152,9 @@ class LoadingButton @JvmOverloads constructor(
117152
)
118153
layoutParams = pbParams
119154
}
155+
}
120156

157+
private fun updatedText() {
121158
tvText.apply {
122159
var customText = "Loading Button"
123160
var size = array.getDimension(R.styleable.app_textSize, 14f * Resources.getSystem().displayMetrics.density)
@@ -142,8 +179,6 @@ class LoadingButton @JvmOverloads constructor(
142179
typeface = tf
143180
}
144181
}
145-
146-
array.recycle()
147182
}
148183

149184
}

0 commit comments

Comments
 (0)