Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Commit

Permalink
2020-07-18 Version 4.3.0: Closed #14 and updated libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
fartem committed Jul 18, 2020
1 parent 13b0635 commit f83714d
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 78 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName '4.2.0'
versionName '4.3.0'

testInstrumentationRunner 'com.smlnskgmail.jaman.randomnotes.runner.AndroidJacocoTestRunner'

Expand Down Expand Up @@ -70,7 +70,7 @@ allOpen {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
Expand All @@ -92,7 +92,7 @@ dependencies {
implementation 'me.jahirfiquitiva:FABsMenu:1.1.4'

// Dagger 2
implementation 'com.google.dagger:dagger:2.24'
implementation 'com.google.dagger:dagger:2.27'
kapt 'com.google.dagger:dagger-compiler:2.24'

// Unit tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ class DataRepository(
}

fun syncNotes(
errorOnSave: (e: Exception?) -> Unit
errorOnSave: (success: Boolean) -> Unit
) {
val notes = localDataSource.allNotes()
cloudDataSource.saveAllNotes(notes) {
if (it == null) {
cloudDataSource.saveAllNotes(notes) { success ->
if (success) {
notes.forEach { note ->
localDataSource.createOrUpdateNote(
note
)
}
} else {
errorOnSave(it)
errorOnSave(success)
}
}
}
Expand All @@ -39,11 +39,11 @@ class DataRepository(
}

fun restoreAllNotes(
afterRestore: (e: Exception?) -> Unit
afterRestore: (success: Boolean) -> Unit
) {
val localNotes = localDataSource.allNotes()
cloudDataSource.restoreAllNotes { notes, e ->
if (e == null) {
cloudDataSource.restoreAllNotes { notes, success ->
if (success) {
notes.forEach { note ->
val localNote = localNotes.firstOrNull {
it.remoteId == note.remoteId
Expand All @@ -56,7 +56,7 @@ class DataRepository(
)
}
}
afterRestore(e)
afterRestore(success)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ interface CloudAuth {
username: String,
email: String,
password: String,
signUpResult: (e: Exception?) -> Unit
signUpResult: (success: Boolean) -> Unit
)

fun signInWithEmail(
username: String,
password: String,
signInResult: (e: Exception?) -> Unit
signInResult: (success: Boolean)-> Unit
)

fun signInWithGoogle(
activity: Activity,
signInResult: (e: Exception?) -> Unit
signInResult: (success: Boolean) -> Unit
)

fun signInWithFacebook(
activity: Activity,
signInResult: (e: Exception?) -> Unit
signInResult: (success: Boolean) -> Unit
)

fun bindForAuth(
Expand All @@ -36,9 +36,9 @@ interface CloudAuth {
data: Intent?
)

fun deleteAccount(afterDelete: (e: Exception?) -> Unit)
fun deleteAccount(afterDelete: (success: Boolean) -> Unit)

fun logOut(afterLogOut: (e: Exception?) -> Unit)
fun logOut(afterLogOut: (success: Boolean) -> Unit)

fun isValidEmail(email: String): Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ interface CloudDataSource {

fun saveAllNotes(
notes: List<Note>,
errorOnSave: (e: Exception?) -> Unit
result: (success: Boolean) -> Unit
)

fun restoreAllNotes(
afterRestore: (notes: List<Note>, e: Exception?) -> Unit
afterRestore: (notes: List<Note>, success: Boolean) -> Unit
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface CloudInvite {

fun invite(
email: String,
inviteResult: (e: Exception?) -> Unit
inviteResult: (success: Boolean) -> Unit
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ class FakeCloudAuth : CloudAuth {
username: String,
email: String,
password: String,
signUpResult: (e: Exception?) -> Unit
signUpResult: (success: Boolean) -> Unit
) {
handleAuth()
signUpResult(null)
signUpResult(true)
}

override fun signInWithEmail(
username: String,
password: String,
signInResult: (e: Exception?) -> Unit
signInResult: (success: Boolean) -> Unit
) {
handleAuth()
signInResult(null)
signInResult(true)
}


override fun signInWithFacebook(
activity: Activity,
signInResult: (e: Exception?) -> Unit
signInResult: (success: Boolean) -> Unit
) {
handleAuth()
signInResult(null)
signInResult(true)
}

private fun handleAuth() {
Expand All @@ -56,10 +56,10 @@ class FakeCloudAuth : CloudAuth {

override fun signInWithGoogle(
activity: Activity,
signInResult: (e: Exception?) -> Unit
signInResult: (success: Boolean) -> Unit
) {
handleAuth()
signInResult(null)
signInResult(true)
}

override fun bindForAuth(
Expand All @@ -71,17 +71,17 @@ class FakeCloudAuth : CloudAuth {
}

override fun deleteAccount(
afterDelete: (e: Exception?) -> Unit
afterDelete: (success: Boolean) -> Unit
) {
isAuth = false
afterDelete(null)
afterDelete(true)
}

override fun logOut(
afterLogOut: (e: Exception?) -> Unit
afterLogOut: (success: Boolean) -> Unit
) {
isAuth = false
afterLogOut(null)
afterLogOut(true)
}

// CPD-OFF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ class FakeCloudDataSource : CloudDataSource {

override fun saveAllNotes(
notes: List<Note>,
errorOnSave: (e: Exception?) -> Unit
result: (success: Boolean) -> Unit
) {
storage.addAll(notes)
errorOnSave(null)
result(true)
}

override fun restoreAllNotes(
afterRestore: (notes: List<Note>, e: Exception?) -> Unit
afterRestore: (notes: List<Note>, success: Boolean) -> Unit
) {
afterRestore(
emptyList(),
null
true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class FakeCloudInvite : CloudInvite {

override fun invite(
email: String,
inviteResult: (e: Exception?) -> Unit
inviteResult: (success: Boolean) -> Unit
) {
inviteResult(null)
inviteResult(true)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,45 @@ class ParseServerAuth(

override fun signInWithFacebook(
activity: Activity,
signInResult: (e: Exception?) -> Unit
signInResult: (success: Boolean) -> Unit
) {
ParseFacebookUtils.initialize(
context
)
ParseFacebookUtils.logInWithReadPermissionsInBackground(
activity,
listOf("public_profile")
) { _, e -> signInResult(e) }
) { _, e -> signInResult(e == null) }
}

override fun signUpWithEmail(
username: String,
email: String,
password: String,
signUpResult: (e: Exception?) -> Unit
signUpResult: (success: Boolean) -> Unit
) {
val parseUser = ParseUser()
parseUser.username = username
parseUser.email = email
parseUser.setPassword(password)
parseUser.signUpInBackground {
signUpResult(it)
signUpResult(it == null)
}
}

override fun signInWithEmail(
username: String,
password: String,
signInResult: (e: Exception?) -> Unit
signInResult: (success: Boolean) -> Unit
) {
ParseUser.logInInBackground(username, password) { _, e ->
signInResult(e)
signInResult(e == null)
}
}

override fun signInWithGoogle(
activity: Activity,
signInResult: (e: Exception?) -> Unit
signInResult: (success: Boolean) -> Unit
) {
ParseGoogleUtils.initialize(
context.getString(
Expand All @@ -77,8 +77,8 @@ class ParseServerAuth(
)
ParseGoogleUtils.logIn(
activity,
LogInCallback { user, e ->
signInResult(e)
LogInCallback { _, e ->
signInResult(e == null)
}
)
}
Expand All @@ -101,14 +101,14 @@ class ParseServerAuth(
}

override fun deleteAccount(
afterDelete: (e: Exception?) -> Unit
afterDelete: (success: Boolean) -> Unit
) {
ParseUser.getCurrentUser()?.deleteInBackground {
afterDelete(it)
afterDelete(it == null)
}
}

override fun logOut(afterLogOut: (e: Exception?) -> Unit) {
override fun logOut(afterLogOut: (success: Boolean) -> Unit) {
val parseUser = ParseUser.getCurrentUser()
if (ParseFacebookUtils.isLinked(parseUser)) {
AccessToken.setCurrentAccessToken(null)
Expand All @@ -117,7 +117,7 @@ class ParseServerAuth(
}
}
ParseUser.logOutInBackground {
afterLogOut(it)
afterLogOut(it == null)
}
}

Expand All @@ -127,7 +127,6 @@ class ParseServerAuth(
Pattern.CASE_INSENSITIVE
)
return pattern.matcher(email).find()

}

override fun isValidPassword(password: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ParseServerDataSource(

override fun saveAllNotes(
notes: List<Note>,
errorOnSave: (e: Exception?) -> Unit
result: (success: Boolean) -> Unit
) {
val objectsToSave = mutableListOf<ParseObject>()
for (note in notes) {
Expand All @@ -61,7 +61,7 @@ class ParseServerDataSource(
}
}
}
errorOnSave(it)
result(it == null)
}
}

Expand All @@ -74,9 +74,11 @@ class ParseServerDataSource(
}

override fun restoreAllNotes(
afterRestore: (notes: List<Note>, e: Exception?) -> Unit
afterRestore: (notes: List<Note>, success: Boolean) -> Unit
) {
val parseQuery: ParseQuery<ParseObject> = ParseQuery.getQuery(tableNote)
val parseQuery: ParseQuery<ParseObject> = ParseQuery.getQuery(
tableNote
)
parseQuery.findInBackground { objects, e ->
if (objects.isNotEmpty()) {
val notes = mutableListOf<Note>()
Expand All @@ -87,9 +89,9 @@ class ParseServerDataSource(
)
)
}
afterRestore(notes, null)
afterRestore(notes, true)
} else if (e != null) {
afterRestore(emptyList(), e)
afterRestore(emptyList(), false)
}
}
}
Expand Down
Loading

0 comments on commit f83714d

Please sign in to comment.