我在Android应用程序的存储库类中发出网络请求。我为了学习目的而这样做,所以我试图了解,而不使用RXJava,我将如何从我的Repository更新UI?使用MVP在Android网络请求上更新UI
调用的线索去像这样MainActivity - >演示 - >交互器 - >库 - >网络
这里是我的存储库中的代码
WeatherRepository {
WeatherNetwork network = new WeatherNetwork();
public CurrentWeather getCurrentWeather(float lat, float lng) {
network.getDailyWeather(lat, lng, new Callback() {
@Override
public void onFailure(Request request, IOException e) {
}
@Override
public void onResponse(Response response) throws IOException {
try{
String jsonData = response.body().string();
if (response.isSuccessful()) {
CurrentWeather currentWeather = getCurrentWeatherData(jsonData);
}
} catch(JSONException e) {
Log.d("DWPresen" + " JSONEXCEPTION", e.getMessage());
} catch(IOException e){
Log.d("DWPresent" + " IOEXCEPTION", e.getMessage());
}
}
});
}
}
我给了一个+1,但你也许应该接受一个答复或写你自己的。 – trocchietto