|
@@ -1,6 +1,7 @@
|
|
|
package com.sheishuo.app.main.fragment;
|
|
package com.sheishuo.app.main.fragment;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
+import android.content.Intent;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
@@ -13,9 +14,8 @@ import com.netease.nim.uikit.contact_selector.activity.ContactSelectActivity;
|
|
|
import com.netease.nim.uikit.team.helper.TeamHelper;
|
|
import com.netease.nim.uikit.team.helper.TeamHelper;
|
|
|
import com.netease.nimlib.sdk.NIMClient;
|
|
import com.netease.nimlib.sdk.NIMClient;
|
|
|
import com.netease.nimlib.sdk.team.TeamService;
|
|
import com.netease.nimlib.sdk.team.TeamService;
|
|
|
-import com.netease.nimlib.sdk.team.constant.TeamFieldEnum;
|
|
|
|
|
-import com.sheishuo.app.cache.AccountCache;
|
|
|
|
|
import com.sheishuo.app.R;
|
|
import com.sheishuo.app.R;
|
|
|
|
|
+import com.sheishuo.app.cache.AccountCache;
|
|
|
import com.sheishuo.app.cache.GiftCache;
|
|
import com.sheishuo.app.cache.GiftCache;
|
|
|
import com.sheishuo.app.common.beans.GiftBean;
|
|
import com.sheishuo.app.common.beans.GiftBean;
|
|
|
import com.sheishuo.app.common.beans.NearbyGroupsBean;
|
|
import com.sheishuo.app.common.beans.NearbyGroupsBean;
|
|
@@ -24,11 +24,15 @@ import com.sheishuo.app.common.util.net.NetImpl;
|
|
|
import com.sheishuo.app.common.util.net.NetInfo;
|
|
import com.sheishuo.app.common.util.net.NetInfo;
|
|
|
import com.sheishuo.app.common.util.net.ResponseCallback;
|
|
import com.sheishuo.app.common.util.net.ResponseCallback;
|
|
|
import com.sheishuo.app.common.views.BaseToolbar;
|
|
import com.sheishuo.app.common.views.BaseToolbar;
|
|
|
|
|
+import com.sheishuo.app.core_module.location.LocationSelectActivity;
|
|
|
import com.sheishuo.app.login.beans.LoginBean;
|
|
import com.sheishuo.app.login.beans.LoginBean;
|
|
|
import com.sheishuo.app.main.activity.MainActivity;
|
|
import com.sheishuo.app.main.activity.MainActivity;
|
|
|
import com.sheishuo.app.main.adapter.AreaGroupsAdapter;
|
|
import com.sheishuo.app.main.adapter.AreaGroupsAdapter;
|
|
|
import com.sheishuo.app.main.adapter.OnItemClickListener;
|
|
import com.sheishuo.app.main.adapter.OnItemClickListener;
|
|
|
|
|
|
|
|
|
|
+import org.json.JSONException;
|
|
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
+
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
@@ -44,9 +48,9 @@ public class AreaGroupsFragment extends MainTabFragment {
|
|
|
private BaseToolbar toolbar;
|
|
private BaseToolbar toolbar;
|
|
|
private MainActivity parent;
|
|
private MainActivity parent;
|
|
|
|
|
|
|
|
- private RecyclerView areaGroupsRecyclerview,nearbyGroupsRecyclerview;
|
|
|
|
|
|
|
+ private RecyclerView areaGroupsRecyclerview, nearbyGroupsRecyclerview;
|
|
|
|
|
|
|
|
- private AreaGroupsAdapter areaGroupsAdapter,nearbyGroupsAdapter;
|
|
|
|
|
|
|
+ private AreaGroupsAdapter areaGroupsAdapter, nearbyGroupsAdapter;
|
|
|
|
|
|
|
|
private LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
|
private LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
|
|
private LinearLayoutManager nearbyLayoutManager = new LinearLayoutManager(getActivity());
|
|
private LinearLayoutManager nearbyLayoutManager = new LinearLayoutManager(getActivity());
|
|
@@ -63,16 +67,17 @@ public class AreaGroupsFragment extends MainTabFragment {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void findViews(){
|
|
|
|
|
- parent = (MainActivity)getActivity();
|
|
|
|
|
|
|
+ void findViews() {
|
|
|
|
|
+ parent = (MainActivity) getActivity();
|
|
|
toolbar = (BaseToolbar) parent.getToolBar();
|
|
toolbar = (BaseToolbar) parent.getToolBar();
|
|
|
areaGroupsRecyclerview = findView(R.id.area_groups_recyclerview);
|
|
areaGroupsRecyclerview = findView(R.id.area_groups_recyclerview);
|
|
|
nearbyGroupsRecyclerview = findView(R.id.area_groups_nearby_recyclerview);
|
|
nearbyGroupsRecyclerview = findView(R.id.area_groups_nearby_recyclerview);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//初始化Toolbar
|
|
//初始化Toolbar
|
|
|
- void initToolbar(){
|
|
|
|
|
|
|
+ void initToolbar() {
|
|
|
toolbar.init();
|
|
toolbar.init();
|
|
|
|
|
+
|
|
|
toolbar.setTitle("谁说");
|
|
toolbar.setTitle("谁说");
|
|
|
LoginBean.DBean account = AccountCache.getAccount();
|
|
LoginBean.DBean account = AccountCache.getAccount();
|
|
|
toolbar.setLeftText(account.getCity() + account.getDistrict());
|
|
toolbar.setLeftText(account.getCity() + account.getDistrict());
|
|
@@ -84,10 +89,20 @@ public class AreaGroupsFragment extends MainTabFragment {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ toolbar.setLeftText("重庆市北碚区");
|
|
|
|
|
+ toolbar.getLeftTV().setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ Intent intent = new Intent(getActivity(), LocationSelectActivity.class);
|
|
|
|
|
+ startActivityForResult(intent, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//加载聊天室信息
|
|
//加载聊天室信息
|
|
|
- void loadGroups(){
|
|
|
|
|
|
|
+ void loadGroups() {
|
|
|
List<String> groupIds = new ArrayList<>();
|
|
List<String> groupIds = new ArrayList<>();
|
|
|
List<String> tempList = new ArrayList<>();
|
|
List<String> tempList = new ArrayList<>();
|
|
|
tempList.add(AccountCache.getAccount().getCountry_room_id());
|
|
tempList.add(AccountCache.getAccount().getCountry_room_id());
|
|
@@ -97,44 +112,44 @@ public class AreaGroupsFragment extends MainTabFragment {
|
|
|
|
|
|
|
|
|
|
|
|
|
//去除空的和重复的id
|
|
//去除空的和重复的id
|
|
|
- for (int i = 0;i<tempList.size();i++){
|
|
|
|
|
|
|
+ for (int i = 0; i < tempList.size(); i++) {
|
|
|
if (!groupIds.contains(tempList.get(i)) && !tempList.get(i).isEmpty())
|
|
if (!groupIds.contains(tempList.get(i)) && !tempList.get(i).isEmpty())
|
|
|
groupIds.add(tempList.get(i));
|
|
groupIds.add(tempList.get(i));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- areaGroupsAdapter = new AreaGroupsAdapter(getActivity(),groupIds);
|
|
|
|
|
|
|
+ areaGroupsAdapter = new AreaGroupsAdapter(getActivity(), groupIds);
|
|
|
|
|
+ areaGroupsRecyclerview.setLayoutManager(layoutManager);
|
|
|
|
|
|
|
|
areaGroupsRecyclerview.setAdapter(areaGroupsAdapter);
|
|
areaGroupsRecyclerview.setAdapter(areaGroupsAdapter);
|
|
|
- areaGroupsRecyclerview.setLayoutManager(layoutManager);
|
|
|
|
|
|
|
+
|
|
|
areaGroupsAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
areaGroupsAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onItemClick(View view) {
|
|
public void onItemClick(View view) {
|
|
|
- String groupId = (String)view.getTag();
|
|
|
|
|
- if (!NIMClient.getService(TeamService.class).queryTeamBlock(groupId).isMyTeam()){
|
|
|
|
|
- NIMClient.getService(TeamService.class).applyJoinTeam(groupId,"申请入群");
|
|
|
|
|
|
|
+ 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());
|
|
|
|
|
|
|
+ NimUIKit.startTeamSession(getActivity(), (String) view.getTag());
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
//加载附近的群
|
|
//加载附近的群
|
|
|
new Thread(new Runnable() {
|
|
new Thread(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
FormBody body = new FormBody.Builder()
|
|
FormBody body = new FormBody.Builder()
|
|
|
- .add("page","1")
|
|
|
|
|
- .add("latitude",AccountCache.getAccount().getLatitude())
|
|
|
|
|
- .add("longitude",AccountCache.getAccount().getLongitude())
|
|
|
|
|
|
|
+ .add("page", "1")
|
|
|
|
|
+ .add("latitude", AccountCache.getAccount().getLatitude())
|
|
|
|
|
+ .add("longitude", AccountCache.getAccount().getLongitude())
|
|
|
.build();
|
|
.build();
|
|
|
net.post(NetInfo.GET_NEARBY_GROUP, body, new ResponseCallback() {
|
|
net.post(NetInfo.GET_NEARBY_GROUP, body, new ResponseCallback() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onSuccess(Object object) {
|
|
public void onSuccess(Object object) {
|
|
|
- String resultStr = (String)object;
|
|
|
|
|
- final NearbyGroupsBean bean = new Gson().fromJson(resultStr,NearbyGroupsBean.class);
|
|
|
|
|
- if (bean.getC() == 0){
|
|
|
|
|
|
|
+ String resultStr = (String) object;
|
|
|
|
|
+ final NearbyGroupsBean bean = new Gson().fromJson(resultStr, NearbyGroupsBean.class);
|
|
|
|
|
+ if (bean.getC() == 0) {
|
|
|
final List<String> nearbyGroupIds = new ArrayList<>();
|
|
final List<String> nearbyGroupIds = new ArrayList<>();
|
|
|
for (NearbyGroupsBean.DBean.ListBean entity : bean.getD().getList())
|
|
for (NearbyGroupsBean.DBean.ListBean entity : bean.getD().getList())
|
|
|
nearbyGroupIds.add(entity.getId());
|
|
nearbyGroupIds.add(entity.getId());
|
|
@@ -143,17 +158,17 @@ public class AreaGroupsFragment extends MainTabFragment {
|
|
|
getHandler().post(new Runnable() {
|
|
getHandler().post(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
- nearbyGroupsAdapter = new AreaGroupsAdapter(getActivity(),nearbyGroupIds);
|
|
|
|
|
|
|
+ nearbyGroupsAdapter = new AreaGroupsAdapter(getActivity(), nearbyGroupIds);
|
|
|
nearbyGroupsRecyclerview.setAdapter(nearbyGroupsAdapter);
|
|
nearbyGroupsRecyclerview.setAdapter(nearbyGroupsAdapter);
|
|
|
nearbyGroupsRecyclerview.setLayoutManager(nearbyLayoutManager);
|
|
nearbyGroupsRecyclerview.setLayoutManager(nearbyLayoutManager);
|
|
|
nearbyGroupsAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
nearbyGroupsAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onItemClick(View view) {
|
|
public void onItemClick(View view) {
|
|
|
- String groupId = (String)view.getTag();
|
|
|
|
|
- if (!NIMClient.getService(TeamService.class).queryTeamBlock(groupId).isMyTeam()){
|
|
|
|
|
- NIMClient.getService(TeamService.class).applyJoinTeam(groupId,"申请入群");
|
|
|
|
|
|
|
+ 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());
|
|
|
|
|
|
|
+ NimUIKit.startTeamSession(getActivity(), (String) view.getTag());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -169,8 +184,6 @@ public class AreaGroupsFragment extends MainTabFragment {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
}).start();
|
|
}).start();
|
|
|
|
|
|
|
@@ -178,12 +191,12 @@ public class AreaGroupsFragment extends MainTabFragment {
|
|
|
|
|
|
|
|
|
|
|
|
|
//预加载礼物信息
|
|
//预加载礼物信息
|
|
|
- void loadGiftCache(){
|
|
|
|
|
|
|
+ void loadGiftCache() {
|
|
|
net.getGiftList(new ResponseCallback() {
|
|
net.getGiftList(new ResponseCallback() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onSuccess(Object object) {
|
|
public void onSuccess(Object object) {
|
|
|
- Log.e(TAG,"礼物列表加载成功");
|
|
|
|
|
- GiftBean.DBean gift = (GiftBean.DBean)object;
|
|
|
|
|
|
|
+ Log.e(TAG, "礼物列表加载成功");
|
|
|
|
|
+ GiftBean.DBean gift = (GiftBean.DBean) object;
|
|
|
GiftCache.setCache(gift);
|
|
GiftCache.setCache(gift);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -195,25 +208,99 @@ public class AreaGroupsFragment extends MainTabFragment {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void setUserVisibleHint(boolean isVisibleToUser) {
|
|
public void setUserVisibleHint(boolean isVisibleToUser) {
|
|
|
super.setUserVisibleHint(isVisibleToUser);
|
|
super.setUserVisibleHint(isVisibleToUser);
|
|
|
- if (isVisibleToUser && toolbar != null){
|
|
|
|
|
|
|
+ if (isVisibleToUser && toolbar != null) {
|
|
|
initToolbar();
|
|
initToolbar();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- protected void showToast(final String toast){
|
|
|
|
|
|
|
+ protected void showToast(final String toast) {
|
|
|
getHandler().post(new Runnable() {
|
|
getHandler().post(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
- Toast.makeText(getActivity(),toast,Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
+ Toast.makeText(getActivity(), toast, Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void updateAccountLocation(final String province, final String city, final String district){
|
|
|
|
|
+ //更新Cache
|
|
|
|
|
+ AccountCache.getAccount().setProvince(province);
|
|
|
|
|
+ AccountCache.getAccount().setCity(city);
|
|
|
|
|
+ AccountCache.getAccount().setDistrict(district);
|
|
|
|
|
+
|
|
|
|
|
+ net.updateLocation(province, city, district, new ResponseCallback() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onSuccess(Object object) {
|
|
|
|
|
+ String jsonStr = (String)object;
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject(jsonStr);
|
|
|
|
|
+
|
|
|
|
|
+ String provinceRoomId = jsonObject.getJSONObject("d").getString("province");
|
|
|
|
|
+ String cityRoomId = jsonObject.getJSONObject("d").getString("city");
|
|
|
|
|
+ String districtRoomId = jsonObject.getJSONObject("d").getString("district");
|
|
|
|
|
+
|
|
|
|
|
+ AccountCache.getAccount().setProvince_room_id(provinceRoomId);
|
|
|
|
|
+ AccountCache.getAccount().setCity_room_id(cityRoomId);
|
|
|
|
|
+ AccountCache.getAccount().setDistrict_room_id(districtRoomId);
|
|
|
|
|
+
|
|
|
|
|
+ getHandler().post(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ loadGroups();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ } catch (JSONException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFailed() {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
+ if (LocationSelectActivity.LOCATION_SELECTED == resultCode) {
|
|
|
|
|
+ String province = data.getExtras().getString(LocationSelectActivity.LOCATION_PROVINCE);
|
|
|
|
|
+ String city = data.getExtras().getString(LocationSelectActivity.LOCATION_CITY);
|
|
|
|
|
+ String area = data.getExtras().getString(LocationSelectActivity.LOCATION_AREA);
|
|
|
|
|
+ if (province.equals("北京")
|
|
|
|
|
+ || province.equals("天津")
|
|
|
|
|
+ || province.equals("上海")
|
|
|
|
|
+ || province.equals("重庆")) {
|
|
|
|
|
+ province = province + "市";
|
|
|
|
|
+ }else if (!province.equals("钓鱼岛")
|
|
|
|
|
+ && !province.equals("香港")
|
|
|
|
|
+ && !province.equals("澳门")){
|
|
|
|
|
+ province = province + "省";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!city.contains("特别")
|
|
|
|
|
+ && !city.contains("自治")) {
|
|
|
|
|
+ city = city + "市";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ updateAccountLocation(province,city,area);
|
|
|
|
|
|
|
|
|
|
+ String location = city + area;
|
|
|
|
|
+ if (location.length() > 6) {
|
|
|
|
|
+ location = location.substring(0, 6) + "...";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ toolbar.setLeftText(location);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|