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

Desafio Ricardo #44

Open
wants to merge 2 commits into
base: master
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
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
70 changes: 70 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "com.example.nexaas"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}

}

ext {
supportVersion = "28.0.0"
retrofitVersion = "2.6.0"
}

dependencies {
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-moshi:$retrofitVersion"

implementation("com.squareup.moshi:moshi:1.9.3")
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
implementation 'androidx.navigation:navigation-fragment:2.2.2'
implementation 'androidx.navigation:navigation-ui:2.2.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

compile 'com.squareup.picasso:picasso:2.5.2'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "com.android.support:recyclerview-v7:$supportVersion"

implementation 'android.arch.lifecycle:extensions:1.1.1'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
}
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 com.example.nexaas

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.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.getInstrumentation().targetContext
assertEquals("com.example.nexaas", appContext.packageName)
}
}
30 changes: 30 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nexaas">

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

<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">
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity android:name=".presentation.details.PencilDetailsActivity" />
<activity android:name=".presentation.pencils.PencilsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
31 changes: 31 additions & 0 deletions app/src/main/java/com/example/nexaas/FirstFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.nexaas

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.navigation.fragment.findNavController

/**
* A simple [Fragment] subclass as the default destination in the navigation.
*/
class FirstFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_first, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<Button>(R.id.button_first).setOnClickListener {
findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)
}
}
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/example/nexaas/SecondFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.nexaas

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.navigation.fragment.findNavController

/**
* A simple [Fragment] subclass as the second destination in the navigation.
*/
class SecondFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_second, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<Button>(R.id.button_second).setOnClickListener {
findNavController().navigate(R.id.action_SecondFragment_to_FirstFragment)
}
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/example/nexaas/data/ApiService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.nexaas.data

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory


class ApiService {
companion object {
fun getRetrofitInstance(url : String) : Retrofit {
return Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
}

/*
fun initRetrofit(): Retrofit{
return Retrofit.Builder()
.baseUrl("https://raw.githubusercontent.com/")
.addConverterFactory(GsonConverterFactory.create())
.build()
}

val services = initRetrofit().create(PencilServices::class.java)
*/
}
10 changes: 10 additions & 0 deletions app/src/main/java/com/example/nexaas/data/PencilServices.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.nexaas.data

import com.example.nexaas.data.response.PencilBodyResponse
import retrofit2.Call
import retrofit2.http.GET

interface PencilServices {
@GET("myfreecomm/desafio-mobile-android/master/api/data.json")
fun getPencils(): Call<List<PencilBodyResponse>>
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/example/nexaas/data/model/Pencil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.nexaas.data.model

import com.google.gson.annotations.SerializedName

data class Pencil(
val item: String,
val quantity: Int,
val stock: String,
val imageUrl: String,
val price: Double,
val tax: Double,
val shipping: Double,
val description: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.nexaas.data.response

import com.google.gson.annotations.SerializedName

data class PencilBodyResponse (
@SerializedName("name") val name: String,
@SerializedName("quantity") val quantity: Int,
@SerializedName("stock") val stock: String,
@SerializedName("image_url") val imageUrl: String,
@SerializedName("price") val price: Double,
@SerializedName("tax") val tax: Double,
@SerializedName("shipping") val shipping: Double,
@SerializedName("description") val description: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.nexaas.presentation.base

import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar

open class BaseActivity : AppCompatActivity() {

protected fun setupToolBar(toolbar: Toolbar, title: Int){
toolbar.title = getString(title)
setSupportActionBar(toolbar)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.example.nexaas.presentation.details

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.example.nexaas.R
import com.example.nexaas.presentation.base.BaseActivity
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.activity_pencil_details.*

class PencilDetailsActivity : BaseActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_pencil_details)

val url = intent.getStringExtra(EXTRA_URL)
val item = intent.getStringExtra(EXTRA_ITEM)
val stock = intent.getIntExtra(EXTRA_STOCK,0)
val price = intent.getDoubleExtra(EXTRA_PRICE, 0.0)
val description = intent.getStringExtra(EXTRA_DESCRIPTION)

var stockText: String

if(stock < 2){
stockText = [email protected](R.string.low_stock)
stockText = stockText.replace("#", stock.toString())
}
else
stockText = [email protected](R.string.item_in_stock)

Picasso.with(this@PencilDetailsActivity).load(url).into(imageDetailItem)

item_detail.text = item
stock_item.text = stockText
price_item.text = "$${price}"
item_description.text = description
}

companion object{

private const val EXTRA_URL = "EXTRA_URL"
private const val EXTRA_ITEM = "EXTRA_ITEM"
private const val EXTRA_STOCK = "EXTRA_STOCK"
private const val EXTRA_PRICE = "EXTRA_PRICE"
private const val EXTRA_DESCRIPTION = "EXTRA_DESCRIPTION"

fun getStartIntent(context: Context, url: String, item: String, stock: Int,
price: Double, description: String): Intent {

return Intent(context, PencilDetailsActivity::class.java).apply {
putExtra(EXTRA_URL, url)
putExtra(EXTRA_ITEM, item)
putExtra(EXTRA_STOCK, stock)
putExtra(EXTRA_PRICE, price)
putExtra(EXTRA_DESCRIPTION, description)
}
}
}
}
Loading