|
1 | 1 | # Commons
|
2 | 2 | Common android components, helper functions, adaptors, dialogs, logs and extentions functions that is required for almost every application at startup.
|
3 | 3 |
|
4 |
| -## How to use |
| 4 | +## Modules |
| 5 | +1. [Dialogs](#Dialogs) |
| 6 | + |
| 7 | +## Dialogs |
| 8 | +1. [Information Dialog](#Information-Dialog) |
| 9 | +2. [Warning Dialog](#Warning-Dialog) |
| 10 | +3. [Error Dialog](#Error-Dialog) |
| 11 | +4. [Delete Dialog](#Delete-Dialog) |
| 12 | +5. [Wait Dialog](#Wait-Dialog) |
| 13 | +6. [How to use](#How-to-use-dialogs) |
| 14 | +7. [Calling From Java](#Calling-from-Java) |
| 15 | + |
| 16 | +### Information Dialog |
| 17 | +```kotlin |
| 18 | + infoDialog( |
| 19 | + this, // context |
| 20 | + "Information", // title |
| 21 | + "Some informational message", // message |
| 22 | + true // cancelable on back press or touch anywhere on the screen |
| 23 | + ).show() |
| 24 | +``` |
| 25 | +#### or |
| 26 | +```kotlin |
| 27 | + infoDialog( |
| 28 | + this, // context |
| 29 | + "Information", // title |
| 30 | + "Some informational message", // message |
| 31 | + true // cancelable on back press or touch anywhere on the screen |
| 32 | + ).setPositiveButton("OK") { dialog, _ -> |
| 33 | + // Ok button action |
| 34 | + dialog.dismiss() |
| 35 | + }.setNegativeButton("Close") { dialog, _ -> |
| 36 | + // close button action |
| 37 | + dialog.dismiss() |
| 38 | + }.show() |
| 39 | +``` |
| 40 | + |
| 41 | +### Warning Dialog |
| 42 | +```kotlin |
| 43 | + warningDialog( |
| 44 | + this, // context |
| 45 | + "Warning", // title |
| 46 | + "Some warning message", // message |
| 47 | + true // cancelable on back press or touch anywhere on the screen |
| 48 | + ).show() |
| 49 | +``` |
| 50 | +#### or |
| 51 | +```kotlin |
| 52 | + warningDialog( |
| 53 | + this, // context |
| 54 | + "Warning", // title |
| 55 | + "Some warning message", // message |
| 56 | + true // cancelable on back press or touch anywhere on the screen |
| 57 | + ).setPositiveButton("OK") { dialog, _ -> |
| 58 | + // Ok button action |
| 59 | + dialog.dismiss() |
| 60 | + }.setNegativeButton("Close") { dialog, _ -> |
| 61 | + // close button action |
| 62 | + dialog.dismiss() |
| 63 | + }.show() |
| 64 | +``` |
| 65 | + |
| 66 | +### Error Dialog |
| 67 | +```kotlin |
| 68 | + errorDialog( |
| 69 | + this, // context |
| 70 | + "Error", // title |
| 71 | + "Some error message", // message |
| 72 | + true // cancelable on back press or touch anywhere on the screen |
| 73 | + ).show() |
| 74 | +``` |
| 75 | +#### or |
| 76 | +```kotlin |
| 77 | + errorDialog( |
| 78 | + this, // context |
| 79 | + "Error", // title |
| 80 | + "Some error message", // message |
| 81 | + true // cancelable on back press or touch anywhere on the screen |
| 82 | + ).setPositiveButton("OK") { dialog, _ -> |
| 83 | + // Ok button action |
| 84 | + dialog.dismiss() |
| 85 | + }.setNegativeButton("Close") { dialog, _ -> |
| 86 | + // close button action |
| 87 | + dialog.dismiss() |
| 88 | + }.show() |
| 89 | +``` |
| 90 | + |
| 91 | +### Delete Dialog |
| 92 | +```kotlin |
| 93 | + confirmDelete( |
| 94 | + this, // context |
| 95 | + "Confirm Delete", // title |
| 96 | + "Some confirmation message", // message |
| 97 | + true // cancelable on back press or touch anywhere on the screen |
| 98 | + ).setPositiveButton("Delete") { dialog, _ -> |
| 99 | + // Ok button action |
| 100 | + dialog.dismiss() |
| 101 | + }.setNegativeButton("Close") { dialog, _ -> |
| 102 | + // close button action |
| 103 | + dialog.dismiss() |
| 104 | + }.show() |
| 105 | + .getButton(AlertDialog.BUTTON_POSITIVE) |
| 106 | + .setTextColor(ContextCompat.getColor(this, android.R.color.holo_red_light)) |
| 107 | +``` |
| 108 | + |
| 109 | +### Wait Dialog |
| 110 | +```kotlin |
| 111 | + waitDialog( |
| 112 | + this, // context |
| 113 | + "Loading, Please wait...", // message |
| 114 | + true // cancelable on back press or touch anywhere on the screen |
| 115 | + ).show() |
| 116 | +``` |
| 117 | + |
| 118 | +### How to use dialogs |
| 119 | +#### add this line to project `build.gradle` file |
5 | 120 | ```gradle
|
6 | 121 | allprojects {
|
7 | 122 | repositories {
|
8 |
| - ... |
9 | 123 | maven { url 'https://jitpack.io' }
|
10 | 124 | }
|
11 | 125 | }
|
12 | 126 | ```
|
13 |
| - |
14 |
| -### add this line to app `build.gradle` file |
| 127 | +#### add this line to app `build.gradle` file |
15 | 128 | ```gradle
|
16 | 129 | dependencies {
|
17 |
| - implementation 'com.github.ArbazMateen:Commons:0.1.1' |
| 130 | + implementation 'com.github.ArbazMateen.Commons:dialogs:0.1.1' |
18 | 131 | }
|
19 | 132 | ```
|
| 133 | + |
| 134 | +### Calling from Java |
| 135 | +```java |
| 136 | + NotificationDialog.infoDialog( |
| 137 | + this, |
| 138 | + "Some informational message" |
| 139 | + ).setPositiveButton("", new DialogInterface.OnClickListener() { |
| 140 | + @Override |
| 141 | + public void onClick(DialogInterface dialog, int which) { |
| 142 | + // positive button action |
| 143 | + dialog.dismiss(); |
| 144 | + } |
| 145 | + }).setNegativeButton("Close", new DialogInterface.OnClickListener() { |
| 146 | + @Override |
| 147 | + public void onClick(DialogInterface dialog, int which) { |
| 148 | + // negative button action |
| 149 | + dialog.dismiss(); |
| 150 | + } |
| 151 | + }).show(); |
| 152 | +``` |
| 153 | + |
0 commit comments