diff --git a/app/app-release.apk b/app/app-release.apk deleted file mode 100644 index 5c4b82c..0000000 Binary files a/app/app-release.apk and /dev/null differ diff --git a/app/src/main/java/com/liyu/fakeweather/ui/bus/BusFragment.java b/app/src/main/java/com/liyu/fakeweather/ui/bus/BusFragment.java index a6ed53c..1d8a12d 100644 --- a/app/src/main/java/com/liyu/fakeweather/ui/bus/BusFragment.java +++ b/app/src/main/java/com/liyu/fakeweather/ui/bus/BusFragment.java @@ -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; diff --git a/app/src/main/java/com/liyu/fakeweather/ui/bus/LineDetailActivity.java b/app/src/main/java/com/liyu/fakeweather/ui/bus/LineDetailActivity.java index c0d68cb..82de02e 100644 --- a/app/src/main/java/com/liyu/fakeweather/ui/bus/LineDetailActivity.java +++ b/app/src/main/java/com/liyu/fakeweather/ui/bus/LineDetailActivity.java @@ -4,6 +4,7 @@ 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; @@ -11,11 +12,13 @@ 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; @@ -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; @@ -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); @@ -190,14 +195,22 @@ public void call(BusLineDetail busLineDetail) { } } }) - .flatMap(new Func1>>() { + .flatMap(new Func1>() { @Override - public Observable> call(BusLineDetail busLineDetail) { + public Observable call(BusLineDetail busLineDetail) { + return RxLocation.get().locate(LineDetailActivity.this); + } + }) + .flatMap(new Func1>>() { + @Override + public Observable> call(BDLocation bdLocation) { Map 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()); } }) @@ -225,10 +238,25 @@ public void onNext(BaseBusResponse 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) { diff --git a/app/src/main/java/com/liyu/fakeweather/ui/bus/adapter/LineDetailAdapter.java b/app/src/main/java/com/liyu/fakeweather/ui/bus/adapter/LineDetailAdapter.java index 7bb10d0..dd8ae93 100644 --- a/app/src/main/java/com/liyu/fakeweather/ui/bus/adapter/LineDetailAdapter.java +++ b/app/src/main/java/com/liyu/fakeweather/ui/bus/adapter/LineDetailAdapter.java @@ -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; @@ -24,7 +26,13 @@ public LineDetailAdapter(int layoutResId, List 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())) { @@ -39,4 +47,6 @@ public void onClick(View view) { } }); } + + }