Commit cf052242 authored by jyx's avatar jyx

添加上传照片功能

parent 331223d6
...@@ -256,6 +256,14 @@ ...@@ -256,6 +256,14 @@
android:name=".ui.activitys.BasicUserProfileActivity" android:name=".ui.activitys.BasicUserProfileActivity"
android:exported="false" android:exported="false"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity
android:name=".ui.activitys.AlbumActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".ui.preview.ImagePreviewActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity <activity
android:name=".ui.activitys.IMActivity" android:name=".ui.activitys.IMActivity"
......
...@@ -2,6 +2,7 @@ package com.duben.roseplaylet.common ...@@ -2,6 +2,7 @@ package com.duben.roseplaylet.common
enum class OssType(var type: String) { enum class OssType(var type: String) {
ALBUM("album"),
PHOTO("photo"), PHOTO("photo"),
VIDEO("video") VIDEO("video")
......
...@@ -53,7 +53,10 @@ class IMHelper private constructor() { ...@@ -53,7 +53,10 @@ class IMHelper private constructor() {
override fun onCompleted() {} override fun onCompleted() {}
override fun onError(e: Throwable) {} override fun onError(e: Throwable) {}
override fun onNext(baseResponse: BaseResponse<JsonObject>) { override fun onNext(baseResponse: BaseResponse<JsonObject>) {
if (baseResponse.status == 200) {
val psw = baseResponse.data["pass"].asString
SECRET_KEY = psw
}
} }
}) })
} }
......
package com.duben.roseplaylet.mvp.model
import com.chad.library.adapter.base.entity.MultiItemEntity
const val IMAGE_MULTI_ITEM_ADD = 1
const val IMAGE_MULTI_ITEM_NORMAL = 2
data class ImageMultiItemEntity(
override val itemType: Int,
var img: String,
) : MultiItemEntity, java.io.Serializable
package com.duben.roseplaylet.mvp.presenters
import com.duben.library.net.neterror.BaseSubscriber
import com.duben.library.net.neterror.Throwable
import com.duben.roseplaylet.manager.AppHttpManager
import com.duben.roseplaylet.mvp.model.BaseResponse
import com.duben.roseplaylet.mvp.views.AlbumView
import com.google.gson.JsonObject
class AlbumPresenter : BasePresenter<AlbumView>() {
fun getImages() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.getImages({}),
object : BaseSubscriber<BaseResponse<JsonObject>>() {
override fun onCompleted() {
if (isLinkView) return
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.getImagesFail()
}
override fun onNext(baseResponse: BaseResponse<JsonObject>) {
if (isLinkView) return
view.hideLoading()
val code = baseResponse.status
val message = baseResponse.message
when (code) {
200 -> {
val ja = baseResponse.data["images"].asJsonArray
val imagesList = arrayListOf<String>()
ja.forEach {
imagesList.add(it.asString)
}
view.getImagesSuc(imagesList)
}
else -> {
view.showToast(message)
view.getImagesFail()
}
}
}
})
}
fun setImages(images: ArrayList<String> = arrayListOf(), image: String = "", type: Int = 0) {
val vo = HashMap<String, Any>()
if (images.isEmpty() && image.isEmpty()) return
if (images.isNotEmpty()) {
vo["images"] = images
} else {
vo["image"] = image
vo["type"] = type
}
AppHttpManager.getInstance(loanApplication)
.call(loanService.setImages(vo),
object : BaseSubscriber<BaseResponse<JsonObject>>() {
override fun onCompleted() {
if (isLinkView) return
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.setImagesFail()
}
override fun onNext(baseResponse: BaseResponse<JsonObject>) {
if (isLinkView) return
view.hideLoading()
val code = baseResponse.status
val message = baseResponse.message
when (code) {
200 -> {
view.setImagesSuc()
}
else -> {
view.showToast(message)
view.setImagesFail()
}
}
}
})
}
}
\ No newline at end of file
package com.duben.roseplaylet.mvp.views
interface AlbumView : BaseView {
fun getImagesSuc(data: List<String>)
fun getImagesFail()
fun setImagesSuc()
fun setImagesFail()
}
...@@ -488,7 +488,7 @@ public interface LoanService { ...@@ -488,7 +488,7 @@ public interface LoanService {
* 查看图片 * 查看图片
*/ */
@POST("roseApi/user/getImages") @POST("roseApi/user/getImages")
Observable<BaseResponse<JsonObject>> getImages(); Observable<BaseResponse<JsonObject>> getImages(@Body Object obj);
/** /**
* 设置图片 * 设置图片
......
package com.duben.roseplaylet.ui.activitys package com.duben.roseplaylet.ui.activitys
import android.Manifest import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.app.Dialog
import android.content.Intent import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.text.TextUtils import android.text.TextUtils
import android.view.View import android.view.View
import com.duben.library.utils.nodoubleclick.AntiShake
import com.duben.roseplaylet.R
import com.duben.roseplaylet.common.OssType
import com.duben.roseplaylet.manager.OssManager
import com.duben.roseplaylet.mvp.presenters.AlbumPresenter
import com.duben.roseplaylet.mvp.views.AlbumView
import com.duben.roseplaylet.ui.activitys.base.BaseActivity
import com.duben.roseplaylet.ui.preview.ImagePreviewActivity
import com.duben.roseplaylet.ui.widgets.DeletePhotoConfirmDialog
import com.duben.roseplaylet.ui.widgets.DialogListener
import com.duben.roseplaylet.ui.widgets.nineImage.AddImagesInfo
import com.duben.roseplaylet.ui.widgets.nineImage.AddImagesView
import com.duben.roseplaylet.utils.GlideEngine
import com.luck.picture.lib.PictureSelector import com.luck.picture.lib.PictureSelector
import com.luck.picture.lib.compress.Luban import com.luck.picture.lib.compress.Luban
import com.luck.picture.lib.config.PictureConfig import com.luck.picture.lib.config.PictureConfig
...@@ -15,66 +32,29 @@ import com.luck.picture.lib.entity.LocalMedia ...@@ -15,66 +32,29 @@ import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.style.PictureWindowAnimationStyle import com.luck.picture.lib.style.PictureWindowAnimationStyle
import com.luck.picture.lib.thread.PictureThreadUtils import com.luck.picture.lib.thread.PictureThreadUtils
import com.luck.picture.lib.tools.DateUtils import com.luck.picture.lib.tools.DateUtils
import com.luck.picture.lib.tools.SdkVersionUtils
import com.duben.library.net.neterror.BaseSubscriber
import com.duben.roseplaylet.R
import com.duben.roseplaylet.manager.AppHttpManager
import com.duben.roseplaylet.manager.OssManager
import com.duben.roseplaylet.mvp.model.BaseResponse
import com.duben.roseplaylet.mvp.model.OrderRecordBean
import com.duben.roseplaylet.ui.activitys.base.BaseActivity
import com.duben.roseplaylet.ui.widgets.nineImage.AddImagesInfo
import com.duben.roseplaylet.ui.widgets.nineImage.AddImagesView
import com.duben.roseplaylet.utils.GlideEngine
import com.duben.roseplaylet.utils.SpanUtils
import com.tbruyelle.rxpermissions.RxPermissions import com.tbruyelle.rxpermissions.RxPermissions
import com.yalantis.ucrop.UCrop import com.yalantis.ucrop.UCrop
import kotlinx.android.synthetic.main.activity_template.* import kotlinx.android.synthetic.main.activity_album.*
import kotlinx.android.synthetic.main.header_layout.* import kotlinx.android.synthetic.main.header_layout.*
import java.io.File import java.io.File
import java.util.*
import kotlin.collections.HashMap
/** class AlbumActivity : BaseActivity(), View.OnClickListener, AlbumView {
* 描述:申请模板
*/
@SuppressLint("SetTextI18n")
class TemplateActivity : BaseActivity(), View.OnClickListener {
private var mOssList = arrayListOf<String>() companion object {
const val MAX_ALBUM_SIZE = 6
}
// 图片选择框架跳转动画 private var mCanUploadMax = MAX_ALBUM_SIZE
private var mUploadCount = 0
private lateinit var mWindowAnimationStyle: PictureWindowAnimationStyle private lateinit var mWindowAnimationStyle: PictureWindowAnimationStyle
override fun getContentViewLayoutID() = R.layout.activity_template private var mOssList = arrayListOf<String>()
private val albumPresenter by lazy { AlbumPresenter() }
override fun isApplyKitKatTranslucency() = false override fun getContentViewLayoutID() = R.layout.activity_album
override fun initViewsAndEvents() { override fun initViewsAndEvents() {
tv_title.text = "计数模型申请" albumPresenter.attachView(this)
iv_left_icon.visibility = View.VISIBLE
iv_left_icon.setImageResource(R.mipmap.ic_arrow_back)
tv_name.text = SpanUtils()
.append("*")
.setForegroundColor(resources.getColor(R.color.color_FF4144))
.append("需要计数的物品名称")
.setForegroundColor(resources.getColor(R.color.black))
.create()
tv_phone.text = SpanUtils()
.append("*")
.setForegroundColor(resources.getColor(R.color.color_FF4144))
.append("联系方式")
.setForegroundColor(resources.getColor(R.color.black))
.create()
tv_photo.text = SpanUtils()
.append("*")
.setForegroundColor(resources.getColor(R.color.color_FF4144))
.append("需要计数的物品照片(5-10张图片)")
.setForegroundColor(resources.getColor(R.color.black))
.create()
mWindowAnimationStyle = PictureWindowAnimationStyle() mWindowAnimationStyle = PictureWindowAnimationStyle()
mWindowAnimationStyle.ofAllAnimation( mWindowAnimationStyle.ofAllAnimation(
...@@ -82,75 +62,90 @@ class TemplateActivity : BaseActivity(), View.OnClickListener { ...@@ -82,75 +62,90 @@ class TemplateActivity : BaseActivity(), View.OnClickListener {
com.luck.picture.lib.R.anim.picture_anim_down_out com.luck.picture.lib.R.anim.picture_anim_down_out
) )
initListener() albumPresenter.getImages()
initView()
} }
private fun initView() {
tv_title.text = "我的相册"
tv_title.setTextColor(Color.WHITE)
iv_left_icon.visibility = View.VISIBLE
iv_left_icon.setImageResource(R.mipmap.ic_arrow_white)
iv_left_icon.setOnClickListener(this)
line.visibility = View.GONE
override fun onClick(v: View?) { aiv.enableCloseView(false)
when (v?.id) { aiv.setAddImagesViewListener(object : AddImagesView.AddImagesViewListener {
R.id.iv_left_icon -> finish() override fun onAdd() {
R.id.btn_submit -> { showAlbum()
if (TextUtils.isEmpty(et_name.text)) {
showToast("申请名称不能为空")
return
} }
if (TextUtils.isEmpty(et_phone.text)) {
showToast("联系方式不能为空") override fun onDelete(position: Int) {}
return
override fun onLongClick(item: AddImagesInfo?) {
DeletePhotoConfirmDialog(this@AlbumActivity, object : DialogListener() {
override fun onClick(dialog: Dialog?, v: View?) {
super.onClick(dialog, v)
dialog?.dismiss()
if (v?.id == R.id.tv_confirm) {
aiv.deleteImage(item)
// 删除图片
albumPresenter.setImages(arrayListOf(), item?.imgUrl.toString(), 2)
} }
if (aiv.getAddImages().size < 5) {
showToast("模板照片最少需要5张")
return
} }
mOssList.clear() }).show()
luban()
} }
override fun onPreview(position: Int, lists: List<AddImagesInfo>?) {
lists?.let {
val preData = arrayListOf<String>()
for (info in it) {
preData.add(info.imgUrl.toString())
} }
val bundle = Bundle()
bundle.putStringArrayList(ImagePreviewActivity.IMAGE_PREVIEW_DATA, preData)
bundle.putInt(ImagePreviewActivity.IMAGE_PREVIEW_POSITION, position)
readyGo(ImagePreviewActivity::class.java, bundle)
} }
private fun initListener() {
iv_left_icon.setOnClickListener(this)
btn_submit.setOnClickListener(this)
aiv.setAddImagesViewListener(object : AddImagesView.AddImagesViewListener {
override fun onAdd() {
showAlbum()
} }
})
override fun onDelete(position: Int) {
} }
override fun onPreview(item: AddImagesInfo?, lists: List<AddImagesInfo>?) { override fun isApplyKitKatTranslucency() = false
override fun onClick(v: View?) {
if (AntiShake.check(v?.id)) return
when (v?.id) {
R.id.iv_left_icon -> finish()
} }
})
} }
private fun showAlbum() { private fun showAlbum() {
mCanUploadMax = MAX_ALBUM_SIZE - aiv.getAddImages().size
RxPermissions(this) RxPermissions(this)
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE) .request(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
.subscribe { granted: Boolean -> .subscribe { granted: Boolean ->
if (granted) { if (granted) {
val isEnableCrop = false
PictureSelector.create(this) PictureSelector.create(this)
.openGallery(PictureMimeType.ofImage()) .openGallery(PictureMimeType.ofImage())
.theme(R.style.picture_WeChat_style) // 微信主题色 .theme(R.style.picture_WeChat_style) // 微信主题色
.isWeChatStyle(true) // 微信样式 .isWeChatStyle(true) // 微信样式
.isCamera(false) //列表是否显示拍照按钮 .isCamera(false) //列表是否显示拍照按钮
.isZoomAnim(isEnableCrop)//图片选择缩放效果 .isZoomAnim(false)//图片选择缩放效果
.isEnableCrop(isEnableCrop)//是否开启裁剪 .isEnableCrop(true)//是否开启裁剪
.setPictureWindowAnimationStyle(mWindowAnimationStyle) .setPictureWindowAnimationStyle(mWindowAnimationStyle)
.withAspectRatio(2, 4) .withAspectRatio(2, 4)
.isCompress(true)//是否压缩 .isCompress(true)//是否压缩
.compressFocusAlpha(false)//压缩后是否保持图片的透明通道 .compressFocusAlpha(true)//压缩后是否保持图片的透明通道
.minimumCompressSize(200)// 小于多少kb的图片不压缩 .minimumCompressSize(200)// 小于多少kb的图片不压缩
.compressQuality(60)//图片压缩后输出质量 .compressQuality(60)//图片压缩后输出质量
.synOrAsy(true)//开启同步or异步压缩 .synOrAsy(true)//开启同步or异步压缩
.maxSelectNum(10) .maxSelectNum(mCanUploadMax)
.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)//屏幕旋转方向 .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)//屏幕旋转方向
.selectionMode(PictureConfig.MULTIPLE)//单选or多选 .selectionMode(PictureConfig.MULTIPLE)//单选or多选
.imageEngine(GlideEngine.createGlideEngine())// 图片加载引擎 .imageEngine(GlideEngine.createGlideEngine())// 图片加载引擎
.forResult(PictureConfig.CHOOSE_REQUEST) .forResult(PictureConfig.CHOOSE_REQUEST)
} else { } else {
showMissingPermissionDialog("存储") showMissingPermissionDialog("存储")
} }
...@@ -164,13 +159,9 @@ class TemplateActivity : BaseActivity(), View.OnClickListener { ...@@ -164,13 +159,9 @@ class TemplateActivity : BaseActivity(), View.OnClickListener {
// 相册获取图片 // 相册获取图片
PictureConfig.CHOOSE_REQUEST -> { PictureConfig.CHOOSE_REQUEST -> {
val selectList: List<LocalMedia> = PictureSelector.obtainMultipleResult(data) val selectList: List<LocalMedia> = PictureSelector.obtainMultipleResult(data)
mUploadCount = selectList.size
val imgList = arrayListOf<AddImagesInfo>() mOssList.clear()
for (localMedia in selectList) { luban(selectList)
val addImagesInfo = AddImagesInfo(localMedia.compressPath, "2")
imgList.add(addImagesInfo)
}
aiv.addAddImages(imgList)
} }
} }
} else if (resultCode == UCrop.RESULT_ERROR) { } else if (resultCode == UCrop.RESULT_ERROR) {
...@@ -182,23 +173,9 @@ class TemplateActivity : BaseActivity(), View.OnClickListener { ...@@ -182,23 +173,9 @@ class TemplateActivity : BaseActivity(), View.OnClickListener {
/** /**
* 鲁班压缩 * 鲁班压缩
*/ */
private fun luban() { private fun luban(images: List<LocalMedia>) {
val dataList = arrayListOf<LocalMedia>()
aiv.getAddImages().let {
for (addImagesInfo in it) {
val cutPath = addImagesInfo.imgUrl as String
val media = LocalMedia(cutPath, 0, false, 1, 0, PictureMimeType.ofImage())
media.cutPath = cutPath
if (SdkVersionUtils.checkedAndroid_Q()) {
media.androidQToPath = cutPath
}
dataList.add(media)
}
}
runOnUiThread { runOnUiThread {
showLoading("加载中...") showLoading("正在上传中...")
} }
val newFileName = DateUtils.getCreateFileName("IMG_CMP_") + ".jpeg" val newFileName = DateUtils.getCreateFileName("IMG_CMP_") + ".jpeg"
...@@ -207,7 +184,7 @@ class TemplateActivity : BaseActivity(), View.OnClickListener { ...@@ -207,7 +184,7 @@ class TemplateActivity : BaseActivity(), View.OnClickListener {
@Throws(Exception::class) @Throws(Exception::class)
override fun doInBackground(): List<File> { override fun doInBackground(): List<File> {
return Luban.with(mContext) return Luban.with(mContext)
.loadMediaData<LocalMedia>(dataList) .loadMediaData<LocalMedia>(images)
.ignoreBy(200) .ignoreBy(200)
.isCamera(false) .isCamera(false)
.setCompressQuality(80) .setCompressQuality(80)
...@@ -218,7 +195,7 @@ class TemplateActivity : BaseActivity(), View.OnClickListener { ...@@ -218,7 +195,7 @@ class TemplateActivity : BaseActivity(), View.OnClickListener {
override fun onSuccess(files: List<File>) { override fun onSuccess(files: List<File>) {
for (file in files) { for (file in files) {
uploadOss(file.path, "APPLY_TEMPLATE") uploadOss(file.path, OssType.ALBUM.type)
} }
} }
...@@ -249,30 +226,53 @@ class TemplateActivity : BaseActivity(), View.OnClickListener { ...@@ -249,30 +226,53 @@ class TemplateActivity : BaseActivity(), View.OnClickListener {
showToast("图片异常,请重新添加") showToast("图片异常,请重新添加")
return@runOnUiThread return@runOnUiThread
} }
hideLoading()
mOssList.add(imgPath!!) mOssList.add(imgPath!!)
if (mOssList.size == aiv.getAddImages().size) { if (mOssList.size == mUploadCount) {
val imgList = arrayListOf<AddImagesInfo>()
for (ossUrl in mOssList) {
val addImagesInfo = AddImagesInfo(ossUrl, "2")
imgList.add(addImagesInfo)
}
aiv.addAddImages(imgList)
val hashMap = HashMap<String, Any>() Handler(Looper.getMainLooper()).postDelayed({
hashMap["title"] = et_name.text.toString() val uploadImages = arrayListOf<String>()
hashMap["mobile"] = et_phone.text.toString() for (image in aiv.getAddImages()) {
hashMap["imgs"] = mOssList.toArray() uploadImages.add(image.imgUrl.toString())
// AppHttpManager.getInstance(baseApplication) }
// .call(baseApplication.loanService.numFeedback(hashMap), albumPresenter.setImages(uploadImages)
// object : BaseSubscriber<BaseResponse<OrderRecordBean>>() { }, 1000)
// override fun onError(e: Throwable) {
// hideLoading()
// }
//
// override fun onNext(t: BaseResponse<OrderRecordBean>) {
// hideLoading()
// finish()
// }
// })
} }
} }
} }
}) })
} }
} }
override fun onDestroy() {
super.onDestroy()
albumPresenter.detachView()
}
override fun getImagesSuc(data: List<String>) {
val imgList = arrayListOf<AddImagesInfo>()
for (s in data) {
val addImagesInfo = AddImagesInfo(s, "2")
imgList.add(addImagesInfo)
}
aiv.addAddImages(imgList)
}
override fun getImagesFail() {
}
override fun setImagesSuc() {
}
override fun setImagesFail() {
}
} }
\ No newline at end of file
...@@ -62,7 +62,7 @@ class IMActivity : TUIBaseChatActivity() { ...@@ -62,7 +62,7 @@ class IMActivity : TUIBaseChatActivity() {
val chatView = chatFragment.chatView val chatView = chatFragment.chatView
chatView.viewline.visibility = View.GONE chatView.viewline.visibility = View.GONE
chatView.inputView.setInterceptTouchEvent(true) // chatView.inputView.setInterceptTouchEvent(true)
chatView.inputView.setBgColor(resources.getColor(R.color.color_171619)) chatView.inputView.setBgColor(resources.getColor(R.color.color_171619))
chatView.inputView.setOnClickListener { chatView.inputView.setOnClickListener {
......
...@@ -57,6 +57,7 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base ...@@ -57,6 +57,7 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base
|| TextUtils.equals(getClass().getSimpleName(), "EditProfileActivity") || TextUtils.equals(getClass().getSimpleName(), "EditProfileActivity")
|| TextUtils.equals(getClass().getSimpleName(), "UserProfileActivity") || TextUtils.equals(getClass().getSimpleName(), "UserProfileActivity")
|| TextUtils.equals(getClass().getSimpleName(), "MainActivity") || TextUtils.equals(getClass().getSimpleName(), "MainActivity")
|| TextUtils.equals(getClass().getSimpleName(), "AlbumActivity")
) { ) {
setDarkStatusBar(); setDarkStatusBar();
} else { } else {
......
package com.duben.roseplaylet.ui.adapter
import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.duben.library.utils.GlideUtils
import com.duben.roseplaylet.R
import com.duben.roseplaylet.mvp.model.*
/**
* @author Assen
* @date 2024/1/9
* @desc
*/
class AlbumAdapter : BaseMultiItemQuickAdapter<ImageMultiItemEntity, BaseViewHolder>() {
init {
addItemType(IMAGE_MULTI_ITEM_ADD, R.layout.item_album_add)
addItemType(IMAGE_MULTI_ITEM_NORMAL, R.layout.item_album_normal)
}
override fun convert(holder: BaseViewHolder, item: ImageMultiItemEntity) {
when (holder.itemViewType) {
IMAGE_MULTI_ITEM_ADD -> {
holder.getView<View>(R.id.iv_add).setOnClickListener {
mOnAlbumClickListener?.onAddClick()
}
}
IMAGE_MULTI_ITEM_NORMAL -> {
val iv = holder.getView<ImageView>(R.id.iv_normal)
iv.setOnClickListener {
mOnAlbumClickListener?.onImageClick(holder.adapterPosition)
}
iv.setOnLongClickListener {
mOnAlbumClickListener?.onDeleteClick(holder.adapterPosition)
return@setOnLongClickListener true
}
GlideUtils.loadImageViewNoAnim2(context, item.img, iv)
}
}
}
private var mOnAlbumClickListener: OnAlbumClickListener? = null
fun setOnAlbumClickListener(onAlbumClickListener: OnAlbumClickListener) {
mOnAlbumClickListener = onAlbumClickListener
}
interface OnAlbumClickListener {
fun onDeleteClick(position: Int)
fun onAddClick()
fun onImageClick(position: Int)
}
}
\ No newline at end of file
...@@ -19,7 +19,6 @@ class SquarePageAdapter( ...@@ -19,7 +19,6 @@ class SquarePageAdapter(
override fun getItemCount() = data.size override fun getItemCount() = data.size
override fun createFragment(position: Int): Fragment { override fun createFragment(position: Int): Fragment {
LogUtil.d("AAAAAAAAAA$position")
val newFragment = SquareListFragment.newInstance(position + 1) val newFragment = SquareListFragment.newInstance(position + 1)
fragments[position] = newFragment fragments[position] = newFragment
return newFragment return newFragment
......
...@@ -110,13 +110,13 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR ...@@ -110,13 +110,13 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
//获取游客登录数据 //获取游客登录数据
homePresenter.userLogin() homePresenter.userLogin()
} else { } else {
homePresenter.topTabs() // homePresenter.topTabs()
homePresenter.orders() // homePresenter.orders()
if (userManager.vipFlag) { // if (userManager.vipFlag) {
homePresenter.signAfterSeconds() // homePresenter.signAfterSeconds()
} // }
IMHelper.instance.getImMsg() // IMHelper.instance.getImMsg()
TrackManager.getInstance().getMyInfo() // TrackManager.getInstance().getMyInfo()
} }
AppConfig.showVipAdDialog = false AppConfig.showVipAdDialog = false
......
...@@ -99,6 +99,7 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener { ...@@ -99,6 +99,7 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
tuiLoginConfig.isInitLocalStorageOnly = true tuiLoginConfig.isInitLocalStorageOnly = true
val userID = instance.userID val userID = instance.userID
val userSig = IMHelper.instance.getUserSig() val userSig = IMHelper.instance.getUserSig()
LogUtil.i("LoginWrapper ", "userSig $userSig")
LoginWrapper.getInstance().loginIMSDK(MintsApplication.getContext(), LoginWrapper.getInstance().loginIMSDK(MintsApplication.getContext(),
IMHelper.IM_SDK_APPID, userID, userSig, tuiLoginConfig, object : TUICallback() { IMHelper.IM_SDK_APPID, userID, userSig, tuiLoginConfig, object : TUICallback() {
override fun onSuccess() { override fun onSuccess() {
...@@ -129,8 +130,8 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener { ...@@ -129,8 +130,8 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
R.id.ll_my_setting -> { R.id.ll_my_setting -> {
// readyGo(SettingsActivity::class.java) // readyGo(SettingsActivity::class.java)
// readyGo(RealAuthActivity::class.java) // readyGo(RealAuthActivity::class.java)
// readyGo(BasicUserProfileActivity::class.java)
readyGo(BasicUserProfileActivity::class.java) readyGo(AlbumActivity::class.java)
} }
R.id.tv_my_account, R.id.ll_my_login -> { R.id.tv_my_account, R.id.ll_my_login -> {
if (!userManager.userIsLogin()) { if (!userManager.userIsLogin()) {
...@@ -139,7 +140,9 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener { ...@@ -139,7 +140,9 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
} }
R.id.ll_my_record -> { R.id.ll_my_record -> {
// readyGo(WatchRecordActivity::class.java) // readyGo(WatchRecordActivity::class.java)
readyGo(UserProfileActivity::class.java) IMHelper.instance.getImMsg()
// readyGo(UserProfileActivity::class.java)
} }
R.id.ll_my_feed -> { R.id.ll_my_feed -> {
// readyGo(FeedbackActivity::class.java) // readyGo(FeedbackActivity::class.java)
......
package com.duben.roseplaylet.ui.widgets
import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import com.duben.roseplaylet.R
class DeletePhotoConfirmDialog(
private val context: Context,
private val listener: DialogListener?
) :
Dialog(context, R.style.dialog) {
private val lp: WindowManager.LayoutParams
private val tv_confirm: TextView
private val iv_close: ImageView
init {
setContentView(R.layout.dialog_delete_photo_confirm)
// 设置window属性
lp = window!!.attributes
lp.gravity = Gravity.CENTER
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.windowAnimations = R.style.DialogAnimFade
window!!.attributes = lp
// 设置外部不可关闭
setCancelable(false)
setCanceledOnTouchOutside(false)
setOnKeyListener { _, i, _ -> i == KeyEvent.KEYCODE_BACK }
tv_confirm = findViewById<View>(R.id.tv_confirm) as TextView
iv_close = findViewById<View>(R.id.iv_close) as ImageView
iv_close.setOnClickListener(listener)
tv_confirm.setOnClickListener(listener)
listener?.setDialog(this)
}
}
\ No newline at end of file
...@@ -2,6 +2,7 @@ package com.duben.roseplaylet.ui.widgets.nineImage ...@@ -2,6 +2,7 @@ package com.duben.roseplaylet.ui.widgets.nineImage
import android.content.Context import android.content.Context
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
...@@ -9,8 +10,7 @@ import android.view.WindowManager ...@@ -9,8 +10,7 @@ import android.view.WindowManager
import android.widget.ImageView import android.widget.ImageView
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide import com.duben.library.utils.GlideUtils
import com.bumptech.glide.request.RequestOptions
import com.duben.roseplaylet.R import com.duben.roseplaylet.R
class AddImagesAdapter( class AddImagesAdapter(
...@@ -20,8 +20,7 @@ class AddImagesAdapter( ...@@ -20,8 +20,7 @@ class AddImagesAdapter(
addCloseImgs: Int, addCloseImgs: Int,
addErrImgs: Int, addErrImgs: Int,
addLimitNums: Int addLimitNums: Int
) : ) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
var mContext: Context var mContext: Context
var limtNum = 5 var limtNum = 5
var addImgs = -1 var addImgs = -1
...@@ -29,6 +28,7 @@ class AddImagesAdapter( ...@@ -29,6 +28,7 @@ class AddImagesAdapter(
var addErrImgs = -1 var addErrImgs = -1
var addLimitNums = 9 var addLimitNums = 9
var addImages = ArrayList<AddImagesInfo>() var addImages = ArrayList<AddImagesInfo>()
var enableClose = false
init { init {
this.mContext = mContext this.mContext = mContext
...@@ -46,12 +46,7 @@ class AddImagesAdapter( ...@@ -46,12 +46,7 @@ class AddImagesAdapter(
} }
fun getHeight(): Int { fun getHeight(): Int {
return (getScreenWidth(mContext)) / 5 return (getScreenWidth(mContext)) / 2
}
private fun dip2px(context: Context, dp: Int): Int {
val density = context.resources.displayMetrics.density
return (dp * density + 0.5).toInt()
} }
private fun getScreenWidth(context: Context): Int { private fun getScreenWidth(context: Context): Int {
...@@ -62,7 +57,6 @@ class AddImagesAdapter( ...@@ -62,7 +57,6 @@ class AddImagesAdapter(
return outMetrics.widthPixels return outMetrics.widthPixels
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(parent.context) val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_add_images, parent, false) .inflate(R.layout.item_add_images, parent, false)
...@@ -71,45 +65,71 @@ class AddImagesAdapter( ...@@ -71,45 +65,71 @@ class AddImagesAdapter(
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val ktHolder = holder as AddImagesViewHolder val ktHolder = holder as AddImagesViewHolder
if (addImgs != -1) { if (addImgs != -1) {
ktHolder.ivAdd.setBackgroundResource(addImgs) ktHolder.ivAdd.setBackgroundResource(addImgs)
} else { } else {
ktHolder.ivAdd.setBackgroundResource(R.drawable.iv_add_images_add) ktHolder.ivAdd.setBackgroundResource(R.drawable.iv_add_images_add)
} }
if (addCloseImgs != -1) {
ktHolder.ivClose.setBackgroundResource(addCloseImgs)
} else {
ktHolder.ivClose.setBackgroundResource(R.drawable.iv_add_img_close)
}
ktHolder.rlClose.setOnClickListener { ktHolder.rlClose.setOnClickListener {
processDelete(getItem(position)) processDelete(getItem(position))
if (listener != null) listener!!.onDeleteClick(position) listener?.onDeleteClick(position)
} }
ktHolder.rlAdd.setOnClickListener { ktHolder.rlAdd.setOnClickListener {
if (listener != null) listener!!.onAddClick(ktHolder.rlAdd, getItem(position)) listener?.onAddClick(ktHolder.rlAdd, position)
} }
ktHolder.ivContent.setOnClickListener { ktHolder.ivContent.setOnClickListener {
if (listener != null) listener!!.onAddClick(ktHolder.ivContent, getItem(position)) listener?.onAddClick(ktHolder.ivContent, position)
}
ktHolder.ivContent.setOnLongClickListener() {
listener?.onLongClick(getItem(position))
return@setOnLongClickListener false
} }
val width = (getScreenWidth(mContext) - dp2px(40f)) / limtNum
if (getItem(position)!!.type == "2") { if (getItem(position)!!.type == "2") {
ktHolder.ivContent.visibility = View.VISIBLE ktHolder.ivContent.visibility = View.VISIBLE
ktHolder.rlClose.visibility = View.VISIBLE ktHolder.rlClose.visibility = View.VISIBLE
ktHolder.rlAdd.visibility = View.GONE ktHolder.rlAdd.visibility = View.GONE
if (addErrImgs != -1) {
val requestOptions = RequestOptions().error(addErrImgs) if (enableClose) {
Glide.with(mContext).load(getItem(position)!!.imgUrl).apply(requestOptions) if (addCloseImgs != -1) {
.into(ktHolder.ivContent) ktHolder.ivClose.setBackgroundResource(addCloseImgs)
} else { } else {
val requestOptions = RequestOptions().error(R.drawable.iv_add_err) ktHolder.ivClose.setBackgroundResource(R.drawable.iv_add_img_close)
Glide.with(mContext).load(getItem(position)!!.imgUrl).apply(requestOptions) }
.into(ktHolder.ivContent) } else {
ktHolder.ivClose.visibility = View.GONE
} }
if (addErrImgs != -1) {
GlideUtils.loadImageViewNoAnim2(
mContext,
getItem(position)?.imgUrl,
ktHolder.ivContent
)
} else {
GlideUtils.loadImageViewNoAnim2(
mContext,
getItem(position)?.imgUrl,
ktHolder.ivContent
)
}
// 设置宽高一致
val layoutParams = ktHolder.ivContent.layoutParams
layoutParams.height = width
ktHolder.ivContent.layoutParams = layoutParams
} else { } else {
// 设置宽高一致
val layoutParams2 = ktHolder.ivAdd.layoutParams
layoutParams2.height = width
ktHolder.ivAdd.layoutParams = layoutParams2
ktHolder.ivContent.visibility = View.GONE ktHolder.ivContent.visibility = View.GONE
ktHolder.rlAdd.visibility = View.VISIBLE ktHolder.rlAdd.visibility = View.VISIBLE
ktHolder.rlClose.visibility = View.GONE ktHolder.rlClose.visibility = View.GONE
...@@ -117,14 +137,13 @@ class AddImagesAdapter( ...@@ -117,14 +137,13 @@ class AddImagesAdapter(
} }
private fun processDelete(item: AddImagesInfo?) { fun processDelete(item: AddImagesInfo?) {
addImages.remove(item) addImages.remove(item)
if (!hasAdd()) { if (!hasAdd()) {
addItem(AddImagesInfo(R.drawable.iv_add_images_add, "1")) addItem(AddImagesInfo(R.drawable.iv_add_images_add, "1"))
} else { } else {
notifyDataSetChanged() notifyDataSetChanged()
} }
} }
fun addItems(lists: List<AddImagesInfo>) { fun addItems(lists: List<AddImagesInfo>) {
...@@ -153,7 +172,6 @@ class AddImagesAdapter( ...@@ -153,7 +172,6 @@ class AddImagesAdapter(
private fun processData(addDatas: List<AddImagesInfo>) { private fun processData(addDatas: List<AddImagesInfo>) {
val newList = processEnd(getItems()) val newList = processEnd(getItems())
// if (newList.size >= limtNum) return
if (newList.size + addDatas.size < addLimitNums) { if (newList.size + addDatas.size < addLimitNums) {
newList.addAll(addDatas) newList.addAll(addDatas)
newList.add(AddImagesInfo("", "1")) newList.add(AddImagesInfo("", "1"))
...@@ -161,7 +179,6 @@ class AddImagesAdapter( ...@@ -161,7 +179,6 @@ class AddImagesAdapter(
newList.addAll(addDatas.subList(0, addLimitNums - newList.size)) newList.addAll(addDatas.subList(0, addLimitNums - newList.size))
} }
notifyDataSetChanged() notifyDataSetChanged()
} }
private fun processEnd(addDatas: ArrayList<AddImagesInfo>): ArrayList<AddImagesInfo> { private fun processEnd(addDatas: ArrayList<AddImagesInfo>): ArrayList<AddImagesInfo> {
...@@ -174,7 +191,7 @@ class AddImagesAdapter( ...@@ -174,7 +191,7 @@ class AddImagesAdapter(
} }
private fun hasAdd(): Boolean { private fun hasAdd(): Boolean {
getItems()!!.forEach { getItems().forEach {
if (it.type == "1") { if (it.type == "1") {
return true return true
} }
...@@ -194,8 +211,18 @@ class AddImagesAdapter( ...@@ -194,8 +211,18 @@ class AddImagesAdapter(
return null return null
} }
fun enableClose(enable: Boolean) {
this.enableClose = enable
}
private fun dp2px(dp: Float): Int {
val displayMetrics: DisplayMetrics = mContext.resources.displayMetrics
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, displayMetrics).toInt()
}
interface OnAddClickListener { interface OnAddClickListener {
fun onAddClick(view: View?, item: AddImagesInfo?) fun onAddClick(view: View?, position: Int)
fun onLongClick(item: AddImagesInfo?)
fun onDeleteClick(position: Int) fun onDeleteClick(position: Int)
} }
......
package com.duben.roseplaylet.ui.widgets.nineImage package com.duben.roseplaylet.ui.widgets.nineImage
class AddImagesInfo (var imgUrl:Any,var type:String) class AddImagesInfo(var imgUrl: Any, var type: String)
\ No newline at end of file \ No newline at end of file
...@@ -31,7 +31,7 @@ class AddImagesView @JvmOverloads constructor( ...@@ -31,7 +31,7 @@ class AddImagesView @JvmOverloads constructor(
//最大图片数 //最大图片数
private var add_limit_nums = 9 private var add_limit_nums = 9
private var mAdapter: AddImagesAdapter? = null private lateinit var mAdapter: AddImagesAdapter
init { init {
this.mContext = mContext this.mContext = mContext
...@@ -68,42 +68,51 @@ class AddImagesView @JvmOverloads constructor( ...@@ -68,42 +68,51 @@ class AddImagesView @JvmOverloads constructor(
add_limit_nums add_limit_nums
) )
rvContent.adapter = mAdapter rvContent.adapter = mAdapter
mAdapter!!.addItem(AddImagesInfo("", "1")) mAdapter.addItem(AddImagesInfo("", "1"))
mAdapter!!.setOnAddListener(object : AddImagesAdapter.OnAddClickListener { mAdapter.setOnAddListener(object : AddImagesAdapter.OnAddClickListener {
override fun onAddClick(view: View?, item: AddImagesInfo?) { override fun onAddClick(view: View?, position: Int) {
when (view!!.id) { when (view?.id) {
R.id.rl_add -> { R.id.rl_add -> {
if (listener != null) listener?.onAdd()
listener!!.onAdd()
} }
R.id.iv_content -> { R.id.iv_content -> {
if (listener != null) listener?.onPreview(position, mAdapter.getItems())
listener!!.onPreview(item, mAdapter!!.getItems())
} }
} }
} }
override fun onDeleteClick(position: Int) { override fun onLongClick(item: AddImagesInfo?) {
if (listener != null) listener?.onLongClick(item)
listener!!.onDelete(position)
} }
override fun onDeleteClick(position: Int) {
listener?.onDelete(position)
}
}) })
} }
//添加数据 //添加数据
fun addAddImages(lists: List<AddImagesInfo>) { fun addAddImages(lists: List<AddImagesInfo>) {
mAdapter!!.addItems(lists) mAdapter.addItems(lists)
} }
fun getAddImages(): List<AddImagesInfo> { fun getAddImages(): List<AddImagesInfo> {
return mAdapter!!.getItems() return mAdapter.getItems()
}
fun enableCloseView(enable: Boolean) {
mAdapter.enableClose(enable)
}
fun deleteImage(item: AddImagesInfo?) {
mAdapter.processDelete(item)
} }
interface AddImagesViewListener { interface AddImagesViewListener {
fun onAdd() fun onAdd()
fun onDelete(position: Int) fun onDelete(position: Int)
fun onPreview(item: AddImagesInfo?, lists: List<AddImagesInfo>?) fun onLongClick(item: AddImagesInfo?)
fun onPreview(position: Int, lists: List<AddImagesInfo>?)
} }
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_232122"
android:orientation="vertical">
<include layout="@layout/header_layout" />
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/gray"
android:gravity="center"
android:text="最多上传6张图片,长按可删除照片"
android:textColor="@color/white" />
<com.duben.roseplaylet.ui.widgets.nineImage.AddImagesView
android:id="@+id/aiv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:add_limit_nums="6"
app:column_nums="3" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_bg_hall"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
android:gravity="center"
android:text="删除后无法找回,确定要删除吗?"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_confirm"
android:layout_width="260dp"
android:layout_height="40dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:background="@drawable/shape_square_tab"
android:gravity="center"
android:text="确定"
android:textColor="@color/black"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:id="@+id/iv_close"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="@id/ll_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="@mipmap/ic_close" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="80dp" android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="vertical"> android:orientation="vertical">
<RelativeLayout <RelativeLayout
...@@ -16,13 +15,14 @@ ...@@ -16,13 +15,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:layout_margin="5dp"
android:scaleType="center" /> android:scaleType="center" />
</RelativeLayout> </RelativeLayout>
<ImageView <ImageView
android:id="@+id/iv_content" android:id="@+id/iv_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:padding="5dp" android:padding="5dp"
android:scaleType="center" android:scaleType="center"
android:visibility="gone" /> android:visibility="gone" />
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="6dp"
android:background="@drawable/shape_green"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_add"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ksad_reward_follow_add" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="6dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment