admin
2022-04-29 67bdeebb4dc381a2f46f31e3027ebcc3243a8aeb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.yeshi.makemoney.video.app.ui.main;
 
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
 
import com.bytedance.novel.pangolin.NovelSDK;
import com.demo.lib.common.RetainViewFragment;
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;
 
/**
 * 小说
 */
public class NovelFragment extends RetainViewFragment implements
        OnClickListener {
    private FragmentManager fragmentManager;
 
    public NovelFragment() {
        super();
    }
 
    public NovelFragment(FragmentManager fragmentManager) {
        super();
        this.fragmentManager = fragmentManager;
    }
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
 
    @Override
    public int getContentResource() {
        return R.layout.fragment_novel;
    }
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        getChildFragmentManager().beginTransaction().replace(R.id.fl_container, NovelSDK.INSTANCE.getNovelFragment(), "novel").commitAllowingStateLoss();
    }
 
 
    @Override
    public void onResume() {
        super.onResume();
        NovelSDK.INSTANCE.getNovelFragment().onResume();
        //今日阅读的时间
        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
    public void onPause() {
        super.onPause();
        NovelSDK.INSTANCE.getNovelFragment().onPause();
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy();
        NovelSDK.INSTANCE.getNovelFragment().onDestroy();
    }
 
    @Override
    public void onClick(View v) {
 
    }
}