Skip to content

Commit f71cd9b

Browse files
committed
增加是否自定义位置标志
限定提交字符长度 Maopao增加address
1 parent 608f6e5 commit f71cd9b

9 files changed

Lines changed: 45 additions & 28 deletions

File tree

app/src/main/java/net/coding/program/maopao/BaiduLbsLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void search(Context context, String keyword, double latitude, doub
4747
params.put("ak", ak);
4848
UserObject userObject = AccountInfo.loadAccount(context);
4949
if (userObject != null) {
50-
params.put("filter", String.format("userid:[%d,%d]", userObject.id, userObject.id));
50+
params.put("filter", String.format("user_id:[%d]", userObject.id));
5151
}
5252
params.put("geotable_id", geotable);
5353
params.put("q", keyword);
@@ -127,7 +127,7 @@ public static void store(Context context, String name, String address, double la
127127
params.put("latitude", String.valueOf(latitude));
128128
params.put("longitude", String.valueOf(longitude));
129129
params.put("title", name);
130-
params.put("userid", getUserId(context));
130+
params.put("user_id", getUserId(context));
131131

132132
try {
133133
params.put("sn", sn(path, params));

app/src/main/java/net/coding/program/maopao/LocationDetailActivity.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ public class LocationDetailActivity extends BaseActivity {
2020
@ViewById
2121
TextView nameText, addressText;
2222
@ViewById
23-
View map_button;
23+
View map_button, customText;
2424
@Extra
2525
double latitude, longitude;
2626
@Extra
27-
String name, address, shareId;
27+
String name, address;
28+
@Extra
29+
boolean isCustom;
2830

2931
@AfterViews
3032
void afterViews() {
3133
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
3234
nameText.setText(name);
3335
addressText.setText(address);
36+
customText.setVisibility(isCustom? View.VISIBLE:View.GONE);
3437
if (address != null) {
3538
map_button.setOnClickListener(new View.OnClickListener() {
3639
@Override
@@ -41,16 +44,6 @@ public void onClick(View v) {
4144
}
4245
});
4346
}
44-
// BaiduLbsLoader.requestLocationObject(this, shareId, new BaiduLbsLoader.LocationDetailListner(){
45-
// @Override
46-
// public void onReceiveLocationObject(LocationObject locationObject) {
47-
// if(LocationDetailActivity.this.isFinishing()) return;
48-
// if(locationObject == null) return;
49-
// addressText.setText(address= locationObject.address);
50-
// latitude = locationObject.latitude;
51-
// longitude = locationObject.longitude;
52-
// }
53-
// });
5447
}
5548

5649
@OptionsItem(android.R.id.home)

app/src/main/java/net/coding/program/maopao/LocationEditActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void onStoreResult(boolean success, String id) {
5959
if (!success) {
6060
Toast.makeText(LocationEditActivity.this, "保存失败,请重试", Toast.LENGTH_SHORT).show();
6161
} else {
62-
final LocationObject data = LocationObject.custom(id, customName, customAddress, latitude, longitude);
62+
final LocationObject data = LocationObject.newCustom(id, customName, customAddress, latitude, longitude);
6363
data.city = city;
6464
Intent intent = new Intent();
6565
intent.putExtra("location", data);

app/src/main/java/net/coding/program/maopao/MaopaoAddActivity.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,23 @@ void uploadText() {
320320

321321
params.put("content", content);
322322
params.put("device", Build.MODEL);
323-
if(!TextUtils.isEmpty( locationText.getText())) {
324-
params.put("location", currentLocation.type == LocationObject.Type.City?
325-
currentLocation.name : currentLocation.city + "·" + currentLocation.name);
326-
params.put("coord", LocationCoord.from(currentLocation).toString());
323+
if(currentLocation != null && !TextUtils.isEmpty(locationText.getText())) {
324+
String locationName = currentLocation.type == LocationObject.Type.City?
325+
currentLocation.name : currentLocation.city + "·" + currentLocation.name;
326+
params.put("location", ensureLength(locationName,16));
327+
params.put("coord", ensureLength(LocationCoord.from(currentLocation).toString(),32));
328+
params.put("address", ensureLength(currentLocation.address,64));
327329
}
328330
postNetwork(sendUrl, params, sendUrl);
329331
}
330332

333+
private static String ensureLength(String src,int maxLength){
334+
if(TextUtils.isEmpty(src)) return "";
335+
if(src.length() <= maxLength) return src;
336+
if(maxLength < 1) throw new IllegalArgumentException("maxLength");
337+
return src.substring(0,maxLength) + "…";
338+
}
339+
331340
final String HOST_IMAGE = Global.HOST + "/api/tweet/insert_image";
332341

333342
@Override

app/src/main/java/net/coding/program/maopao/MaopaoLocationArea.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void bind(TextView topView, TextView bottomView, final Maopao.Maop
3737
public void onClick(View v) {
3838
LocationDetailActivity_.intent(v.getContext())
3939
.name(data.location)
40-
.address(locationCoord.address)
40+
.address(data.address)
4141
.latitude(locationCoord.latitude)
4242
.longitude(locationCoord.longitude)
4343
.start();

app/src/main/java/net/coding/program/maopao/item/LocationCoord.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
*/
1111
public class LocationCoord {
1212
// 经纬度均使用百度经纬度坐标(bd09ll),
13-
public String address;
1413
public double latitude, longitude;
15-
public static final String FORMAT_VERSION = "1";
14+
public boolean isCustom = false;
1615

1716
public static LocationCoord from(LocationObject locationObject) {
1817
LocationCoord locationCoord = new LocationCoord();
1918
locationCoord.latitude = locationObject.latitude;
2019
locationCoord.longitude = locationObject.longitude;
21-
locationCoord.address = locationObject.address;
20+
locationCoord.isCustom = locationObject.type == LocationObject.Type.newCustom;
2221
return locationCoord;
2322
}
2423

@@ -30,7 +29,7 @@ public static LocationCoord parse(String coord) {
3029
try {
3130
result.latitude = Double.parseDouble(parts[0]);
3231
result.longitude = Double.parseDouble(parts[1]);
33-
result.address = parts.length > 2 ? parts[2] : "不详";
32+
result.isCustom = parts.length > 2 && !("0".equals(parts[2].trim()));
3433
} catch (Throwable e) {
3534
Log.e("LocationCoord", "invalid coord format", e);
3635
return null;
@@ -43,8 +42,6 @@ public static LocationCoord parse(String coord) {
4342

4443
@Override
4544
public String toString() {
46-
return String.format("%.4f,%.4f", latitude, longitude);
47-
// String output = String.format("%f,%f", latitude, longitude);
48-
// return output;
45+
return String.format("%f,%f,%d", latitude, longitude, (isCustom?1:0));
4946
}
5047
}

app/src/main/java/net/coding/program/model/LocationObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static LocationObject newCustom(String name, double latitude, double long
5252
return locationObject;
5353
}
5454

55-
public static LocationObject custom(String id, String name, String address, double latitude, double longitude){
55+
public static LocationObject newCustom(String id, String name, String address, double latitude, double longitude){
5656
LocationObject locationObject = new LocationObject(Type.Custom, id, name, address);
5757
locationObject.latitude = latitude;
5858
locationObject.longitude = longitude;

app/src/main/java/net/coding/program/model/Maopao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static class MaopaoObject implements Serializable {
3131
public String device = "";
3232
public String location = "";
3333
public String coord = "";
34+
public String address = "";
3435

3536
public MaopaoObject(JSONObject json) throws JSONException {
3637
activity_id = json.optString("activity_id");
@@ -66,6 +67,7 @@ public MaopaoObject(JSONObject json) throws JSONException {
6667
device = json.optString("device");
6768
location = json.optString("location");
6869
coord = json.optString("coord");
70+
address = json.optString("address");
6971
}
7072
}
7173

app/src/main/res/layout/activity_location_detail.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,20 @@
6565
android:background="@drawable/line_gray"
6666
android:layout_width="match_parent"
6767
android:layout_height="1px" />
68+
69+
<TextView
70+
android:id="@+id/customText"
71+
android:visibility="gone"
72+
android:layout_width="match_parent"
73+
android:layout_height="45dp"
74+
android:paddingLeft="15dp"
75+
android:paddingRight="15dp"
76+
android:maxLines="1"
77+
android:singleLine="true"
78+
android:includeFontPadding="false"
79+
android:paddingTop="2dp"
80+
android:gravity="center"
81+
android:text="此地点为用户创建"
82+
android:textColor="#888888"
83+
android:textSize="15sp" />
6884
</LinearLayout>

0 commit comments

Comments
 (0)