Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c586c7b
Inicio do app 1 - Adicionando as bibliotecas
Oct 31, 2019
8550cf3
Tela vitrine 1 - Preparando activity, viewModel, cliente e repository
Oct 31, 2019
cc7f335
Tela vitrine 2 - Fazendo chamada a API corretamente
Oct 31, 2019
74c8dbe
Tela vitrine 3 - Chamada de Search resgatando de fato o menor preço
Oct 31, 2019
0acc75c
Tela vitrine 4 - Inicio de injeção de dependência
Oct 31, 2019
47aec00
Tela Vitrine 5 - Adicionado ViewModel e Search com MutableLiveData
Oct 31, 2019
d3733eb
Tela vitrine 6 - Mostrando lista de produtos
Oct 31, 2019
2a0bbe2
Tela vitrine 7- Binding com avisos de loading e error
Oct 31, 2019
d754423
Tela vitrine 8 - Colocando adapter com duas colunas
Oct 31, 2019
55aeca3
Tela vitrine 9 - Busca implementada
Nov 1, 2019
d4adab1
Tela categoria 1 - Inicio repositório para categoria
Nov 1, 2019
408a922
Tela categoria 2 - Repositório de categoria funcionando
Nov 1, 2019
3c53d86
Tela categoria 3 - Adapter da tela de categoria pronto
Nov 1, 2019
3739fa6
Tela categoria 4 - Comportamentos implementados
Nov 1, 2019
81b700e
Revisao final 1 - Merge das duas telas prontas
Nov 1, 2019
843c0c1
Revisao final 2 - Telas integradas e prontas
Nov 1, 2019
9b1ca5b
Revisao final 3 - ScrollListener implementado, funcionando também search
Nov 1, 2019
1801587
Revisão final 4 - Pesquisa melhorada
Nov 1, 2019
ad6f96c
Revisão final 5 - Melhoria nos textos dos preços dos items a venda
Nov 1, 2019
eb400d3
Revisao final 6 - Ajuste de cores no item a venda e espacamento na catg.
Nov 1, 2019
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
Prev Previous commit
Next Next commit
Tela categoria 4 - Comportamentos implementados
  • Loading branch information
Felcks authored and Felcks committed Nov 1, 2019
commit 3739fa685e227be2b8c350f1218472794548fefb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.felcks.desafiofulllab.ui.categoria

import android.os.Bundle
import android.view.Menu
import android.widget.Toast
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatImageView
Expand All @@ -10,15 +11,10 @@ import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.felcks.desafiofulllab.App
import com.felcks.desafiofulllab.R
import com.felcks.desafiofulllab.api.RestApi
import com.felcks.desafiofulllab.common.repository.CategoryRepository
import com.felcks.desafiofulllab.common.viewmodel.Response
import com.felcks.desafiofulllab.common.viewmodel.Status
import com.felcks.desafiofulllab.databinding.ActivityCategoriaBinding
import kotlinx.android.synthetic.main.activity_categoria.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject

class CategoriaActivity: AppCompatActivity(){
Expand Down Expand Up @@ -64,14 +60,33 @@ class CategoriaActivity: AppCompatActivity(){
rv_list.layoutManager = layoutManager
rv_list.setItemViewCacheSize(listCategory.size)

this.adapter = CategoriaAdapter(listCategory)
this.adapter = CategoriaAdapter(listCategory, categoriaClickListener)
rv_list.adapter = adapter
}
else{
this.adapter?.updateAllItens(listCategory)
}
}

private fun updateToolbarTitle(){

val tipoCategoria = viewModel.getCurrentType()
supportActionBar?.title = tipoCategoria?.name ?: "Categoria"
}

private val categoriaClickListener = object : TwoParametersClickListener {
override fun onClick(pos: Int, obj: Any) {

try{
viewModel.selectItem(pos, obj)
updateToolbarTitle()
}
catch (e: Throwable){
Toast.makeText(this@CategoriaActivity, e.message, Toast.LENGTH_SHORT).show()
}
}
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
val actionBar : ActionBar? = supportActionBar
actionBar?.setDisplayHomeAsUpEnabled(true)
Expand All @@ -82,4 +97,20 @@ class CategoriaActivity: AppCompatActivity(){
onBackPressed()
return true
}

override fun onBackPressed() {

val tipoCategoria = viewModel.getCurrentType()
if(tipoCategoria == TipoCategoriaDTO.Categoria)
super.onBackPressed()
else{
try{
viewModel.showHomeCategory()
updateToolbarTitle()
}
catch (e: Throwable){
Toast.makeText(this@CategoriaActivity, e.message, Toast.LENGTH_SHORT).show()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import com.felcks.desafiofulllab.App
import com.felcks.desafiofulllab.R
import kotlinx.android.synthetic.main.item_category.view.*

class CategoriaAdapter(private var list: List<CategoriaDTO>):
class CategoriaAdapter(private var list: List<CategoriaDTO>,
private val selectCategoryListener: TwoParametersClickListener):
RecyclerView.Adapter<CategoriaAdapter.MyViewHolder>() {

val mLayoutInflater: LayoutInflater = App.instance.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
private val mLayoutInflater: LayoutInflater = App.instance.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view = mLayoutInflater.inflate(R.layout.item_category, parent, false)
Expand All @@ -27,7 +28,9 @@ class CategoriaAdapter(private var list: List<CategoriaDTO>):
val item = list[position]

holder.itemView.tv_name.text = item.name
//TODO implementar o clique
holder.itemView.layout_categoria.setOnClickListener {
selectCategoryListener.onClick(position, item)
}
}

fun updateAllItens(listCategory: List<CategoriaDTO>){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.felcks.desafiofulllab.ui.categoria

class CategoriaDTO (val name: String,
val icone: String?)
val icone: String?,
val tipo: TipoCategoriaDTO)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CategoriaViewModel(private val categoryRepository: CategoryRepository) : V
listCategoryDomain = list
listCategory.postValue(Response.success(
list.map {
CategoriaDTO(it.name, null)
CategoriaDTO(it.name, null, TipoCategoriaDTO.Categoria)
}
))
}
Expand All @@ -55,4 +55,38 @@ class CategoriaViewModel(private val categoryRepository: CategoryRepository) : V
}
}
}

fun selectItem(pos: Int, obj: Any){

val categoriaDTO = obj as? CategoriaDTO
?: throw Throwable("Função não implementada para esse objeto.")

if(categoriaDTO.tipo == TipoCategoriaDTO.Subcategoria)
throw Throwable("Pesquisa na subcategoria - função não implementada.")


val subCategorias = listCategoryDomain[pos].listSubCategories.map {
CategoriaDTO(it.name,
null,
TipoCategoriaDTO.Subcategoria)
}

listCategory.value = Response.success(subCategorias)
}

fun showHomeCategory(){

val categorias = this.listCategoryDomain.map {
CategoriaDTO(it.name,
null,
TipoCategoriaDTO.Categoria)
}

listCategory.value = Response.success(categorias)

}

fun getCurrentType(): TipoCategoriaDTO?{
return (this.listCategory.value?.data as? List<*>)?.filterIsInstance<CategoriaDTO>()?.first()?.tipo
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.felcks.desafiofulllab.ui.categoria

enum class TipoCategoriaDTO() {
Categoria,
Subcategoria
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.felcks.desafiofulllab.ui.categoria

interface TwoParametersClickListener {
fun onClick(pos: Int, obj: Any)
}