|
@@ -0,0 +1,147 @@
|
|
|
+package com.sheishuo.app.main.fragment;
|
|
|
+
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.netease.nim.uikit.NimUIKit;
|
|
|
+import com.netease.nim.uikit.robot.parser.elements.group.LinearLayout;
|
|
|
+import com.netease.nim.uikit.session.SessionCustomization;
|
|
|
+import com.netease.nimlib.sdk.NIMClient;
|
|
|
+import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
|
|
|
+import com.netease.nimlib.sdk.team.TeamService;
|
|
|
+import com.netease.nimlib.sdk.team.model.Team;
|
|
|
+import com.sheishuo.app.AccountCache;
|
|
|
+import com.sheishuo.app.R;
|
|
|
+import com.sheishuo.app.common.beans.NearbyGroupsBean;
|
|
|
+import com.sheishuo.app.common.util.net.INet;
|
|
|
+import com.sheishuo.app.common.util.net.NetImpl;
|
|
|
+import com.sheishuo.app.common.util.net.NetInfo;
|
|
|
+import com.sheishuo.app.common.util.net.ResponseCallback;
|
|
|
+import com.sheishuo.app.main.adapter.AreaGroupsAdapter;
|
|
|
+import com.sheishuo.app.main.adapter.OnItemClickListener;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import okhttp3.FormBody;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by KN on 2017/7/18.
|
|
|
+ */
|
|
|
+
|
|
|
+public class AreaGroupsFragment extends MainTabFragment {
|
|
|
+ private TextView headSearchBar;
|
|
|
+
|
|
|
+ private RecyclerView areaGroupsRecyclerview,nearbyGroupsRecyclerview;
|
|
|
+
|
|
|
+ private AreaGroupsAdapter areaGroupsAdapter,nearbyGroupsAdapter;
|
|
|
+
|
|
|
+ private LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
|
|
+ private LinearLayoutManager nearbyLayoutManager = new LinearLayoutManager(getActivity());
|
|
|
+
|
|
|
+
|
|
|
+ private INet net = new NetImpl();
|
|
|
+ @Override
|
|
|
+ protected void onInit() {
|
|
|
+ findViews();
|
|
|
+ loadGroups();
|
|
|
+ }
|
|
|
+
|
|
|
+ void findViews(){
|
|
|
+ areaGroupsRecyclerview = findView(R.id.area_groups_recyclerview);
|
|
|
+ nearbyGroupsRecyclerview = findView(R.id.area_groups_nearby_recyclerview);
|
|
|
+ }
|
|
|
+
|
|
|
+ void loadGroups(){
|
|
|
+ List<String> groupIds = new ArrayList<>();
|
|
|
+ groupIds.add(AccountCache.getAccount().getCountry_room_id());
|
|
|
+ groupIds.add(AccountCache.getAccount().getProvince_room_id());
|
|
|
+ groupIds.add(AccountCache.getAccount().getCity_room_id());
|
|
|
+ groupIds.add(AccountCache.getAccount().getDistrict_room_id());
|
|
|
+
|
|
|
+ //去除重复的id
|
|
|
+ if (groupIds.get(1).equals(groupIds.get(2)))groupIds.remove(2);
|
|
|
+ //去除空的id
|
|
|
+ for (int i = 0;i<groupIds.size();i++){
|
|
|
+ if (groupIds.get(i).isEmpty())groupIds.remove(i);
|
|
|
+ }
|
|
|
+ areaGroupsAdapter = new AreaGroupsAdapter(getActivity(),groupIds);
|
|
|
+
|
|
|
+ areaGroupsRecyclerview.setAdapter(areaGroupsAdapter);
|
|
|
+ areaGroupsRecyclerview.setLayoutManager(layoutManager);
|
|
|
+ areaGroupsAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(View view) {
|
|
|
+ String groupId = (String)view.getTag();
|
|
|
+ if (!NIMClient.getService(TeamService.class).queryTeamBlock(groupId).isMyTeam()){
|
|
|
+ NIMClient.getService(TeamService.class).applyJoinTeam(groupId,"申请入群");
|
|
|
+ }
|
|
|
+ NimUIKit.startTeamSession(getActivity(), (String)view.getTag());
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //加载附近的群
|
|
|
+
|
|
|
+
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ FormBody body = new FormBody.Builder()
|
|
|
+ .add("page","1")
|
|
|
+ .add("latitude",AccountCache.getAccount().getLatitude())
|
|
|
+ .add("longitude",AccountCache.getAccount().getLongitude())
|
|
|
+ .build();
|
|
|
+ net.post(NetInfo.INDEX + NetInfo.GET_NEARBY_GROUP, body, new ResponseCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Object object) {
|
|
|
+ String resultStr = (String)object;
|
|
|
+ final NearbyGroupsBean bean = new Gson().fromJson(resultStr,NearbyGroupsBean.class);
|
|
|
+ if (bean.getC() == 0){
|
|
|
+ final List<String> nearbyGroupIds = new ArrayList<>();
|
|
|
+ for (NearbyGroupsBean.DBean.ListBean entity : bean.getD().getList())
|
|
|
+ nearbyGroupIds.add(entity.getId());
|
|
|
+
|
|
|
+
|
|
|
+ getHandler().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ nearbyGroupsAdapter = new AreaGroupsAdapter(getActivity(),nearbyGroupIds);
|
|
|
+ nearbyGroupsRecyclerview.setAdapter(nearbyGroupsAdapter);
|
|
|
+ nearbyGroupsRecyclerview.setLayoutManager(nearbyLayoutManager);
|
|
|
+ nearbyGroupsAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(View view) {
|
|
|
+ String groupId = (String)view.getTag();
|
|
|
+ if (!NIMClient.getService(TeamService.class).queryTeamBlock(groupId).isMyTeam()){
|
|
|
+ NIMClient.getService(TeamService.class).applyJoinTeam(groupId,"申请入群");
|
|
|
+ }
|
|
|
+ NimUIKit.startTeamSession(getActivity(), (String)view.getTag());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailed() {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+
|
|
|
+ }
|
|
|
+}
|