diff options
author | cyberta <cyberta@riseup.net> | 2022-11-22 19:15:06 +0000 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2022-11-22 19:15:06 +0000 |
commit | c3613c8521edb8f3e979331d2396977808581eeb (patch) | |
tree | 15aeeb09e1948466ae11b3591c7be89bb6de7bf9 /app/src/main/java/se/leap/bitmaskclient/motd/MotdClient.java | |
parent | 5bec8a2ab69cd3d457756ca43fa28b880f95befa (diff) | |
parent | 2d20c8e269a502945e981662abe1f7818090a618 (diff) |
Merge branch 'motd' into 'master'
Motd
Closes #9082
See merge request leap/bitmask_android!213
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/motd/MotdClient.java')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/motd/MotdClient.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/motd/MotdClient.java b/app/src/main/java/se/leap/bitmaskclient/motd/MotdClient.java new file mode 100644 index 00000000..d80a8992 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/motd/MotdClient.java @@ -0,0 +1,47 @@ +package se.leap.bitmaskclient.motd; + +import androidx.annotation.WorkerThread; + +import org.json.JSONException; +import org.json.JSONObject; + +import de.blinkt.openvpn.core.VpnStatus; +import motd.IMessages; +import motd.IMotd; +import motd.Motd; +import se.leap.bitmaskclient.base.models.Provider; + +public class MotdClient { + IMotd motd; + + public MotdClient(Provider provider) { + motd = Motd.newMotd(provider.getMotdUrl().toString(), provider.getName(), "android"); + } + + @WorkerThread + public IMessages fetch() { + if (!VpnStatus.isVPNActive()) { + VpnStatus.logError("Tried to fetch Message of the Day while VPN was off."); + return null; + } + + return Motd.newMessages(motd.fetchLatestAsJson()); + } + + @WorkerThread + public JSONObject fetchJson() { + if (!VpnStatus.isVPNActive()) { + VpnStatus.logError("Tried to fetch Message of the Day while VPN was off."); + return null; + } + + try { + return new JSONObject(motd.fetchLatestAsJson()); + } catch (NullPointerException | JSONException e) { + e.printStackTrace(); + return null; + } + + } + +} |