我有几个问题,
首先,当我阅读一些文章时,我应该在活动中实现LocationListener,ConnectionCallback和OnConnectionFailedListener接口,
将这些类的实现分别放在不同的文件中是正确的吗?
像下面这样:
public class LocationListener implements
com.google.android.gms.location.LocationListener {
@Inject
Location mLastLocation;
@Override
public void onLocationChanged(Location location) {
// Assign the new location
mLastLocation = location;
// Displaying the new location on UI
}
}
在我的活动中,我处理显示mLastLocation属性是正确的吗?
//Fields
@Inject
GoogleApiClient client;
Location mLastLocation;
//Fields
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(client);
其次,我该如何编写它的提供者方法?我的猜测是这样的,你们有什么建议吗?
//Constructor
public LocationModule(Context context, GoogleApiClient.ConnectionCallbacks callback, GoogleApiClient.OnConnectionFailedListener listener) {
this.context = context;
this.callback = callback;
this.listener = listener;
}
@Provides
@Singleton
GoogleApiClient providesGoogleApi() {
return new GoogleApiClient.Builder(context)
.addOnConnectionFailedListener(listener)
.addConnectionCallbacks(callback)
.addApi(LocationServices.API)
.build();
}
最后,在 Android 6 及以上设备上处理权限应该放在哪儿?是在 View 上还是 Presenter 上?
我听说 View 很蠢,所以不需要测试它,但我该如何遵循这个原则呢?
如果有人能给我一个符合我的情况的参考或 Github 的示例代码,那就太好了。