Skip to content

Commit

Permalink
Merge branch 'kotlin-migration-last' of github.com:Wolox/wolmo-core-a…
Browse files Browse the repository at this point in the history
…ndroid into kotlin-migration-last
  • Loading branch information
dylan-muszel committed Dec 19, 2019
2 parents 92fc687 + 000fad9 commit 5956ec4
Show file tree
Hide file tree
Showing 19 changed files with 173 additions and 191 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.31'
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
22 changes: 12 additions & 10 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ apply plugin: 'jacoco-android'
apply plugin: 'com.github.kt3k.coveralls'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
compileSdkVersion 29
buildToolsVersion '29.0.2'
testOptions.unitTests.includeAndroidResources = true

compileOptions {
Expand All @@ -15,7 +15,7 @@ android {

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 29
consumerProguardFiles 'proguard-joda-time.pro', 'proguard-dagger.pro'
}

Expand All @@ -37,11 +37,11 @@ coveralls {
}

buildscript {
ext.androidx_appcompat_version = '1.0.2'
ext.dagger_version = '2.22.1'
ext.androidx_appcompat_version = '1.1.0'
ext.dagger_version = '2.25.3'
ext.powermock_version = '1.7.0'
ext.junit_version = '4.12'
ext.robolectric_version = '4.2'
ext.robolectric_version = '4.3.1'
ext.androidx_test_core_version = '1.1.0'
ext.mockito_inline_version = '2.13.0'
ext.assertj_version = '3.9.0'
Expand All @@ -59,7 +59,8 @@ dependencies {

// Testing as api to let tests package use it
api "junit:junit:$junit_version"
api "org.mockito:mockito-inline:$mockito_inline_version" // Mockito inline adds support for mocking final classes and methods
// Mockito inline adds support for mocking final classes and methods
api "org.mockito:mockito-inline:$mockito_inline_version"

// Dagger
api "com.google.dagger:dagger:$dagger_version"
Expand All @@ -69,14 +70,15 @@ dependencies {
annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"

// Android KTX
implementation "androidx.core:core-ktx:$android_ktx_version"
implementation "androidx.fragment:fragment-ktx:$android_ktx_version"
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"
testImplementation "androidx.test:core:$androidx_test_core_version"
testImplementation "org.mockito:mockito-inline:$mockito_inline_version" // Mockito inline adds support for mocking final classes and methods
testImplementation "org.mockito:mockito-inline:$mockito_inline_version"
// Mockito inline adds support for mocking final classes and methods
testImplementation "org.assertj:assertj-core:$assertj_version"
testAnnotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
testAnnotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,34 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package ar.com.wolox.wolmo.core.di.modules
package ar.com.wolox.wolmo.core.di.modules;

import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import ar.com.wolox.wolmo.core.di.scopes.ApplicationScope
import ar.com.wolox.wolmo.core.di.scopes.ApplicationScope;

import dagger.Module
import dagger.Provides
import dagger.Module;
import dagger.Provides;

/**
* Provides objects that depends of the Application [Context].
* The objects provided by this module uses [ApplicationScope].
* Provides objects that depends of the Application {@link Context}.
* The objects provided by this module uses {@link ApplicationScope}.
*/
@Module
class ContextModule {
public class ContextModule {

@Provides
@ApplicationScope
fun provideContext(application: Application): Context = application.applicationContext
@Provides
@ApplicationScope
Context provideContext(Application application) {
return application.getApplicationContext();
}

@Provides
@ApplicationScope
fun provideSharedPreferences(sharedPrefName: String, context: Context): SharedPreferences {
return context.getSharedPreferences(sharedPrefName, Activity.MODE_PRIVATE)
}
}
@Provides
@ApplicationScope
SharedPreferences provideSharedPreferences(String sharedPrefName, Context context) {
return context.getSharedPreferences(sharedPrefName, Activity.MODE_PRIVATE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) Wolox S.A
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package ar.com.wolox.wolmo.core.di.modules;

import android.util.SparseArray;

import ar.com.wolox.wolmo.core.fragment.WolmoFragmentHandler;
import ar.com.wolox.wolmo.core.permission.PermissionListener;
import ar.com.wolox.wolmo.core.presenter.BasePresenter;
import ar.com.wolox.wolmo.core.util.Logger;
import ar.com.wolox.wolmo.core.util.ToastFactory;

import dagger.Component;
import dagger.Module;
import dagger.Provides;

/**
* Provides default implementations for Wolmo's dependencies and utils.
* You can add this module to your {@link Component} if you don't need to customize any dependency.
*/
@Module
public class DefaultModule {

@Provides
static SparseArray<PermissionListener> providesPermissionManagerArray() {
return new SparseArray<>();
}

@Provides
static BasePresenter providesDefaultBasePresenter() {
return new BasePresenter();
}

/**
* Provides a default {@link WolmoFragmentHandler} with no presenter for fragments that don't
* need it.
*/
@Provides
static WolmoFragmentHandler providesDefaultWolmoFragmentHandler(ToastFactory toastFactory,
Logger logger,
BasePresenter<Object> basePresenter) {
return new WolmoFragmentHandler<>(toastFactory, logger, basePresenter);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ abstract class WolmoDialogFragment<V : Any, P : BasePresenter<V>> : DaggerAppCom
@Inject
lateinit var fragmentHandler: WolmoFragmentHandler<V, P>

val presenter: P
get() = fragmentHandler.presenter

override fun onCreateDialog(savedInstanceState: Bundle?) = super.onCreateDialog(savedInstanceState).apply {
window?.run {
requestFeature(Window.FEATURE_NO_TITLE)
Expand Down Expand Up @@ -192,12 +195,6 @@ abstract class WolmoDialogFragment<V : Any, P : BasePresenter<V>> : DaggerAppCom
return false
}

/**
* Tries to return a non null instance of the presenter [P] for this fragment.
* If the presenter is null this will throw a NullPointerException.
*/
fun requirePresenter() = fragmentHandler.requirePresenter()

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>,
grantResults: IntArray) {
permissionManager.onRequestPermissionsResult(requestCode, permissions, grantResults)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ abstract class WolmoFragment<V : Any, P : BasePresenter<V>> : DaggerFragment(),
@Inject
lateinit var permissionManager: PermissionManager

/**
* Tries to return a non null instance of the presenter [P] for this fragment.
* If the presenter is null this will throw a NullPointerException.
*/
val presenter: P
get() = fragmentHandler.presenter

@CallSuper
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -89,9 +96,9 @@ abstract class WolmoFragment<V : Any, P : BasePresenter<V>> : DaggerFragment(),
/** Delegates permission handling to Wolmo's [PermissionManager]. */
@CallSuper
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
) {
permissionManager.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
Expand Down Expand Up @@ -139,10 +146,4 @@ abstract class WolmoFragment<V : Any, P : BasePresenter<V>> : DaggerFragment(),
override fun onBackPressed(): Boolean {
return false
}

/**
* Tries to return a non null instance of the presenter [P] for this fragment.
* If the presenter is null this will throw a NullPointerException.
*/
fun requirePresenter() = fragmentHandler.requirePresenter()
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ import javax.inject.Inject
* This class is used to separate Wolox Fragments logic so that different subclasses of
* Fragment can implement MVP without re-writing this.
*/
class WolmoFragmentHandler<V : Any, P : BasePresenter<V>> @Inject @JvmOverloads constructor(
class WolmoFragmentHandler<V : Any, P : BasePresenter<V>> @Inject constructor(
private val toastFactory: ToastFactory,
private val logger: Logger,
val presenter: P? = null
val presenter: P
) {

private lateinit var fragment: Fragment
Expand Down Expand Up @@ -86,7 +86,7 @@ class WolmoFragmentHandler<V : Any, P : BasePresenter<V>> @Inject @JvmOverloads
*/
fun onViewCreated(view: View) {
created = true
presenter?.attachView(wolmoView)
presenter.attachView(wolmoView)
with(wolmoFragment) {
setUi(view)
init()
Expand Down Expand Up @@ -124,13 +124,7 @@ class WolmoFragmentHandler<V : Any, P : BasePresenter<V>> @Inject @JvmOverloads
* Called from [WolmoFragment.onDestroyView]. It notifies the [BasePresenter] that
* the view is destroyed, calling [BasePresenter.onViewDetached]
*/
fun onDestroyView() = requirePresenter().detachView()

/**
* Tries to return a non null instance of the presenter [P] for this fragment.
* If the presenter is null this will throw a NullPointerException.
*/
fun requirePresenter() = presenter!!
fun onDestroyView() = presenter.detachView()

private fun onVisibilityChanged() {
if (!created) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ open class BasePresenter<V> @Inject constructor() {
}

/** Listener called when a view is attached and it's safe to interact with it. */
fun onViewAttached() {}
open fun onViewAttached() {}

/**
* Method called when the view is destroyed and it's no longer safe for the presenter to
* interact with it.
*/
fun onViewDetached() {}
open fun onViewDetached() {}

/**
* Runs the [method] if the [view] is attached to the presenter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import javax.inject.Inject
@ApplicationScope
class SharedPreferencesManager @Inject constructor(private val sharedPreferences: SharedPreferences) {

fun store(key: String, value: String) = sharedPreferences.edit().putString(key, value).apply()
fun store(key: String, value: String?) = sharedPreferences.edit().putString(key, value).apply()

fun store(key: String, value: Int) = sharedPreferences.edit().putInt(key, value).apply()

Expand All @@ -43,7 +43,7 @@ class SharedPreferencesManager @Inject constructor(private val sharedPreferences

fun store(key: String, value: Long) = sharedPreferences.edit().putLong(key, value).apply()

operator fun get(key: String, defValue: String): String? = sharedPreferences.getString(key, defValue)
operator fun get(key: String, defValue: String?): String? = sharedPreferences.getString(key, defValue)

operator fun get(key: String, defValue: Int): Int = sharedPreferences.getInt(key, defValue)

Expand Down
Loading

0 comments on commit 5956ec4

Please sign in to comment.