Skip to content

Commit 17553f1

Browse files
CODIEX0VUYISWA-NKOSI
authored andcommitted
Modified Settings. Added Personal Settings Fragment - User can change username and email address.
2 parents 8fe8283 + 9f83bf1 commit 17553f1

36 files changed

Lines changed: 657 additions & 338 deletions

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ dependencies {
6565
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
6666
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.1'
6767

68+
6869
// google maps dependencies
6970
implementation 'com.google.maps.android:android-maps-utils:2.2.2'
7071
implementation 'com.google.android.gms:play-services-maps:18.1.0'
@@ -74,4 +75,5 @@ dependencies {
7475
// image picker dependencies
7576
implementation 'com.github.dhaval2404:imagepicker:2.1'
7677

78+
7779
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
android:name=".MainActivity"
2323
android:exported="false"/>
2424
<activity
25-
android:name=".LoginActivity"
25+
android:name=".RegisterActivity"
2626
android:exported="false" />
2727
<!--set the register activity as the start up screen-->
2828
<activity
29-
android:name=".RegisterActivity"
29+
android:name=".LoginActivity"
3030
android:exported="true">
3131
<intent-filter>
3232
<action android:name="android.intent.action.MAIN" />

app/src/main/java/com/example/avianwatch/LoginActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class LoginActivity : AppCompatActivity() {
6565
val email = binding.edtEmail.text.toString()
6666
val password = binding.etPassWord.text.toString()
6767
validateLogin(email, password)
68-
//val intent = Intent(this, MainActivity::class.java)
69-
//startActivity(intent)
7068
}
7169

7270
val imgIcon: ImageView = findViewById(R.id.imgIcon)

app/src/main/java/com/example/avianwatch/MainActivity.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
package com.example.avianwatch
22

3-
43
import androidx.appcompat.app.AppCompatActivity
54
import android.os.Bundle
6-
import android.widget.TextView
75
import androidx.fragment.app.Fragment
86
import androidx.navigation.fragment.NavHostFragment
97
import androidx.navigation.ui.setupWithNavController
8+
import com.example.avianwatch.databinding.ActivityMainBinding
109
import com.example.avianwatch.fragments.BirdFactsFragment
1110
import com.example.avianwatch.fragments.PostsFragment
1211
import com.example.avianwatch.fragments.GoBirdingFragment
1312
import com.example.avianwatch.fragments.HomeFragment
1413
import com.example.avianwatch.fragments.ObservationListFragment
15-
import com.google.android.material.bottomnavigation.BottomNavigationView
1614

1715
class MainActivity : AppCompatActivity(), OnCardClickListener{
18-
private lateinit var bottomNav: BottomNavigationView
19-
lateinit var txtTitle: TextView
16+
private lateinit var binding: ActivityMainBinding
2017

2118
override fun onCreate(savedInstanceState: Bundle?) {
2219
super.onCreate(savedInstanceState)
23-
setContentView(R.layout.activity_main)
20+
binding = ActivityMainBinding.inflate(layoutInflater)
21+
setContentView(binding.root)
2422

25-
txtTitle = findViewById(R.id.txtTitle)
23+
binding.txtTitle.setText("Dashboard")
2624

2725
//setup the bottom navigation bar
2826
val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment
2927
val navController = navHostFragment.navController
30-
bottomNav = findViewById(R.id.bottom_navigation)
31-
bottomNav.setupWithNavController(navController)
28+
29+
binding.bottomNavigation.setupWithNavController(navController)
3230

3331
// as soon as the application opens the first fragment should
3432
// be shown to the user in this case it is the Home Fragment
3533
val fragment = HomeFragment()
3634
replaceFragment(fragment)
3735

3836
//change the fragment every time the user presses a different bottom navigation button
39-
bottomNav.setOnNavigationItemSelectedListener { menuItem ->
37+
binding.bottomNavigation.setOnNavigationItemSelectedListener { menuItem ->
4038
// By using switch we can easily get the
4139
// selected fragment by using the id
4240
lateinit var selectedFragment: Fragment
@@ -78,7 +76,7 @@ class MainActivity : AppCompatActivity(), OnCardClickListener{
7876
}
7977

8078
fun updateTitle(newText: String) {
81-
txtTitle.text = newText
79+
binding.txtTitle.setText(newText)
8280
}
8381

8482
//method used to replace the current fragment with the fragment passed in the parameters

app/src/main/java/com/example/avianwatch/adapters/ObservationAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ObservationAdapter(private val observations: List<BirdObservation>) : Recy
2323
name.text = observation.birdSpecies
2424
date.text = observation.dateTime.toString()
2525
//location.text = observation.hotspot.toString()
26-
location.text = observation.hotspot.locName
26+
location.text = observation.location
2727
notes.text = observation.additionalNotes
2828

2929
// Check if the image is null or empty, and hide the image view if it is

app/src/main/java/com/example/avianwatch/adapters/PostAdapter.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class PostAdapter(private val posts: List<Post>) : RecyclerView.Adapter<PostAdap
6767
likes.text = updatedLikesCount.toString()
6868

6969
// Update the likes count in the database
70-
updatePostLikes(post.pId, userHasLiked, updatedLikesCount) { success ->
70+
updatePostLikes(post.pId, post.userHasLiked, updatedLikesCount) { success ->
7171
if (success) {
7272
// Likes updated successfully
7373
println("Likes and status updated successfully")
@@ -78,8 +78,6 @@ class PostAdapter(private val posts: List<Post>) : RecyclerView.Adapter<PostAdap
7878
}
7979
}
8080
}
81-
82-
8381
}
8482

8583
init {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.example.avianwatch.data
2+
3+
import android.util.Patterns
4+
import android.widget.Toast
5+
import com.google.firebase.auth.FirebaseAuth
6+
import com.google.firebase.auth.SignInMethodQueryResult
7+
8+
object AuthUtils {
9+
10+
fun checkEmailAvailability(email: String, onComplete: (Boolean, String?) -> Unit) {
11+
if (email.isNotEmpty() && Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
12+
val auth = FirebaseAuth.getInstance()
13+
auth.fetchSignInMethodsForEmail(email)
14+
.addOnCompleteListener { task ->
15+
if (task.isSuccessful) {
16+
val result: SignInMethodQueryResult? = task.result
17+
if (result?.signInMethods?.isEmpty() == true) {
18+
// Email is not registered, availability check is successful
19+
onComplete(true, null)
20+
} else {
21+
// Email is already in use
22+
onComplete(false, "Email Taken!")
23+
}
24+
} else {
25+
// Failed to check email availability
26+
onComplete(false, "Error checking email availability")
27+
}
28+
}
29+
} else {
30+
// Invalid email address
31+
onComplete(false, "Invalid Email Address")
32+
}
33+
}
34+
}

app/src/main/java/com/example/avianwatch/data/BirdObservation.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ data class BirdObservation(
1010
val additionalNotes: String,
1111
val birdImage: String?,
1212
val dateTime: String?,
13-
val hotspot: Hotspot
13+
val location: String
1414
){
15-
constructor() : this("", "", "", "", null, null, Hotspot())
15+
constructor() : this("", "", "", "", null, null, "")
1616
}

app/src/main/java/com/example/avianwatch/data/UserPreferences.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.example.avianwatch.data
22

3+
import com.google.maps.model.TravelMode
4+
35
data class UserPreferences(
46
var userUID: String? = null,
57
var unitSystem: String = "Metric",

0 commit comments

Comments
 (0)