消息中心支持删除操作
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
package com.gh.gamecenter.message;
|
||||
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.common.util.MtaHelper;
|
||||
@ -17,6 +20,7 @@ import com.halo.assistant.HaloApp;
|
||||
* 消息-客服
|
||||
*/
|
||||
public class KeFuFragment extends ListFragment<MessageKeFuEntity, KeFuViewModel> {
|
||||
|
||||
private KeFuFragmentAdapter mAdapter;
|
||||
private MessageUnreadViewModel mUnreadViewModel;
|
||||
|
||||
@ -49,7 +53,7 @@ public class KeFuFragment extends ListFragment<MessageKeFuEntity, KeFuViewModel>
|
||||
|
||||
@Override
|
||||
public void onListClick(View view, int position, Object data) {
|
||||
if (view.getId() == R.id.message_kaifu_item) {
|
||||
if (view.getId() == R.id.message_kaifu_item) {
|
||||
MtaHelper.onEvent("消息中心", "系统_二级列表", "点击卡片");
|
||||
MessageKeFuEntity keFuEntity = (MessageKeFuEntity) data;
|
||||
if (!keFuEntity.isRead()) {
|
||||
|
||||
@ -190,6 +190,16 @@ public class KeFuFragmentAdapter extends ListAdapter<MessageKeFuEntity> {
|
||||
PersonalHomeActivity.startTargetActivity(mContext, serviceEntity.getId(), mEntrance, "消息中心-系统");
|
||||
}
|
||||
});
|
||||
|
||||
viewHolder.itemView.setOnLongClickListener(v -> {
|
||||
DialogUtils.showAlertDialog(mContext,
|
||||
"删除消息",
|
||||
"消息删除将不可恢复,确定删除吗?",
|
||||
"确定", "取消", () -> {
|
||||
mListViewModel.deleteMessage(keFuEntity.getId());
|
||||
}, null);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private void linkSkip(MessageLinkEntity data) {
|
||||
|
||||
@ -49,4 +49,24 @@ class KeFuViewModel(application: Application) : ListViewModel<MessageKeFuEntity,
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
})
|
||||
}
|
||||
|
||||
fun deleteMessage(messageId: String) {
|
||||
RetrofitManager.getInstance(getApplication()).api
|
||||
.deleteKaiFuMessage(UserManager.getInstance().userId, messageId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
val listData = mListLiveData.value
|
||||
if (listData != null) {
|
||||
for (data in listData) {
|
||||
if (data.id == messageId) {
|
||||
listData.remove(data)
|
||||
mListLiveData.postValue(listData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,16 @@
|
||||
package com.gh.gamecenter.message;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gh.base.OnListClickListener;
|
||||
import com.gh.common.constant.ItemViewType;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
@ -19,6 +22,8 @@ import com.gh.gamecenter.entity.MessageUnreadEntity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.tencent.stat.hybrid.StatHybridHandler.getContext;
|
||||
|
||||
/**
|
||||
* Created by khy on 23/03/18.
|
||||
*/
|
||||
@ -29,12 +34,18 @@ public class MessageAdapter extends ListAdapter<MessageEntity> {
|
||||
|
||||
private MessageUnreadEntity mUnreadEntity;
|
||||
|
||||
private MessageViewModel mViewModel;
|
||||
|
||||
private String mEntrance;
|
||||
|
||||
public MessageAdapter(Context context, OnListClickListener clickListener, String entrance) {
|
||||
public MessageAdapter(Context context,
|
||||
OnListClickListener clickListener,
|
||||
String entrance,
|
||||
MessageViewModel viewModel) {
|
||||
super(context);
|
||||
mClickListener = clickListener;
|
||||
mEntrance = entrance;
|
||||
mViewModel = viewModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -84,6 +95,15 @@ public class MessageAdapter extends ListAdapter<MessageEntity> {
|
||||
MessageItemViewHolder viewHolder = (MessageItemViewHolder) holder;
|
||||
MessageEntity entity = mEntityList.get(position - TOP_ITEM_COUNT);
|
||||
viewHolder.setMessageItem(entity, mContext, mEntrance);
|
||||
viewHolder.itemView.setOnLongClickListener(v -> {
|
||||
DialogUtils.showAlertDialog(mContext,
|
||||
"删除消息",
|
||||
"消息删除将不可恢复,确定删除吗?",
|
||||
"确定", "取消", () -> {
|
||||
mViewModel.deleteMessage(entity.getId());
|
||||
}, null);
|
||||
return false;
|
||||
});
|
||||
break;
|
||||
case ItemViewType.ITEM_FOOTER:
|
||||
FooterViewHolder footerViewHolder = (FooterViewHolder) holder;
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
package com.gh.gamecenter.message;
|
||||
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.MtaHelper;
|
||||
import com.gh.gamecenter.MessageInviteActivity;
|
||||
import com.gh.gamecenter.MessageKeFuActivity;
|
||||
@ -43,7 +47,11 @@ public class MessageFragment extends ListFragment<MessageEntity, MessageViewMode
|
||||
|
||||
@Override
|
||||
protected MessageAdapter provideListAdapter() {
|
||||
return mAdapter == null ? mAdapter = new MessageAdapter(getContext(), this, mEntrance) : mAdapter;
|
||||
return mAdapter == null ? mAdapter = new MessageAdapter(
|
||||
getContext(),
|
||||
this,
|
||||
mEntrance,
|
||||
mListViewModel) : mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
package com.gh.gamecenter.message;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gh.base.OnListClickListener;
|
||||
import com.gh.common.constant.ItemViewType;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
@ -22,17 +25,20 @@ public class MessageNormalAdapter extends ListAdapter<MessageEntity> {
|
||||
|
||||
private OnListClickListener mClickListener;
|
||||
|
||||
private MessageNormalViewModel mViewModel;
|
||||
private String mEntrance;
|
||||
private String mOuterInfo;
|
||||
|
||||
public MessageNormalAdapter(Context context,
|
||||
OnListClickListener clickListener,
|
||||
String entrance,
|
||||
String outerInfo) {
|
||||
String outerInfo,
|
||||
MessageNormalViewModel viewModel) {
|
||||
super(context);
|
||||
mClickListener = clickListener;
|
||||
mEntrance = entrance;
|
||||
mOuterInfo = outerInfo;
|
||||
mViewModel = viewModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,6 +64,15 @@ public class MessageNormalAdapter extends ListAdapter<MessageEntity> {
|
||||
MessageEntity entity = mEntityList.get(position);
|
||||
entity.setRead(true);
|
||||
viewHolder.setMessageItem(entity, mContext, mEntrance);
|
||||
viewHolder.itemView.setOnLongClickListener(v -> {
|
||||
DialogUtils.showAlertDialog(mContext,
|
||||
"删除消息",
|
||||
"消息删除将不可恢复,确定删除吗?",
|
||||
"确定", "取消", () -> {
|
||||
mViewModel.deleteMessage(entity.getId());
|
||||
}, null);
|
||||
return false;
|
||||
});
|
||||
break;
|
||||
case ItemViewType.ITEM_FOOTER:
|
||||
((FooterViewHolder) holder).initFooterViewHolder(mIsLoading, mIsNetworkError, mIsOver, R.string.ask_loadover_hint);
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
package com.gh.gamecenter.message;
|
||||
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.baselist.ListAdapter;
|
||||
@ -71,7 +75,12 @@ public class MessageNormalFragment extends ListFragment<MessageEntity, MessageNo
|
||||
|
||||
@Override
|
||||
protected ListAdapter provideListAdapter() {
|
||||
return mAdapter == null ? mAdapter = new MessageNormalAdapter(getContext(), this, mEntrance, mOuterInfo) : mAdapter;
|
||||
return mAdapter == null ? mAdapter = new MessageNormalAdapter(
|
||||
getContext(),
|
||||
this,
|
||||
mEntrance,
|
||||
mOuterInfo,
|
||||
mListViewModel) : mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -6,9 +6,13 @@ import androidx.lifecycle.ViewModelProvider
|
||||
import com.gh.gamecenter.baselist.ListViewModel
|
||||
import com.gh.gamecenter.entity.MessageEntity
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.lightgame.utils.Utils
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import okhttp3.ResponseBody
|
||||
|
||||
class MessageNormalViewModel(application: Application,
|
||||
private val mMessageType: String) : ListViewModel<MessageEntity, MessageEntity>(application) {
|
||||
@ -47,6 +51,26 @@ class MessageNormalViewModel(application: Application,
|
||||
// })
|
||||
// }
|
||||
|
||||
fun deleteMessage(messageId: String) {
|
||||
RetrofitManager.getInstance(getApplication()).api
|
||||
.deleteMessage(UserManager.getInstance().userId, messageId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
val listData = mListLiveData.value
|
||||
if (listData != null) {
|
||||
for (data in listData) {
|
||||
if (data.id == messageId) {
|
||||
listData.remove(data)
|
||||
mListLiveData.postValue(listData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
class Factory(private val mApplication: Application,
|
||||
private val mMessageType: String) : ViewModelProvider.NewInstanceFactory() {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
|
||||
@ -25,6 +25,26 @@ class MessageViewModel(application: Application) : ListViewModel<MessageEntity,
|
||||
mResultLiveData.addSource<List<MessageEntity>>(mListLiveData) { mResultLiveData.postValue(it) }
|
||||
}
|
||||
|
||||
fun deleteMessage(messageId: String) {
|
||||
RetrofitManager.getInstance(getApplication()).api
|
||||
.deleteMessage(UserManager.getInstance().userId, messageId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
val listData = mListLiveData.value
|
||||
if (listData != null) {
|
||||
for (data in listData) {
|
||||
if (data.id == messageId) {
|
||||
listData.remove(data)
|
||||
mListLiveData.postValue(listData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
fun postMessageRead(messageId: String, type: String) {
|
||||
|
||||
|
||||
@ -1264,6 +1264,18 @@ public interface ApiService {
|
||||
@POST("users/{user_id}/messages/{message_id}:read")
|
||||
Observable<ResponseBody> postMessageRead(@Path("user_id") String userId, @Path("message_id") String messageId, @Body RequestBody body);
|
||||
|
||||
/**
|
||||
* 将消息删除
|
||||
*/
|
||||
@POST("users/{user_id}/messages/{message_id}:inactivate")
|
||||
Observable<ResponseBody> deleteMessage(@Path("user_id") String userId, @Path("message_id") String messageId);
|
||||
|
||||
/**
|
||||
* 将消息删除
|
||||
*/
|
||||
@POST("users/{user_id}/private_messages/{message_id}:inactivate")
|
||||
Observable<ResponseBody> deleteKaiFuMessage(@Path("user_id") String userId, @Path("message_id") String messageId);
|
||||
|
||||
/**
|
||||
* 在社区发布文章
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user