添加/修改 开服对接接口

This commit is contained in:
kehaoyuan
2018-05-31 20:28:12 +08:00
parent 5eb815dba7
commit a9b885c97f
11 changed files with 224 additions and 74 deletions

View File

@ -5,6 +5,7 @@ import android.databinding.Bindable
import android.os.Parcel
import android.os.Parcelable
import com.gh.gamecenter.BR
import com.google.gson.annotations.SerializedName
import java.text.SimpleDateFormat
import java.util.*
@ -13,6 +14,7 @@ import java.util.*
*/
class KaiFuCalendarEntity() : Parcelable, BaseObservable() {
@SerializedName("_id")
var id: String? = null
private var note: String? = null

View File

@ -572,7 +572,7 @@ public class FuLiAdapter extends BaseRecyclerAdapter<ViewHolder> {
viewHolder.kaifuRv.setLayoutManager(new GridLayoutManager(mContext, 7));
viewHolder.kaifuRv.addItemDecoration(new GridDivider(mContext, 1, 7, Color.BLACK));
viewHolder.kaifuRv.setAdapter(new GameDetailKaiFuAdapter(mContext, serverEntity.getCalendar(),
viewHolder, mGameEntity.getName()));
viewHolder, mGameEntity.getName(), mGameEntity.getId()));
}
}

View File

@ -20,6 +20,7 @@ import android.widget.TextView;
import com.gh.common.util.DisplayUtils;
import com.gh.common.util.StringUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.SuggestionActivity;
import com.gh.gamecenter.adapter.viewholder.GameDetailCalenderViewHolder;
import com.gh.gamecenter.adapter.viewholder.GameDetailKaiFuViewHolder;
import com.gh.gamecenter.databinding.KaifuDetailItemRowBinding;
@ -27,7 +28,7 @@ import com.gh.gamecenter.entity.CalendarEntity;
import com.gh.gamecenter.entity.KaiFuCalendarEntity;
import com.gh.gamecenter.eventbus.EBReuse;
import com.gh.gamecenter.kaifu.add.AddKaiFuActivity;
import com.gh.gamecenter.kaifu.amend.KaiFuAmendActivity;
import com.gh.gamecenter.kaifu.patch.PatchKaifuActivity;
import com.gh.gamecenter.retrofit.Response;
import com.lightgame.adapter.BaseRecyclerAdapter;
@ -66,6 +67,7 @@ public class GameDetailKaiFuAdapter extends BaseRecyclerAdapter<ViewHolder> {
private String suggestTime;
private String gameName;
private String gameId;
private List<CalendarEntity> mCurDayData;
private List<KaiFuCalendarEntity> mServerList;
@ -75,7 +77,7 @@ public class GameDetailKaiFuAdapter extends BaseRecyclerAdapter<ViewHolder> {
private SharedPreferences sp;
GameDetailKaiFuAdapter(Context context, List<KaiFuCalendarEntity> serverInfo,
GameDetailKaiFuViewHolder viewHolder, String gameName) {
GameDetailKaiFuViewHolder viewHolder, String gameName, String gameId) {
super(context);
week = context.getResources().getStringArray(R.array.weekdays);
@ -83,6 +85,7 @@ public class GameDetailKaiFuAdapter extends BaseRecyclerAdapter<ViewHolder> {
this.mServerList = serverInfo;
this.viewHolder = viewHolder;
this.gameName = gameName;
this.gameId = gameId;
sp = PreferenceManager.getDefaultSharedPreferences(mContext);
@ -192,9 +195,9 @@ public class GameDetailKaiFuAdapter extends BaseRecyclerAdapter<ViewHolder> {
@Override
public void onClick(View v) {
mContext.startActivity(AddKaiFuActivity.Companion.getIntent(mContext,
mOpenCalendarEntity, (ArrayList<KaiFuCalendarEntity>) mServerList));
// SuggestionActivity.startSuggestionActivity(mContext, 1, "service"
// , StringUtils.buildString(gameName, "", suggestTime, "开服信息有误:"));
mOpenCalendarEntity, (ArrayList<KaiFuCalendarEntity>) mServerList, gameId));
SuggestionActivity.startSuggestionActivity(mContext, 1, "service"
, StringUtils.buildString(gameName, "", suggestTime, "开服信息有误:"));
}
});
@ -515,7 +518,7 @@ public class GameDetailKaiFuAdapter extends BaseRecyclerAdapter<ViewHolder> {
KaiFuCalendarEntity serverEntity = entity.getServer().get(i - 1);
binding.setEntity(serverEntity);
binding.getRoot().setOnClickListener(v -> {
mContext.startActivity(KaiFuAmendActivity.Companion.getIntent(mContext, serverEntity));
mContext.startActivity(PatchKaifuActivity.Companion.getIntent(mContext, serverEntity, gameId));
});
}
viewHolder.detailList.addView(view);

View File

@ -39,7 +39,8 @@ class AddKaiFuActivity : BaseActivity() {
// initViewModel
mViewModel = ViewModelProviders.of(this).get(AddKaiFuViewModel::class.java)
mViewModel?.initData(intent.getParcelableExtra(KaiFuCalendarEntity.TAG)
, intent.getParcelableArrayListExtra<KaiFuCalendarEntity>(EntranceUtils.KEY_KAIFU_LIST))
, intent.getParcelableArrayListExtra<KaiFuCalendarEntity>(EntranceUtils.KEY_KAIFU_LIST)
, intent.getStringExtra(EntranceUtils.KEY_GAMEID))
// initView
mBinding = ActivityKaifuAddBinding.bind(mContentView)
@ -62,7 +63,7 @@ class AddKaiFuActivity : BaseActivity() {
}
}
mBinding?.addPost?.setOnClickListener({
mViewModel?.post()
mViewModel?.post(this)
})
}
@ -115,9 +116,10 @@ class AddKaiFuActivity : BaseActivity() {
companion object {
fun getIntent(context: Context, entity: KaiFuCalendarEntity, kaifuList: ArrayList<KaiFuCalendarEntity>): Intent {
fun getIntent(context: Context, entity: KaiFuCalendarEntity, kaifuList: ArrayList<KaiFuCalendarEntity>, gameId: String): Intent {
val intent = Intent(context, AddKaiFuActivity::class.java)
intent.putExtra(KaiFuCalendarEntity.TAG, entity)
intent.putExtra(EntranceUtils.KEY_GAMEID, gameId)
intent.putParcelableArrayListExtra(EntranceUtils.KEY_KAIFU_LIST, kaifuList)
return intent
}

View File

@ -1,11 +1,21 @@
package com.gh.gamecenter.kaifu.add
import android.app.Activity
import android.app.Application
import android.arch.lifecycle.AndroidViewModel
import com.gh.common.util.DialogUtils
import com.gh.common.util.GsonUtils
import com.gh.gamecenter.entity.KaiFuCalendarEntity
import com.gh.gamecenter.retrofit.Response
import com.gh.gamecenter.retrofit.RetrofitManager
import com.lightgame.utils.Utils
import com.lightgame.utils.Utils.toast
import java.util.*
import okhttp3.MediaType
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.HttpException
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import java.util.regex.Pattern
class AddKaiFuViewModel(application: Application) : AndroidViewModel(application) {
@ -14,8 +24,11 @@ class AddKaiFuViewModel(application: Application) : AndroidViewModel(application
private var mAllKaifuList = ArrayList<KaiFuCalendarEntity>()
fun initData(entity: KaiFuCalendarEntity, allKaifuList: ArrayList<KaiFuCalendarEntity>) {
private var mGameId = ""
fun initData(entity: KaiFuCalendarEntity, allKaifuList: ArrayList<KaiFuCalendarEntity>, gameId: String) {
mAllKaifuList = allKaifuList
mGameId = gameId
entity.setNote(entity.getNote() + "+") // 第一条 添加+(号)
calendarList.add(entity)
for (i in 0 until 5) {
@ -51,7 +64,7 @@ class AddKaiFuViewModel(application: Application) : AndroidViewModel(application
}
}
fun post() {
fun post(activity: Activity) {
var isSuccess = true
// 初始化标红提示
@ -120,9 +133,36 @@ class AddKaiFuViewModel(application: Application) : AndroidViewModel(application
}
}
if (i == calendarList.size - 1 && !isSuccess) {
toast(getApplication(), "当前开服表中已经存在相同的内容")
DialogUtils.showAlertDialog(activity, "提示", "当前开服表中已经存在相同的内容,请检查修改"
, "返回修改", null, null, null)
return
}
}
val postList = ArrayList<KaiFuCalendarEntity>()
for (entity in calendarList) if (entity.getTime() != 0L) postList.add(entity) // filter empty data
DialogUtils.showAlertDialog(activity, "提示", "确定提交${postList.size}条开服信息吗?"
, "确定", "返回", DialogUtils.ConfirmListener {
postData(postList)
}, null)
}
private fun postData(postList: ArrayList<KaiFuCalendarEntity>) {
val body = RequestBody.create(MediaType.parse("application/json"), GsonUtils.getInstance().toJson(postList))
RetrofitManager.getInstance(getApplication()).api.addKaifu(body, mGameId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Response<ResponseBody>() {
override fun onResponse(response: ResponseBody?) {
super.onResponse(response)
Utils.toast(getApplication(), "PATCH_SUCCESS")
}
override fun onFailure(e: HttpException?) {
super.onFailure(e)
Utils.toast(getApplication(), "PATCH_ERROR")
}
})
}
}

View File

@ -1,49 +0,0 @@
package com.gh.gamecenter.kaifu.amend
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.gh.base.BaseActivity
import com.gh.common.util.GsonUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.databinding.ActivityKaifuAmendBinding
import com.gh.gamecenter.entity.KaiFuCalendarEntity
import com.lightgame.utils.Utils
class KaiFuAmendActivity : BaseActivity() {
private var mBinding: ActivityKaifuAmendBinding? = null
private var mServerEntity: KaiFuCalendarEntity? = null
override fun getLayoutId(): Int {
return R.layout.activity_kaifu_amend
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setNavigationTitle("修改开服")
mServerEntity = intent.getParcelableExtra(KaiFuCalendarEntity.TAG)
mBinding = ActivityKaifuAmendBinding.bind(mContentView)
mBinding?.entity = mServerEntity
mBinding?.amendBtn?.setOnCheckedChangeListener({ _, b: Boolean ->
if (b) mBinding?.deleteBtn?.isChecked = false
})
mBinding?.deleteBtn?.setOnCheckedChangeListener({ _, b: Boolean ->
if (b) mBinding?.amendBtn?.isChecked = false
})
mBinding?.amendPost?.setOnClickListener(View.OnClickListener {
Utils.log("==========WWW::" + GsonUtils.getInstance().toJson(mServerEntity!!))
})
}
companion object {
fun getIntent(context: Context, serverEntity: KaiFuCalendarEntity): Intent {
var intent = Intent(context, KaiFuAmendActivity::class.java)
intent.putExtra(KaiFuCalendarEntity.TAG, serverEntity)
return intent
}
}
}

View File

@ -0,0 +1,70 @@
package com.gh.gamecenter.kaifu.patch
import android.arch.lifecycle.ViewModelProviders
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.gh.base.BaseActivity
import com.gh.common.util.DialogUtils
import com.gh.common.util.EntranceUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.databinding.ActivityKaifuPatchBinding
import com.gh.gamecenter.entity.KaiFuCalendarEntity
class PatchKaifuActivity : BaseActivity() {
private var mViewModel: PatchKaifuViewModel? = null
private var mBinding: ActivityKaifuPatchBinding? = null
override fun getLayoutId(): Int {
return R.layout.activity_kaifu_patch
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setNavigationTitle("修改开服")
mViewModel = ViewModelProviders.of(this).get(PatchKaifuViewModel::class.java)
mViewModel?.initData(intent.getParcelableExtra(KaiFuCalendarEntity.TAG), intent.getStringExtra(EntranceUtils.KEY_GAMEID))
mBinding = ActivityKaifuPatchBinding.bind(mContentView)
mBinding?.entity = mViewModel?.serverEntity
mBinding?.patchBtn?.setOnCheckedChangeListener({ _, b: Boolean ->
if (b) mBinding?.deleteBtn?.isChecked = false
})
mBinding?.deleteBtn?.setOnCheckedChangeListener({ _, b: Boolean ->
if (b) mBinding?.patchBtn?.isChecked = false
})
mBinding?.patchPost?.setOnClickListener({
if (!mBinding?.deleteBtn?.isChecked!! == !mBinding?.patchBtn?.isChecked!!) {
toast("请选择修改类型")
} else {
if (mBinding?.patchBtn?.isChecked!!
&& mViewModel?.serverEntity?.getNote() == mViewModel?.originalEntity?.getNote()
&& mViewModel?.serverEntity?.getTime() == mViewModel?.originalEntity?.getTime()
&& mViewModel?.serverEntity?.remark == mViewModel?.originalEntity?.remark) {
toast("内容没有变化,不能提交")
return@setOnClickListener
}
DialogUtils.showAlertDialog(this, "提示"
, if (mBinding?.patchBtn?.isChecked!!) "确定修改开服信息吗?" else "确定删除开服信息吗?"
, "确定", "返回"
, DialogUtils.ConfirmListener {
mViewModel?.post(mBinding?.patchBtn?.isChecked!!)
}, null)
}
})
}
companion object {
fun getIntent(context: Context, serverEntity: KaiFuCalendarEntity, gameId: String): Intent {
val intent = Intent(context, PatchKaifuActivity::class.java)
intent.putExtra(KaiFuCalendarEntity.TAG, serverEntity)
intent.putExtra(EntranceUtils.KEY_GAMEID, gameId)
return intent
}
}
}

View File

@ -0,0 +1,60 @@
package com.gh.gamecenter.kaifu.patch
import android.app.Application
import android.arch.lifecycle.AndroidViewModel
import com.gh.gamecenter.entity.KaiFuCalendarEntity
import com.gh.gamecenter.retrofit.Response
import com.gh.gamecenter.retrofit.RetrofitManager
import com.lightgame.utils.Utils
import okhttp3.MediaType
import okhttp3.RequestBody
import okhttp3.ResponseBody
import org.json.JSONObject
import retrofit2.HttpException
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
class PatchKaifuViewModel(application: Application) : AndroidViewModel(application) {
var apiService = RetrofitManager.getInstance(getApplication()).api
var serverEntity: KaiFuCalendarEntity? = null
var originalEntity = KaiFuCalendarEntity()
var gameId: String? = null
fun initData(serverEntity: KaiFuCalendarEntity, gameId: String) {
this.serverEntity = serverEntity
this.gameId = gameId
originalEntity.setTime(serverEntity.getTime())
originalEntity.setNote(serverEntity.getNote())
originalEntity.remark = serverEntity.remark
}
fun post(isPatch: Boolean) {
val observable = if (isPatch) {
val jsonObject = JSONObject()
jsonObject.put("note", serverEntity?.getNote())
jsonObject.put("remark", serverEntity?.remark)
val body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString())
apiService.patchKaifu(body, gameId, serverEntity!!.id)
} else {
apiService.deleteKaifu(gameId, serverEntity!!.id)
}
observable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Response<ResponseBody>() {
override fun onResponse(response: ResponseBody?) {
super.onResponse(response)
Utils.toast(getApplication(), "PATCH_SUCCESS")
}
override fun onFailure(e: HttpException?) {
super.onFailure(e)
Utils.toast(getApplication(), "PATCH_ERROR")
}
})
}
}

View File

@ -985,4 +985,26 @@ public interface ApiService {
@POST("logout")
Observable<ResponseBody> logout();
/**
* 修改开服信息
*/
@Headers({"Content-Type: application/json", "Accept: application/json"})
@POST("games/{game_id}/servers/{server_id}")
Observable<ResponseBody> patchKaifu(@Body RequestBody body, @Path("game_id") String gameId, @Path("server_id") String serverId);
/**
* 删除开服信息
*/
@Headers({"Content-Type: application/json", "Accept: application/json"})
@POST("games/{game_id}/servers/{server_id}")
Observable<ResponseBody> deleteKaifu(@Path("game_id") String gameId, @Path("server_id") String serverId);
/**
* 创建开服信息
*/
@Headers({"Content-Type: application/json", "Accept: application/json"})
@POST("games/{game_id}/servers")
Observable<ResponseBody> addKaifu(@Body RequestBody body, @Path("game_id") String gameId);
}