-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from horaciocome1/bug-fixes-and-improvements-p…
…art-VI Bug fixes and improvements part vi
- Loading branch information
Showing
36 changed files
with
626 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...rc/main/java/io/github/horaciocome1/reaque/data/configurations/ConfigurationsInterface.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.github.horaciocome1.reaque.data.configurations | ||
|
||
import androidx.lifecycle.LiveData | ||
|
||
interface ConfigurationsInterface { | ||
|
||
fun isUpdateAvailable(): LiveData<Boolean> | ||
|
||
fun getLatestVersionName(): LiveData<String> | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...c/main/java/io/github/horaciocome1/reaque/data/configurations/ConfigurationsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.github.horaciocome1.reaque.data.configurations | ||
|
||
class ConfigurationsRepository private constructor( | ||
private val service: ConfigurationsService | ||
) : ConfigurationsInterface { | ||
|
||
override fun isUpdateAvailable() = service.isUpdateAvailable() | ||
|
||
override fun getLatestVersionName() = service.getLatestVersionName() | ||
|
||
companion object { | ||
|
||
@Volatile | ||
private var instance: ConfigurationsRepository? = null | ||
|
||
fun getInstance(service: ConfigurationsService) = instance ?: synchronized(this) { | ||
instance ?: ConfigurationsRepository(service) | ||
.also { | ||
instance = it | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/io/github/horaciocome1/reaque/data/configurations/ConfigurationsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.github.horaciocome1.reaque.data.configurations | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.google.firebase.firestore.FirebaseFirestore | ||
import io.github.horaciocome1.reaque.BuildConfig | ||
import io.github.horaciocome1.reaque.util.addSafeSnapshotListener | ||
|
||
class ConfigurationsService : ConfigurationsInterface { | ||
|
||
private val versionCode: Int by lazy { | ||
BuildConfig.VERSION_CODE | ||
} | ||
|
||
private val db: FirebaseFirestore by lazy { | ||
FirebaseFirestore.getInstance() | ||
} | ||
|
||
private val isUpdateAvailable: MutableLiveData<Boolean> by lazy { | ||
MutableLiveData<Boolean>() | ||
.apply { | ||
value = false | ||
} | ||
} | ||
|
||
private val latestVersionName: MutableLiveData<String> by lazy { | ||
MutableLiveData<String>() | ||
.apply { | ||
value = "" | ||
} | ||
} | ||
|
||
override fun isUpdateAvailable(): LiveData<Boolean> { | ||
isUpdateAvailable.value = false | ||
db.document("configurations/default") | ||
.addSafeSnapshotListener { snapshot -> | ||
snapshot["version_code"]?.let { | ||
isUpdateAvailable.value = versionCode < it.toString().toInt() | ||
} | ||
} | ||
return isUpdateAvailable | ||
} | ||
|
||
override fun getLatestVersionName(): LiveData<String> { | ||
db.document("configurations/default") | ||
.addSafeSnapshotListener { snapshot -> | ||
snapshot["version_name"]?.let { | ||
latestVersionName.value = it.toString() | ||
} | ||
} | ||
return latestVersionName | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.