Skip to content

Commit

Permalink
default dynamic news
Browse files Browse the repository at this point in the history
  • Loading branch information
leroynicolasalexi committed May 25, 2021
1 parent 1457b19 commit 40eb8dc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
30 changes: 30 additions & 0 deletions Corona-Warn-App/src/main/assets/dynamicNews.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"structure": {
"news": {
"explanation": [
{
"title": "title",
"text": "text"
}
]
}
},
"texts": {
"en": {
"title": "Latest News",
"text": "The Coronalert app has been updated. You can add your test anonymously."
},
"nl": {
"title": "Laatste Nieuws",
"text": "De Coronalert-app is bijgewerkt. U kunt uw test anoniem toevoegen."
},
"fr": {
"title": "Dernièrre Nouvelle",
"text": "Coronalert à été mise à jour. Vous pouvez rajouter votre test de manière anonyme."
},
"de": {
"title": "Letzte Neuigkeiten",
"text": "Die Coronalert-App wurde aktualisiert. Sie können Ihren Test anonym hinzufügen."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ object DynamicTextsService {
return dynamicTexts
}

private fun readDefaultDynamicNews(context: Context): DynamicNews {
val bufferedReader = context.assets.open("dynamicNews.json").bufferedReader()
val dynamicNews = gson.fromJson(
bufferedReader
.use { it.readText() },
DynamicNews::class.java
)

bufferedReader.close()
return dynamicNews
}

suspend fun fetchDynamicNews(context: Context): DynamicNews? {
val file = File("${context.filesDir}/dynamicNews.json")

Expand All @@ -109,7 +121,7 @@ object DynamicTextsService {
if (file.exists()) {
readDynamicNewsFile(file)
} else {
return null
readDefaultDynamicNews(context)
}
}
}
Expand Down

0 comments on commit 40eb8dc

Please sign in to comment.