Skip to content

Commit

Permalink
Support /event/ URLs for real this time
Browse files Browse the repository at this point in the history
Fixes #59
  • Loading branch information
grishka committed Feb 21, 2021
1 parent 91f706a commit 7021773
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Houseclub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 35 additions & 1 deletion Houseclub/src/main/java/me/grishka/houseclub/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -103,7 +108,36 @@ protected void onNewIntent(Intent intent){

private void joinChannelFromIntent(){
Uri data=getIntent().getData();
String id=data.getLastPathSegment();
List<String> 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<GetEvent.Response>(){
@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<Channel>(){
Expand Down
Original file line number Diff line number Diff line change
@@ -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<GetEvent.Response>{

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;
}
}
15 changes: 15 additions & 0 deletions Houseclub/src/main/java/me/grishka/houseclub/api/model/Event.java
Original file line number Diff line number Diff line change
@@ -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<FullUser> hosts;
public boolean clubIsMember, clubIsFollower;
}
2 changes: 2 additions & 0 deletions Houseclub/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@
<string name="invited_by">Nominated by %s</string>
<string name="update_bio">Update bio</string>
<string name="save">Save</string>
<string name="event_not_started">This event hasn\'t started yet</string>
<string name="event_expired">This event has already ended</string>
</resources>

0 comments on commit 7021773

Please sign in to comment.