This file contains hidden or 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
inline fun showMessegeDialogWithAction(ctx: Context, msg: String, btnTxtPositive: String, btnTxtNegative: String, crossinline onPositiveButtonClick: () -> Unit){ | |
val builder = AlertDialog.Builder(ctx) | |
builder.setMessage(msg) | |
builder.setIcon(android.R.drawable.ic_dialog_alert) | |
builder.setPositiveButton(btnTxtPositive) { dialogInterface, which -> | |
onPositiveButtonClick.invoke() | |
} | |
builder.setNegativeButton(btnTxtNegative) { dialogInterface, which -> | |
dialogInterface.dismiss() | |
} |
This file contains hidden or 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
inline fun tryCatch(onTry: () -> Unit, onCatch: (Exception) -> Unit) { | |
try { | |
onTry.invoke() | |
} catch (e: Exception) { | |
onCatch.invoke(e) | |
} | |
} |
This file contains hidden or 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
1. Create this BaseLocalJsonParser Compenion object | |
object BaseLocalJsonParser { | |
fun parseJSONData(context: Context, jsonFileName: String): String? { | |
val JSONString: String? | |
JSONString = try { | |
val inputStream: InputStream = context.assets.open(jsonFileName) | |
val sizeOfJSONFile: Int = inputStream.available() | |
val bytes = ByteArray(sizeOfJSONFile) | |
inputStream.read(bytes) |
This file contains hidden or 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
object BaseFragmentController { | |
fun load(fragment: Fragment, framelayout: Int, context: Context) { | |
val transaction = (context as FragmentActivity).supportFragmentManager.beginTransaction() | |
transaction.replace(framelayout, fragment, fragment::class.java.name) | |
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) | |
transaction.addToBackStack(null) | |
transaction.commit() | |
} |
This file contains hidden or 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
object RandomCodeGen { | |
fun generate(): String { | |
val rnd = Random() | |
val number = rnd.nextInt(999999) | |
return String.format("%06d", number) | |
} | |
} |
This file contains hidden or 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
1. Create a Class file Called ProgressDialog & past below code | |
--------------------------------------------------------------- | |
class ProgressDialog(private val context: Context) { | |
private var dialog: Dialog? = null | |
fun showProgressDialog() { | |
dialog = Dialog(context) | |
dialog!!.requestWindowFeature(Window.FEATURE_NO_TITLE) | |
dialog!!.setCancelable(false) | |
dialog!!.setContentView(your_progress_dialog_xml_layout) | |
dialog!!.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) |
This file contains hidden or 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
inline fun View.setVisibility(value: Boolean) { | |
this.visibility = if (value) View.VISIBLE else View.GONE | |
} |
This file contains hidden or 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
object CalculateDiscount { | |
fun discountInPercentage(totalprice: Int, discount: Int) : Int | |
{ | |
val discountInTk = totalprice * discount / 100 | |
val result = totalprice - discountInTk | |
return result | |
} | |
fun discountInTaka(context: Context, totalprice: Int, taka: Int) : Int |
This file contains hidden or 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
object DateTimeUtils { | |
fun convertDateToLong(date : String) : Long | |
{ | |
val dateFormat = SimpleDateFormat("yyyy/MM/dd") | |
val date = dateFormat.parse(date) | |
val dateInLong = date.time | |
return dateInLong | |
} |
OlderNewer