diff --git a/app/build.gradle b/app/build.gradle index 6a35015967..91342150d2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -216,6 +216,8 @@ dependencies { // provided libs.tinker_anno // compile libs.tinker_lib + compile libs.weiboSDK + compile libs.eventbus apt libs.eventbusApt // compile project(':libraries:EventBus') @@ -225,7 +227,7 @@ dependencies { compile project(':libraries:TalkingData') compile project(':libraries:UmengPush') compile project(':libraries:WechatShare') - compile project(':libraries:WeiboShare') +// compile project(':libraries:WeiboShare') compile project(':libraries:iosched') } diff --git a/app/proguard-rules.txt b/app/proguard-rules.txt index 52ed580b8f..ea91562c9a 100644 --- a/app/proguard-rules.txt +++ b/app/proguard-rules.txt @@ -117,6 +117,8 @@ (java.lang.Throwable); } +# weiboSdk +-keep class com.sina.weibo.sdk.** { *; } # app models -keep class com.gh.common.view.** {*;} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 15574ac7b5..9eb9383c9f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -179,6 +179,15 @@ android:name = "com.gh.gamecenter.ToolBoxActivity" android:screenOrientation = "portrait" android:windowSoftInputMode="stateHidden"/> + + + + + diff --git a/app/src/main/java/com/gh/common/util/LoginUtils.java b/app/src/main/java/com/gh/common/util/LoginUtils.java new file mode 100644 index 0000000000..0ffe64eea0 --- /dev/null +++ b/app/src/main/java/com/gh/common/util/LoginUtils.java @@ -0,0 +1,179 @@ +package com.gh.common.util; + +import android.app.Activity; +import android.content.Context; +import android.widget.Toast; + +import com.gh.common.constant.Config; +import com.sina.weibo.sdk.WbSdk; +import com.sina.weibo.sdk.auth.AuthInfo; +import com.sina.weibo.sdk.auth.Oauth2AccessToken; +import com.sina.weibo.sdk.auth.WbConnectErrorMessage; +import com.sina.weibo.sdk.auth.sso.SsoHandler; +import com.tencent.connect.UserInfo; +import com.tencent.connect.auth.QQToken; +import com.tencent.mm.sdk.openapi.IWXAPI; +import com.tencent.mm.sdk.openapi.SendAuth; +import com.tencent.mm.sdk.openapi.WXAPIFactory; +import com.tencent.tauth.IUiListener; +import com.tencent.tauth.Tencent; +import com.tencent.tauth.UiError; + +import org.json.JSONObject; + +import java.text.SimpleDateFormat; + +/** + * Created by khy on 14/06/17. + */ + +public class LoginUtils { + + private static LoginUtils instance; + + private Context mContext; + + private Tencent mTencent; + private IWXAPI mIWXAPI; + private SsoHandler mSsoHandler; + + private Oauth2AccessToken mAccessToken; // wb + public static final String SCOPE = + "email,direct_messages_read,direct_messages_write," + + "friendships_groups_read,friendships_groups_write,statuses_to_me_read," + + "follow_app_official_microblog," + "invitation_write"; + + private LoginUtils(Context context) { + mTencent = Tencent.createInstance(Config.TENCENT_APPID, context); //初始化QQ分享 + mIWXAPI = WXAPIFactory.createWXAPI(context, Config.WECHAT_APPID, true); //初始化微信分享 + WbSdk.install(context,new AuthInfo(context, Config.WEIBO_APPKEY, "http://www.sina.com", SCOPE)); + mSsoHandler = new SsoHandler((Activity) context); + mContext = context; + Utils.log("LoginUtils", "initLogin"); + } + + public static LoginUtils getInstance(Activity context) { + if (instance == null) { + instance = new LoginUtils(context); + } + return instance; + } + + //QQ登录回调处理 + public IUiListener QqLoginListener = new IUiListener() { + @Override + public void onComplete(Object o) { + Toast.makeText(mContext, "登录成功", Toast.LENGTH_SHORT).show(); + if (o instanceof JSONObject) { + String s = o.toString(); + Utils.log("LoginUtils", "QQLoginComplete::" + s); + } + + QQToken qqToken = mTencent.getQQToken(); + UserInfo userInfo = new UserInfo(mContext, qqToken); + userInfo.getUserInfo(new IUiListener() { + @Override + public void onComplete(Object o) { + Utils.log("LoginUtils", "QQUserInfo::" + o.toString()); + } + + @Override + public void onError(UiError uiError) { + Utils.log("LoginUtils", "QQUserInfoUiError::" + uiError.errorDetail + "==" + uiError.errorMessage + "==" + uiError.errorCode); + } + + @Override + public void onCancel() { + Utils.log("LoginUtils", "QQUserInfoonCancel"); + } + }); + } + + @Override + public void onError(UiError uiError) { + Toast.makeText(mContext, "登录失败", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onCancel() { + Toast.makeText(mContext, "登录取消", Toast.LENGTH_SHORT).show(); + } + }; + + + public void QQLogin() { + if (mTencent != null && !mTencent.isSessionValid()) { + mTencent.login((Activity) mContext, "all", QqLoginListener); + } + } + + public void QQLogout() { + if (mTencent != null) { + mTencent.logout(mContext); + } + } + + public void WCLogin() { + if (mIWXAPI != null) { + boolean register = mIWXAPI.registerApp("wx3ffd0785fad18396"); + + SendAuth.Req req = new SendAuth.Req(); + req.scope = "all"; + req.state = "光环助手"; + boolean b = mIWXAPI.sendReq(req); + Utils.log("LoginUtils", "微信注册状态::" + register + "\n 发送状态::" + b); + } + } + + public void WeiBoLogin() { + mSsoHandler.authorizeClientSso(new SelfWbAuthListener()); + } + + private class SelfWbAuthListener implements com.sina.weibo.sdk.auth.WbAuthListener{ + @Override + public void onSuccess(final Oauth2AccessToken token) { + ((Activity) mContext).runOnUiThread(new Runnable() { + @Override + public void run() { + mAccessToken = token; + if (mAccessToken.isSessionValid()) { + // 显示 Token + updateTokenView(false); + // 保存 Token 到 SharedPreferences + AccessTokenKeeper.writeAccessToken(mContext, mAccessToken); + Toast.makeText(mContext, "授权成功", Toast.LENGTH_SHORT).show(); + } + } + }); + } + + @Override + public void cancel() { + Toast.makeText(mContext, "取消授权", Toast.LENGTH_LONG).show(); + } + + @Override + public void onFailure(WbConnectErrorMessage errorMessage) { + Toast.makeText(mContext, errorMessage.getErrorMessage(), Toast.LENGTH_LONG).show(); + } + } + + /** + * 显示当前 Token 信息。 + * + * @param hasExisted 配置文件中是否已存在 token 信息并且合法 + */ + private void updateTokenView(boolean hasExisted) { + String date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format( + new java.util.Date(mAccessToken.getExpiresTime())); + String format = "Token:%1$s \\n有效期:%2$s"; + String token = String.format(format, mAccessToken.getToken(), date); + Utils.log("LoginUtils::WB_TOKEN::" + token); + String message = String.format(format, mAccessToken.getToken(), date); + if (hasExisted) { + message = "Token 仍在有效期内,无需再次登录。" + "\n" + message; + } + Utils.log("LoginUtils::WB_MESSAGE::" + message); + } + +} diff --git a/app/src/main/java/com/gh/common/util/ShareUtils.java b/app/src/main/java/com/gh/common/util/ShareUtils.java index 48f89f4856..66774bf607 100644 --- a/app/src/main/java/com/gh/common/util/ShareUtils.java +++ b/app/src/main/java/com/gh/common/util/ShareUtils.java @@ -31,6 +31,8 @@ import com.facebook.imagepipeline.image.CloseableImage; import com.gh.common.constant.Config; import com.gh.gamecenter.R; import com.gh.gamecenter.WeiBoShareActivity; +import com.sina.weibo.sdk.WbSdk; +import com.sina.weibo.sdk.auth.AuthInfo; import com.tencent.connect.share.QQShare; import com.tencent.connect.share.QzoneShare; import com.tencent.mm.sdk.openapi.IWXAPI; @@ -47,6 +49,8 @@ import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; +import static com.gh.common.util.LoginUtils.SCOPE; + /** * Created by khy on 2016/9/4. */ @@ -99,6 +103,7 @@ public class ShareUtils { private ShareUtils(Context context) { mTencent = Tencent.createInstance(Config.TENCENT_APPID, context); //初始化QQ分享 mIWXAPI = WXAPIFactory.createWXAPI(context, Config.WECHAT_APPID); //初始化微信分享 + WbSdk.install(context,new AuthInfo(context, Config.WEIBO_APPKEY, "http://www.sina.com", SCOPE)); mContext = context; } diff --git a/app/src/main/java/com/gh/gamecenter/InstallActivity.java b/app/src/main/java/com/gh/gamecenter/InstallActivity.java new file mode 100644 index 0000000000..f8cb192ad2 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/InstallActivity.java @@ -0,0 +1,157 @@ +package com.gh.gamecenter; + +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.gh.base.BaseActivity; +import com.gh.common.util.DialogUtils; +import com.gh.common.util.DownloadItemUtils; +import com.gh.common.view.SwipeLayout; +import com.gh.common.view.VerticalItemDecoration; +import com.gh.download.DataWatcher; +import com.gh.download.DownloadEntity; +import com.gh.download.DownloadManager; +import com.gh.gamecenter.adapter.InstallFragmentAdapter; +import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.eventbus.EBPackage; +import com.gh.gamecenter.eventbus.EBReuse; +import com.gh.gamecenter.eventbus.EBSkip; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; + +import butterknife.BindView; + +/** + * Created by khy on 15/06/17. + */ + +public class InstallActivity extends BaseActivity implements InstallFragmentAdapter.onSmoothLayoutListener { + + @BindView(R.id.fm_install_rv_show) + RecyclerView fm_install_rv_show; + @BindView(R.id.reuse_nodata_skip) + LinearLayout reuse_nodata_skip; + @BindView(R.id.reuse_nodata_skip_tv_hint) + TextView reuse_nodata_skip_tv_hint; + @BindView(R.id.reuse_nodata_skip_tv_btn) + TextView reuse_nodata_skip_tv_btn; + + private InstallFragmentAdapter mAdapter; + + private DataWatcher dataWatcher = new DataWatcher() { + @Override + public void onDataChanged(DownloadEntity downloadEntity) { + ArrayList locationList = mAdapter.getLocationMap().get(downloadEntity.getPackageName()); + if (locationList != null && locationList.size() != 0) { + GameEntity gameEntity; + for (int location : locationList) { + gameEntity = mAdapter.getGameList().get(location); + if (gameEntity != null) { + DownloadItemUtils.processDate(InstallActivity.this, gameEntity, + downloadEntity, mAdapter, location); + } + } + } + } + }; + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + + // 分享成绩单 + if (requestCode == 0x170 || requestCode == 0x180) { + DialogUtils.showKuaiChuanResult(this, new Handler(), requestCode, "shareKc.jpg"); + + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + init("我的游戏"); + reuse_nodata_skip.setVisibility(View.GONE); + reuse_nodata_skip_tv_hint.setText("暂无游戏"); + reuse_nodata_skip_tv_btn.setText("查看精品推荐"); + reuse_nodata_skip_tv_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + EventBus.getDefault().post(new EBSkip(MainActivity.EB_SKIP_GAMEFRAGMENT, 1)); + } + }); + + fm_install_rv_show.setHasFixedSize(true); + fm_install_rv_show.setLayoutManager(new LinearLayoutManager(this)); + mAdapter = new InstallFragmentAdapter(this); + fm_install_rv_show.addItemDecoration(new VerticalItemDecoration(this, 1, true)); + fm_install_rv_show.setAdapter(mAdapter); + } + + @Override + protected int getLayoutId() { + return R.layout.activity_install; + } + + @Override + public void onResume() { +// if (isEverpause) { +// for (GameEntity entity : mAdapter.getGameList()) { +// entity.setEntryMap(DownloadManager.getInstance(this).getEntryMap(entity.getName())); +// } +// mAdapter.notifyDataSetChanged(); +// } + super.onResume(); + DownloadManager.getInstance(this).addObserver(dataWatcher); + } + + @Override + public void onPause() { + super.onPause(); + DownloadManager.getInstance(this).removeObserver(dataWatcher); + } + + @Override + public void loadEmpty() { + fm_install_rv_show.setVisibility(View.GONE); + reuse_nodata_skip.setVisibility(View.VISIBLE); + } + + // 打开下载按钮事件 + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEventMainThread(EBReuse reuse) { + if (("Refresh".equals(reuse.getType()) || "PlatformChanged".equals(reuse.getType())) + && mAdapter != null) { + mAdapter.notifyItemRangeChanged(0, mAdapter.getItemCount()); + } + } + + //安装、卸载事件 + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEventMainThread(EBPackage busFour) { + if ("安装".equals(busFour.getType()) || "卸载".equals(busFour.getType())) { + fm_install_rv_show.setVisibility(View.VISIBLE); + reuse_nodata_skip.setVisibility(View.GONE); + mAdapter = new InstallFragmentAdapter(this); + fm_install_rv_show.setAdapter(mAdapter); + } + } + + // 滑动item + @Override + public void onSmooth() { + View childAt = fm_install_rv_show.getChildAt(fm_install_rv_show.getChildCount() - 2); + SwipeLayout swipeLayout = (SwipeLayout) childAt.findViewById(R.id.swipeLayout); + if (swipeLayout == null) return; + swipeLayout.openAndColse(); +// swipeLayout.close(); + } +} diff --git a/app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java b/app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java index 0a9561928f..cdf49c470f 100644 --- a/app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java +++ b/app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java @@ -12,8 +12,6 @@ import com.facebook.common.references.CloseableReference; import com.facebook.datasource.DataSource; import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber; import com.facebook.imagepipeline.image.CloseableImage; -import com.gh.common.constant.Config; -import com.gh.common.util.AccessTokenKeeper; import com.gh.common.util.ImageUtils; import com.gh.common.util.ShareUtils; import com.gh.common.util.Utils; @@ -21,16 +19,8 @@ import com.sina.weibo.sdk.api.ImageObject; import com.sina.weibo.sdk.api.TextObject; import com.sina.weibo.sdk.api.WebpageObject; import com.sina.weibo.sdk.api.WeiboMultiMessage; -import com.sina.weibo.sdk.api.share.BaseResponse; -import com.sina.weibo.sdk.api.share.IWeiboHandler; -import com.sina.weibo.sdk.api.share.IWeiboShareAPI; -import com.sina.weibo.sdk.api.share.SendMultiMessageToWeiboRequest; -import com.sina.weibo.sdk.api.share.WeiboShareSDK; -import com.sina.weibo.sdk.auth.AuthInfo; -import com.sina.weibo.sdk.auth.Oauth2AccessToken; -import com.sina.weibo.sdk.auth.WeiboAuthListener; -import com.sina.weibo.sdk.constant.WBConstants; -import com.sina.weibo.sdk.exception.WeiboException; +import com.sina.weibo.sdk.share.WbShareCallback; +import com.sina.weibo.sdk.share.WbShareHandler; import com.sina.weibo.sdk.utils.Utility; /** @@ -38,7 +28,7 @@ import com.sina.weibo.sdk.utils.Utility; *

* 微博分享 */ -public class WeiBoShareActivity extends Activity implements IWeiboHandler.Response { +public class WeiBoShareActivity extends Activity implements WbShareCallback { private String shareUrl; private String shareGameName; @@ -49,7 +39,7 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon private boolean ispopupWindow; private boolean isToolsBox; - private IWeiboShareAPI mWeiboShareAPI; + private WbShareHandler mWeiboShareAPI; @NonNull public static Intent getWeiboshareIntent(Context context, String shareNewsTitle, String shareIcon, @@ -83,7 +73,7 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon Utils.toast(this, "分享跳转中..."); - mWeiboShareAPI = WeiboShareSDK.createWeiboAPI(this, Config.WEIBO_APPKEY); + mWeiboShareAPI = new WbShareHandler(this); mWeiboShareAPI.registerApp(); weiboLoadBitMap(shareIcon); @@ -92,7 +82,7 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon protected void onNewIntent(Intent intent) { super.onNewIntent(intent); - mWeiboShareAPI.handleWeiboResponse(intent, this); //当前应用唤起微博分享后,返回当前应用 + mWeiboShareAPI.doResultIntent(intent, this); //当前应用唤起微博分享后,返回当前应用 } private void weiboLoadBitMap(String iconUrl) { @@ -135,36 +125,8 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon weiboMessage.textObject = textObject; weiboMessage.imageObject = imageObject; weiboMessage.mediaObject = webObject; - SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest(); - request.transaction = String.valueOf(System.currentTimeMillis()); - request.multiMessage = weiboMessage; - AuthInfo authInfo = new AuthInfo(WeiBoShareActivity.this, Config.WEIBO_APPKEY, "https://api.weibo.com/oauth2/default.html", ""); - Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(WeiBoShareActivity.this); - String token = ""; - if (accessToken != null) { - token = accessToken.getToken(); - } - - mWeiboShareAPI.sendRequest(WeiBoShareActivity.this, request, authInfo, token, new WeiboAuthListener() { - @Override - public void onComplete(Bundle bundle) { -// Oauth2AccessToken newToken = Oauth2AccessToken.parseAccessToken(bundle); -// AccessTokenKeeper.writeAccessToken(getApplicationContext(), newToken); -// Toast.makeText(getApplicationContext(), "onAuthorizeComplete token = " + newToken.getToken(), 0).show(); - } - - // 微博web端 - @Override - public void onWeiboException(WeiboException arg0) { - - } - - @Override - public void onCancel() { - - } - }); + mWeiboShareAPI.shareMessage(weiboMessage, false); } @Override @@ -175,18 +137,20 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon } @Override - public void onResponse(BaseResponse baseResponse) { - switch (baseResponse.errCode) { - case WBConstants.ErrorCode.ERR_OK: - Toast.makeText(this, "分享成功", Toast.LENGTH_SHORT).show(); - break; - case WBConstants.ErrorCode.ERR_CANCEL: - Toast.makeText(this, "分享取消", Toast.LENGTH_SHORT).show(); - break; - case WBConstants.ErrorCode.ERR_FAIL: - Toast.makeText(this, "分享失败", Toast.LENGTH_SHORT).show(); - break; - } + public void onWbShareSuccess() { + Toast.makeText(this, "分享成功", Toast.LENGTH_SHORT).show(); + finish(); + } + + @Override + public void onWbShareCancel() { + Toast.makeText(this, "分享取消", Toast.LENGTH_SHORT).show(); + finish(); + } + + @Override + public void onWbShareFail() { + Toast.makeText(this, "分享失败", Toast.LENGTH_SHORT).show(); finish(); } } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/InstallFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/InstallFragmentAdapter.java new file mode 100644 index 0000000000..4c126c4976 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/adapter/InstallFragmentAdapter.java @@ -0,0 +1,577 @@ +package com.gh.gamecenter.adapter; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.graphics.drawable.Drawable; +import android.support.v4.util.ArrayMap; +import android.support.v7.widget.RecyclerView.ViewHolder; +import android.text.TextUtils; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.gh.base.AppController; +import com.gh.common.constant.Config; +import com.gh.common.constant.ItemViewType; +import com.gh.common.util.ApkActiveUtils; +import com.gh.common.util.BitmapUtils; +import com.gh.common.util.DataCollectionUtils; +import com.gh.common.util.DataUtils; +import com.gh.common.util.DisplayUtils; +import com.gh.common.util.DownloadItemUtils; +import com.gh.common.util.GameViewUtils; +import com.gh.common.util.ImageUtils; +import com.gh.common.util.PackageUtils; +import com.gh.common.util.PlatformUtils; +import com.gh.common.util.TrafficUtils; +import com.gh.common.view.SwipeLayout; +import com.gh.download.DownloadManager; +import com.gh.gamecenter.ChooseReceiverActivity; +import com.gh.gamecenter.GameDetailActivity; +import com.gh.gamecenter.InstallActivity; +import com.gh.gamecenter.R; +import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; +import com.gh.gamecenter.adapter.viewholder.GameNormalSwipeViewHolder; +import com.gh.gamecenter.db.info.ConcernInfo; +import com.gh.gamecenter.entity.ApkEntity; +import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.entity.GameInfoEntity; +import com.gh.gamecenter.kuaichuan.FileInfo; +import com.gh.gamecenter.manager.ConcernManager; +import com.gh.gamecenter.manager.GameManager; +import com.gh.gamecenter.retrofit.Response; +import com.gh.gamecenter.retrofit.RetrofitManager; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import rx.Observable; +import rx.android.schedulers.AndroidSchedulers; +import rx.schedulers.Schedulers; + +/** + * Created by LGT on 2016/8/12. + * 已安装界面-数据适配器 + */ +public class InstallFragmentAdapter extends BaseRecyclerAdapter { + + private InstallActivity mActivity; + + private onSmoothLayoutListener smoothListener; + + private SharedPreferences sp; + + private ArrayList gameList; + private ArrayList sortedList; + + //下载用到的map + private ArrayMap> locationMap; + + private boolean isRemove; + + private boolean isSwipe; + + private boolean showUserNameHint; + + private boolean showKcHint; + + private int maxWidth; + + + public InstallFragmentAdapter(InstallActivity activity) { + super(activity); + this.mActivity = activity; + smoothListener = activity; + + gameList = new ArrayList<>(); + sortedList = new ArrayList<>(); + + locationMap = new ArrayMap<>(); + + isRemove = false; + isSwipe = false; + + sp = mContext.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); + showUserNameHint = sp.getBoolean("showUserNameHint", true); + showKcHint = sp.getBoolean("showKcHint", true); + + maxWidth = mContext.getResources().getDisplayMetrics().widthPixels; + + ConcernManager cManager = new ConcernManager(mContext); + List runnableGame = cManager.getInstalledGame(); + if (runnableGame.isEmpty()) { + mActivity.loadEmpty(); + } else { + AppController.MAIN_EXECUTOR.execute(new Runnable() { + @Override + public void run() { + init(); + List ids = new ArrayList<>(); + for (GameInfoEntity info : sortedList) { + if (!ids.contains(info.getId())) { + ids.add(info.getId()); + } + } + initGameList(ids); + } + }); + } + } + + //初始化 + private void init() { + + ArrayList list = new ArrayList<>(); + ArrayList signatureList = new ArrayList<>(); // 是我们签名的游戏 + ArrayList unsignatureList = new ArrayList<>(); // 不是我们签名的游戏 + ArrayList noopenList = new ArrayList<>(); // 未打开过的游戏 + ArrayList oftenuseList = new ArrayList<>(); // 已经打开过的游戏 + + TrafficUtils trafficUtils = TrafficUtils.getInstance(mContext); + + ConcernManager cManager = new ConcernManager(mContext); + List runnableGame = cManager.getInstalledGame(); + for (ConcernInfo concernEntity : runnableGame) { + for (Map.Entry entry : concernEntity.getPackageNames().entrySet()) { + if (entry.getValue()) { + GameInfoEntity info = new GameInfoEntity(); + info.setId(concernEntity.getId()); + info.setPackageName(entry.getKey()); + info.setTraffic(trafficUtils.getTraffice(entry.getKey())); + info.setSignature(PackageUtils.isSignature(mContext, entry.getKey())); + info.setInstallTime(PackageUtils.getInstalledTime(mContext, entry.getKey())); + list.add(info); + } + } + } + + ArrayMap> map = new ArrayMap<>(); + ArrayList mList; + for (int i = 0, size = list.size(); i < size; i++) { + mList = map.get(list.get(i).getPackageName()); + if (mList == null) { + mList = new ArrayList<>(); + map.put(list.get(i).getPackageName(), mList); + } + mList.add(list.get(i)); + } + Comparator comparator = new Comparator() { + @Override + public int compare(GameInfoEntity lhs, GameInfoEntity rhs) { + return rhs.getId().compareTo(lhs.getId()); + } + }; + Object gh_id; + for (String key : map.keySet()) { + mList = map.get(key); + if (mList.size() > 1) { + Collections.sort(mList, comparator); + } + if (mList.get(0).isSignature()) { + gh_id = PackageUtils.getMetaData(mContext, key, "gh_id"); + for (GameInfoEntity info : mList) { + if (gh_id == null || info.getId().equals(gh_id)) { + signatureList.add(info); + break; + } + } + } else { + unsignatureList.add(mList.get(0)); + } + } + + for (GameInfoEntity info : signatureList) { + if (info.getTraffic() == 0) { + noopenList.add(info); + } else { + oftenuseList.add(info); + } + } + + comparator = new Comparator() { + @Override + public int compare(GameInfoEntity lhs, GameInfoEntity rhs) { + if (rhs.getInstallTime() > lhs.getInstallTime()) { + return 1; + } else if (rhs.getInstallTime() < lhs.getInstallTime()) { + return -1; + } else { + return 0; + } + } + }; + Collections.sort(noopenList, comparator); + + comparator = new Comparator() { + @Override + public int compare(GameInfoEntity lhs, GameInfoEntity rhs) { + if (rhs.getTraffic() > lhs.getTraffic()) { + return 1; + } else if (rhs.getTraffic() < lhs.getTraffic()) { + return -1; + } else { + return 0; + } + } + }; + Collections.sort(oftenuseList, comparator); + + Collections.sort(unsignatureList, comparator); + + sortedList.addAll(noopenList); + sortedList.addAll(oftenuseList); + sortedList.addAll(unsignatureList); + } + + //获取游戏简介 + private void initGameList(List ids) { + final List result = new ArrayList<>(); + + List> sequences = new ArrayList<>(); + for (String id : ids) { + sequences.add(RetrofitManager.getApi().getGameDigest(id)); + } + Observable.merge(sequences) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onCompleted() { + processingData(result); + } + + @Override + public void onNext(GameEntity response) { + ApkActiveUtils.filterHideApk(response); + result.add(response); + } + }); + } + + private void processingData(List gameList) { + if (gameList.size() != 0) { + for (int i = 0, size = sortedList.size(); i < size; i++) { + String id = sortedList.get(i).getId(); + for (GameEntity entity : gameList) { + if (entity.getId().equals(id)) { + GameEntity newEntity = entity.clone(); + newEntity.setLibaoExists(entity.isLibaoExists()); + if (newEntity.getApk().size() > 1) { + for (ApkEntity apkEntity : newEntity.getApk()) { + if (sortedList.get(i).getPackageName().equals(apkEntity.getPackageName())) { + ArrayList list = new ArrayList<>(); + list.add(apkEntity); + newEntity.setApk(list); + break; + } + } + } + this.gameList.add(newEntity); + break; + } + } + } + GameManager manager = new GameManager(mContext); + for (GameEntity entity : this.gameList) { + entity.setEntryMap(DownloadManager.getInstance(mContext).getEntryMap(entity.getName())); + manager.addOrUpdate(entity.getApk(), entity.getId(), entity.getName()); + } + } + + if (this.gameList.size() != 0) { + ArrayMap> map = new ArrayMap<>(); + ArrayList list; + for (GameEntity gameEntity : this.gameList) { + list = map.get(gameEntity.getId()); + if (list == null) { + list = new ArrayList<>(); + map.put(gameEntity.getId(), list); + } + list.add(gameEntity); + } + list = new ArrayList<>(); + for (String key : map.keySet()) { + list.addAll(map.get(key)); + } + this.gameList = list; + isRemove = true; + notifyDataSetChanged(); + + initLocationMap(); + } + } + + private void initLocationMap() { + locationMap.clear(); + GameEntity gameEntity; + ArrayList list; + for (int i = 0; i < gameList.size(); i++) { + gameEntity = gameList.get(i); + if (gameEntity.getApk() != null && gameEntity.getApk().size() != 0) { + for (ApkEntity apkEntity : gameEntity.getApk()) { + list = locationMap.get(apkEntity.getPackageName()); + if (list == null) { + list = new ArrayList<>(); + locationMap.put(apkEntity.getPackageName(), list); + } + list.add(i); + } + } + } + } + + public ArrayList getGameList() { + return gameList; + } + + public ArrayMap> getLocationMap() { + return locationMap; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + switch (viewType) { + case ItemViewType.GAME_NORMAL: + return new GameNormalSwipeViewHolder( + mLayoutInflater.inflate(R.layout.game_normal_item_swipe, parent, false)); + case ItemViewType.LOADING: + return new FooterViewHolder( + mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false)); + case ItemViewType.KC_HINT: + return new KcHintViewHolder( + mLayoutInflater.inflate(R.layout.installfragment_footerview, parent, false)); + default: + break; + } + return null; + } + + @Override + public void onBindViewHolder(final ViewHolder holder, int position) { + if (holder instanceof GameNormalSwipeViewHolder) { + initGameNormal((GameNormalSwipeViewHolder) holder, gameList.get(position), position); + } else if (holder instanceof KcHintViewHolder) { + ((KcHintViewHolder) holder).mTextView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sp.edit().putBoolean("showKcHint", false).apply(); + smoothListener.onSmooth(); + ((KcHintViewHolder) holder).mTextView.postDelayed(new Runnable() { + @Override + public void run() { + showKcHint = false; + notifyDataSetChanged(); + } + }, 500); + } + }); + } + } + + @Override + public int getItemViewType(int position) { + if (gameList.size() != 0 && position >= 0 && position < gameList.size()) { + return ItemViewType.GAME_NORMAL; + } + + if (isRemove && !showUserNameHint && showKcHint) { + return ItemViewType.KC_HINT; + } + + return ItemViewType.LOADING; + } + + @Override + public int getItemCount() { + if (gameList.isEmpty() && !isRemove) { + return 1; + } + if (isRemove && !showUserNameHint && showKcHint) { + return gameList.size() + 1; + } + if (isRemove) { + return gameList.size(); + } + return gameList.size() + 1; + } + + private void initGameNormal(final GameNormalSwipeViewHolder holder, final GameEntity gameEntity, final int i) { + + holder.swipeText.setPadding(0, 0, DisplayUtils.dip2px(mContext, 15), 0); + + ImageUtils.display(holder.gameThumb, gameEntity.getIcon()); + + if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty() + || gameEntity.getTag() == null || gameEntity.getTag().isEmpty()) { + if (gameEntity.getApk() != null && gameEntity.getApk().size() > 0 + && !TextUtils.isEmpty(gameEntity.getApk().get(0).getVersion())) { + holder.gameDes.setText(String.format("V%s", gameEntity.getApk().get(0).getVersion())); + } else { + holder.gameDes.setText(gameEntity.getBrief()); + } + holder.gameName.setText(gameEntity.getName()); + } else { + holder.gameName.setText(String.format("%s - %s", gameEntity.getName(), + PlatformUtils.getInstance(mContext).getPlatformName(gameEntity.getApk().get(0).getPlatform()))); + holder.gameDes.setText(String.format("V%s", gameEntity.getApk().get(0).getVersion())); + } + GameViewUtils.setLabelList(mContext, holder.gameLabelList, gameEntity.getTag(), ""); + + holder.cardView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (!isSwipe) { + Map kv = new HashMap<>(); + kv.put("名字", gameEntity.getName()); + kv.put("位置", String.valueOf(holder.getPosition() + 1)); + DataUtils.onEvent(mContext, "点击", "我的光环-已安装", kv); + + DataCollectionUtils.uploadClick(mContext, "列表", "我的光环-已安装", gameEntity.getName()); + + GameDetailActivity.startGameDetailActivity(mContext, gameEntity.getId(), "(我的光环-已安装)"); + } + } + }); + + + int paddRight = 0; + String serverType = gameEntity.getServerType(); + if (TextUtils.isEmpty(serverType)) { + holder.gameServerType.setVisibility(View.GONE); + } else { + holder.gameServerType.setVisibility(View.VISIBLE); + holder.gameServerType.setText(serverType); + if ("删档内测".equals(serverType) || "不删档内测".equals(serverType)) { + holder.gameServerType.setBackgroundResource(R.drawable.textview_server_tag); + if ("删档内测".equals(serverType)) { + paddRight = DisplayUtils.dip2px(mContext, 50); + } else { + paddRight = DisplayUtils.dip2px(mContext, 60); + } + } else { + holder.gameServerType.setBackgroundResource(R.drawable.textview_orange_up); + paddRight = DisplayUtils.dip2px(mContext, 30); + } + } + holder.gameName.setPadding(0, 0, paddRight, 0); + + DownloadItemUtils.setOnClickListener(mContext, holder.gameDownloadBtn, gameEntity, i, + this, "(我的光环-已安装)", "我的光环-已安装" + ":" + gameEntity.getName()); + + DownloadItemUtils.updateItem(mContext, gameEntity, holder, false); + + holder.swipeLayout.close(); + holder.swipeShareText.setPadding((maxWidth / 12), 0, 0, 0); + holder.swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { + @Override + public void onStartOpen(SwipeLayout layout) { + isSwipe = true; + + } + + @Override + public void onOpen(SwipeLayout layout) { + skipKc(i); + holder.swipeLayout.close(); +// holder.swipeLayout.postDelayed(new Runnable() { +// @Override +// public void run() { +// notifyItemRangeChanged(0 ,getItemCount()); +// } +// }, 500); + } + + @Override + public void onStartClose(SwipeLayout layout) { + } + + @Override + public void onClose(SwipeLayout layout) { + isSwipe = false; +// holder.swipeText.setPadding(0, 0, DisplayUtils.dip2px(mContext, 15), 0); + holder.swipeText.setText("右划发给好友\n免流量安装"); + } + + @Override + public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) { + if (leftOffset > maxWidth / 2.7 && leftOffset < maxWidth / 2.5) { +// holder.swipeText.setPadding(0, 0, DisplayUtils.dip2px(mContext, 30), 0); + holder.swipeText.setVisibility(View.GONE); + holder.swipeShareText.setVisibility(View.VISIBLE); + } else if (leftOffset > maxWidth / 2.5) { + holder.swipeText.setVisibility(View.GONE); + holder.swipeShareText.setVisibility(View.VISIBLE); + holder.swipeShareText.setText("放手发给好友\n免流量安装"); + } else if (leftOffset < maxWidth / 2.7) { +// holder.swipeText.setPadding(0, 0, DisplayUtils.dip2px(mContext, 15), 0); + holder.swipeText.setVisibility(View.VISIBLE); + holder.swipeShareText.setVisibility(View.GONE); + holder.swipeShareText.setText("右划发给好友\n免流量安装"); + } + } + + @Override + public void onHandRelease(SwipeLayout layout, float xvel, float yvel) { + } + }); + } + + //跳转到快传 - 搜索接收者页面 + public void skipKc(int i) { + GameEntity gameEntity = gameList.get(i); + String packageName = gameEntity.getApk().get(0).getPackageName(); + PackageManager pm = mContext.getPackageManager(); + FileInfo fileInfo = new FileInfo(); + List installedPackages = pm.getInstalledPackages(0); + for (PackageInfo installedPackage : installedPackages) { + if ((installedPackage.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 + && installedPackage.packageName.equals(packageName)) { + fileInfo.setFilePath(installedPackage.applicationInfo.sourceDir); + File file = new File(installedPackage.applicationInfo.sourceDir); + fileInfo.setSize(file.length()); + Drawable drawable = installedPackage.applicationInfo.loadIcon(pm); + fileInfo.setBitmap(BitmapUtils.drawableToBitmap(drawable)); + fileInfo.setFileTag(String.valueOf(System.currentTimeMillis())); + } + } + if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty() + || gameEntity.getTag() == null || gameEntity.getTag().isEmpty()) { + fileInfo.setName(gameEntity.getName()); + } else { + fileInfo.setName(String.format("%s - %s", gameEntity.getName(), + PlatformUtils.getInstance(mContext).getPlatformName(gameEntity.getApk().get(0).getPlatform()))); + } + fileInfo.setPackageName(packageName); + List fileInfos = new ArrayList<>(); + fileInfos.add(fileInfo); + + AppController.put(AppController.KEY_FILE_INFO, fileInfos); + Intent intent = new Intent(mContext, ChooseReceiverActivity.class); + intent.putExtra("showConnHintDialog", true); + mActivity.startActivityForResult(intent, 0x170); + + } + + public interface onSmoothLayoutListener { + void onSmooth(); + } + + public class KcHintViewHolder extends ViewHolder { + TextView mTextView; + + public KcHintViewHolder(View itemView) { + super(itemView); + mTextView = (TextView) itemView.findViewById(R.id.kuaichuan_hint); + } + } + +} diff --git a/app/src/main/java/com/gh/gamecenter/personal/InstallFragment.java b/app/src/main/java/com/gh/gamecenter/personal/InstallFragment.java index d09511e27f..988a3b72b8 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/InstallFragment.java +++ b/app/src/main/java/com/gh/gamecenter/personal/InstallFragment.java @@ -122,7 +122,7 @@ public class InstallFragment extends BaseFragment implements InstallFragmentAdap public void loadEmpty() { fm_install_rv_show.setVisibility(View.GONE); reuse_nodata_skip.setVisibility(View.VISIBLE); - EventBus.getDefault().post(new EBReuse(PersonalFragment.NO_INSTALL_HINT)); +// EventBus.getDefault().post(new EBReuse(PersonalFragment.NO_INSTALL_HINT)); } // 打开下载按钮事件 diff --git a/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java b/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java index e9e3970dae..1b4ccce009 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java +++ b/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java @@ -1,220 +1,114 @@ package com.gh.gamecenter.personal; -import android.app.Dialog; -import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; -import android.database.Cursor; -import android.net.Uri; -import android.os.Build; import android.os.Bundle; -import android.provider.MediaStore; import android.support.annotation.Nullable; -import android.support.v4.app.FragmentTransaction; -import android.text.TextUtils; -import android.util.DisplayMetrics; -import android.view.KeyEvent; import android.view.View; -import android.view.Window; -import android.view.inputmethod.EditorInfo; -import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; -import android.widget.Toast; import com.facebook.drawee.view.SimpleDraweeView; import com.gh.base.BaseFragment; -import com.gh.common.constant.Config; import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; -import com.gh.common.util.DialogUtils; -import com.gh.common.util.DisplayUtils; import com.gh.common.util.EntranceUtils; -import com.gh.common.util.ImageUtils; -import com.gh.common.util.TokenUtils; -import com.gh.common.util.Util_System_Keyboard; -import com.gh.common.util.Utils; +import com.gh.common.util.LoginUtils; +import com.gh.gamecenter.InstallActivity; import com.gh.gamecenter.LibaoActivity; import com.gh.gamecenter.R; -import com.gh.gamecenter.SelectUserIconActivity; import com.gh.gamecenter.SettingActivity; import com.gh.gamecenter.ShareGhActivity; import com.gh.gamecenter.SuggestSelectActivity; import com.gh.gamecenter.eventbus.EBNetworkState; -import com.gh.gamecenter.eventbus.EBReuse; -import com.gh.gamecenter.retrofit.Response; -import com.gh.gamecenter.retrofit.RetrofitManager; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.json.JSONObject; - -import java.util.HashMap; -import java.util.Map; import butterknife.BindView; import butterknife.OnClick; -import okhttp3.MediaType; -import okhttp3.RequestBody; -import okhttp3.ResponseBody; -import retrofit2.HttpException; -import rx.Observable; -import rx.android.schedulers.AndroidSchedulers; -import rx.functions.Func1; -import rx.schedulers.Schedulers; /** * @author 温冠超 * 294299195@qq.com * 2015-8-8 我的光环页面 */ -public class PersonalFragment extends BaseFragment implements View.OnClickListener { +public class PersonalFragment extends BaseFragment { - public final static String NO_INSTALL_HINT = "noInstallHint"; - @BindView(R.id.me_iv_top_icon) - SimpleDraweeView me_iv_top_icon; - @BindView(R.id.me_tv_top_name) - TextView me_tv_top_name; + + @BindView(R.id.personal_login_qq) + LinearLayout mLoginQq; + @BindView(R.id.personal_login_wechat) + LinearLayout mLoginWechat; + @BindView(R.id.personal_login_weibo) + LinearLayout mLoginWeibo; + @BindView(R.id.personal_user_icon) + SimpleDraweeView mUserIcon; @BindView(R.id.user_name_hint) - ImageView userNameHint; - @BindView(R.id.personal_entrance_libao) - LinearLayout entranceLibao; - @BindView(R.id.personal_entrance_setting) - LinearLayout entranceSetting; - @BindView(R.id.personal_entrance_share) - LinearLayout entranceShare; - @BindView(R.id.personal_entrance_suggest) - LinearLayout entranceSuggest; - @BindView(R.id.me_ll_info) - RelativeLayout infoLl; - @BindView(R.id.personal_share_hint) - TextView shareHint; - private boolean isLogin; - private SharedPreferences sp; + ImageView mUserNameHint; + @BindView(R.id.personal_user_name) + TextView mUserName; + @BindView(R.id.login_qq_icon) + ImageView mLoginQqIcon; + @BindView(R.id.login_qq_tv) + TextView mLoginQqTv; + @BindView(R.id.login_wechat_icon) + ImageView mLoginWechatIcon; + @BindView(R.id.login_wechat_tv) + TextView mLoginWechatTv; + @BindView(R.id.login_weibo_icon) + ImageView mLoginWeiboIcon; + @BindView(R.id.login_weibo_tv) + TextView mLoginWeiboTv; + @BindView(R.id.personal_game) + RelativeLayout mPersonalGame; + @BindView(R.id.personal_libao) + RelativeLayout mPersonalLibao; + @BindView(R.id.personal_share) + RelativeLayout mPersonalShare; + @BindView(R.id.personal_suggestion) + RelativeLayout mPersonalSuggestion; + @BindView(R.id.personal_setting_update_hint) + TextView mPersonalSettingUpdateHint; + @BindView(R.id.personal_setting) + RelativeLayout mPersonalSetting; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - init(R.layout.fragment_personal); - - sp = getActivity().getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); - - me_iv_top_icon.setOnClickListener(this); - me_tv_top_name.setOnClickListener(this); - userNameHint.setOnClickListener(this); - - userNameHint = (ImageView) view.findViewById(R.id.user_name_hint); - - if (sp.getBoolean("showUserNameHint", true)) { - userNameHint.setVisibility(View.VISIBLE); - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - - RelativeLayout me_ll_info = (RelativeLayout) view.findViewById(R.id.me_ll_info); - me_ll_info.setPadding(0, DisplayUtils.getStatusBarHeight(getResources()), 0, 0); - } - - DisplayMetrics outMetrics = new DisplayMetrics(); - getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); - - isLogin = false; - - login(null); - - FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); - InstallFragment fragment = new InstallFragment(); - transaction.add(R.id.personal_install_fl, fragment); - transaction.commit(); } - public void login(final Dialog dialog) { - TokenUtils.getToken(getActivity(), true) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(String token) { - if (getActivity() != null) { - TokenUtils.checkDeviceInfo(getActivity(), token); - - SharedPreferences sp = getActivity().getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); - String name = sp.getString("user_name", null); - if (!TextUtils.isEmpty(name)) { - me_tv_top_name.setText(name); - checkUserName(name); - } - String icon = sp.getString("user_icon", null); - if (!TextUtils.isEmpty(icon)) { - ImageUtils.display(me_iv_top_icon, icon); - } - isLogin = true; - } - if (dialog != null) { - Toast.makeText(getActivity(), "登录成功", Toast.LENGTH_SHORT).show(); - dialog.dismiss(); - } - } - - @Override - public void onFailure(HttpException e) { - if (dialog != null) { - Toast.makeText(getActivity(), "登录失败", Toast.LENGTH_SHORT).show(); - dialog.dismiss(); - } - } - }); - } - - private void checkUserName(String name) { - if (sp.getBoolean("showUserNameHint", true) && - (!name.startsWith("光环用户") || name.length() != 10)) { - sp.edit().putBoolean("showUserNameHint", false).apply(); - userNameHint.setVisibility(View.GONE); - } - } // 连接上网络事件 @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(EBNetworkState busNetworkState) { - if (busNetworkState.isNetworkConnected() && !isLogin) { - login(null); - } } - // 安装列表为空,隐藏分享提示 - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(EBReuse reuse) { - if (NO_INSTALL_HINT.equals(reuse.getType())) { - shareHint.setVisibility(View.GONE); - } - } - - @OnClick({R.id.personal_entrance_suggest, R.id.personal_entrance_share, R.id.personal_entrance_setting - , R.id.personal_entrance_libao}) - public void onEntranceClick(View v) { - switch (v.getId()) { - case R.id.personal_entrance_suggest: - Intent intent1 = new Intent(getActivity(), SuggestSelectActivity.class); - getActivity().startActivity(intent1); + @OnClick({R.id.personal_login_qq, R.id.personal_login_wechat, R.id.personal_login_weibo, R.id.personal_user_icon, + R.id.personal_user_name, R.id.personal_game, R.id.personal_libao, R.id.personal_share, R.id.personal_suggestion, + R.id.personal_setting}) + public void onViewClicked(View view) { + switch (view.getId()) { + case R.id.personal_login_qq: + LoginUtils.getInstance(getActivity()).QQLogin(); break; - case R.id.personal_entrance_share: - Intent intent2 = new Intent(getActivity(), ShareGhActivity.class); - getActivity().startActivity(intent2); + case R.id.personal_login_wechat: + LoginUtils.getInstance(getActivity()).WCLogin(); break; - case R.id.personal_entrance_setting: - DataUtils.onEvent(getActivity(), "我的光环", "设置图标"); - DataCollectionUtils.uploadClick(getActivity(), "设置图标", "我的光环"); - - Intent intent3 = new Intent(getActivity(), SettingActivity.class); - intent3.putExtra(EntranceUtils.KEY_ENTRANCE, "(我的光环)"); - startActivity(intent3); + case R.id.personal_login_weibo: + LoginUtils.getInstance(getActivity()).WeiBoLogin(); break; - case R.id.personal_entrance_libao: + case R.id.personal_user_icon: + break; + case R.id.personal_user_name: + break; + case R.id.personal_game: + Intent intent0 = new Intent(getContext(), InstallActivity.class); + getContext().startActivity(intent0); + break; + case R.id.personal_libao: DataUtils.onEvent(getActivity(), "主页", "礼包图标"); DataCollectionUtils.uploadClick(getActivity(), "礼包图标", "我的光环"); Intent intent = new Intent(getActivity(), LibaoActivity.class); @@ -223,213 +117,23 @@ public class PersonalFragment extends BaseFragment implements View.OnClickListen DataCollectionUtils.uploadPosition(getActivity(), "我的光环", "1", "礼包"); break; + case R.id.personal_share: + Intent intent2 = new Intent(getActivity(), ShareGhActivity.class); + getActivity().startActivity(intent2); + break; + case R.id.personal_suggestion: + Intent intent1 = new Intent(getActivity(), SuggestSelectActivity.class); + getActivity().startActivity(intent1); + break; + case R.id.personal_setting: + DataUtils.onEvent(getActivity(), "我的光环", "设置图标"); + DataCollectionUtils.uploadClick(getActivity(), "设置图标", "我的光环"); + + Intent intent3 = new Intent(getActivity(), SettingActivity.class); + intent3.putExtra(EntranceUtils.KEY_ENTRANCE, "(我的光环)"); + startActivity(intent3); + break; } } - @Override - public void onClick(View v) { - final int id = v.getId(); - if (id == R.id.me_tv_top_name) { - DataUtils.onEvent(getActivity(), "我的光环", "用户昵称"); - DataCollectionUtils.uploadClick(getActivity(), "用户昵称", "我的光环"); - - if (isLogin) { - showModifyNicknameDialog(me_tv_top_name.getText().toString()); - } else { - login(DialogUtils.showWaitDialog(getActivity(), "登录中...")); - } - } else if (id == R.id.me_iv_top_icon) { - DataUtils.onEvent(getActivity(), "我的光环", "用户头像"); - DataCollectionUtils.uploadClick(getActivity(), "用户头像", "我的光环"); - - if (isLogin) { - Intent intent = new Intent(getContext(), SelectUserIconActivity.class); - startActivityForResult(intent, 0x125); - } else { - login(DialogUtils.showWaitDialog(getActivity(), "登录中...")); - } - } else if (id == R.id.user_name_hint) { - DataUtils.onEvent(getActivity(), "我的光环", "用户昵称"); - DataCollectionUtils.uploadClick(getActivity(), "用户昵称", "我的光环"); - - if (isLogin) { - showModifyNicknameDialog(me_tv_top_name.getText().toString()); - } else { - login(DialogUtils.showWaitDialog(getActivity(), "登录中...")); - } - } - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (data != null && requestCode == 0x123) { - Uri selectedImage = data.getData(); - if (selectedImage == null) { - return; - } - String[] filePathColumn = {MediaStore.Images.Media.DATA}; - - Cursor cursor = getActivity().getContentResolver().query(selectedImage, filePathColumn, null, null, null); - if (cursor == null) { - return; - } - cursor.moveToFirst(); - - int columnIndex = cursor.getColumnIndex(filePathColumn[0]); - String picturePath = cursor.getString(columnIndex); - cursor.close(); - - Utils.log("picturePath = " + picturePath); - // 上传头像 -// Intent intent = new Intent(getActivity(), CropImageActivity.class); -// intent.putExtra("path", picturePath); -// intent.putExtra("mEntrance", "(我的光环)"); -// startActivityForResult(intent, 0x124); - } else if (data != null && requestCode == 0x125) { - String url = data.getExtras().getString("url"); - sp.edit().putString("user_icon", url).apply(); -// me_iv_top_icon.setImageURI(url); - ImageUtils.display(me_iv_top_icon, url); - } - } - - private void showModifyNicknameDialog(String name) { - final Dialog dialog = new Dialog(getActivity()); - - View view = View.inflate(getActivity(), R.layout.dialog_modify_nickname, null); - - final EditText input = (EditText) view.findViewById(R.id.dialog_nickname_input); - input.setText(name); - input.setSelection(input.getText().length()); - - input.setOnEditorActionListener(new TextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - if (actionId == EditorInfo.IME_ACTION_DONE) { - String nickname = input.getText().toString().trim(); - if (TextUtils.isEmpty(nickname)) { - Toast.makeText(getActivity(), "请输入昵称", Toast.LENGTH_SHORT).show(); - return true; - } - modifyNickname(nickname); - dialog.dismiss(); - return true; - } - return false; - } - }); - - // 取消按钮 - TextView cancel = (TextView) view.findViewById(R.id.dialog_nickname_cancel); - cancel.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - dialog.dismiss(); - } - }); - - // 确定按钮 - TextView confirm = (TextView) view.findViewById(R.id.dialog_nickname_confirm); - confirm.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (userNameHint.getVisibility() == View.VISIBLE) { - userNameHint.setVisibility(View.GONE); - sp.edit().putBoolean("showUserNameHint", false).apply(); - } - - String nickname = input.getText().toString().trim(); - if (TextUtils.isEmpty(nickname)) { - Toast.makeText(getActivity(), "请输入昵称", Toast.LENGTH_SHORT).show(); - return; - } - dialog.dismiss(); - modifyNickname(nickname); - } - }); - - dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - Util_System_Keyboard.hideSoftKeyboard(getActivity()); - } - }); - - dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - dialog.setContentView(view); - dialog.show(); - - input.postDelayed(new Runnable() { - @Override - public void run() { - Util_System_Keyboard.showSoftKeyboard(getContext(), input); - } - }, 300); - } - - private void modifyNickname(String nickname) { - final Dialog waitDialog = DialogUtils.showWaitDialog(getActivity(), "修改中..."); - modifyNickname(waitDialog, nickname, true); - } - - private void modifyNickname(final Dialog waitDialog, final String nickname, final boolean isCheck) { - TokenUtils.getToken(getActivity(), isCheck) - .flatMap(new Func1>() { - @Override - public Observable call(String token) { - Map params = new HashMap<>(); - params.put("name", nickname); - RequestBody body = RequestBody.create(MediaType.parse("application/json"), - new JSONObject(params).toString()); - return RetrofitManager.getUser().postName(token, body); - } - }) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(ResponseBody response) { - waitDialog.dismiss(); - - SharedPreferences sp = getActivity().getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); - sp.edit().putString("user_name", nickname).apply(); - Toast.makeText(getActivity(), "修改成功", Toast.LENGTH_SHORT).show(); - me_tv_top_name.setText(nickname); - } - - @Override - public void onFailure(HttpException e) { - if (e != null) { - if (e.code() == 401) { - modifyNickname(waitDialog, nickname, false); - return; - } - if (e.code() == 403) { - try { - JSONObject response = new JSONObject(new String(e.response().errorBody().bytes())); - String detail = response.getString("detail"); - if ("too long".equals(detail)) { - Toast.makeText(getActivity(), "昵称太长", Toast.LENGTH_SHORT).show(); - } else if ("invalid".equals(detail)) { - Toast.makeText(getActivity(), "非法字符", Toast.LENGTH_SHORT).show(); - } else if ("repeat".equals(detail)) { - Toast.makeText(getActivity(), "昵称已存在", Toast.LENGTH_SHORT).show(); - } else if ("no change".equals(detail)) { - Toast.makeText(getActivity(), "昵称一致", Toast.LENGTH_SHORT).show(); - } else if ("too frequent".equals(detail)) { - Toast.makeText(getActivity(), "每天最多修改2次昵称", Toast.LENGTH_SHORT).show(); - } - } catch (Exception ex) { - ex.printStackTrace(); - Toast.makeText(getActivity(), "修改失败", Toast.LENGTH_SHORT).show(); - } - } - } - Toast.makeText(getActivity(), "修改失败", Toast.LENGTH_SHORT).show(); - waitDialog.dismiss(); - } - }); - } - } diff --git a/app/src/main/res/drawable-hdpi/personal_answer_icon.png b/app/src/main/res/drawable-hdpi/personal_answer_icon.png new file mode 100644 index 0000000000..23dcaa8417 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_answer_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/personal_collection_icon.png b/app/src/main/res/drawable-hdpi/personal_collection_icon.png new file mode 100644 index 0000000000..1d530a27c7 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_collection_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/personal_drafts_icon.png b/app/src/main/res/drawable-hdpi/personal_drafts_icon.png new file mode 100644 index 0000000000..078752a58f Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_drafts_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/personal_game_icon.png b/app/src/main/res/drawable-hdpi/personal_game_icon.png new file mode 100644 index 0000000000..1c3fff9c1d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_game_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/personal_libao_icon.png b/app/src/main/res/drawable-hdpi/personal_libao_icon.png new file mode 100644 index 0000000000..f271100f67 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_libao_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/personal_message_icon.png b/app/src/main/res/drawable-hdpi/personal_message_icon.png new file mode 100644 index 0000000000..1e4252af0f Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_message_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/personal_question_icon.png b/app/src/main/res/drawable-hdpi/personal_question_icon.png new file mode 100644 index 0000000000..e00f1d3191 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_question_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/personal_setting_icon.png b/app/src/main/res/drawable-hdpi/personal_setting_icon.png new file mode 100644 index 0000000000..9533d5d081 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_setting_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/personal_share_icon.png b/app/src/main/res/drawable-hdpi/personal_share_icon.png new file mode 100644 index 0000000000..60f5796239 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_share_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/personal_sign_icon.png b/app/src/main/res/drawable-hdpi/personal_sign_icon.png new file mode 100644 index 0000000000..9fa99dfec9 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_sign_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/personal_suggestion_icon.png b/app/src/main/res/drawable-hdpi/personal_suggestion_icon.png new file mode 100644 index 0000000000..b7fc28be8d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/personal_suggestion_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/qq_login_icon.png b/app/src/main/res/drawable-hdpi/qq_login_icon.png new file mode 100644 index 0000000000..912058c532 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/qq_login_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/wechat_login_icon.png b/app/src/main/res/drawable-hdpi/wechat_login_icon.png new file mode 100644 index 0000000000..becef15867 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/wechat_login_icon.png differ diff --git a/app/src/main/res/drawable-hdpi/weibo_login_icon.png b/app/src/main/res/drawable-hdpi/weibo_login_icon.png new file mode 100644 index 0000000000..a6a4c55e2b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/weibo_login_icon.png differ diff --git a/app/src/main/res/layout/activity_install.xml b/app/src/main/res/layout/activity_install.xml new file mode 100644 index 0000000000..1ebeb51357 --- /dev/null +++ b/app/src/main/res/layout/activity_install.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_personal.xml b/app/src/main/res/layout/fragment_personal.xml index 80bec5853a..ae4bcc809e 100644 --- a/app/src/main/res/layout/fragment_personal.xml +++ b/app/src/main/res/layout/fragment_personal.xml @@ -3,18 +3,18 @@ xmlns:fresco = "http://schemas.android.com/apk/res-auto" android:layout_width = "match_parent" android:layout_height = "match_parent" + android:background = "@android:color/white" android:orientation = "vertical" > - + android:layout_height = "match_parent" + android:scrollbars="none"> - + android:orientation = "vertical" > @@ -34,178 +34,442 @@ android:id = "@+id/user_name_hint" android:layout_width = "wrap_content" android:layout_height = "wrap_content" - android:layout_above = "@+id/me_tv_top_name" + android:layout_above = "@+id/personal_user_name" android:layout_marginBottom = "-13dp" android:layout_marginLeft = "2dp" - android:layout_toRightOf = "@+id/me_iv_top_icon" + android:layout_toRightOf = "@+id/personal_user_icon" android:src = "@drawable/user_name_hint" android:visibility = "gone" /> - + android:textColor = "@android:color/black" + android:textSize = "15sp" /> + android:layout_height = "wrap_content" + android:layout_marginTop = "55dp" + android:layout_marginBottom="15dp"> - + + + + - + android:layout_marginTop = "14dp" + android:text = "QQ" + android:textColor = "@color/title" /> - + + + + + + - + android:layout_marginTop = "14dp" + android:text = "微信" + android:textColor = "@color/title" /> - + + + + + + + - - - - - - - - - + android:layout_marginTop = "14dp" + android:text = "新浪微博" + android:textColor = "@color/title" /> - - - + - + - + - + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ca5c692d11..ecaba96a87 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -27,7 +27,7 @@ #00B7FA - @color/text_3a3a3a + @color/text_5d5d5d @color/text_9a9a9a @@ -83,5 +83,6 @@ #b2b2b2 #9a9a9a #3a3a3a + #5d5d5d \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cd3f16ff6f..cf5e901803 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,12 +32,16 @@ 推荐关注 关注 分享 - 礼包 + 礼包中心 反馈 设置 我的游戏 (右划免流量分享给好友) 光环用户 + 我的问题 + 我的回答 + 我的草稿 + 新版本 请输入搜索关键字 搜索 44.5% diff --git a/app/src/main/res/values/styles_themes.xml b/app/src/main/res/values/styles_themes.xml index 00ef25bd9e..fd31cc7756 100644 --- a/app/src/main/res/values/styles_themes.xml +++ b/app/src/main/res/values/styles_themes.xml @@ -60,8 +60,8 @@ true - @color/theme - @color/theme + + diff --git a/build.gradle b/build.gradle index 1bfb361c8a..8de45112f6 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,8 @@ apply from: 'dependencies.gradle' buildscript { repositories { jcenter() + + maven { url "https://dl.bintray.com/thelasterstar/maven/" } //weiboSDK } dependencies { classpath 'com.android.tools.build:gradle:2.3.1' @@ -18,6 +20,13 @@ buildscript { } } +allprojects { + repositories { + jcenter() + maven { url "https://dl.bintray.com/thelasterstar/maven/" }//weiboSDK + } +} + subprojects { subproject -> afterEvaluate { diff --git a/dependencies.gradle b/dependencies.gradle index 5697bf9995..72b24c7432 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -53,6 +53,7 @@ ext { swipeLayout = "1.2.0@aar" autoScrollViewPager = "1.1.2" circleImageView = "2.1.0" + weiboSDK = "2.0.3" onesignal = "2.3.0@aar" google_play_services = "8.4.0" @@ -120,6 +121,7 @@ ext { tinker_anno : "com.tencent.tinker:tinker-android-anno:${tinker}", tinker_lib : "com.tencent.tinker:tinker-android-lib:${tinker}", apkChannelPackage : "com.leon.channel:helper:${apkChannelPackage}", + weiboSDK : "com.sina.weibo.sdk:core:${weiboSDK}:openDefaultRelease@aar", ]