|
|
@@ -9,6 +9,7 @@ import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.view.Window;
|
|
|
@@ -23,6 +24,7 @@ import com.netease.nim.uikit.ContextCache;
|
|
|
import com.netease.nim.uikit.common.media.picker.PickImageHelper;
|
|
|
import com.netease.nim.uikit.common.media.picker.activity.PickImageActivity;
|
|
|
import com.netease.nim.uikit.common.media.picker.model.PhotoInfo;
|
|
|
+import com.netease.nim.uikit.common.ui.imageview.HeadImageView;
|
|
|
import com.netease.nimlib.sdk.NIMClient;
|
|
|
import com.netease.nimlib.sdk.RequestCallback;
|
|
|
import com.netease.nimlib.sdk.uinfo.UserService;
|
|
|
@@ -33,6 +35,7 @@ import com.sheishuo.app.cache.AccountCache;
|
|
|
import com.sheishuo.app.R;
|
|
|
import com.sheishuo.app.SheishuoApplication;
|
|
|
import com.sheishuo.app.cache.SocialInfoCache;
|
|
|
+import com.sheishuo.app.common.beans.CircleUnreadBean;
|
|
|
import com.sheishuo.app.common.beans.SocialInfoBean;
|
|
|
import com.sheishuo.app.common.util.net.INet;
|
|
|
import com.sheishuo.app.common.util.net.NetImpl;
|
|
|
@@ -46,12 +49,17 @@ import com.sheishuo.app.core_module.circle.activity.NewTweetingActivity;
|
|
|
import com.sheishuo.app.common.beans.CircleBean;
|
|
|
import com.sheishuo.app.common.views.BaseToolbar;
|
|
|
import com.sheishuo.app.core_module.mine.view.ui.activity.UserInfoDetailActivity;
|
|
|
+import com.sheishuo.app.main.activity.CircleMessageActivity;
|
|
|
import com.sheishuo.app.main.activity.MainActivity;
|
|
|
import com.sheishuo.app.main.adapter.CircleListAdapter;
|
|
|
import com.sheishuo.app.main.adapter.OnCircleItemClickListener;
|
|
|
import com.sheishuo.app.main.model.MainTab;
|
|
|
import com.sheishuo.app.main.presenter.CirclePresenter;
|
|
|
|
|
|
+import org.w3c.dom.Text;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -82,6 +90,10 @@ public class CircleOfFriendsFragment extends MainTabFragment{
|
|
|
private MainActivity parent;
|
|
|
private INet net = new NetImpl();
|
|
|
|
|
|
+ private LinearLayout unreadLayout;
|
|
|
+ private HeadImageView unreadHead;
|
|
|
+ private TextView unreadTxt;
|
|
|
+
|
|
|
private CircleListAdapter adapter;
|
|
|
|
|
|
private LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
|
|
@@ -91,6 +103,9 @@ public class CircleOfFriendsFragment extends MainTabFragment{
|
|
|
private Toast toast = null;
|
|
|
private long lastTime = System.currentTimeMillis();
|
|
|
|
|
|
+ public static CircleUnreadBean unreadBean;
|
|
|
+ private String newLikeId;
|
|
|
+ private String newCommId;
|
|
|
|
|
|
public CircleOfFriendsFragment(){
|
|
|
setContainerId(MainTab.CIRCLE_OF_FRIENDS.fragmentId);
|
|
|
@@ -102,6 +117,7 @@ public class CircleOfFriendsFragment extends MainTabFragment{
|
|
|
findViews();
|
|
|
initToolbar();
|
|
|
|
|
|
+ unreadLayout.setVisibility(View.GONE);
|
|
|
|
|
|
presenter.loadCircleList(AccountCache.getAccount().getId(),"0", null);
|
|
|
|
|
|
@@ -125,6 +141,19 @@ public class CircleOfFriendsFragment extends MainTabFragment{
|
|
|
fillTop();
|
|
|
isLoaded = true;
|
|
|
|
|
|
+ unreadLayout.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setClass(getContext(), CircleMessageActivity.class);
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ intent.putExtra(CircleMessageActivity.DATA, (Serializable) unreadBean.getD().getList());
|
|
|
+ getContext().startActivity(intent);
|
|
|
+
|
|
|
+ unreadLayout.setVisibility(View.GONE);
|
|
|
+ syncUnread();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -142,6 +171,12 @@ public class CircleOfFriendsFragment extends MainTabFragment{
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void onCurrent() {
|
|
|
+ super.onCurrent();
|
|
|
+ fetchUnreadList();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void onResume() {
|
|
|
super.onResume();
|
|
|
fillTop();
|
|
|
@@ -164,6 +199,10 @@ public class CircleOfFriendsFragment extends MainTabFragment{
|
|
|
avatar = (ImageView) getView().findViewById(R.id.circle_avatar);
|
|
|
username = (TextView) getView().findViewById(R.id.circle_username);
|
|
|
backgroundImg = (ImageView) getView().findViewById(R.id.circle_background);
|
|
|
+
|
|
|
+ unreadLayout = findView(R.id.circle_unread_layout);
|
|
|
+ unreadHead = findView(R.id.circle_unread_head);
|
|
|
+ unreadTxt = findView(R.id.circle_unread_txt);
|
|
|
}
|
|
|
|
|
|
void fillTop(){
|
|
|
@@ -282,9 +321,12 @@ public class CircleOfFriendsFragment extends MainTabFragment{
|
|
|
@Override
|
|
|
public void onLikedClick(View view) {
|
|
|
CircleBean.DBean.ListBean bean = (CircleBean.DBean.ListBean) view.getTag();
|
|
|
- bean.getLike_users().add(AccountCache.getAccount().getId());
|
|
|
+ if(bean.getLiked().equals("1"))
|
|
|
+ bean.getLike_users().add(AccountCache.getAccount().getId());
|
|
|
+ else
|
|
|
+ bean.getLike_users().remove(AccountCache.getAccount().getId());
|
|
|
Log.e(TAG,"点赞的朋友圈ID === " + bean.getId());
|
|
|
- presenter.onUserLiked(bean.getId());
|
|
|
+ presenter.onUserLiked(bean.getId(), bean.getLiked().equals("1"));
|
|
|
getHandler().post(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
@@ -340,7 +382,118 @@ public class CircleOfFriendsFragment extends MainTabFragment{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void fetchUnreadList()
|
|
|
+ {
|
|
|
+ if(unreadLayout == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ unreadLayout.setVisibility(View.GONE);
|
|
|
+
|
|
|
+ SocialInfoBean infoBean = SocialInfoCache.get(AccountCache.getAccount().getId());
|
|
|
+ final long lastLikeId = Long.parseLong(infoBean.getSocial_last_like());
|
|
|
+ final int lastCommId = Integer.parseInt(infoBean.getSocial_last_comment());
|
|
|
+ net.socialUnreadList(infoBean.getSocial_last_like(), infoBean.getSocial_last_comment(), new ResponseCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Object object) {
|
|
|
+ unreadBean = (CircleUnreadBean)object;
|
|
|
+ boolean firstTime = false;
|
|
|
+ if(lastCommId == 0 && lastLikeId == 0)
|
|
|
+ {
|
|
|
+ firstTime = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ long newLikeId = lastLikeId;
|
|
|
+ int newCommId = lastCommId;
|
|
|
+ for(CircleUnreadBean.DBean.ListBean listBean : unreadBean.getD().getList())
|
|
|
+ {
|
|
|
+ if(TextUtils.isEmpty(listBean.getComment())) {
|
|
|
+ long likeId = Long.parseLong(listBean.getId());
|
|
|
+ if(likeId > newLikeId)
|
|
|
+ newLikeId = likeId;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int commId = Integer.parseInt(listBean.getId());
|
|
|
+ if(commId > newCommId)
|
|
|
+ newCommId = commId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //firstTime = false;
|
|
|
+
|
|
|
+ final int count = unreadBean.getD().getList().size();
|
|
|
+ if(!firstTime && count > 0)
|
|
|
+ {
|
|
|
+ CircleUnreadBean.DBean.ListBean listBean = unreadBean.getD().getList().get(count-1);
|
|
|
+ NimUserInfo nimUserInfo = NIMClient.getService(UserService.class).getUserInfo(listBean.getUser_id());
|
|
|
+ if(nimUserInfo == null)
|
|
|
+ {
|
|
|
+ List<String> userList = new ArrayList<String>();
|
|
|
+ userList.add(listBean.getUser_id());
|
|
|
+ NIMClient.getService(UserService.class).fetchUserInfo(userList).setCallback(new RequestCallback<List<NimUserInfo>>() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(List<NimUserInfo> nimUserInfos) {
|
|
|
+ setUnreadInfo(nimUserInfos.get(0), count);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailed(int i) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onException(Throwable throwable) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ setUnreadInfo(nimUserInfo, count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateUnread(newLikeId, newCommId);
|
|
|
+ if(firstTime)
|
|
|
+ syncUnread();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailed(String error) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setUnreadInfo(final NimUserInfo nimUserInfo, final int count)
|
|
|
+ {
|
|
|
+ getHandler().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ unreadLayout.setVisibility(View.VISIBLE);
|
|
|
+ String url = nimUserInfo.getAvatar();
|
|
|
+ if(TextUtils.isEmpty(url))
|
|
|
+ unreadHead.setImageResource(R.drawable.nim_avatar_default);
|
|
|
+ else
|
|
|
+ Glide.with(unreadHead.getContext()).load(url).into(unreadHead);
|
|
|
+ unreadTxt.setText(count+"条新消息");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateUnread(long newLikeId, int newCommId)
|
|
|
+ {
|
|
|
+ this.newLikeId = ""+newLikeId;
|
|
|
+ this.newCommId = ""+newCommId;
|
|
|
+ }
|
|
|
|
|
|
+ private void syncUnread()
|
|
|
+ {
|
|
|
+ SocialInfoBean infoBean = SocialInfoCache.get(AccountCache.getAccount().getId());
|
|
|
+ infoBean.setSocial_last_like(""+newLikeId);
|
|
|
+ infoBean.setSocial_last_comment(""+newCommId);
|
|
|
+ net.socialUnreadUpdate(""+newLikeId, ""+newCommId);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@Override
|