| | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.FrameLayout; |
| | | import android.widget.ImageView; |
| | | import android.widget.PopupWindow; |
| | | |
| | | import androidx.fragment.app.Fragment; |
| | |
| | | import androidx.lifecycle.Observer; |
| | | |
| | | import com.android.app_base.manager.AppManager; |
| | | import com.android.app_base.utils.GlideUtil; |
| | | import com.android.app_base.utils.ScreenSizeUtils; |
| | | import com.android.app_base.utils.rxbus.MessageEvent; |
| | | import com.android.app_base.utils.rxbus.RxBus; |
| | | import com.application.zhangshi_app_android.BR; |
| | | import com.application.zhangshi_app_android.R; |
| | | import com.application.zhangshi_app_android.bean.BannerBean; |
| | | import com.application.zhangshi_app_android.bean.FamilyMemorabiliaBean; |
| | | import com.application.zhangshi_app_android.databinding.FragmentFunctionBinding; |
| | | import com.application.zhangshi_app_android.ui.DLBaseFragment; |
| | | import com.application.zhangshi_app_android.ui.TestActivity; |
| | | import com.application.zhangshi_app_android.ui.home.HomeFragment; |
| | | import com.application.zhangshi_app_android.ui.main.MainActivity; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | import io.reactivex.functions.Consumer; |
| | | |
| | | /** |
| | | * @author Ljj |
| | |
| | | |
| | | private PopupWindow mOperatePopupWindow; |
| | | private ImageCarouselFragment imageCarouselFragment; |
| | | private VideoFragment videoFragment; |
| | | private VideoCarouselFragment videoCarouselFragment; |
| | | |
| | | private FunctionFragment() { |
| | | } |
| | |
| | | binding.layoutContacts.setOnClickListener(v->{ |
| | | AppManager.getAppManager().startActivity(ContactsActivity.class); |
| | | }); |
| | | binding.ivOperate.setOnClickListener(v->{ |
| | | AppManager.getAppManager().startActivity(TestActivity.class); |
| | | }); |
| | | |
| | | imageCarouselFragment = ImageCarouselFragment.newInstance(); |
| | | videoFragment = VideoFragment.newInstance(); |
| | | replaceFragment(imageCarouselFragment); |
| | | binding.ivOperateSelect.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | mOperatePopupWindow = initPopUpWindow(View.inflate(getSelfActivity(),R.layout.pop_switch_video_or_image,null)); |
| | | mOperatePopupWindow.getContentView().findViewById(R.id.tv_image).setOnClickListener(v -> { |
| | | mOperatePopupWindow.dismiss(); |
| | | if (imageCarouselFragment == null){ |
| | | imageCarouselFragment = ImageCarouselFragment.newInstance(); |
| | | } |
| | | imageCarouselFragment = ImageCarouselFragment.newInstance(); |
| | | replaceFragment(imageCarouselFragment); |
| | | imageCarouselFragment.setImageList(viewModel.getImageListLiveData().getValue()); |
| | | binding.ivOperateSelect.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | }); |
| | | mOperatePopupWindow.getContentView().findViewById(R.id.tv_video).setOnClickListener(v -> { |
| | | mOperatePopupWindow.dismiss(); |
| | | if (videoFragment == null){ |
| | | videoFragment = VideoFragment.newInstance(); |
| | | } |
| | | replaceFragment(videoFragment); |
| | | videoCarouselFragment = VideoCarouselFragment.newInstance(); |
| | | replaceFragment(videoCarouselFragment); |
| | | videoCarouselFragment.setVideoList(viewModel.getVideoListLiveData().getValue()); |
| | | binding.ivOperateSelect.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | AppManager.getAppManager().startActivity(new Intent(getSelfActivity(),ImageSelectActivity.class).putExtra("flag",1).putExtra("list", (Serializable) videoFragment.getVideoList())); |
| | | AppManager.getAppManager().startActivity(new Intent(getSelfActivity(),ImageSelectActivity.class).putExtra("flag",1).putExtra("list", (Serializable) videoCarouselFragment.getVideoList())); |
| | | } |
| | | |
| | | }); |
| | |
| | | binding.ivOperate.setOnClickListener(v -> { |
| | | mOperatePopupWindow.showAsDropDown(binding.ivOperate,-ScreenSizeUtils.dip2px(getSelfActivity(),85) +binding.ivOperate.getWidth(),0); |
| | | }); |
| | | |
| | | imageCarouselFragment = ImageCarouselFragment.newInstance(); |
| | | replaceFragment(imageCarouselFragment); |
| | | } |
| | | public void replaceFragment(Fragment fragment){ |
| | | FragmentTransaction transaction = getSelfActivity().getSupportFragmentManager().beginTransaction(); |
| | |
| | | |
| | | @Override |
| | | protected void initLiveDataObserve() { |
| | | viewModel.getBannerListLiveData().observe(this, new Observer<List<BannerBean>>() { |
| | | viewModel.getImageListLiveData().observe(this, new Observer<List<BannerBean>>() { |
| | | @Override |
| | | public void onChanged(List<BannerBean> bannerBeans) { |
| | | List<BannerBean> imageList = new ArrayList<>(); |
| | | List<BannerBean> videoList = new ArrayList<>(); |
| | | for (BannerBean bannerBean : bannerBeans) { |
| | | if (bannerBean.getFlag() == 0){ |
| | | //图片 |
| | | imageList.add(bannerBean); |
| | | }else if (bannerBean.getFlag() == 1){ |
| | | //视频 |
| | | videoList.add(bannerBean); |
| | | } |
| | | if (imageCarouselFragment != null){ |
| | | imageCarouselFragment.setImageList(bannerBeans); |
| | | } |
| | | imageCarouselFragment.setImageList(imageList); |
| | | videoFragment.setVideoList(videoList); |
| | | } |
| | | }); |
| | | |
| | | viewModel.getVideoListLiveData().observe(this, new Observer<List<BannerBean>>() { |
| | | @Override |
| | | public void onChanged(List<BannerBean> bannerBeans) { |
| | | if (videoCarouselFragment != null){ |
| | | videoCarouselFragment.setVideoList(bannerBeans); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |