Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change api initialization #175

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ branches:
- develop

script:
- ./gradlew build jacocoTestReport connectedCheck
- ./gradlew -PactiveProductFlavor="withoutApi" build jacocoTestReport connectedCheck

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
45 changes: 45 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
apply plugin: 'jacoco-android'

def apiLibrary = null

android {
def globalConfiguration = rootProject.extensions.getByName("ext")

Expand All @@ -23,6 +25,37 @@ android {
multiDexEnabled true
}

flavorDimensions "api"

productFlavors {
withoutApi {
dimension "api"
}
shopifyApi {
dimension "api"

def shopappShopifyVersion = project.getProperties().get("shopappShopifyVersion")
if (shopappShopifyVersion != null) {
apiLibrary = "com.github.rubygarage:shopapp-shopify-android:$shopappShopifyVersion"
}

def appId = project.getProperties().get("appId")
applicationId = appId != null ? appId : applicationId

def domain = project.getProperties().get("domain")
buildConfigField "String", "BASE_DOMAIN", "\"$domain\""

def accessToken = project.getProperties().get("token")
buildConfigField "String", "STOREFRONT_ACCESS_TOKEN", "\"$accessToken\""

def apiKey = project.getProperties().get("apiKey")
buildConfigField "String", "API_KEY", "\"$apiKey\""

def apiPassword = project.getProperties().get("apiPassword")
buildConfigField "String", "API_PASSWORD", "\"$apiPassword\""
}
}

testOptions {
unitTests {
includeAndroidResources = true
Expand Down Expand Up @@ -80,6 +113,11 @@ dependencies {
implementation project(':data')
implementation project(':domain')
implementation project(':gateway')
if (apiLibrary != null) {
implementation(apiLibrary) {
exclude module: 'shopapp-android'
}
}

testImplementation "com.google.dagger:dagger:$daggerVersion"
kaptTest "com.google.dagger:dagger-compiler:$daggerVersion"
Expand All @@ -93,6 +131,13 @@ dependencies {
androidTestImplementation "com.android.support.test:runner:$testRunnerVersion"
}

android.variantFilter { variant ->
def activeProductFlavor = project.getProperties().get("activeProductFlavor")
if (activeProductFlavor != null && variant.getFlavors().get(0).name != activeProductFlavor) {
variant.setIgnore(true)
}
}

project.afterEvaluate {
android.applicationVariants.all { variant ->
def realVariantName = variant.name
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/shopapp/ApiInitializer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.shopapp

import android.content.Context
import com.shopapp.gateway.Api

interface ApiInitializer {

fun initialize(context: Context): Api?
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/shopapp/ShopApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ open class ShopApplication : Application() {
override fun onCreate() {
super.onCreate()

val api = null //Initialize your api here.
val api = ApiInitializerImpl.initialize(this)
val dao = DaoImpl(this)

appComponent = buildAppComponent(api, dao)
Expand Down
12 changes: 12 additions & 0 deletions app/src/shopifyApi/java/com/shopapp/ApiInitializerImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.shopapp

import android.content.Context
import com.shopapp.gateway.Api
import com.shopapp.shopify.api.ShopifyApi

object ApiInitializerImpl : ApiInitializer {

override fun initialize(context: Context): Api? =
ShopifyApi(context, BuildConfig.BASE_DOMAIN, BuildConfig.STOREFRONT_ACCESS_TOKEN,
BuildConfig.API_KEY, BuildConfig.API_PASSWORD)
}
9 changes: 9 additions & 0 deletions app/src/withoutApi/java/com/shopapp/ApiInitializerImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.shopapp

import android.content.Context
import com.shopapp.gateway.Api

object ApiInitializerImpl : ApiInitializer {

override fun initialize(context: Context): Api? = null
}