Client:优化性能,去除多余的刷新;解决主界面我的SettingFragment不自动刷新
This commit is contained in:
parent
8e75a24624
commit
47e882773b
@ -86,6 +86,7 @@
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
<activity
|
||||
android:name="apijson.demo.client.activity_fragment.UserActivity"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
<activity
|
||||
|
@ -195,21 +195,20 @@ public class MainTabActivity extends BaseBottomTabActivity implements OnBottomDr
|
||||
public void initData() {// 必须调用
|
||||
super.initData();
|
||||
|
||||
reloadAll();
|
||||
if (isCurrentUserCorrect() == false) {
|
||||
reloadAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void reloadAll() {
|
||||
Log.d(TAG, "reloadAll >>> ");
|
||||
HttpRequest.getUser(APIJSONApplication.getInstance().getCurrentUserId(), 0, new OnHttpResponseListener() {
|
||||
|
||||
@Override
|
||||
public void onHttpResponse(int requestCode, String resultJson, Exception e) {
|
||||
Log.d(TAG, "reloadAll >>> HttpRequest.getUser.onHttpResponse >> saveCurrentUser >>");
|
||||
APIJSONApplication.getInstance().saveCurrentUser(new JSONResponse(resultJson).getObject(User.class));
|
||||
runUiThread(new Runnable() {
|
||||
|
||||
|
@ -21,6 +21,7 @@ import zuo.biao.apijson.JSONRequest;
|
||||
import zuo.biao.apijson.JSONResponse;
|
||||
import zuo.biao.apijson.SQL;
|
||||
import zuo.biao.apijson.StringUtil;
|
||||
import zuo.biao.library.base.BaseView.OnDataChangedListener;
|
||||
import zuo.biao.library.interfaces.AdapterCallBack;
|
||||
import zuo.biao.library.interfaces.CacheCallBack;
|
||||
import zuo.biao.library.interfaces.OnBottomDragListener;
|
||||
@ -57,7 +58,8 @@ import com.alibaba.fastjson.JSONObject;
|
||||
* 查看 .SettingUtil 中的@must和@warn
|
||||
*/
|
||||
public class MomentListFragment extends BaseHttpListFragment<MomentItem, MomentAdapter>
|
||||
implements CacheCallBack<MomentItem>, OnHttpResponseListener, Runnable, TopBarMenuCallback, OnBottomDragListener {
|
||||
implements CacheCallBack<MomentItem>, OnHttpResponseListener, TopBarMenuCallback
|
||||
, OnBottomDragListener, OnDataChangedListener {
|
||||
private static final String TAG = "MomentListFragment";
|
||||
|
||||
//与Activity通信<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
@ -133,6 +135,8 @@ implements CacheCallBack<MomentItem>, OnHttpResponseListener, Runnable, TopBarMe
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
registerObserver(this);
|
||||
|
||||
argument = getArguments();
|
||||
if (argument != null) {
|
||||
range = argument.getInt(ARGUMENT_RANGE, range);
|
||||
@ -329,16 +333,18 @@ implements CacheCallBack<MomentItem>, OnHttpResponseListener, Runnable, TopBarMe
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if (range == RANGE_ALL) {
|
||||
run();
|
||||
} else {
|
||||
if (range == RANGE_USER_CIRCLE) {
|
||||
loadAfterCorrect();
|
||||
} else {
|
||||
super.onRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
super.onRefresh();
|
||||
public void onDataChanged() {
|
||||
if (range == RANGE_USER_CIRCLE) {
|
||||
super.onRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
//系统自带监听方法 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
@ -18,6 +18,7 @@ import java.io.File;
|
||||
|
||||
import zuo.biao.apijson.JSONResponse;
|
||||
import zuo.biao.apijson.StringUtil;
|
||||
import zuo.biao.library.base.BaseView.OnDataChangedListener;
|
||||
import zuo.biao.library.manager.HttpManager.OnHttpResponseListener;
|
||||
import zuo.biao.library.ui.AlertDialog;
|
||||
import zuo.biao.library.ui.AlertDialog.OnDialogButtonClickListener;
|
||||
@ -44,7 +45,7 @@ import apijson.demo.client.util.HttpRequest;
|
||||
* @use new SettingFragment(),详细使用见.DemoFragmentActivity(initData方法内)
|
||||
*/
|
||||
public class SettingFragment extends BaseFragment implements OnClickListener, OnDialogButtonClickListener
|
||||
, OnHttpResponseListener {
|
||||
, OnHttpResponseListener, OnDataChangedListener {
|
||||
private static final String TAG = "SettingFragment";
|
||||
|
||||
//与Activity通信<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
@ -67,12 +68,14 @@ public class SettingFragment extends BaseFragment implements OnClickListener, On
|
||||
setContentView(R.layout.setting_fragment);
|
||||
//类相关初始化,必须使用>>>>>>>>>>>>>>>>
|
||||
|
||||
registerObserver(this);
|
||||
|
||||
//功能归类分区方法,必须调用<<<<<<<<<<
|
||||
initView();
|
||||
initData();
|
||||
initEvent();
|
||||
//功能归类分区方法,必须调用>>>>>>>>>>
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@ -132,8 +135,7 @@ public class SettingFragment extends BaseFragment implements OnClickListener, On
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
//do nothing
|
||||
public void onDataChanged() {
|
||||
setUser(APIJSONApplication.getInstance().getCurrentUser());
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ import apijson.demo.client.view.UserView;
|
||||
* @author Lemon
|
||||
*/
|
||||
public class UserActivity extends BaseActivity implements OnClickListener, OnBottomDragListener
|
||||
, OnBottomMenuItemClickListener, OnHttpResponseListener, Runnable, OnDialogButtonClickListener {
|
||||
, OnBottomMenuItemClickListener, OnHttpResponseListener, OnDialogButtonClickListener, OnDataChangedListener {
|
||||
public static final String TAG = "UserActivity";
|
||||
|
||||
public static final String INTENT_IS_ON_EDIT_MODE = "INTENT_IS_ON_EDIT_MODE";
|
||||
@ -92,6 +92,8 @@ public class UserActivity extends BaseActivity implements OnClickListener, OnBot
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.user_activity, this);
|
||||
|
||||
registerObserver(this);
|
||||
|
||||
intent = getIntent();
|
||||
id = intent.getLongExtra(INTENT_ID, id);
|
||||
isOnEditMode = intent.getBooleanExtra(INTENT_IS_ON_EDIT_MODE, isOnEditMode);
|
||||
@ -255,12 +257,12 @@ public class UserActivity extends BaseActivity implements OnClickListener, OnBot
|
||||
super.initData();
|
||||
|
||||
if (isCurrentUserCorrect() == false) {//解决不能在未登录情况下查看
|
||||
run();
|
||||
onDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void onDataChanged() {
|
||||
tvBaseTitle.setText(isOnEditMode ? "编辑资料" : (isCurrentUser(id) ? "我的资料" : "详细资料"));
|
||||
|
||||
if (bottomMenuView != null) {
|
||||
@ -475,8 +477,7 @@ public class UserActivity extends BaseActivity implements OnClickListener, OnBot
|
||||
case HTTP_PUT:
|
||||
if (isSucceed) {
|
||||
isDataChanged = false;
|
||||
sendBroadcast(new Intent(ActionUtil.ACTION_USER_CHANGED)
|
||||
.putExtra(INTENT_ID, id));
|
||||
sendBroadcast(new Intent(ActionUtil.ACTION_RELOAD_CURRENT_USER));
|
||||
}
|
||||
showShortToast(isSucceed ? "提交成功" : "提交失败,请检查网络后重试");
|
||||
break;
|
||||
|
@ -21,6 +21,7 @@ import zuo.biao.apijson.JSON;
|
||||
import zuo.biao.apijson.JSONRequest;
|
||||
import zuo.biao.apijson.JSONResponse;
|
||||
import zuo.biao.apijson.StringUtil;
|
||||
import zuo.biao.library.base.BaseView.OnDataChangedListener;
|
||||
import zuo.biao.library.interfaces.AdapterCallBack;
|
||||
import zuo.biao.library.interfaces.CacheCallBack;
|
||||
import zuo.biao.library.interfaces.OnBottomDragListener;
|
||||
@ -54,7 +55,8 @@ import com.alibaba.fastjson.JSONObject;
|
||||
* 查看 .SettingUtil 中的@must和@warn
|
||||
*/
|
||||
public class UserListFragment extends BaseHttpListFragment<User, UserAdapter>
|
||||
implements CacheCallBack<User>, OnHttpResponseListener, Runnable, OnBottomDragListener, TopBarMenuCallback {
|
||||
implements CacheCallBack<User>, OnHttpResponseListener, OnBottomDragListener
|
||||
, TopBarMenuCallback, OnDataChangedListener {
|
||||
// private static final String TAG = "UserListFragment";
|
||||
|
||||
//与Activity通信<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
@ -148,6 +150,8 @@ implements CacheCallBack<User>, OnHttpResponseListener, Runnable, OnBottomDragLi
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
registerObserver(this);
|
||||
|
||||
argument = getArguments();
|
||||
if (argument != null) {
|
||||
idList = (List<Long>) argument.getSerializable(ARGUMENT_ID_LIST);
|
||||
@ -344,16 +348,18 @@ implements CacheCallBack<User>, OnHttpResponseListener, Runnable, OnBottomDragLi
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if (range == RANGE_ALL) {
|
||||
run();
|
||||
} else {
|
||||
if (range == RANGE_USER_FRIEND) {
|
||||
loadAfterCorrect();
|
||||
} else {
|
||||
super.onRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
super.onRefresh();
|
||||
public void onDataChanged() {
|
||||
if (range == RANGE_USER_FRIEND) {
|
||||
super.onRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
//系统自带监听方法 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
@ -15,6 +15,7 @@ limitations under the License.*/
|
||||
package apijson.demo.client.base;
|
||||
|
||||
import zuo.biao.library.base.BaseBroadcastReceiver;
|
||||
import zuo.biao.library.base.BaseView.OnDataChangedListener;
|
||||
import zuo.biao.library.util.Log;
|
||||
import zuo.biao.library.util.StringUtil;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -27,7 +28,7 @@ import apijson.demo.client.application.APIJSONApplication;
|
||||
import apijson.demo.client.model.User;
|
||||
import apijson.demo.client.util.ActionUtil;
|
||||
|
||||
public abstract class BaseActivity extends zuo.biao.library.base.BaseActivity implements Runnable {
|
||||
public abstract class BaseActivity extends zuo.biao.library.base.BaseActivity {
|
||||
private static final String TAG = "BaseActivity";
|
||||
|
||||
|
||||
@ -40,7 +41,6 @@ public abstract class BaseActivity extends zuo.biao.library.base.BaseActivity im
|
||||
|
||||
setCurrentUser();
|
||||
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
|
||||
private void setCurrentUser() {
|
||||
@ -71,33 +71,31 @@ public abstract class BaseActivity extends zuo.biao.library.base.BaseActivity im
|
||||
public void initData() {
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
/*只有当isCurrentUserCorrect()时才会被调用,如果不符合则会获取currentUser并再次判断来决定是否调用
|
||||
*/
|
||||
@Override
|
||||
public abstract void run();
|
||||
|
||||
|
||||
|
||||
private boolean isDataChanged = false;
|
||||
/**
|
||||
*/
|
||||
protected void invalidate() {
|
||||
if (isRunning() == false) {
|
||||
isDataChanged = true;
|
||||
Log.w(TAG, "invalidate isRunning() == false >> return;");
|
||||
Log.w(TAG, "onDataChanged isRunning() == false >> return;");
|
||||
return;
|
||||
}
|
||||
isDataChanged = false;
|
||||
|
||||
|
||||
setCurrentUser();
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isDataChanged) {
|
||||
Log.d(TAG, "onResume isDataChanged >> invalidate();");
|
||||
invalidate();
|
||||
if (onDataChangedListener != null) {
|
||||
Log.d(TAG, "onResume isDataChanged >> onDataChangedListener.onDataChanged();");
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +107,9 @@ public abstract class BaseActivity extends zuo.biao.library.base.BaseActivity im
|
||||
Log.e(TAG, "loadAfterCorrect isCurrentUserCorrect() == false >> return;");
|
||||
return;
|
||||
}
|
||||
run();
|
||||
if (onDataChangedListener != null) {
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -130,11 +130,20 @@ public abstract class BaseActivity extends zuo.biao.library.base.BaseActivity im
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
unregisterObserver();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
private OnDataChangedListener onDataChangedListener;
|
||||
protected void registerObserver(OnDataChangedListener onDataChangedListener) {
|
||||
this.onDataChangedListener = onDataChangedListener;
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
protected void unregisterObserver() {
|
||||
onDataChangedListener = null;
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
}
|
||||
|
||||
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -15,6 +15,7 @@ limitations under the License.*/
|
||||
package apijson.demo.client.base;
|
||||
|
||||
import zuo.biao.library.base.BaseBroadcastReceiver;
|
||||
import zuo.biao.library.base.BaseView.OnDataChangedListener;
|
||||
import zuo.biao.library.util.Log;
|
||||
import zuo.biao.library.util.StringUtil;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -27,7 +28,7 @@ import apijson.demo.client.application.APIJSONApplication;
|
||||
import apijson.demo.client.model.User;
|
||||
import apijson.demo.client.util.ActionUtil;
|
||||
|
||||
public abstract class BaseBottomTabActivity extends zuo.biao.library.base.BaseBottomTabActivity implements Runnable {
|
||||
public abstract class BaseBottomTabActivity extends zuo.biao.library.base.BaseBottomTabActivity {
|
||||
private static final String TAG = "BaseBottomTabActivity";
|
||||
|
||||
|
||||
@ -40,7 +41,6 @@ public abstract class BaseBottomTabActivity extends zuo.biao.library.base.BaseBo
|
||||
|
||||
setCurrentUser();
|
||||
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
|
||||
private void setCurrentUser() {
|
||||
@ -72,33 +72,31 @@ public abstract class BaseBottomTabActivity extends zuo.biao.library.base.BaseBo
|
||||
super.initData();
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
/*只有当isCurrentUserCorrect()时才会被调用,如果不符合则会获取currentUser并再次判断来决定是否调用
|
||||
*/
|
||||
@Override
|
||||
public abstract void run();
|
||||
|
||||
|
||||
|
||||
private boolean isDataChanged = false;
|
||||
/**
|
||||
*/
|
||||
protected void invalidate() {
|
||||
if (isRunning() == false) {
|
||||
isDataChanged = true;
|
||||
Log.w(TAG, "invalidate isRunning() == false >> return;");
|
||||
Log.w(TAG, "onDataChanged isRunning() == false >> return;");
|
||||
return;
|
||||
}
|
||||
isDataChanged = false;
|
||||
|
||||
|
||||
setCurrentUser();
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isDataChanged) {
|
||||
Log.d(TAG, "onResume isDataChanged >> invalidate();");
|
||||
invalidate();
|
||||
if (onDataChangedListener != null) {
|
||||
Log.d(TAG, "onResume isDataChanged >> onDataChangedListener.onDataChanged();");
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +108,9 @@ public abstract class BaseBottomTabActivity extends zuo.biao.library.base.BaseBo
|
||||
Log.e(TAG, "loadAfterCorrect isCurrentUserCorrect() == false >> return;");
|
||||
return;
|
||||
}
|
||||
run();
|
||||
if (onDataChangedListener != null) {
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -131,11 +131,20 @@ public abstract class BaseBottomTabActivity extends zuo.biao.library.base.BaseBo
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
unregisterObserver();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
private OnDataChangedListener onDataChangedListener;
|
||||
protected void registerObserver(OnDataChangedListener onDataChangedListener) {
|
||||
this.onDataChangedListener = onDataChangedListener;
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
protected void unregisterObserver() {
|
||||
onDataChangedListener = null;
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
}
|
||||
|
||||
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -15,6 +15,7 @@ limitations under the License.*/
|
||||
package apijson.demo.client.base;
|
||||
|
||||
import zuo.biao.library.base.BaseBroadcastReceiver;
|
||||
import zuo.biao.library.base.BaseView.OnDataChangedListener;
|
||||
import zuo.biao.library.util.Log;
|
||||
import zuo.biao.library.util.StringUtil;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -31,7 +32,7 @@ import apijson.demo.client.application.APIJSONApplication;
|
||||
import apijson.demo.client.model.User;
|
||||
import apijson.demo.client.util.ActionUtil;
|
||||
|
||||
public abstract class BaseFragment extends zuo.biao.library.base.BaseFragment implements Runnable {
|
||||
public abstract class BaseFragment extends zuo.biao.library.base.BaseFragment {
|
||||
private static final String TAG = "BaseFragment";
|
||||
|
||||
|
||||
@ -46,8 +47,6 @@ public abstract class BaseFragment extends zuo.biao.library.base.BaseFragment im
|
||||
|
||||
setCurrentUser();
|
||||
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@ -79,33 +78,31 @@ public abstract class BaseFragment extends zuo.biao.library.base.BaseFragment im
|
||||
public void initData() {
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
/*只有当isCurrentUserCorrect()时才会被调用,如果不符合则会获取currentUser并再次判断来决定是否调用
|
||||
*/
|
||||
@Override
|
||||
public abstract void run();
|
||||
|
||||
|
||||
|
||||
private boolean isDataChanged = false;
|
||||
/**
|
||||
*/
|
||||
protected void invalidate() {
|
||||
if (isRunning() == false) {
|
||||
isDataChanged = true;
|
||||
Log.w(TAG, "invalidate isRunning() == false >> return;");
|
||||
Log.w(TAG, "onDataChanged isRunning() == false >> return;");
|
||||
return;
|
||||
}
|
||||
isDataChanged = false;
|
||||
|
||||
|
||||
setCurrentUser();
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isDataChanged) {
|
||||
Log.d(TAG, "onResume isDataChanged >> invalidate();");
|
||||
invalidate();
|
||||
if (onDataChangedListener != null) {
|
||||
Log.d(TAG, "onResume isDataChanged >> onDataChangedListener.onDataChanged();");
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +114,9 @@ public abstract class BaseFragment extends zuo.biao.library.base.BaseFragment im
|
||||
Log.e(TAG, "loadAfterCorrect isCurrentUserCorrect() == false >> return;");
|
||||
return;
|
||||
}
|
||||
run();
|
||||
if (onDataChangedListener != null) {
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -138,11 +137,20 @@ public abstract class BaseFragment extends zuo.biao.library.base.BaseFragment im
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
unregisterObserver();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
private OnDataChangedListener onDataChangedListener;
|
||||
protected void registerObserver(OnDataChangedListener onDataChangedListener) {
|
||||
this.onDataChangedListener = onDataChangedListener;
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
protected void unregisterObserver() {
|
||||
onDataChangedListener = null;
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
}
|
||||
|
||||
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -15,6 +15,7 @@ limitations under the License.*/
|
||||
package apijson.demo.client.base;
|
||||
|
||||
import zuo.biao.library.base.BaseBroadcastReceiver;
|
||||
import zuo.biao.library.base.BaseView.OnDataChangedListener;
|
||||
import zuo.biao.library.util.Log;
|
||||
import zuo.biao.library.util.StringUtil;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -29,7 +30,7 @@ import apijson.demo.client.model.User;
|
||||
import apijson.demo.client.util.ActionUtil;
|
||||
|
||||
public abstract class BaseHttpListActivity<T, BA extends BaseAdapter>
|
||||
extends zuo.biao.library.base.BaseHttpListActivity<T, BA> implements Runnable {
|
||||
extends zuo.biao.library.base.BaseHttpListActivity<T, BA> {
|
||||
private static final String TAG = "BaseHttpListFragment";
|
||||
|
||||
|
||||
@ -42,7 +43,6 @@ extends zuo.biao.library.base.BaseHttpListActivity<T, BA> implements Runnable {
|
||||
|
||||
setCurrentUser();
|
||||
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
|
||||
private void setCurrentUser() {
|
||||
@ -74,33 +74,31 @@ extends zuo.biao.library.base.BaseHttpListActivity<T, BA> implements Runnable {
|
||||
super.initData();
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
/*只有当isCurrentUserCorrect()时才会被调用,如果不符合则会获取currentUser并再次判断来决定是否调用
|
||||
*/
|
||||
@Override
|
||||
public abstract void run();
|
||||
|
||||
|
||||
|
||||
private boolean isDataChanged = false;
|
||||
/**
|
||||
*/
|
||||
protected void invalidate() {
|
||||
if (isRunning() == false) {
|
||||
isDataChanged = true;
|
||||
Log.w(TAG, "invalidate isRunning() == false >> return;");
|
||||
Log.w(TAG, "onDataChanged isRunning() == false >> return;");
|
||||
return;
|
||||
}
|
||||
isDataChanged = false;
|
||||
|
||||
|
||||
setCurrentUser();
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isDataChanged) {
|
||||
Log.d(TAG, "onResume isDataChanged >> invalidate();");
|
||||
invalidate();
|
||||
if (onDataChangedListener != null) {
|
||||
Log.d(TAG, "onResume isDataChanged >> onDataChangedListener.onDataChanged();");
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +110,9 @@ extends zuo.biao.library.base.BaseHttpListActivity<T, BA> implements Runnable {
|
||||
Log.e(TAG, "loadAfterCorrect isCurrentUserCorrect() == false >> return;");
|
||||
return;
|
||||
}
|
||||
run();
|
||||
if (onDataChangedListener != null) {
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -133,11 +133,20 @@ extends zuo.biao.library.base.BaseHttpListActivity<T, BA> implements Runnable {
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
unregisterObserver();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
private OnDataChangedListener onDataChangedListener;
|
||||
protected void registerObserver(OnDataChangedListener onDataChangedListener) {
|
||||
this.onDataChangedListener = onDataChangedListener;
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
protected void unregisterObserver() {
|
||||
onDataChangedListener = null;
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
}
|
||||
|
||||
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -15,6 +15,7 @@ limitations under the License.*/
|
||||
package apijson.demo.client.base;
|
||||
|
||||
import zuo.biao.library.base.BaseBroadcastReceiver;
|
||||
import zuo.biao.library.base.BaseView.OnDataChangedListener;
|
||||
import zuo.biao.library.util.Log;
|
||||
import zuo.biao.library.util.StringUtil;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -33,7 +34,7 @@ import apijson.demo.client.model.User;
|
||||
import apijson.demo.client.util.ActionUtil;
|
||||
|
||||
public abstract class BaseHttpListFragment<T, BA extends BaseAdapter>
|
||||
extends zuo.biao.library.base.BaseHttpListFragment<T, BA> implements Runnable {
|
||||
extends zuo.biao.library.base.BaseHttpListFragment<T, BA> {
|
||||
private static final String TAG = "BaseHttpListFragment";
|
||||
|
||||
|
||||
@ -48,8 +49,6 @@ extends zuo.biao.library.base.BaseHttpListFragment<T, BA> implements Runnable {
|
||||
|
||||
setCurrentUser();
|
||||
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@ -83,10 +82,6 @@ extends zuo.biao.library.base.BaseHttpListFragment<T, BA> implements Runnable {
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
/*只有当isCurrentUserCorrect()时才会被调用,如果不符合则会获取currentUser并再次判断来决定是否调用
|
||||
*/
|
||||
@Override
|
||||
public abstract void run();
|
||||
|
||||
private boolean isDataChanged = false;
|
||||
/**
|
||||
@ -94,7 +89,7 @@ extends zuo.biao.library.base.BaseHttpListFragment<T, BA> implements Runnable {
|
||||
protected void invalidate() {
|
||||
if (isRunning() == false) {
|
||||
isDataChanged = true;
|
||||
Log.w(TAG, "invalidate isRunning() == false >> return;");
|
||||
Log.w(TAG, "onDataChanged isRunning() == false >> return;");
|
||||
return;
|
||||
}
|
||||
isDataChanged = false;
|
||||
@ -107,8 +102,10 @@ extends zuo.biao.library.base.BaseHttpListFragment<T, BA> implements Runnable {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isDataChanged) {
|
||||
Log.d(TAG, "onResume isDataChanged >> invalidate();");
|
||||
invalidate();
|
||||
if (onDataChangedListener != null) {
|
||||
Log.d(TAG, "onResume isDataChanged >> onDataChangedListener.onDataChanged();");
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +117,9 @@ extends zuo.biao.library.base.BaseHttpListFragment<T, BA> implements Runnable {
|
||||
Log.e(TAG, "loadAfterCorrect isCurrentUserCorrect() == false >> return;");
|
||||
return;
|
||||
}
|
||||
run();
|
||||
if (onDataChangedListener != null) {
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -141,10 +140,19 @@ extends zuo.biao.library.base.BaseHttpListFragment<T, BA> implements Runnable {
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
unregisterObserver();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private OnDataChangedListener onDataChangedListener;
|
||||
protected void registerObserver(OnDataChangedListener onDataChangedListener) {
|
||||
this.onDataChangedListener = onDataChangedListener;
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
protected void unregisterObserver() {
|
||||
onDataChangedListener = null;
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
}
|
||||
|
||||
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
|
||||
|
@ -15,6 +15,7 @@ limitations under the License.*/
|
||||
package apijson.demo.client.base;
|
||||
|
||||
import zuo.biao.library.base.BaseBroadcastReceiver;
|
||||
import zuo.biao.library.base.BaseView.OnDataChangedListener;
|
||||
import zuo.biao.library.util.Log;
|
||||
import zuo.biao.library.util.StringUtil;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -30,7 +31,7 @@ import apijson.demo.client.model.User;
|
||||
import apijson.demo.client.util.ActionUtil;
|
||||
|
||||
public abstract class BaseListActivity<T, LV extends AbsListView, BA extends BaseAdapter>
|
||||
extends zuo.biao.library.base.BaseListActivity<T, LV, BA> implements Runnable {
|
||||
extends zuo.biao.library.base.BaseListActivity<T, LV, BA> {
|
||||
private static final String TAG = "BaseActivity";
|
||||
|
||||
|
||||
@ -43,7 +44,6 @@ extends zuo.biao.library.base.BaseListActivity<T, LV, BA> implements Runnable {
|
||||
|
||||
setCurrentUser();
|
||||
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
|
||||
private void setCurrentUser() {
|
||||
@ -75,33 +75,31 @@ extends zuo.biao.library.base.BaseListActivity<T, LV, BA> implements Runnable {
|
||||
super.initData();
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
/*只有当isCurrentUserCorrect()时才会被调用,如果不符合则会获取currentUser并再次判断来决定是否调用
|
||||
*/
|
||||
@Override
|
||||
public abstract void run();
|
||||
|
||||
|
||||
|
||||
private boolean isDataChanged = false;
|
||||
/**
|
||||
*/
|
||||
protected void invalidate() {
|
||||
if (isRunning() == false) {
|
||||
isDataChanged = true;
|
||||
Log.w(TAG, "invalidate isRunning() == false >> return;");
|
||||
Log.w(TAG, "onDataChanged isRunning() == false >> return;");
|
||||
return;
|
||||
}
|
||||
isDataChanged = false;
|
||||
|
||||
|
||||
setCurrentUser();
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isDataChanged) {
|
||||
Log.d(TAG, "onResume isDataChanged >> invalidate();");
|
||||
invalidate();
|
||||
if (onDataChangedListener != null) {
|
||||
Log.d(TAG, "onResume isDataChanged >> onDataChangedListener.onDataChanged();");
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +111,9 @@ extends zuo.biao.library.base.BaseListActivity<T, LV, BA> implements Runnable {
|
||||
Log.e(TAG, "loadAfterCorrect isCurrentUserCorrect() == false >> return;");
|
||||
return;
|
||||
}
|
||||
run();
|
||||
if (onDataChangedListener != null) {
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -134,11 +134,20 @@ extends zuo.biao.library.base.BaseListActivity<T, LV, BA> implements Runnable {
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
unregisterObserver();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
private OnDataChangedListener onDataChangedListener;
|
||||
protected void registerObserver(OnDataChangedListener onDataChangedListener) {
|
||||
this.onDataChangedListener = onDataChangedListener;
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
protected void unregisterObserver() {
|
||||
onDataChangedListener = null;
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
}
|
||||
|
||||
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -15,6 +15,7 @@ limitations under the License.*/
|
||||
package apijson.demo.client.base;
|
||||
|
||||
import zuo.biao.library.base.BaseBroadcastReceiver;
|
||||
import zuo.biao.library.base.BaseView.OnDataChangedListener;
|
||||
import zuo.biao.library.util.Log;
|
||||
import zuo.biao.library.util.StringUtil;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -34,7 +35,7 @@ import apijson.demo.client.model.User;
|
||||
import apijson.demo.client.util.ActionUtil;
|
||||
|
||||
public abstract class BaseListFragment<T, LV extends AbsListView, BA extends BaseAdapter>
|
||||
extends zuo.biao.library.base.BaseListFragment<T, LV, BA> implements Runnable {
|
||||
extends zuo.biao.library.base.BaseListFragment<T, LV, BA> {
|
||||
protected static final String TAG = "BaseListFragment";
|
||||
|
||||
|
||||
@ -49,8 +50,6 @@ extends zuo.biao.library.base.BaseListFragment<T, LV, BA> implements Runnable {
|
||||
|
||||
setCurrentUser();
|
||||
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@ -83,33 +82,31 @@ extends zuo.biao.library.base.BaseListFragment<T, LV, BA> implements Runnable {
|
||||
super.initData();
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
/*只有当isCurrentUserCorrect()时才会被调用,如果不符合则会获取currentUser并再次判断来决定是否调用
|
||||
*/
|
||||
@Override
|
||||
public abstract void run();
|
||||
|
||||
|
||||
|
||||
private boolean isDataChanged = false;
|
||||
/**
|
||||
*/
|
||||
protected void invalidate() {
|
||||
if (isRunning() == false) {
|
||||
isDataChanged = true;
|
||||
Log.w(TAG, "invalidate isRunning() == false >> return;");
|
||||
Log.w(TAG, "onDataChanged isRunning() == false >> return;");
|
||||
return;
|
||||
}
|
||||
isDataChanged = false;
|
||||
|
||||
|
||||
setCurrentUser();
|
||||
loadAfterCorrect();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isDataChanged) {
|
||||
Log.d(TAG, "onResume isDataChanged >> invalidate();");
|
||||
invalidate();
|
||||
if (onDataChangedListener != null) {
|
||||
Log.d(TAG, "onResume isDataChanged >> onDataChangedListener.onDataChanged();");
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +118,9 @@ extends zuo.biao.library.base.BaseListFragment<T, LV, BA> implements Runnable {
|
||||
Log.e(TAG, "loadAfterCorrect isCurrentUserCorrect() == false >> return;");
|
||||
return;
|
||||
}
|
||||
run();
|
||||
if (onDataChangedListener != null) {
|
||||
onDataChangedListener.onDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -142,11 +141,20 @@ extends zuo.biao.library.base.BaseListFragment<T, LV, BA> implements Runnable {
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
unregisterObserver();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
private OnDataChangedListener onDataChangedListener;
|
||||
protected void registerObserver(OnDataChangedListener onDataChangedListener) {
|
||||
this.onDataChangedListener = onDataChangedListener;
|
||||
BaseBroadcastReceiver.register(context, receiver, ActionUtil.ACTION_USER_CHANGED);
|
||||
}
|
||||
protected void unregisterObserver() {
|
||||
onDataChangedListener = null;
|
||||
BaseBroadcastReceiver.unregister(context, receiver);
|
||||
}
|
||||
|
||||
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
Loading…
Reference in New Issue
Block a user