Skip to content

Commit

Permalink
Merge pull request #3 from mavinii/nav_view
Browse files Browse the repository at this point in the history
First pull request
  • Loading branch information
mavinii authored May 8, 2022
2 parents 81d09da + 1c322aa commit 142a613
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 143 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
4 - Show order history:
- [ ] List users orders
- [ ] On clicking an Order, show Order details and Products ordered
- [ ] On clicking a Product, take them to Product description page created for 3.3
- [x] On clicking a Product, take them to Product description page created for 3.3

5 - Show User details:
- [ ] Use the stored userID to show user details
- [ ] Show a random circular profile image from https://thispersondoesnotexist.com/
- [ ] Show Logout button, on click take back to Signup / Log In page (Restart should not auto login after logout)
- [x] Use the stored userID to show user details
- [x] Show a random circular profile image from https://thispersondoesnotexist.com/
- [x] Show Logout button, on click take back to Signup / Log In page (Restart should not auto login after logout)

6 - UI/Implementations Requirements:
- [ ] RecyclerView used for all Lists: Categories, Products, Orders
- [ ] ViewPager2 with bottom TabLayout for: Shop, Orders, Profile icons
- [ ] If logged in, attach authentication token to all requests until logout
- [ ] Add a small "About this app" button in the profile page, that shows a page with your copyright details and credits.
- [x] If logged in, attach authentication token to all requests until logout
- [x] Add a small "About this app" button in the profile page, that shows a page with your copyright details and credits.

## JSON API Links:
- Root URL: https://fakestoreapi.com
Expand Down
46 changes: 13 additions & 33 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"

repositories {
mavenCentral()

flatDir{
dirs 'libs'
}
}

android {
compileSdkVersion 32
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.marcosoliveira.myshopapp"
minSdkVersion 28
minSdkVersion 22
targetSdkVersion 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

androidExtensions{
experimental = true
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -41,43 +28,35 @@ android {
buildFeatures {
viewBinding true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
jvmTarget = '1.8'
}
}

dependencies {
implementation platform('com.google.firebase:firebase-bom:29.3.1')
implementation 'com.google.firebase:firebase-firestore-ktx:24.1.2'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.firebase:firebase-auth:21.0.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

implementation 'com.google.firebase:firebase-auth:21.0.3'
implementation platform('com.google.firebase:firebase-bom:29.3.1')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-firestore-ktx:24.1.2'

implementation 'com.google.firebase:firebase-database-ktx:20.0.5'
implementation 'com.google.firebase:firebase-database:20.0.5'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

// Architectural Components
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"

// Room
implementation "androidx.room:room-runtime:2.2.5"
implementation "androidx.room:room-runtime:2.4.2"
kapt "androidx.room:room-compiler:2.2.5"

// Kotlin Extensions and Coroutines support for Room
Expand All @@ -93,8 +72,8 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"

// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation "com.squareup.okhttp3:logging-interceptor:4.5.0"

// Navigation Components
Expand All @@ -107,4 +86,5 @@ dependencies {

//material design
implementation 'com.google.android.material:material:1.2.0-alpha04'

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FirestoreClass {

// This function register an user, from the RegisterActivity
fun registerUser(activity: RegisterActivity, userInfo: User){
mFirestore.collection(Constants.USER)
mFirestore.collection(Constants.USERS)
.document(userInfo.id) // It gets the id from "User" activity
.set(userInfo, SetOptions.merge()) // It merges the both information
.addOnFailureListener {
Expand Down Expand Up @@ -52,7 +52,7 @@ class FirestoreClass {
fun getUserDetails(activity: Activity){

// Passing the collection name with the data we want
mFirestore.collection(Constants.USER)
mFirestore.collection(Constants.USERS)

// The document if to get the fields of an user
.document(getCurrentUserID())
Expand All @@ -64,11 +64,15 @@ class FirestoreClass {
val user = document.toObject(User::class.java)!!

// to retrieve data from firebase and share between MainActivity, UserProfileActivity
val sharedPreferences = activity.getSharedPreferences(Constants.MYSHOPAPP_PREFERENCES, Context.MODE_PRIVATE)
val sharedPreferences = activity.getSharedPreferences(
Constants.MYSHOPAPP_PREFERENCES,
Context.MODE_PRIVATE
)

val editor: SharedPreferences.Editor = sharedPreferences.edit()
editor.putString(
Constants.LOGGED_IN_USERNAME,
"${user.firstName} ${user.email} ${user.phone}"
"${user.firstName} ${user.phone} ${user.email}"
)
editor.apply()//4:28

Expand All @@ -92,6 +96,13 @@ class FirestoreClass {
)
}
}

// UPDATE USER PROFILE?
// use HashMap for display user details?
// fun displayUserDetails(user: User){
//
// }

}


Expand Down
20 changes: 11 additions & 9 deletions app/src/main/java/com/marcosoliveira/myshopapp/models/User.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.marcosoliveira.myshopapp.models

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

// all inf that is going to be stored on Firebase
// Parcelize can send some information to the UserActivity
@Parcelize
data class User (
val id: String = "",
val firstName: String? = "",
val lastName: String? = "",
val email: String? = "",
val phone: String? = "",
val address: String? = "",
val city: String? = "",
val state: String? = "",
val zipCode: String? = ""
val firstName: String = "",
val lastName: String = "",
val email: String = "",
val phone: String = "+353 ",
val address: String = "",
val city: String = "",
val state: String = "",
val zipCode: String = "",
val profileCompleted: Int = 0
): Parcelable
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.marcosoliveira.myshopapp.ui.activities

import android.app.Dialog
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.google.android.material.snackbar.Snackbar
import com.marcosoliveira.myshopapp.R
import kotlinx.android.synthetic.main.dialog_progress.*
//import kotlinx.android.synthetic.main.dialog_progress.*

open class BaseActivity : AppCompatActivity() {

Expand All @@ -25,14 +26,18 @@ open class BaseActivity : AppCompatActivity() {
}

// Function that shows the Progress Dialog
fun showProgressDialog(text: String){
fun showProgressDialog(){
mProgressDialog = Dialog(this)

// Set the screen content from a layout resource.
// the resource will be inflated adding all top-level views to the screen
mProgressDialog.setContentView(R.layout.dialog_progress)

mProgressDialog.tv_progress_text.text = text
// AFTER i started to user "parcelize" i cannot get the val directly
// https://stackoverflow.com/questions/64925126/how-to-use-parcelize-now-that-kotlin-android-extensions-is-being-deprecated
// val progressText = findViewById<TextView>(R.id.tv_progress_text).text
// mProgressDialog.setTitle("Please, wait...")
// mProgressDialog.progressText = text OLD

mProgressDialog.setCancelable(false)
mProgressDialog.setCanceledOnTouchOutside(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.google.firebase.ktx.Firebase
import com.marcosoliveira.myshopapp.R
import com.marcosoliveira.myshopapp.models.User

class DeliveryActivity : AppCompatActivity() {
open class DeliveryActivity : AppCompatActivity() {

lateinit var user: User
lateinit var auth: FirebaseAuth
Expand Down Expand Up @@ -124,35 +124,42 @@ class DeliveryActivity : AppCompatActivity() {
)
val currentUser = FirebaseAuth.getInstance().currentUser
if (currentUser != null) {
db.collection("user").document(currentUser.uid)
db.collection("users").document(currentUser.uid)
.set(data, SetOptions.merge())
}

// Notification after all inputs have been filled in
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_icon)
.setContentTitle("Payment confirmation.")
.setContentText("Please check user profile for more.")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.build()

val notificationManager = NotificationManagerCompat.from(this)
notificationManager.notify(NOTIFICATION_ID, notification)

sendMessageOrderCompleted()
orderCompletedWithSuccess()
}
}

fun sendMessageOrderCompleted(){

// Notification after all inputs have been filled in
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_icon)
.setContentTitle("Payment confirmation.")
.setContentText("Thanks for buying with us.")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.build()

val notificationManager = NotificationManagerCompat.from(this)
notificationManager.notify(NOTIFICATION_ID, notification)

}

// Order completed
fun orderCompletedWithSuccess(){

// TODO Send the user their profile after payment
// TODO using the intent, try to display user product bought in the profile activity
val intent = Intent(this@DeliveryActivity, MainActivity::class.java)
val intent = Intent(this@DeliveryActivity, UserProfileActivity::class.java)
startActivity(intent)

// It takes the user to the login page and close the register screen
finish()
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ open class LoginActivity : BaseActivity(), View.OnClickListener {
fun userLoggedInSuccess(user: User){

// it prints the user details in the log
Log.i("First Name: ", user.firstName!!)
Log.i("Last Phone: ", user.phone!!)
Log.i("Last Name: ", user.email!!)
Log.i("First Name: ", user.firstName)
Log.i("Last Phone: ", user.lastName)
Log.i("Last Name: ", user.email)

// TODO: later on i can add a "if" case the user had already entered their info,
// TODO: take them to the payment screen without take the user to the delivery screen. 4:12:00
// If the user profile is incomplete then launch the UserProfileActivity
if (user.firstName != null){
if (user.profileCompleted == 0){
// If the user profile is incomplete then launch the UserProfileActivity.
val intent = Intent( this@LoginActivity, UserProfileActivity::class.java)
val intent = Intent( this@LoginActivity, UserProfileActivity::class.java) //DeliveryActivity
intent.putExtra(Constants.EXTRA_USER_DETAILS, user) //it gets the parcelable details from Constants
startActivity(intent)
} else {
// Redirect the user to Main Screen after log in.
val intent = Intent(this@LoginActivity, DeliveryActivity::class.java)
val intent = Intent(this@LoginActivity, UserProfileActivity::class.java)
startActivity(intent)
}
finish()
Expand Down Expand Up @@ -124,7 +124,7 @@ open class LoginActivity : BaseActivity(), View.OnClickListener {
if (validateLoginDetails()){

// shows the progressbar
showProgressDialog(resources.getString(R.string.please_wait))
// showProgressDialog()

// trim cuts all the empty spaces
val email = findViewById<EditText>(R.id.EmailText).text.toString().trim { it <= ' '}
Expand All @@ -135,13 +135,13 @@ open class LoginActivity : BaseActivity(), View.OnClickListener {

.addOnCompleteListener { task ->

// Hide de progress dialog
hideProgressDialog()

// If user is registered on database, he can login
// If user is registered on database, he can login
if(task.isSuccessful){
FirestoreClass().getUserDetails(this@LoginActivity)
} else {
// Hide de progress dialog
hideProgressDialog()

//It show a message in case something goes wrong
makeText(this, task.exception!!.message.toString(), Toast.LENGTH_LONG).show()
}
Expand Down
Loading

0 comments on commit 142a613

Please sign in to comment.