From c9cace3b68dddf0aef599f60dbc804921b4f631b Mon Sep 17 00:00:00 2001 From: maning <154292322@qq.com> Date: Fri, 16 Oct 2020 23:25:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=91=BD=E5=90=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gankmm/ui/adapter/WeatherAdapter.java | 80 ++++++++++--------- .../ui/presenter/impl/MainPresenterImpl.java | 50 +++++++----- .../main/res/layout/item_weather_later.xml | 1 + 3 files changed, 71 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/com/maning/gankmm/ui/adapter/WeatherAdapter.java b/app/src/main/java/com/maning/gankmm/ui/adapter/WeatherAdapter.java index 2a5f881..bd50fb5 100644 --- a/app/src/main/java/com/maning/gankmm/ui/adapter/WeatherAdapter.java +++ b/app/src/main/java/com/maning/gankmm/ui/adapter/WeatherAdapter.java @@ -1,14 +1,16 @@ package com.maning.gankmm.ui.adapter; import android.content.Context; -import androidx.recyclerview.widget.DefaultItemAnimator; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.TextView; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import com.maning.gankmm.R; import com.maning.gankmm.bean.rolltools.HolidayBean; import com.maning.gankmm.bean.rolltools.WeatherFuturedaysResultBean; @@ -61,16 +63,16 @@ public void updateDatas(WeatherInfoBean weatherEntity, HolidayBean holidayBean, public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == 0) { View inflate = layoutInflater.inflate(R.layout.item_weather_header, parent, false); - return new WeatherAdapter.MyViewHolder01(inflate); + return new WeatherAdapter.ViewHolderWeatherInfo(inflate); } else if (viewType == 1) { View inflate = layoutInflater.inflate(R.layout.item_weather_later, parent, false); - return new WeatherAdapter.MyViewHolder02(inflate); + return new WeatherAdapter.ViewHolderWeatherForecast(inflate); } else if (viewType == 2) { View inflate = layoutInflater.inflate(R.layout.item_weather_suggestion, parent, false); - return new WeatherAdapter.MyViewHolderSuggestion(inflate); + return new WeatherAdapter.ViewHolderSuggestion(inflate); } else if (viewType == 3) { View inflate = layoutInflater.inflate(R.layout.item_weather_calendar, parent, false); - return new WeatherAdapter.MyViewHolder04(inflate); + return new WeatherAdapter.ViewHolderHoliday(inflate); } else { return null; } @@ -78,29 +80,29 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { - if (holder instanceof MyViewHolder01) { - final MyViewHolder01 myViewHolder01 = (MyViewHolder01) holder; - myViewHolder01.tv_01.setText(weatherEntity.getTemperature() + "°"); - myViewHolder01.tv_02.setText(weatherEntity.getWeather_desc()); - myViewHolder01.tv_03.setText("湿度:" + weatherEntity.getHumidity() + "%"); - myViewHolder01.tv_04.setText("体感:" + weatherEntity.getFeels_like() + "°"); - myViewHolder01.tv_05.setText(weatherEntity.getWind_direction() + " " + weatherEntity.getWind_scale() + "级"); + if (holder instanceof ViewHolderWeatherInfo) { + final ViewHolderWeatherInfo viewHolderWeatherInfo = (ViewHolderWeatherInfo) holder; + viewHolderWeatherInfo.tv_01.setText(weatherEntity.getTemperature() + "°"); + viewHolderWeatherInfo.tv_02.setText(weatherEntity.getWeather_desc()); + viewHolderWeatherInfo.tv_03.setText("湿度:" + weatherEntity.getHumidity() + "%"); + viewHolderWeatherInfo.tv_04.setText("体感:" + weatherEntity.getFeels_like() + "°"); + viewHolderWeatherInfo.tv_05.setText(weatherEntity.getWind_direction() + " " + weatherEntity.getWind_scale() + "级"); - } else if (holder instanceof MyViewHolder02) { - final MyViewHolder02 myViewHolder02 = (MyViewHolder02) holder; + } else if (holder instanceof ViewHolderWeatherForecast) { + final ViewHolderWeatherForecast viewHolderWeatherForecast = (ViewHolderWeatherForecast) holder; //初始化RecycleView LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false); - myViewHolder02.recycle_later.setLayoutManager(linearLayoutManager); - myViewHolder02.recycle_later.setItemAnimator(new DefaultItemAnimator()); - myViewHolder02.recycle_later.addItemDecoration(new VerticalDividerItemDecoration.Builder(mContext).color(mContext.getResources().getColor(R.color.lineColor)).build()); + viewHolderWeatherForecast.recycle_later.setLayoutManager(linearLayoutManager); + viewHolderWeatherForecast.recycle_later.setItemAnimator(new DefaultItemAnimator()); + viewHolderWeatherForecast.recycle_later.addItemDecoration(new VerticalDividerItemDecoration.Builder(mContext).color(mContext.getResources().getColor(R.color.lineColor)).build()); if (weatherForecasts != null && weatherForecasts.size() > 0) { Weather2Adapter weather2Adapter = new Weather2Adapter(mContext, weatherForecasts); - myViewHolder02.recycle_later.setAdapter(weather2Adapter); + viewHolderWeatherForecast.recycle_later.setAdapter(weather2Adapter); } - } else if (holder instanceof MyViewHolderSuggestion) { - final MyViewHolderSuggestion viewHolderSuggestion = (MyViewHolderSuggestion) holder; + } else if (holder instanceof ViewHolderSuggestion) { + final ViewHolderSuggestion viewHolderSuggestion = (ViewHolderSuggestion) holder; //生活指数 if (lifeSuggestionBean != null) { viewHolderSuggestion.tv_suggestion_01.setText(lifeSuggestionBean.getCar_washing().getBrief()); @@ -117,15 +119,15 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { viewHolderSuggestion.tv_suggestion_05.setText("旅游"); viewHolderSuggestion.tv_suggestion_06.setText("紫外线"); } - } else if (holder instanceof MyViewHolder04) { - final MyViewHolder04 myViewHolder04 = (MyViewHolder04) holder; + } else if (holder instanceof ViewHolderHoliday) { + final ViewHolderHoliday viewHolderHoliday = (ViewHolderHoliday) holder; - myViewHolder04.tv_01.setText(holidayBean.getDate()); - myViewHolder04.tv_06.setText(holidayBean.getTypeDes()); - myViewHolder04.tv_02.setText(holidayBean.getLunarCalendar()); - myViewHolder04.tv_03.setText(holidayBean.getYearTips() + " (" + holidayBean.getChineseZodiac() + ") - " + holidayBean.getSolarTerms()); - myViewHolder04.tv_04.setText(holidayBean.getSuit()); - myViewHolder04.tv_05.setText(holidayBean.getAvoid()); + viewHolderHoliday.tv_01.setText(holidayBean.getDate()); + viewHolderHoliday.tv_06.setText(holidayBean.getTypeDes()); + viewHolderHoliday.tv_02.setText(holidayBean.getLunarCalendar()); + viewHolderHoliday.tv_03.setText(holidayBean.getYearTips() + " (" + holidayBean.getChineseZodiac() + ") - " + holidayBean.getSolarTerms()); + viewHolderHoliday.tv_04.setText(holidayBean.getSuit()); + viewHolderHoliday.tv_05.setText(holidayBean.getAvoid()); } @@ -145,7 +147,7 @@ public int getItemViewType(int position) { return position; } - public static class MyViewHolder01 extends RecyclerView.ViewHolder { + public static class ViewHolderWeatherInfo extends RecyclerView.ViewHolder { @Bind(R.id.tv_01) TextView tv_01; @@ -158,24 +160,26 @@ public static class MyViewHolder01 extends RecyclerView.ViewHolder { @Bind(R.id.tv_05) TextView tv_05; - public MyViewHolder01(View itemView) { + public ViewHolderWeatherInfo(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } } - public static class MyViewHolder02 extends RecyclerView.ViewHolder { + public static class ViewHolderWeatherForecast extends RecyclerView.ViewHolder { @Bind(R.id.recycle_later) RecyclerView recycle_later; + @Bind(R.id.ll_root_weather_forecast) + LinearLayout ll_root_weather_forecast; - public MyViewHolder02(View itemView) { + public ViewHolderWeatherForecast(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } } - public static class MyViewHolderSuggestion extends RecyclerView.ViewHolder { + public static class ViewHolderSuggestion extends RecyclerView.ViewHolder { @Bind(R.id.tv_suggestion_01) TextView tv_suggestion_01; @@ -190,7 +194,7 @@ public static class MyViewHolderSuggestion extends RecyclerView.ViewHolder { @Bind(R.id.tv_suggestion_06) TextView tv_suggestion_06; - public MyViewHolderSuggestion(View itemView) { + public ViewHolderSuggestion(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } @@ -208,7 +212,7 @@ public MyViewHolderAir(View itemView) { } - public static class MyViewHolder04 extends RecyclerView.ViewHolder { + public static class ViewHolderHoliday extends RecyclerView.ViewHolder { @Bind(R.id.tv_01) TextView tv_01; @@ -223,7 +227,7 @@ public static class MyViewHolder04 extends RecyclerView.ViewHolder { @Bind(R.id.tv_06) TextView tv_06; - public MyViewHolder04(View itemView) { + public ViewHolderHoliday(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } diff --git a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java index ad72f9e..bbf8328 100644 --- a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java +++ b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java @@ -17,6 +17,7 @@ import com.maning.gankmm.utils.NetUtils; import com.maning.gankmm.utils.PermissionUtils; import com.maning.gankmm.utils.SharePreUtil; +import com.maning.gankmm.utils.ThreadPoolUtils; /** * Created by maning on 16/6/21. @@ -100,22 +101,27 @@ public void destroyLocation() { @Override public void initDatas() { - SharePreUtil.saveIntData(context, "未知", R.drawable.icon_weather_none); - SharePreUtil.saveIntData(context, "晴", R.drawable.icon_weather_sunny); - SharePreUtil.saveIntData(context, "阴", R.drawable.icon_weather_cloudy); - SharePreUtil.saveIntData(context, "多云", R.drawable.icon_weather_cloudy); - SharePreUtil.saveIntData(context, "少云", R.drawable.icon_weather_cloudy); - SharePreUtil.saveIntData(context, "晴间多云", R.drawable.icon_weather_cloudytosunny); - SharePreUtil.saveIntData(context, "局部多云", R.drawable.icon_weather_cloudy); - SharePreUtil.saveIntData(context, "雨", R.drawable.icon_weather_rain); - SharePreUtil.saveIntData(context, "小雨", R.drawable.icon_weather_rain); - SharePreUtil.saveIntData(context, "中雨", R.drawable.icon_weather_rain); - SharePreUtil.saveIntData(context, "大雨", R.drawable.icon_weather_rain); - SharePreUtil.saveIntData(context, "阵雨", R.drawable.icon_weather_rain); - SharePreUtil.saveIntData(context, "雷阵雨", R.drawable.icon_weather_thunderstorm); - SharePreUtil.saveIntData(context, "霾", R.drawable.icon_weather_haze); - SharePreUtil.saveIntData(context, "雾", R.drawable.icon_weather_fog); - SharePreUtil.saveIntData(context, "雨夹雪", R.drawable.icon_weather_snowrain); + ThreadPoolUtils.execute(new Runnable() { + @Override + public void run() { + SharePreUtil.saveIntData(context, "未知", R.drawable.icon_weather_none); + SharePreUtil.saveIntData(context, "晴", R.drawable.icon_weather_sunny); + SharePreUtil.saveIntData(context, "阴", R.drawable.icon_weather_cloudy); + SharePreUtil.saveIntData(context, "多云", R.drawable.icon_weather_cloudy); + SharePreUtil.saveIntData(context, "少云", R.drawable.icon_weather_cloudy); + SharePreUtil.saveIntData(context, "晴间多云", R.drawable.icon_weather_cloudytosunny); + SharePreUtil.saveIntData(context, "局部多云", R.drawable.icon_weather_cloudy); + SharePreUtil.saveIntData(context, "雨", R.drawable.icon_weather_rain); + SharePreUtil.saveIntData(context, "小雨", R.drawable.icon_weather_rain); + SharePreUtil.saveIntData(context, "中雨", R.drawable.icon_weather_rain); + SharePreUtil.saveIntData(context, "大雨", R.drawable.icon_weather_rain); + SharePreUtil.saveIntData(context, "阵雨", R.drawable.icon_weather_rain); + SharePreUtil.saveIntData(context, "雷阵雨", R.drawable.icon_weather_thunderstorm); + SharePreUtil.saveIntData(context, "霾", R.drawable.icon_weather_haze); + SharePreUtil.saveIntData(context, "雾", R.drawable.icon_weather_fog); + SharePreUtil.saveIntData(context, "雨夹雪", R.drawable.icon_weather_snowrain); + } + }); } @@ -128,13 +134,13 @@ public void onSuccess(AMapLocation aMapLocation) { double latitude = aMapLocation.getLatitude(); //获取城市 cityName = aMapLocation.getCity(); - if (cityName.endsWith("市")) { - cityName = cityName.substring(0, cityName.length() - 1); - } provinceName = aMapLocation.getProvince(); - if (provinceName.endsWith("省") || provinceName.endsWith("市")) { - provinceName = provinceName.substring(0, provinceName.length() - 1); - } +// if (cityName.endsWith("市")) { +// cityName = cityName.substring(0, cityName.length() - 1); +// } +// if (provinceName.endsWith("省") || provinceName.endsWith("市")) { +// provinceName = provinceName.substring(0, provinceName.length() - 1); +// } getCityWeather(provinceName, cityName, longitude, latitude); } diff --git a/app/src/main/res/layout/item_weather_later.xml b/app/src/main/res/layout/item_weather_later.xml index 2e16ffd..b8bf514 100644 --- a/app/src/main/res/layout/item_weather_later.xml +++ b/app/src/main/res/layout/item_weather_later.xml @@ -1,6 +1,7 @@