|
@@ -2,6 +2,7 @@ package com.sheishuo.app.main.fragment;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
|
|
+import android.location.Location;
|
|
|
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;
|
|
@@ -10,8 +11,14 @@ import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
+import com.netease.nim.uikit.LocationProvider;
|
|
|
|
|
+import com.netease.nim.uikit.NimUIKit;
|
|
|
|
|
+import com.netease.nim.uikit.common.ui.dialog.EasyAlertDialog;
|
|
|
|
|
+import com.netease.nim.uikit.common.util.log.LogUtil;
|
|
|
import com.netease.nimlib.sdk.NIMClient;
|
|
import com.netease.nimlib.sdk.NIMClient;
|
|
|
import com.netease.nimlib.sdk.RequestCallback;
|
|
import com.netease.nimlib.sdk.RequestCallback;
|
|
|
|
|
+import com.netease.nimlib.sdk.msg.MessageBuilder;
|
|
|
|
|
+import com.netease.nimlib.sdk.msg.model.IMMessage;
|
|
|
import com.netease.nimlib.sdk.team.TeamService;
|
|
import com.netease.nimlib.sdk.team.TeamService;
|
|
|
import com.netease.nimlib.sdk.team.model.Team;
|
|
import com.netease.nimlib.sdk.team.model.Team;
|
|
|
import com.netease.nimlib.sdk.uinfo.UserService;
|
|
import com.netease.nimlib.sdk.uinfo.UserService;
|
|
@@ -30,6 +37,8 @@ import com.sheishuo.app.core_module.sheishuo.view.ui.CreateNewGroupActivity;
|
|
|
import com.sheishuo.app.core_module.sheishuo.view.ui.MoreGroupsInTheAreaActivity;
|
|
import com.sheishuo.app.core_module.sheishuo.view.ui.MoreGroupsInTheAreaActivity;
|
|
|
import com.sheishuo.app.core_module.sheishuo.view.ui.NearbyGroupActivity;
|
|
import com.sheishuo.app.core_module.sheishuo.view.ui.NearbyGroupActivity;
|
|
|
import com.sheishuo.app.impl.SheishuoUIKit;
|
|
import com.sheishuo.app.impl.SheishuoUIKit;
|
|
|
|
|
+import com.sheishuo.app.location.helper.NimLocationManager;
|
|
|
|
|
+import com.sheishuo.app.location.model.NimLocation;
|
|
|
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;
|
|
@@ -45,13 +54,15 @@ import java.util.List;
|
|
|
* Created by KN on 2017/7/18.
|
|
* Created by KN on 2017/7/18.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-public class AreaGroupsFragment extends MainTabFragment {
|
|
|
|
|
|
|
+public class AreaGroupsFragment extends MainTabFragment implements NimLocationManager.NimLocationListener {
|
|
|
private String TAG = this.getClass().getSimpleName();
|
|
private String TAG = this.getClass().getSimpleName();
|
|
|
private Context context = getActivity();
|
|
private Context context = getActivity();
|
|
|
private BaseToolbar toolbar;
|
|
private BaseToolbar toolbar;
|
|
|
private TextView toolbarLeftTxt, createGroupTxt;
|
|
private TextView toolbarLeftTxt, createGroupTxt;
|
|
|
private MainActivity parent;
|
|
private MainActivity parent;
|
|
|
|
|
|
|
|
|
|
+ private NimLocationManager locationManager = null;
|
|
|
|
|
+
|
|
|
private RecyclerView areaGroupsRecyclerview, recentGroupsRecyclerview;
|
|
private RecyclerView areaGroupsRecyclerview, recentGroupsRecyclerview;
|
|
|
|
|
|
|
|
private AreaGroupsAdapter areaGroupsAdapter, recentGroupsAdapter;
|
|
private AreaGroupsAdapter areaGroupsAdapter, recentGroupsAdapter;
|
|
@@ -160,7 +171,57 @@ public class AreaGroupsFragment extends MainTabFragment {
|
|
|
|
|
|
|
|
//更新地理位置
|
|
//更新地理位置
|
|
|
public void updateLocation() {
|
|
public void updateLocation() {
|
|
|
- net.updateLatitudeAndLongitude(new ResponseCallback() {
|
|
|
|
|
|
|
+ locationManager = new NimLocationManager(getContext(), this);
|
|
|
|
|
+
|
|
|
|
|
+ if (!NimLocationManager.isLocationEnable(getContext())) {
|
|
|
|
|
+ final EasyAlertDialog alertDialog = new EasyAlertDialog(context);
|
|
|
|
|
+ alertDialog.setMessage("位置服务未开启");
|
|
|
|
|
+ alertDialog.addNegativeButton("取消", EasyAlertDialog.NO_TEXT_COLOR, EasyAlertDialog.NO_TEXT_SIZE,
|
|
|
|
|
+ new View.OnClickListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ alertDialog.dismiss();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ alertDialog.addPositiveButton("设置", EasyAlertDialog.NO_TEXT_COLOR, EasyAlertDialog.NO_TEXT_SIZE,
|
|
|
|
|
+ new View.OnClickListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ alertDialog.dismiss();
|
|
|
|
|
+ Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
|
|
|
+ try {
|
|
|
|
|
+ context.startActivity(intent);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ LogUtil.e("LOC", "start ACTION_LOCATION_SOURCE_SETTINGS error");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ alertDialog.show();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ locationManager.activate();
|
|
|
|
|
+ Location location = locationManager.getLastKnownLocation();
|
|
|
|
|
+ if(location != null && location.getLongitude() > 0 && location.getLatitude() > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ sendNewLocation(location.getLongitude(), location.getLatitude());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onLocationChanged(NimLocation location) {
|
|
|
|
|
+ if(location != null && location.hasCoordinates() && location.getLongitude() > 0 && location.getLatitude() > 0 && locationManager != null) {
|
|
|
|
|
+ sendNewLocation(location.getLongitude(), location.getLatitude());
|
|
|
|
|
+ locationManager.deactive();
|
|
|
|
|
+ locationManager = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void sendNewLocation(double longitude, double latitude)
|
|
|
|
|
+ {
|
|
|
|
|
+ net.updateLatitudeAndLongitude(longitude, latitude, new ResponseCallback() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onSuccess(Object object) {
|
|
public void onSuccess(Object object) {
|
|
|
getHandler().post(new Runnable() {
|
|
getHandler().post(new Runnable() {
|