diff --git a/src/main/java/com/hnucm/weather/WeatherFragment.java b/src/main/java/com/hnucm/weather/WeatherFragment.java index bc9dbec..6b0cf6e 100644 --- a/src/main/java/com/hnucm/weather/WeatherFragment.java +++ b/src/main/java/com/hnucm/weather/WeatherFragment.java @@ -1,5 +1,6 @@ package com.hnucm.weather; +import android.content.Intent; import android.os.Bundle; import androidx.annotation.NonNull; @@ -25,48 +26,70 @@ import retrofit2.Response; public class WeatherFragment extends Fragment { //https://ali-weather.showapi.com/area-to-weather-date - RecyclerView recyclerView; + RecyclerView recyclerView,recyclerView1; MyAdapter myAdapter; + MyAdapter1 myAdapter1; List weatherList = new ArrayList(); - List airList = new ArrayList<>(); + List hourList = new ArrayList(); @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_weather, container, false); recyclerView = view.findViewById(R.id.recycleview); + recyclerView1 = view.findViewById(R.id.recycleview1); + myAdapter1 = new MyAdapter1(); myAdapter = new MyAdapter(); + recyclerView1.setAdapter(myAdapter1); recyclerView.setAdapter(myAdapter); + recyclerView1.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + view.findViewById(R.id.imageView52).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getActivity(),TourismActivity.class); + startActivity(intent); + } + }); Call weatherCall = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") .create(Api.class).getWeatherlist("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); Call airCall = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") .create(Api.class).getAirlist("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); -// Call hourCall = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") -// .create(Api.class).getHourlist("APPCODE 7675f2257b9b4aea938392b8fba00fdc","长沙"); -// Call weather7Call = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") -// .create(Api.class).getWearther7list("APPCODE 7675f2257b9b4aea938392b8fba00fdc","长沙"); -// weather7Call.enqueue(new Callback() { -// @Override -// public void onResponse(Call call, Response response) { -// -// } -// -// @Override -// public void onFailure(Call call, Throwable t) { -// -// } -// }); -// hourCall.enqueue(new Callback() { -// @Override -// public void onResponse(Call call, Response response) { -// -// } -// -// @Override -// public void onFailure(Call call, Throwable t) { -// -// } -// }); + Call weather7Call = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") + .create(Api.class).getWearther7list("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); + Call hourCall = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") + .create(Api.class).getHourlist("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); + hourCall.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + hourList.addAll(response.body().showapi_res_body.hourList); + myAdapter1.notifyDataSetChanged(); + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + weather7Call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + ImageView imageView = view.findViewById(R.id.imageView50); + TextView textView1,textView2,textView3; + textView1 = view.findViewById(R.id.textView107); + textView2 = view.findViewById(R.id.textView108); + textView3 = view.findViewById(R.id.textView110); + textView1.setText(response.body().showapi_res_body.f1.day_weather); + textView2.setText(response.body().showapi_res_body.f1.night_air_temperature+"/"+response.body().showapi_res_body.f1.day_air_temperature); + Glide.with(getContext()) + .load(response.body().showapi_res_body.f1.day_weather_pic) + .into(imageView); + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); weatherCall.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { @@ -112,6 +135,47 @@ public class WeatherFragment extends Fragment { }); return view; } + public class MyViewHolder1 extends RecyclerView.ViewHolder{ + TextView time,weather,temperature; + //TextView day + //ImageView imageView; + public MyViewHolder1(@NonNull View itemView) { + super(itemView); + time = itemView.findViewById(R.id.textView105); + //day = itemView.findViewById(R.id.textView68); + weather = itemView.findViewById(R.id.textView106); + temperature = itemView.findViewById(R.id.textView109); + // imageView = itemView.findViewById(R.id.imageView); + } + } + + public class MyAdapter1 extends RecyclerView.Adapter{ + + //加载item布局文件 + @NonNull + @Override + public MyViewHolder1 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(getContext()) + .inflate(R.layout.weatherhour_item_layout, parent, false); + return new MyViewHolder1(view); + } + + //设置item中控件的值 + @Override + public void onBindViewHolder(@NonNull MyViewHolder1 holder, int position) { + String string = hourList.get(position).time; + string=string.substring(string.length()-4); + holder.time.setText(string.substring(0,2)+":"+string.substring(2)); + //holder.day.setText(weatherList.get(position).daytime); + holder.weather.setText(hourList.get(position).weather); +// holder.imageView.setImageURI(Uri.parse("https://app1.showapi.com/weather/icon/night/01.png")); + holder.temperature.setText(hourList.get(position).temperature); + } + + //列表显示的条数 + @Override + public int getItemCount() {return hourList.size();} + } public class MyViewHolder extends RecyclerView.ViewHolder{ TextView daytime; //TextView day; diff --git a/src/main/res/drawable/img_51.png b/src/main/res/drawable/img_51.png new file mode 100644 index 0000000..c0bc135 Binary files /dev/null and b/src/main/res/drawable/img_51.png differ diff --git a/src/main/res/drawable/img_52.png b/src/main/res/drawable/img_52.png new file mode 100644 index 0000000..341f64f Binary files /dev/null and b/src/main/res/drawable/img_52.png differ diff --git a/src/main/res/drawable/img_53.png b/src/main/res/drawable/img_53.png new file mode 100644 index 0000000..b10d3cc Binary files /dev/null and b/src/main/res/drawable/img_53.png differ diff --git a/src/main/res/drawable/img_54.png b/src/main/res/drawable/img_54.png new file mode 100644 index 0000000..a9dcfee Binary files /dev/null and b/src/main/res/drawable/img_54.png differ diff --git a/src/main/res/drawable/img_55.png b/src/main/res/drawable/img_55.png new file mode 100644 index 0000000..a9dcfee Binary files /dev/null and b/src/main/res/drawable/img_55.png differ diff --git a/src/main/res/drawable/img_56.png b/src/main/res/drawable/img_56.png new file mode 100644 index 0000000..3aa6904 Binary files /dev/null and b/src/main/res/drawable/img_56.png differ diff --git a/src/main/res/drawable/img_57.png b/src/main/res/drawable/img_57.png new file mode 100644 index 0000000..3aa6904 Binary files /dev/null and b/src/main/res/drawable/img_57.png differ diff --git a/src/main/res/drawable/img_58.png b/src/main/res/drawable/img_58.png new file mode 100644 index 0000000..8958257 Binary files /dev/null and b/src/main/res/drawable/img_58.png differ diff --git a/src/main/res/layout/activity_air.xml b/src/main/res/layout/activity_air.xml index 8838251..9b36659 100644 --- a/src/main/res/layout/activity_air.xml +++ b/src/main/res/layout/activity_air.xml @@ -180,7 +180,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:srcCompat="@drawable/img_22" /> + app:srcCompat="@drawable/img_55" /> + app:srcCompat="@drawable/img_53" /> + app:srcCompat="@drawable/img_52" /> + app:srcCompat="@drawable/img_51" /> + app:srcCompat="@drawable/img_56" /> + app:srcCompat="@drawable/img_58" /> + + + + + + - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/textView64" /> + + + + + + + + + \ No newline at end of file