PageRenderTime 139ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 1ms

/yueai/src/main/java/com/yueai/activity/MainActivity.java

https://bitbucket.org/juzhiwiscom/datelove
Java | 2083 lines | 904 code | 159 blank | 1020 comment | 147 complexity | 3de966df17849e9e192bc5a1e472aeb9 MD5 | raw file
  1. package com.yueai.activity;
  2. import android.Manifest;
  3. import android.content.BroadcastReceiver;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.IntentFilter;
  7. import android.content.pm.PackageManager;
  8. import android.location.Location;
  9. import android.location.LocationListener;
  10. import android.location.LocationManager;
  11. import android.os.Build;
  12. import android.os.Bundle;
  13. import android.os.Handler;
  14. import android.os.Message;
  15. import android.os.Vibrator;
  16. import android.support.annotation.NonNull;
  17. import android.support.v4.app.ActivityCompat;
  18. import android.support.v4.app.Fragment;
  19. import android.support.v4.app.FragmentManager;
  20. import android.support.v4.app.FragmentPagerAdapter;
  21. import android.support.v4.content.ContextCompat;
  22. import android.support.v4.view.ViewPager;
  23. import android.text.TextUtils;
  24. import android.util.Log;
  25. import android.view.View;
  26. import android.view.WindowManager;
  27. import android.view.animation.Animation;
  28. import android.view.animation.AnimationUtils;
  29. import android.widget.FrameLayout;
  30. import android.widget.ImageView;
  31. import android.widget.LinearLayout;
  32. import android.widget.RelativeLayout;
  33. import android.widget.TextView;
  34. import com.alibaba.fastjson.JSON;
  35. import com.alibaba.fastjson.JSONArray;
  36. import com.alibaba.fastjson.JSONObject;
  37. import com.library.imageloader.ImageLoader;
  38. import com.library.imageloader.ImageLoaderUtil;
  39. import com.library.utils.HeightUtils;
  40. import com.library.utils.LogUtil;
  41. import com.library.utils.SharedPreferenceUtil;
  42. import com.library.utils.Util;
  43. import com.library.widgets.CircleImageView;
  44. import com.library.widgets.ScrollControlViewPager;
  45. import com.yueai.R;
  46. import com.yueai.base.BaseFragmentActivity;
  47. import com.yueai.bean.BaseModel;
  48. import com.yueai.bean.FateUser;
  49. import com.yueai.bean.HeadMsgNotice;
  50. import com.yueai.bean.Image;
  51. import com.yueai.bean.LocationInfo;
  52. import com.yueai.bean.MsgBox;
  53. import com.yueai.bean.NewHeadMsgNotice;
  54. import com.yueai.bean.RecommendUser;
  55. import com.yueai.bean.User;
  56. import com.yueai.bean.UserBase;
  57. import com.yueai.constant.IUrlConstant;
  58. import com.yueai.event.BaseOpenMailFragmentEvent;
  59. import com.yueai.event.CloseMainActivityEvent;
  60. import com.yueai.event.HeadMsgEvent;
  61. import com.yueai.event.MatchInfoChangeEvent;
  62. import com.yueai.event.MessageChangedEvent;
  63. import com.yueai.event.NoSeeMeEvent;
  64. import com.yueai.event.OpenMailFragmentEvent;
  65. import com.yueai.event.RegistEvent;
  66. import com.yueai.event.UpdateMessageCountEvent;
  67. import com.yueai.event.UpdateUserProvince;
  68. import com.yueai.fragment.FateCardFragment;
  69. import com.yueai.fragment.MeFragment;
  70. import com.yueai.fragment.MessageFragment;
  71. import com.yueai.fragment.NearbyFragment;
  72. import com.yueai.fragment.SearchFragment;
  73. import com.yueai.utils.CommonRequestUtil;
  74. import com.yueai.xml.PlatformInfoXml;
  75. import com.yueai.xml.UserInfoXml;
  76. import com.zhy.http.okhttp.OkHttpUtils;
  77. import com.zhy.http.okhttp.callback.Callback;
  78. import com.zhy.http.okhttp.callback.StringCallback;
  79. import org.greenrobot.eventbus.EventBus;
  80. import org.greenrobot.eventbus.Subscribe;
  81. import java.lang.ref.WeakReference;
  82. import java.util.ArrayList;
  83. import java.util.HashMap;
  84. import java.util.List;
  85. import java.util.Map;
  86. import butterknife.BindView;
  87. import butterknife.OnClick;
  88. import okhttp3.Call;
  89. import okhttp3.Response;
  90. import static com.yueai.utils.GoogleUtil.getGoogleProviceL1Key;
  91. /**
  92. * modified by zhangdroid on 2017-02-28
  93. */
  94. public class MainActivity extends BaseFragmentActivity {
  95. @BindView(R.id.viewPager)
  96. ScrollControlViewPager mViewPager;
  97. // 页眉
  98. @BindView(R.id.head_msg_container)
  99. RelativeLayout mRlHeadMsgContainer;
  100. @BindView(R.id.head_msg_content)
  101. TextView mTvHeadMsgContent;
  102. @BindView(R.id.head_msg_clear)
  103. ImageView mIvHeadMsgClear;
  104. // 新页眉
  105. @BindView(R.id.headMsg_container)
  106. FrameLayout mFlHeadMsgNew;
  107. @BindView(R.id.headMsg_unread)
  108. RelativeLayout mRlHeadMsgUnread;
  109. @BindView(R.id.headMsg_avatar)
  110. CircleImageView mIvHeadMsgAvatar;
  111. @BindView(R.id.headMsg_nickname)
  112. TextView mTvNickname;
  113. @BindView(R.id.headMsg_age)
  114. TextView mTvAge;
  115. @BindView(R.id.headMsg_height)
  116. TextView mTvHeight;
  117. @BindView(R.id.headMsg_content)
  118. TextView mTvMsgContent;
  119. @BindView(R.id.headMsg_check)
  120. TextView mTvMsgCheck;
  121. // 访客
  122. @BindView(R.id.headMsg_visitor)
  123. RelativeLayout mRlHeadMsgVisitor;
  124. @BindView(R.id.visitor_avatar)
  125. CircleImageView mIvVisitorAvatar;
  126. @BindView(R.id.visitor_content)
  127. TextView mTvVisitorContent;
  128. @BindView(R.id.visitor_ignore)
  129. TextView mTvVisitorIgnore;
  130. @BindView(R.id.visitor_look)
  131. TextView mTvVisitorLook;
  132. // 推荐用户
  133. @BindView(R.id.recommend_user_container)
  134. LinearLayout mLlRecommendUser;
  135. @BindView(R.id.recommend_user_avatar)
  136. CircleImageView mIvRecommendAvatar;
  137. @BindView(R.id.recommend_user_content)
  138. TextView mTvRecommendContent;
  139. @BindView(R.id.recommend_user_ignore)
  140. TextView mTvRecommendIgnore;
  141. @BindView(R.id.recommend_user_look)
  142. TextView mTvRecommendLook;
  143. // tab页
  144. @BindView(R.id.main_tab_fate)
  145. TextView mTvTabFate;
  146. @BindView(R.id.main_tab_search)
  147. TextView mTvTabSearch;
  148. @BindView(R.id.main_tab_mail)
  149. TextView mTvTabMail;
  150. @BindView(R.id.unread_msg_count)
  151. TextView mTvUnreadMsgCount;// 未读消息数
  152. @BindView(R.id.main_tab_nearby)
  153. TextView mTvTabNearby;
  154. @BindView(R.id.main_tab_me)
  155. TextView mTvTabMe;
  156. private static final int TAB_INDEX_FATE = 0;
  157. private static final int TAB_INDEX_SEARCH = 1;
  158. private static final int TAB_INDEX_MAIL = 2;
  159. private static final int TAB_INDEX_NEARBY = 3;
  160. private static final int TAB_INDEX_ME = 4;
  161. private static final int HEAD_MSG_REFRESH_PERIOD = 20 * 1000;
  162. private static final int MSG_TYPE_LOAD_DATA = 1;
  163. private static final int MSG_TYPE_HEAD_MSG = 2;
  164. private static final int MSG_TYPE_HEAD_MSG_NEW = 3;
  165. private static final int MSG_TYPE_RECOMMEND_USER = 4;
  166. private static final int MSG_TYPE_SHOW_UNREAD_MSG = 5;
  167. private static final int MSG_TYPE_DISMISS_UNREAD_MSG = 6;
  168. private static final int MSG_TYPE_DISMISS_VISITOR = 7;
  169. private static final int MSG_TYPE_HIDE_RECOMMEND_USER = 8;
  170. private static final int PERMISSION_CODE_ACCESS_FINE_LOCATION = 0;
  171. private LocationManager mLocationManager;
  172. /**
  173. * 页眉对象缓存
  174. */
  175. private HeadMsgNotice mHeadMsgNotice;
  176. /**
  177. * 新页眉对象缓存
  178. */
  179. private NewHeadMsgNotice mNewHeadMsgNotice;
  180. /**
  181. * 推荐用户对象缓存
  182. */
  183. private RecommendUser mRecommendUser;
  184. /**
  185. * 新页眉最后一条未读消息毫秒数
  186. */
  187. private long mLastMsgTime;
  188. /**
  189. * 推荐用户轮询周期(秒)
  190. */
  191. private int cycle;
  192. /**
  193. * 新页眉中当前正在显示的未读消息索引
  194. */
  195. private int mCurrDisplayItem = 0;
  196. private TimerHandler mTimerHandler;
  197. private Context mContext;
  198. private Vibrator vibrator;
  199. private boolean isShake = true;
  200. private MainAdapter mainAdapter;
  201. private int currentUnreadMsgCount;
  202. private boolean isFirstInto=true;
  203. private boolean getProvince=false;
  204. private String getLatitude;
  205. private String getLongitude;
  206. private boolean LocationSuccess=true;
  207. @Override
  208. protected int getLayoutResId() {
  209. return R.layout.activity_main;
  210. }
  211. @Override
  212. protected void initViewsAndVariables() {
  213. // 设置状态栏
  214. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {// 5.0及以上
  215. View decorView = getWindow().getDecorView();
  216. decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
  217. // 设置状态栏背景
  218. getWindow().setStatusBarColor(getResources().getColor(R.color.main_color));
  219. } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {// 4.4
  220. getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  221. }
  222. // 获取位置信息并上传
  223. requestLocation();
  224. getAdapter();
  225. // 延时加载数据
  226. mTimerHandler = new TimerHandler(this);
  227. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_LOAD_DATA,1000*15);
  228. //注册广播
  229. registerReceiver(mHomeKeyEventReceiver, new IntentFilter(
  230. Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
  231. }
  232. private void getAdapter() {
  233. if(isFirstInto){
  234. isFirstInto=false;
  235. mainAdapter = new MainAdapter(getSupportFragmentManager());
  236. mViewPager.setAdapter(mainAdapter);
  237. mViewPager.setCanScroll(false);
  238. mViewPager.setOffscreenPageLimit(4);
  239. mViewPager.setCurrentItem(TAB_INDEX_FATE);
  240. mTvTabFate.setSelected(true);
  241. /**对viewPage的界面改变进行监听,当刷新聊天列表的界面开始刷新,刷出聊天列表界面停止刷新**/
  242. mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  243. @Override
  244. public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  245. }
  246. @Override
  247. public void onPageSelected(int position) {
  248. MessageFragment item = (MessageFragment)mainAdapter.getItem(2);
  249. if(position!=2){
  250. item.stopRefish();
  251. }else{
  252. item.startFirstRefish();
  253. }
  254. }
  255. @Override
  256. public void onPageScrollStateChanged(int state) {
  257. }
  258. });
  259. }
  260. }
  261. /**
  262. * 加载页眉和推荐用户
  263. */
  264. private void loadData() {
  265. // // 获取页眉
  266. // if (UserInfoXml.isShowHeadMsg()) {
  267. // getHeadMsg();
  268. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG, HEAD_MSG_REFRESH_PERIOD);
  269. // }
  270. // 获取新页眉
  271. if (UserInfoXml.isShowHeadMsgNew()) {
  272. getNewHeadMsg();
  273. }
  274. // 获取推荐用户
  275. if (UserInfoXml.isShowRecommendUser()) {
  276. getRecommendUsr();
  277. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_RECOMMEND_USER, HEAD_MSG_REFRESH_PERIOD);
  278. }
  279. }
  280. /**
  281. * 获取页眉
  282. */
  283. private void getHeadMsg() {
  284. CommonRequestUtil.getHeadMsg(new CommonRequestUtil.OnGetHeadMsgListener() {
  285. @Override
  286. public void onSuccess(HeadMsgNotice headMsgNotice) {
  287. if (headMsgNotice != null) {
  288. mHeadMsgNotice = headMsgNotice;
  289. String message = headMsgNotice.getMessage();
  290. if (mViewPager.getCurrentItem() != TAB_INDEX_MAIL && !TextUtils.isEmpty(message)) {
  291. mRlHeadMsgContainer.setVisibility(View.VISIBLE);
  292. mTvHeadMsgContent.setText(message);
  293. } else {
  294. mRlHeadMsgContainer.setVisibility(View.GONE);
  295. }
  296. String noticeType = headMsgNotice.getNoticeType();
  297. if (!TextUtils.isEmpty(noticeType) && "1".equals(noticeType)) {
  298. // 有未读消息时刷新消息列表
  299. EventBus.getDefault().post(new MessageChangedEvent());
  300. }
  301. }
  302. }
  303. @Override
  304. public void onFail() {
  305. }
  306. });
  307. }
  308. /**
  309. * 获取新页眉
  310. */
  311. private void getNewHeadMsg() {
  312. String lastMsgTime=new SharedPreferenceUtil(MainActivity.this).takeLastTime();
  313. if(!TextUtils.isEmpty(lastMsgTime)){
  314. mLastMsgTime=Long.parseLong(lastMsgTime);
  315. }
  316. CommonRequestUtil.getNewHeadMsg(mLastMsgTime, new CommonRequestUtil.OnGetNewHeadMsgListener() {
  317. @Override
  318. public void onSuccess(NewHeadMsgNotice newHeadMsgNotice) {
  319. if (newHeadMsgNotice != null) {
  320. mNewHeadMsgNotice = newHeadMsgNotice;
  321. mLastMsgTime = newHeadMsgNotice.getLastMsgTime();
  322. mCurrDisplayItem = 0;
  323. //将时间戳保存下来
  324. new SharedPreferenceUtil(MainActivity.this).saveLastTime(mLastMsgTime);
  325. String noticeType = newHeadMsgNotice.getNoticeType();
  326. if (!TextUtils.isEmpty(noticeType)) {
  327. switch (noticeType) {
  328. case "0":// 没有页眉,继续轮询
  329. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  330. break;
  331. case "1"://未读消息
  332. // 刷新聊天列表
  333. EventBus.getDefault().post(new MessageChangedEvent());
  334. setNewHeadMsg();
  335. break;
  336. case "2":// 访客
  337. FateUser fateUser = newHeadMsgNotice.getRemoteYuanfenUserBase();
  338. if (fateUser != null) {
  339. UserBase userBase = fateUser.getUserBaseEnglish();
  340. if (userBase != null) {
  341. ImageLoaderUtil.getInstance().loadImage(MainActivity.this, new ImageLoader.Builder()
  342. .url(userBase.getImage().getThumbnailUrl()).imageView(mIvVisitorAvatar).build());
  343. mTvVisitorContent.setText(getString(R.string.visitor_tip, userBase.getNickName()));
  344. }
  345. }
  346. mRlHeadMsgUnread.setVisibility(View.GONE);
  347. mRlHeadMsgVisitor.setVisibility(View.VISIBLE);
  348. showWithAnim(mFlHeadMsgNew);
  349. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_DISMISS_VISITOR, newHeadMsgNotice.getDisplaySecond() * 1000);
  350. break;
  351. }
  352. }
  353. }
  354. }
  355. @Override
  356. public void onFail() {
  357. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  358. }
  359. });
  360. }
  361. /**
  362. * 按照未读消息列表顺序显示未读信
  363. */
  364. private void setNewHeadMsg() {
  365. if (mNewHeadMsgNotice != null) {
  366. List<MsgBox> msgBoxList = mNewHeadMsgNotice.getUnreadMsgBoxList();
  367. if (!Util.isListEmpty(msgBoxList) && mCurrDisplayItem < msgBoxList.size()) {
  368. MsgBox msgBox = msgBoxList.get(mCurrDisplayItem);
  369. if (msgBox != null) {
  370. UserBase userBase = msgBox.getUserBaseEnglish();
  371. if (userBase != null) {
  372. Image image = userBase.getImage();
  373. if (image != null) {
  374. ImageLoaderUtil.getInstance().loadImage(MainActivity.this, new ImageLoader.Builder()
  375. .url(image.getThumbnailUrl()).imageView(mIvHeadMsgAvatar).build());
  376. }
  377. mTvNickname.setText(userBase.getNickName());
  378. if(userBase.getSex() ==0){
  379. mTvAge.setBackgroundResource(R.drawable.shape_round_rectangle_blue_bg);
  380. }
  381. mTvAge.setText(TextUtils.concat(String.valueOf(userBase.getAge())));
  382. mTvAge.setSelected(userBase.getSex() == 0);
  383. mTvHeight.setText(HeightUtils.getInchCmByCm(userBase.getHeightCm()));
  384. }
  385. String msgContent = msgBox.getMsg();
  386. if (!TextUtils.isEmpty(msgContent)) {
  387. // mTvMsgContent.setText(getString(R.string.get_msg));
  388. mTvMsgContent.setText(msgContent);
  389. }
  390. mRlHeadMsgUnread.setVisibility(View.VISIBLE);
  391. mRlHeadMsgVisitor.setVisibility(View.GONE);
  392. showWithAnim(mFlHeadMsgNew);
  393. }
  394. // 一段时间后显示下一条未读消息
  395. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_SHOW_UNREAD_MSG, mNewHeadMsgNotice.getDisplaySecond() * 1000);
  396. }
  397. }
  398. }
  399. private void showWithAnim(View view) {
  400. if (isShake) {
  401. view.setVisibility(View.VISIBLE);
  402. vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
  403. vibrator.vibrate(200);
  404. view.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim_in));
  405. }
  406. // view.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.push_bottom_in));
  407. }
  408. private void dismissWithAnim(final View view, final View view2) {
  409. // Animation outAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.push_bottom_out);
  410. Animation outAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim_out);
  411. view.startAnimation(outAnimation);
  412. outAnimation.setAnimationListener(new Animation.AnimationListener() {
  413. @Override
  414. public void onAnimationStart(Animation animation) {
  415. }
  416. @Override
  417. public void onAnimationEnd(Animation animation) {
  418. view.setVisibility(View.GONE);
  419. view2.setVisibility(View.GONE);
  420. }
  421. @Override
  422. public void onAnimationRepeat(Animation animation) {
  423. }
  424. });
  425. }
  426. /**
  427. * 获取推荐用户
  428. */
  429. private void getRecommendUsr() {
  430. CommonRequestUtil.getRecommendUser(cycle, new CommonRequestUtil.OnGetRecommendUserListener() {
  431. @Override
  432. public void onSuccess(RecommendUser recommendUser) {
  433. if (recommendUser != null) {
  434. mRecommendUser = recommendUser;
  435. cycle = recommendUser.getCycle();
  436. User user = recommendUser.getUser();
  437. if (user != null) {
  438. UserBase userBase = user.getUserBaseEnglish();
  439. if (userBase != null) {
  440. // 显示推荐用户
  441. mLlRecommendUser.setVisibility(View.VISIBLE);
  442. mTvRecommendContent.setText(TextUtils.concat(userBase.getNickName(), " ", recommendUser.getSentence()));
  443. ImageLoaderUtil.getInstance().loadImage(MainActivity.this, new ImageLoader.Builder()
  444. .url(userBase.getImage().getThumbnailUrl()).imageView(mIvRecommendAvatar).build());
  445. showWithAnim(mLlRecommendUser);
  446. }
  447. }
  448. }
  449. // 一段时间后隐藏推荐用户
  450. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HIDE_RECOMMEND_USER, 5 * 1000);
  451. }
  452. @Override
  453. public void onFail() {
  454. // 一段时间后隐藏推荐用户
  455. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HIDE_RECOMMEND_USER, 5 * 1000);
  456. }
  457. });
  458. }
  459. @Override
  460. protected void addListeners() {
  461. mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  462. @Override
  463. public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  464. }
  465. @Override
  466. public void onPageSelected(int position) {
  467. switch (position) {
  468. case TAB_INDEX_FATE:
  469. mTvTabFate.setSelected(true);
  470. mTvTabSearch.setSelected(false);
  471. mTvTabMail.setSelected(false);
  472. mTvTabNearby.setSelected(false);
  473. mTvTabMe.setSelected(false);
  474. break;
  475. case TAB_INDEX_SEARCH:
  476. mTvTabFate.setSelected(false);
  477. mTvTabSearch.setSelected(true);
  478. mTvTabMail.setSelected(false);
  479. mTvTabNearby.setSelected(false);
  480. mTvTabMe.setSelected(false);
  481. break;
  482. case TAB_INDEX_MAIL:
  483. mTvTabFate.setSelected(false);
  484. mTvTabSearch.setSelected(false);
  485. mTvTabMail.setSelected(true);
  486. mTvTabNearby.setSelected(false);
  487. mTvTabMe.setSelected(false);
  488. // 信箱tab页不显示页眉
  489. if (mRlHeadMsgContainer.isShown()) {
  490. mRlHeadMsgContainer.setVisibility(View.GONE);
  491. }
  492. // 隐藏新页眉
  493. if (mFlHeadMsgNew.isShown()) {
  494. mFlHeadMsgNew.setVisibility(View.GONE);
  495. if (mTimerHandler != null) {
  496. mTimerHandler.removeMessages(MSG_TYPE_SHOW_UNREAD_MSG);
  497. }
  498. }
  499. break;
  500. case TAB_INDEX_NEARBY:
  501. mTvTabFate.setSelected(false);
  502. mTvTabSearch.setSelected(false);
  503. mTvTabMail.setSelected(false);
  504. mTvTabNearby.setSelected(true);
  505. mTvTabMe.setSelected(false);
  506. break;
  507. case TAB_INDEX_ME:
  508. mTvTabFate.setSelected(false);
  509. mTvTabSearch.setSelected(false);
  510. mTvTabMail.setSelected(false);
  511. mTvTabNearby.setSelected(false);
  512. mTvTabMe.setSelected(true);
  513. break;
  514. }
  515. }
  516. @Override
  517. public void onPageScrollStateChanged(int state) {
  518. }
  519. });
  520. // 查看页眉消息
  521. mRlHeadMsgContainer.setOnClickListener(new View.OnClickListener() {
  522. @Override
  523. public void onClick(View v) {
  524. if (mHeadMsgNotice != null) {
  525. mRlHeadMsgContainer.setVisibility(View.GONE);
  526. String noticeType = mHeadMsgNotice.getNoticeType();
  527. if (!TextUtils.isEmpty(noticeType)) {
  528. switch (noticeType) {
  529. case "1": // 未读消息
  530. if (mViewPager.getCurrentItem() != TAB_INDEX_MAIL) {
  531. mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  532. }
  533. break;
  534. case "2":// 正在看我
  535. UserInfoDetailActivity.toUserInfoDetailActivity(MainActivity.this, mHeadMsgNotice.getRemoteUserId(), null, UserInfoDetailActivity.SOURCE_HEAD_MSG);
  536. break;
  537. }
  538. }
  539. }
  540. }
  541. });
  542. mIvHeadMsgClear.setOnClickListener(new View.OnClickListener() {
  543. @Override
  544. public void onClick(View v) {
  545. mRlHeadMsgContainer.setVisibility(View.GONE);
  546. }
  547. });
  548. // 新页眉
  549. mRlHeadMsgUnread.setOnClickListener(new View.OnClickListener() {
  550. @Override
  551. public void onClick(View v) {
  552. // 查看未读消息,进入聊天页面
  553. mFlHeadMsgNew.setVisibility(View.GONE);
  554. if (mNewHeadMsgNotice != null && mCurrDisplayItem < mNewHeadMsgNotice.getUnreadMsgBoxList().size()) {
  555. List<MsgBox> msgBoxList = mNewHeadMsgNotice.getUnreadMsgBoxList();
  556. if (!Util.isListEmpty(msgBoxList)) {
  557. MsgBox msgBox = msgBoxList.get(mCurrDisplayItem);
  558. if (msgBox != null) {
  559. UserBase userBase = msgBox.getUserBaseEnglish();
  560. if (userBase != null) {
  561. ChatActivity.toChatActivity(MainActivity.this, userBase.getId(), userBase.getNickName(), userBase.getImage().getThumbnailUrl());
  562. }
  563. }
  564. }
  565. }
  566. }
  567. });
  568. mTvVisitorLook.setOnClickListener(new View.OnClickListener() {
  569. @Override
  570. public void onClick(View v) {
  571. // 隐藏新页眉
  572. mRlHeadMsgVisitor.setVisibility(View.GONE);
  573. mFlHeadMsgNew.setVisibility(View.GONE);
  574. // 查看用户详情
  575. if (mNewHeadMsgNotice != null) {
  576. FateUser fateUser = mNewHeadMsgNotice.getRemoteYuanfenUserBase();
  577. if (fateUser != null) {
  578. UserBase userBase = fateUser.getUserBaseEnglish();
  579. if (userBase != null) {
  580. UserInfoDetailActivity.toUserInfoDetailActivity(MainActivity.this, userBase.getId(), null, UserInfoDetailActivity.SOURCE_HEAD_MSG);
  581. }
  582. }
  583. }
  584. }
  585. });
  586. mTvVisitorIgnore.setOnClickListener(new View.OnClickListener() {
  587. @Override
  588. public void onClick(View v) {
  589. // 隐藏新页眉
  590. mRlHeadMsgVisitor.setVisibility(View.GONE);
  591. mFlHeadMsgNew.setVisibility(View.GONE);
  592. }
  593. });
  594. // 推荐用户
  595. mTvRecommendLook.setOnClickListener(new View.OnClickListener() {
  596. @Override
  597. public void onClick(View v) {
  598. if (mRecommendUser != null) {
  599. UserBase userBase = mRecommendUser.getUser().getUserBaseEnglish();
  600. if (userBase != null) {
  601. // 隐藏推荐用户
  602. mLlRecommendUser.setVisibility(View.GONE);
  603. Image image = userBase.getImage();
  604. if (UserInfoXml.isMale()) {
  605. if (UserInfoXml.isMonthly()) {// 已付费男用户进入聊天页
  606. ChatActivity.toChatActivity(MainActivity.this, userBase.getId(), userBase.getNickName(),
  607. image == null ? null : image.getThumbnailUrl());
  608. } else {// 未付费男用户,进入对方空间页
  609. UserInfoDetailActivity.toUserInfoDetailActivity(MainActivity.this, userBase.getId(), null, UserInfoDetailActivity.SOURCE_FROM_RECOMMEND_USER);
  610. }
  611. } else {// 女用户进入聊天页
  612. ChatActivity.toChatActivity(MainActivity.this, userBase.getId(), userBase.getNickName(),
  613. image == null ? null : image.getThumbnailUrl());
  614. }
  615. }
  616. }
  617. }
  618. });
  619. mTvRecommendIgnore.setOnClickListener(new View.OnClickListener() {
  620. @Override
  621. public void onClick(View v) {
  622. // 隐藏推荐用户
  623. mLlRecommendUser.setVisibility(View.GONE);
  624. }
  625. });
  626. }
  627. @OnClick({R.id.main_tab_fate, R.id.main_tab_search, R.id.main_tab_mail, R.id.main_tab_nearby, R.id.main_tab_me})
  628. public void onClick(View view) {
  629. switch (view.getId()) {
  630. case R.id.main_tab_fate:
  631. mViewPager.setCurrentItem(TAB_INDEX_FATE);
  632. break;
  633. case R.id.main_tab_search:
  634. mViewPager.setCurrentItem(TAB_INDEX_SEARCH);
  635. break;
  636. case R.id.main_tab_mail:
  637. mViewPager.setCurrentItem(TAB_INDEX_MAIL);
  638. break;
  639. case R.id.main_tab_nearby:
  640. mViewPager.setCurrentItem(TAB_INDEX_NEARBY);
  641. break;
  642. case R.id.main_tab_me:
  643. mViewPager.setCurrentItem(TAB_INDEX_ME);
  644. break;
  645. }
  646. }
  647. /**
  648. * 请求定位信息
  649. */
  650. private void requestLocation() {
  651. mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  652. if (ContextCompat.checkSelfPermission(MainActivity.this,
  653. Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {
  654. // 请求android.permission.ACCESS_FINE_LOCATION
  655. ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_CODE_ACCESS_FINE_LOCATION);
  656. } else {
  657. if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {// Network定位
  658. mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 5, mLocationListener);
  659. } else if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {// GPS定位
  660. uploadLocation(mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
  661. }
  662. }
  663. }
  664. private LocationListener mLocationListener = new LocationListener() {
  665. @Override
  666. public void onLocationChanged(Location location) {
  667. uploadLocation(location);
  668. }
  669. @Override
  670. public void onStatusChanged(String provider, int status, Bundle extras) {
  671. }
  672. @Override
  673. public void onProviderEnabled(String provider) {
  674. }
  675. @Override
  676. public void onProviderDisabled(String provider) {
  677. }
  678. };
  679. @Override
  680. public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  681. if (requestCode == PERMISSION_CODE_ACCESS_FINE_LOCATION) {
  682. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {// 申请权限成功
  683. if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {// Network定位
  684. if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  685. // TODO: Consider calling
  686. // ActivityCompat#requestPermissions
  687. // here to request the missing permissions, and then overriding
  688. // public void onRequestPermissionsResult(int requestCode, String[] permissions,
  689. // int[] grantResults)
  690. // to handle the case where the user grants the permission. See the documentation
  691. // for ActivityCompat#requestPermissions for more details.
  692. return;
  693. }
  694. mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 5, mLocationListener);
  695. } else if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {// GPS定位
  696. uploadLocation(mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
  697. }
  698. }
  699. }
  700. }
  701. /**
  702. * 上传位置信息
  703. *
  704. * @param location 定位成功后的信息
  705. */
  706. private void uploadLocation(Location location) {
  707. if (location != null) {
  708. getLatitude = String.valueOf(location.getLatitude());
  709. getLongitude = String.valueOf(location.getLongitude());
  710. String country = UserInfoXml.getCountry();
  711. getAddress(getLatitude, getLongitude,"English", country);
  712. // Map<String, String> googleAddress = GoogleUtil.getGoogleAddress(getLatitude, getLongitude, "zh-TW", "Taiwan");
  713. // String province = googleAddress.get("province");
  714. // if(!TextUtils.isEmpty(province)){
  715. // if (!province.equals(UserInfoXml.getProvinceName())) {
  716. // UserInfoXml.setProvinceName(province);
  717. // getProvince = true;
  718. // }
  719. // }
  720. }else{
  721. // getAdapter();
  722. }
  723. }
  724. // 获取城市
  725. private void getAddress(String getLatitude, String getLongitude, final String language, final String country) {
  726. // 本地
  727. String url = "http://ditu.google.cn/maps/api/geocode/json?latlng="+ getLatitude + "," + getLongitude + "&&sensor=false&&language=";
  728. // 线上
  729. // String url = "http://ditu.google.com/maps/api/geocode/json?latlng="+ lat + "," + lng + "&&sensor=false&&language=";
  730. //获取国际化参数
  731. String localInfo = "en_US";
  732. url += localInfo; //拼接url地址
  733. String charset = "UTF-8";
  734. OkHttpUtils.get()
  735. .url(url)
  736. .build()
  737. .execute(new StringCallback() {
  738. @Override
  739. public void onError(Call call, Exception e, int id) {
  740. Log.v("Exception",e.toString());
  741. }
  742. @Override
  743. public void onResponse(String response, int id) {
  744. if (null != response) {
  745. JSONObject json = JSON.parseObject(response);// 转换为json数据
  746. JSONArray jsonArray = json.getJSONArray("results");
  747. Map<String, String> map = null;
  748. if (null != jsonArray && jsonArray.size() > 0) {// 增加验证
  749. JSONObject objResult = (JSONObject) jsonArray.get(0);
  750. JSONArray addressComponents = objResult.getJSONArray("address_components");
  751. //解析结果
  752. getByGoogleMap(addressComponents, objResult, language, country);
  753. }
  754. }
  755. }
  756. });
  757. }
  758. private void getByGoogleMap(JSONArray addressComponents, JSONObject objResult, String language, String country) {
  759. String countryResult="";
  760. String province="";
  761. String city="";
  762. if(addressComponents!=null&&addressComponents.size()>0){
  763. for(int i=0;i<addressComponents.size();i++){
  764. JSONObject obj = (JSONObject) addressComponents
  765. .get(i);
  766. JSONArray types = obj.getJSONArray("types");
  767. String type = (String)types.get(0);
  768. //获取目标解析单位的key
  769. String proviceKey = getGoogleProviceL1Key(country);
  770. if(type.equals(proviceKey)){
  771. province = obj.getString("long_name");// 州
  772. }else if(type.equals("administrative_area_level_2")){
  773. city = obj.getString("long_name");// 城市
  774. }else if (type.equals("country")){ //国家
  775. countryResult = obj.getString("long_name");
  776. }
  777. }
  778. // if(StringUtils.isBlank(province)){ //不是一级城市 取二级城市
  779. if(TextUtils.isEmpty(province)){ //不是一级城市 取二级城市
  780. province = city;
  781. }
  782. }
  783. String formatted_address = objResult.getString("formatted_address");
  784. Map<String, String> map = new HashMap<String, String>();
  785. map.put("city", city);
  786. map.put("formatted_address", formatted_address);
  787. map.put("province", province);
  788. map.put("country", countryResult);
  789. if (map != null) {
  790. String province2 = map.get("province");
  791. // 英国城市为空。。。
  792. if (!TextUtils.isEmpty(province2) && !province.equals(UserInfoXml.getProvinceName())) {
  793. UserInfoXml.setProvinceName(province2);
  794. getProvince = true;
  795. }
  796. if(LocationSuccess){
  797. LocationSuccess=false;
  798. getLocation(getLatitude, getLongitude, province);
  799. }
  800. }
  801. }
  802. private void getLocation(String getLatitude, String getLongitude, String province) {
  803. LocationInfo locationInfo = new LocationInfo();
  804. locationInfo.setAddrStr("");
  805. locationInfo.setProvince(province);
  806. locationInfo.setCity("");
  807. locationInfo.setCityCode("");
  808. locationInfo.setDistrict("");
  809. locationInfo.setStreet("");
  810. locationInfo.setStreetNumber("");
  811. locationInfo.setLatitude(getLatitude);
  812. locationInfo.setLongitude(getLongitude);
  813. Map<String, LocationInfo> map = new HashMap<String, LocationInfo>();
  814. map.put("locationInfo", locationInfo);
  815. OkHttpUtils.post()
  816. .url(IUrlConstant.URL_UPLOAD_LOCATION)
  817. .addHeader("token", PlatformInfoXml.getToken())
  818. .addParams("platformInfo", PlatformInfoXml.getPlatformJsonString())
  819. .addParams("locationInfo", JSON.toJSONString(map))
  820. .build()
  821. .execute(new Callback<BaseModel>() {
  822. @Override
  823. public BaseModel parseNetworkResponse(Response response, int id) throws Exception {
  824. String resultJson = response.body().string();
  825. if (!TextUtils.isEmpty(resultJson)) {
  826. return JSON.parseObject(resultJson, BaseModel.class);
  827. }
  828. return null;
  829. }
  830. @Override
  831. public void onError(Call call, Exception e, int id) {
  832. }
  833. @Override
  834. public void onResponse(BaseModel response, int id) {
  835. if (response != null) {
  836. String isSucceed = response.getIsSucceed();
  837. if (!TextUtils.isEmpty(isSucceed) && "1".equals(isSucceed)) {// 上传成功
  838. LogUtil.i(LogUtil.TAG_ZL, "上传位置信息成功");
  839. // getAdapter();
  840. // 发送事件,更新位置信息
  841. if(getProvince){
  842. EventBus.getDefault().post(new UpdateUserProvince());
  843. EventBus.getDefault().post(new MatchInfoChangeEvent());
  844. }
  845. }
  846. }
  847. }
  848. });
  849. }
  850. @Override
  851. protected void doRegister() {
  852. super.doRegister();
  853. EventBus.getDefault().register(this);
  854. }
  855. @Override
  856. protected void unregister() {
  857. super.unregister();
  858. EventBus.getDefault().unregister(this);
  859. }
  860. @Subscribe
  861. public void onEvent(NoSeeMeEvent event) {
  862. mViewPager.setCurrentItem(TAB_INDEX_FATE, false);
  863. }
  864. @Subscribe
  865. public void onEvent(OpenMailFragmentEvent event) {
  866. mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  867. }
  868. @Subscribe
  869. public void onEvent(HeadMsgEvent event) {
  870. mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  871. }
  872. @Subscribe
  873. public void onEvent(BaseOpenMailFragmentEvent event) {
  874. mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  875. }
  876. @Subscribe
  877. public void onEvent(RegistEvent event) {
  878. finish();
  879. }
  880. @Subscribe
  881. public void onEvent(UpdateMessageCountEvent event) {
  882. int unreadMsgCount = event.getUnreadMsgCount();
  883. /**有未读消息进行刷新**/
  884. // if(unreadMsgCount>currentUnreadMsgCount){
  885. // MessageFragment item = (MessageFragment)mainAdapter.getItem(2);
  886. // item.startFirstRefish();
  887. // }
  888. if (unreadMsgCount > 0) {
  889. mTvUnreadMsgCount.setVisibility(View.VISIBLE);
  890. mTvUnreadMsgCount.setText(String.valueOf(unreadMsgCount>99?99:unreadMsgCount));
  891. currentUnreadMsgCount=unreadMsgCount;
  892. } else {
  893. mTvUnreadMsgCount.setVisibility(View.GONE);
  894. }
  895. }
  896. @Subscribe
  897. public void onEvent(CloseMainActivityEvent event) {
  898. mTimerHandler.removeMessages(MSG_TYPE_HEAD_MSG);
  899. mTimerHandler.removeMessages(MSG_TYPE_HEAD_MSG_NEW);
  900. mTimerHandler.removeMessages(MSG_TYPE_RECOMMEND_USER);
  901. mTimerHandler.removeMessages(MSG_TYPE_HIDE_RECOMMEND_USER);
  902. finish();
  903. }
  904. private static class TimerHandler extends Handler {
  905. private WeakReference<MainActivity> mWeakReference;
  906. public TimerHandler(MainActivity mainActivity) {
  907. this.mWeakReference = new WeakReference<MainActivity>(mainActivity);
  908. }
  909. @Override
  910. public void handleMessage(Message msg) {
  911. final MainActivity mainActivity = mWeakReference.get();
  912. switch (msg.what) {
  913. case MSG_TYPE_LOAD_DATA:// 加载数据
  914. if (mainActivity != null) {
  915. mainActivity.loadData();
  916. }
  917. break;
  918. // case MSG_TYPE_HEAD_MSG:// 页眉刷新
  919. // if (mainActivity != null) {
  920. // mainActivity.getHeadMsg();
  921. // }
  922. // sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG, HEAD_MSG_REFRESH_PERIOD);
  923. // break;
  924. case MSG_TYPE_HEAD_MSG_NEW:// 新页眉刷新
  925. if (mainActivity != null) {
  926. mainActivity.getNewHeadMsg();
  927. }
  928. break;
  929. case MSG_TYPE_RECOMMEND_USER:// 推荐用户刷新
  930. int cycle = 0;
  931. if (mainActivity != null) {
  932. mainActivity.getRecommendUsr();
  933. cycle = mainActivity.cycle;
  934. }
  935. // sendEmptyMessageDelayed(MSG_TYPE_RECOMMEND_USER, cycle < 20 ? HEAD_MSG_REFRESH_PERIOD : cycle * 1000);
  936. break;
  937. case MSG_TYPE_SHOW_UNREAD_MSG:// 显示未读消息页眉
  938. // 先隐藏上一条
  939. if (mainActivity != null) {
  940. mainActivity.dismissWithAnim(mainActivity.mFlHeadMsgNew, mainActivity.mRlHeadMsgUnread);
  941. mainActivity.mFlHeadMsgNew.postDelayed(new Runnable() {
  942. @Override
  943. public void run() {
  944. // 如果存在下一条,则显示
  945. if (mainActivity.mNewHeadMsgNotice != null && mainActivity.mCurrDisplayItem < mainActivity.mNewHeadMsgNotice.getUnreadMsgBoxList().size() - 1) {
  946. mainActivity.mCurrDisplayItem++;
  947. mainActivity.setNewHeadMsg();
  948. } else {
  949. // 继续轮询
  950. sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  951. }
  952. }
  953. }, 500);
  954. }
  955. break;
  956. case MSG_TYPE_DISMISS_UNREAD_MSG:// 隐藏未读消息页眉
  957. if (mainActivity != null) {
  958. mainActivity.dismissWithAnim(mainActivity.mFlHeadMsgNew, mainActivity.mRlHeadMsgUnread);
  959. }
  960. break;
  961. case MSG_TYPE_HIDE_RECOMMEND_USER:// 隐藏推荐用户页眉
  962. // 隐藏上一条
  963. if (mainActivity != null) {
  964. mainActivity.dismissWithAnim(mainActivity.mLlRecommendUser, mainActivity.mLlRecommendUser);
  965. }
  966. sendEmptyMessageDelayed(MSG_TYPE_RECOMMEND_USER, HEAD_MSG_REFRESH_PERIOD);
  967. break;
  968. case MSG_TYPE_DISMISS_VISITOR:// 隐藏访客页眉
  969. if (mainActivity != null) {
  970. mainActivity.dismissWithAnim(mainActivity.mFlHeadMsgNew, mainActivity.mRlHeadMsgVisitor);
  971. }
  972. sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  973. break;
  974. }
  975. }
  976. }
  977. private static class MainAdapter extends FragmentPagerAdapter {
  978. private List<Fragment> fragments = new ArrayList<>();
  979. public MainAdapter(FragmentManager fm) {
  980. super(fm);
  981. fragments.add(new FateCardFragment());
  982. fragments.add(new SearchFragment());
  983. fragments.add(new MessageFragment());
  984. fragments.add(new NearbyFragment());
  985. fragments.add(new MeFragment());
  986. }
  987. @Override
  988. public Fragment getItem(int position) {
  989. return fragments.get(position);
  990. }
  991. @Override
  992. public int getCount() {
  993. return fragments.size();
  994. }
  995. }
  996. @Override
  997. protected void onStart() {
  998. super.onStart();
  999. isShake = true;
  1000. }
  1001. @Override
  1002. protected void onPause() {
  1003. super.onPause();
  1004. isShake = false;
  1005. }
  1006. @Override
  1007. protected void onRestart() {
  1008. super.onRestart();
  1009. isShake = true;
  1010. }
  1011. @Override
  1012. protected void onResume() {
  1013. super.onResume();
  1014. isShake = true;
  1015. }
  1016. // @Override
  1017. // protected void onStop() {
  1018. // super.onStop();
  1019. // isShake=false;
  1020. // }
  1021. /**
  1022. * 监听是否点击了home键将客户端推到后台
  1023. */
  1024. private BroadcastReceiver mHomeKeyEventReceiver = new BroadcastReceiver() {
  1025. String SYSTEM_REASON = "reason";
  1026. String SYSTEM_HOME_KEY = "homekey";
  1027. String SYSTEM_HOME_KEY_LONG = "recentapps";
  1028. @Override
  1029. public void onReceive(Context context, Intent intent) {
  1030. String action = intent.getAction();
  1031. if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
  1032. String reason = intent.getStringExtra(SYSTEM_REASON);
  1033. if (TextUtils.equals(reason, SYSTEM_HOME_KEY)) {
  1034. //表示按了home键,程序到了后台
  1035. isShake = false;
  1036. } else if (TextUtils.equals(reason, SYSTEM_HOME_KEY_LONG)) {
  1037. //表示长按home键,显示最近使用的程序列表
  1038. }
  1039. }
  1040. }
  1041. };
  1042. }
  1043. //
  1044. ///**
  1045. // * modified by zhangdroid on 2017-02-28
  1046. // */
  1047. //public class MainActivity extends BaseFragmentActivity {
  1048. // @BindView(R.id.viewPager)
  1049. // ScrollControlViewPager mViewPager;
  1050. // // 页眉
  1051. // @BindView(R.id.head_msg_container)
  1052. // RelativeLayout mRlHeadMsgContainer;
  1053. // @BindView(R.id.head_msg_content)
  1054. // TextView mTvHeadMsgContent;
  1055. // @BindView(R.id.head_msg_clear)
  1056. // ImageView mIvHeadMsgClear;
  1057. // // 新页眉
  1058. // @BindView(R.id.headMsg_container)
  1059. // FrameLayout mFlHeadMsgNew;
  1060. // @BindView(R.id.headMsg_unread)
  1061. // RelativeLayout mRlHeadMsgUnread;
  1062. // @BindView(R.id.headMsg_avatar)
  1063. // CircleImageView mIvHeadMsgAvatar;
  1064. // @BindView(R.id.headMsg_nickname)
  1065. // TextView mTvNickname;
  1066. // @BindView(R.id.headMsg_age)
  1067. // TextView mTvAge;
  1068. // @BindView(R.id.headMsg_height)
  1069. // TextView mTvHeight;
  1070. // @BindView(R.id.headMsg_content)
  1071. // TextView mTvMsgContent;
  1072. // @BindView(R.id.headMsg_check)
  1073. // TextView mTvMsgCheck;
  1074. // // 访客
  1075. // @BindView(R.id.headMsg_visitor)
  1076. // RelativeLayout mRlHeadMsgVisitor;
  1077. // @BindView(R.id.visitor_avatar)
  1078. // CircleImageView mIvVisitorAvatar;
  1079. // @BindView(R.id.visitor_content)
  1080. // TextView mTvVisitorContent;
  1081. // @BindView(R.id.visitor_ignore)
  1082. // TextView mTvVisitorIgnore;
  1083. // @BindView(R.id.visitor_look)
  1084. // TextView mTvVisitorLook;
  1085. // // 推荐用户
  1086. // @BindView(R.id.recommend_user_container)
  1087. // LinearLayout mLlRecommendUser;
  1088. // @BindView(R.id.recommend_user_avatar)
  1089. // CircleImageView mIvRecommendAvatar;
  1090. // @BindView(R.id.recommend_user_content)
  1091. // TextView mTvRecommendContent;
  1092. // @BindView(R.id.recommend_user_ignore)
  1093. // TextView mTvRecommendIgnore;
  1094. // @BindView(R.id.recommend_user_look)
  1095. // TextView mTvRecommendLook;
  1096. // // tab页
  1097. // @BindView(R.id.main_tab_fate)
  1098. // TextView mTvTabFate;
  1099. // @BindView(R.id.main_tab_search)
  1100. // TextView mTvTabSearch;
  1101. // @BindView(R.id.main_tab_mail)
  1102. // TextView mTvTabMail;
  1103. // @BindView(R.id.unread_msg_count)
  1104. // TextView mTvUnreadMsgCount;// 未读消息数
  1105. // @BindView(R.id.main_tab_nearby)
  1106. // TextView mTvTabNearby;
  1107. // @BindView(R.id.main_tab_me)
  1108. // TextView mTvTabMe;
  1109. //
  1110. // private static final int TAB_INDEX_FATE = 0;
  1111. // private static final int TAB_INDEX_SEARCH = 1;
  1112. // private static final int TAB_INDEX_MAIL = 2;
  1113. // private static final int TAB_INDEX_NEARBY = 3;
  1114. // private static final int TAB_INDEX_ME = 4;
  1115. // private boolean isShake = true;
  1116. // private static final int HEAD_MSG_REFRESH_PERIOD = 20 * 1000;
  1117. // private static final int MSG_TYPE_LOAD_DATA = 1;
  1118. // private static final int MSG_TYPE_HEAD_MSG = 2;
  1119. // private static final int MSG_TYPE_HEAD_MSG_NEW = 3;
  1120. // private static final int MSG_TYPE_RECOMMEND_USER = 4;
  1121. // private static final int MSG_TYPE_SHOW_UNREAD_MSG = 5;
  1122. // private static final int MSG_TYPE_DISMISS_UNREAD_MSG = 6;
  1123. // private static final int MSG_TYPE_DISMISS_VISITOR = 7;
  1124. // private Vibrator vibrator;
  1125. // private static final int PERMISSION_CODE_ACCESS_FINE_LOCATION = 0;
  1126. // private MainAdapter mainAdapter;
  1127. // private LocationManager mLocationManager;
  1128. // /**
  1129. // * 页眉对象缓存
  1130. // */
  1131. // private HeadMsgNotice mHeadMsgNotice;
  1132. // /**
  1133. // * 新页眉对象缓存
  1134. // */
  1135. // private NewHeadMsgNotice mNewHeadMsgNotice;
  1136. // /**
  1137. // * 推荐用户对象缓存
  1138. // */
  1139. // private RecommendUser mRecommendUser;
  1140. // /**
  1141. // * 新页眉最后一条未读消息毫秒数
  1142. // */
  1143. // private long mLastMsgTime;
  1144. // /**
  1145. // * 推荐用户轮询周期(秒)
  1146. // */
  1147. // private int cycle;
  1148. // /**
  1149. // * 新页眉中当前正在显示的未读消息索引
  1150. // */
  1151. // private int mCurrDisplayItem = 0;
  1152. // private TimerHandler mTimerHandler;
  1153. // private int currentUnreadMsgCount;
  1154. //
  1155. // @Override
  1156. // protected int getLayoutResId() {
  1157. // return R.layout.activity_main;
  1158. // }
  1159. //
  1160. // @Override
  1161. // protected void initViewsAndVariables() {
  1162. // // 设置状态栏
  1163. // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {// 5.0及以上
  1164. // View decorView = getWindow().getDecorView();
  1165. // decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
  1166. // // 设置状态栏背景
  1167. // getWindow().setStatusBarColor(getResources().getColor(R.color.main_color));
  1168. // } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {// 4.4
  1169. // getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  1170. // }
  1171. //
  1172. //// mViewPager.setAdapter(new MainAdapter(getSupportFragmentManager()));
  1173. // mainAdapter = new MainAdapter(getSupportFragmentManager());
  1174. // mViewPager.setAdapter(mainAdapter);
  1175. // mViewPager.setCanScroll(false);
  1176. // mViewPager.setOffscreenPageLimit(4);
  1177. // mViewPager.setCurrentItem(TAB_INDEX_FATE);
  1178. // mTvTabFate.setSelected(true);
  1179. // /**对viewPage的界面改变进行监听,当刷新聊天列表的界面开始刷新,刷出聊天列表界面停止刷新**/
  1180. // mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  1181. // @Override
  1182. // public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  1183. // }
  1184. // @Override
  1185. // public void onPageSelected(int position) {
  1186. // MessageFragment item = (MessageFragment)mainAdapter.getItem(2);
  1187. // if(position!=2){
  1188. // item.stopRefish();
  1189. // }else{
  1190. // item.startFirstRefish();
  1191. // }
  1192. //
  1193. // }
  1194. // @Override
  1195. // public void onPageScrollStateChanged(int state) {
  1196. //
  1197. // }
  1198. // });
  1199. //
  1200. //
  1201. //
  1202. // // 获取位置信息并上传
  1203. // requestLocation();
  1204. // // 延时加载数据
  1205. // mTimerHandler = new TimerHandler(this);
  1206. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_LOAD_DATA, 500);
  1207. // }
  1208. //
  1209. // /**
  1210. // * 加载页眉和推荐用户
  1211. // */
  1212. // private void loadData() {
  1213. // // 获取页眉
  1214. // if (UserInfoXml.isShowHeadMsg()) {
  1215. // getHeadMsg();
  1216. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG, HEAD_MSG_REFRESH_PERIOD);
  1217. // }
  1218. // // 获取新页眉
  1219. // if (UserInfoXml.isShowHeadMsgNew()) {
  1220. // getNewHeadMsg();
  1221. // }
  1222. // // 获取推荐用户
  1223. // if (UserInfoXml.isShowRecommendUser()) {
  1224. // getRecommendUsr();
  1225. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_RECOMMEND_USER, HEAD_MSG_REFRESH_PERIOD);
  1226. // }
  1227. // }
  1228. //
  1229. // /**
  1230. // * 获取页眉
  1231. // */
  1232. // private void getHeadMsg() {
  1233. // CommonRequestUtil.getHeadMsg(new CommonRequestUtil.OnGetHeadMsgListener() {
  1234. // @Override
  1235. // public void onSuccess(HeadMsgNotice headMsgNotice) {
  1236. // if (headMsgNotice != null) {
  1237. // mHeadMsgNotice = headMsgNotice;
  1238. // String message = headMsgNotice.getMessage();
  1239. // if (mViewPager.getCurrentItem() != TAB_INDEX_MAIL && !TextUtils.isEmpty(message)) {
  1240. // mRlHeadMsgContainer.setVisibility(View.VISIBLE);
  1241. // mTvHeadMsgContent.setText(message);
  1242. // } else {
  1243. // mRlHeadMsgContainer.setVisibility(View.GONE);
  1244. // }
  1245. // String noticeType = headMsgNotice.getNoticeType();
  1246. // if (!TextUtils.isEmpty(noticeType) && "1".equals(noticeType)) {
  1247. // // 有未读消息时刷新消息列表
  1248. // EventBus.getDefault().post(new MessageChangedEvent());
  1249. // }
  1250. // }
  1251. // }
  1252. //
  1253. // @Override
  1254. // public void onFail() {
  1255. //
  1256. // }
  1257. // });
  1258. // }
  1259. //
  1260. // /**
  1261. // * 获取新页眉
  1262. // */
  1263. // private void getNewHeadMsg() {
  1264. // CommonRequestUtil.getNewHeadMsg(mLastMsgTime, new CommonRequestUtil.OnGetNewHeadMsgListener() {
  1265. // @Override
  1266. // public void onSuccess(NewHeadMsgNotice newHeadMsgNotice) {
  1267. // if (newHeadMsgNotice != null) {
  1268. // mNewHeadMsgNotice = newHeadMsgNotice;
  1269. // mLastMsgTime = newHeadMsgNotice.getLastMsgTime();
  1270. // mCurrDisplayItem = 0;
  1271. // String noticeType = newHeadMsgNotice.getNoticeType();
  1272. // if (!TextUtils.isEmpty(noticeType)) {
  1273. // switch (noticeType) {
  1274. // case "0":// 没有页眉,继续轮询
  1275. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  1276. // break;
  1277. // case "1":// 未读消息
  1278. // // 刷新聊天列表
  1279. // EventBus.getDefault().post(new MessageChangedEvent());
  1280. // setNewHeadMsg();
  1281. // break;
  1282. //
  1283. // case "2":// 访客
  1284. // FateUser fateUser = newHeadMsgNotice.getRemoteYuanfenUserBase();
  1285. // if (fateUser != null) {
  1286. // UserBase userBase = fateUser.getUserBaseEnglish();
  1287. // if (userBase != null) {
  1288. // ImageLoaderUtil.getInstance().loadImage(MainActivity.this, new ImageLoader.Builder()
  1289. // .url(userBase.getImage().getThumbnailUrl()).imageView(mIvVisitorAvatar).build());
  1290. // mTvVisitorContent.setText(getString(R.string.visitor_tip, userBase.getNickName()));
  1291. // }
  1292. // }
  1293. // mRlHeadMsgUnread.setVisibility(View.GONE);
  1294. // mRlHeadMsgVisitor.setVisibility(View.VISIBLE);
  1295. // showWithAnim(mFlHeadMsgNew);
  1296. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_DISMISS_VISITOR, newHeadMsgNotice.getDisplaySecond() * 1000);
  1297. // break;
  1298. // }
  1299. // }
  1300. // }
  1301. // }
  1302. //
  1303. // @Override
  1304. // public void onFail() {
  1305. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  1306. // }
  1307. // });
  1308. // }
  1309. //
  1310. // /**
  1311. // * 按照未读消息列表顺序显示未读信
  1312. // */
  1313. // private void setNewHeadMsg() {
  1314. // if (mNewHeadMsgNotice != null) {
  1315. // List<MsgBox> msgBoxList = mNewHeadMsgNotice.getUnreadMsgBoxList();
  1316. // if (!Util.isListEmpty(msgBoxList) && mCurrDisplayItem < msgBoxList.size()) {
  1317. // MsgBox msgBox = msgBoxList.get(mCurrDisplayItem);
  1318. // if (msgBox != null) {
  1319. // UserBase userBase = msgBox.getUserBaseEnglish();
  1320. // if (userBase != null) {
  1321. // Image image = userBase.getImage();
  1322. // if (image != null) {
  1323. // ImageLoaderUtil.getInstance().loadImage(MainActivity.this, new ImageLoader.Builder()
  1324. // .url(image.getThumbnailUrl()).imageView(mIvHeadMsgAvatar).build());
  1325. // }
  1326. // mTvNickname.setText(userBase.getNickName());
  1327. // mTvAge.setText(TextUtils.concat(String.valueOf(userBase.getAge()), getString(R.string.age)));
  1328. // mTvAge.setSelected(userBase.getSex() == 0);
  1329. // mTvHeight.setText(HeightUtils.getInchCmByCm(userBase.getHeightCm()));
  1330. // }
  1331. // String msgContent = msgBox.getMsg();
  1332. // if (!TextUtils.isEmpty(msgContent)) {
  1333. // mTvMsgContent.setText(msgContent);
  1334. // }
  1335. // mRlHeadMsgUnread.setVisibility(View.VISIBLE);
  1336. // mRlHeadMsgVisitor.setVisibility(View.GONE);
  1337. // showWithAnim(mFlHeadMsgNew);
  1338. // }
  1339. // // 一段时间后显示下一条未读消息
  1340. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_SHOW_UNREAD_MSG, mNewHeadMsgNotice.getDisplaySecond() * 1000);
  1341. // }
  1342. // }
  1343. // }
  1344. //
  1345. // private void showWithAnim(View view) {
  1346. // if (isShake) {
  1347. // view.setVisibility(View.VISIBLE);
  1348. // vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
  1349. // vibrator.vibrate(200);
  1350. // view.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim_in));
  1351. // }
  1352. // }
  1353. //
  1354. // private void dismissWithAnim(final View view, final View view2) {
  1355. // Animation outAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.push_bottom_out);
  1356. // view.startAnimation(outAnimation);
  1357. // outAnimation.setAnimationListener(new Animation.AnimationListener() {
  1358. // @Override
  1359. // public void onAnimationStart(Animation animation) {
  1360. //
  1361. // }
  1362. //
  1363. // @Override
  1364. // public void onAnimationEnd(Animation animation) {
  1365. // view.setVisibility(View.GONE);
  1366. // view2.setVisibility(View.GONE);
  1367. // }
  1368. //
  1369. // @Override
  1370. // public void onAnimationRepeat(Animation animation) {
  1371. //
  1372. // }
  1373. // });
  1374. // }
  1375. //
  1376. // /**
  1377. // * 获取推荐用户
  1378. // */
  1379. // private void getRecommendUsr() {
  1380. // CommonRequestUtil.getRecommendUser(cycle, new CommonRequestUtil.OnGetRecommendUserListener() {
  1381. // @Override
  1382. // public void onSuccess(RecommendUser recommendUser) {
  1383. // if (recommendUser != null) {
  1384. // mRecommendUser = recommendUser;
  1385. // cycle = recommendUser.getCycle();
  1386. // User user = recommendUser.getUser();
  1387. // if (user != null) {
  1388. // UserBase userBase = user.getUserBaseEnglish();
  1389. // if (userBase != null) {
  1390. // // 显示推荐用户
  1391. // mLlRecommendUser.setVisibility(View.VISIBLE);
  1392. // mTvRecommendContent.setText(TextUtils.concat(userBase.getNickName(), " ", recommendUser.getSentence()));
  1393. // ImageLoaderUtil.getInstance().loadImage(MainActivity.this, new ImageLoader.Builder()
  1394. // .url(userBase.getImage().getThumbnailUrl()).imageView(mIvRecommendAvatar).build());
  1395. // }
  1396. // }
  1397. // }
  1398. // }
  1399. //
  1400. // @Override
  1401. // public void onFail() {
  1402. // }
  1403. // });
  1404. // }
  1405. //
  1406. // @Override
  1407. // protected void addListeners() {
  1408. // mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  1409. // @Override
  1410. // public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  1411. // }
  1412. //
  1413. // @Override
  1414. // public void onPageSelected(int position) {
  1415. // switch (position) {
  1416. // case TAB_INDEX_FATE:
  1417. // mTvTabFate.setSelected(true);
  1418. // mTvTabSearch.setSelected(false);
  1419. // mTvTabMail.setSelected(false);
  1420. // mTvTabNearby.setSelected(false);
  1421. // mTvTabMe.setSelected(false);
  1422. // break;
  1423. //
  1424. // case TAB_INDEX_SEARCH:
  1425. // mTvTabFate.setSelected(false);
  1426. // mTvTabSearch.setSelected(true);
  1427. // mTvTabMail.setSelected(false);
  1428. // mTvTabNearby.setSelected(false);
  1429. // mTvTabMe.setSelected(false);
  1430. // break;
  1431. //
  1432. // case TAB_INDEX_MAIL:
  1433. // mTvTabFate.setSelected(false);
  1434. // mTvTabSearch.setSelected(false);
  1435. // mTvTabMail.setSelected(true);
  1436. // mTvTabNearby.setSelected(false);
  1437. // mTvTabMe.setSelected(false);
  1438. // // 信箱tab页不显示页眉
  1439. // if (mRlHeadMsgContainer.isShown()) {
  1440. // mRlHeadMsgContainer.setVisibility(View.GONE);
  1441. // }
  1442. // // 隐藏新页眉
  1443. // if (mFlHeadMsgNew.isShown()) {
  1444. // mFlHeadMsgNew.setVisibility(View.GONE);
  1445. // if (mTimerHandler != null) {
  1446. // mTimerHandler.removeMessages(MSG_TYPE_SHOW_UNREAD_MSG);
  1447. // }
  1448. // }
  1449. // break;
  1450. //
  1451. // case TAB_INDEX_NEARBY:
  1452. // mTvTabFate.setSelected(false);
  1453. // mTvTabSearch.setSelected(false);
  1454. // mTvTabMail.setSelected(false);
  1455. // mTvTabNearby.setSelected(true);
  1456. // mTvTabMe.setSelected(false);
  1457. // break;
  1458. //
  1459. // case TAB_INDEX_ME:
  1460. // mTvTabFate.setSelected(false);
  1461. // mTvTabSearch.setSelected(false);
  1462. // mTvTabMail.setSelected(false);
  1463. // mTvTabNearby.setSelected(false);
  1464. // mTvTabMe.setSelected(true);
  1465. // break;
  1466. // }
  1467. // }
  1468. //
  1469. // @Override
  1470. // public void onPageScrollStateChanged(int state) {
  1471. //
  1472. // }
  1473. // });
  1474. // // 查看页眉消息
  1475. // mRlHeadMsgContainer.setOnClickListener(new View.OnClickListener() {
  1476. // @Override
  1477. // public void onClick(View v) {
  1478. // if (mHeadMsgNotice != null) {
  1479. // mRlHeadMsgContainer.setVisibility(View.GONE);
  1480. // String noticeType = mHeadMsgNotice.getNoticeType();
  1481. // if (!TextUtils.isEmpty(noticeType)) {
  1482. // switch (noticeType) {
  1483. // case "1": // 未读消息
  1484. // if (mViewPager.getCurrentItem() != TAB_INDEX_MAIL) {
  1485. // mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  1486. // }
  1487. // break;
  1488. //
  1489. // case "2":// 正在看我
  1490. // UserInfoDetailActivity.toUserInfoDetailActivity(MainActivity.this, mHeadMsgNotice.getRemoteUserId(), null, UserInfoDetailActivity.SOURCE_HEAD_MSG);
  1491. // break;
  1492. // }
  1493. // }
  1494. // }
  1495. // }
  1496. // });
  1497. // mIvHeadMsgClear.setOnClickListener(new View.OnClickListener() {
  1498. // @Override
  1499. // public void onClick(View v) {
  1500. // mRlHeadMsgContainer.setVisibility(View.GONE);
  1501. // }
  1502. // });
  1503. // // 新页眉
  1504. // mTvMsgCheck.setOnClickListener(new View.OnClickListener() {
  1505. //
  1506. // @Override
  1507. // public void onClick(View v) {
  1508. // // 查看未读消息,进入聊天页面
  1509. // mFlHeadMsgNew.setVisibility(View.GONE);
  1510. // if (mNewHeadMsgNotice != null && mCurrDisplayItem < mNewHeadMsgNotice.getUnreadMsgBoxList().size()) {
  1511. // List<MsgBox> msgBoxList = mNewHeadMsgNotice.getUnreadMsgBoxList();
  1512. // if (!Util.isListEmpty(msgBoxList)) {
  1513. // MsgBox msgBox = msgBoxList.get(mCurrDisplayItem);
  1514. // if (msgBox != null) {
  1515. // UserBase userBase = msgBox.getUserBaseEnglish();
  1516. // if (userBase != null) {
  1517. // ChatActivity.toChatActivity(MainActivity.this, userBase.getId(), userBase.getNickName(), userBase.getImage().getThumbnailUrl());
  1518. // }
  1519. // }
  1520. // }
  1521. // }
  1522. // }
  1523. // });
  1524. // mTvVisitorLook.setOnClickListener(new View.OnClickListener() {
  1525. // @Override
  1526. // public void onClick(View v) {
  1527. // // 隐藏新页眉
  1528. // mRlHeadMsgVisitor.setVisibility(View.GONE);
  1529. // mFlHeadMsgNew.setVisibility(View.GONE);
  1530. // // 查看用户详情
  1531. // if (mNewHeadMsgNotice != null) {
  1532. // FateUser fateUser = mNewHeadMsgNotice.getRemoteYuanfenUserBase();
  1533. // if (fateUser != null) {
  1534. // UserBase userBase = fateUser.getUserBaseEnglish();
  1535. // if (userBase != null) {
  1536. // UserInfoDetailActivity.toUserInfoDetailActivity(MainActivity.this, userBase.getId(), null, UserInfoDetailActivity.SOURCE_HEAD_MSG);
  1537. // }
  1538. // }
  1539. // }
  1540. // }
  1541. // });
  1542. // mTvVisitorIgnore.setOnClickListener(new View.OnClickListener() {
  1543. // @Override
  1544. // public void onClick(View v) {
  1545. // // 隐藏新页眉
  1546. // mRlHeadMsgVisitor.setVisibility(View.GONE);
  1547. // mFlHeadMsgNew.setVisibility(View.GONE);
  1548. // }
  1549. // });
  1550. // // 推荐用户
  1551. // mTvRecommendLook.setOnClickListener(new View.OnClickListener() {
  1552. // @Override
  1553. // public void onClick(View v) {
  1554. // if (mRecommendUser != null) {
  1555. // UserBase userBase = mRecommendUser.getUser().getUserBaseEnglish();
  1556. // if (userBase != null) {
  1557. // // 隐藏推荐用户
  1558. // mLlRecommendUser.setVisibility(View.GONE);
  1559. // Image image = userBase.getImage();
  1560. // if (UserInfoXml.isMale()) {
  1561. // if (UserInfoXml.isMonthly()) {// 已付费男用户进入聊天页
  1562. // ChatActivity.toChatActivity(MainActivity.this, userBase.getId(), userBase.getNickName(),
  1563. // image == null ? null : image.getThumbnailUrl());
  1564. // } else {// 未付费男用户,进入对方空间页
  1565. // UserInfoDetailActivity.toUserInfoDetailActivity(MainActivity.this, userBase.getId(), null, UserInfoDetailActivity.SOURCE_FROM_RECOMMEND_USER);
  1566. // }
  1567. // } else {// 女用户进入聊天页
  1568. // ChatActivity.toChatActivity(MainActivity.this, userBase.getId(), userBase.getNickName(),
  1569. // image == null ? null : image.getThumbnailUrl());
  1570. // }
  1571. // }
  1572. // }
  1573. // }
  1574. // });
  1575. // mTvRecommendIgnore.setOnClickListener(new View.OnClickListener() {
  1576. // @Override
  1577. // public void onClick(View v) {
  1578. // // 隐藏推荐用户
  1579. // mLlRecommendUser.setVisibility(View.GONE);
  1580. // }
  1581. // });
  1582. // }
  1583. //
  1584. // @OnClick({R.id.main_tab_fate, R.id.main_tab_search, R.id.main_tab_mail, R.id.main_tab_nearby, R.id.main_tab_me})
  1585. // public void onClick(View view) {
  1586. // switch (view.getId()) {
  1587. // case R.id.main_tab_fate:
  1588. // mViewPager.setCurrentItem(TAB_INDEX_FATE);
  1589. // break;
  1590. //
  1591. // case R.id.main_tab_search:
  1592. // mViewPager.setCurrentItem(TAB_INDEX_SEARCH);
  1593. // break;
  1594. //
  1595. // case R.id.main_tab_mail:
  1596. // mViewPager.setCurrentItem(TAB_INDEX_MAIL);
  1597. // break;
  1598. //
  1599. // case R.id.main_tab_nearby:
  1600. // mViewPager.setCurrentItem(TAB_INDEX_NEARBY);
  1601. // break;
  1602. //
  1603. // case R.id.main_tab_me:
  1604. // mViewPager.setCurrentItem(TAB_INDEX_ME);
  1605. // break;
  1606. // }
  1607. // }
  1608. //
  1609. // /**
  1610. // * 请求定位信息
  1611. // */
  1612. // private void requestLocation() {
  1613. // mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  1614. // if (ContextCompat.checkSelfPermission(MainActivity.this,
  1615. // Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {
  1616. // // 请求android.permission.ACCESS_FINE_LOCATION
  1617. // ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_CODE_ACCESS_FINE_LOCATION);
  1618. // } else {
  1619. // if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {// Network定位
  1620. // mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 5, mLocationListener);
  1621. // } else if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {// GPS定位
  1622. // uploadLocation(mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
  1623. // }
  1624. // }
  1625. // }
  1626. //
  1627. // private LocationListener mLocationListener = new LocationListener() {
  1628. //
  1629. // @Override
  1630. // public void onLocationChanged(Location location) {
  1631. // uploadLocation(location);
  1632. // }
  1633. //
  1634. // @Override
  1635. // public void onStatusChanged(String provider, int status, Bundle extras) {
  1636. // }
  1637. //
  1638. // @Override
  1639. // public void onProviderEnabled(String provider) {
  1640. // }
  1641. //
  1642. // @Override
  1643. // public void onProviderDisabled(String provider) {
  1644. // }
  1645. // };
  1646. //
  1647. // @Override
  1648. // public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  1649. // if (requestCode == PERMISSION_CODE_ACCESS_FINE_LOCATION) {
  1650. // if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {// 申请权限成功
  1651. // if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {// Network定位
  1652. // if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  1653. // // TODO: Consider calling
  1654. // // ActivityCompat#requestPermissions
  1655. // // here to request the missing permissions, and then overriding
  1656. // // public void onRequestPermissionsResult(int requestCode, String[] permissions,
  1657. // // int[] grantResults)
  1658. // // to handle the case where the user grants the permission. See the documentation
  1659. // // for ActivityCompat#requestPermissions for more details.
  1660. // return;
  1661. // }
  1662. // mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 5, mLocationListener);
  1663. // } else if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {// GPS定位
  1664. // uploadLocation(mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
  1665. // }
  1666. // }
  1667. // }
  1668. // }
  1669. //
  1670. // /**
  1671. // * 上传位置信息
  1672. // *
  1673. // * @param location 定位成功后的信息
  1674. // */
  1675. // private void uploadLocation(Location location) {
  1676. // if (location != null) {
  1677. // LocationInfo locationInfo = new LocationInfo();
  1678. // locationInfo.setAddrStr("");
  1679. // locationInfo.setProvince("");
  1680. // locationInfo.setCity("");
  1681. // locationInfo.setCityCode("");
  1682. // locationInfo.setDistrict("");
  1683. // locationInfo.setStreet("");
  1684. // locationInfo.setStreetNumber("");
  1685. // locationInfo.setLatitude(String.valueOf(location.getLatitude()));
  1686. // locationInfo.setLongitude(String.valueOf(location.getLongitude()));
  1687. // Map<String, LocationInfo> map = new HashMap<String, LocationInfo>();
  1688. // map.put("locationInfo", locationInfo);
  1689. // OkHttpUtils.post()
  1690. // .url(IUrlConstant.URL_UPLOAD_LOCATION)
  1691. // .addHeader("token", PlatformInfoXml.getToken())
  1692. // .addParams("platformInfo", PlatformInfoXml.getPlatformJsonString())
  1693. // .addParams("locationInfo", JSON.toJSONString(map))
  1694. // .build()
  1695. // .execute(new Callback<BaseModel>() {
  1696. // @Override
  1697. // public BaseModel parseNetworkResponse(Response response, int id) throws Exception {
  1698. // String resultJson = response.body().string();
  1699. // if (!TextUtils.isEmpty(resultJson)) {
  1700. // return JSON.parseObject(resultJson, BaseModel.class);
  1701. // }
  1702. // return null;
  1703. // }
  1704. //
  1705. // @Override
  1706. // public void onError(Call call, Exception e, int id) {
  1707. // }
  1708. //
  1709. // @Override
  1710. // public void onResponse(BaseModel response, int id) {
  1711. // if (response != null) {
  1712. // String isSucceed = response.getIsSucceed();
  1713. // if (!TextUtils.isEmpty(isSucceed) && "1".equals(isSucceed)) {// 上传成功
  1714. // LogUtil.i(LogUtil.TAG_ZL, "上传位置信息成功");
  1715. // }
  1716. // }
  1717. // }
  1718. // });
  1719. // }
  1720. // }
  1721. //
  1722. // @Override
  1723. // protected void doRegister() {
  1724. // super.doRegister();
  1725. // EventBus.getDefault().register(this);
  1726. // }
  1727. //
  1728. // @Override
  1729. // protected void unregister() {
  1730. // super.unregister();
  1731. // EventBus.getDefault().unregister(this);
  1732. // }
  1733. //
  1734. // @Subscribe
  1735. // public void onEvent(NoSeeMeEvent event) {
  1736. // mViewPager.setCurrentItem(TAB_INDEX_FATE, false);
  1737. // }
  1738. //
  1739. // @Subscribe
  1740. // public void onEvent(OpenMailFragmentEvent event) {
  1741. // mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  1742. // }
  1743. //
  1744. // @Subscribe
  1745. // public void onEvent(HeadMsgEvent event) {
  1746. // mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  1747. // }
  1748. //
  1749. // @Subscribe
  1750. // public void onEvent(BaseOpenMailFragmentEvent event) {
  1751. // mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  1752. // }
  1753. //
  1754. // @Subscribe
  1755. // public void onEvent(RegistEvent event) {
  1756. // finish();
  1757. // }
  1758. //
  1759. // @Subscribe
  1760. // public void onEvent(UpdateMessageCountEvent event) {
  1761. //
  1762. // int unreadMsgCount = event.getUnreadMsgCount();
  1763. // /**有未读消息进行刷新**/
  1764. // if(unreadMsgCount>currentUnreadMsgCount){
  1765. // MessageFragment item = (MessageFragment)mainAdapter.getItem(2);
  1766. // item.startFirstRefish();
  1767. // }
  1768. // if (unreadMsgCount > 0) {
  1769. // mTvUnreadMsgCount.setVisibility(View.VISIBLE);
  1770. // mTvUnreadMsgCount.setText(String.valueOf(unreadMsgCount));
  1771. // currentUnreadMsgCount=unreadMsgCount;
  1772. // } else {
  1773. // mTvUnreadMsgCount.setVisibility(View.GONE);
  1774. // }
  1775. //// int unreadMsgCount = event.getUnreadMsgCount();
  1776. //// if (unreadMsgCount > 0) {
  1777. //// mTvUnreadMsgCount.setVisibility(View.VISIBLE);
  1778. //// mTvUnreadMsgCount.setText(String.valueOf(unreadMsgCount));
  1779. //// } else {
  1780. //// mTvUnreadMsgCount.setVisibility(View.GONE);
  1781. //// }
  1782. // }
  1783. //
  1784. // @Subscribe
  1785. // public void onEvent(CloseMainActivityEvent event) {
  1786. // mTimerHandler.removeMessages(MSG_TYPE_HEAD_MSG);
  1787. // mTimerHandler.removeMessages(MSG_TYPE_HEAD_MSG_NEW);
  1788. // mTimerHandler.removeMessages(MSG_TYPE_RECOMMEND_USER);
  1789. // finish();
  1790. // }
  1791. //
  1792. // private static class TimerHandler extends Handler {
  1793. // private WeakReference<MainActivity> mWeakReference;
  1794. //
  1795. // public TimerHandler(MainActivity mainActivity) {
  1796. // this.mWeakReference = new WeakReference<MainActivity>(mainActivity);
  1797. // }
  1798. //
  1799. // @Override
  1800. // public void handleMessage(Message msg) {
  1801. // final MainActivity mainActivity = mWeakReference.get();
  1802. // switch (msg.what) {
  1803. // case MSG_TYPE_LOAD_DATA:// 加载数据
  1804. // if (mainActivity != null) {
  1805. // mainActivity.loadData();
  1806. // }
  1807. // break;
  1808. //
  1809. // case MSG_TYPE_HEAD_MSG:// 页眉刷新
  1810. // if (mainActivity != null) {
  1811. // mainActivity.getHeadMsg();
  1812. // }
  1813. // sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG, HEAD_MSG_REFRESH_PERIOD);
  1814. // break;
  1815. // case MSG_TYPE_HEAD_MSG_NEW:// 新页眉刷新
  1816. // if (mainActivity != null) {
  1817. // mainActivity.getNewHeadMsg();
  1818. // }
  1819. // break;
  1820. // case MSG_TYPE_RECOMMEND_USER:// 推荐用户刷新
  1821. // int cycle = 0;
  1822. // if (mainActivity != null) {
  1823. // mainActivity.getRecommendUsr();
  1824. // cycle = mainActivity.cycle;
  1825. // }
  1826. // sendEmptyMessageDelayed(MSG_TYPE_RECOMMEND_USER, cycle < 20 ? HEAD_MSG_REFRESH_PERIOD : cycle * 1000);
  1827. // break;
  1828. //
  1829. // case MSG_TYPE_SHOW_UNREAD_MSG:// 显示未读消息页眉
  1830. // // 先隐藏上一条
  1831. // if (mainActivity != null) {
  1832. // mainActivity.dismissWithAnim(mainActivity.mFlHeadMsgNew, mainActivity.mRlHeadMsgUnread);
  1833. // mainActivity.mFlHeadMsgNew.postDelayed(new Runnable() {
  1834. // @Override
  1835. // public void run() {
  1836. // // 如果存在下一条,则显示
  1837. // if (mainActivity.mNewHeadMsgNotice != null && mainActivity.mCurrDisplayItem < mainActivity.mNewHeadMsgNotice.getUnreadMsgBoxList().size() - 1) {
  1838. // mainActivity.mCurrDisplayItem++;
  1839. // mainActivity.setNewHeadMsg();
  1840. // } else {// 继续轮询
  1841. // sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  1842. // }
  1843. // }
  1844. // }, 500);
  1845. // }
  1846. // break;
  1847. // case MSG_TYPE_DISMISS_UNREAD_MSG:// 隐藏未读消息页眉
  1848. // if (mainActivity != null) {
  1849. // mainActivity.dismissWithAnim(mainActivity.mFlHeadMsgNew, mainActivity.mRlHeadMsgUnread);
  1850. // }
  1851. // break;
  1852. // case MSG_TYPE_DISMISS_VISITOR:// 隐藏访客页眉
  1853. // if (mainActivity != null) {
  1854. // mainActivity.dismissWithAnim(mainActivity.mFlHeadMsgNew, mainActivity.mRlHeadMsgVisitor);
  1855. // }
  1856. // sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  1857. // break;
  1858. // }
  1859. // }
  1860. //
  1861. // }
  1862. //
  1863. // private static class MainAdapter extends FragmentPagerAdapter {
  1864. // private List<Fragment> fragments = new ArrayList<>();
  1865. //
  1866. // public MainAdapter(FragmentManager fm) {
  1867. // super(fm);
  1868. // fragments.add(new FateCardFragment());
  1869. // fragments.add(new SearchFragment());
  1870. // fragments.add(new MessageFragment());
  1871. // fragments.add(new NearbyFragment());
  1872. // fragments.add(new MeFragment());
  1873. // }
  1874. //
  1875. // @Override
  1876. // public Fragment getItem(int position) {
  1877. // return fragments.get(position);
  1878. // }
  1879. //
  1880. // @Override
  1881. // public int getCount() {
  1882. // return fragments.size();
  1883. // }
  1884. // }
  1885. // @Override
  1886. // protected void onStart() {
  1887. // super.onStart();
  1888. // isShake = true;
  1889. // }
  1890. //
  1891. // @Override
  1892. // protected void onPause() {
  1893. // super.onPause();
  1894. // isShake = false;
  1895. // }
  1896. //
  1897. // @Override
  1898. // protected void onRestart() {
  1899. // super.onRestart();
  1900. // isShake = true;
  1901. // }
  1902. // /**
  1903. // * 监听是否点击了home键将客户端推到后台
  1904. // */
  1905. // private BroadcastReceiver mHomeKeyEventReceiver = new BroadcastReceiver() {
  1906. // String SYSTEM_REASON = "reason";
  1907. // String SYSTEM_HOME_KEY = "homekey";
  1908. // String SYSTEM_HOME_KEY_LONG = "recentapps";
  1909. //
  1910. // @Override
  1911. // public void onReceive(Context context, Intent intent) {
  1912. // String action = intent.getAction();
  1913. // if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
  1914. // String reason = intent.getStringExtra(SYSTEM_REASON);
  1915. // if (TextUtils.equals(reason, SYSTEM_HOME_KEY)) {
  1916. // //表示按了home键,程序到了后台
  1917. // isShake = false;
  1918. // } else if (TextUtils.equals(reason, SYSTEM_HOME_KEY_LONG)) {
  1919. // //表示长按home键,显示最近使用的程序列表
  1920. // }
  1921. // }
  1922. // }
  1923. // };
  1924. //}