From 1b8d8208f7307d6e03cb0823c04b8da743a16205 Mon Sep 17 00:00:00 2001 From: dylan-muszel <42148418+dylan-muszel@users.noreply.github.com> Date: Wed, 8 Jan 2020 17:45:26 -0300 Subject: [PATCH] Readme features (#63) * Kotlin Migration - Adapter and DI (#50) * Adapter * DI * Converting object to class * Fix pair * Migrate BasePresenter * Migrate LceView and add copyright to BasePresenter * Migrate LeView * Migrate BasePresenterTest * Add deprecated to runIfViewAttached, replace apply for run in tests, clean code * Migration of permissionsManager * Migration of permissionListener * Fix redundant private set * Refactor to clean code * More refactor * Kotlin migration utils (#52) * Keyboard * Logger * Shared preferences * Migration (#53) * WolmoActivityHandler converted to kotlin (#51) * WolmoActivityHandler converted to kotlin * WolmoActivityHandler converted to kotlin * WolmoActivityHandler converted to kotlin * Kotlin migration fragments (#56) * FRagments migrated * Restoring GetImage.java * Restoring java getimage test * To spaces * Indentation * Reformat * Code reformats * fixing tests * Reverting get image fragment * changing imports * Last migration (#58) * FRagments migrated * Restoring GetImage.java * Restoring java getimage test * To spaces * Indentation * Reformat * Code reformats * fixing tests * Last migration * Kotlin migration fixes - update versions (#59) * Fixing overriding base presenter * Presenter as val * Fix tests * Get presnter instead of require * Fixing wolmo fragment inject * DefaultModule as class * Shared preferences string nullable * Android core as api * Reverting modules * Updating version * Updating versions * Fixing tests * Using implmentation * API insteda of implementation revert * Rollback handler * Also adding some minor changes * Another minor change * Updating comments and using requireArgument * Handle arguments nullable on fragment * Fixing url * Adding coroutine base presenter * Coroutines and more * updating get image fragment * Fixing doc * Updating get image fragment * Rollback handler and minor changes (#61) * Rollback handler * Also adding some minor changes * Another minor change * Updating comments and using requireArgument * Handle arguments nullable on fragment * Fixing url * Removing wrong comment * Updating get image * Moving all get image stuff to a helper * Fixing issues * Some fixes * Removing wrong test * Serializable * Importing * Fixing * Reverting image provider * Provider change * More fixes * Removing wrong arguments * More navigation utils * Updating kapt * Removing getimagekt * Reverting get image fragment * Reverting get image fragment test * Reverting spaces * More reverts * More reverts * Reverting tests * More test reverts * Minor fixes * More comments * Removing log * Single lines * Removing imports * Updating gradle * More tests * Features readme * Reformat * View extensions readme * Removing wrong blank line Co-authored-by: igsosa92 <43349271+igsosa92@users.noreply.github.com> Co-authored-by: patofernandez <49655621+patofernandez@users.noreply.github.com> --- FEATURES.md | 89 +++++++++++++++++++ README.md | 2 + core/build.gradle | 4 - .../wolox/wolmo/core/util/NavigationUtils.kt | 3 +- 4 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 FEATURES.md diff --git a/FEATURES.md b/FEATURES.md new file mode 100644 index 0000000..237db95 --- /dev/null +++ b/FEATURES.md @@ -0,0 +1,89 @@ +

+ +

+ +# WOLMO features + +### BasePresenter +Base implementation of a presenter. It contains a nullable view [V] which is attached and detached given fragment’s lifecycle. It provides some callbacks to be overridden if needed: +- `onViewAttached(): Unit`: invoked when the view is attached. +- `onViewDetached(): Unit`: invoked when the view is detached. + +### CoroutineBasePresenter +Coroutine implementation of a `BasePresenter`. It’s a `CoroutineScope` attached to fragment’s lifecycle (it’s cancelled on view detached). It accepts a `CoroutineContext` and uses `MainDispatcher` as default. + +### GetImageHelper +Injectable helper class to open gallery and camera to get an image. +- `fun openGallery(fragment: Fragment, code: Int, onPermissionDenied: () -> Unit = {}, onGalleryNotFound: () -> Unit = {})`: Request read permissions and open the gallery for result with the given [code] app if exists. +- `fun openCamera(fragment: Fragment, code: Int, destinationFilename: String, onPermissionDenied: () -> Unit = {}, onCameraNotFound: () -> Unit = {})`: Request camera permissions and open the camera for result with the given [code] app if exists, saving the picture on the [destinationFilename]. + +### ImageProvider +Singleton injectable utils class to manipulate and retrieve images. +- `addPictureToDeviceGallery(picture: Uri): Unit`: adds the given [picture] to the device images gallery. +- `getImageFromGallery(fragment: Fragment, requestCode: Int): Boolean `: tries to open gallery to retrieve an image. Returns true if successful, false otherwise. Override `onActivityResult` on the given [fragment] and check the given [requestCode] for result. +- `getImageFromCamera(fragment: Fragment, requestCode: Int, file: String): Boolean`: tries to open camera to take a picture to be saved on the given [file]. Returns true if successful, false otherwise. Override `onActivityResult` on the given [fragment] and check the given [requestCode] for result. +- … and more! + +### KeyboardManager +Injectable class to manage the Android's soft keyboard. +- `show(editText: EditText): Unit`: forces the soft keyboard to show for a specific [editText]. +- `hide(view: View): Unit`: forces the soft keyboard to hide, meant to be called from inside a Fragment's [view]. +- `hide(view: View): Unit`: forces the soft keyboard to hide, meant to be called from inside an [activity]. + +### Logger +Injectable wrapper of [Log] to simplify logs in the same class by reusing the tag and to simplify unit tests. + +### NavigationUtils +Provides some context extensions for navigation. +- `Context.jumpTo(clazz: Class<*>, vararg intentExtras: IntentExtra): Unit`: opens a new activity [clazz] sending all the given [intentExtras]. +- `Context.jumpToClearingTask(clazz: Class<*>, transition: ActivityOptionsCompat?, vararg intentExtras: IntentExtra): Unit`: opens a new activity [clazz] with a [transition] sending all the given [intentExtras]. +- `Context.jumpTo(clazz: Class<*>, vararg intentExtras: IntentExtra): Unit`: opens a new activity [clazz] clearing the current task and sending all the given [intentExtras]. +- `Context.openBrowser(url: String?): Unit`: opens browser with the given [url] (if it's null, open a blank page). +- `Context.makeCall(phone: String): Unit`: make a call to the given [phone]. It needs the [CALL_PHONE] permission. +- `Context.openDial(phone: String): Unit`: open the dial with the given [phone]. It doesn't need any extra permission. + +### PermissionManager +Singleton injectable helper class to handler Android’s runtime permissions. +- `requestPermission(fragment: Fragment, listener: PermissionListener?, vararg permissions: String): Unit`: request one or more [permissions] from a [fragment] and invokes the [listener] on complete. +- `requestPermission(activity: Activity, listener: PermissionListener?, vararg permissions: String): Unit`: request one or more [permissions] from an [activity] and invokes the [listener] on complete. +- `onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray): Unit`: should be invoked on fragment/activity onRequestPermissionsResult. It’s already implemented on `WolmoActivity` so, since `PermissionManager` is a singleton, by using `WolmoActivity` no importance should be given to this. + +### SharedPreferencesManager +Singleton injectable utility class to query and store values in [SharedPreferences]. + +### SimpleFragmentPagerAdapterBase +Base implementation of a `FragmentStatePagerAdapter` for a `ViewPager` that allows, simply, to add fragments: +- `addFragment(fragment: Fragment, title: String): Unit`: adds a single fragment with its titile to the adapter. +- `addFragments(fragments: List>): Unit`: adds multiple fragments with theirs titles to the adapter. + +Note: The fragments given to this should be injected. + +### ToastFactory +Singleton injectable utility class to simplify work with Android's [Toast] messages. + +### View extensions +Provides some view extensions. +- `ViewGroup.inflate(@LayoutRes layoutRes: Int, attachToRoot: Boolean = false): View`: inflates a layout inside the [ViewGroup]. +- `TextView.setTextOrGone(newText: String?): Unit`: set text and show if text is not null or empty or hide otherwise. + +### WolmoActivity +Base implementation of a `DaggerActivity` that provides these extra features: +- `replaceFragment(@IdRes resId: Int, fragment: Fragment): Unit`: replace the [resId] with the given [fragment]. +- `requireArgument(key: String): T`: get the argument from the intent extras by the given [key] and returns it as a non-null [T]. + +### WolmoFileProvider +Singleton injectable utils class for managing [File]s. +- `getNewCachePictureFilename(name: String, imageType: ImageType): String`: returns a new picture filename inside the app cache. The filename will be [name]_[System.nanoTime()]. +- `getNewCacheVideoFilename(name: String): String`: returns a new video filename inside the app cache. The filename will be [name]_[System.nanoTime()]. +- `getNewPictureName(name: String, imageType: ImageType): String`: returns a new picture filename inside the DCIM folder. The filename will be [name]_[System.nanoTime()]. +- `getNewVideoName(name: String): String`: returns a new video filename inside the Videos folder. The filename will be [name]_[System.nanoTime()]. +- … and more! + +### WolmoFragment +Base implementation of a `DaggerFragment` that is MVP-ready (you can access the presenter [T] by `presenter`) and provides some extra callbacks to be overridden if needed: +- `init(): Unit`: invoked on view created and used to initialize everything necessary. +- `setListeners(): Unit`: invoked on view created and used to set listeners like `onClick`. +- `handleArguments(arguments: Bundle?): Boolean`: invoked on create and used to verify if arguments contains what fragment requires. Returning null or false will end the execution. + +It also provides this extra feature: +- `requireArgument(key: String): T`: get argument by the given [key] and returns it as a non-null [T]. diff --git a/README.md b/README.md index 8e8224c..902a6c2 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,8 @@ These features can be found in CORE: * Files helpers * Camera and image helpers +[See all the features available here.](FEATURES.md) + ## Contributing 1. Fork it diff --git a/core/build.gradle b/core/build.gradle index 46472ac..9dc988e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -84,10 +84,6 @@ dependencies { api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version" - // Android KTX - api "androidx.core:core-ktx:$android_ktx_version" - api "androidx.fragment:fragment-ktx:$android_ktx_version" - // Test testImplementation "junit:junit:$junit_version" testImplementation "org.robolectric:robolectric:$robolectric_version" diff --git a/core/src/main/java/ar/com/wolox/wolmo/core/util/NavigationUtils.kt b/core/src/main/java/ar/com/wolox/wolmo/core/util/NavigationUtils.kt index aaf4d5c..e3368c3 100644 --- a/core/src/main/java/ar/com/wolox/wolmo/core/util/NavigationUtils.kt +++ b/core/src/main/java/ar/com/wolox/wolmo/core/util/NavigationUtils.kt @@ -83,7 +83,6 @@ fun Context.makeCall(phone: String) { /** * Sends an intent to start an [Activity] for the provided [clazz] from a [context] * with a variable number of instances of [intentExtras] that will be sent as extras. - * It accepts a [transition] that defines the animation behaviour. */ @SafeVarargs fun Context.jumpTo( @@ -110,7 +109,7 @@ fun Context.jumpTo( } /** - * Sends an intent to start an [Activity] for the provided [clazz] from a [context] but clearing + * Sends an intent to start an [Activity] for the provided [clazz] from a [Context] but clearing * the current task and starting a new one with a variable number of instances of * [intentExtras] that will be sent as extras. */