-
Notifications
You must be signed in to change notification settings - Fork 3
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 #17 from m1awicki/ml/countries_reports_follow_sett…
…ings Countries reports follow feature
- Loading branch information
Showing
16 changed files
with
232 additions
and
60 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/mobilecoronatracker/data/persistence/CountriesFollowRepo.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,7 @@ | ||
package com.mobilecoronatracker.data.persistence | ||
|
||
interface CountriesFollowRepo { | ||
fun addFollowedCountry(country: String) | ||
fun removeFollowedCountry(country: String) | ||
fun getFollowedCountries(): List<String> | ||
} |
43 changes: 43 additions & 0 deletions
43
...ava/com/mobilecoronatracker/data/persistence/impl/SharedPreferencesCountriesFollowRepo.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,43 @@ | ||
package com.mobilecoronatracker.data.persistence.impl | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import com.mobilecoronatracker.data.persistence.CountriesFollowRepo | ||
|
||
class SharedPreferencesCountriesFollowRepo(context: Context) : CountriesFollowRepo { | ||
private val sharedPrefs: SharedPreferences | ||
|
||
init { | ||
sharedPrefs = context.getSharedPreferences(SHARED_PREFS_FILE_NAME, SHARED_PREFS_MODE) | ||
} | ||
|
||
override fun addFollowedCountry(country: String) { | ||
val followed = sharedPrefs.getStringSet(FOLLOWED_COUNTRIES, emptySet()) ?: emptySet() | ||
if (followed.contains(country)) { | ||
return | ||
} | ||
val newSet = HashSet(followed) | ||
newSet.add(country) | ||
sharedPrefs.edit().putStringSet(FOLLOWED_COUNTRIES, newSet).apply() | ||
} | ||
|
||
override fun removeFollowedCountry(country: String) { | ||
val followed = sharedPrefs.getStringSet(FOLLOWED_COUNTRIES, emptySet()) ?: emptySet() | ||
if (followed.contains(country)) { | ||
val newSet = HashSet(followed) | ||
newSet.remove(country) | ||
sharedPrefs.edit().putStringSet(FOLLOWED_COUNTRIES, newSet).apply() | ||
} | ||
} | ||
|
||
override fun getFollowedCountries(): List<String> { | ||
val followed = sharedPrefs.getStringSet(FOLLOWED_COUNTRIES, emptySet()) ?: emptySet() | ||
return followed.toList() | ||
} | ||
|
||
companion object { | ||
const val FOLLOWED_COUNTRIES = "corona.tracker.prefs.followed" | ||
const val SHARED_PREFS_FILE_NAME = "corona.tracker.prefs" | ||
const val SHARED_PREFS_MODE = Context.MODE_PRIVATE | ||
} | ||
} |
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
19 changes: 10 additions & 9 deletions
19
app/src/main/java/com/mobilecoronatracker/model/CountryReportModelable.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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package com.mobilecoronatracker.model | ||
|
||
interface CountryReportModelable { | ||
var country: String | ||
var cases: Int | ||
var todayCases: Int | ||
var deaths: Int | ||
var todayDeaths: Int | ||
var recovered: Int | ||
var critical: Int | ||
var active: Int | ||
} | ||
val country: String | ||
val cases: Int | ||
val todayCases: Int | ||
val deaths: Int | ||
val todayDeaths: Int | ||
val recovered: Int | ||
val critical: Int | ||
val active: Int | ||
var followed: Boolean | ||
} |
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
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/mobilecoronatracker/ui/countriesreports/CountryFollowListener.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,6 @@ | ||
package com.mobilecoronatracker.ui.countriesreports | ||
|
||
interface CountryFollowListener { | ||
fun onCountryFollowed(countryName: String) | ||
fun onCountryUnfollowed(countryName: String) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="32dp" | ||
android:height="32dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M14.4,6L14,4H5v17h2v-7h5.6l0.4,2h7V6z"/> | ||
</vector> |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle" > | ||
<corners android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp" /> | ||
<solid android:color="@android:color/white" /> | ||
</shape> |
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.