forked from zhengxiaopeng/Rocko-Android-Demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb23855
commit bcba4cd
Showing
21 changed files
with
721 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
android-mvp/src/main/java/org/rocko/demos/mvp/MainActivity.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
android-mvp/src/main/java/org/rocko/demos/mvp/app/MVPDemoApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.rocko.demos.mvp.app; | ||
|
||
import android.app.Application; | ||
|
||
import com.android.volley.toolbox.Volley; | ||
|
||
import org.rocko.demos.mvp.util.volley.VolleyRequest; | ||
|
||
/** | ||
* Created by Administrator on 2015/2/6. | ||
* 替换默认的Application实现 | ||
*/ | ||
public class MVPDemoApplication extends Application { | ||
private static MVPDemoApplication instance; | ||
|
||
public MVPDemoApplication() { | ||
instance = this; | ||
} | ||
|
||
public static Application getContext() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
VolleyRequest.buildRequestQueue(this); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
android-mvp/src/main/java/org/rocko/demos/mvp/model/WeatherModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.rocko.demos.mvp.model; | ||
|
||
import org.rocko.demos.mvp.presenter.OnWeatherListener; | ||
|
||
/** | ||
* Created by Administrator on 2015/2/6. | ||
* 天气Model接口 | ||
*/ | ||
public interface WeatherModel { | ||
void loadWeather(String cityNO, OnWeatherListener listener); | ||
} |
17 changes: 17 additions & 0 deletions
17
android-mvp/src/main/java/org/rocko/demos/mvp/model/entity/Weather.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.rocko.demos.mvp.model.entity; | ||
|
||
/** | ||
* Created by Administrator on 2015/2/6. | ||
* 天气实体类 | ||
*/ | ||
public class Weather { | ||
private WeatherInfo weatherinfo; | ||
|
||
public WeatherInfo getWeatherinfo() { | ||
return weatherinfo; | ||
} | ||
|
||
public void setWeatherinfo(WeatherInfo weatherinfo) { | ||
this.weatherinfo = weatherinfo; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
android-mvp/src/main/java/org/rocko/demos/mvp/model/entity/WeatherInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.rocko.demos.mvp.model.entity; | ||
|
||
/** | ||
* Created by Administrator on 2015/2/6. | ||
*/ | ||
public class WeatherInfo { | ||
private String city; | ||
private String cityid; | ||
private String temp; | ||
private String WD; | ||
private String WS; | ||
private String SD; | ||
private String WSE; | ||
private String time; | ||
private String njd; | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public void setCity(String city) { | ||
this.city = city; | ||
} | ||
|
||
public String getCityid() { | ||
return cityid; | ||
} | ||
|
||
public void setCityid(String cityid) { | ||
this.cityid = cityid; | ||
} | ||
|
||
public String getTemp() { | ||
return temp; | ||
} | ||
|
||
public void setTemp(String temp) { | ||
this.temp = temp; | ||
} | ||
|
||
public String getWD() { | ||
return WD; | ||
} | ||
|
||
public void setWD(String WD) { | ||
this.WD = WD; | ||
} | ||
|
||
public String getWS() { | ||
return WS; | ||
} | ||
|
||
public void setWS(String WS) { | ||
this.WS = WS; | ||
} | ||
|
||
public String getSD() { | ||
return SD; | ||
} | ||
|
||
public void setSD(String SD) { | ||
this.SD = SD; | ||
} | ||
|
||
public String getWSE() { | ||
return WSE; | ||
} | ||
|
||
public void setWSE(String WSE) { | ||
this.WSE = WSE; | ||
} | ||
|
||
public String getTime() { | ||
return time; | ||
} | ||
|
||
public void setTime(String time) { | ||
this.time = time; | ||
} | ||
|
||
public String getNjd() { | ||
return njd; | ||
} | ||
|
||
public void setNjd(String njd) { | ||
this.njd = njd; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
android-mvp/src/main/java/org/rocko/demos/mvp/model/impl/WeatherModelImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.rocko.demos.mvp.model.impl; | ||
|
||
import android.util.Log; | ||
|
||
import com.android.volley.Response; | ||
import com.android.volley.VolleyError; | ||
import com.google.gson.Gson; | ||
|
||
import org.rocko.demos.mvp.model.WeatherModel; | ||
import org.rocko.demos.mvp.model.entity.Weather; | ||
import org.rocko.demos.mvp.presenter.OnWeatherListener; | ||
import org.rocko.demos.mvp.util.volley.VolleyRequest; | ||
|
||
/** | ||
* Created by Administrator on 2015/2/6. | ||
* 天气Model实现 | ||
*/ | ||
public class WeatherModelImpl implements WeatherModel { | ||
@Override | ||
public void loadWeather(String cityNO, final OnWeatherListener listener) { | ||
/*数据层操作*/ | ||
VolleyRequest.newInstance().newGsonRequest("http://www.weather.com.cn/data/sk/" + cityNO + ".html", | ||
Weather.class, new Response.Listener<Weather>() { | ||
@Override | ||
public void onResponse(Weather weather) { | ||
if (weather != null) { | ||
listener.onSuccess(weather); | ||
} else { | ||
listener.onError(); | ||
} | ||
} | ||
}, new Response.ErrorListener() { | ||
@Override | ||
public void onErrorResponse(VolleyError error) { | ||
listener.onError(); | ||
} | ||
}); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
android-mvp/src/main/java/org/rocko/demos/mvp/presenter/OnWeatherListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.rocko.demos.mvp.presenter; | ||
|
||
import org.rocko.demos.mvp.model.entity.Weather; | ||
|
||
/** | ||
* Created by Administrator on 2015/2/7. | ||
* 在Presenter层实现,给Model层回调,更改View层的状态,确保Model层不直接操作View层 | ||
*/ | ||
public interface OnWeatherListener { | ||
/** | ||
* 成功时回调 | ||
* | ||
* @param weather | ||
*/ | ||
void onSuccess(Weather weather); | ||
/** | ||
* 失败时回调,简单处理,没做什么 | ||
*/ | ||
void onError(); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
android-mvp/src/main/java/org/rocko/demos/mvp/presenter/WeatherPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.rocko.demos.mvp.presenter; | ||
|
||
/** | ||
* Created by Administrator on 2015/2/6. | ||
* 天气 Presenter接口 | ||
*/ | ||
public interface WeatherPresenter { | ||
/** | ||
* 获取天气的逻辑 | ||
*/ | ||
void getWeather(String cityNO); | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
android-mvp/src/main/java/org/rocko/demos/mvp/presenter/impl/WeatherPresenterImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.rocko.demos.mvp.presenter.impl; | ||
|
||
import org.rocko.demos.mvp.model.WeatherModel; | ||
import org.rocko.demos.mvp.model.entity.Weather; | ||
import org.rocko.demos.mvp.model.impl.WeatherModelImpl; | ||
import org.rocko.demos.mvp.presenter.OnWeatherListener; | ||
import org.rocko.demos.mvp.presenter.WeatherPresenter; | ||
import org.rocko.demos.mvp.ui.view.WeatherView; | ||
|
||
/** | ||
* Created by Administrator on 2015/2/6. | ||
* 天气 Prestener实现 | ||
*/ | ||
public class WeatherPresenterImpl implements WeatherPresenter, OnWeatherListener { | ||
/*Presenter作为中间层,持有View和Model的引用*/ | ||
private WeatherView weatherView; | ||
private WeatherModel weatherModel; | ||
|
||
public WeatherPresenterImpl(WeatherView weatherView) { | ||
this.weatherView = weatherView; | ||
weatherModel = new WeatherModelImpl(); | ||
} | ||
|
||
@Override | ||
public void getWeather(String cityNO) { | ||
weatherView.showLoading(); | ||
weatherModel.loadWeather(cityNO, this); | ||
} | ||
|
||
@Override | ||
public void onSuccess(Weather weather) { | ||
weatherView.hideLoading(); | ||
weatherView.setWeatherInfo(weather); | ||
} | ||
|
||
@Override | ||
public void onError() { | ||
weatherView.hideLoading(); | ||
weatherView.showError(); | ||
} | ||
} |
Oops, something went wrong.