diff --git a/app/src/main/java/com/gh/common/databind/BindingAdapters.java b/app/src/main/java/com/gh/common/databind/BindingAdapters.java index d7fa0f91dc..e0f639d182 100644 --- a/app/src/main/java/com/gh/common/databind/BindingAdapters.java +++ b/app/src/main/java/com/gh/common/databind/BindingAdapters.java @@ -3,6 +3,7 @@ package com.gh.common.databind; import android.content.Intent; import android.graphics.Color; import android.graphics.Typeface; +import android.text.Html; import android.text.Spannable; import android.text.SpannableString; import android.text.TextUtils; @@ -169,7 +170,7 @@ public class BindingAdapters { public static void addKaiFuView(LinearLayout view, List list, OnViewClickListener listener) { if (list == null) return; view.removeAllViews(); - view.addView(LayoutInflater.from(view.getContext()).inflate(R.layout.kaifu_add_item_title, null)); + view.addView(LayoutInflater.from(view.getContext()).inflate(R.layout.kaifu_new_add_item_title, null)); for (int i = 0; i < list.size(); i++) { View inflate = LayoutInflater.from(view.getContext()).inflate(R.layout.kaifu_add_item, null); KaifuAddItemBinding binding = KaifuAddItemBinding.bind(inflate); @@ -179,18 +180,18 @@ public class BindingAdapters { binding.setIsCloseBottom(list.size() - 1 == i); view.addView(inflate); - binding.kaifuAddName.setOnFocusChangeListener((v, hasFocus) -> { + binding.kaifuAddFirstName.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { - binding.kaifuAddName.setHint(""); + binding.kaifuAddFirstName.setHint(""); } else { - binding.kaifuAddName.setHint("点击填写"); + binding.kaifuAddFirstName.setHint("点击填写"); } }); - binding.kaifuAddRemark.setOnFocusChangeListener((v, hasFocus) -> { + binding.kaifuAddServerName.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { - binding.kaifuAddRemark.setHint(""); + binding.kaifuAddServerName.setHint(""); } else { - binding.kaifuAddRemark.setHint("点击填写"); + binding.kaifuAddServerName.setHint("点击填写"); } }); } @@ -202,23 +203,21 @@ public class BindingAdapters { view.setHint("点击选择"); view.setText(""); } else { - String pattern; - if (position == 0) { - pattern = "yyy-MM-dd HH:mm +"; - } else { - pattern = "yyy-MM-dd HH:mm"; - } + String pattern = "yyy-MM-dd HH:mm"; SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.CHINA); view.setText(format.format(time * 1000)); + if (position == 0) { + view.append(Html.fromHtml(String.format("%1$s", " +"))); + } } } @BindingAdapter({"kaiFuTextColor", "kaiFuTextPosition"}) public static void kaiFuTextColor(EditText view, Integer dataMark, Integer position) { if (dataMark == 1 && view.getId() == R.id.kaifu_add_time - || dataMark == 2 && view.getId() == R.id.kaifu_add_name - || dataMark == 3 && view.getId() == R.id.kaifu_add_remark - || dataMark == 4 && (view.getId() == R.id.kaifu_add_time || view.getId() == R.id.kaifu_add_name)) { + || dataMark == 2 && view.getId() == R.id.kaifu_add_first_name + || dataMark == 3 && view.getId() == R.id.kaifu_add_server_name + || dataMark == 4) { view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.red)); view.setHintTextColor(ContextCompat.getColor(view.getContext(), R.color.red)); } else if (position == 0) { diff --git a/app/src/main/java/com/gh/gamecenter/entity/ServerCalendarEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/ServerCalendarEntity.kt index a49fdfd8d1..2b011d72ae 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/ServerCalendarEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/ServerCalendarEntity.kt @@ -19,6 +19,10 @@ class ServerCalendarEntity() : Parcelable, BaseObservable() { private var note: String? = null + private var firstName: CharSequence? = "" + + private var serverName: CharSequence? = "" + private var time: Long = 0 private var dataMark: Int = 0 // 判断字段是否符合条件 1:时间,2:名字,3:备注,4:时间&名字, 0: 正常 @@ -37,6 +41,26 @@ class ServerCalendarEntity() : Parcelable, BaseObservable() { return this.note } + public fun setFirstName(firstName: CharSequence?) { + this.firstName = firstName + notifyPropertyChanged(BR.firstName) + } + + @Bindable + public fun getFirstName(): CharSequence? { + return this.firstName + } + + public fun setServerName(serverName: CharSequence?) { + this.serverName = serverName + notifyPropertyChanged(BR.serverName) + } + + @Bindable + public fun getServerName(): CharSequence? { + return this.serverName + } + public fun setTime(time: Long) { this.time = time notifyPropertyChanged(BR.time) diff --git a/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuActivity.kt b/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuActivity.kt index 6def31f2fc..2ea2304fc4 100644 --- a/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuActivity.kt +++ b/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuActivity.kt @@ -10,12 +10,16 @@ import android.text.Spanned import android.text.method.LinkMovementMethod import android.text.style.ClickableSpan import android.view.Gravity +import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.EditText import android.widget.FrameLayout +import android.widget.LinearLayout import android.widget.TextView import androidx.core.content.ContextCompat import androidx.lifecycle.ViewModelProviders +import androidx.recyclerview.widget.LinearLayoutManager import com.bigkoo.pickerview.builder.TimePickerBuilder import com.bigkoo.pickerview.listener.OnTimeSelectListener import com.contrarywind.view.WheelView @@ -23,8 +27,13 @@ import com.gh.base.OnViewClickListener import com.gh.base.ToolBarActivity import com.gh.common.util.EntranceUtils import com.gh.common.util.HaloWheelViewAdapter +import com.gh.common.util.dip2px +import com.gh.common.util.showAutoOrientation +import com.gh.common.view.BugFixedPopupWindow import com.gh.gamecenter.R import com.gh.gamecenter.databinding.ActivityKaifuAddBinding +import com.gh.gamecenter.databinding.LayoutAddKaifuPopupBinding +import com.gh.gamecenter.databinding.LayoutPopupContainerBinding import com.gh.gamecenter.entity.ServerCalendarEntity import com.gh.gamecenter.gamedetail.fuli.kaifu.ServersCalendarActivity import java.util.* @@ -76,10 +85,16 @@ class AddKaiFuActivity : ToolBarActivity() { mBinding?.clickListener = OnViewClickListener { view: View, position: Any -> if (position is Int) { if (position == 0) { - if (view.id == R.id.kaifu_add_name) { // 自动填充->名字 - mViewModel?.copyNameToNext() - } else { // 自动填充->时间 - mViewModel?.copyTimeToNext() + when (view.id) { + R.id.kaifu_add_first_name -> { // 自动填充->名字 + mViewModel?.copyLastFirstNameToNext() + } + R.id.kaifu_add_server_name -> { + mViewModel?.copyLastFirstAndServerNameToNext() + } + R.id.kaifu_add_time -> { // 自动填充->时间 + mViewModel?.copyTimeToNext() + } } } else if (view.id == R.id.kaifu_add_time) { showDataPicker(OnTimeSelectListener { data: Date?, _ -> @@ -89,6 +104,14 @@ class AddKaiFuActivity : ToolBarActivity() { } }) } + if (view is EditText) { + if (view.id == R.id.kaifu_add_first_name && position != 0 && view.text.isNullOrEmpty()) { + showPopupOption(view) { + view.setText(it) + view.setSelection(it.length) + } + } + } } } mBinding?.addPost?.setOnClickListener { @@ -180,6 +203,34 @@ class AddKaiFuActivity : ToolBarActivity() { } } + private fun showPopupOption(view: View, callback: (text: String) -> Unit) { + val inflater = LayoutInflater.from(view.context) + val mainBinding = LayoutPopupContainerBinding.inflate(inflater) + val popupWindow = BugFixedPopupWindow( + mainBinding.root, + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ) + + LayoutAddKaifuPopupBinding.inflate(inflater, mainBinding.container, false).apply { + root.layoutParams = root.layoutParams.apply { + width = 120F.dip2px() + } + popupRv.adapter = AddKaiFuPopupAdapter( + root.context, + arrayListOf("安卓混服", "硬核专服", "官方专服", "官方渠道服", "腾讯QQ服", "腾讯微信服") + ) { + callback.invoke(it) + popupWindow.dismiss() + } + popupRv.layoutManager = LinearLayoutManager(root.context) + mainBinding.container.addView(root) + } + + popupWindow.isTouchable = true + popupWindow.isFocusable = true + popupWindow.showAutoOrientation(view, (-8F).dip2px(), (-10F).dip2px()) + } companion object { fun getIntent(context: Context, entity: ServerCalendarEntity, diff --git a/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuPopupAdapter.kt b/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuPopupAdapter.kt new file mode 100644 index 0000000000..e431d62097 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuPopupAdapter.kt @@ -0,0 +1,54 @@ +package com.gh.gamecenter.servers.add + +import android.content.Context +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.gh.base.BaseRecyclerViewHolder +import com.gh.gamecenter.R +import com.gh.gamecenter.databinding.LayoutAddKaifuPopupItemBinding +import com.gh.gamecenter.entity.ApplyModeratorTaskEntity +import com.lightgame.adapter.BaseRecyclerAdapter + +class AddKaiFuPopupAdapter( + context: Context, + data: ArrayList, + callback: (text: String) -> Unit +) : + BaseRecyclerAdapter(context) { + + var nameList = data + + val action = callback + + fun setListData(data: ArrayList) { + nameList = data + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + return AddKaiFuPopupViewHolder( + LayoutAddKaifuPopupItemBinding.bind( + mLayoutInflater.inflate( + R.layout.layout_add_kaifu_popup_item, + parent, + false + ) + ) + ) + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + if (holder is AddKaiFuPopupViewHolder) { + holder.binding.hintText.text = nameList[position] + holder.binding.hintText.setOnClickListener { action.invoke(nameList[position]) } + if (position == nameList.size - 1) { + holder.binding.divider.visibility = View.GONE + } + } + } + + override fun getItemCount(): Int = nameList.size + + class AddKaiFuPopupViewHolder(val binding: LayoutAddKaifuPopupItemBinding) : + BaseRecyclerViewHolder(binding.root) +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuViewModel.kt b/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuViewModel.kt index 665d61d240..8b7cbf56a1 100644 --- a/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/servers/add/AddKaiFuViewModel.kt @@ -2,14 +2,19 @@ package com.gh.gamecenter.servers.add import android.app.Activity import android.app.Application +import android.os.Build +import android.text.Html +import android.text.Spanned import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.MutableLiveData import android.text.TextUtils +import com.gh.common.databind.BindingAdapters import com.gh.common.util.DialogUtils import com.gh.common.util.GsonUtils import com.gh.gamecenter.entity.ServerCalendarEntity import com.gh.gamecenter.retrofit.Response import com.gh.gamecenter.retrofit.RetrofitManager +import com.lightgame.utils.Utils import com.lightgame.utils.Utils.toast import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers @@ -30,14 +35,48 @@ class AddKaiFuViewModel(application: Application) : AndroidViewModel(application fun initData(entity: ServerCalendarEntity?, allKaifuList: ArrayList, gameId: String) { mAllKaifuList = allKaifuList mGameId = gameId - entity?.setNote(entity.getNote() + " +") // 第一条 添加+(号) - if (entity?.remark.isNullOrEmpty()) entity?.remark = "-" + val text = entity?.getNote() + if (!text.isNullOrEmpty()) { + var firstName = "" + var serverName = "" + var str: Array = text.split("︱".toRegex()).toTypedArray() + if (str.size == 1) { + str = text.split("\\|".toRegex()).toTypedArray() + if (str.size == 1) { + serverName = text + } else { + firstName = str[0].trim() + serverName = str[1].trim() + } + } else { + firstName = str[0].trim() + serverName = str[1].trim() + } + entity.setFirstName(getColorPlusText(firstName)) + entity.setServerName(getColorPlusText(serverName)) + } if (entity != null) calendarList.add(entity) for (i in 0 until 5) { calendarList.add(ServerCalendarEntity()) } } + fun getColorPlusText(str: String): Spanned { + val plus = String.format("%1\$s", " +") + val name = String.format("%1\$s", str) + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + Html.fromHtml(name + plus, Html.FROM_HTML_MODE_LEGACY) + else + Html.fromHtml(name + plus) + } + + fun bluePlus(): Spanned = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) Html.fromHtml( + String.format( + "%1\$s", + " +" + ), Html.FROM_HTML_MODE_LEGACY + ) else Html.fromHtml(String.format("%1\$s", " +")) + fun copyTimeToNext() { for (i in 0 until calendarList.size) { if (i != calendarList.size - 1 && calendarList[i].getTime() != 0L && calendarList[i + 1].getTime() == 0L) { @@ -47,20 +86,57 @@ class AddKaiFuViewModel(application: Application) : AndroidViewModel(application } } - fun copyNameToNext() { +// fun copyNameToNext() { +// for (i in 0 until calendarList.size) { +// if (i != calendarList.size - 1 && !calendarList[i].getNote().isNullOrEmpty() && calendarList[i + 1].getNote().isNullOrEmpty()) { +// val compile = Pattern.compile("^.*?(\\d+)[^\\d]*$") +// var note = calendarList[i].getNote() +// val m = compile.matcher(note) +// if (m.find()) { +// val group = m.group(1).toInt() +// note = note?.replace(group.toString(), (group + 1).toString()) // todo 替换最后出现的数字(有可能出现两次相同) +// } +// if (!note.isNullOrEmpty() && "+" == note?.get(note.length - 1).toString()) { +// note = note!!.substring(0, note.length - 1) +// } +// calendarList[i + 1].setNote(note) +// break +// } +// } +// } + + fun copyLastFirstNameToNext() { for (i in 0 until calendarList.size) { - if (i != calendarList.size - 1 && !calendarList[i].getNote().isNullOrEmpty() && calendarList[i + 1].getNote().isNullOrEmpty()) { - val compile = Pattern.compile("^.*?(\\d+)[^\\d]*$") - var note = calendarList[i].getNote() - val m = compile.matcher(note) - if (m.find()) { - val group = m.group(1).toInt() - note = note?.replace(group.toString(), (group + 1).toString()) // todo 替换最后出现的数字(有可能出现两次相同) + if (i != calendarList.size - 1 && !calendarList[i].getFirstName().isNullOrEmpty() && calendarList[i + 1].getFirstName().isNullOrEmpty()) { + var firstName = calendarList[i].getFirstName().toString() + if (firstName.isNotEmpty() && "+" == firstName[firstName.length - 1].toString()) { + firstName = firstName.substring(0, firstName.length - 2) } - if (!note.isNullOrEmpty() && "+" == note?.get(note.length - 1).toString()) { - note = note!!.substring(0, note.length - 1) + calendarList[i + 1].setFirstName(firstName) + break + } + } + } + + fun copyLastFirstAndServerNameToNext() { + for (i in 0 until calendarList.size) { + if (i != calendarList.size - 1 && !calendarList[i].getServerName().isNullOrEmpty() && calendarList[i + 1].getServerName().isNullOrEmpty()) { + var firstName = calendarList[i].getFirstName().toString() + var serverName = calendarList[i].getServerName().toString() + val pattern = "[0-9]+(?=[^0-9]*\$)" + val number = Regex(pattern).find(serverName)?.value + if (!number.isNullOrEmpty()) { + val newNum = (number.toInt() + 1).toString() + serverName = serverName.replace(number, newNum) } - calendarList[i + 1].setNote(note) + if (serverName.isNotEmpty() && "+" == serverName[serverName.length - 1].toString()) { + serverName = serverName.substring(0, serverName.length - 2) + } + if (firstName.isNotEmpty() && "+" == firstName[firstName.length - 1].toString()) { + firstName = firstName.substring(0, firstName.length - 2) + } + calendarList[i + 1].setFirstName(firstName) + calendarList[i + 1].setServerName(serverName) break } } @@ -68,11 +144,11 @@ class AddKaiFuViewModel(application: Application) : AndroidViewModel(application fun post(activity: Activity) { var isSuccess = true - for (entity in calendarList) { - if (!TextUtils.isEmpty(entity.getNote())) { - entity.setNote(entity.getNote()?.trim()) - } - } +// for (entity in calendarList) { +// if (!TextUtils.isEmpty(entity.getNote())) { +// entity.setNote(entity.getNote()?.trim()) +// } +// } // 初始化标红提示 for (i in 1 until calendarList.size) { @@ -81,7 +157,7 @@ class AddKaiFuViewModel(application: Application) : AndroidViewModel(application for (i in 1 until calendarList.size) { val entity = calendarList[i] - if (entity.getTime() != 0L || !entity.remark.isNullOrEmpty() || !entity.getNote().isNullOrEmpty()) { + if (entity.getTime() != 0L || !entity.getFirstName().isNullOrEmpty() || !entity.getServerName().isNullOrEmpty()) { break } if (i == calendarList.size - 1) { @@ -90,27 +166,38 @@ class AddKaiFuViewModel(application: Application) : AndroidViewModel(application } } - for (i in 1 until calendarList.size) { - val entity = calendarList[i] - if (!entity.remark.isNullOrEmpty() && entity.getTime() == 0L && entity.getNote().isNullOrEmpty()) { - entity.setDataMark(4) - isSuccess = false - } - if (i == calendarList.size - 1 && !isSuccess) { - toast(getApplication(), "必须填写时间和名字") - return - } - } +// for (i in 1 until calendarList.size) { +// val entity = calendarList[i] +// if (!entity.getFirstName().isNullOrEmpty() && entity.getTime() == 0L && entity.getServerName().isNullOrEmpty()) { +// entity.setDataMark(4) +// isSuccess = false +// } +// if (i == calendarList.size - 1 && !isSuccess) { +// toast(getApplication(), "必须填写时间和服务器名称") +// return +// } +// } +// +// for (i in 1 until calendarList.size) { +// val entity = calendarList[i] +// if (entity.getTime() != 0L && entity.getNote().isNullOrEmpty() || entity.getTime() == 0L && !entity.getNote().isNullOrEmpty()) { +// isSuccess = false +// entity.setDataMark(if (entity.getTime() != 0L) 2 else 1) +// } +// if (i == calendarList.size - 1 && !isSuccess) { +// toast(getApplication(), "时间和名字必须同时填写") +// return +// } +// } for (i in 1 until calendarList.size) { val entity = calendarList[i] - if (entity.getTime() != 0L && entity.getNote().isNullOrEmpty() || entity.getTime() == 0L && !entity.getNote().isNullOrEmpty()) { - isSuccess = false - entity.setDataMark(if (entity.getTime() != 0L) 2 else 1) - } - if (i == calendarList.size - 1 && !isSuccess) { - toast(getApplication(), "时间和名字必须同时填写") - return + if (entity.getTime() == 0L || entity.getFirstName().toString().isEmpty() || entity.getServerName().toString().isEmpty()){ + break + } else { + val note = entity.getFirstName().toString().trim() + " | " + entity.getServerName().toString().trim() + entity.setNote(note) + entity.remark = "新服" } } @@ -165,7 +252,7 @@ class AddKaiFuViewModel(application: Application) : AndroidViewModel(application .subscribe(object : Response>() { override fun onResponse(response: List?) { if (response != null) { - for (i in 0 until response.size) { + for (i in response.indices) { postList[i].id = response[i] } } diff --git a/app/src/main/res/layout/activity_kaifu_add.xml b/app/src/main/res/layout/activity_kaifu_add.xml index 9846de1925..5b5b94c5d9 100644 --- a/app/src/main/res/layout/activity_kaifu_add.xml +++ b/app/src/main/res/layout/activity_kaifu_add.xml @@ -37,22 +37,22 @@ android:padding = "20dp" > + android:id="@+id/kaifu_add_container" + addKaiFuView="@{list}" + clickListener="@{clickListener}" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" /> + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/kaifu_add_container" + android:layout_marginTop="20dp" + android:lineSpacingExtra="5dp" + android:text="@string/kaifu_add_hint" + android:textColor="@color/title" + android:textSize="12sp" /> diff --git a/app/src/main/res/layout/kaifu_add_item.xml b/app/src/main/res/layout/kaifu_add_item.xml index 00385c626b..b5926d42ad 100644 --- a/app/src/main/res/layout/kaifu_add_item.xml +++ b/app/src/main/res/layout/kaifu_add_item.xml @@ -1,5 +1,5 @@ - + @@ -24,7 +24,7 @@ - diff --git a/app/src/main/res/layout/kaifu_new_add_item_title.xml b/app/src/main/res/layout/kaifu_new_add_item_title.xml new file mode 100644 index 0000000000..feacd1c390 --- /dev/null +++ b/app/src/main/res/layout/kaifu_new_add_item_title.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + diff --git a/app/src/main/res/layout/layout_add_kaifu_popup.xml b/app/src/main/res/layout/layout_add_kaifu_popup.xml new file mode 100644 index 0000000000..ec5d24c92c --- /dev/null +++ b/app/src/main/res/layout/layout_add_kaifu_popup.xml @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_add_kaifu_popup_item.xml b/app/src/main/res/layout/layout_add_kaifu_popup_item.xml new file mode 100644 index 0000000000..fba0b0b123 --- /dev/null +++ b/app/src/main/res/layout/layout_add_kaifu_popup_item.xml @@ -0,0 +1,35 @@ + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5b58cc8556..f7a92ae5f0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -642,7 +642,7 @@ 已连续签到 %1$d 天]]> %1$d]]> 著作权归作者所有©光环助手 - 操作说明:\n1.第1行是当前开服表上最新的开服信息,仅供参考\n2.点击第1行的内容,会自动在下方表格填入对应的内容\n3.自动填入内容时,时间保留当天,名字会自动按数字加1 + 操作说明:\n1.第1行是当前开服表上最新的开服信息,仅供参考\n2.点击第1行的内容,会自动在下方表格填入对应的内容\n3.自动填入内容时,时间保留当天,名字会自动按数字加1\n4.填入前缀名和服务器名称,提交后会自动合成名字,无需填写 “| ”\n5.时间、前缀名、服务器名称必须同时填写,否则提交后不会新增开服 专栏 找不到图片管理器 个人主页