| | |
| | | package com.weikou.beibeivideo.ui.recent; |
| | | |
| | | import android.app.Dialog; |
| | | import android.os.Bundle; |
| | | import android.support.v4.app.Fragment; |
| | | import android.support.v4.widget.SwipeRefreshLayout; |
| | | import androidx.fragment.app.Fragment; |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.lcjian.library.util.RefreshLayout; |
| | | import com.lcjian.library.dialog.DialogUtil; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.weikou.beibeivideo.BasicTextHttpResponseHandler; |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.BeibeiVideoApplication; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.entity.vo.WatchHistoryVO; |
| | | import com.weikou.beibeivideo.ui.dialog.LoadingDialogUtil; |
| | | import com.weikou.beibeivideo.util.JsonUtil; |
| | | import com.weikou.beibeivideo.util.UserUtil; |
| | | import com.weikou.beibeivideo.widget.MySwipeRefreshLayout; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONObject; |
| | |
| | | |
| | | public class WatchHistoryFragment extends Fragment { |
| | | |
| | | private RefreshLayout srl; |
| | | private MySwipeRefreshLayout srl; |
| | | |
| | | private WatchHistoryAdapter mAdapter; |
| | | |
| | |
| | | |
| | | private long count = 0; |
| | | |
| | | private Dialog loadingDialog; |
| | | |
| | | public void setDeleteCallback( |
| | | DownloadAdapter2.IGetDeleteCallback getdeleteNumber) { |
| | | this.getdeleteNumber = getdeleteNumber; |
| | |
| | | mAdapter.setDeleteCallback(getdeleteNumber); |
| | | } |
| | | |
| | | private void initView(View view){ |
| | | private void initView(View view) { |
| | | list = view.findViewById(R.id.list); |
| | | list.setDividerHeight(1); |
| | | mAdapter = new WatchHistoryAdapter(list.getContext(), voList); |
| | |
| | | mAdapter.setDeleteCallback(getdeleteNumber); |
| | | list.setAdapter(mAdapter); |
| | | |
| | | srl = view.findViewById(R.id.srl_watch_history); |
| | | srl = view.findViewById(R.id.srl_watch_history); |
| | | ProgressBar pb = new ProgressBar(getContext()); |
| | | srl.setFooter(pb); |
| | | srl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | currentPage = 1; |
| | | getWatchHistory(currentPage); |
| | | currentPage = 1; |
| | | getWatchHistory(currentPage); |
| | | } |
| | | }); |
| | | srl.setOnLoadListener(new RefreshLayout.OnLoadListener() { |
| | | srl.setOnLoadListener(new MySwipeRefreshLayout.OnLoadListener() { |
| | | @Override |
| | | public void onLoad() { |
| | | getWatchHistory(currentPage+1); |
| | | getWatchHistory(currentPage + 1); |
| | | } |
| | | }); |
| | | srl.setRefreshing(true); |
| | | |
| | | |
| | | |
| | | loadingDialog = LoadingDialogUtil.getLoadingDialog(getContext(), ""); |
| | | getWatchHistory(currentPage); |
| | | } |
| | | |
| | |
| | | Bundle savedInstanceState) { |
| | | View view = inflater.inflate(R.layout.watch_history_fragment, container, |
| | | false); |
| | | |
| | | return view; |
| | | } |
| | | |
| | | @Override |
| | | public void onViewCreated(View view, Bundle savedInstanceState) { |
| | | super.onViewCreated(view, savedInstanceState); |
| | | initView(view); |
| | | empty = view.findViewById(R.id.fl_empty); |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onResume() { |
| | | super.onResume(); |
| | | mAdapter.setSelectedMode(false); |
| | | MobclickAgent.onPageStart("主页面——最近——观看记录"); |
| | | if (mAdapter != null) |
| | | mAdapter.setSelectedMode(false); |
| | | } |
| | | |
| | | @Override |
| | | public void onPause() { |
| | | super.onPause(); |
| | | MobclickAgent.onPageEnd("主页面——最近——观看记录"); |
| | | } |
| | | |
| | | |
| | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | Gson gson = new GsonBuilder().setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE) |
| | | .create(); |
| | | |
| | | JSONObject data = jsonObject.optJSONObject("Data"); |
| | | count = data.optLong("count"); |
| | | Type type = new TypeToken<List<WatchHistoryVO>>() { |
| | | }.getType(); |
| | | |
| | | List<WatchHistoryVO> list = gson.fromJson(data.optJSONArray("list").toString(), type); |
| | | List<WatchHistoryVO> list = JsonUtil.videoGson.fromJson(data.optJSONArray("list").toString(), type); |
| | | currentPage = page; |
| | | if (voList == null) |
| | | voList = new ArrayList<>(); |
| | | if (page == 1) |
| | | voList.clear(); |
| | | if (list != null && list.size() > 0) { |
| | | voList.addAll(list); |
| | | } |
| | | if (voList.size() > 0) { |
| | | empty.setVisibility(View.GONE); |
| | | } else { |
| | | empty.setVisibility(View.VISIBLE); |
| | | } |
| | | mAdapter.notifyDataSetChanged(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | | srl.setRefreshing(false); |
| | | srl.setLoading(false); |
| | | } |
| | | }); |
| | | } |
| | |
| | | |
| | | BeibeiVideoAPI.deleteWatchHistory(BeibeiVideoApplication.application, UserUtil.getUid(BeibeiVideoApplication.application), ids, new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onStart() { |
| | | super.onStart(); |
| | | DialogUtil.show(loadingDialog); |
| | | } |
| | | |
| | | @Override |
| | | public void onFinish() { |
| | | super.onFinish(); |
| | | DialogUtil.dismiss(loadingDialog); |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | for (int i = 0; i < voList.size(); i++) { |