Kotlin高仿微信-项目实践58篇详细讲解了各个功能点,包括:注册、登录、主页、单聊(文本、表情、语音、图片、小视频、视频通话、语音通话、红包、转账)、群聊、个人信息、朋友圈、支付服务、扫一扫、搜索好友、添加好友、开通VIP等众多功能。
效果图:
实现代码:
/** * Author : wangning * Email : maoning20080809@163.com * Date : 2022/5/24 16:11 * Description : 朋友圈小视频播放 */ class SVideoPlayFragment : BaseDataBindingFragment(){ override fun getLayoutRes() = R.layout.wc_svideo_play private var navController: NavController? = null private var enterType: Int = 0 private var isHideConfirm : Boolean = false private var svideoView: SVideoView? = null override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) navController = findNavController() svideoView = svideo_play_view //2图片、3、小视频 var type = arguments?.get(CommonUtils.Moments.TYPE_NAME) as Int var filePath = arguments?.get(CommonUtils.Moments.TYPE_IMAGE_PATH).toString() //小视频路径 var videoFilePath = arguments?.get(CommonUtils.Moments.TYPE_VIDEO_PATH).toString() //enterType = arguments?.get(CameraFragment.TYPE_ENTER) arguments?.let { it.get(CameraFragment.TYPE_ENTER)?.let { enterType = it as Int } it.get(CommonUtils.Chat.IS_HIDE_CONFIRM)?.let { isHideConfirm = it as Boolean } } if(type.equals(CommonUtils.Moments.TYPE_PICTURE)){ super.builder().setTitleContent(R.string.me_moments_picture_preview) svideo_play_view.visibility = View.GONE photo_preview_icon.visibility = View.VISIBLE var degree = ImageUtils.getExifOrientation(filePath) TagUtils.d("图片角度:${degree} , 图片路径:${filePath}") if(degree == 0){ GlideUtils.load(photo_preview_icon, filePath) } else { GlideUtils.loadRounded(photo_preview_icon, filePath, degree) } } else if(type.equals(CommonUtils.Moments.TYPE_VIDEO)){ super.builder().setTitleContent(R.string.me_moments_video_preview) svideo_play_view.visibility = View.VISIBLE photo_preview_icon.visibility = View.GONE TagUtils.d("播放小视频文件:${videoFilePath}") svideo_play_view.initData(videoFilePath, true) } if(isHideConfirm){ photo_preview_confirm.visibility = View.GONE } photo_preview_confirm.setOnClickListener { TagUtils.d("点击返回按钮:${enterType}") if(enterType == CameraFragment.TYPE_CHAT){ var sVideoBean : SVideoBean? = null if(type.equals(CommonUtils.Moments.TYPE_PICTURE)){ //图片 sVideoBean = SVideoBean(type, filePath) } else if(type.equals(CommonUtils.Moments.TYPE_VIDEO)){ //小视频 sVideoBean = SVideoBean(type, videoFilePath) } EventBus.getDefault().post(sVideoBean) navController?.popBackStack(R.id.nav_chat, false) } else if(enterType == CameraFragment.TYPE_MOMENT){ TagUtils.d("跳转到发布:${type}, ${videoFilePath} , ${filePath}") navController?.popBackStack() var bundle = bundleOf(CommonUtils.Moments.TYPE_NAME to type, CommonUtils.Moments.TYPE_IMAGE_PATH to filePath, CommonUtils.Moments.TYPE_VIDEO_PATH to videoFilePath) navController?.navigate(R.id.action_moments_publish, bundle) } else { TagUtils.d("点击返回按钮:else ") } } svideo_play_root.setOnClickListener { //svideo_play_view.onDestroy() svideoView?.onDestroy() Navigation.findNavController(it).popBackStack() } } override fun onResume() { super.onResume() } var isOnPause = false override fun onStart() { super.onStart() if(isOnPause){ svideoView?.onStart() isOnPause = false } } override fun onPause() { super.onPause() isOnPause = true svideoView?.onStop() } override fun onStop() { super.onStop() } override fun onDestroy() { super.onDestroy() svideoView?.onDestroy() } }