Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosUvaSilva committed Mar 1, 2021
2 parents 6e12e19 + cd84f1e commit 92f39c8
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Houseclub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ android {
targetSdkVersion 30
versionCode 9
versionName "1.0.8"

Properties properties = new Properties()
if (project.rootProject.file('local.properties').canRead()) {
properties.load(project.rootProject.file("local.properties").newDataInputStream())
}

buildConfigField "String", "INSTAGRAM_APP_ID", '"'+properties.getProperty("instagramAppId")+'"'
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class ClubhouseAPIController{

private static final Uri API_URL=Uri.parse("https://www.clubhouseapi.com/api");
// private static final Uri API_URL=Uri.parse("http://192.168.0.51:8080/");
private static final String API_BUILD_ID="304";
private static final String API_BUILD_VERSION="0.1.28";
private static final String API_UA="clubhouse/"+API_BUILD_ID+" (iPhone; iOS 13.5.1; Scale/3.00)";
public static final String API_BUILD_ID="304";
public static final String API_BUILD_VERSION="0.1.28";
public static final String API_UA="clubhouse/"+API_BUILD_ID+" (iPhone; iOS 13.5.1; Scale/3.00)";

public static final String PUBNUB_PUB_KEY = "pub-c-6878d382-5ae6-4494-9099-f930f938868b";
public static final String PUBNUB_SUB_KEY = "sub-c-a4abea84-9ca3-11ea-8e71-f2b83ac9263d";
Expand Down Expand Up @@ -150,6 +150,12 @@ public void run(){
if(DEBUG)
Log.i(TAG, "Raw response: "+respStr);
BaseResponse br=gson.fromJson(respStr, BaseResponse.class);

String error;
if (!br.errorMessage.isEmpty()) error=br.errorMessage;
else error="ERROR with code " +resp.code();
br.errorMessage = error;

req.onError(new ClubhouseErrorResponse(br));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.grishka.houseclub.api.methods;

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

public class UpdateInstagram extends ClubhouseAPIRequest<BaseResponse> {
public static String REDIRECT_INSTAGRAM_URL = "https://www.joinclubhouse.com/callback/instagram";
public UpdateInstagram(String code) {
super("POST", "update_instagram_username", BaseResponse.class);
requestBody = new Body(code);
}

private static class Body{
public String code;
Body(String code){
this.code = code;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
Expand All @@ -26,23 +29,28 @@
import android.widget.Toast;

import java.text.DateFormat;
import java.util.HashMap;

import me.grishka.appkit.Nav;
import me.grishka.appkit.api.Callback;
import me.grishka.appkit.api.ErrorResponse;
import me.grishka.appkit.api.SimpleCallback;
import me.grishka.appkit.fragments.LoaderFragment;
import me.grishka.appkit.imageloader.ViewImageLoader;
import me.grishka.houseclub.BuildConfig;
import me.grishka.houseclub.R;
import me.grishka.houseclub.VoiceService;
import me.grishka.houseclub.api.BaseResponse;
import me.grishka.houseclub.api.ClubhouseAPIController;
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.UpdateInstagram;
import me.grishka.houseclub.api.methods.UpdatePhoto;
import me.grishka.houseclub.api.methods.UpdateName;
import me.grishka.houseclub.api.methods.UpdatePhoto;
import me.grishka.houseclub.api.model.FullUser;
Expand All @@ -62,6 +70,7 @@ public class ProfileFragment extends LoaderFragment{
private View socialButtons, inviteLayout;
private boolean self, isImageFitToScreen;

private WebView webView;

@Override
public void onAttach(Activity activity){
Expand Down Expand Up @@ -95,6 +104,7 @@ public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bu
inviteButton = v.findViewById(R.id.invite_button);
invites = v.findViewById(R.id.num_of_invites);
invitePhoneNum = v.findViewById(R.id.invite_phone_num);
webView = v.findViewById(R.id.webView);

followBtn.setOnClickListener(this::onFollowClick);
instagram.setOnClickListener(this::onInstagramClick);
Expand All @@ -113,6 +123,10 @@ public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bu
photo.setOnClickListener(this::onForeignPhotoClick);
}

webView.setVisibility(View.GONE);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

return v;
}

Expand Down Expand Up @@ -147,16 +161,18 @@ public void onSuccess(GetProfile.Response result){
else
followBtn.setText(user.isFollowed() ? R.string.following : R.string.follow);

if(user.twitter==null && user.instagram==null){
if(!self && user.twitter==null && user.instagram==null){
socialButtons.setVisibility(View.GONE);
}else{
socialButtons.setVisibility(View.VISIBLE);
twitter.setVisibility(user.twitter==null ? View.GONE : View.VISIBLE);
instagram.setVisibility(user.instagram==null ? View.GONE : View.VISIBLE);
instagram.setVisibility(user.instagram==null && !self ? View.GONE : View.VISIBLE);
if(user.twitter!=null)
twitter.setText(user.twitter);
if(user.instagram!=null)
instagram.setText(user.instagram);
if(self && user.instagram==null)
instagram.setText(R.string.add_instagram);
}

String joined=getString(R.string.joined_date, DateFormat.getDateInstance().format(user.timeCreated));
Expand Down Expand Up @@ -298,9 +314,98 @@ public void onError(ErrorResponse error){
}

private void onInstagramClick(View v){
if (self){
HashMap<String, String> headers = new HashMap<>();
headers.put("CH-AppBuild", ClubhouseAPIController.API_BUILD_ID);
headers.put("CH-AppVersion", ClubhouseAPIController.API_BUILD_VERSION);
headers.put("User-Agent", ClubhouseAPIController.API_UA);

headers.put("CH-DeviceId", ClubhouseSession.deviceID);
headers.put("Authorization", "Token "+ClubhouseSession.userToken);
headers.put("CH-UserID", ClubhouseSession.userID);

if (user.instagram == null) {
webView.setVisibility(View.VISIBLE);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Boolean redirect = checkRedirect(request.getUrl().toString());
view.loadUrl(request.getUrl().toString());
return redirect;
}

public boolean shouldOverrideUrlLoading(WebView view, String url) {
Boolean redirect = checkRedirect(url);
view.loadUrl(url);
return redirect;
}
});
webView.loadUrl(
"https://www.instagram.com/oauth/authorize?client_id=" +
BuildConfig.INSTAGRAM_APP_ID +
"&redirect_uri=" + UpdateInstagram.REDIRECT_INSTAGRAM_URL +
"&scope=user_profile" +
"&response_type=code",
headers
);
} else {
new AlertDialog.Builder(getActivity())
.setMessage(getString(R.string.confirm_unlink_instagram_title))
.setMessage(getString(R.string.confirm_unlink_instagram))
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialogInterface, int i){
new UpdateInstagram(null)
.wrapProgress(getActivity())
.setCallback(new Callback<BaseResponse>(){
@Override
public void onSuccess(BaseResponse result){
instagram.setText(R.string.add_instagram);
webView.setVisibility(View.GONE);
}

@Override
public void onError(ErrorResponse error){
error.showToast(getActivity());
}
})
.exec();
}
})
.setNegativeButton(R.string.no, null)
.show();
}
} else
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://instagram.com/"+user.instagram)));
}

private Boolean checkRedirect(String url){
if (url.startsWith(UpdateInstagram.REDIRECT_INSTAGRAM_URL)) {

// last2 chars is #_ by docs https://developers.facebook.com/docs/instagram-basic-display-api/getting-started
String code = url.substring((UpdateInstagram.REDIRECT_INSTAGRAM_URL+ "?code=").length(), url.length()-2);

new UpdateInstagram(code)
.wrapProgress(getActivity())
.setCallback(new Callback<BaseResponse>(){
@Override
public void onSuccess(BaseResponse result){
instagram.setText(R.string.instagram_linked);
webView.setVisibility(View.GONE);
}

@Override
public void onError(ErrorResponse error){
error.showToast(getActivity());
}
})
.exec();
return false;
} else {
return true;
}
}

private void onTwitterClick(View v){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/"+user.twitter)));
}
Expand Down
5 changes: 5 additions & 0 deletions Houseclub/src/main/res/layout/profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@
android:text="@string/invite_button_label" />

</LinearLayout>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="540dp"/>

</LinearLayout>

Expand Down
4 changes: 4 additions & 0 deletions Houseclub/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@
<string name="contact_is_invited">Is invited: %s</string>
<string name="contact_num_friends">%d friends on Clubhouse</string>
<string name="contact_separator" translatable="false">,&#160;</string>
<string name="add_instagram">Link instagram</string>
<string name="confirm_unlink_instagram_title">Unlink instagram?</string>
<string name="confirm_unlink_instagram">Are you sure want to unlink instagram? It can be linked in future</string>
<string name="instagram_linked">Instagram linked, reopen page to see</string>
</resources>
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

instagramAppId=1352866981588597

0 comments on commit 92f39c8

Please sign in to comment.