Skip to content

Commit

Permalink
2.1.0 (23) (#24)
Browse files Browse the repository at this point in the history
* changed home background

* add datastore to save if user signed in

* add ExpandableSearchBar.kt to TravellersActivity.kt

* fix fab on travellers activity

* Fix uploading photo to firestore and set sdk_version = 32

* update CI/CD

* update CI/CD

* update gradle and README.md

* update gradle and dependencies

* remove deprecated on back pressed and replaced with a new approach

* remove deprecated on back pressed and replaced with a new approach

* replaced deprecated getParcelable and getPackageInfo methods

* upgraded koin and okhttp version

* upgraded firebase_bom_version

* Fix updating the the number of visited countries

* upgrade koin version

* add org.gradle.unsafe.configuration-cache-problems=warn

* increment version to 2.0.8(21)

* increment java version to 17 in ci/cd

* Update dependencies

* Add onion architecture pattern to README.md

* Add link on the original documentation of the onion architecture in the README.md

* Add link to app center build

* Move di component to presentation component and allow admin to see all users

* increment version to 2.1.0 (23)
  • Loading branch information
Turskyi authored Jul 9, 2023
1 parent 72c9e63 commit 33feb50
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 275 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ countries visited other members of the app.
• CI/CD: [GitHub Actions](https://docs.github.com/en/actions) is used to deliver new Android
Package (APK) to [Firebase App Distribution](https://firebase.google.com/docs/app-distribution)
after every push to the **dev** branch,
[Visual Studio App Center](https://docs.microsoft.com/en-us/appcenter/) is used to deliver new
[Visual Studio App Center](https://docs.microsoft.com/en-us/appcenter/) is used to
[deliver](https://appcenter.ms/users/Turskyi/apps/Travelling-Pro/build/branches/master) new
release app bundle to **Google Play** after every push to **master** branch;

• App testing platforms:
Expand Down Expand Up @@ -71,8 +72,8 @@ release app bundle to **Google Play** after every push to **master** branch;

• Architectural pattern:
<br>
<a href="https://jeffreypalermo.com/2008/07/the-onion-architecture-part-1/">
<img src="documentation/onion_architecture_with_di.jpeg" width="800" >
<a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel">
<img src="documentation/android_model_view_viewmodel.jpeg" width="800" >
</a>
</br>

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ buildscript {
min_sdk_version = 21
target_sdk_version = 33
// last version is here [https://play.google.com/console/u/0/developers/6867856033872987263/app/4972072127034375090/releases/overview]
version_code = 22
version_name = "2.0.9"
version_code = 23
version_name = "2.1.0"
}
repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import android.net.Uri
import com.google.android.gms.tasks.Task
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser
import com.google.firebase.firestore.*
import com.google.firebase.firestore.CollectionReference
import com.google.firebase.firestore.DocumentReference
import com.google.firebase.firestore.DocumentSnapshot
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.Query
import com.google.firebase.firestore.QueryDocumentSnapshot
import com.google.firebase.firestore.QuerySnapshot
import com.google.firebase.firestore.WriteBatch
import com.google.firebase.storage.FirebaseStorage
import com.google.firebase.storage.StorageMetadata
import com.google.firebase.storage.StorageReference
Expand Down Expand Up @@ -51,6 +58,7 @@ class FirestoreDatabaseSourceImpl(
private const val KEY_PARENT_ID = "parentId"
private const val KEY_COUNTER = "counter"
private const val KEY_FLAG = "flag"
private const val KEY_IS_ADMIN = "isAdmin"
}

// init Authentication
Expand Down Expand Up @@ -103,7 +111,9 @@ class FirestoreDatabaseSourceImpl(
val userRef: DocumentReference = usersRef.document(currentUser.uid)
userRef.update(KEY_IS_VISIBLE, visible)
.addOnSuccessListener { onSuccess.invoke() }
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
Expand All @@ -125,7 +135,9 @@ class FirestoreDatabaseSourceImpl(
onError.invoke(NotFoundException())
}
}
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
Expand All @@ -147,7 +159,9 @@ class FirestoreDatabaseSourceImpl(
onSuccess(notVisitedCountries.size())
}
} else {
task.exception?.let { exception: java.lang.Exception -> onError.invoke(exception) }
task.exception?.let { exception: java.lang.Exception ->
onError.invoke(exception)
}
}
}
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
Expand Down Expand Up @@ -175,7 +189,9 @@ class FirestoreDatabaseSourceImpl(
}
}
}
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
Expand Down Expand Up @@ -203,7 +219,9 @@ class FirestoreDatabaseSourceImpl(
}
}
}
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
Expand Down Expand Up @@ -252,7 +270,8 @@ class FirestoreDatabaseSourceImpl(
)
if (currentUser != null) {
usersRef.document(currentUser.uid)
.collection(COLLECTION_COUNTRIES).document(countryEntity.shortName).set(country)
.collection(COLLECTION_COUNTRIES).document(countryEntity.shortName)
.set(country)
.addOnSuccessListener {
if (index == countries.lastIndex) {
onSuccess.invoke()
Expand Down Expand Up @@ -308,7 +327,9 @@ class FirestoreDatabaseSourceImpl(
.addOnSuccessListener {
addToListOfVisited(userDocRef, countryEntity, onSuccess, onError)
}
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
Expand Down Expand Up @@ -562,7 +583,8 @@ class FirestoreDatabaseSourceImpl(
) {
if (currentUser != null) {
val userDocRef: DocumentReference = usersRef.document(currentUser.uid)
userDocRef.collection(COLLECTION_VISITED_COUNTRIES).whereEqualTo(KEY_ID, city.parentId)
userDocRef.collection(COLLECTION_VISITED_COUNTRIES)
.whereEqualTo(KEY_ID, city.parentId)
.get()
.addOnSuccessListener { documents: QuerySnapshot ->
for (document: QueryDocumentSnapshot in documents) {
Expand Down Expand Up @@ -603,7 +625,9 @@ class FirestoreDatabaseSourceImpl(
.collection(COLLECTION_CITIES).document(id)
.delete()
.addOnSuccessListener { onSuccess() }
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
Expand Down Expand Up @@ -634,7 +658,9 @@ class FirestoreDatabaseSourceImpl(
}
}
}
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
onError.invoke(NotFoundException())
}
Expand All @@ -660,7 +686,11 @@ class FirestoreDatabaseSourceImpl(
)
countries.add(country)
if (documentSnapshot.id == queryDocumentSnapshots.last().id) {
onSuccess(countries.sortedBy { listItem: VisitedCountryEntity -> listItem.name })
onSuccess(
countries.sortedBy { listItem: VisitedCountryEntity ->
listItem.name
},
)
}
}
}
Expand Down Expand Up @@ -752,7 +782,9 @@ class FirestoreDatabaseSourceImpl(
onSuccess(cities.sortedBy { city: CityEntity -> city.name })
}
}
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
Expand Down Expand Up @@ -793,7 +825,9 @@ class FirestoreDatabaseSourceImpl(
}
}
}
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
Expand Down Expand Up @@ -823,7 +857,9 @@ class FirestoreDatabaseSourceImpl(
}
onSuccess(countries)
}
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
Expand Down Expand Up @@ -853,7 +889,9 @@ class FirestoreDatabaseSourceImpl(
}
}
}
.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
Expand All @@ -866,30 +904,63 @@ class FirestoreDatabaseSourceImpl(
onSuccess: (List<TravellerEntity>) -> Unit,
onError: (Exception) -> Unit
) {
val usersRef: CollectionReference = usersRef
usersRef
// getting only users who allowed to be visible
.whereEqualTo(KEY_IS_VISIBLE, true)
// getting part of the list for pagination
.limit(to)
.get()
.addOnSuccessListener { queryDocumentSnapshots: QuerySnapshot ->
val travellers: MutableList<TravellerEntity> = mutableListOf()
for (i in from until queryDocumentSnapshots.size()) {
val snapshot: DocumentSnapshot = queryDocumentSnapshots.documents[i]
travellers.add(
TravellerEntity(
id = snapshot.id,
name = snapshot[KEY_NAME] as String,
avatar = snapshot[KEY_AVATAR] as String,
counter = snapshot[KEY_COUNTER] as Long,
isVisible = snapshot[KEY_IS_VISIBLE] as Boolean,
)
)
if (currentUser != null) {
val userRef: DocumentReference = usersRef.document(currentUser.uid)
userRef.get()
.addOnSuccessListener { document: DocumentSnapshot ->
val isAdmin = document.getBoolean(KEY_IS_ADMIN) ?: false

val visibleQuery: Query = usersRef
// getting only users who allowed to be visible
.whereEqualTo(KEY_IS_VISIBLE, true)

val taskWithAllTravellers: Task<QuerySnapshot> = usersRef
// getting part of the list for pagination
.limit(to)
.get()

val taskWithVisibleTravellers: Task<QuerySnapshot> = visibleQuery
// getting part of the list for pagination
.limit(to)
.get()

val taskWithTravellers = if (isAdmin) {
taskWithAllTravellers
} else {
taskWithVisibleTravellers
}
taskWithTravellers
.addOnSuccessListener { queryDocumentSnapshots: QuerySnapshot ->
val travellers: MutableList<TravellerEntity> = mutableListOf()
for (i in from until queryDocumentSnapshots.size()) {
val snapshot: DocumentSnapshot =
queryDocumentSnapshots.documents[i]
travellers.add(
TravellerEntity(
id = snapshot.id,
name = snapshot[KEY_NAME] as String,
avatar = snapshot[KEY_AVATAR] as String,
counter = snapshot[KEY_COUNTER] as Long,
isVisible = snapshot[KEY_IS_VISIBLE] as Boolean,
)
)
}

travellers.sortByDescending { traveller: TravellerEntity ->
traveller.counter
}
onSuccess(travellers)
}.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
}
.addOnFailureListener { exception: java.lang.Exception ->
onError.invoke(exception)
}
travellers.sortByDescending { traveller: TravellerEntity -> traveller.counter }
onSuccess(travellers)
}.addOnFailureListener { exception: java.lang.Exception -> onError.invoke(exception) }
} else {
mFirebaseAuth.signOut()
onError.invoke(NotFoundException())
}
}

override suspend fun setTravellersByName(
Expand Down
1 change: 0 additions & 1 deletion di/.gitignore

This file was deleted.

59 changes: 0 additions & 59 deletions di/build.gradle

This file was deleted.

Empty file removed di/consumer-rules.pro
Empty file.
21 changes: 0 additions & 21 deletions di/proguard-rules.pro

This file was deleted.

Loading

0 comments on commit 33feb50

Please sign in to comment.