Commit 0b81449f authored by sheteng's avatar sheteng

fix

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