android eventbus ui sqlite http
실행 결과:
로그 인쇄:
흐름 도:
1
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mBaseView = LayoutInflater.from(getActivity()).inflate(R.layout.friendship_list_fragment, null);
initUtils();
initView(mBaseView);
initListeners();
EventBus.getDefault().register( this );
FriendshipUserRequest.getFriendshipUserFromWeb(user.getId());
return mBaseView;
}
2
public class FriendshipUserRequest {
public static void getFriendshipUserFromWeb(long userId ){
GsonRequest<QueryResultJson> gsonRequest = new GsonRequest<QueryResultJson>(
Constants.friendship_url+ userId, QueryResultJson.class,
new Response.Listener<QueryResultJson>() {
@Override
public void onResponse(QueryResultJson response) {
JsonElement obj = response.retdata;
if (obj != null && response.retcode == 200) {
Log.e("baoyou","obj.toString() == "+ obj.toString());
FriendshipUserEntity resultjson = JsonParser.parseDateJson(obj.toString(), FriendshipUserEntity.class);
FriendshipUserHttpManager.getFriendshipUserFromWeb(resultjson);
}else{
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) ;
Volley.newRequestQueue(MyApplication.newInstance()).add(gsonRequest);
}
}
3
public class FriendshipUserHttpManager {
public static void getFriendshipUserFromWeb( FriendshipUserEntity item){
List<FriendshipUserEntity> list = new ArrayList<FriendshipUserEntity>();
list.add(item);
FriendshipUserHttpEvent dbEvent = new FriendshipUserHttpEvent();
dbEvent.status = list.size() == 0? RequestStatus.HTTP_NONE: RequestStatus.HTTP_SUCCESS;
dbEvent.mDataList = list;
Log.e("baoyou", "--"+list.size() + list.toString());
EventBus.getDefault().post(dbEvent);
}
}
4.
public void onEventMainThread(RequestEvent dbEvent) {
Log.e("baoyou", "-- event ==================" );
if (dbEvent instanceof FriendshipUserHttpEvent) {
Log.e("baoyou", "-- event http ==================" );
FriendshipUserHttpEvent event = (FriendshipUserHttpEvent) dbEvent;
switch (dbEvent.status) {
case HTTP_NONE:
break;
case HTTP_SUCCESS: {
FriendshipUserEntity item = event.mDataList.get(0);
userDB.deleteAll();
friendShipDB.deleteAll();
for (UserEntity ue : item.userList) {
userDB.saveOrUpdate(ue);
}
for (FriendShipEntity fse : item.friendShipList) {
friendShipDB.saveOrUpdate(fse);
}
FriendShipDBManager.getAllFromDB(friendShipDB);
}
break;
default:
break;
}
}
@Override
public void onDestroy() {
EventBus.getDefault().unregister( this );
super.onDestroy();
}
5.
public class FriendShipDBManager {
public static void getAllFromDB(FriendShipDB friendShipDB){
List<FriendShipEntity> list = friendShipDB.getAll();
FriendShipDBEvent dbEvent = new FriendShipDBEvent();
dbEvent.status = list.size() == 0? RequestStatus.DB_NONE: RequestStatus.DB_SUCCESS;
dbEvent.mDataList = list;
EventBus.getDefault().post(dbEvent);
}
}
6.
else if (dbEvent instanceof FriendShipDBEvent) {
Log.e("baoyou", "-- event db ==================" );
FriendShipDBEvent event = (FriendShipDBEvent) dbEvent;
switch (dbEvent.status) {
case DB_NONE:
break;
case DB_SUCCESS: {
List<FriendShipEntity> list = event.mDataList;
List<FriendShips> dataList = new ArrayList<FriendShips>();
for (FriendShipEntity fs : list) {
UserEntity userEntityByIndex = null;
if (fs.getUserId() != 0)
userEntityByIndex = userDB.getEntityById(fs.getUserId() + "");
FriendShips item = new FriendShips();
item.setId(fs.getId());
item.setUserSrc(fs.getUserSrc());
item.setParentId(fs.getParentId());
item.setName(fs.getName());
if (userEntityByIndex != null)
item.setName(userEntityByIndex.getNickName());
item.setUserId(fs.getUserId());
if (userEntityByIndex != null)
item.setPhoto(userEntityByIndex.getPhoto());
dataList.add(item);
}
for (FriendShips fs : dataList) {
if (fs.getParentId() == 0) {
long id = fs.getId();
List<FriendShips> childs = new ArrayList<FriendShips>();
for (FriendShips fs2 : dataList) {
if (id == fs2.getParentId()) {
childs.add(fs2);
}
}
fs.setChilds(childs);
mDataList.add(fs);
}
}
mAdapter.notifyDataSetChanged();
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Application Development in WebOSDevelop applications in WebOS Recognize the abstract class Application The operating system accepts classes that impleme...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.