Skip to content
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
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
35 changes: 35 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
69 changes: 69 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 28
defaultConfig {
applicationId "android.sample.wavechallenge"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

buildTypes.each {
Properties properties = new Properties()
properties.load(project.rootProject.file("local.properties").newDataInputStream())
def waveApiKey = properties.getProperty("wave_api_key", "")
it.buildConfigField 'String', "WAVE_API_KEY", waveApiKey
it.resValue 'string', "api_key", waveApiKey
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
implementation 'androidx.core:core-ktx:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

//Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
implementation "com.squareup.retrofit2:retrofit-mock:$retrofitVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttpLoggingInterceptorVersion"

//RecyclerView
implementation 'com.android.support:recyclerview-v7:28.0.0'

//Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" // For Kotlin use navigation-fragment-ktx
implementation "androidx.navigation:navigation-ui-ktx:$nav_version" // For Kotlin use navigation-ui-ktx

//Kotlin Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinCoroutineVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutineVersion"
implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2"

implementation "android.arch.lifecycle:extensions:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-common:$lifecycleVersion"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0-alpha03"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package android.sample.wavechallenge

import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("android.sample.wavechallenge", appContext.packageName)
}
}
24 changes: 24 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="android.sample.wavechallenge">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
7 changes: 7 additions & 0 deletions app/src/main/java/android/sample/wavechallenge/Constants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package android.sample.wavechallenge

object Constants {
const val WAVE_API_KEY = BuildConfig.WAVE_API_KEY

const val WAVE_API_URL = "https://api.waveapps.com/"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package android.sample.wavechallenge.adapter

import android.content.Context
import android.sample.wavechallenge.R
import android.sample.wavechallenge.model.Product
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.item_product_layout.view.*

class ProductListAdapter(
private var context: Context?,
private var itemList: List<Product>?
) : RecyclerView.Adapter<ProductListAdapter.ItemViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.item_product_layout, parent, false)
return ItemViewHolder(view)
}

override fun getItemCount(): Int {
return itemList?.size ?: 0
}

override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
val product = itemList?.get(position)
product?.let {
holder.tvName.text = product.name
holder.tvPrice.text = context?.getString(R.string.formatted_price, product.price.toString())
}
}

fun updateItems(products: List<Product>) {
itemList = listOf()
itemList = products
notifyDataSetChanged()
}

class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) {
var tvName: TextView = view.tv_name
var tvPrice: TextView = view.tv_price
}
}
39 changes: 39 additions & 0 deletions app/src/main/java/android/sample/wavechallenge/api/ApiFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package android.sample.wavechallenge.api

import android.sample.wavechallenge.Constants
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object ApiFactory {

private val authInterceptor = Interceptor { chain ->
val newRequest = chain.request()
.newBuilder()
.addHeader("Authorization", "Bearer " + Constants.WAVE_API_KEY)
.build()

chain.proceed(newRequest)
}

private val logger = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC)

private val waveClient = OkHttpClient().newBuilder()
.addInterceptor(logger)
.addInterceptor(authInterceptor)
.build()


private fun retrofit(): Retrofit = Retrofit.Builder()
.client(waveClient)
.baseUrl(Constants.WAVE_API_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build()


val waveApi: WaveApi = retrofit().create(WaveApi::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package android.sample.wavechallenge.api

open class DataSourceException(message: String? = null) : Exception(message)

class RemoteDataNotFoundException : DataSourceException("Data not found from the remote source")
12 changes: 12 additions & 0 deletions app/src/main/java/android/sample/wavechallenge/api/WaveApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package android.sample.wavechallenge.api

import android.sample.wavechallenge.model.Product
import kotlinx.coroutines.Deferred
import retrofit2.http.GET
import retrofit2.http.Path

//A retrofit Network Interface for the Wave Api
interface WaveApi{
@GET("businesses/{business_id}/products/")
fun getProductsAsync(@Path("business_id") businessId: String): Deferred<List<Product>>
}
Loading