Skip to content

Commit

Permalink
- Bug fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mehatab committed May 1, 2020
1 parent d6e838e commit a871f5d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# COVID-19 Tracker Android Application
This application displays the latest updates based on numbers from https://www.covid19india.org/

## <a href="https://github.com/Mehatab/covid-19/releases/download/v1.5.5/app-release.apk">Download</a> APK & install
## <a href="https://github.com/Mehatab/covid-19/releases/download/v1.5.6/app-release.apk">Download</a> APK & install

## Required Permissions
android.permission.INTERNET
Expand Down
4 changes: 2 additions & 2 deletions app/release/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"apkData": {
"type": "MAIN",
"splits": [],
"versionCode": 14,
"versionName": "1.5.4",
"versionCode": 16,
"versionName": "1.5.6",
"enabled": true,
"outputFile": "app-release.apk",
"fullName": "release",
Expand Down
24 changes: 17 additions & 7 deletions app/src/main/java/info/covid/state/StateDetailsRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ package info.covid.state

import info.covid.customview.DataPoint
import info.covid.models.DistrictState
import info.covid.models.StateDailyResponse
import info.covid.network.RetrofitClient
import retrofit2.Response

class StateDetailsRepository {
object StateDetailsRepository {

private val apiService = RetrofitClient.get().create(StateAPIService::class.java)
private lateinit var districtListResp: Response<List<DistrictState>>

suspend fun <T> getDistrictInfo(
stateName: String,
success: (DistrictState?) -> T,
error: (String) -> T
) {
try {
val resp = apiService.getStateDistrictWise()
if (resp.isSuccessful) {
val states = resp.body() ?: emptyList()

if (::districtListResp.isInitialized.not() || districtListResp.isSuccessful.not())
districtListResp = apiService.getStateDistrictWise()

if (districtListResp.isSuccessful) {
val states = districtListResp.body() ?: emptyList()
val state = states.find { it.state == stateName }
success(state)
} else error("Oops, Something went wrong")
Expand All @@ -25,15 +31,19 @@ class StateDetailsRepository {
}
}

private lateinit var StateDaily: Response<StateDailyResponse>

suspend fun <T> getStateDaily(
state: String,
success: (HashMap<String, ArrayList<DataPoint>>, max: Float) -> T,
error: (String) -> T
) {
try {
val resp = apiService.getStateDaily()
if (resp.isSuccessful) {
val states = resp.body()?.dailyStats ?: emptyList()
if (::districtListResp.isInitialized.not() || districtListResp.isSuccessful.not())
StateDaily = apiService.getStateDaily()

if (StateDaily.isSuccessful) {
val states = StateDaily.body()?.dailyStats ?: emptyList()
val mapData = HashMap<String, ArrayList<DataPoint>>()
var max = 0f

Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/info/covid/state/StateDetailsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class StateDetailsViewModel(application: Application) : AndroidViewModel(application) {
private val stateWiseRepository = StateDetailsRepository()
val districts = MutableLiveData<List<District>>()
val stateName = MutableLiveData<String>()
val recoversMapData = MutableLiveData<List<DataPoint>>()
Expand All @@ -36,7 +35,7 @@ class StateDetailsViewModel(application: Application) : AndroidViewModel(applica
private fun getDistrictsData(state: String) {
progress.set(View.VISIBLE)
viewModelScope.launch(Dispatchers.IO) {
stateWiseRepository.getDistrictInfo(state, {
StateDetailsRepository.getDistrictInfo(state, {
districts.postValue((it?.districts?.sortedByDescending { it.confirmed }
?: emptyList()))
progress.set(View.GONE)
Expand All @@ -50,7 +49,7 @@ class StateDetailsViewModel(application: Application) : AndroidViewModel(applica

private fun getDailyData(stateName: String) {
viewModelScope.launch(Dispatchers.IO) {
stateWiseRepository.getStateDaily(stateName, { it, max ->
StateDetailsRepository.getStateDaily(stateName, { it, max ->
maxNumber = max
recoversMapData.postValue(it["Recovered"])
confirmedMapData.postValue(it["Confirmed"])
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/xml/preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
</PreferenceScreen>

<PreferenceScreen app:enabled="false"/>
<PreferenceScreen app:enabled="false"/>

</PreferenceCategory>

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ object Config {
const val applicationId = "info.covid"
const val minSdk = 19
const val targetSdk = 29
const val versionCode = 15
const val versionName = "1.5.5"
const val versionCode = 16
const val versionName = "1.5.6"
}

object Versions {
Expand Down

0 comments on commit a871f5d

Please sign in to comment.