diff --git a/work/src/main/java/com/hnucm/weather/AirActivity.java b/work/src/main/java/com/hnucm/weather/AirActivity.java index 3df052c..810891d 100644 --- a/work/src/main/java/com/hnucm/weather/AirActivity.java +++ b/work/src/main/java/com/hnucm/weather/AirActivity.java @@ -2,6 +2,7 @@ package com.hnucm.weather; import androidx.appcompat.app.AppCompatActivity; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.TextView; @@ -16,11 +17,13 @@ public class AirActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_air); - Call weather7Call = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") - .create(Api.class).getWearther7list("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); - weather7Call.enqueue(new Callback() { + SharedPreferences sharedPreferences = getSharedPreferences("data",MODE_PRIVATE); + String token = sharedPreferences.getString("token",""); + Call weather7ResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Weatherlist("Bearer "+ token); + weather7ResultCall.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { TextView textView1,textView2,textView3,textView4,textView5,textView6,textView7; textView1 = findViewById(R.id.textView96); textView2 = findViewById(R.id.textView97); @@ -29,17 +32,17 @@ public class AirActivity extends AppCompatActivity { textView5 = findViewById(R.id.textView100); textView6 = findViewById(R.id.textView102); textView7 = findViewById(R.id.textView103); - textView1.setText(response.body().showapi_res_body.f1.day_air_temperature); - textView2.setText(response.body().showapi_res_body.f1.day_weather); - textView3.setText(response.body().showapi_res_body.f1.night_air_temperature+"/"+response.body().showapi_res_body.f1.day_air_temperature); - textView4.setText(response.body().showapi_res_body.f1.day_wind_direction); - textView5.setText(response.body().showapi_res_body.f1.day_wind_power); - textView6.setText(response.body().showapi_res_body.f1.index.ls.title); - textView7.setText(response.body().showapi_res_body.f1.index.ls.desc); + textView1.setText(response.body().rows.get(0).dayAirTemperature); + textView2.setText(response.body().rows.get(0).dayWeather); + textView3.setText(response.body().rows.get(0).nightAirTemperature+"/"+response.body().rows.get(0).dayAirTemperature); + textView4.setText(response.body().rows.get(0).dayWindDirection); + textView5.setText(response.body().rows.get(0).dayWindPower); + textView6.setText(response.body().rows.get(0).lstitle); + textView7.setText(response.body().rows.get(0).lsdesc); } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); diff --git a/work/src/main/java/com/hnucm/weather/AirResult.java b/work/src/main/java/com/hnucm/weather/AirResult.java new file mode 100644 index 0000000..833189f --- /dev/null +++ b/work/src/main/java/com/hnucm/weather/AirResult.java @@ -0,0 +1,41 @@ +package com.hnucm.weather; + + +import java.util.List; + +public class AirResult { + + public Integer total; + public Integer code; + public String msg; + public List rows; + + public static class Rows { + public Object createBy; + public Object createTime; + public Object updateBy; + public Object updateTime; + public Object remark; + public Integer id; + public String c5; + public String c6; + public String f2DayWeather; + public String f2NightAirTemperature; + public String f2DayAirTemperature; + public String nowWeather; + public String aqidetailQuality; + public String aqidetailAqi; + public String aqidetailPm10; + public String aqidetailCo; + public String aqidetailO3; + public String aqidetailNo2; + public String aqidetailSo2; + public String aqidetailPm25; + public String f3DayWeather; + public String f3NightAirTemperature; + public String f3DayAirTemperature; + public String f1DayWeather; + public String f1NightAirTemperature; + public String f1DayAirTemperature; + } +} diff --git a/work/src/main/java/com/hnucm/weather/Api.java b/work/src/main/java/com/hnucm/weather/Api.java index 3e3d77a..fffa6aa 100644 --- a/work/src/main/java/com/hnucm/weather/Api.java +++ b/work/src/main/java/com/hnucm/weather/Api.java @@ -1,8 +1,13 @@ package com.hnucm.weather; +import java.util.Map; + import retrofit2.Call; +import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; +import retrofit2.http.PATCH; +import retrofit2.http.POST; import retrofit2.http.Query; public interface Api { @@ -14,4 +19,14 @@ public interface Api { Call getHourlist(@Header("Authorization") String code, @Query("area")String area); @GET("area-to-weather-date") Call getWearther7list(@Header("Authorization") String code, @Query("area")String area); + @POST("login") + Call login(@Body Map map); + @GET("system/hour24/list") + Call Hourlist(@Header("Authorization") String token); + @GET("system/day15/list") + Call Daylist(@Header("Authorization") String token); + @GET("system/weather/list") + Call Airlist(@Header("Authorization") String token); + @GET("system/weather7/list") + Call Weatherlist(@Header("Authorization") String token); } diff --git a/work/src/main/java/com/hnucm/weather/BeautyActivity.java b/work/src/main/java/com/hnucm/weather/BeautyActivity.java index e85c3aa..e924f13 100644 --- a/work/src/main/java/com/hnucm/weather/BeautyActivity.java +++ b/work/src/main/java/com/hnucm/weather/BeautyActivity.java @@ -2,6 +2,7 @@ package com.hnucm.weather; import androidx.appcompat.app.AppCompatActivity; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.TextView; @@ -16,11 +17,13 @@ public class BeautyActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_beauty); - Call weather7Call = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") - .create(Api.class).getWearther7list("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); - weather7Call.enqueue(new Callback() { + SharedPreferences sharedPreferences = getSharedPreferences("data",MODE_PRIVATE); + String token = sharedPreferences.getString("token",""); + Call weather7ResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Weatherlist("Bearer "+ token); + weather7ResultCall.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { TextView textView1,textView2,textView3,textView4,textView5,textView6,textView7; textView1 = findViewById(R.id.textView96); textView2 = findViewById(R.id.textView97); @@ -29,17 +32,16 @@ public class BeautyActivity extends AppCompatActivity { textView5 = findViewById(R.id.textView100); textView6 = findViewById(R.id.textView102); textView7 = findViewById(R.id.textView103); - textView1.setText(response.body().showapi_res_body.f1.day_air_temperature); - textView2.setText(response.body().showapi_res_body.f1.day_weather); - textView3.setText(response.body().showapi_res_body.f1.night_air_temperature+"/"+response.body().showapi_res_body.f1.day_air_temperature); - textView4.setText(response.body().showapi_res_body.f1.day_wind_direction); - textView5.setText(response.body().showapi_res_body.f1.day_wind_power); - textView6.setText(response.body().showapi_res_body.f1.index.beauty.title); - textView7.setText(response.body().showapi_res_body.f1.index.beauty.desc); + textView1.setText(response.body().rows.get(0).dayAirTemperature); + textView2.setText(response.body().rows.get(0).dayWeather); + textView3.setText(response.body().rows.get(0).nightAirTemperature+"/"+response.body().rows.get(0).dayAirTemperature); + textView4.setText(response.body().rows.get(0).dayWindDirection); + textView5.setText(response.body().rows.get(0).dayWindPower); + textView6.setText(response.body().rows.get(0).betitle); + textView7.setText(response.body().rows.get(0).bedesc); } - @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); diff --git a/work/src/main/java/com/hnucm/weather/DayResult.java b/work/src/main/java/com/hnucm/weather/DayResult.java new file mode 100644 index 0000000..f50eb39 --- /dev/null +++ b/work/src/main/java/com/hnucm/weather/DayResult.java @@ -0,0 +1,35 @@ +package com.hnucm.weather; + +import java.util.List; +public class DayResult { + + public Integer total; + public Integer code; + public String msg; + public List rows; + + public static class Rows { + public Object createBy; + public Object createTime; + public Object updateBy; + public Object updateTime; + public Object remark; + public Integer id; + public String nightWeatherPic; + public String daytime; + public String dayWindDirection; + public String dayWeatherCode; + public String area; + public String nightWindPower; + public String nightWeatherCode; + public String areaCode; + public String dayWeather; + public String dayAirTemperature; + public String nightWindDirection; + public Integer areaid; + public String nightWeather; + public String nightAirTemperature; + public String dayWeatherPic; + public String dayWindPower; + } +} \ No newline at end of file diff --git a/work/src/main/java/com/hnucm/weather/DressActivity.java b/work/src/main/java/com/hnucm/weather/DressActivity.java index 4cd1b9d..9e899a0 100644 --- a/work/src/main/java/com/hnucm/weather/DressActivity.java +++ b/work/src/main/java/com/hnucm/weather/DressActivity.java @@ -2,6 +2,7 @@ package com.hnucm.weather; import androidx.appcompat.app.AppCompatActivity; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.TextView; @@ -16,11 +17,13 @@ public class DressActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dress); - Call weather7Call = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") - .create(Api.class).getWearther7list("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); - weather7Call.enqueue(new Callback() { + SharedPreferences sharedPreferences = getSharedPreferences("data",MODE_PRIVATE); + String token = sharedPreferences.getString("token",""); + Call weather7ResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Weatherlist("Bearer "+ token); + weather7ResultCall.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { TextView textView1,textView2,textView3,textView4,textView5,textView6,textView7; textView1 = findViewById(R.id.textView96); textView2 = findViewById(R.id.textView97); @@ -29,17 +32,17 @@ public class DressActivity extends AppCompatActivity { textView5 = findViewById(R.id.textView100); textView6 = findViewById(R.id.textView102); textView7 = findViewById(R.id.textView104); - textView1.setText(response.body().showapi_res_body.f1.day_air_temperature); - textView2.setText(response.body().showapi_res_body.f1.day_weather); - textView3.setText(response.body().showapi_res_body.f1.night_air_temperature+"/"+response.body().showapi_res_body.f1.day_air_temperature); - textView4.setText(response.body().showapi_res_body.f1.day_wind_direction); - textView5.setText(response.body().showapi_res_body.f1.day_wind_power); - textView6.setText(response.body().showapi_res_body.f1.index.clothes.title); - textView7.setText(response.body().showapi_res_body.f1.index.clothes.desc); + textView1.setText(response.body().rows.get(0).dayAirTemperature); + textView2.setText(response.body().rows.get(0).dayWeather); + textView3.setText(response.body().rows.get(0).nightAirTemperature+"/"+response.body().rows.get(0).dayAirTemperature); + textView4.setText(response.body().rows.get(0).dayWindDirection); + textView5.setText(response.body().rows.get(0).dayWindPower); + textView6.setText(response.body().rows.get(0).clotitle); + textView7.setText(response.body().rows.get(0).clodesc); } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); diff --git a/work/src/main/java/com/hnucm/weather/HourResult.java b/work/src/main/java/com/hnucm/weather/HourResult.java new file mode 100644 index 0000000..b26f204 --- /dev/null +++ b/work/src/main/java/com/hnucm/weather/HourResult.java @@ -0,0 +1,30 @@ +package com.hnucm.weather; + + +import java.util.List; + +public class HourResult { + + + public Integer total; + public Integer code; + public String msg; + public List rows; + + public static class RowsBean { + public Object createBy; + public Object createTime; + public Object updateBy; + public Object updateTime; + public Object remark; + public String time; + public Integer id; + public String windDirection; + public String windPower; + public Integer areaid; + public String weatherCode; + public String temperature; + public String area; + public String weather; + } +} diff --git a/work/src/main/java/com/hnucm/weather/LoginResult.java b/work/src/main/java/com/hnucm/weather/LoginResult.java index b94c065..711a1c6 100644 --- a/work/src/main/java/com/hnucm/weather/LoginResult.java +++ b/work/src/main/java/com/hnucm/weather/LoginResult.java @@ -2,4 +2,7 @@ package com.hnucm.weather; public class LoginResult { -} + public String msg; + public Integer code; + public String token; +} \ No newline at end of file diff --git a/work/src/main/java/com/hnucm/weather/RoadActivity.java b/work/src/main/java/com/hnucm/weather/RoadActivity.java index ad8e602..dacc9b4 100644 --- a/work/src/main/java/com/hnucm/weather/RoadActivity.java +++ b/work/src/main/java/com/hnucm/weather/RoadActivity.java @@ -2,6 +2,7 @@ package com.hnucm.weather; import androidx.appcompat.app.AppCompatActivity; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.TextView; @@ -16,11 +17,13 @@ public class RoadActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_road); - Call weather7Call = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") - .create(Api.class).getWearther7list("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); - weather7Call.enqueue(new Callback() { + SharedPreferences sharedPreferences = getSharedPreferences("data",MODE_PRIVATE); + String token = sharedPreferences.getString("token",""); + Call weather7ResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Weatherlist("Bearer "+ token); + weather7ResultCall.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { TextView textView1,textView2,textView3,textView4,textView5,textView6,textView7; textView1 = findViewById(R.id.textView96); textView2 = findViewById(R.id.textView97); @@ -29,17 +32,17 @@ public class RoadActivity extends AppCompatActivity { textView5 = findViewById(R.id.textView100); textView6 = findViewById(R.id.textView102); textView7 = findViewById(R.id.textView103); - textView1.setText(response.body().showapi_res_body.f1.day_air_temperature); - textView2.setText(response.body().showapi_res_body.f1.day_weather); - textView3.setText(response.body().showapi_res_body.f1.night_air_temperature+"/"+response.body().showapi_res_body.f1.day_air_temperature); - textView4.setText(response.body().showapi_res_body.f1.day_wind_direction); - textView5.setText(response.body().showapi_res_body.f1.day_wind_power); - textView6.setText(response.body().showapi_res_body.f1.index.yh.title); - textView7.setText(response.body().showapi_res_body.f1.index.yh.desc); + textView1.setText(response.body().rows.get(0).dayAirTemperature); + textView2.setText(response.body().rows.get(0).dayWeather); + textView3.setText(response.body().rows.get(0).nightAirTemperature+"/"+response.body().rows.get(0).dayAirTemperature); + textView4.setText(response.body().rows.get(0).dayWindDirection); + textView5.setText(response.body().rows.get(0).dayWindPower); + textView6.setText(response.body().rows.get(0).yhtitle); + textView7.setText(response.body().rows.get(0).yhdesc); } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); diff --git a/work/src/main/java/com/hnucm/weather/SportsActivity.java b/work/src/main/java/com/hnucm/weather/SportsActivity.java index d68c8cb..be2a406 100644 --- a/work/src/main/java/com/hnucm/weather/SportsActivity.java +++ b/work/src/main/java/com/hnucm/weather/SportsActivity.java @@ -2,6 +2,7 @@ package com.hnucm.weather; import androidx.appcompat.app.AppCompatActivity; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.TextView; @@ -16,11 +17,13 @@ public class SportsActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sports); - Call weather7Call = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") - .create(Api.class).getWearther7list("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); - weather7Call.enqueue(new Callback() { + SharedPreferences sharedPreferences = getSharedPreferences("data",MODE_PRIVATE); + String token = sharedPreferences.getString("token",""); + Call weather7ResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Weatherlist("Bearer "+ token); + weather7ResultCall.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { TextView textView1,textView2,textView3,textView4,textView5,textView6,textView7; textView1 = findViewById(R.id.textView96); textView2 = findViewById(R.id.textView97); @@ -29,17 +32,17 @@ public class SportsActivity extends AppCompatActivity { textView5 = findViewById(R.id.textView100); textView6 = findViewById(R.id.textView102); textView7 = findViewById(R.id.textView103); - textView1.setText(response.body().showapi_res_body.f1.day_air_temperature); - textView2.setText(response.body().showapi_res_body.f1.day_weather); - textView3.setText(response.body().showapi_res_body.f1.night_air_temperature+"/"+response.body().showapi_res_body.f1.day_air_temperature); - textView4.setText(response.body().showapi_res_body.f1.day_wind_direction); - textView5.setText(response.body().showapi_res_body.f1.day_wind_power); - textView6.setText(response.body().showapi_res_body.f1.index.cl.title); - textView7.setText(response.body().showapi_res_body.f1.index.cl.desc); + textView1.setText(response.body().rows.get(0).dayAirTemperature); + textView2.setText(response.body().rows.get(0).dayWeather); + textView3.setText(response.body().rows.get(0).nightAirTemperature+"/"+response.body().rows.get(0).dayAirTemperature); + textView4.setText(response.body().rows.get(0).dayWindDirection); + textView5.setText(response.body().rows.get(0).dayWindPower); + textView6.setText(response.body().rows.get(0).cltitle); + textView7.setText(response.body().rows.get(0).cldesc); } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); diff --git a/work/src/main/java/com/hnucm/weather/TourismActivity.java b/work/src/main/java/com/hnucm/weather/TourismActivity.java index 7b4ee2c..0ca32d1 100644 --- a/work/src/main/java/com/hnucm/weather/TourismActivity.java +++ b/work/src/main/java/com/hnucm/weather/TourismActivity.java @@ -2,6 +2,7 @@ package com.hnucm.weather; import androidx.appcompat.app.AppCompatActivity; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.TextView; @@ -16,11 +17,13 @@ public class TourismActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tourism); - Call weather7Call = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") - .create(Api.class).getWearther7list("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); - weather7Call.enqueue(new Callback() { + SharedPreferences sharedPreferences = getSharedPreferences("data",MODE_PRIVATE); + String token = sharedPreferences.getString("token",""); + Call weather7ResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Weatherlist("Bearer "+ token); + weather7ResultCall.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { TextView textView1,textView2,textView3,textView4,textView5,textView6,textView7; textView1 = findViewById(R.id.textView96); textView2 = findViewById(R.id.textView97); @@ -29,17 +32,16 @@ public class TourismActivity extends AppCompatActivity { textView5 = findViewById(R.id.textView100); textView6 = findViewById(R.id.textView102); textView7 = findViewById(R.id.textView103); - textView1.setText(response.body().showapi_res_body.f1.day_air_temperature); - textView2.setText(response.body().showapi_res_body.f1.day_weather); - textView3.setText(response.body().showapi_res_body.f1.night_air_temperature+"/"+response.body().showapi_res_body.f1.day_air_temperature); - textView4.setText(response.body().showapi_res_body.f1.day_wind_direction); - textView5.setText(response.body().showapi_res_body.f1.day_wind_power); - textView6.setText(response.body().showapi_res_body.f1.index.travel.title); - textView7.setText(response.body().showapi_res_body.f1.index.travel.desc); + textView1.setText(response.body().rows.get(0).dayAirTemperature); + textView2.setText(response.body().rows.get(0).dayWeather); + textView3.setText(response.body().rows.get(0).nightAirTemperature+"/"+response.body().rows.get(0).dayAirTemperature); + textView4.setText(response.body().rows.get(0).dayWindDirection); + textView5.setText(response.body().rows.get(0).dayWindPower); + textView6.setText(response.body().rows.get(0).trtitle); + textView7.setText(response.body().rows.get(0).trdesc); } - @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); diff --git a/work/src/main/java/com/hnucm/weather/WashActivity.java b/work/src/main/java/com/hnucm/weather/WashActivity.java index 1af39ef..befafe9 100644 --- a/work/src/main/java/com/hnucm/weather/WashActivity.java +++ b/work/src/main/java/com/hnucm/weather/WashActivity.java @@ -2,6 +2,7 @@ package com.hnucm.weather; import androidx.appcompat.app.AppCompatActivity; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.TextView; @@ -16,11 +17,13 @@ public class WashActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wash); - Call weather7Call = RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/") - .create(Api.class).getWearther7list("APPCODE e1954955b4ca410c82c39b46677b95bd","长沙"); - weather7Call.enqueue(new Callback() { + SharedPreferences sharedPreferences = getSharedPreferences("data",MODE_PRIVATE); + String token = sharedPreferences.getString("token",""); + Call weather7ResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Weatherlist("Bearer "+ token); + weather7ResultCall.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { TextView textView1,textView2,textView3,textView4,textView5,textView6,textView7; textView1 = findViewById(R.id.textView96); textView2 = findViewById(R.id.textView97); @@ -29,17 +32,17 @@ public class WashActivity extends AppCompatActivity { textView5 = findViewById(R.id.textView100); textView6 = findViewById(R.id.textView102); textView7 = findViewById(R.id.textView103); - textView1.setText(response.body().showapi_res_body.f1.day_air_temperature); - textView2.setText(response.body().showapi_res_body.f1.day_weather); - textView3.setText(response.body().showapi_res_body.f1.night_air_temperature+"/"+response.body().showapi_res_body.f1.day_air_temperature); - textView4.setText(response.body().showapi_res_body.f1.day_wind_direction); - textView5.setText(response.body().showapi_res_body.f1.day_wind_power); - textView6.setText(response.body().showapi_res_body.f1.index.wash_car.title); - textView7.setText(response.body().showapi_res_body.f1.index.wash_car.desc); + textView1.setText(response.body().rows.get(0).dayAirTemperature); + textView2.setText(response.body().rows.get(0).dayWeather); + textView3.setText(response.body().rows.get(0).nightAirTemperature+"/"+response.body().rows.get(0).dayAirTemperature); + textView4.setText(response.body().rows.get(0).dayWindDirection); + textView5.setText(response.body().rows.get(0).dayWindPower); + textView6.setText(response.body().rows.get(0).watitle); + textView7.setText(response.body().rows.get(0).wadesc); } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); diff --git a/work/src/main/java/com/hnucm/weather/Weather7Result.java b/work/src/main/java/com/hnucm/weather/Weather7Result.java new file mode 100644 index 0000000..e4495e1 --- /dev/null +++ b/work/src/main/java/com/hnucm/weather/Weather7Result.java @@ -0,0 +1,42 @@ +package com.hnucm.weather; + +import java.util.List; + +public class Weather7Result { + + public Integer total; + public Integer code; + public String msg; + public List rows; + + public static class Rows { + public Object createBy; + public Object createTime; + public Object updateBy; + public Object updateTime; + public Object remark; + public Integer id; + public String c5; + public String c6; + public String dayWindPower; + public String dayWeather; + public String dayWindDirection; + public String nightAirTemperature; + public String dayWeatherPic; + public String dayAirTemperature; + public String yhdesc; + public String yhtitle; + public String cldesc; + public String cltitle; + public String trdesc; + public String trtitle; + public String bedesc; + public String betitle; + public String lsdesc; + public String lstitle; + public String clodesc; + public String clotitle; + public String wadesc; + public String watitle; + } +} \ No newline at end of file diff --git a/work/src/main/java/com/hnucm/weather/WeatherFragment.java b/work/src/main/java/com/hnucm/weather/WeatherFragment.java index 5e4f6c4..ccf9460 100644 --- a/work/src/main/java/com/hnucm/weather/WeatherFragment.java +++ b/work/src/main/java/com/hnucm/weather/WeatherFragment.java @@ -1,6 +1,9 @@ package com.hnucm.weather; +import static android.content.Context.MODE_PRIVATE; + import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import androidx.annotation.NonNull; @@ -29,12 +32,14 @@ public class WeatherFragment extends Fragment { RecyclerView recyclerView,recyclerView1; MyAdapter myAdapter; MyAdapter1 myAdapter1; - List weatherList = new ArrayList(); - List hourList = new ArrayList(); + List weatherList = 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); + SharedPreferences sharedPreferences = getActivity().getSharedPreferences("data",MODE_PRIVATE); + String token = sharedPreferences.getString("token",""); recyclerView = view.findViewById(R.id.recycleview); recyclerView1 = view.findViewById(R.id.recycleview1); myAdapter1 = new MyAdapter1(); @@ -50,65 +55,60 @@ public class WeatherFragment extends Fragment { 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 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() { + Call weather7ResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Weatherlist("Bearer "+ token); + weather7ResultCall.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) { + 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); + // textView3 = view.findViewById(R.id.textView110); + textView1.setText(response.body().rows.get(0).dayWeather); + textView2.setText(response.body().rows.get(0).nightAirTemperature+"/"+response.body().rows.get(0).dayAirTemperature); Glide.with(getContext()) - .load(response.body().showapi_res_body.f1.day_weather_pic) + .load(response.body().rows.get(0).dayWeatherPic) .into(imageView); } - @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); - weatherCall.enqueue(new Callback() { + Call hourResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Hourlist("Bearer "+ token); + hourResultCall.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { - - weatherList.addAll(response.body().showapi_res_body.dayList); - - Log.i( "onResponse: ","123456789"); - myAdapter.notifyDataSetChanged(); + public void onResponse(Call call, Response response) { + hourList.addAll(response.body().rows); + myAdapter1.notifyDataSetChanged(); } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); - airCall.enqueue(new Callback() { + Call dayResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Daylist("Bearer "+ token); + dayResultCall.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { -// airList.add(response.body()); + public void onResponse(Call call, Response response) { + weatherList.addAll(response.body().rows); + myAdapter.notifyDataSetChanged(); + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + Call airResultCall = + RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).Airlist("Bearer "+ token); + airResultCall.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { TextView textView1,textView2,textView3,textView4,textView5,textView6,textView7,textView8; textView1=view.findViewById(R.id.textView71); textView2=view.findViewById(R.id.textView73); @@ -118,18 +118,18 @@ public class WeatherFragment extends Fragment { textView6=view.findViewById(R.id.textView83); textView7=view.findViewById(R.id.textView86); textView8=view.findViewById(R.id.textView89); - textView1.setText(response.body().showapi_res_body.now.aqiDetail.aqi); - textView2.setText(response.body().showapi_res_body.now.aqiDetail.quality); - textView3.setText(response.body().showapi_res_body.now.aqiDetail.pm2_5); - textView4.setText(response.body().showapi_res_body.now.aqiDetail.no2); - textView5.setText(response.body().showapi_res_body.now.aqiDetail.o3); - textView6.setText(response.body().showapi_res_body.now.aqiDetail.pm10); - textView7.setText(response.body().showapi_res_body.now.aqiDetail.co); - textView8.setText(response.body().showapi_res_body.now.aqiDetail.so2); + textView1.setText(response.body().rows.get(0).aqidetailAqi); + textView2.setText(response.body().rows.get(0).aqidetailQuality); + textView3.setText(response.body().rows.get(0).aqidetailPm25); + textView4.setText(response.body().rows.get(0).aqidetailNo2); + textView5.setText(response.body().rows.get(0).aqidetailO3); + textView6.setText(response.body().rows.get(0).aqidetailPm10); + textView7.setText(response.body().rows.get(0).aqidetailCo); + textView8.setText(response.body().rows.get(0).aqidetailSo2); } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { } }); @@ -211,11 +211,11 @@ public class WeatherFragment extends Fragment { Log.i("onBindViewHolder","onBindViewHolder"); holder.daytime.setText(weatherList.get(position).daytime); //holder.day.setText(weatherList.get(position).daytime); - holder.weather.setText(weatherList.get(position).day_weather); + holder.weather.setText(weatherList.get(position).dayWeather); // holder.imageView.setImageURI(Uri.parse("https://app1.showapi.com/weather/icon/night/01.png")); - holder.temp.setText(weatherList.get(position).night_air_temperature+"/"+weatherList.get(position).day_air_temperature); + holder.temp.setText(weatherList.get(position).nightAirTemperature+"/"+weatherList.get(position).dayAirTemperature); Glide.with(getContext()) - .load(weatherList.get(position).day_weather_pic) + .load(weatherList.get(position).dayWeatherPic) .into(holder.imageView); } diff --git a/work/src/main/java/com/hnucm/weather/WelcomeActivity.java b/work/src/main/java/com/hnucm/weather/WelcomeActivity.java index f420429..0ed16df 100644 --- a/work/src/main/java/com/hnucm/weather/WelcomeActivity.java +++ b/work/src/main/java/com/hnucm/weather/WelcomeActivity.java @@ -12,44 +12,42 @@ import android.util.Log; import com.gyf.immersionbar.ImmersionBar; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; -import okhttp3.Call; -import okhttp3.Callback; import okhttp3.OkHttp; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.Response; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; public class WelcomeActivity extends AppCompatActivity { - +//10.138.78.100 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcome); ImmersionBar.with(this).init(); -// Request request = new Request.Builder() -// .url("https://test1265l.usemock.com/text3213") -// .get() -// .build(); -// OkHttpClient okHttpClient = new OkHttpClient(); -// Call call = okHttpClient.newCall(request); -// call.enqueue(new Callback() { -// @Override -// public void onFailure(@NonNull Call call, @NonNull IOException e) { -// Log.i("errorTest",e.toString()); -// } -// @Override -// public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { -// String result = response.body().string(); -// Log.i("test",result); -// runOnUiThread(new Runnable() { -// @Override -// public void run() { -// -// } -// }); -// } -// }); + Map map = new HashMap<>(); + map.put("username","admin"); + map.put("password","admin123"); + Call loginResultCall= RetrofitUtils.getRetrofit("http://10.138.78.100:8080/").create(Api.class).login(map); + loginResultCall.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + LoginResult loginResult = response.body(); + if(loginResult.code==200){ + SharedPreferences.Editor editor = getSharedPreferences("data",MODE_PRIVATE).edit(); + editor.putString("token",loginResult.token); + editor.apply(); + } + } + @Override + public void onFailure(Call call, Throwable t) { + + } + }); Thread thread = new Thread(new Runnable() { @Override public void run() {