-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
294 additions
and
5 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
10 changes: 10 additions & 0 deletions
10
app/src/main/java/es/gob/radarcovid/datamanager/repository/ExposureRecordRepository.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,10 @@ | ||
package es.gob.radarcovid.datamanager.repository | ||
|
||
import es.gob.radarcovid.models.domain.ExposureInfo | ||
|
||
interface ExposureRecordRepository { | ||
|
||
fun getExposureRecords() : List<ExposureInfo> | ||
fun addExposure(exposureInfo: ExposureInfo) | ||
fun removeExposures() | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/es/gob/radarcovid/datamanager/repository/ExposureRecordRepositoryImpl.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 es.gob.radarcovid.datamanager.repository | ||
|
||
import es.gob.radarcovid.models.domain.ExposureInfo | ||
import android.content.SharedPreferences | ||
import com.google.gson.Gson | ||
import com.google.gson.reflect.TypeToken | ||
import es.gob.radarcovid.common.extensions.toJson | ||
import javax.inject.Inject | ||
|
||
class ExposureRecordRepositoryImpl @Inject constructor( | ||
private val sharedPreferences: SharedPreferences? | ||
): ExposureRecordRepository { | ||
|
||
companion object { | ||
private const val KEY_EXPOSURE_RECORD_LIST = "key_exposure_record_list" | ||
} | ||
|
||
private fun saveToPrefs(key: String, data: String) { | ||
sharedPreferences?.edit()?.putString(key, data)?.apply() | ||
} | ||
|
||
private fun getFromPreferences(key: String): String? = | ||
sharedPreferences?.getString(key, null) | ||
|
||
private fun removeFromPrefs(key: String) { | ||
sharedPreferences?.edit()?.remove(key)?.apply() | ||
} | ||
|
||
|
||
override fun getExposureRecords(): List<ExposureInfo> { | ||
val list = getFromPreferences(KEY_EXPOSURE_RECORD_LIST) | ||
return if (list != null) { | ||
val itemType = object : TypeToken<List<ExposureInfo>>() {}.type | ||
Gson().fromJson( | ||
list, | ||
itemType | ||
) | ||
} else { | ||
emptyList() | ||
} | ||
} | ||
|
||
override fun addExposure(exposureInfo: ExposureInfo) { | ||
var list = getExposureRecords() | ||
list += exposureInfo | ||
saveToPrefs(KEY_EXPOSURE_RECORD_LIST, list.toJson()) | ||
} | ||
|
||
override fun removeExposures() { | ||
removeFromPrefs(KEY_EXPOSURE_RECORD_LIST) | ||
} | ||
|
||
|
||
} |
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
81 changes: 81 additions & 0 deletions
81
app/src/main/java/es/gob/radarcovid/features/information/view/ExposureRecordDialog.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,81 @@ | ||
package es.gob.radarcovid.features.information.view | ||
|
||
import android.app.AlertDialog | ||
import android.app.Dialog | ||
import android.content.Context | ||
import android.graphics.Color | ||
import android.graphics.drawable.ColorDrawable | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import dagger.android.HasAndroidInjector | ||
import es.gob.radarcovid.R | ||
import es.gob.radarcovid.common.extensions.toDateFormat | ||
import es.gob.radarcovid.datamanager.repository.ExposureRecordRepository | ||
import es.gob.radarcovid.datamanager.utils.LabelManager | ||
import es.gob.radarcovid.models.domain.ExposureInfo | ||
import kotlinx.android.extensions.LayoutContainer | ||
import kotlinx.android.synthetic.main.dialog_exposure_record.* | ||
import java.util.* | ||
import javax.inject.Inject | ||
|
||
class ExposureRecordDialog(context: Context) : LayoutContainer { | ||
|
||
private val dialog: Dialog | ||
|
||
override val containerView: View = | ||
LayoutInflater.from(context).inflate(R.layout.dialog_exposure_record, null) | ||
|
||
@Inject | ||
lateinit var labelManager: LabelManager | ||
|
||
@Inject | ||
lateinit var exposureRecordRepository: ExposureRecordRepository | ||
|
||
init { | ||
|
||
initializeInjector(context) | ||
|
||
dialog = AlertDialog.Builder(context) | ||
.setView(containerView) | ||
.create() | ||
.apply { | ||
window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) | ||
} | ||
|
||
buttonClose.setOnClickListener { dialog.dismiss() } | ||
buttonCancel.setOnClickListener { dialog.dismiss() } | ||
|
||
} | ||
|
||
private fun loadRecords() { | ||
val records = exposureRecordRepository.getExposureRecords() | ||
var text = "" | ||
if (records.isEmpty()) { | ||
text = labelManager.getText( | ||
"EXPOSURE_RECORDS_NO_DATA", | ||
R.string.exposure_records_no_data | ||
).toString() | ||
} else { | ||
records.forEach { | ||
text += "\u25CF " + it.lastExposureDate.toDateFormat() + "\n" | ||
} | ||
} | ||
|
||
recordContent.text = text | ||
} | ||
|
||
private fun initializeInjector(context: Context) { | ||
(context.applicationContext as? HasAndroidInjector)?.androidInjector()?.inject(this) | ||
} | ||
|
||
fun show() { | ||
dialog.show() | ||
dialog.window?.setLayout( | ||
ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.MATCH_PARENT | ||
) | ||
loadRecords() | ||
} | ||
|
||
} |
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.