[Modify]facebook接入

This commit is contained in:
wushaocheng
2023-08-14 12:27:53 +08:00
parent cc21e2969a
commit 44e918bd68
9 changed files with 157 additions and 52 deletions

View File

@@ -287,6 +287,8 @@ dependencies {
//wheelView
implementation 'com.contrarywind:wheelview:4.1.0'
implementation 'com.facebook.android:facebook-login:latest.release'
}
channel {

View File

@@ -1046,6 +1046,26 @@
<service
android:name=".service.DaemonService"
android:enabled="true" />
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>
</application>
</manifest>

View File

@@ -402,7 +402,6 @@ public class XChatApplication extends BaseApp {
.setBaseUrl(url)
.addInterceptors(new ParamsInterceptor(httpParams))
.addInterceptors(new NoParamsInterceptor())//注意:拦截器的添加顺序,请求的拦截顺序
// .addInterceptors(new MyOkHttpRetryInterceptor())
.certificates()
.build();
//单例的model 初始化

View File

@@ -270,23 +270,23 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
giftReceiver.setNick(giftReceiveInfo.getTargetNick());
targetUsers.add(giftReceiver);
}
// GiftReceiveInfo giftReceiveInfo = giftReceiveInfos.get(0);
// GiftInfo giftInfo = giftReceiveInfo.getGift();
// if (totalCoin >= 520 || (giftInfo != null && giftInfo.isHasEffect())) {
// Message msg = Message.obtain();
// msg.what = 0;
// GiftEffectInfo giftEffectInfo = new GiftEffectInfo();
// giftEffectInfo.setUid(giftReceiveInfo.getUid());
// giftEffectInfo.setNick(giftReceiveInfo.getNick());
// giftEffectInfo.setAvatar(giftReceiveInfo.getAvatar());
// giftEffectInfo.setGiftId(giftReceiveInfo.getGiftId());
// giftEffectInfo.setGiftNum(giftReceiveInfo.getGiftNum());
// giftEffectInfo.setGift(giftInfo);
// giftEffectInfo.setTargetUsers(targetUsers);
// giftEffectInfo.setGiftReceiveType(giftReceiveType);
// msg.obj = giftEffectInfo;
// handler.sendMessageDelayed(msg, 200);
// }
GiftReceiveInfo giftReceiveInfo = giftReceiveInfos.get(0);
GiftInfo giftInfo = giftReceiveInfo.getGift();
if (totalCoin >= 520 || (giftInfo != null && giftInfo.isHasEffect())) {
Message msg = Message.obtain();
msg.what = 0;
GiftEffectInfo giftEffectInfo = new GiftEffectInfo();
giftEffectInfo.setUid(giftReceiveInfo.getUid());
giftEffectInfo.setNick(giftReceiveInfo.getNick());
giftEffectInfo.setAvatar(giftReceiveInfo.getAvatar());
giftEffectInfo.setGiftId(giftReceiveInfo.getGiftId());
giftEffectInfo.setGiftNum(giftReceiveInfo.getGiftNum());
giftEffectInfo.setGift(giftInfo);
giftEffectInfo.setTargetUsers(targetUsers);
giftEffectInfo.setGiftReceiveType(giftReceiveType);
msg.obj = giftEffectInfo;
handler.sendMessageDelayed(msg, 200);
}
}
}
}

View File

@@ -60,9 +60,6 @@ class EarnRecordActivity : BaseViewBindingActivity<ActivityEarnRecordBinding>(),
earnRecordModel.queryRoomTypeLiveData.observe(this) {
it?.let {
if (it.roomType == 4) {
binding.csGoldBg.visibility = View.GONE
}
roomTypeInfo = it
binding.tvDiamondNum.text = String.format(it.diamonds.toString())
binding.tvGoldNum.text = String.format(it.golds.toString())

View File

@@ -10,12 +10,23 @@ import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.widget.CheckBox;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.Profile;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.netease.nim.uikit.StatusBarUtil;
import com.tongdaxing.erban.upgrade.AppUpgradeHelper;
@@ -36,12 +47,15 @@ import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.auth.event.LoginEvent;
import com.yizhuan.xchat_android_core.auth.event.LoginReportEvent;
import com.yizhuan.xchat_android_library.utils.AppMetaDataUtil;
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
import io.reactivex.SingleObserver;
import io.reactivex.disposables.Disposable;
@@ -52,6 +66,8 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
protected CheckBox tvProtocol;
private TextView tvProtocolHint;
private CallbackManager callbackManager;
public static void start(Context context) {
Intent intent = new Intent(context, LoginActivity.class);
context.startActivity(intent);
@@ -70,6 +86,58 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
HashMap<String, Object> map = new HashMap<>(2);
map.put(IReportConstants.MODULE, IReportConstants.PEKO_LOGIN);
ReportManager.get().reportEvent(IReportConstants.LOGIN_SHOW, map);
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
SingleToastUtil.showToast("成功");
getFbLoginInfo(loginResult.getAccessToken());
}
@Override
public void onCancel() {
SingleToastUtil.showToast("cancel");
CookieSyncManager.createInstance(LoginActivity.this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
CookieSyncManager.getInstance().sync();
}
@Override
public void onError(FacebookException error) {
SingleToastUtil.showToast("error");
}
});
}
/**
* 获取Facebook个人信息
*/
public void getFbLoginInfo(AccessToken accessToken) {
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
if (object != null) {
String id = object.optString("id");
String name = object.optString("name");
String gender = object.optString("gender"); //性别
String email = object.optString("email");
//获取用户头像
JSONObject object_pic = object.optJSONObject("picture");
JSONObject object_data = object_pic.optJSONObject("data");
String photo = object_data.optString("url");
//获取地域信息
String locale = object.optString("locale"); //zh_CN 代表中文简体
// getP().doLoginByOauth(id, name, photo, "2");
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link,gender,birthday,email,picture,locale,updated_time,timezone,age_range,first_name,last_name");
request.setParameters(parameters);
request.executeAsync();
}
private void onFindViews() {
@@ -167,33 +235,42 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
switch (v.getId()) {
case R.id.tv_facebook:
reportLoginType(IReportConstants.ONE);
getDialogManager().showProgressDialog(this);
AuthModel.get().facebookLogin()
.compose(bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new SingleObserver<String>() {
@Override
public void onSubscribe(Disposable d) {
//判断当前token如果不为空则已经获取过权限否则读取权限走registerCallback回调
AccessToken accessToken = AccessToken.getCurrentAccessToken();
Profile profile = Profile.getCurrentProfile();
if (accessToken == null || accessToken.isExpired() || profile == null) {
LoginManager.getInstance().logInWithReadPermissions(this, List.of("public_profile, email, user_birthday, user_friends"));
} else {
getFbLoginInfo(accessToken);
}
}
@Override
public void onSuccess(String result) {
reportLoginResult(IReportConstants.ONE, IReportConstants.ONE, "");
HashMap<String, Object> map = new HashMap<>(2);
map.put(FirebaseAnalytics.Param.METHOD, getString(R.string.login_facebook));
ReportManager.get().reportEvent(FirebaseAnalytics.Event.LOGIN, map);
ReportManager.get().reportAdjustEvent(IReportConstants.ADJUST_LOGIN);
getDialogManager().dismissDialog();
}
@Override
public void onError(Throwable e) {
reportLoginResult(IReportConstants.ONE, IReportConstants.ZERO, e.getMessage());
getDialogManager().dismissDialog();
dealWithLoginError(e);
}
});
// reportLoginType(IReportConstants.ONE);
// getDialogManager().showProgressDialog(this);
// AuthModel.get().facebookLogin()
// .compose(bindUntilEvent(ActivityEvent.DESTROY))
// .subscribe(new SingleObserver<String>() {
// @Override
// public void onSubscribe(Disposable d) {
//
// }
//
// @Override
// public void onSuccess(String result) {
// reportLoginResult(IReportConstants.ONE, IReportConstants.ONE, "");
// HashMap<String, Object> map = new HashMap<>(2);
// map.put(FirebaseAnalytics.Param.METHOD, getString(R.string.login_facebook));
// ReportManager.get().reportEvent(FirebaseAnalytics.Event.LOGIN, map);
// ReportManager.get().reportAdjustEvent(IReportConstants.ADJUST_LOGIN);
// getDialogManager().dismissDialog();
// }
//
// @Override
// public void onError(Throwable e) {
// reportLoginResult(IReportConstants.ONE, IReportConstants.ZERO, e.getMessage());
// getDialogManager().dismissDialog();
// dealWithLoginError(e);
// }
// });
break;
case R.id.tv_line:
reportLoginType(IReportConstants.TWO);
@@ -268,6 +345,12 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
/**
* 上报登录结果
*

View File

@@ -5101,4 +5101,8 @@
<string name="Senior_management_setup">高管設置</string>
<string name="contract_statement">簽約流水</string>
<string name="facebook_app_id">1266232494209868</string>
<string name="fb_login_protocol_scheme">fb1266232494209868</string>
<string name="facebook_client_token">189d1a90712cc61cedded4cf1372cb21</string>
</resources>