Skip to content

Commit

Permalink
Merge pull request #154 from dvkolesnikov/feature/invite_by_phone_num
Browse files Browse the repository at this point in the history
Implement invitation by phone number
  • Loading branch information
grishka authored Feb 26, 2021
2 parents d6bf4d9 + 205b20b commit 7f7879b
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.grishka.houseclub.api.methods;

import me.grishka.houseclub.api.BaseResponse;
import me.grishka.houseclub.api.ClubhouseAPIRequest;

public class InviteToApp extends ClubhouseAPIRequest<BaseResponse> {

public InviteToApp(String name, String phone_number, String message) {
super("POST", "invite_to_app", BaseResponse.class);
requestBody = new InviteToApp.Body(name, phone_number, message);
}

private static class Body {
public String name;
public String phone_number;
public String message;

public Body(String name, String phone_number, String message) {
this.name = name;
this.phone_number = phone_number;
this.message = message;
}
}

}
28 changes: 28 additions & 0 deletions Houseclub/src/main/java/me/grishka/houseclub/api/methods/Me.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package me.grishka.houseclub.api.methods;

import java.util.TimeZone;

import me.grishka.houseclub.api.ClubhouseAPIRequest;

public class Me extends ClubhouseAPIRequest<Me.Response> {
public Me() {
super("POST", "me", Response.class);
requestBody = new Body();
}

private static class Body {
public boolean return_blocked_ids;
public String timezone_identifier;
public boolean return_following_ids;

public Body() {
this.return_blocked_ids = true;
this.return_following_ids = true;
this.timezone_identifier = TimeZone.getDefault().getDisplayName();
}
}

public static class Response {
public int num_invites;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.text.DateFormat;

Expand All @@ -37,6 +38,8 @@
import me.grishka.houseclub.api.ClubhouseSession;
import me.grishka.houseclub.api.methods.Follow;
import me.grishka.houseclub.api.methods.GetProfile;
import me.grishka.houseclub.api.methods.InviteToApp;
import me.grishka.houseclub.api.methods.Me;
import me.grishka.houseclub.api.methods.Unfollow;
import me.grishka.houseclub.api.methods.UpdateBio;
import me.grishka.houseclub.api.methods.UpdatePhoto;
Expand All @@ -49,10 +52,12 @@ public class ProfileFragment extends LoaderFragment{

private FullUser user;

private TextView name, username, followers, following, followsYou, bio, inviteInfo, twitter, instagram;
private TextView name, username, followers, following, followsYou, bio, inviteInfo, twitter, instagram,
invites;
private ImageView photo, inviterPhoto;
private Button followBtn;
private View socialButtons;
private Button followBtn, inviteButton;
private EditText invitePhoneNum;
private View socialButtons, inviteLayout;
private boolean self;

@Override
Expand Down Expand Up @@ -81,6 +86,10 @@ public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bu
twitter=v.findViewById(R.id.twitter);
instagram=v.findViewById(R.id.instagram);
socialButtons=v.findViewById(R.id.social);
inviteLayout = v.findViewById(R.id.invite_layout);
inviteButton = v.findViewById(R.id.invite_button);
invites = v.findViewById(R.id.num_of_invites);
invitePhoneNum = v.findViewById(R.id.invite_phone_num);

followBtn.setOnClickListener(this::onFollowClick);
instagram.setOnClickListener(this::onInstagramClick);
Expand All @@ -92,6 +101,7 @@ public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bu
bio.setOnClickListener(this::onBioClick);
photo.setOnClickListener(this::onPhotoClick);
name.setOnClickListener(this::onNameClick);
inviteButton.setOnClickListener(this::onInviteClick);
}

return v;
Expand Down Expand Up @@ -156,6 +166,7 @@ public void onSuccess(GetProfile.Response result){
}
})
.exec();
loadInvites();
}

@Override
Expand Down Expand Up @@ -212,6 +223,25 @@ public void onError(ErrorResponse error){
}
}

private void loadInvites() {
new Me().setCallback(new Callback<Me.Response>() {
@Override
public void onSuccess(Me.Response result) {
if (self && result.num_invites > 0) {
invites.setText(getResources().getQuantityString(R.plurals.invites, result.num_invites, result.num_invites));
inviteLayout.setVisibility(View.VISIBLE);
} else {
inviteLayout.setVisibility(View.GONE);
}
}

@Override
public void onError(ErrorResponse error) {
inviteLayout.setVisibility(View.GONE);
}
}).exec();
}

private void onFollowClick(View v){
if(user.isFollowed()){
new AlertDialog.Builder(getActivity())
Expand Down Expand Up @@ -321,6 +351,26 @@ public void onError(ErrorResponse error) {
.show();
}

private void onInviteClick(View v) {
final String numberToInvite = invitePhoneNum.getText().toString();
new InviteToApp("", numberToInvite, "")
.wrapProgress(getContext())
.setCallback(new Callback<BaseResponse>() {
@Override
public void onSuccess(BaseResponse result) {
Toast.makeText(getContext(), "success", Toast.LENGTH_SHORT).show();
loadInvites();
}

@Override
public void onError(ErrorResponse error) {
Toast.makeText(getContext(), "failed", Toast.LENGTH_SHORT).show();
loadInvites();
}
})
.exec();
}

private void onBioClick(View v){
final EditText edit=new EditText(getActivity());
edit.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | edit.getInputType());
Expand Down
32 changes: 32 additions & 0 deletions Houseclub/src/main/res/layout/profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,38 @@

</LinearLayout>

<LinearLayout
android:id="@+id/invite_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="16dp"
android:visibility="gone"
tools:visibility="visible">

<TextView
android:id="@+id/num_of_invites"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="You have 3 invites" />

<EditText
android:id="@+id/invite_phone_num"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/invite_phone_hint"
android:importantForAutofill="no"
android:inputType="phone" />

<Button
android:id="@+id/invite_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/invite_button_label" />

</LinearLayout>

</LinearLayout>

</ScrollView>
6 changes: 6 additions & 0 deletions Houseclub/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
<item quantity="one">%d following</item>
<item quantity="other">%d following</item>
</plurals>
<plurals name="invites">
<item quantity="one">You have %d invite</item>
<item quantity="other">You have %d invites</item>
</plurals>
<string name="invite_button_label">Invite</string>
<string name="invite_phone_hint">Enter phone number</string>
<string name="follows_you">Follows you</string>
<string name="follow">Follow</string>
<string name="following">Following</string>
Expand Down

1 comment on commit 7f7879b

@Om-moemen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Please sign in to comment.