-
Notifications
You must be signed in to change notification settings - Fork 46
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
8 changed files
with
289 additions
and
172 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
44 changes: 44 additions & 0 deletions
44
app/src/main/java/org/openobservatory/ooniprobe/activity/overview/OverviewViewModel.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,44 @@ | ||
package org.openobservatory.ooniprobe.activity.overview | ||
|
||
import android.text.format.DateUtils | ||
import android.view.View | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import org.openobservatory.ooniprobe.model.database.Result | ||
import org.openobservatory.ooniprobe.test.suite.AbstractSuite | ||
import org.openobservatory.ooniprobe.test.suite.OONIRunSuite | ||
import org.openobservatory.ooniprobe.test.suite.WebsitesSuite | ||
|
||
class OverviewViewModel : ViewModel() { | ||
var suite: MutableLiveData<AbstractSuite?> = MutableLiveData<AbstractSuite?>() | ||
var name = MutableLiveData<String>() | ||
var title = MutableLiveData<String>() | ||
var icon = MutableLiveData<Int>() | ||
var dataUsage = MutableLiveData<String>() | ||
var lastTime = MutableLiveData<String>() | ||
var author = MutableLiveData<String?>() | ||
var description = MutableLiveData<String>() | ||
fun onTestSuiteChanged(suite: AbstractSuite) { | ||
this.suite.value = suite | ||
name.value = suite.name | ||
title.value = suite.title | ||
icon.value = suite.icon | ||
dataUsage.value = suite.dataUsage.toString() | ||
// TODO: (aanorbel) Use runID for fetching value, all ooni-run tests register as one with same name. | ||
lastTime.value = Result.getLastResult(suite.name)?.start_time?.time?.let { | ||
DateUtils.getRelativeTimeSpanString( | ||
it | ||
)?.toString() | ||
} | ||
|
||
description.value = suite.desc1 | ||
if (suite is OONIRunSuite) { | ||
author.value = String.format("Author : %s", suite.descriptor.author) | ||
} | ||
} | ||
val authorVisibility: Int | ||
get() = if (author.value != null) View.VISIBLE else View.GONE | ||
|
||
val customUrlVisibility: Int | ||
get() = if (name.value == WebsitesSuite.NAME) View.VISIBLE else View.GONE | ||
} |
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.