Skip to content

Commit

Permalink
Adds default property values for color and animation if backend d…
Browse files Browse the repository at this point in the history
…oesnt provide any
  • Loading branch information
aanorbel committed Aug 21, 2023
1 parent 7ab812a commit f99de74
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public static TestDescriptor fetchDescriptorFromRunId(long runId, Context contex
.withDescription(descriptor.getDescription())
.withDescriptionIntl(descriptor.getDescriptionIntl())
.withIcon(descriptor.getIcon())
.withColor(descriptor.getColor())
.withAnimation(descriptor.getAnimation())
.withArchived(response.archived)
.withAuthor(descriptor.getAuthor())
.withCreationTime(response.creationTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.openobservatory.ooniprobe.common.AppDatabase;
import org.openobservatory.ooniprobe.common.LocaleUtils;
import org.openobservatory.ooniprobe.common.MapUtility;
import org.openobservatory.ooniprobe.common.ThirdPartyServices;
import org.openobservatory.ooniprobe.domain.MapConverter;
import org.openobservatory.ooniprobe.domain.NettestConverter;
import org.openobservatory.ooniprobe.test.suite.OONIRunSuite;
Expand All @@ -26,6 +27,30 @@
import java.util.HashMap;
import java.util.List;

import javax.annotation.Nullable;

enum Animations {
checkMark("anim/checkMark.json"),
circumvention("anim/circumvention.json"),
crossMark("anim/crossMark.json"),
experimental("anim/experimental.json"),
instant_messaging("anim/instant_messaging.json"),
middle_boxes("anim/middle_boxes.json"),
performance("anim/performance.json"),
websites("anim/websites.json");

private final String asset;

Animations(String asset) {
this.asset = asset;
}

@Override
public String toString() {
return this.asset;
}
}

@Table(database = AppDatabase.class)
public class TestDescriptor extends BaseModel implements Serializable {
@PrimaryKey()
Expand All @@ -52,6 +77,12 @@ public class TestDescriptor extends BaseModel implements Serializable {
@Column
private String icon;

@Column
private String color;

@Column
private String animation;

@Column
private String author;

Expand Down Expand Up @@ -136,6 +167,37 @@ public void setIcon(String icon) {
this.icon = icon;
}

public String getColor() {
return color != null ? color : "#495057";
}

public void setColor(String color) {
this.color = color;
}

public String getAnimation() {
return animation != null ? animation : "experimental";
}

public void setAnimation(String animation) {
this.animation = animation;
}

public int getParsedColor() {
return Color.parseColor(getColor());
}

@Nullable
public String getAnimationAsset() {
try {
return Animations.valueOf(getAnimation()).toString();
}catch (Exception e){
e.printStackTrace();
ThirdPartyServices.logException(e);
return null;
}
}

public String getAuthor() {
return author;
}
Expand Down Expand Up @@ -222,14 +284,6 @@ public boolean shouldUpdate(TestDescriptor updatedDescriptor) {
|| updatedDescriptor.translationCreationTime.after(translationCreationTime);
}

public String getAnimation() {
return "anim/websites.json";
}

public int getParsedColor() {
return Color.parseColor("#c92a2a");
}


public static final class Builder {
private long runId;
Expand All @@ -240,6 +294,8 @@ public static final class Builder {
private String description;
private HashMap descriptionIntl;
private String icon;
private String color;
private String animation;
private String author;
private boolean archived;
private boolean autoRun;
Expand Down Expand Up @@ -295,6 +351,16 @@ public Builder withIcon(String icon) {
return this;
}

public Builder withColor(String color) {
this.color = color;
return this;
}

public Builder withAnimation(String animation) {
this.animation = animation;
return this;
}

public Builder withAuthor(String author) {
this.author = author;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public OONIRunSuite(Context context, TestDescriptor descriptor, AbstractTest...
R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Experimental,
R.style.Theme_MaterialComponents_NoActionBar_App_Experimental,
descriptor.getDescription(),
descriptor.getAnimation(),
descriptor.getAnimationAsset(),
R.string.TestResults_NotAvailable);
this.tests = tests;
this.descriptor = descriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ data class OONIRunDescriptor(
@SerializedName("description_intl")
val descriptionIntl: HashMap<String, String>,
val icon: String,
val color: String,
val animation: String,
val name: String,
@SerializedName("name_intl")
val nameIntl: HashMap<String, String>,
Expand Down

0 comments on commit f99de74

Please sign in to comment.