|
| 1 | +# ProjectArchitecture |
| 2 | + |
| 3 | +# Usage |
| 4 | + |
| 5 | +- [Api Call](https://github.com/hamiranisahil/ProjectArchitecture#api-call) |
| 6 | +- Recyclerview |
| 7 | +- App Permission |
| 8 | +- Database |
| 9 | +- SharedPreferenceUtility |
| 10 | +- Sqlite Database |
| 11 | +- MyLog |
| 12 | +- ViewPagerAdapter |
| 13 | +- ApplicationOperations |
| 14 | +- BannerAdInListUtility |
| 15 | +- BannerAdUtility |
| 16 | +- CustomAlertDialogWithBannerAd |
| 17 | +- ListDialog |
| 18 | +- CircleImageView |
| 19 | +- RateThisApp (Rate Dialog) |
| 20 | +- TextDrawable (Text to Image) |
| 21 | +- MySnackbar |
| 22 | +- CustomAlertDialog (One-Two Button) |
| 23 | +- DatePickerDialogUtility |
| 24 | +- DateUtility |
| 25 | +- FileUtility |
| 26 | +- FirebasePhoneAuthentication |
| 27 | +- ImagePickerUtility |
| 28 | +- ImageUtility |
| 29 | +- [IntentUtility](https://github.com/hamiranisahil/ProjectArchitecture#intentutility) |
| 30 | +- KeyboardUtility |
| 31 | +- LocaleManager |
| 32 | +- NetworkUtility |
| 33 | +- NotificationUtility |
| 34 | +- StringUtility |
| 35 | +- ValidatorUtility |
| 36 | +- [jsonschema2pojo Plugin](https://github.com/hamiranisahil/ProjectArchitecture#jsonschema2pojo-plugin) |
| 37 | + |
| 38 | +### Api Call |
| 39 | + |
| 40 | +Add this Dependencies. |
| 41 | +``` |
| 42 | + // retrofit, gson |
| 43 | + implementation 'com.google.code.gson:gson:2.8.5' |
| 44 | + implementation 'com.squareup.retrofit2:retrofit:2.4.0' |
| 45 | + implementation 'com.squareup.retrofit2:converter-gson:2.4.0' |
| 46 | +``` |
| 47 | +Step-1 Create Application Class and add it to Manifest file. |
| 48 | +``` |
| 49 | +class AppClass : Application() { |
| 50 | +
|
| 51 | + override fun onCreate() { |
| 52 | + super.onCreate() |
| 53 | + AppConfig().projectSetUp(applicationContext) |
| 54 | + } |
| 55 | +
|
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +Now add this class in AndroidManifest.xml file. |
| 60 | +``` |
| 61 | +android:name=".AppClass" |
| 62 | +``` |
| 63 | + |
| 64 | +Step-2 Create AppConfig Class. |
| 65 | +``` |
| 66 | +class AppConfig { |
| 67 | +
|
| 68 | + val REQUEST_REGISTER_USER = 2 |
| 69 | +
|
| 70 | + fun projectSetUp(context: Context) { |
| 71 | + ApiCall.BASE_URL = "http://localhost/p2j/api/Master/" |
| 72 | + ApiCall.HEADER_MAP = getHeader() |
| 73 | + ApiCall.LOADING_TITLE = "Title for Loading Dialog" // set Loading Title when api call shows the loading dialog. |
| 74 | + ApiCall.LOADING_DIALOG_SHOW = true // true or false: if you want to show loading dialog when api calling |
| 75 | + ApiCall.INTERNET_DIALOG_SHOW = true // true or false: if you want to show no internet dialog when internet goes and user tries to api call. |
| 76 | + ApiCall.HANDLE_STATUS = true // true or false: if you want to handle status automatically then set true or else pass false it gives directly response. |
| 77 | + ApiCall.FILE_DOWNLOAD_PATH = Environment.getExternalStorageDirectory().path // when we downloading file then set file path to save file at particular location. |
| 78 | +
|
| 79 | + //map.put("ClassName", arrayOf("URL","METHOD","REQUEST CODE")) |
| 80 | + map.put("RegisterReq", arrayOf("register_user", ApiCall.RequestType.POST, AppConfig().REQUEST_REGISTER_USER)) |
| 81 | + } |
| 82 | +
|
| 83 | + private fun getHeader(): HashMap<String, Any> { |
| 84 | + val map = HashMap<String, Any>() |
| 85 | + map["x-api-key"] = "368405e7872ffea848b6603ebdd455e2" |
| 86 | + map["Authorization"] = "Basic d2luQGluZm86I3dpbjEyMw==" |
| 87 | + return map |
| 88 | + } |
| 89 | +
|
| 90 | + fun getRequestparams(classObject: Any): Array<Any> { |
| 91 | + val enclosingClass = classObject.javaClass |
| 92 | + val className = enclosingClass.simpleName |
| 93 | + return map.get(className)!! |
| 94 | + } |
| 95 | +
|
| 96 | + companion object { |
| 97 | + val map = HashMap<String, Array<Any>>() |
| 98 | +
|
| 99 | + } |
| 100 | +} |
| 101 | +``` |
| 102 | +Step-2 Create Api Call. |
| 103 | +``` |
| 104 | +// 1. Post(raw) Api Call |
| 105 | +val registerReq = RegisterReq() // Create Request Class Object |
| 106 | +registerReq.name = tiedt_name.text.toString() // set data to request class |
| 107 | +
|
| 108 | +// Now do the api call |
| 109 | +// ApiCall(context, AppConfig().getRequestparams(class_object), class_object, webServiceType, listener). |
| 110 | +ApiCall(this, AppConfig().getRequestparams(registerReq), registerReq, ApiCall.WebServiceType.WS_SIMPLE, object : ApiCall.RetrofitResponseListener{ |
| 111 | + override fun onSuccess(response: String?, apiRequestCode: Int) { |
| 112 | +
|
| 113 | + } |
| 114 | +
|
| 115 | + override fun onFailure(t: Throwable, apiRequestCode: Int) { |
| 116 | + |
| 117 | + } |
| 118 | +
|
| 119 | +}) |
| 120 | +
|
| 121 | +
|
| 122 | +// 2. Get Api Call |
| 123 | +
|
| 124 | +
|
| 125 | +``` |
| 126 | + |
| 127 | + |
| 128 | +### SharedPreferenceUtility |
| 129 | + |
| 130 | +Step-1 Add line into AppConfig File. |
| 131 | +``` |
| 132 | +SharedPreferenceUtility.SHARED_PREFERENCE_NAME = "sp_expense_manager" |
| 133 | +``` |
| 134 | + |
| 135 | +Step-2 how to add Data into SharedPreference. |
| 136 | +``` |
| 137 | +
|
| 138 | +``` |
| 139 | + |
| 140 | +Step-3 how to get Data from SharedPreference. |
| 141 | +``` |
| 142 | +SharedPreferenceUtility().getData(this, AppConfig().SP_NUMBER, "") as String |
| 143 | +``` |
| 144 | + |
| 145 | +### IntentUtility |
| 146 | +1. launchPlayStoreApp : open PlayStore with packageName |
| 147 | + |
| 148 | + - launchPlayStoreApp(context: Context): |
| 149 | + Only pass **context**. it will get packagename from **applicationId **. |
| 150 | + ```IntentUtility().launchPlayStoreWithPackageName(context!!)``` |
| 151 | + |
| 152 | + - launchPlayStoreApp(context: Context, packageName: String): |
| 153 | + pass **context** and **packageName**. |
| 154 | + ```IntentUtility().launchPlayStoreWithPackageName(context!!, packageName)``` |
| 155 | + |
| 156 | +2. launchPlayStoreWithPublisher: open playstore with publish id |
| 157 | + |
| 158 | + - launchPlayStoreWithPublisher(context: Context) : |
| 159 | + need to pass context |
| 160 | + Step:1 Go to strings.xml File and write. |
| 161 | + ```<string name="developer_name">Declare Developer Name</string>``` |
| 162 | + |
| 163 | + Step:2 Use code |
| 164 | + ```IntentUtility().launchPlayStoreWithPublisher(context!!) ``` |
| 165 | + |
| 166 | +### jsonschema2pojo Plugin |
| 167 | + |
| 168 | +Step-1 Open build.gradle(project-level) file. |
| 169 | + |
| 170 | +``` |
| 171 | +buildscript { |
| 172 | + repositories { |
| 173 | + mavenCentral() |
| 174 | + } |
| 175 | +
|
| 176 | + dependencies { |
| 177 | + // this plugin |
| 178 | + classpath 'org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:${js2p.version}' |
| 179 | + // add additional dependencies here if you wish to reference instead of generate them (see example directory) |
| 180 | + } |
| 181 | +} |
| 182 | +``` |
| 183 | + |
| 184 | +Step-2 Open build.gradle(project-level) file. |
| 185 | +``` |
| 186 | +apply plugin: 'jsonschema2pojo' |
| 187 | +
|
| 188 | +
|
| 189 | +// Each configuration is set to the default value |
| 190 | +jsonSchema2Pojo { |
| 191 | +
|
| 192 | + // Whether to allow 'additional' properties to be supported in classes by adding a map to |
| 193 | + // hold these. This is true by default, meaning that the schema rule 'additionalProperties' |
| 194 | + // controls whether the map is added. Set this to false to globabally disable additional properties. |
| 195 | + includeAdditionalProperties = false |
| 196 | +
|
| 197 | + // Whether to generate builder-style methods of the form withXxx(value) (that return this), |
| 198 | + // alongside the standard, void-return setters. |
| 199 | + generateBuilders = false |
| 200 | +
|
| 201 | + // Whether to use primitives (long, double, boolean) instead of wrapper types where possible |
| 202 | + // when generating bean properties (has the side-effect of making those properties non-null). |
| 203 | + usePrimitives = false |
| 204 | +
|
| 205 | + // Location of the JSON Schema file(s). This may refer to a single file or a directory of files. |
| 206 | + source = files("${project.rootDir}/schema") |
| 207 | +
|
| 208 | + // Target directory for generated Java source files. The plugin will add this directory to the |
| 209 | + // java source set so the compiler will find and compile the newly generated source files. |
| 210 | + targetDirectory = file("${project.buildDir}/generated-sources/js2p") |
| 211 | +
|
| 212 | + // Package name used for generated Java classes (for types where a fully qualified name has not |
| 213 | + // been supplied in the schema using the 'javaType' property). |
| 214 | + targetPackage = 'com.modal' |
| 215 | +
|
| 216 | + // The characters that should be considered as word delimiters when creating Java Bean property |
| 217 | + // names from JSON property names. If blank or not set, JSON properties will be considered to |
| 218 | + // contain a single word when creating Java Bean property names. |
| 219 | + propertyWordDelimiters = [] as char[] |
| 220 | +
|
| 221 | + // Whether to use the java type long (or Long) instead of int (or Integer) when representing the |
| 222 | + // JSON Schema type 'integer'. |
| 223 | + useLongIntegers = false |
| 224 | +
|
| 225 | + // Whether to use the java type BigInteger when representing the JSON Schema type 'integer'. Note |
| 226 | + // that this configuration overrides useLongIntegers |
| 227 | + useBigIntegers = false |
| 228 | +
|
| 229 | + // Whether to use the java type double (or Double) instead of float (or Float) when representing |
| 230 | + // the JSON Schema type 'number'. |
| 231 | + useDoubleNumbers = true |
| 232 | +
|
| 233 | + // Whether to use the java type BigDecimal when representing the JSON Schema type 'number'. Note |
| 234 | + // that this configuration overrides useDoubleNumbers |
| 235 | + useBigDecimals = false |
| 236 | +
|
| 237 | + // Whether to include hashCode and equals methods in generated Java types. |
| 238 | + includeHashcodeAndEquals = true |
| 239 | +
|
| 240 | + // Whether to include a toString method in generated Java types. |
| 241 | + includeToString = true |
| 242 | +
|
| 243 | + // The style of annotations to use in the generated Java types. Supported values: |
| 244 | + // - jackson (alias of jackson2) |
| 245 | + // - jackson2 (apply annotations from the Jackson 2.x library) |
| 246 | + // - jackson1 (apply annotations from the Jackson 1.x library) |
| 247 | + // - gson (apply annotations from the Gson library) |
| 248 | + // - moshi1 (apply annotations from the Moshi 1.x library) |
| 249 | + // - none (apply no annotations at all) |
| 250 | + annotationStyle = 'gson' |
| 251 | +
|
| 252 | + // A fully qualified class name, referring to a custom annotator class that implements |
| 253 | + // org.jsonschema2pojo.Annotator and will be used in addition to the one chosen |
| 254 | + // by annotationStyle. If you want to use the custom annotator alone, set annotationStyle to none. |
| 255 | + customAnnotator = 'org.jsonschema2pojo.NoopAnnotator' |
| 256 | +
|
| 257 | + // Whether to include JSR-303/349 annotations (for schema rules like minimum, maximum, etc) in |
| 258 | + // generated Java types. Schema rules and the annotation they produce: |
| 259 | + // - maximum = @DecimalMax |
| 260 | + // - minimum = @DecimalMin |
| 261 | + // - minItems,maxItems = @Size |
| 262 | + // - minLength,maxLength = @Size |
| 263 | + // - pattern = @Pattern |
| 264 | + // - required = @NotNull |
| 265 | + // Any Java fields which are an object or array of objects will be annotated with @Valid to |
| 266 | + // support validation of an entire document tree. |
| 267 | + includeJsr303Annotations = false |
| 268 | +
|
| 269 | + // The type of input documents that will be read. Supported values: |
| 270 | + // - jsonschema (schema documents, containing formal rules that describe the structure of JSON data) |
| 271 | + // - json (documents that represent an example of the kind of JSON data that the generated Java types |
| 272 | + // will be mapped to) |
| 273 | + // - yamlschema (JSON schema documents, represented as YAML) |
| 274 | + // - yaml (documents that represent an example of the kind of YAML (or JSON) data that the generated Java types |
| 275 | + // will be mapped to) |
| 276 | + sourceType = 'json' |
| 277 | +
|
| 278 | + // Whether to empty the target directory before generation occurs, to clear out all source files |
| 279 | + // that have been generated previously. <strong>Be warned</strong>, when activated this option |
| 280 | + // will cause jsonschema2pojo to <strong>indiscriminately delete the entire contents of the target |
| 281 | + // directory (all files and folders)</strong> before it begins generating sources. |
| 282 | + removeOldOutput = false |
| 283 | +
|
| 284 | + // The character encoding that should be used when writing the generated Java source files |
| 285 | + outputEncoding = 'UTF-8' |
| 286 | +
|
| 287 | + // Whether to use {@link org.joda.time.DateTime} instead of {@link java.util.Date} when adding |
| 288 | + // date type fields to generated Java types. |
| 289 | + useJodaDates = false |
| 290 | +
|
| 291 | + // Whether to add JsonFormat annotations when using Jackson 2 that cause format "date", "time", and "date-time" |
| 292 | + // fields to be formatted as yyyy-MM-dd, HH:mm:ss.SSS and yyyy-MM-dd'T'HH:mm:ss.SSSZ respectively. To customize these |
| 293 | + // patterns, use customDatePattern, customTimePattern, and customDateTimePattern config options or add these inside a |
| 294 | + // schema to affect an individual field |
| 295 | + formatDateTimes = true |
| 296 | + formatDates = true |
| 297 | + formatTimes = true |
| 298 | +
|
| 299 | + // Whether to initialize Set and List fields as empty collections, or leave them as null. |
| 300 | + initializeCollections = true |
| 301 | +
|
| 302 | + // Whether to add a prefix to generated classes. |
| 303 | + classNamePrefix = "" |
| 304 | +
|
| 305 | + // Whether to add a suffix to generated classes. |
| 306 | + classNameSuffix = "" |
| 307 | +
|
| 308 | + // An array of strings that should be considered as file extensions and therefore not included in class names. |
| 309 | + fileExtensions = [] as String[] |
| 310 | +
|
| 311 | + // Whether to generate constructors or not. |
| 312 | + includeConstructors = false |
| 313 | +
|
| 314 | + // **EXPERIMENTAL** Whether to make the generated types Parcelable for Android |
| 315 | + parcelable = false |
| 316 | +
|
| 317 | + // Whether to make the generated types Serializable |
| 318 | + serializable = false |
| 319 | +
|
| 320 | + // Whether to include getters or to omit these accessor methods and create public fields instead. |
| 321 | + includeGetters = false |
| 322 | +
|
| 323 | + // Whether to include setters or to omit these accessor methods and create public fields instead. |
| 324 | + includeSetters = false |
| 325 | +
|
| 326 | + // Whether to include dynamic getters, setters, and builders or to omit these methods. |
| 327 | + includeDynamicAccessors = false |
| 328 | +
|
| 329 | + // Whether to include dynamic getters or to omit these methods. |
| 330 | + includeDynamicGetters = false |
| 331 | +
|
| 332 | + // Whether to include dynamic setters or to omit these methods. |
| 333 | + includeDynamicSetters = false |
| 334 | +
|
| 335 | + // Whether to include dynamic builders or to omit these methods. |
| 336 | + includeDynamicBuilders = false |
| 337 | +
|
| 338 | + // What type to use instead of string when adding string properties of format "date" to Java types |
| 339 | + dateType = "java.time.LocalDate" |
| 340 | +
|
| 341 | + // What type to use instead of string when adding string properties of format "date-time" to Java types |
| 342 | + dateTimeType = "java.time.LocalDateTime" |
| 343 | +} |
| 344 | +``` |
0 commit comments