admin
2022-05-07 4c7cde7ae5ed57335405459e47de4bbd2726c4ba
android/app/src/main/java/com/yeshi/makemoney/video/app/ui/main/NovelFragment.java
@@ -6,7 +6,15 @@
import com.bytedance.novel.pangolin.NovelSDK;
import com.demo.lib.common.RetainViewFragment;
import com.yeshi.makemoney.video.app.R;
import com.yeshi.makemoney.video.R;
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.NovelGoldCornUtil;
import com.yeshi.makemoney.video.app.utils.videos.VideoGoldCornUtil;
import org.apache.http.Header;
import org.json.JSONObject;
import androidx.fragment.app.FragmentManager;
@@ -46,7 +54,55 @@
    public void onResume() {
        super.onResume();
        NovelSDK.INSTANCE.getNovelFragment().onResume();
//        DPEventCollectUtil.uploadNovelReadTime(getContext());
        //今日阅读的时间
        uploadReadTime();
    }
    private void uploadReadTime() {
        long todayReadTime = NovelSDK.INSTANCE.getNovelReadingDuration();
        if (todayReadTime <= 0L) {
            return;
        }
        long lastDuration = NovelGoldCornUtil.getReadTime(getContext());
        if (lastDuration == todayReadTime) {
            return;
        }
        NovelGoldCornUtil.setReadTime(todayReadTime, getContext());
        if (!UserUtil.isLogin(getContext())) {
            return;
        }
        //上传
        HttpApiUtil.readNovel(getContext(), (int) (todayReadTime / 1000), 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) {
                    JSONObject data = jsonObject.optJSONObject("data");
                    VideoGoldCornUtil.showInComeToast(data.optInt("goldCorn"), getContext());
                }
            }
            @Override
            public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
                super.onFailure(statusCode, headers, jsonObject, e);
            }
            @Override
            public void onFinish() {
                super.onFinish();
            }
        });
    }
    @Override