Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NetworkModule(private val context: Context) {
val httpClientBuilder = OkHttpClient.Builder()
httpClientBuilder.addInterceptor(requestInterceptor)
if (BuildConfig.DEBUG) {
// httpClientBuilder.addInterceptor(httpLoggingInterceptor)
httpClientBuilder.addInterceptor(httpLoggingInterceptor)
}
return httpClientBuilder.build()

Expand All @@ -47,7 +47,7 @@ class NetworkModule(private val context: Context) {
@Provides
@Singleton
internal fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor =
HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC)

@Provides
@Singleton
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<color name="primary_dark">#D32F2F</color>
<color name="accent">#FF5722</color>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="light_grey">#F1F1F1</color>
<color name="defaultTextColor">#ADADAD</color>
</resources>
2 changes: 0 additions & 2 deletions library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<resources>
<string name="app_name">Constructor.io</string>
<string name="search_hint">Search…</string>
<string name="group_text">in %s</string>

</resources>
9 changes: 6 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation "com.android.support:cardview-v7:28.0.0"
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.13'
implementation "com.android.support:design:28.0.0"
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
testImplementation 'junit:junit:4.12'
}
}
23 changes: 14 additions & 9 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,32 @@
package="io.constructor.sample">

<application
android:name=".SampleApp"
android:name=".BodegaApp"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SampleActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity
android:name=".SampleActivityCustom"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".MainActivity">
<activity android:name=".feature.home.HomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".feature.checkout.CheckoutActivity"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity
android:name=".feature.cart.CartActivity"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity
android:name=".feature.searchresult.SearchResultActivity"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity
android:name=".feature.productdetail.ProductDetailActivity"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import android.app.Application
import io.constructor.core.ConstructorIo
import io.constructor.core.ConstructorIoConfig

class SampleApp : Application() {
class BodegaApp : Application() {

override fun onCreate() {
super.onCreate()
ConstructorIo.init(this, ConstructorIoConfig("key_OucJxxrfiTVUQx0C",
testCells = listOf("ab" to "cd", "11" to "22")))
ConstructorIo.init(this, ConstructorIoConfig("key_K2hlXt5aVSwoI1Uw"))
ConstructorIo.userId = "uid"
}
}
26 changes: 0 additions & 26 deletions sample/src/main/java/io/constructor/sample/MainActivity.kt

This file was deleted.

39 changes: 0 additions & 39 deletions sample/src/main/java/io/constructor/sample/SampleActivity.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.constructor.sample.common

import android.os.Bundle
import android.support.v7.app.AppCompatActivity

abstract class BaseActivity<T : BasePresenter<*>> : AppCompatActivity() {

protected lateinit var presenter: T

abstract fun initPresenter(): T

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
presenter = initPresenter()
}

override fun onDestroy() {
super.onDestroy()
presenter.onDestroy()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.constructor.sample.common

import io.reactivex.disposables.CompositeDisposable

open class BasePresenter<V : BaseView>(protected var view: V) {

protected val compositeDisposable = CompositeDisposable()

fun onDestroy() {
if (!compositeDisposable.isDisposed) {
compositeDisposable.dispose()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.constructor.sample.common

interface BaseView
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package io.constructor.sample.data

import android.content.Context
import io.constructor.data.model.search.SearchResult
import java.io.*

class CartDataStorage(private val context: Context) {

private var cartFile: File = File(context.filesDir, "cart")

init {
if (!cartFile.exists()) {
cartFile.createNewFile()
}
}

fun addToCart(item: SearchResult, quantity: Int = 1) {
readAndWrite {
if (it.containsKey(item.result.id)) {
it[item.result.id] = it[item.result.id]!!.first to (it[item.result.id]!!.second + quantity)
} else {
it[item.result.id] = item to quantity
}
}
}

fun removeFromCart(item: SearchResult) {
readAndWrite {
if (it.containsKey(item.result.id)) {
if (it.get(item.result.id)!!.second == 1) {
it.remove(item.result.id)
} else {
it[item.result.id] = it[item.result.id]!!.first to (it[item.result.id]!!.second - 1)
}
}
}
}

fun removeAll() {
readAndWrite {
it.clear()
}
}

fun getCartContent(): LinkedHashMap<String, Pair<SearchResult, Int>> {
var searchResult: LinkedHashMap<String, Pair<SearchResult, Int>> = linkedMapOf()
readAndWrite {
searchResult = it
}
return searchResult
}

fun readAndWrite(action: (LinkedHashMap<String, Pair<SearchResult, Int>>) -> Unit) {
var cartItems: LinkedHashMap<String, Pair<SearchResult, Int>> = linkedMapOf()
try {
val input = ObjectInputStream(FileInputStream(cartFile))
cartItems = input.readObject() as LinkedHashMap<String, Pair<SearchResult, Int>>
input.close()
} catch (e: Exception) {
e.printStackTrace()
}
action.invoke(cartItems)
val output = ObjectOutputStream(FileOutputStream(cartFile))
output.writeObject(cartItems)
output.close()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.constructor.sample.di

import android.content.Context
import io.constructor.sample.data.CartDataStorage

class DependencyProvider {
companion object {

fun provideCartStorage(context: Context): CartDataStorage {
return CartDataStorage(context)
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.constructor.sample.extensions

import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable

operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
this.add(disposable)
}
Loading