diff --git a/Houseclub/src/main/java/me/grishka/houseclub/api/methods/InviteToApp.java b/Houseclub/src/main/java/me/grishka/houseclub/api/methods/InviteToApp.java new file mode 100644 index 00000000..badd813a --- /dev/null +++ b/Houseclub/src/main/java/me/grishka/houseclub/api/methods/InviteToApp.java @@ -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 { + + 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; + } + } + +} \ No newline at end of file diff --git a/Houseclub/src/main/java/me/grishka/houseclub/api/methods/Me.java b/Houseclub/src/main/java/me/grishka/houseclub/api/methods/Me.java new file mode 100644 index 00000000..8024c67c --- /dev/null +++ b/Houseclub/src/main/java/me/grishka/houseclub/api/methods/Me.java @@ -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 { + 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; + } +} diff --git a/Houseclub/src/main/java/me/grishka/houseclub/fragments/ProfileFragment.java b/Houseclub/src/main/java/me/grishka/houseclub/fragments/ProfileFragment.java index 58612cc8..e0ee265a 100644 --- a/Houseclub/src/main/java/me/grishka/houseclub/fragments/ProfileFragment.java +++ b/Houseclub/src/main/java/me/grishka/houseclub/fragments/ProfileFragment.java @@ -22,6 +22,7 @@ import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import java.text.DateFormat; @@ -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; @@ -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 @@ -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); @@ -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; @@ -156,6 +166,7 @@ public void onSuccess(GetProfile.Response result){ } }) .exec(); + loadInvites(); } @Override @@ -212,6 +223,25 @@ public void onError(ErrorResponse error){ } } + private void loadInvites() { + new Me().setCallback(new Callback() { + @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()) @@ -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() { + @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()); diff --git a/Houseclub/src/main/res/layout/profile.xml b/Houseclub/src/main/res/layout/profile.xml index ab6785cb..ed9ae7a8 100644 --- a/Houseclub/src/main/res/layout/profile.xml +++ b/Houseclub/src/main/res/layout/profile.xml @@ -156,6 +156,38 @@ + + + + + + +