diff --git a/app/src/main/java/com/gh/base/fragment/BaseFragment.java b/app/src/main/java/com/gh/base/fragment/BaseFragment.java index 3be0fb3e50..867ce5ed87 100644 --- a/app/src/main/java/com/gh/base/fragment/BaseFragment.java +++ b/app/src/main/java/com/gh/base/fragment/BaseFragment.java @@ -9,14 +9,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import androidx.annotation.LayoutRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentTransaction; -import androidx.recyclerview.widget.RecyclerView; - import com.gh.base.OnListClickListener; import com.gh.base.OnRequestCallBackListener; import com.gh.common.constant.Constants; @@ -37,6 +29,13 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; +import androidx.annotation.LayoutRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentTransaction; +import androidx.recyclerview.widget.RecyclerView; import butterknife.ButterKnife; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -145,7 +144,10 @@ public abstract class BaseFragment extends Fragment implements OnRequestCallB } else { mCachedView = View.inflate(getContext(), getLayoutId(), null); } - ButterKnife.bind(this, mCachedView); + + if (useButterKnife()) { + ButterKnife.bind(this, mCachedView); + } initView(mCachedView); @@ -309,4 +311,8 @@ public abstract class BaseFragment extends Fragment implements OnRequestCallB protected boolean addSyncPageObserver() { return false; } + + protected boolean useButterKnife() { + return true; + } } diff --git a/app/src/main/java/com/gh/common/util/PackageUtils.java b/app/src/main/java/com/gh/common/util/PackageUtils.java index 55b04a0973..511724c547 100644 --- a/app/src/main/java/com/gh/common/util/PackageUtils.java +++ b/app/src/main/java/com/gh/common/util/PackageUtils.java @@ -14,8 +14,6 @@ import android.os.Build; import android.os.Bundle; import android.text.TextUtils; -import androidx.core.content.FileProvider; - import com.g00fy2.versioncompare.Version; import com.gh.common.constant.Constants; import com.gh.gamecenter.BuildConfig; @@ -38,7 +36,8 @@ import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; +import androidx.annotation.Nullable; +import androidx.core.content.FileProvider; public class PackageUtils { 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 bec64fadeb..f94d7638a1 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java +++ b/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java @@ -2,29 +2,18 @@ package com.gh.gamecenter.personal; import android.annotation.SuppressLint; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; -import android.preference.PreferenceManager; import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; +import android.view.ViewStub; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; -import androidx.core.content.ContextCompat; -import androidx.lifecycle.Observer; -import androidx.lifecycle.ViewModelProviders; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - import com.facebook.drawee.view.SimpleDraweeView; -import com.gh.base.fragment.BaseFragment; +import com.gh.base.fragment.BaseLazyFragment; import com.gh.common.databind.BindingAdapters; import com.gh.common.notifier.Notifier; import com.gh.common.util.CheckLoginUtils; @@ -86,7 +75,16 @@ import java.util.ArrayList; import java.util.Locale; import java.util.concurrent.TimeUnit; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProviders; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import butterknife.BindView; +import butterknife.ButterKnife; import butterknife.OnClick; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; @@ -97,7 +95,8 @@ import retrofit2.HttpException; import static com.gh.gamecenter.fragment.MainWrapperFragment.INDEX_PERSONAL; -public class PersonalFragment extends BaseFragment implements Observer> { +// TODO 转成 kotlin,处理红点相关逻辑,优化列表刷新方式 +public class PersonalFragment extends BaseLazyFragment implements Observer> { @BindView(R.id.list_refresh) SwipeRefreshLayout mListRefresh; @@ -138,13 +137,12 @@ public class PersonalFragment extends BaseFragment implements Observer { + int absOffset = Math.abs(verticalOffset); + int invisibleOffset = DisplayUtils.dip2px(40F); + if (absOffset <= invisibleOffset) { + mUserIconSmall.setVisibility(View.GONE); + mPersonalUserNameSmall.setVisibility(View.GONE); + } else { + mUserIconSmall.setVisibility(View.VISIBLE); + mPersonalUserNameSmall.setVisibility(View.VISIBLE); + } + mListRefresh.setEnabled(absOffset <= 2); + }); + mListRefresh.setColorSchemeColors(ContextCompat.getColor(requireContext(), R.color.theme)); + mListRefresh.setProgressViewOffset(false, 0, DisplayUtils.dip2px(80) + DisplayUtils.getStatusBarHeight(requireContext().getResources())); + mListRefresh.setOnRefreshListener(() -> { + mPersonalViewModel.getHaloAddons(); + if (CheckLoginUtils.isLogin()) { + mUnreadViewModel.retry(); + MessageUnreadRepository.INSTANCE.loadMessageUnreadTotal(); + mUserHomeViewModel.getBadgeList(); + mUserHomeViewModel.availableBadges(); + } + mBaseHandler.postDelayed(() -> { + mListRefresh.setRefreshing(false); + }, 2000); + MtaHelper.onEvent("我的光环_新", "下拉刷新", "下拉刷新"); + }); + } + + private void observeChanges() { mUserViewModel.getLoginObsUserinfo().observe(this, this); - mUserHomeViewModel = ViewModelProviders.of(this, new UserHomeViewModel.Factory(HaloApp.getInstance().getApplication(), - UserManager.getInstance().getUserId())).get(UserHomeViewModel.class); mUserHomeViewModel.getBadges().observe(this, badgeEntities -> { if (badgeEntities.isEmpty()) { mPersonalBadgeTv.setText("领取徽章"); @@ -201,7 +259,6 @@ public class PersonalFragment extends BaseFragment implements Observer mPersonalBadgeTips.setVisibility(count > 0 ? View.VISIBLE : View.GONE)); - mPersonalViewModel = ViewModelProviders.of(this).get(PersonalViewModel.class); mPersonalViewModel.getHaloAddData().observe(this, datas -> { if (!datas.isEmpty()) { mPersonalFuncGroupAdapter.setListData(datas); @@ -211,8 +268,6 @@ public class PersonalFragment extends BaseFragment implements Observer { if (messageUnread != null && messageUnread.getTotal() > 0) { @@ -256,45 +311,9 @@ public class PersonalFragment extends BaseFragment implements Observer { - int absOffset = Math.abs(verticalOffset); - int invisibleOffset = DisplayUtils.dip2px(40F); - if (absOffset <= invisibleOffset) { - mUserIconSmall.setVisibility(View.GONE); - mPersonalUserNameSmall.setVisibility(View.GONE); - } else { - mUserIconSmall.setVisibility(View.VISIBLE); - mPersonalUserNameSmall.setVisibility(View.VISIBLE); - } - mListRefresh.setEnabled(absOffset <= 2); - }); - mListRefresh.setColorSchemeColors(ContextCompat.getColor(requireContext(), R.color.theme)); - mListRefresh.setProgressViewOffset(false, 0, DisplayUtils.dip2px(80) + DisplayUtils.getStatusBarHeight(requireContext().getResources())); - mListRefresh.setOnRefreshListener(() -> { - mPersonalViewModel.getHaloAddons(); - if (CheckLoginUtils.isLogin()) { - mUnreadViewModel.retry(); - MessageUnreadRepository.INSTANCE.loadMessageUnreadTotal(); - mUserHomeViewModel.getBadgeList(); - mUserHomeViewModel.availableBadges(); - } - mBaseHandler.postDelayed(() -> { - mListRefresh.setRefreshing(false); - }, 2000); - MtaHelper.onEvent("我的光环_新", "下拉刷新", "下拉刷新"); - }); - } - - @Override - public void onResume() { - super.onResume(); if (NetworkUtils.isNetworkConnected(requireContext())) { mUnreadViewModel.retry(); mUserHomeViewModel.getBadgeList(); @@ -465,7 +484,6 @@ public class PersonalFragment extends BaseFragment implements Observer 24 * 60 * 60 * 1000) { - return true; - } - return false; + return lastSignDay != curDay || curTime - lastSignTime > 24 * 60 * 60 * 1000; } - private String getSignSkipText(String text) { return TextUtils.isEmpty(text) ? "去首页看看" : text; } @@ -551,7 +565,6 @@ public class PersonalFragment extends BaseFragment implements Observer userInfoEntity) { UserInfoEntity notifyUserInfo; @@ -583,7 +596,7 @@ public class PersonalFragment extends BaseFragment implements Observer>, LoginHelper.LoginCallback { - - @BindView(R.id.scroll_view) - ScrollView mScrollView; - @BindView(R.id.personal_login_qq) - View mLoginQq; - @BindView(R.id.personal_login_wechat) - View mLoginWechat; - @BindView(R.id.personal_login_weibo) - View mLoginWeibo; - @BindView(R.id.personal_user_icon) - SimpleDraweeView mUserIcon; - @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) - View mPersonalGame; - @BindView(R.id.personal_share) - View mPersonalShare; - @BindView(R.id.personal_suggestion) - View mPersonalSuggestion; - @BindView(R.id.personal_setting_update_hint) - TextView mPersonalSettingUpdateHint; - @BindView(R.id.personal_setting) - View mPersonalSetting; - @BindView(R.id.login_message_hint) - TextView mLoginMessageHint; // 亦即登录后按钮 - @BindView(R.id.user_icon_hint) - View mIconHint; - @BindView(R.id.personal_ask) - View mPersonalAsk; - @BindView(R.id.personal_home_fans_hint) - TextView mFansHint; - @BindView(R.id.personal_user_badge) - SimpleDraweeView mUserBadge; - - public final static String LOGIN_TAG = "login_tag"; //登入标识 - public final static String LOGOUT_TAG = "logout_tag"; // 登出标识 - public final static String MESSAGE_UNREAD_TAG = "message_unread_tag"; - public final static String MESSAGE_READ_OVER = "MESSAGE_READ_OVER"; - public static final int REQUEST_MESSAGE = 199; - - private UserInfoEntity mUserInfoEntity; - - private WaitingDialogFragment mLoginDialog; - - private SharedPreferences sp; - private AppDatabase mDatabase; - - private UserViewModel mUserViewModel; - private MessageUnreadViewModel mUnreadViewModel; - - private boolean mIsLogging = false; - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == Constants.REQUEST_LOGIN) { // QQ Login callback - LoginHelper.onQQLoginCallback(requestCode, resultCode, data); - } else if (requestCode == 32973) {// 32973 WeiBo requestCode - LoginHelper.onWeiboLoginCallback(requestCode, resultCode, data); - } else if (requestCode == REQUEST_MESSAGE) { - if (mUnreadViewModel != null) mUnreadViewModel.retry(); - } - } - - @Override - protected int getLayoutId() { - return R.layout.fragment_personal_copy; - } - - @SuppressLint("CheckResult") - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - sp = PreferenceManager.getDefaultSharedPreferences(getContext()); - mDatabase = AppDatabase.getInstance(getContext()); - - checkUpdate(); - - final UserViewModel.Factory factory = new UserViewModel.Factory(getActivity().getApplication()); - mUserViewModel = ViewModelProviders.of(this, factory).get(UserViewModel.class); - mUserViewModel.getLoginObsUserinfo().observe(this, this); - - mUnreadViewModel = ViewModelProviders.of(this, - new MessageUnreadViewModel.Factory(HaloApp.getInstance().getApplication())).get(MessageUnreadViewModel.class); - mUnreadViewModel.getLiveData().observe(this - , messageUnread -> { - if (messageUnread != null && messageUnread.getTotal() > 0) { - mFansHint.setVisibility(messageUnread.getFans() > 0 ? View.VISIBLE : View.GONE); - mFansHint.setText((messageUnread.getFans() + "个新粉丝")); - int count = messageUnread.getTotal() - messageUnread.getFans(); - mLoginMessageHint.setVisibility(count > 0 ? View.VISIBLE : View.GONE); - BindingAdapters.setMessageUnread(mLoginMessageHint, count); - - // 第一次开启应用时检查消息中心看有没有未读消息确定需不需要弹 Notifier 通知 - if (mUnreadViewModel.isFirstTimeInit()) { - mUnreadViewModel.flagFirstTimeInit(false); - - if (messageUnread.getMeta() != null && messageUnread.getMeta().getUser() != null) { - if (messageUnread.getMeta() != null) { - String displayText = StringUtils.shrinkStringWithDot(messageUnread.getMeta().getUser().getName(), 8); - String suffixText; - if ("follow_question".equals(messageUnread.getMeta().getType())) { - suffixText = "回答了你关注的问题"; - } else { - suffixText = "回答了你的问题"; - } - displayText += suffixText; - - String content = messageUnread.getMeta().getAnswerId() + displayText; - - if (Notifier.shouldShowNotifier(content)) { - Notifier.create(getActivity()) - .setText(displayText) - .setDuration(5000) - .setIcon(messageUnread.getMeta().getUser().getIcon()) - .setOnClickListener(view -> { - Bundle bundle = new Bundle(); - bundle.putString(EntranceUtils.KEY_ANSWER_ID, messageUnread.getMeta().getAnswerId()); - bundle.putString(EntranceUtils.KEY_ENTRANCE, EntranceUtils.ENTRANCE_UMENG); - bundle.putString(EntranceUtils.KEY_TO, AnswerDetailActivity.class.getName()); - EntranceUtils.jumpActivity(getActivity(), bundle); - - MtaHelper.onEvent("消息弹窗", suffixText, "Does not contains any parameter."); - - // 标记已读 - JSONObject jsonObject = new JSONObject(); - try { - jsonObject.put("type", messageUnread.getMeta().getType()); - RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString()); - RetrofitManager.getInstance(requireContext()).getApi() - .postMessageRead(UserManager.getInstance().getUserId(), messageUnread.getMeta().getMessageId(), body) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(@Nullable ResponseBody response) { - super.onResponse(response); - MessageUnreadRepository.INSTANCE.loadMessageUnreadData(); - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - - Notifier.hide(); - }) - .show(true, 500L); - Notifier.tagNotifierAsShowed(content); - } - } - } - } - EventBus.getDefault().post(new EBReuse(MESSAGE_UNREAD_TAG)); - } else { - mLoginMessageHint.setVisibility(View.GONE); - mFansHint.setVisibility(View.GONE); - EventBus.getDefault().post(new EBReuse(MESSAGE_READ_OVER)); - } - }); - - // 微信/签到 - RxView.clicks(mLoginWechat) - .throttleFirst(1, TimeUnit.SECONDS) - .subscribe(aVoid -> { - if (mUserInfoEntity != null) { - MtaHelper.onEvent("我的光环", "签到"); - sign(); - } else { - MtaHelper.onEvent("我的光环", "微信登录"); - LoginHelper.loginWithWechat(this); - } - }); - } - - // 连接上网络事件 - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(EBNetworkState busNetworkState) { - if (busNetworkState.isNetworkConnected() - && mUserViewModel.isLogin() - && (mUserInfoEntity == null || TextUtils.isEmpty(UserManager.getInstance().getToken()))) { - mUserViewModel.retryCheckLogin(); - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(EBReuse reuse) { - if (MESSAGE_READ_OVER.equals(reuse.getType())) { // 消息阅读完成 - if (mLoginMessageHint != null) { - mLoginMessageHint.setVisibility(View.GONE); - } - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(EBUISwitch busNine) { - if (MainWrapperFragment.EB_MAIN_SCROLL_TOP.equals(busNine.getFrom()) - && MainWrapperFragment.INDEX_PERSONAL == busNine.getPosition()) { - mScrollView.fullScroll(ScrollView.FOCUS_UP); - } - } - - @OnClick({ - R.id.personal_login_qq, R.id.personal_login_weibo, R.id.personal_user_icon, - R.id.personal_history, R.id.personal_user_name, R.id.personal_game, R.id.personal_share, - R.id.personal_suggestion, R.id.personal_setting, R.id.personal_ask, R.id.personal_home, - R.id.personal_draft, R.id.personal_video_manager, R.id.personal_bind_wechat}) - public void onViewClicked(View view) { - switch (view.getId()) { - case R.id.personal_login_qq: - if (mUserInfoEntity != null) { - MtaHelper.onEvent("我的光环", "收藏"); - startActivity(CollectionActivity.getCollectionActivity(getContext(), "(我的光环)")); - } else { - MtaHelper.onEvent("我的光环", "QQ登录"); - LoginHelper.loginWithQQ(this, requireActivity()); - } - break; - case R.id.personal_login_weibo: - if (mUserInfoEntity != null) { - MtaHelper.onEvent("我的光环", "消息"); - startActivityForResult(MessageActivity.getIntent(getContext(), "(我的光环)+(消息中心)"), REQUEST_MESSAGE); - } else { - MtaHelper.onEvent("我的光环", "微博登录"); - LoginHelper.loginWithWeibo(this, requireActivity()); - } - break; - case R.id.personal_user_icon: - case R.id.personal_user_name: - if (mIconHint.getVisibility() == View.VISIBLE) { - LoginTokenEntity loginToken = UserManager.getInstance().getLoginTokenEntity(); - mIconHint.setVisibility(View.GONE); - if (loginToken != null && loginToken.getId() != null) - sp.edit().putBoolean(loginToken.getId(), false).apply(); - } - - if (mUserInfoEntity != null) { - MtaHelper.onEvent("我的光环", "个人中心"); - startActivity(UserInfoActivity.getIntent(getContext())); - } else { - MtaHelper.onEvent("我的光环", "手机登录"); - CheckLoginUtils.checkLogin(getContext(), "我的光环-手机登录", null); - } - break; - case R.id.personal_game: - if (mUserInfoEntity != null) { - MtaHelper.onEvent("我的光环", "我的游戏"); - startActivity(new Intent(getContext(), MyGameActivity.class)); - } else { - toast("请先登录"); - MtaHelper.onEvent("我的光环", "我的游戏"); - CheckLoginUtils.checkLogin(getContext(), "我的光环-我的游戏", null); - } - break; - case R.id.personal_share: - MtaHelper.onEvent("我的光环", "分享"); - startActivity(ShareGhActivity.getIntent(getContext())); - break; - case R.id.personal_suggestion: - MtaHelper.onEvent("我的光环", "反馈"); - startActivity(HelpAndFeedbackActivity.getIntent(getActivity())); - break; - case R.id.personal_bind_wechat: - MtaHelper.onEvent("我的光环", "设置微信提醒"); - startActivity(WebActivity.getBindWechatIntent(requireContext())); - break; - case R.id.personal_setting: - MtaHelper.onEvent("我的光环", "设置图标"); - DataCollectionUtils.uploadClick(getActivity(), "设置图标", "我的光环"); - startActivity(SettingActivity.getIntent(getContext(), - mPersonalSettingUpdateHint.getVisibility() == View.VISIBLE, "(我的光环)")); - break; - case R.id.personal_ask: - MtaHelper.onEvent("我的光环", "我的问答"); - CheckLoginUtils.checkLogin(getContext(), "我的光环-我的问答", () -> startActivity(MyAskActivity.getIntent(getContext()))); - break; - case R.id.personal_home: - CheckLoginUtils.checkLogin(getContext(), "我的光环-个人主页", () -> { - DirectUtils.directToHomeActivity(getContext(), UserManager.getInstance().getUserId(), "", "我的光环"); - }); - MtaHelper.onEvent("我的光环", "个人主页"); - break; - case R.id.personal_draft: - CheckLoginUtils.checkLogin(getContext(), "我的光环-我的草稿", () -> { - startActivity(CommunityDraftWrapperActivity.getIntent(getContext())); - }); - MtaHelper.onEvent("我的光环", "我的草稿"); - break; - case R.id.personal_history: - startActivity(HistoryActivity.getHistoryIntent(getContext(), "我的光环-浏览记录")); - MtaHelper.onEvent("我的光环", "浏览记录"); - break; - case R.id.personal_video_manager: - CheckLoginUtils.checkLogin(getContext(), "我的光环-视频投稿", () -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { - startActivity(VideoManagerActivity.getIntent(getContext(), "", "我的光环-视频投稿")); - } else { - DialogUtils.showAlertDialog(getContext(), "提示", - "抱歉,您当前系统版本过低,暂不支持视频功能", "我知道了", - null, null, null); - } - }); - MtaHelper.onEvent("我的光环", "视频投稿"); - break; - } - } - - private boolean isCanSign(long time) { - SimpleDateFormat formatDay = new SimpleDateFormat("dd", Locale.CHINA); - - long lastSignTime = time * 1000; - long curTime = Utils.getTime(getContext()) * 1000; - int lastSignDay = Integer.parseInt(formatDay.format(lastSignTime)); - int curDay = Integer.parseInt(formatDay.format(curTime)); - if (lastSignDay != curDay || curTime - lastSignTime > 24 * 60 * 60 * 1000) { - return true; - } - return false; - } - - private void sign() { - RetrofitManager.getInstance(getContext()).getApi() - .postSign(UserManager.getInstance().getUserId()) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(SignEntity signEntity) { - mLoginWechatTv.setText("已签到"); - if (isCanSign(signEntity.getLastTime())) { - DialogUtils.showSignDialog(getContext(), "签到成功,获得经验:1" - , getString(R.string.sign_dialog_content, signEntity.getSerialSign()) - , getString(R.string.sign_dialog_content2, signEntity.getExperience()) - , getSignSkipText(signEntity.getTitle()), () -> { - signSkip(signEntity); - } - ); - signEntity.setLastTime(System.currentTimeMillis() / 1000); - } else { - DialogUtils.showSignDialog(getContext(), "今天已签到,明天再来吧~" - , getString(R.string.sign_dialog_content, signEntity.getSerialSign()) - , getString(R.string.sign_dialog_content2, signEntity.getExperience()) - , getSignSkipText(signEntity.getTitle()), () -> { - signSkip(signEntity); - } - ); - } - - signEntity.setId(UserManager.getInstance().getUserId()); - if (mDatabase.signDao().updateSignEntity(signEntity) <= 0) { - mDatabase.signDao().addSignEntity(signEntity); - } - } - - @Override - public void onFailure(HttpException e) { - if (e == null || e.code() != 401) { - toast(R.string.loading_network_error); - } - } - }); - - } - - private String getSignSkipText(String text) { - return TextUtils.isEmpty(text) ? "去首页看看" : text; - } - - private void signSkip(SignEntity signEntity) { - SignEntity.Data data = signEntity.getData(); - String entrance = "(我的光环)+(签到)"; - if (data == null || TextUtils.isEmpty(data.getType())) { - EventBus.getDefault().post(new EBSkip(MainActivity.EB_SKIP_MAIN, MainWrapperFragment.INDEX_HOME)); - return; - } - switch (data.getType()) { - case "game": - DataUtils.onMtaEvent(getActivity(), "我的光环_签到跳转", "游戏", signEntity.getTitle()); - GameDetailActivity.startGameDetailActivity(getContext(), data.getLink(), entrance); - break; - case "news": - DataUtils.onMtaEvent(getActivity(), "我的光环_签到跳转", "文章", signEntity.getTitle()); - startActivity(NewsDetailActivity.getIntentById(getContext(), data.getLink(), entrance)); - break; - case "column": - DataUtils.onMtaEvent(getActivity(), "我的光环_签到跳转", "专题", signEntity.getTitle()); - SubjectActivity.startSubjectActivity(getContext(), data.getLink(), null, false, entrance); - break; - } - } - - - private void changeLoginState(boolean isLogin) { - if (isLogin) { - SignEntity signEntity = mDatabase.signDao().getSignEntityById(UserManager.getInstance().getUserId()); - if (signEntity != null && !isCanSign(signEntity.getLastTime())) { - mLoginWechatTv.setText("已签到"); - } else { - mLoginWechatTv.setText("签到"); - } - if (mUserInfoEntity != null) { - ImageUtils.displayIcon(mUserIcon, mUserInfoEntity.getIcon()); - mUserName.setText(mUserInfoEntity.getName()); - if (mUserInfoEntity.getAuth() != null) { - mUserBadge.setVisibility(View.VISIBLE); - ImageUtils.display(mUserBadge, mUserInfoEntity.getAuth().getIcon()); - } - } - mLoginQqIcon.setImageResource(R.drawable.personal_collection_icon); - mLoginQqTv.setText("收藏"); - mLoginWechatIcon.setImageResource(R.drawable.personal_sign_icon); - mLoginWeiboIcon.setImageResource(R.drawable.personal_message_icon); - mLoginWeiboTv.setText("消息"); - } else { - mUserBadge.setVisibility(View.GONE); - mIconHint.setVisibility(View.GONE); - mLoginQqIcon.setImageResource(R.drawable.qq_login_icon); - mLoginQqTv.setText(getString(R.string.QQ)); - mLoginWechatIcon.setImageResource(R.drawable.wechat_login_icon); - mLoginWechatTv.setText(getString(R.string.wechat)); - mLoginWeiboIcon.setImageResource(R.drawable.weibo_login_icon); - mLoginWeiboTv.setText(getString(R.string.sina_weibo)); - mUserIcon.setImageURI(""); - mUserName.setText("手机登录"); - if (mLoginMessageHint.getVisibility() == View.VISIBLE) { - mLoginMessageHint.setVisibility(View.GONE); - EventBus.getDefault().post(new EBReuse(MESSAGE_READ_OVER)); - } - } - } - - private void checkUpdate() { - String channel = HaloApp.getInstance().getChannel(); - RetrofitManager.getInstance(getContext()) - .getApi() - .getUpdate(PackageUtils.getVersionName(), PackageUtils.getVersionCode(), channel) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(AppEntity response) { - super.onResponse(response); - if (response.getVersionCode() > PackageUtils.getVersionCode()) { - mPersonalSettingUpdateHint.setVisibility(View.VISIBLE); - } else { - mPersonalSettingUpdateHint.setVisibility(View.GONE); - } - } - }); - } - - @Override - public void onLoginSuccess(@NotNull LoginTag loginType, @NotNull JSONObject jsonContent) { - if (CommonDebug.IS_DEBUG) { - Utils.log("Login Output=>获取第三方登录信息成功" + jsonContent.toString() + "" + loginType.name()); - } - if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { - mLoginDialog = WaitingDialogFragment.newInstance(getString(R.string.logging)); - mLoginDialog.show(getChildFragmentManager(), null); - } - - mIsLogging = true; - mUserViewModel.login(jsonContent, loginType); - LogUtils.login("logging", loginType.name(), getLoginEntranceByType(loginType.name())); - } - - @Override - public void onLoginFailure(@NotNull LoginTag loginType, @NotNull String error) { - toast(error); - } - - @Override - public void onChanged(@Nullable ApiResponse userInfoEntity) { - UserInfoEntity notifyUserInfo; - if (userInfoEntity != null) { - notifyUserInfo = userInfoEntity.getData(); - } else { - notifyUserInfo = null; - } - - if (notifyUserInfo != null && mUserInfoEntity == null) { // 单个用户,首次触发 - mUnreadViewModel.retry(); // 检查是否有未读消息 - EventBus.getDefault().post(new EBConcernChanged()); - /** - * default_icon_ 判断是不是默认头像 - * 具体默认头像链接请看: - * {@link com.gh.common.util.UserIconUtils#getUserIconUrl(int)} - */ - LoginTokenEntity loginToken = UserManager.getInstance().getLoginTokenEntity(); - if (loginToken != null && loginToken.getId() != null && - sp.getBoolean(loginToken.getId(), true) && - notifyUserInfo.getIcon() != null && - notifyUserInfo.getIcon().contains("default_icon_")) { - mIconHint.setVisibility(View.VISIBLE); - } - - LoginTokenEntity loginTokenEntity = UserManager.getInstance().getLoginTokenEntity(); - if (mIsLogging && loginTokenEntity != null) { - String loginType = loginTokenEntity.getLoginType(); - LogUtils.login("success", loginType, getLoginEntranceByType(loginType)); - mIsLogging = false; - } - } - - mUserInfoEntity = notifyUserInfo; - if (notifyUserInfo == null) { - mUnreadViewModel.clean(); - changeLoginState(false); - EventBus.getDefault().post(new EBConcernChanged()); - } else { - changeLoginState(true); - } - - if (mLoginDialog != null) { - mLoginDialog.dismissAllowingStateLoss(); - } - } - - public static String getLoginEntranceByType(String loginTag) { - String entrance = ""; - switch (loginTag) { - case "qq": - entrance = "我的光环-QQ"; - break; - case "wechat": - entrance = "我的光环-微信"; - break; - case "weibo": - entrance = "我的光环-新浪微博"; - break; - } - return entrance; - } -} diff --git a/app/src/main/res/layout/fragment_personal_copy.xml b/app/src/main/res/layout/fragment_personal_copy.xml deleted file mode 100644 index 07281c2dc6..0000000000 --- a/app/src/main/res/layout/fragment_personal_copy.xml +++ /dev/null @@ -1,539 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_personal_stub.xml b/app/src/main/res/layout/fragment_personal_stub.xml new file mode 100644 index 0000000000..0be2c48211 --- /dev/null +++ b/app/src/main/res/layout/fragment_personal_stub.xml @@ -0,0 +1,11 @@ + + + + +