Skip to content

Commit

Permalink
refactor(main):refactor main code
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCShou committed Oct 15, 2022
1 parent 5b18c85 commit edd5ef4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 52 deletions.
64 changes: 34 additions & 30 deletions app/src/main/java/com/zcshou/gogogo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ protected void onCreate(Bundle savedInstanceState) {

DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
this, drawer, toolbar, R.string.nav_drawer_open, R.string.nav_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

Expand Down Expand Up @@ -361,8 +361,8 @@ public boolean onQueryTextSubmit(String query) {
mBaiduMap.clear();
mSearchLayout.setVisibility(View.INVISIBLE);
} catch (Exception e) {
GoUtils.DisplayToast(MainActivity.this, getResources().getString(R.string.error_gps));
XLog.d(getResources().getString(R.string.error_gps));
GoUtils.DisplayToast(MainActivity.this, getResources().getString(R.string.app_error_search));
XLog.d(getResources().getString(R.string.app_error_search));
e.printStackTrace();
}

Expand All @@ -382,8 +382,8 @@ public boolean onQueryTextChange(String newText) {
.city(mCurrentCity)
);
} catch (Exception e) {
GoUtils.DisplayToast(MainActivity.this,"搜索失败,请检查网络连接");
XLog.d("HTTP: 搜索失败,请检查网络连接");
GoUtils.DisplayToast(MainActivity.this, getResources().getString(R.string.app_error_search));
XLog.d(getResources().getString(R.string.app_error_search));
e.printStackTrace();
}
}
Expand Down Expand Up @@ -444,7 +444,7 @@ private void initNavigationView() {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
startActivity(intent);
} catch (Exception e) {
GoUtils.DisplayToast(this,"无法跳转到开发者选项,请先确保您的设备已处于开发者模式");
GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_dev));
e.printStackTrace();
}
} else if (id == R.id.nav_update) {
Expand Down Expand Up @@ -585,12 +585,12 @@ private void setSearchHistoryClickListener() {
try {
searchView.setQuery(searchKey, true);
} catch (Exception e) {
GoUtils.DisplayToast(this,"搜索失败,请检查网络连接");
XLog.e("ERROR: 搜索失败,请检查网络连接");
GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_search));
XLog.e(getResources().getString(R.string.app_error_search));
e.printStackTrace();
}
} else {
XLog.e("ERROR:搜索失败,参数非法");
XLog.e(getResources().getString(R.string.app_error_param));
}
});
mSearchHistoryList.setOnItemLongClickListener((parent, view, position, id) -> {
Expand Down Expand Up @@ -623,7 +623,7 @@ private void setSearchHistoryClickListener() {
}
} catch (Exception e) {
XLog.e("ERROR: delete database error");
GoUtils.DisplayToast(MainActivity.this,"删除记录出错");
GoUtils.DisplayToast(MainActivity.this,getResources().getString(R.string.history_delete_error));
e.printStackTrace();
}
})
Expand All @@ -640,7 +640,7 @@ private void setSearchSuggestListener() {
mSuggestionSearch = SuggestionSearch.newInstance();
mSuggestionSearch.setOnGetSuggestionResultListener(suggestionResult -> {
if (suggestionResult == null || suggestionResult.getAllSuggestions() == null) {
GoUtils.DisplayToast(this,"没有找到检索结果");
GoUtils.DisplayToast(this,getResources().getString(R.string.app_search_null));
} else { //获取在线建议检索结果
List<Map<String, Object>> data = new ArrayList<>();
int retCnt = suggestionResult.getAllSuggestions().size();
Expand Down Expand Up @@ -734,15 +734,15 @@ public void afterTextChanged(Editable s) {
TextView regAgree = window.findViewById(R.id.reg_agree);
regAgree.setOnClickListener(v -> {
if (!mPtlCheckBox.isChecked()) {
GoUtils.DisplayToast(this,"您必须先阅读并同意免责声明");
GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_protocol));
return;
}
if (TextUtils.isEmpty(regUserName.getText())) {
GoUtils.DisplayToast(this, "用户名不能为空");
GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_username));
return;
}
if (TextUtils.isEmpty(regResp.getText())) {
GoUtils.DisplayToast(this,"注册码不能为空");
GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_code));
return;
}
try {
Expand Down Expand Up @@ -808,7 +808,7 @@ private void initBaiduMap() {
ImageButton ibSave = poiView.findViewById(R.id.poi_save);
ibSave.setOnClickListener(v -> {
recordGetPositionInfo();
GoUtils.DisplayToast(this, "已保存位置");
GoUtils.DisplayToast(this, getResources().getString(R.string.app_location_save));
});
ImageButton ibCopy = poiView.findViewById(R.id.poi_copy);
ibCopy.setOnClickListener(v -> {
Expand All @@ -819,7 +819,7 @@ private void initBaiduMap() {
// 将 ClipData内容放到系统剪贴板里。
cm.setPrimaryClip(mClipData);

GoUtils.DisplayToast(this, "已复制到剪切板");
GoUtils.DisplayToast(this, getResources().getString(R.string.app_location_copy));
});
ImageButton ibShare = poiView.findViewById(R.id.poi_share);
ibShare.setOnClickListener(v -> ShareUtils.shareText(MainActivity.this, "分享位置", poiLongitude.getText()+","+poiLatitude.getText()));
Expand Down Expand Up @@ -1059,27 +1059,31 @@ private void initListenerMapBtn() {
String dialog_lat_str = dialog_lat.getText().toString();

if (TextUtils.isEmpty(dialog_lng_str) || TextUtils.isEmpty(dialog_lat_str)) {
GoUtils.DisplayToast(MainActivity.this,"输入不能为空");
GoUtils.DisplayToast(MainActivity.this,getResources().getString(R.string.app_error_input));
} else {
double dialog_lng_double = Double.parseDouble(dialog_lng_str);
double dialog_lat_double = Double.parseDouble(dialog_lat_str);

if (dialog_lng_double > 180.0 || dialog_lng_double < -180.0 || dialog_lat_double > 90.0 || dialog_lat_double < -90.0) {
GoUtils.DisplayToast(MainActivity.this, "经纬度超出限制!\n-180.0<经度<180.0\n-90.0<纬度<90.0");
if (dialog_lng_double > 180.0 || dialog_lng_double < -180.0) {
GoUtils.DisplayToast(MainActivity.this, getResources().getString(R.string.app_error_longitude));
} else {
if (rbBD.isChecked()) {
mMarkLatLngMap = new LatLng(dialog_lat_double, dialog_lng_double);
if (dialog_lat_double > 90.0 || dialog_lat_double < -90.0) {
GoUtils.DisplayToast(MainActivity.this, getResources().getString(R.string.app_error_latitude));
} else {
double[] bdLonLat = MapUtils.wgs2bd09(dialog_lat_double, dialog_lng_double);
mMarkLatLngMap = new LatLng(bdLonLat[1], bdLonLat[0]);
}
if (rbBD.isChecked()) {
mMarkLatLngMap = new LatLng(dialog_lat_double, dialog_lng_double);
} else {
double[] bdLonLat = MapUtils.wgs2bd09(dialog_lat_double, dialog_lng_double);
mMarkLatLngMap = new LatLng(bdLonLat[1], bdLonLat[0]);
}

markMap();
markMap();

MapStatusUpdate mapstatusupdate = MapStatusUpdateFactory.newLatLng(mMarkLatLngMap);
mBaiduMap.setMapStatus(mapstatusupdate);
MapStatusUpdate mapstatusupdate = MapStatusUpdateFactory.newLatLng(mMarkLatLngMap);
mBaiduMap.setMapStatus(mapstatusupdate);

dialog.dismiss();
dialog.dismiss();
}
}
}
});
Expand Down Expand Up @@ -1483,13 +1487,13 @@ public void onResponse(@NonNull Call call, @NonNull okhttp3.Response response) t
Button updateAgree = window.findViewById(R.id.update_agree);
updateAgree.setOnClickListener(v -> {
alertDialog.cancel();
GoUtils.DisplayToast(MainActivity.this,"升级文件下载中");
GoUtils.DisplayToast(MainActivity.this, getResources().getString(R.string.update_downloading));
downloadNewVersion(download_url);
});
}
} else {
if (result) {
GoUtils.DisplayToast(MainActivity.this,"恭喜,当前版本的影梭已经是最新版!");
GoUtils.DisplayToast(MainActivity.this, getResources().getString(R.string.update_last));
}
}
} catch (JSONException e) {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/zcshou/joystick/JoyStick.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ public boolean onQueryTextChange(String newText) {
GoUtils.DisplayToast(mContext, getResources().getString(R.string.app_location_ok));
}
}

});
btnGo.setColorFilter(getResources().getColor(R.color.colorAccent, mContext.getTheme()));

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/nav_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/nav_header_vertical_spacing"
android:text="@string/user_name"
android:text="@string/nav_user_name"
android:textSize="18sp"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

Expand All @@ -33,7 +33,7 @@
android:layout_marginTop="10dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="@string/user_limit_info"
android:text="@string/nav_user_limit_info"
android:drawablePadding="5dip"
app:drawableStartCompat="@drawable/ic_msg"/>

Expand Down
47 changes: 28 additions & 19 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@
<string name="app_error_input">输入有误,请检查输入是否合法</string>
<string name="app_error_search">查找失败,请检查网络或定位</string>
<string name="app_error_location">请先选择位置</string>
<string name="app_error_dev">无法跳转到开发者选项,请先确保已开启开发者模式</string>
<string name="app_error_param">非法参数</string>
<string name="app_error_protocol">请先阅读并接收用户协议</string>
<string name="app_error_username">用户名不合法</string>
<string name="app_error_code">注册码不能为空</string>
<string name="app_error_longitude">纬度超出限制!\n取值:-180.0 ~ 180.0</string>
<string name="app_error_latitude">纬度超出限制!\n取值:-90.0 ~ 90.0</string>
<string name="app_search_null">没有匹配结果,请重新搜索</string>
<string name="app_location_ok">位置已传送</string>
<string name="app_location_copy">位置已复制到剪切板</string>
<string name="app_location_save">位置已保存</string>

<!-- 欢迎页 -->
<string name="welcome_btn_txt">进入应用</string>
Expand All @@ -51,38 +60,39 @@
<string name="setting_group_sys">系统</string>

<!-- 历史记录页面 -->
<string name="history_expiration">7</string>
<string name="history_idle">暂无历史记录</string>
<string name="history_delete_ok">删除成功!</string>
<string name="history_expiration">7</string>
<string name="history_delete_error">删除记录失败</string>
<string name="history_error_location">定位失败,请手动选取定位点</string>
<string name="history_error_search">未搜索到指定内容</string>

<!-- 通知栏 -->
<string name="note_show">显示摇杆</string>
<string name="note_hide">隐藏摇杆</string>

<!-- 主界面 -->
<string name="label_longitude">经度</string>
<string name="label_latitude">纬度</string>
<string name="input_position_ok">传送</string>
<string name="input_position_cancel">取消</string>
<string name="input_position_baidu">BD09 坐标系</string>
<string name="input_position_gps">GPS 坐标系</string>
<string name="error_gps">位置检索失败,请检查 GPS 是否开启</string>
<string name="error_network">搜索失败,请检查网络连接</string>

<!-- 摇杆 -->
<string name="joystick_map_tips">搜索或点击地图位置</string>
<string name="joystick_history_tips">搜索或点击历史位置</string>
<!-- 导航页 -->
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="user_name">影梭</string>
<string name="user_limit_info">仅供学习使用,否则后果自负!</string>
<string name="nav_drawer_open">打开导航菜单</string>
<string name="nav_drawer_close">关闭导航菜单</string>
<string name="nav_menu_history">历史记录</string>
<string name="nav_menu_settings">设置</string>
<string name="nav_menu_dev">开发人员选项</string>
<string name="nav_menu_more">更多</string>
<string name="nav_menu_upgrade">检测更新</string>
<string name="nav_menu_feedback">问题反馈</string>
<string name="nav_menu_contact">联系作者</string>
<string name="nav_user_name">影梭</string>
<string name="nav_user_limit_info">仅供学习使用,否则后果自负!</string>

<!-- 主界面 -->
<string name="label_longitude">经度</string>
<string name="label_latitude">纬度</string>
<string name="input_position_ok">传送</string>
<string name="input_position_cancel">取消</string>
<string name="input_position_baidu">BD09 坐标系</string>
<string name="input_position_gps">GPS 坐标系</string>

<!-- 百度地图 -->
<string name="map_pic_sate">卫星图</string>
Expand All @@ -92,14 +102,13 @@

<!-- 更新 -->
<string name="update_title">新版本可用</string>
<string name="update_downloading">升级文件下载中。。。</string>
<string name="update_last">恭喜,影梭已是最新版</string>
<string name="update_download">立即下载</string>
<string name="update_ignore">忽略一次</string>
<string name="update_time">更新时间:</string>
<string name="update_commit">提交信息:</string>

<!-- 摇杆 -->
<string name="joystick_map_tips">搜索或点击地图位置</string>
<string name="joystick_history_tips">搜索或点击历史位置</string>
<!-- 注册 -->
<string name="register_title">离线注册</string>
<string name="register_user_name">用户名</string>
Expand Down

0 comments on commit edd5ef4

Please sign in to comment.