add determine duplicate tags

This commit is contained in:
inxtes
2022-01-03 15:46:50 +08:00
parent 6507fae975
commit 8a3679b4df
@@ -7,6 +7,7 @@ import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.lsp.view.R import com.lsp.view.R
@@ -43,6 +44,13 @@ class TagAdapter(val tagList:List<Tags>,val context: Context):RecyclerView.Adapt
val tagListType = object :TypeToken<ArrayList<Tags>>(){}.type val tagListType = object :TypeToken<ArrayList<Tags>>(){}.type
tagsArray = Gson().fromJson(tagsArrayJson,tagListType) tagsArray = Gson().fromJson(tagsArrayJson,tagListType)
} }
for (tag:Tags in tagsArray){
if (tag.tag == viewHolder.tagText.text.toString()){
Toast.makeText(context,"收藏过了哦",Toast.LENGTH_SHORT).show()
return@setOnLongClickListener true
}
}
tagsArray.add(Tags(viewHolder.tagText.text.toString())) tagsArray.add(Tags(viewHolder.tagText.text.toString()))
tagsArraySp.edit().putString("array",Gson().toJson(tagsArray)).apply() tagsArraySp.edit().putString("array",Gson().toJson(tagsArray)).apply()
Toast.makeText(context,"收藏了新标签",Toast.LENGTH_SHORT).show() Toast.makeText(context,"收藏了新标签",Toast.LENGTH_SHORT).show()