66陪玩-origin
This commit is contained in:
127
app/src/main/java/com/yizhuan/erban/common/ReloadFragment.java
Normal file
127
app/src/main/java/com/yizhuan/erban/common/ReloadFragment.java
Normal file
@@ -0,0 +1,127 @@
|
||||
package com.yizhuan.erban.common;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yizhuan.xchat_android_library.utils.NetworkUtils;
|
||||
import com.yizhuan.xchat_android_library.utils.log.MLog;
|
||||
import com.yizhuan.erban.R;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* Created by xujiexing on 14-4-9.
|
||||
*/
|
||||
public class ReloadFragment extends AbsStatusFragment {
|
||||
private static final String TIP_PARAM = "TIP_PARAM";
|
||||
private static final String DRAWABLE_PARAM = "DRAWABLE_PARAM";
|
||||
private static final String BG_PARAM = "BG_PARAM";
|
||||
private int mTip;
|
||||
private int mDrawable;
|
||||
private int mBgColor = 1;
|
||||
|
||||
public static ReloadFragment newInstance() {
|
||||
return new ReloadFragment();
|
||||
}
|
||||
|
||||
public static ReloadFragment newInstance(int drawable, int tips) {
|
||||
return newInstance(drawable, tips, -1);
|
||||
}
|
||||
|
||||
public static ReloadFragment newInstance(int drawable, int tips, @ColorInt int bgColor) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(TIP_PARAM, tips);
|
||||
bundle.putInt(DRAWABLE_PARAM, drawable);
|
||||
bundle.putInt(BG_PARAM, bgColor);
|
||||
ReloadFragment fragment = new ReloadFragment();
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_reload, container, false);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mTip = savedInstanceState.getInt(TIP_PARAM, R.string.click_screen_reload);
|
||||
mDrawable = savedInstanceState.getInt(DRAWABLE_PARAM, R.drawable.icon_common_failure);
|
||||
mBgColor = savedInstanceState.getInt(BG_PARAM, mBgColor);
|
||||
} else {
|
||||
Bundle bundle = getArguments();
|
||||
if (bundle != null) {
|
||||
mTip = bundle.getInt(TIP_PARAM, R.string.click_screen_reload);
|
||||
mDrawable = bundle.getInt(DRAWABLE_PARAM, R.drawable.icon_common_failure);
|
||||
mBgColor = bundle.getInt(BG_PARAM, mBgColor);
|
||||
} else {
|
||||
mTip = R.string.click_screen_reload;
|
||||
mDrawable = R.drawable.icon_common_failure;
|
||||
}
|
||||
}
|
||||
if (mTip <= 0) {
|
||||
mTip = R.string.click_screen_reload;
|
||||
}
|
||||
|
||||
if (mDrawable <= 0) {
|
||||
mDrawable = R.drawable.icon_common_failure;
|
||||
}
|
||||
if(mBgColor != 1){
|
||||
view.setBackgroundColor(mBgColor);
|
||||
}
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.reload_icon);
|
||||
imageView.setImageDrawable(getResources().getDrawable(mDrawable));
|
||||
TextView textView = (TextView) view.findViewById(R.id.error_text);
|
||||
textView.setText(getString(mTip));
|
||||
view.setOnClickListener(mSelfListener);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(TIP_PARAM, mTip);
|
||||
outState.putInt(DRAWABLE_PARAM, mDrawable);
|
||||
}
|
||||
|
||||
private View.OnClickListener mSelfListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!checkActivityValid())
|
||||
return;
|
||||
if (!NetworkUtils.isNetworkStrictlyAvailable(getActivity())) {
|
||||
checkNetToast();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mLoadListener != null) {
|
||||
mLoadListener.onClick(v);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@TargetApi(17)
|
||||
protected boolean checkActivityValid() {
|
||||
if (getActivity() == null) {
|
||||
MLog.warn(this, "Fragment " + this + " not attached to Activity");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getActivity().isFinishing()) {
|
||||
MLog.warn(this, "activity is finishing");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 17 && getActivity().isDestroyed()) {
|
||||
MLog.warn(this, "activity is isDestroyed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user