Skip to content

Commit

Permalink
bus line fragment show nearby station
Browse files Browse the repository at this point in the history
  • Loading branch information
li-yu committed Mar 8, 2018
1 parent 91c8b48 commit 2e17f91
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
Binary file removed app/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.baidu.location.BDLocation;
import com.liyu.fakeweather.R;
import com.liyu.fakeweather.event.BusFavoritesEvent;
import com.liyu.fakeweather.http.ApiFactory;
import com.liyu.fakeweather.http.BaseBusResponse;
import com.liyu.fakeweather.http.api.BusController;
import com.liyu.fakeweather.location.RxLocation;
import com.liyu.fakeweather.model.BusLineDetail;
import com.liyu.fakeweather.model.FavoritesBusBean;
import com.liyu.fakeweather.model.StandInfoBean;
Expand Down Expand Up @@ -62,6 +65,7 @@ public class LineDetailActivity extends BaseActivity {
private FloatingActionButton fabLike;
private FloatingActionButton fabRefresh;
private SwipeRefreshLayout refreshLayout;
private AppBarLayout appBarLayout;

private boolean isFavorite = false;
private String guid;
Expand Down Expand Up @@ -113,6 +117,7 @@ public void onRefresh() {
tvLineInfoSTime = (TextView) findViewById(R.id.tv_info_stime);
tvLineInfoETime = (TextView) findViewById(R.id.tv_info_etime);
tvLineInfoTotal = (TextView) findViewById(R.id.tv_info_total);
appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
recyclerView = (RecyclerView) findViewById(R.id.rv_line_search);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new LineDetailAdapter(R.layout.item_bus_line_detail, null);
Expand Down Expand Up @@ -190,14 +195,22 @@ public void call(BusLineDetail busLineDetail) {
}
}
})
.flatMap(new Func1<BusLineDetail, Observable<BaseBusResponse<BusLineDetail>>>() {
.flatMap(new Func1<BusLineDetail, Observable<BDLocation>>() {
@Override
public Observable<BaseBusResponse<BusLineDetail>> call(BusLineDetail busLineDetail) {
public Observable<BDLocation> call(BusLineDetail busLineDetail) {
return RxLocation.get().locate(LineDetailActivity.this);
}
})
.flatMap(new Func1<BDLocation, Observable<BaseBusResponse<BusLineDetail>>>() {
@Override
public Observable<BaseBusResponse<BusLineDetail>> call(BDLocation bdLocation) {
Map<String, String> options = new HashMap<>();
options.put("Guid", guid);
options.put("uid", BusController.uid);
options.put("DeviceID", BusController.deviceID);
options.put("sign", BusController.sign);
options.put("lat", String.valueOf(bdLocation.getLatitude()));
options.put("lng", String.valueOf(bdLocation.getLongitude()));
return ApiFactory.getBusController().getLineInfo(options).subscribeOn(Schedulers.io());
}
})
Expand Down Expand Up @@ -225,10 +238,25 @@ public void onNext(BaseBusResponse<BusLineDetail> response) {
line.setStandInfo(stations);
line.setFavorite(isFavorite);
RxDataBase.deleteThenSave(line, "LGUID = ?", response.data.getLGUID());
scrollToCurrentStation();
}
});
}

private void scrollToCurrentStation() {
int currentStation = -1;
for (int i = 0; i < adapter.getData().size(); i++) {
if (adapter.getData().get(i).getIs_vicinity() == 1) {
currentStation = i;
break;
}
}
if (currentStation > 0) {
appBarLayout.setExpanded(false, true);
recyclerView.smoothScrollToPosition(currentStation);
}
}

private void showFabStatus(boolean isFavorite) {
this.isFavorite = isFavorite;
if (isFavorite) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.liyu.fakeweather.R;
import com.liyu.fakeweather.model.StandInfoBean;
import com.liyu.fakeweather.ui.bus.StationDetailActivity;
import com.liyu.fakeweather.utils.ThemeUtil;
import com.liyu.fakeweather.widgets.StationIndicator;

import java.util.List;
Expand All @@ -24,7 +26,13 @@ public LineDetailAdapter(int layoutResId, List<StandInfoBean> data) {

@Override
protected void convert(BaseViewHolder holder, final StandInfoBean item) {
holder.setText(R.id.tv_station_name, item.getSName());
TextView tvName = holder.getView(R.id.tv_station_name);
tvName.setText(item.getSName());
if (item.getIs_vicinity() == 1) {
tvName.setCompoundDrawablesWithIntrinsicBounds(null, null, ThemeUtil.setTintDrawable(mContext.getDrawable(R.drawable.ic_location), mContext), null);
} else {
tvName.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
}
holder.setText(R.id.tv_station_status, item.getS_num_str());
StationIndicator indicator = holder.getView(R.id.bus_indicator);
if (item.getIs_vicinity() == 0 && !TextUtils.isEmpty(item.getS_num_str())) {
Expand All @@ -39,4 +47,6 @@ public void onClick(View view) {
}
});
}


}

0 comments on commit 2e17f91

Please sign in to comment.