-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add Progress Dialog
- Loading branch information
Showing
27 changed files
with
449 additions
and
80 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<manifest> | ||
|
||
</manifest> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.rhdev.btechutils | ||
|
||
import android.app.Application | ||
import com.hjq.toast.Toaster | ||
|
||
class Factory private constructor(private val application: Application) { | ||
|
||
companion object { | ||
private var instance: Factory? = null | ||
|
||
fun create(application: Application): Factory { | ||
return instance ?: synchronized(this) { | ||
instance ?: Factory(application).also { instance = it } | ||
} | ||
} | ||
} | ||
|
||
init { | ||
Toaster.init(application) | ||
DarkMode.initialize(application) | ||
} | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
BtechUtils/src/main/java/com/rhdev/btechutils/ProgressDialog.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,89 @@ | ||
package com.rhdev.btechutils | ||
|
||
import android.content.Context | ||
import android.os.Looper | ||
import android.view.LayoutInflater | ||
import androidx.appcompat.app.AlertDialog | ||
import com.google.android.material.button.MaterialButton | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
import com.google.android.material.progressindicator.LinearProgressIndicator | ||
import com.google.android.material.textview.MaterialTextView | ||
|
||
class ProgressDialog(context: Context) { | ||
|
||
private lateinit var onClickCancel: () -> Unit | ||
private var dialog: AlertDialog | ||
private var progressIndicator: LinearProgressIndicator | ||
private var cancelButton: MaterialButton | ||
private var titleTv: MaterialTextView | ||
|
||
init { | ||
val view = LayoutInflater.from(context).inflate(R.layout.dialog_progress, null) | ||
|
||
cancelButton = view.findViewById<MaterialButton?>(R.id.button).apply { | ||
setOnClickListener { | ||
cancel() | ||
} | ||
} | ||
|
||
titleTv = view.findViewById(R.id.title_tv) | ||
|
||
progressIndicator = view.findViewById(R.id.progress_horizontal) | ||
|
||
dialog = MaterialAlertDialogBuilder(context) | ||
.setView(view) | ||
.setCancelable(false) | ||
.create() | ||
} | ||
|
||
fun setMaxProgress(max:Int) :ProgressDialog{ | ||
progressIndicator.max = max | ||
return this | ||
} | ||
fun setOnClickCancelButton(onClickCancel: () -> Unit) :ProgressDialog{ | ||
this@ProgressDialog.onClickCancel = onClickCancel | ||
return this | ||
} | ||
|
||
fun setText(text: String):ProgressDialog { | ||
titleTv.text = text | ||
return this | ||
} | ||
|
||
|
||
|
||
fun show(onShowListener: () -> Unit = {}):ProgressDialog { | ||
dialog.setOnShowListener { | ||
onShowListener() | ||
} | ||
dialog.show() | ||
return this | ||
} | ||
|
||
fun cancel() { | ||
android.os.Handler(Looper.getMainLooper()).post { | ||
onClickCancel() | ||
dialog.dismiss() | ||
} | ||
} | ||
|
||
|
||
fun setIndeterminate():ProgressDialog { | ||
progressIndicator.isIndeterminate = true | ||
return this | ||
} | ||
|
||
fun setProgress(progress: Int) { | ||
android.os.Handler(Looper.getMainLooper()).post { | ||
progressIndicator.apply { | ||
if (progress < 0) { | ||
isIndeterminate = true | ||
} else { | ||
isIndeterminate = false | ||
setProgressCompat(progress, true) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
BtechUtils/src/main/java/com/rhdev/btechutils/ToasterUtils.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,50 @@ | ||
package com.rhdev.btechutils | ||
|
||
import android.view.Gravity | ||
import android.widget.Toast | ||
import com.hjq.toast.ToastParams | ||
import com.hjq.toast.Toaster | ||
import com.hjq.toast.style.CustomToastStyle | ||
|
||
|
||
object ToasterUtils { | ||
|
||
fun show( | ||
text: String, | ||
duration: Int = Toast.LENGTH_SHORT, | ||
gravity: Int = Gravity.BOTTOM, | ||
toastyType: ToastType = ToastType.INFO | ||
) { | ||
val params = | ||
getParams(text = text, duration = duration, toastyType = toastyType, gravity = gravity) | ||
Toaster | ||
.show(params) | ||
} | ||
|
||
private fun getParams( | ||
text: String, | ||
duration: Int, | ||
gravity: Int, | ||
toastyType: ToastType | ||
): ToastParams { | ||
return ToastParams().also { | ||
it.text = text | ||
it.duration = duration | ||
it.style = CustomToastStyle( | ||
when (toastyType) { | ||
ToastType.ERROR -> R.layout.toast_error | ||
ToastType.SUCCESS -> R.layout.toast_success | ||
ToastType.WARNING -> R.layout.toast_warn | ||
ToastType.INFO -> R.layout.toast_info | ||
}, | ||
gravity , 0 , 0 ,0f , 0.075f | ||
) | ||
} | ||
|
||
} | ||
|
||
} | ||
enum class ToastType { | ||
ERROR, INFO, SUCCESS, WARNING | ||
} | ||
|
64 changes: 0 additions & 64 deletions
64
BtechUtils/src/main/java/com/rhdev/btechutils/ToastyUtils.kt
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<solid android:color="@color/toast_error_color" /> | ||
|
||
<corners android:radius="999dp" /> | ||
</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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#FFFFFF" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" /> | ||
</vector> |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<solid android:color="@color/toast_hint_color" /> | ||
|
||
<corners android:radius="999dp" /> | ||
</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,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#FFFFFF" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
|
||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M11,17h2v-6h-2v6zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM11,9h2L13,7h-2v2z" /> | ||
</vector> |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<solid android:color="@color/toast_success_color" /> | ||
|
||
<corners android:radius="999dp" /> | ||
</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,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#FFFFFF" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
|
||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z" /> | ||
</vector> |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<solid android:color="@color/toast_warn_color" /> | ||
|
||
<corners android:radius="999dp" /> | ||
</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,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#FFFFFF" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
|
||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z" /> | ||
</vector> |
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,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:paddingHorizontal="14dp"> | ||
|
||
<com.google.android.material.textview.MaterialTextView | ||
android:id="@+id/title_tv" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="14dp" | ||
android:layout_marginBottom="26dp" | ||
android:text="@string/processing" | ||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" | ||
android:textColor="?colorOutline" | ||
android:visibility="gone" /> | ||
|
||
|
||
<com.google.android.material.progressindicator.LinearProgressIndicator | ||
android:id="@+id/progress_horizontal" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="16dp" | ||
android:max="100" | ||
app:trackCornerRadius="25dp" /> | ||
|
||
<com.google.android.material.button.MaterialButton | ||
android:id="@+id/button" | ||
style="@style/Widget.Material3.Button.TextButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:layout_marginBottom="16dp" | ||
android:text="@string/cancel" /> | ||
|
||
</LinearLayout> |
Oops, something went wrong.