| | |
| | | import android.support.annotation.Nullable; |
| | | import android.support.v4.app.Fragment; |
| | | import android.support.v4.app.FragmentManager; |
| | | import android.support.v4.app.FragmentPagerAdapter; |
| | | import android.support.v4.app.FragmentStatePagerAdapter; |
| | | import android.support.v4.view.ViewPager; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.FrameLayout; |
| | | |
| | | import com.google.gson.FieldNamingPolicy; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.lcjian.library.RetainViewFragment; |
| | | import com.lcjian.library.util.cache.DiskLruCache; |
| | | import com.lcjian.library.util.common.StorageUtils; |
| | | import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; |
| | | import com.viewpagerindicator.MTabPageIndicator; |
| | | import com.viewpagerindicator.IconPagerAdapter; |
| | | import com.viewpagerindicator.MainTabPageIndicator; |
| | | import com.weikou.beibeivideo.BasicTextHttpResponseHandler; |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.entity.VideoType; |
| | | import com.weikou.beibeivideo.entity.recommend.HomeClass; |
| | | import com.weikou.beibeivideo.ui.MyRetainViewFragment; |
| | | import com.weikou.beibeivideo.ui.dialog.UserProtocolDialog; |
| | | import com.weikou.beibeivideo.ui.recommend.NovelJNZFragment; |
| | | import com.weikou.beibeivideo.ui.recommend.RecommendFragment; |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.util.UserUtil; |
| | | import com.yeshi.buwanshequ.R; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONObject; |
| | |
| | | * Created by weikou2015 on 2017/9/14. |
| | | */ |
| | | |
| | | public class HomeFragment extends RetainViewFragment { |
| | | public class HomeFragment extends MyRetainViewFragment { |
| | | |
| | | private final String TAG = HomeFragment.class.getName(); |
| | | /* |
| | | * viewpager定义 |
| | | */ |
| | | HomePageAdapter adapter; |
| | | ViewPager pager; |
| | | MTabPageIndicator indicator; |
| | | MainTabPageIndicator indicator; |
| | | |
| | | FrameLayout fl_indicator; |
| | | |
| | | private DiskLruCache cache; |
| | | |
| | | public HomeFragment() { |
| | | super(HomeFragment.class.getClass().getName()); |
| | | } |
| | | |
| | | |
| | | @Override |
| | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | showProtocol(); |
| | | if (!BeibeiConstant.IS_TEST) |
| | | showProtocol(); |
| | | } |
| | | |
| | | |
| | | private void showProtocol() { |
| | | String data = "感谢您对布丸影视大全一直以来的信任!<br>"; |
| | | String data = "感谢您对" + getResources().getString(R.string.app_name) + "一直以来的信任!<br>"; |
| | | data += "我们依照新的监管要求条例更新了"; |
| | | data += String.format("<a href='%s'>《隐私政策》</a>和", BeibeiConstant.PRIVACY_POLICY); |
| | | data += String.format("<a href='%s'>《用户协议》</a>", BeibeiConstant.USER_AGREEMENT); |
| | | data += "为采取相应安全保护措施,尽力保护您的个人信息安全可控,特向你说明如下:<br>" + |
| | | "1、您在使用布丸影视大全各项产品或服务时,将会提供与具体功能相关的个人信息(可能涉及帐号、位置、存储等信息)。<br>" + |
| | | "1、您在使用" + getResources().getString(R.string.app_name) + "各项产品或服务时,将会提供与具体功能相关的个人信息(可能涉及帐号、位置、存储等信息)。<br>" + |
| | | "2、您可以随时查询、更正、删除您的个人信息,我们也提供账户注销的渠道。<br>" + |
| | | "3、未经您的再次同意,我们不会将上述信息用于您未授权的其他用途或目的。<br>" + |
| | | "4、未经监护人同意,我们不会收集使用14周岁以下(含14周岁)未成年人个人信息,且不会利用其信息推送新闻、时政信息、广告等定向推送活动。"; |
| | |
| | | public void onCreateView(View contentView, Bundle savedInstanceState) { |
| | | pager = contentView.findViewById(R.id.pager_recomend_category); |
| | | fl_indicator = contentView.findViewById(R.id.fl_indicator); |
| | | pager = contentView.findViewById(R.id.pager_recomend_category); |
| | | if (fl_indicator.getChildCount() > 0) { |
| | | fl_indicator.removeAllViews(); |
| | | } |
| | |
| | | adapter = new HomePageAdapter( |
| | | getChildFragmentManager(), categories); |
| | | pager.setAdapter(adapter); |
| | | indicator = new MTabPageIndicator( |
| | | indicator = new MainTabPageIndicator( |
| | | pager.getContext()); |
| | | indicator.setViewPager(pager, 0); |
| | | fl_indicator.addView(indicator); |
| | |
| | | getCategories(); |
| | | } |
| | | |
| | | List<VideoType> categories = new ArrayList<>(); |
| | | List<HomeClass> categories = new ArrayList<>(); |
| | | |
| | | |
| | | int count = 1; |
| | |
| | | String uid = preferences.getString("uid", ""); |
| | | BeibeiVideoAPI.getChoiceClass(pager.getContext(), uid, |
| | | new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | | Header[] headers, JSONObject jsonObject) |
| | |
| | | .create(); |
| | | categories.clear(); |
| | | |
| | | List list = gson.fromJson( |
| | | List<HomeClass> list = gson.fromJson( |
| | | jsonObject.getJSONObject("Data") |
| | | .getJSONArray("data").toString(), |
| | | new TypeToken<List<VideoType>>() { |
| | | new TypeToken<List<HomeClass>>() { |
| | | }.getType()); |
| | | |
| | | // list=list.subList(0,1); |
| | | categories.addAll(list); |
| | | adapter.notifyDataSetChanged(); |
| | | indicator.notifyDataSetChanged(); |
| | |
| | | }); |
| | | } |
| | | |
| | | class HomePageAdapter extends FragmentPagerAdapter { |
| | | class HomePageAdapter extends FragmentStatePagerAdapter implements IconPagerAdapter { |
| | | private FragmentManager fm; |
| | | |
| | | private List<VideoType> mlist; |
| | | private List<HomeClass> mlist; |
| | | |
| | | private Map<Integer,Fragment> fragments=new HashMap<>(); |
| | | private Map<String, Fragment> fragments = new HashMap<>(); |
| | | |
| | | public HomePageAdapter(FragmentManager fm, List<VideoType> list) { |
| | | public HomePageAdapter(FragmentManager fm, List<HomeClass> list) { |
| | | super(fm); |
| | | this.fm = fm; |
| | | this.mlist=list; |
| | | this.mlist = list; |
| | | } |
| | | |
| | | @Override |
| | | public Fragment getItem(int position) { |
| | | Fragment fragment= RecommendFragment.newInstance(mlist.get(position), position + ""); |
| | | fragments.put(position,fragment); |
| | | return fragment; |
| | | if ("novel".equalsIgnoreCase(mlist.get(position).getDataType())) { |
| | | return NovelJNZFragment.newInstance(); |
| | | } else { |
| | | Fragment fragment = RecommendFragment.newInstance(mlist.get(position), position + ""); |
| | | return fragment; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int getIconResId(int index) { |
| | | if ("novel".equalsIgnoreCase(mlist.get(index).getDataType())) |
| | | return R.drawable.ic_tab_xiaoshuo; |
| | | else |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | |
| | | return mlist.size(); |
| | | } |
| | | |
| | | @Override |
| | | public Object instantiateItem(ViewGroup container, int position) { |
| | | Fragment fragment = (Fragment) super.instantiateItem(container, position); |
| | | fm.beginTransaction().show(fragment).commitAllowingStateLoss(); |
| | | return fragment; |
| | | } |
| | | |
| | | @Override |
| | | public void destroyItem(ViewGroup container, int position, Object object) { |
| | | Fragment fragment=fragments.get(position); |
| | | fm.beginTransaction().hide(fragment).commitAllowingStateLoss(); |
| | | } |
| | | // @Override |
| | | // public Object instantiateItem(ViewGroup container, int position) { |
| | | // Fragment fragment = (Fragment) super.instantiateItem(container, position); |
| | | // fm.beginTransaction().show(fragment).commit(); |
| | | // return fragment; |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void destroyItem(ViewGroup container, int position, Object object) { |
| | | // Fragment fragment = fragments.get(position); |
| | | // try { |
| | | // fm.beginTransaction().hide(fragment).commit(); |
| | | // } catch (Exception e) { |
| | | // |
| | | // } |
| | | // } |
| | | |
| | | @Nullable |
| | | @Override |
| | | public CharSequence getPageTitle(int position) { |
| | | return mlist.get(position).getName(); |
| | | if ("novel".equalsIgnoreCase(mlist.get(position).getDataType())) |
| | | return ""; |
| | | else |
| | | return mlist.get(position).getName(); |
| | | } |
| | | } |
| | | } |