Skip to content

Commit

Permalink
* replace Toasty With Toaster
Browse files Browse the repository at this point in the history
* add Progress Dialog
  • Loading branch information
rahbadev committed Oct 17, 2023
1 parent 784ccb3 commit a709727
Show file tree
Hide file tree
Showing 27 changed files with 449 additions and 80 deletions.
7 changes: 5 additions & 2 deletions BtechUtils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ dependencies {
implementation "androidx.activity:activity-compose"
implementation "androidx.compose.material3:material3"

implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.android.material:material:1.10.0'

// Toasty
implementation 'com.github.GrenderG:Toasty:1.5.2'
// implementation 'com.github.GrenderG:Toasty:1.5.2'

// Toast framework:https://github.com/getActivity/Toaster
implementation 'com.github.getActivity:Toaster:12.5'

// in app review
implementation 'com.google.android.play:review:2.0.1'
Expand Down
2 changes: 1 addition & 1 deletion BtechUtils/src/main/AndroidManifest.xml
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>
2 changes: 1 addition & 1 deletion BtechUtils/src/main/java/com/rhdev/btechutils/DarkMode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object DarkMode {

// ...

fun initialize(context: Context , applyTheme:Boolean) {
fun initialize(context: Context , applyTheme:Boolean = true) {
appContext = context.applicationContext
initModesList()
if (applyTheme) {
Expand Down
23 changes: 23 additions & 0 deletions BtechUtils/src/main/java/com/rhdev/btechutils/Factory.kt
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 BtechUtils/src/main/java/com/rhdev/btechutils/ProgressDialog.kt
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 BtechUtils/src/main/java/com/rhdev/btechutils/ToasterUtils.kt
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 BtechUtils/src/main/java/com/rhdev/btechutils/ToastyUtils.kt

This file was deleted.

7 changes: 7 additions & 0 deletions BtechUtils/src/main/res/drawable/toast_error_bg.xml
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>
11 changes: 11 additions & 0 deletions BtechUtils/src/main/res/drawable/toast_error_ic.xml
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>
7 changes: 7 additions & 0 deletions BtechUtils/src/main/res/drawable/toast_hint_bg.xml
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>
12 changes: 12 additions & 0 deletions BtechUtils/src/main/res/drawable/toast_info_ic.xml
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>
7 changes: 7 additions & 0 deletions BtechUtils/src/main/res/drawable/toast_success_bg.xml
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>
12 changes: 12 additions & 0 deletions BtechUtils/src/main/res/drawable/toast_success_ic.xml
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>
7 changes: 7 additions & 0 deletions BtechUtils/src/main/res/drawable/toast_warn_bg.xml
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>
12 changes: 12 additions & 0 deletions BtechUtils/src/main/res/drawable/toast_warn_ic.xml
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>
38 changes: 38 additions & 0 deletions BtechUtils/src/main/res/layout/dialog_progress.xml
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>
Loading

0 comments on commit a709727

Please sign in to comment.