This repository has been archived by the owner on Oct 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add kotlin support in main app - Move JSONAPI models to another module data - Update Realm and split using RealmModule - Convert preleminary classes to data classes - Balance classes of lombok and Kotlin within modules - Fix kotlin properties and tests - Add mockito extension inline for kotlin classes
- Loading branch information
1 parent
61520f4
commit 0a7aaae
Showing
76 changed files
with
472 additions
and
541 deletions.
There are no files selected for viewing
This file contains 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
102 changes: 0 additions & 102 deletions
102
android/app/src/main/java/org/fossasia/openevent/config/StrategyRegistry.java
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
android/app/src/main/java/org/fossasia/openevent/config/StrategyRegistry.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.fossasia.openevent.config | ||
|
||
import org.fossasia.openevent.config.strategies.* | ||
|
||
/** | ||
* Project level configuration strategies holder singleton | ||
* | ||
* Holds all strategies and provides an interface to get singleton strategies or | ||
* override the default strategy holder. Also sets the order and strategies in default | ||
* holder which is then utilised by [AppConfigurer] to configure the application | ||
*/ | ||
class StrategyRegistry private constructor() { | ||
private val defaultHolder: ConfigStrategyHolder = ConfigStrategyHolder() | ||
|
||
var strategyHolder: ConfigStrategyHolder? = null | ||
|
||
private fun <T> lazyInit(field: T?, initializer: () -> T): T { | ||
return field ?: initializer() | ||
} | ||
|
||
var httpStrategy: HttpStrategy? = null | ||
get() { | ||
field = lazyInit(field) { HttpStrategy() } | ||
return field | ||
} | ||
var languageStrategy: LanguageStrategy? = null | ||
get() { | ||
field = lazyInit(field) { LanguageStrategy() } | ||
return field | ||
} | ||
var leakCanaryStrategy: LeakCanaryStrategy? = null | ||
get() { | ||
field = lazyInit(field) { LeakCanaryStrategy() } | ||
return field | ||
} | ||
var eventBusStrategy: EventBusStrategy? = null | ||
get() { | ||
field = lazyInit(field) { EventBusStrategy() } | ||
return field | ||
} | ||
var mapModuleStrategy: MapModuleStrategy? = null | ||
get() { | ||
field = lazyInit(field) { MapModuleStrategy() } | ||
return field | ||
} | ||
var appConfigStrategy: AppConfigStrategy? = null | ||
get() { | ||
field = lazyInit(field) { AppConfigStrategy() } | ||
return field | ||
} | ||
|
||
|
||
fun getDefaultHolder(): ConfigStrategyHolder { | ||
if (strategyHolder != null) | ||
return strategyHolder as ConfigStrategyHolder | ||
defaultHolder.register(leakCanaryStrategy) | ||
defaultHolder.register(httpStrategy) | ||
defaultHolder.register(eventBusStrategy) | ||
defaultHolder.register(mapModuleStrategy) | ||
defaultHolder.register(appConfigStrategy) | ||
defaultHolder.register(languageStrategy) | ||
defaultHolder.register(TimberStrategy()) | ||
defaultHolder.register(TimeConfigStrategy()) | ||
defaultHolder.register(RealmStrategy()) | ||
return defaultHolder | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
val instance by lazy { StrategyRegistry() } | ||
} | ||
|
||
} |
62 changes: 0 additions & 62 deletions
62
android/app/src/main/java/org/fossasia/openevent/config/strategies/HttpStrategy.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
android/app/src/main/java/org/fossasia/openevent/config/strategies/HttpStrategy.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.fossasia.openevent.config.strategies | ||
|
||
import android.content.Context | ||
import com.facebook.stetho.Stetho | ||
import com.facebook.stetho.okhttp3.StethoInterceptor | ||
import com.jakewharton.picasso.OkHttp3Downloader | ||
import com.squareup.picasso.Picasso | ||
import com.uphyca.stetho_realm.RealmInspectorModulesProvider | ||
import okhttp3.Cache | ||
import okhttp3.OkHttpClient | ||
import org.fossasia.openevent.BuildConfig | ||
import org.fossasia.openevent.config.ConfigStrategy | ||
import java.io.File | ||
|
||
/** | ||
* Configures Http Cache and stetho plugin and sets picasso to use the configured client | ||
* | ||
* Also provides an interface for application to use Picasso with cache | ||
* To be used via [org.fossasia.openevent.config.StrategyRegistry] | ||
*/ | ||
class HttpStrategy : ConfigStrategy { | ||
|
||
lateinit var picassoWithCache: Picasso | ||
private set | ||
|
||
override fun configure(context: Context): Boolean { | ||
//Initialize Cache | ||
val httpCacheDirectory = File(context.cacheDir, "picasso-cache") | ||
val cache = Cache(httpCacheDirectory, (15 * 1024 * 1024).toLong()) | ||
|
||
val okHttpClientBuilder: OkHttpClient.Builder = OkHttpClient.Builder().cache(cache) | ||
|
||
if (BuildConfig.DEBUG) { | ||
// Create an InitializerBuilder | ||
Stetho.initialize( | ||
Stetho.newInitializerBuilder(context) | ||
.enableDumpapp(Stetho.defaultDumperPluginsProvider(context)) | ||
.enableWebKitInspector(RealmInspectorModulesProvider.builder(context).build()) | ||
.build()) | ||
|
||
//Initialize Stetho Interceptor into OkHttp client | ||
val httpClient = OkHttpClient.Builder().addNetworkInterceptor(StethoInterceptor()).build() | ||
okHttpClientBuilder.addNetworkInterceptor(StethoInterceptor()) | ||
|
||
//Initialize Picasso | ||
val picasso = Picasso.Builder(context).downloader(OkHttp3Downloader(httpClient)).build() | ||
Picasso.setSingletonInstance(picasso) | ||
} | ||
|
||
//Initialize Picasso with cache | ||
picassoWithCache = Picasso.Builder(context).downloader(OkHttp3Downloader(okHttpClientBuilder.build())).build() | ||
|
||
return false | ||
} | ||
|
||
} |
28 changes: 0 additions & 28 deletions
28
android/app/src/main/java/org/fossasia/openevent/config/strategies/LanguageStrategy.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.