Commit cf052242 authored by jyx's avatar jyx

添加上传照片功能

parent 331223d6
......@@ -256,6 +256,14 @@
android:name=".ui.activitys.BasicUserProfileActivity"
android:exported="false"
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
android:name=".ui.activitys.IMActivity"
......
......@@ -2,6 +2,7 @@ package com.duben.roseplaylet.common
enum class OssType(var type: String) {
ALBUM("album"),
PHOTO("photo"),
VIDEO("video")
......
......@@ -53,7 +53,10 @@ class IMHelper private constructor() {
override fun onCompleted() {}
override fun onError(e: Throwable) {}
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 {
* 查看图片
*/
@POST("roseApi/user/getImages")
Observable<BaseResponse<JsonObject>> getImages();
Observable<BaseResponse<JsonObject>> getImages(@Body Object obj);
/**
* 设置图片
......
......@@ -62,7 +62,7 @@ class IMActivity : TUIBaseChatActivity() {
val chatView = chatFragment.chatView
chatView.viewline.visibility = View.GONE
chatView.inputView.setInterceptTouchEvent(true)
// chatView.inputView.setInterceptTouchEvent(true)
chatView.inputView.setBgColor(resources.getColor(R.color.color_171619))
chatView.inputView.setOnClickListener {
......
......@@ -57,6 +57,7 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base
|| TextUtils.equals(getClass().getSimpleName(), "EditProfileActivity")
|| TextUtils.equals(getClass().getSimpleName(), "UserProfileActivity")
|| TextUtils.equals(getClass().getSimpleName(), "MainActivity")
|| TextUtils.equals(getClass().getSimpleName(), "AlbumActivity")
) {
setDarkStatusBar();
} 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(
override fun getItemCount() = data.size
override fun createFragment(position: Int): Fragment {
LogUtil.d("AAAAAAAAAA$position")
val newFragment = SquareListFragment.newInstance(position + 1)
fragments[position] = newFragment
return newFragment
......
......@@ -110,13 +110,13 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
//获取游客登录数据
homePresenter.userLogin()
} else {
homePresenter.topTabs()
homePresenter.orders()
if (userManager.vipFlag) {
homePresenter.signAfterSeconds()
}
IMHelper.instance.getImMsg()
TrackManager.getInstance().getMyInfo()
// homePresenter.topTabs()
// homePresenter.orders()
// if (userManager.vipFlag) {
// homePresenter.signAfterSeconds()
// }
// IMHelper.instance.getImMsg()
// TrackManager.getInstance().getMyInfo()
}
AppConfig.showVipAdDialog = false
......
......@@ -99,6 +99,7 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
tuiLoginConfig.isInitLocalStorageOnly = true
val userID = instance.userID
val userSig = IMHelper.instance.getUserSig()
LogUtil.i("LoginWrapper ", "userSig $userSig")
LoginWrapper.getInstance().loginIMSDK(MintsApplication.getContext(),
IMHelper.IM_SDK_APPID, userID, userSig, tuiLoginConfig, object : TUICallback() {
override fun onSuccess() {
......@@ -129,8 +130,8 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
R.id.ll_my_setting -> {
// readyGo(SettingsActivity::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 -> {
if (!userManager.userIsLogin()) {
......@@ -139,7 +140,9 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
}
R.id.ll_my_record -> {
// readyGo(WatchRecordActivity::class.java)
readyGo(UserProfileActivity::class.java)
IMHelper.instance.getImMsg()
// readyGo(UserProfileActivity::class.java)
}
R.id.ll_my_feed -> {
// 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
import android.content.Context
import android.util.DisplayMetrics
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -9,8 +10,7 @@ import android.view.WindowManager
import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.duben.library.utils.GlideUtils
import com.duben.roseplaylet.R
class AddImagesAdapter(
......@@ -20,8 +20,7 @@ class AddImagesAdapter(
addCloseImgs: Int,
addErrImgs: Int,
addLimitNums: Int
) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
var mContext: Context
var limtNum = 5
var addImgs = -1
......@@ -29,6 +28,7 @@ class AddImagesAdapter(
var addErrImgs = -1
var addLimitNums = 9
var addImages = ArrayList<AddImagesInfo>()
var enableClose = false
init {
this.mContext = mContext
......@@ -46,12 +46,7 @@ class AddImagesAdapter(
}
fun getHeight(): Int {
return (getScreenWidth(mContext)) / 5
}
private fun dip2px(context: Context, dp: Int): Int {
val density = context.resources.displayMetrics.density
return (dp * density + 0.5).toInt()
return (getScreenWidth(mContext)) / 2
}
private fun getScreenWidth(context: Context): Int {
......@@ -62,7 +57,6 @@ class AddImagesAdapter(
return outMetrics.widthPixels
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_add_images, parent, false)
......@@ -71,45 +65,71 @@ class AddImagesAdapter(
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val ktHolder = holder as AddImagesViewHolder
if (addImgs != -1) {
ktHolder.ivAdd.setBackgroundResource(addImgs)
} else {
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 {
processDelete(getItem(position))
if (listener != null) listener!!.onDeleteClick(position)
listener?.onDeleteClick(position)
}
ktHolder.rlAdd.setOnClickListener {
if (listener != null) listener!!.onAddClick(ktHolder.rlAdd, getItem(position))
listener?.onAddClick(ktHolder.rlAdd, position)
}
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") {
ktHolder.ivContent.visibility = View.VISIBLE
ktHolder.rlClose.visibility = View.VISIBLE
ktHolder.rlAdd.visibility = View.GONE
if (addErrImgs != -1) {
val requestOptions = RequestOptions().error(addErrImgs)
Glide.with(mContext).load(getItem(position)!!.imgUrl).apply(requestOptions)
.into(ktHolder.ivContent)
if (enableClose) {
if (addCloseImgs != -1) {
ktHolder.ivClose.setBackgroundResource(addCloseImgs)
} else {
ktHolder.ivClose.setBackgroundResource(R.drawable.iv_add_img_close)
}
} else {
val requestOptions = RequestOptions().error(R.drawable.iv_add_err)
Glide.with(mContext).load(getItem(position)!!.imgUrl).apply(requestOptions)
.into(ktHolder.ivContent)
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 {
// 设置宽高一致
val layoutParams2 = ktHolder.ivAdd.layoutParams
layoutParams2.height = width
ktHolder.ivAdd.layoutParams = layoutParams2
ktHolder.ivContent.visibility = View.GONE
ktHolder.rlAdd.visibility = View.VISIBLE
ktHolder.rlClose.visibility = View.GONE
......@@ -117,14 +137,13 @@ class AddImagesAdapter(
}
private fun processDelete(item: AddImagesInfo?) {
fun processDelete(item: AddImagesInfo?) {
addImages.remove(item)
if (!hasAdd()) {
addItem(AddImagesInfo(R.drawable.iv_add_images_add, "1"))
} else {
notifyDataSetChanged()
}
}
fun addItems(lists: List<AddImagesInfo>) {
......@@ -153,7 +172,6 @@ class AddImagesAdapter(
private fun processData(addDatas: List<AddImagesInfo>) {
val newList = processEnd(getItems())
// if (newList.size >= limtNum) return
if (newList.size + addDatas.size < addLimitNums) {
newList.addAll(addDatas)
newList.add(AddImagesInfo("", "1"))
......@@ -161,7 +179,6 @@ class AddImagesAdapter(
newList.addAll(addDatas.subList(0, addLimitNums - newList.size))
}
notifyDataSetChanged()
}
private fun processEnd(addDatas: ArrayList<AddImagesInfo>): ArrayList<AddImagesInfo> {
......@@ -174,7 +191,7 @@ class AddImagesAdapter(
}
private fun hasAdd(): Boolean {
getItems()!!.forEach {
getItems().forEach {
if (it.type == "1") {
return true
}
......@@ -194,8 +211,18 @@ class AddImagesAdapter(
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 {
fun onAddClick(view: View?, item: AddImagesInfo?)
fun onAddClick(view: View?, position: Int)
fun onLongClick(item: AddImagesInfo?)
fun onDeleteClick(position: Int)
}
......
package com.duben.roseplaylet.ui.widgets.nineImage
class AddImagesInfo (var imgUrl:Any,var type:String)
\ No newline at end of file
class AddImagesInfo(var imgUrl: Any, var type: String)
\ No newline at end of file
......@@ -31,7 +31,7 @@ class AddImagesView @JvmOverloads constructor(
//最大图片数
private var add_limit_nums = 9
private var mAdapter: AddImagesAdapter? = null
private lateinit var mAdapter: AddImagesAdapter
init {
this.mContext = mContext
......@@ -68,42 +68,51 @@ class AddImagesView @JvmOverloads constructor(
add_limit_nums
)
rvContent.adapter = mAdapter
mAdapter!!.addItem(AddImagesInfo("", "1"))
mAdapter!!.setOnAddListener(object : AddImagesAdapter.OnAddClickListener {
override fun onAddClick(view: View?, item: AddImagesInfo?) {
when (view!!.id) {
mAdapter.addItem(AddImagesInfo("", "1"))
mAdapter.setOnAddListener(object : AddImagesAdapter.OnAddClickListener {
override fun onAddClick(view: View?, position: Int) {
when (view?.id) {
R.id.rl_add -> {
if (listener != null)
listener!!.onAdd()
listener?.onAdd()
}
R.id.iv_content -> {
if (listener != null)
listener!!.onPreview(item, mAdapter!!.getItems())
listener?.onPreview(position, mAdapter.getItems())
}
}
}
override fun onDeleteClick(position: Int) {
if (listener != null)
listener!!.onDelete(position)
override fun onLongClick(item: AddImagesInfo?) {
listener?.onLongClick(item)
}
override fun onDeleteClick(position: Int) {
listener?.onDelete(position)
}
})
}
//添加数据
fun addAddImages(lists: List<AddImagesInfo>) {
mAdapter!!.addItems(lists)
mAdapter.addItems(lists)
}
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 {
fun onAdd()
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"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
......@@ -16,13 +15,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="5dp"
android:scaleType="center" />
</RelativeLayout>
<ImageView
android:id="@+id/iv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:padding="5dp"
android:scaleType="center"
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