Commit 0b81449f authored by sheteng's avatar sheteng

fix

取消点赞
parent 1fe0d2a8
......@@ -124,7 +124,7 @@ class NewsObjectFragment : XPageFragment() {
}
itemData.isGreat?.let {
if (it) {
itemView.findViewById<TextView>(R.id.great_num).setTextColor(Color.parseColor("#FF3B4FBE"))
itemView.findViewById<TextView>(R.id.great_num).setTextColor(Color.parseColor("#3CA4FD"))
itemView.findViewById<ImageView>(R.id.great_img)
.setBackgroundResource(R.mipmap.icon_praise_bu)
} else {
......@@ -135,13 +135,15 @@ class NewsObjectFragment : XPageFragment() {
}
itemView.findViewById<ImageView>(R.id.great_img).setOnClickListener {
itemData.isGreat?.let {
if (it) {
return@setOnClickListener
}
newsViewModel?.greate(itemData.type, gameId, itemData.id) {
newsViewModel?.greate(this@NewsObjectFragment,itemData.type, gameId, itemData.id,it) {
if (!it) {
ToastUtils.show("点赞成功")
itemData.isGreat = true
itemData.greatNum++
} else {
itemData.isGreat = false
itemData.greatNum--
}
recycle_view?.adapter?.notifyDataSetChanged()
}
}
......
......@@ -4,7 +4,9 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ccwangluo.accelerator.model.NewsModel
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.utils.http.HttpGo
import com.xuexiang.xpage.base.XPageFragment
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
......@@ -37,12 +39,17 @@ class NewsObjectModel : ViewModel() {
/**
* 点赞
*/
fun greate(type: Int?,gameId : Int, parentId: Int, callback: () -> Unit) {
val map = mutableMapOf<String, String>()
map.put("gameId", gameId.toString())
map.put("parentId",parentId.toString())
fun greate(xPageFragment: XPageFragment,type: Int?, gameId: Int, parentId: Int, isGreate: Boolean, callback: () -> Unit) {
val map = mutableMapOf<String, Any>()
map.put("gameId", gameId)
map.put("parentId", parentId)
map.put("isUnGreat", isGreate)
type?.let {
map.put("type", it.toString())
map.put("type", it)
}
if (LoginUtils.token == null) {
LoginUtils.login(xPageFragment,{})
return
}
viewModelScope.launch(Dispatchers.IO) {
val res =
......
......@@ -6,6 +6,7 @@ import com.github.shadowsocks.http.HttpConfig
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.hjq.toast.ToastUtils
import com.umeng.vt.diff.V
import okhttp3.*
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType.Companion.toMediaTypeOrNull
......@@ -76,7 +77,7 @@ object HttpGo {
/**
* 同步请求
*/
inline fun <reified T> postSync(url: String, param: MutableMap<String, String>): BaseModel<T>? {
inline fun <reified T> postSync(url: String, param: MutableMap<String, out Any>): BaseModel<T>? {
try {
val body: RequestBody = gson.toJson(param).toString().toRequestBody(jsonType)
val request = Request.Builder()
......
......@@ -105,10 +105,6 @@
android:theme="@style/Theme.Shadowsocks.ActionBar"/>
<activity android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:theme="@style/Theme.Shadowsocks.ActionBar"/>
<service android:name="com.google.firebase.components.ComponentDiscoveryService"
android:directBootAware="true"/>
<provider android:name="com.google.firebase.provider.FirebaseInitProvider"
tools:node="remove"/>
<service android:name="androidx.room.MultiInstanceInvalidationService"
android:process=":bg"/>
</application>
......
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