Skip to content

Commit

Permalink
Development (#9)
Browse files Browse the repository at this point in the history
* set up project

* Development Branch created

* Pruebas de estilos

* Some resorces added

* Tenderos App Setup

* Tenderos App Setup | Fragment name changed

* Implementación de UI para Sprint 1

* Alex Commit

* Some UI changes made by Alex Trujillo

* App style fixed with new UI elements

* Dev hu003 (#2)

* Initial commit

* Update README.md

* Readme branch (#1)

* Update README.md

* Update README.md

* Update README.dm

Update App Description

Co-authored-by: Arturo Cantú <a01196412@itesm.mx>

* set up project

* Development Branch created

* Pruebas de estilos

* Some resorces added

* Tenderos App Setup

* Tenderos App Setup | Fragment name changed

* Implementación de UI para Sprint 1

* Test read qr code in main activity

* WIP: Transactions

Co-authored-by: Rafael Salazar <rafael.salazar@tec.mx>
Co-authored-by: Arturo Cantú <a01196412@itesm.mx>
Co-authored-by: Alexandro Trujillo <alextrujillo@mbpdealexandro.lan>
Co-authored-by: alextrujillo <alexandro4v@gmail.com>
Co-authored-by: “Samantha <samsolis@tec.mx>

* Fix: extra line in android manifest

* Dev hu002 (#3)

* Update README.md

* Update README.md

* Programa Base

Base para implementa solución HU002

* Implementada Funcionalidad

Desplegar un código QR generado localmente. (Datos de muestra)

Co-authored-by: Arturo Cantú <a01196412@itesm.mx>

* Despliegue transaccion (#4)

* Added transaction info display

* Added display of transaction

* Display transaction that was read from QR code

Co-authored-by: “Samantha <samsolis@tec.mx>

* Fix: Fragment style and async function

* Show acceptance transaction code (#5)

* Modelos de Usuario y Tienda

* Fixed transaction display UI

* Se agregaron observaciones - Alex

* Add deployment.md file

* Readme Updates

* Update README.md

* Mainviewmodel added

* pagoPhone API .java fixed by updating old packages encodedKey

* Pagofon repo queries and ger balance methonds added

* Encrypted/decrypted POS

* Login & Sign up

Funcionando pero sin implementar

* Login y Signup funcionando

Funcionando pero con un solo UI

* commit 5 may 2020

* Login Flow fixed

* Login Flow fixed

* registro agregado con funcionalidades

* logout

* Provider list added

* Encripcion y Desencripcion de Identificacion

* Promo

Encriptada para generar

* Promo qr

* Create list of cupon history

* firestore dashboard mail auth added

* error con login y fragmentos con la libreria de navigation, fixed

* firestore los cupones ya se agregan a firestore en el perfil del cliente

* seguridad de botón agregado

* lista de historial actualizada

* lista de historial actualizada ui fixed

* Update readme

Co-authored-by: Alexandro Trujillo <alextrujillo@mbpdealexandro.lan>
Co-authored-by: alextrujillo <alexandro4v@gmail.com>
Co-authored-by: “Samantha <samsolis@tec.mx>
Co-authored-by: Esteban Arocha <estebanarocha1@gmail.com>
Co-authored-by: Rafael Salazar <rafael.salazar@tec.mx>
Co-authored-by: Arturo Cantú <a01196412@itesm.mx>
Co-authored-by: Esteban Arocha <A01153980@itesm.mx>
  • Loading branch information
8 people authored May 26, 2020
1 parent 67ab122 commit 9ec29c8
Show file tree
Hide file tree
Showing 38 changed files with 1,332 additions and 110 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ You should ask for access to this tools if you don't have it already:

## Development

### Changelog v0.3 - Cupons
- Added HU011 Receive coupon, and encrypt qr codes

### Changelog v0.2 - Authentication Update
- Added HU001 Login, Signup and Logout
- You can now create and access an accound using email and password
Expand Down
4 changes: 0 additions & 4 deletions TenderosApp/.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 TenderosApp/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ dependencies {

// Testing Navigation
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.firebase:firebase-firestore:21.4.3'
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"

//Network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.navigation.NavController
import androidx.navigation.findNavController
import com.example.tenderosapp.data.viewmodel.MainViewModel
import com.google.zxing.integration.android.IntentIntegrator
import kotlinx.android.synthetic.main.fragment_login.*

class MainActivity : AppCompatActivity() {

Expand All @@ -21,12 +22,9 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.main_activity)
navController = findNavController(R.id.nav_host_fragment)
viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)

}
override fun onActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent?) {

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
if (result != null) {
val value = result.contents
Expand All @@ -39,4 +37,5 @@ class MainActivity : AppCompatActivity() {
super.onActivityResult(requestCode, resultCode, data)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.example.tenderosapp.data.client

import android.util.Log
import androidx.annotation.NonNull
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.example.tenderosapp.model.Promo
import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
import com.google.firebase.Timestamp
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.FirebaseFirestoreSettings
import com.google.firebase.firestore.MetadataChanges
import com.google.firebase.firestore.QuerySnapshot
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import java.util.*
import kotlin.collections.ArrayList

class AppClient {
var isEmailRegistered: MutableLiveData<Boolean?>
var isPromoRegistered: MutableLiveData<Boolean?>
var promotionlist: MutableLiveData<ArrayList<Promo>?>


var db: FirebaseFirestore
private val settings : FirebaseFirestoreSettings

init {
isEmailRegistered = MutableLiveData()
isPromoRegistered = MutableLiveData()
promotionlist = MutableLiveData()
db = FirebaseFirestore.getInstance()
settings = FirebaseFirestoreSettings.Builder()
.setPersistenceEnabled(true)
.build()
db.firestoreSettings = settings // Offline Mode

}

companion object {
private var instance: AppClient? = null
fun getInstance(): AppClient {
if (instance == null) {
instance = AppClient()
}
return instance as AppClient
}
}

fun getIsEmailRegistered(): LiveData<Boolean?> = isEmailRegistered
fun getRegisterPromoSucccess(): LiveData<Boolean?> = isPromoRegistered
fun getPromotionList() : LiveData<ArrayList<Promo>?> = promotionlist


fun queryGetPromorionList(uid : String) {
db.collection("profile")
.document(uid)
.collection("promotion_list")
.get()
.addOnCompleteListener { task ->
val promotions : ArrayList<Promo> = ArrayList()

if (task.isSuccessful) {
for (document in task.result!!) {
val myObject = document.toObject(Promo::class.java)
promotions.add(myObject)
Log.d("OBJECT", myObject.toString())
}
} else {
Log.w("ERROR DATA", "Error getting documents.", task.getException())
}
Log.d("promo leng SIZE: ", promotions.size.toString())
if (promotions.size >0){
promotionlist.postValue(promotions)
}else promotionlist.postValue(null)
}

}

fun queryIsEmailRegistered(email : String) {
db.collection("approved_mails")
.whereEqualTo("mail", email)
.get()
.addOnSuccessListener { documents ->
Log.d("QUERY SUCCESS => ", documents.isEmpty.toString())
if (!documents.isEmpty){
isEmailRegistered.postValue(true)
}else{
isEmailRegistered.postValue(false)

}

}
.addOnFailureListener { exception ->
Log.w("NO DOCUMENT FOUND", "Error getting documents: ", exception)
isEmailRegistered.postValue(null)
}
}


fun queryRegisterPromo(promotion : Promo, uid : String) {
Log.d("Promo => ", promotion.toString())

db.collection("profile")
.document(uid)
.collection("promotion_list")
.add(promotion)
.addOnSuccessListener {
Log.d("promotion_list", "DocumentSnapshot successfully written!")
isPromoRegistered.postValue(true)
}
.addOnFailureListener { e -> Log.w(
"promotion_list", "Error writing document", e)
isPromoRegistered.postValue(false)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.example.tenderosapp.data.repository

import androidx.lifecycle.LiveData
import com.example.tenderosapp.data.client.AppClient
import com.example.tenderosapp.model.Promo

//Singleton
class AppRepository {
private val appClient : AppClient

init {
appClient = AppClient.getInstance()
}

companion object {
private var instance: AppRepository? = null
fun getInstance(): AppRepository {
if (instance == null) {
instance = AppRepository()
}
return instance as AppRepository
}
}

fun getIsEmailRegistered(): LiveData<Boolean?> = appClient.getIsEmailRegistered()

fun queryIsEmailRegistered(email : String) = appClient.queryIsEmailRegistered(email)

fun queryRegisterPromo(promo : Promo, uid : String ) = appClient.queryRegisterPromo(promo, uid)
fun getRegisterPromoSucccess(): LiveData<Boolean?> = appClient.getRegisterPromoSucccess()

fun getPromotionList() : LiveData<ArrayList<Promo>?> = appClient.getPromotionList()

fun queryGetPromorionList(uid : String) = appClient.queryGetPromorionList(uid)

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package com.example.tenderosapp.data.viewmodel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.tenderosapp.data.repository.AppRepository
import com.example.tenderosapp.data.repository.PagofonRepository
import com.example.tenderosapp.model.Promo
import com.example.tenderosapp.model.response.BalanceResponse

class MainViewModel : ViewModel() {

private var pagofonRepository : PagofonRepository
private var appRepository : AppRepository

enum class AuthenticationState {
UNAUTHENTICATED, // Initial state, the user needs to authenticate
Expand All @@ -21,11 +24,20 @@ class MainViewModel : ViewModel() {
init {
authenticationState.value = AuthenticationState.UNAUTHENTICATED
pagofonRepository = PagofonRepository.getInstance()

appRepository = AppRepository.getInstance()
}

fun getBalance(): LiveData<BalanceResponse?> = pagofonRepository.getBalance()
fun getIsEmailRegistered(): LiveData<Boolean?> = appRepository.getIsEmailRegistered()
fun getRegisterPromoSucccess(): LiveData<Boolean?> = appRepository.getRegisterPromoSucccess()

fun queryGetBalance() = pagofonRepository.queryGetBalance()

fun queryIsEmailRegistered(email : String) = appRepository.queryIsEmailRegistered(email)

fun queryRegisterPromo(promo : Promo, uid: String) = appRepository.queryRegisterPromo(promo, uid)

fun getPromotionList() : LiveData<ArrayList<Promo>?> = appRepository.getPromotionList()

fun queryGetPromorionList(uid : String) = appRepository.queryGetPromorionList(uid)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.tenderosapp.model

import android.os.Parcelable
import kotlinx.android.parcel.Parcelize

@Parcelize
class Promo (
var couponCode: String,
var couponDiscount: String,
var couponType: String,
var description: String,
var businessId: String,
var businessName: String,
var ExpiryDate: Long
) : Parcelable {
constructor() : this(
couponCode = "",
couponDiscount = "",
couponType = "",
businessId = "",
businessName = "",
description = "",
ExpiryDate = 0
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.example.tenderosapp.model

data class Provider(val name: String, val colorRGB : String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.example.tenderosapp.ui.home

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import android.view.View
import android.widget.Toast
import androidx.annotation.IdRes
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.navigation.Navigation
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.app.calendarioliturgico.view.calendar.CuponHistoryAdapter
import com.example.tenderosapp.MainActivity
import com.example.tenderosapp.R
import com.example.tenderosapp.model.Transaction
import com.example.tenderosapp.model.Promo
import com.example.tenderosapp.data.viewmodel.MainViewModel
import com.example.tenderosapp.model.Provider
import com.google.firebase.auth.FirebaseAuth
import com.google.gson.Gson
import com.google.zxing.integration.android.IntentIntegrator
import kotlinx.android.synthetic.main.home_fragment.*
import kotlinx.android.synthetic.main.home_fragment.readqr_main_fab
import kotlinx.android.synthetic.main.home_fragment.toolbar_main_tb
import com.example.tenderosapp.util.Encrypter.Companion.decyptData
import kotlinx.android.synthetic.main.fragment_cupon_history.*
import kotlinx.android.synthetic.main.home_fragment.provider_recycler_rv
import java.lang.Exception


class CuponHistoryFragment : Fragment(R.layout.fragment_cupon_history) {
private lateinit var auth: FirebaseAuth
private lateinit var viewModel: MainViewModel
public override fun onStart() {
super.onStart()
auth = FirebaseAuth.getInstance()
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
auth = FirebaseAuth.getInstance()

if(auth.currentUser == null){
getFragmentNavController(R.id.nav_host_fragment)!!.navigate(R.id.fragment_login)
}
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
viewModel.queryGetPromorionList(auth.uid!!)
//This is a Dummy List of Providers

//setup lecturas
val llLecturas = LinearLayoutManager(context)
llLecturas.orientation = LinearLayoutManager.VERTICAL
provider_recycler_rv.layoutManager = llLecturas

viewModel.getPromotionList().observe(this, Observer {
it?.let {
Toast.makeText(context,"Desplegando información...", Toast.LENGTH_SHORT).show()
provider_recycler_rv.adapter = CuponHistoryAdapter(context!!, it)
(provider_recycler_rv.adapter as CuponHistoryAdapter).notifyDataSetChanged()
}?:run{
Toast.makeText(context,"Hubo un error obteniendo los datos... Inténtalo de nuevo", Toast.LENGTH_SHORT).show()
}
})


promo_backbutton.setOnClickListener {
getFragmentNavController(R.id.nav_host_fragment)!!.popBackStack()
}
//END --- This is a Dummy List of Providers
}

fun Fragment.getFragmentNavController(@IdRes id: Int) = activity?.let {
return@let Navigation.findNavController(it,id)
}
}

Loading

0 comments on commit 9ec29c8

Please sign in to comment.