From 702177360979c0ccb991439907293ff14c16a443 Mon Sep 17 00:00:00 2001 From: Grishka Date: Sun, 21 Feb 2021 19:03:57 +0300 Subject: [PATCH] Support /event/ URLs for real this time Fixes #59 --- Houseclub/build.gradle | 4 +-- .../me/grishka/houseclub/MainActivity.java | 36 ++++++++++++++++++- .../houseclub/api/methods/GetEvent.java | 24 +++++++++++++ .../me/grishka/houseclub/api/model/Event.java | 15 ++++++++ Houseclub/src/main/res/values/strings.xml | 2 ++ 5 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 Houseclub/src/main/java/me/grishka/houseclub/api/methods/GetEvent.java create mode 100644 Houseclub/src/main/java/me/grishka/houseclub/api/model/Event.java diff --git a/Houseclub/build.gradle b/Houseclub/build.gradle index f99df400..b7d1f960 100644 --- a/Houseclub/build.gradle +++ b/Houseclub/build.gradle @@ -7,8 +7,8 @@ android { applicationId "me.grishka.houseclub" minSdkVersion 24 targetSdkVersion 30 - versionCode 5 - versionName "1.0.4" + versionCode 6 + versionName "1.0.5" } buildTypes { release { diff --git a/Houseclub/src/main/java/me/grishka/houseclub/MainActivity.java b/Houseclub/src/main/java/me/grishka/houseclub/MainActivity.java index 68aeffde..55aa5bb0 100644 --- a/Houseclub/src/main/java/me/grishka/houseclub/MainActivity.java +++ b/Houseclub/src/main/java/me/grishka/houseclub/MainActivity.java @@ -10,6 +10,10 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.widget.Toast; + +import java.util.Date; +import java.util.List; import androidx.annotation.NonNull; import me.grishka.appkit.FragmentStackActivity; @@ -20,6 +24,7 @@ import me.grishka.houseclub.api.ClubhouseSession; import me.grishka.houseclub.api.methods.CheckWaitlistStatus; import me.grishka.houseclub.api.methods.GetChannel; +import me.grishka.houseclub.api.methods.GetEvent; import me.grishka.houseclub.api.methods.JoinChannel; import me.grishka.houseclub.api.model.Channel; import me.grishka.houseclub.fragments.HomeFragment; @@ -103,7 +108,36 @@ protected void onNewIntent(Intent intent){ private void joinChannelFromIntent(){ Uri data=getIntent().getData(); - String id=data.getLastPathSegment(); + List path=data.getPathSegments(); + String id=path.get(path.size()-1); + if(path.get(0).equals("room")){ + joinChannelById(id); + }else if(path.get(0).equals("event")){ + new GetEvent(id) + .wrapProgress(this) + .setCallback(new Callback(){ + @Override + public void onSuccess(GetEvent.Response result){ + if(result.event.channel!=null){ + joinChannelById(result.event.channel); + }else{ + if(result.event.isExpired) + Toast.makeText(MainActivity.this, R.string.event_expired, Toast.LENGTH_SHORT).show(); + else if(result.event.timeStart.after(new Date())) + Toast.makeText(MainActivity.this, R.string.event_not_started, Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onError(ErrorResponse error){ + error.showToast(MainActivity.this); + } + }) + .exec(); + } + } + + private void joinChannelById(String id){ new GetChannel(id) .wrapProgress(this) .setCallback(new Callback(){ diff --git a/Houseclub/src/main/java/me/grishka/houseclub/api/methods/GetEvent.java b/Houseclub/src/main/java/me/grishka/houseclub/api/methods/GetEvent.java new file mode 100644 index 00000000..4d51847c --- /dev/null +++ b/Houseclub/src/main/java/me/grishka/houseclub/api/methods/GetEvent.java @@ -0,0 +1,24 @@ +package me.grishka.houseclub.api.methods; + +import me.grishka.houseclub.api.ClubhouseAPIRequest; +import me.grishka.houseclub.api.model.Event; + +public class GetEvent extends ClubhouseAPIRequest{ + + public GetEvent(String id){ + super("POST", "get_event", Response.class); + requestBody=new Body(id); + } + + private static class Body{ + public String eventHashid; + + public Body(String eventHashid){ + this.eventHashid=eventHashid; + } + } + + public static class Response{ + public Event event; + } +} diff --git a/Houseclub/src/main/java/me/grishka/houseclub/api/model/Event.java b/Houseclub/src/main/java/me/grishka/houseclub/api/model/Event.java new file mode 100644 index 00000000..ea1ae9b8 --- /dev/null +++ b/Houseclub/src/main/java/me/grishka/houseclub/api/model/Event.java @@ -0,0 +1,15 @@ +package me.grishka.houseclub.api.model; + +import java.util.Date; +import java.util.List; + +public class Event{ + public String channel; + public boolean isExpired; + public Date timeStart; + public String description, name; + public int eventId; + public boolean isMemberOnly; + public List hosts; + public boolean clubIsMember, clubIsFollower; +} diff --git a/Houseclub/src/main/res/values/strings.xml b/Houseclub/src/main/res/values/strings.xml index 3925c749..fb6fb4b5 100644 --- a/Houseclub/src/main/res/values/strings.xml +++ b/Houseclub/src/main/res/values/strings.xml @@ -50,4 +50,6 @@ Nominated by %s Update bio Save + This event hasn\'t started yet + This event has already ended