Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
deboraheinig committed Apr 25, 2022
0 parents commit 6dec2a5
Show file tree
Hide file tree
Showing 44 changed files with 1,237 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.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
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

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

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

20 changes: 20 additions & 0 deletions .idea/gradle.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/misc.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
59 changes: 59 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdk 32

defaultConfig {
applicationId "com.example.shark"
minSdk 21
targetSdk 32
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'
}
}

dependencies {

implementation 'com.google.code.gson:gson:2.8.7'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

//glide
def glide_version = "4.12.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"

// GSON
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

// coroutine
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.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.shark

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.shark", 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"
package="com.example.shark">

<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/Theme.Shark">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
10 changes: 10 additions & 0 deletions app/src/main/java/com/example/shark/Deal.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.shark
//Modelação de dados que serão mostrados
data class Deal (
val title: String,
val gameID: Int,
val normalPrice: Double,
val salePrice: Double,
val savings: Double,
val thumb: String
)
67 changes: 67 additions & 0 deletions app/src/main/java/com/example/shark/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.example.shark

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.Settings
import android.view.KeyEvent
import android.view.View
import android.widget.EditText
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.textfield.TextInputEditText
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch


class MainActivity : AppCompatActivity() {

private var layoutManager: RecyclerView.LayoutManager? = null
private var adapter: SharkAdapter? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)

val sharkApi = RetrofitHelper.getInstance().create(SharkService::class.java)

layoutManager = LinearLayoutManager(this)

findViewById<RecyclerView>(R.id.recyclerView).layoutManager = layoutManager

GlobalScope.launch {
val result = sharkApi.getDeals()
if (result != null) {
runOnUiThread {
findViewById<RecyclerView>(R.id.recyclerView).adapter = SharkAdapter(result)
}
}
}
//Função do Button
findViewById<FloatingActionButton>(R.id.button).setOnClickListener {
//Joguinhos em promoção -> Resultados para: (jogo digitado//text)
findViewById<TextView>(R.id.resultados).visibility = View.VISIBLE
val text = findViewById<TextInputEditText>(R.id.textEdit).text.toString()
findViewById<TextView>(R.id.joguinhos).text = text

findViewById<EditText>(R.id.textEdit).setOnKeyListener(View.OnKeyListener { _, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP) {
//Perform Code
//Nova coroutine para a RecyclerView atualizada:
GlobalScope.launch {
//Recycler com itens especificos
val newResult = sharkApi.getDeals(text)
if (newResult != null) {
runOnUiThread {
findViewById<RecyclerView>(R.id.recyclerView).adapter = SharkAdapter(newResult)
}
}
}
return@OnKeyListener true
}
false
})
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/example/shark/RetrofitHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.shark

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

object RetrofitHelper {

val baseUrl = "https://www.cheapshark.com/"

fun getInstance(): Retrofit {
return Retrofit.Builder().baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
//Convert Factory = converter objeto JSON pra objeto JAVA
.build()
}
}
53 changes: 53 additions & 0 deletions app/src/main/java/com/example/shark/SharkAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.shark

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import retrofit2.Call

class SharkAdapter(private var items: List<Deal>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return SharkViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_shark, parent, false)
)
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when(holder){
is SharkViewHolder ->{
holder.bind(items[position])
}
}
}
override fun getItemCount(): Int {
return items.size
}
fun setDataSet(Deal: List<Deal>){
this.items = Deal
}
class SharkViewHolder constructor(
itemView : View
): RecyclerView.ViewHolder(itemView){
private val title = itemView.findViewById<TextView>(R.id.title)
private val gameID = itemView.findViewById<TextView>(R.id.gameID)
private val normalPrice = itemView.findViewById<TextView>(R.id.normalPrice)
private val salePrice = itemView.findViewById<TextView>(R.id.salePrice)
private val savings = itemView.findViewById<TextView>(R.id.savings)
private val thumb = itemView.findViewById<ImageView>(R.id.thumb)

fun bind(deal: Deal){
title.text = deal.title
gameID.text = deal.gameID.toString()
normalPrice.text = deal.normalPrice.toString()
salePrice.text = deal.salePrice.toString()
savings.text = deal.savings.toString()

Glide.with(itemView.context)
.load(deal.thumb)
.into(thumb)
}
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/example/shark/SharkService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.shark
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Query

interface SharkService {
@GET("api/1.0/deals")
suspend fun getDeals() : List<Deal>

@GET("api/1.0/deals")
fun getDeals(@Query("search")title:String) : List<Deal>

}
Loading

0 comments on commit 6dec2a5

Please sign in to comment.