Skip to content

Commit

Permalink
More small bugfixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
NikM3 committed Apr 3, 2023
1 parent b643c99 commit 227abf0
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 72 deletions.
10 changes: 7 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Created by Team Symphony on 4/2/23, 3:50 AM
~ Created by Team Symphony on 4/2/23, 9:44 PM
~ Copyright (c) 2023 . All rights reserved.
~ Last modified 4/2/23, 2:38 AM
~ Last modified 4/2/23, 9:44 PM
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
Expand All @@ -25,10 +25,14 @@
android:supportsRtl="true"
android:theme="@style/Theme.MrFit"
tools:targetApi="31">
<activity
android:name=".ui.CustomExercisesActivity"
android:exported="false"
android:parentActivityName=".ui.MainActivity" />
<activity
android:name=".ui.CalendarActivity"
android:exported="false"
android:parentActivityName=".ui.MainActivity"/>
android:parentActivityName=".ui.MainActivity" />
<activity
android:name=".ui.PostWorkoutActivity"
android:exported="false"
Expand Down
34 changes: 17 additions & 17 deletions app/src/main/java/com/symphony/mrfit/data/profile/UserRepository.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Team Symphony on 4/1/23, 10:04 PM
* Created by Team Symphony on 4/2/23, 9:44 PM
* Copyright (c) 2023 . All rights reserved.
* Last modified 4/1/23, 10:04 PM
* Last modified 4/2/23, 9:42 PM
*/

package com.symphony.mrfit.data.profile
Expand Down Expand Up @@ -105,7 +105,7 @@ class UserRepository {
try {
val docRef = database.collection(USER_COLLECTION).document(user.uid)
.collection(HISTORY_COLLECTION).add(history).await()
docRef.update("historyID", docRef.id)
docRef.update("historyID", docRef.id).await()
} catch (e: java.lang.Exception) {
Log.d(TAG, "Error writing documents: ", e)
}
Expand Down Expand Up @@ -161,6 +161,19 @@ class UserRepository {
.child(auth.currentUser!!.uid)
}

/**
* Add or change a profile picture to a User's Firebase profile
*/
suspend fun changeProfilePicture(uri: Uri) {
Log.d(TAG, "Updating the user's profile picture to $uri")
val ref = storage.reference.child(PROFILE_PICTURE).child(auth.currentUser!!.uid)
val profileUpdates = userProfileChangeRequest {
photoUri = Uri.parse(ref.toString())
}
auth.currentUser!!.updateProfile(profileUpdates).await()
ref.putFile(uri)
}

/**
* Add a new Notification to the user's notification subcollection
*/
Expand Down Expand Up @@ -225,7 +238,7 @@ class UserRepository {
.collection(GOAL_COLLECTION)
.add(goal)
.await()
docRef.update("goalID", docRef.id)
docRef.update("goalID", docRef.id).await()
} catch (e: java.lang.Exception) {
Log.w(TAG, "Error writing document", e)
}
Expand Down Expand Up @@ -286,19 +299,6 @@ class UserRepository {

}

/**
* Add or change a profile picture to a User's Firebase profile
*/
suspend fun changeProfilePicture(uri: Uri) {
Log.d(TAG, "Updating the user's profile picture to $uri")
val ref = storage.reference.child(PROFILE_PICTURE).child(auth.currentUser!!.uid)
val profileUpdates = userProfileChangeRequest {
photoUri = Uri.parse(ref.toString())
}
auth.currentUser!!.updateProfile(profileUpdates).await()
ref.putFile(uri)
}

companion object {
const val USER_COLLECTION = "users"
const val HISTORY_COLLECTION = "_history"
Expand Down
109 changes: 64 additions & 45 deletions app/src/main/java/com/symphony/mrfit/ui/CustomExercisesActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Team Symphony on 4/2/23, 2:50 PM
* Created by Team Symphony on 4/2/23, 9:44 PM
* Copyright (c) 2023 . All rights reserved.
* Last modified 4/2/23, 2:50 PM
* Last modified 4/2/23, 9:44 PM
*/

package com.symphony.mrfit.ui
Expand All @@ -12,10 +12,7 @@ import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.CheckBox
import android.widget.EditText
import android.widget.ImageView
import android.widget.*
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -25,11 +22,11 @@ import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.signature.ObjectKey
import com.google.firebase.ktx.Firebase
import com.google.firebase.storage.ktx.storage
import com.symphony.mrfit.R
import com.symphony.mrfit.data.exercise.ExerciseAdapter2
import com.symphony.mrfit.data.exercise.ExerciseRepository
import com.symphony.mrfit.data.exercise.ExerciseViewModel
import com.symphony.mrfit.data.exercise.ExerciseViewModelFactory
import com.symphony.mrfit.data.model.Exercise
Expand Down Expand Up @@ -119,7 +116,10 @@ class CustomExercisesActivity : AppCompatActivity() {
thumbnail.observe(this, Observer {
val thumbnail = it ?: return@Observer

Glide.with(this).load(thumbnail).into(image)
Glide.with(this)
.load(thumbnail)
.signature(ObjectKey(System.currentTimeMillis().toString()))
.into(image)
})

tags.setOnFocusChangeListener { _, hasFocus ->
Expand All @@ -135,30 +135,40 @@ class CustomExercisesActivity : AppCompatActivity() {
intent.type = "image/*"
photoPicker.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
}

/**
* TODO: If a field is empty, replace it with placeholder text
*/
save.setOnClickListener {
val newName = name.text.toString()
val newDesc = desc.text.toString()
val newTags = ArrayList(tags.text.toString().split(",", ", "))
val newExercise = Exercise(
name = newName,
description = newDesc,
tags = newTags,
repsFlag = reps.isChecked,
setsFlag = sets.isChecked,
durationFlag = duration.isChecked,
distanceFlag = distance.isChecked
)
exerciseViewModel.addExercise(
newExercise,
thumbnail.value!!
)

exerciseViewModel.getExercisesByUser()
dialog.dismiss()
if (name.text.isNotEmpty()) {
val newName = name.text.toString()
var newDesc = ""
if (desc.text.isNotEmpty())
newDesc = desc.text.toString()
var newTags = ArrayList<String>()
if (tags.text.isNotEmpty())
newTags = ArrayList(tags.text.toString().split(",", ", "))
val newExercise = Exercise(
name = newName,
description = newDesc,
tags = newTags,
repsFlag = reps.isChecked,
setsFlag = sets.isChecked,
durationFlag = duration.isChecked,
distanceFlag = distance.isChecked
)
exerciseViewModel.addExercise(
newExercise,
thumbnail.value!!
)

exerciseViewModel.getExercisesByUser()
thumbnail.value = Uri.parse(ExerciseActivity.PLACEHOLDER_THUMBNAIL)
dialog.dismiss()
} else {
Toast.makeText(
this,
"You must name your exercise",
Toast.LENGTH_SHORT
)
.show()
}
}

cancel.setOnClickListener {
Expand All @@ -183,6 +193,7 @@ class CustomExercisesActivity : AppCompatActivity() {
val distance = dialog.findViewById<CheckBox>(R.id.distanceCheckBox)
val save = dialog.findViewById<Button>(R.id.saveExerciseButton)
val cancel = dialog.findViewById<Button>(R.id.cancelExerciseButton)
var loadDefault = true

name.setText(exercise.name)
desc.setText(exercise.description)
Expand All @@ -191,19 +202,20 @@ class CustomExercisesActivity : AppCompatActivity() {
sets.isChecked = exercise.setsFlag
duration.isChecked = exercise.durationFlag
distance.isChecked = exercise.distanceFlag
Glide.with(this)
.load(
storage.reference
.child(ExerciseRepository.EXERCISE_PICTURE)
.child(exercise.exerciseID!!)
)
.placeholder(R.drawable.cactuar)
.into(image)

thumbnail.observe(this, Observer {
val thumbnail = it ?: return@Observer

Glide.with(this).load(thumbnail).into(image)
if (loadDefault) {
Glide.with(this)
.load(exerciseViewModel.getExerciseImage(exercise.exerciseID!!))
.into(image)
loadDefault = false
} else {
Glide.with(this)
.load(thumbnail)
.into(image)
}
})

tags.setOnFocusChangeListener { _, hasFocus ->
Expand All @@ -224,9 +236,15 @@ class CustomExercisesActivity : AppCompatActivity() {
* TODO: If a field is empty, replace it with placeholder text
*/
save.setOnClickListener {
val newName = name.text.toString()
val newDesc = desc.text.toString()
val newTags = ArrayList(tags.text.toString().split(",", ", "))
var newName = exercise.name
if (name.text.isNotEmpty())
newName = name.text.toString()
var newDesc = ""
if (desc.text.isNotEmpty())
newDesc = desc.text.toString()
var newTags = ArrayList<String>()
if (tags.text.isNotEmpty())
newTags = ArrayList(tags.text.toString().split(",", ", "))
val newExercise = Exercise(
name = newName,
description = newDesc,
Expand All @@ -239,10 +257,11 @@ class CustomExercisesActivity : AppCompatActivity() {
exerciseID = exercise.exerciseID
)

dialog.dismiss()
exerciseViewModel.updateExercise(newExercise)
exerciseViewModel.changeExerciseImage(exercise.exerciseID, thumbnail.value!!)
exerciseViewModel.changeExerciseImage(exercise.exerciseID!!, thumbnail.value!!)
exerciseViewModel.getExercisesByUser()
thumbnail.value = Uri.parse(ExerciseActivity.PLACEHOLDER_THUMBNAIL)
dialog.dismiss()
}

cancel.setOnClickListener {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/symphony/mrfit/ui/GoalsActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Team Symphony on 4/1/23, 7:44 PM
* Created by Team Symphony on 4/2/23, 9:44 PM
* Copyright (c) 2023 . All rights reserved.
* Last modified 4/1/23, 7:41 PM
* Last modified 4/2/23, 9:32 PM
*/

package com.symphony.mrfit.ui
Expand Down Expand Up @@ -70,6 +70,7 @@ class GoalsActivity : AppCompatActivity() {
val dialog = Dialog(this)
dialog.setContentView(R.layout.popup_edit_goal)
dialog.setTitle("New Goal")
Toast.makeText(this, "Opening goal ${goal.goalID}", Toast.LENGTH_SHORT).show()

val name = dialog.findViewById<EditText>(R.id.editGoalName)
val prog = dialog.findViewById<EditText>(R.id.progressGoalEditText)
Expand All @@ -90,7 +91,7 @@ class GoalsActivity : AppCompatActivity() {
var newProg = goal.progress
if (prog.text.isNotEmpty())
newProg = prog.text.toString().toDouble()
var newEnd = ZERO.toDouble()
var newEnd = goal.endGoal
if (end.text.isNotEmpty())
newEnd = end.text.toString().toDouble()
profileViewModel.updateGoal(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Team Symphony on 4/1/23, 7:44 PM
* Created by Team Symphony on 4/2/23, 9:44 PM
* Copyright (c) 2023 . All rights reserved.
* Last modified 4/1/23, 7:41 PM
* Last modified 4/2/23, 9:42 PM
*/

package com.symphony.mrfit.ui
Expand Down Expand Up @@ -46,6 +46,7 @@ class NotificationLogActivity : AppCompatActivity() {
super.onStart()

val notificationList = binding.notificationList
val newNotif = binding.addNotificationButton
val spinner = binding.loadingSpinner

fun deleteNotification(date: String) {
Expand Down Expand Up @@ -87,6 +88,11 @@ class NotificationLogActivity : AppCompatActivity() {
NotificationAdapter(this, notifications, ::deleteNotification, ::cancelNotification)
spinner.visibility = View.GONE
})

newNotif.setOnClickListener {
val intent = Intent(this, CalendarActivity::class.java)
startActivity(intent)
}
}

override fun onSupportNavigateUp(): Boolean {
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/res/layout/activity_notification_log.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Created by Team Symphony on 4/1/23, 4:23 AM
~ Created by Team Symphony on 4/2/23, 9:44 PM
~ Copyright (c) 2023 . All rights reserved.
~ Last modified 4/1/23, 4:20 AM
~ Last modified 4/2/23, 9:42 PM
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
Expand Down Expand Up @@ -38,6 +38,20 @@

</LinearLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/addNotificationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:clickable="true"
android:contentDescription="@string/button_notifications"
android:rotation="45"
android:src="@android:drawable/ic_menu_close_clear_cancel"
app:backgroundTint="@color/garnet"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="ContentDescription,KeyboardInaccessibleWidget" />

<ProgressBar
android:id="@+id/loadingSpinner"
style="@android:style/Widget.ProgressBar.Inverse"
Expand Down

0 comments on commit 227abf0

Please sign in to comment.