| | |
| | | package com.yeshi.makemoney.video.app.ui.main; |
| | | |
| | | import android.os.Bundle; |
| | | import android.text.GetChars; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | |
| | |
| | | import com.demo.lib.common.RetainViewFragment; |
| | | import com.demo.lib.common.util.common.DimenUtils; |
| | | import com.jaeger.library.StatusBarUtil; |
| | | import com.yeshi.makemoney.video.app.R; |
| | | import com.yeshi.makemoney.video.R; |
| | | import com.yeshi.makemoney.video.app.utils.SettingUtil; |
| | | import com.yeshi.makemoney.video.app.utils.UserUtil; |
| | | import com.yeshi.makemoney.video.app.utils.api.BasicTextHttpResponseHandler; |
| | | import com.yeshi.makemoney.video.app.utils.api.HttpApiUtil; |
| | | import com.yeshi.makemoney.video.app.utils.videos.NewsGoldCornUtil; |
| | | import com.yeshi.makemoney.video.app.utils.videos.VideoGoldCornUtil; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.util.Map; |
| | | |
| | |
| | | * 主页面--快手视频 |
| | | */ |
| | | public class DYNewsFragment extends RetainViewFragment { |
| | | |
| | | //最少的浏览时间 |
| | | private final Long MIN_SPACE_TIME = 1000 * 5L; |
| | | |
| | | private AQuery mAquery; |
| | | |
| | | private static final String TAG = "DYNewsFragment"; |
| | | private IDPWidget mIDPWidget; |
| | | |
| | |
| | | super(); |
| | | } |
| | | |
| | | private Fragment fragment; |
| | | private long startTime; |
| | | |
| | | |
| | | @Override |
| | |
| | | if (mIDPWidget != null && mIDPWidget.getFragment() != null) { |
| | | mIDPWidget.getFragment().onHiddenChanged(hidden); |
| | | } |
| | | refreshNotify(); |
| | | } |
| | | |
| | | @Override |
| | | public void onCreateView(View contentView, Bundle savedInstanceState) { |
| | | Log.i(TAG, "onCreateView"); |
| | | StatusBarUtil.setDarkMode(getActivity()); |
| | | AQuery mAquery = new AQuery(contentView); |
| | | mAquery = new AQuery(contentView); |
| | | mAquery.id(R.id.view_status_bar).height(DimenUtils.px2dip(getContext(), DimenUtils.getStatusBarHeight(getContext()))); |
| | | |
| | | mAquery.id(R.id.iv_close).clicked(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | closeNotify(); |
| | | } |
| | | }); |
| | | refreshNotify(); |
| | | initNewsWidget(); |
| | | } |
| | | |
| | | private void refreshNotify() { |
| | | if (mAquery == null) { |
| | | return; |
| | | } |
| | | if (SettingUtil.getSetting(SettingUtil.SettingKey.showNewsNotify, getContext())) { |
| | | mAquery.id(R.id.fl_notify).visibility(View.VISIBLE); |
| | | } else { |
| | | mAquery.id(R.id.fl_notify).visibility(View.GONE); |
| | | } |
| | | } |
| | | |
| | | private void closeNotify() { |
| | | if (mAquery == null) { |
| | | return; |
| | | } |
| | | mAquery.id(R.id.fl_notify).visibility(View.GONE); |
| | | SettingUtil.saveSetting(SettingUtil.SettingKey.showNewsNotify, false, getContext()); |
| | | } |
| | | |
| | | private void initNewsWidget() { |
| | |
| | | public void onDPNewsDetailEnter(Map<String, Object> map) { |
| | | log("onDPNewsDetailEnter"); |
| | | // DPEventCollectUtil.newsDetailEnter(getContext(), map); |
| | | if (startTime == 0L) { |
| | | startTime = System.currentTimeMillis(); |
| | | } |
| | | |
| | | if (System.currentTimeMillis() - startTime > MIN_SPACE_TIME) { |
| | | startTime = System.currentTimeMillis(); |
| | | addCount(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onDPNewsDetailExit(Map<String, Object> map) { |
| | | log("onDPNewsDetailExit"); |
| | | if (startTime > 0) { |
| | | if (System.currentTimeMillis() - startTime > MIN_SPACE_TIME) { |
| | | startTime = 0L; |
| | | addCount(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | })); |
| | | |
| | | Fragment fragment = mIDPWidget.getFragment(); |
| | |
| | | Log.d(TAG, String.valueOf(msg)); |
| | | } |
| | | |
| | | private void addCount() { |
| | | NewsGoldCornUtil.addNewsCount(getContext()); |
| | | if (!UserUtil.isLogin(getContext())) { |
| | | return; |
| | | } |
| | | |
| | | int num = NewsGoldCornUtil.getNewsCount(getContext()); |
| | | HttpApiUtil.scanNews(getContext(), num, new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onStart() { |
| | | super.onStart(); |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | super.onSuccessPerfect(statusCode, headers, jsonObject); |
| | | if (jsonObject.optInt("code") == 0) { |
| | | //减去上传的数量 |
| | | NewsGoldCornUtil.setNewsCount(NewsGoldCornUtil.getNewsCount(getContext()) - num, getContext()); |
| | | //上传成功 |
| | | JSONObject data = jsonObject.optJSONObject("data"); |
| | | VideoGoldCornUtil.showInComeToast(data.optInt("goldCorn"), getContext()); |
| | | closeNotify(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) { |
| | | super.onFailure(statusCode, headers, jsonObject, e); |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |