fix: safe model
This commit is contained in:
@@ -4,6 +4,7 @@ import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.content.Intent
|
||||
import android.os.*
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
@@ -157,6 +158,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val nowMode = configSp.getBoolean("safe_mode", true)
|
||||
if (viewModel.uiState.value.isSafe != nowMode){
|
||||
viewModel.updateSafeMode(nowMode)
|
||||
Log.e(TAG,nowMode.toString())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
package com.lsp.view.activity.main
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Message
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.model.GlideUrl
|
||||
@@ -32,7 +27,7 @@ class PostAdapter(val context: Context):
|
||||
|
||||
}
|
||||
|
||||
fun pushNewData(list: ArrayList<YandPost>) {
|
||||
fun pushNewData(list: List<YandPost>) {
|
||||
val oldSize = postList.size
|
||||
postList.clear()
|
||||
notifyItemRangeRemoved(0,oldSize)
|
||||
@@ -40,7 +35,7 @@ class PostAdapter(val context: Context):
|
||||
notifyItemRangeInserted(0, list.size)
|
||||
}
|
||||
|
||||
fun appendDate(list: ArrayList<YandPost>){
|
||||
fun appendDate(list: List<YandPost>){
|
||||
val pos = postList.size
|
||||
postList.addAll(list)
|
||||
notifyItemRangeInserted(pos, list.size)
|
||||
|
||||
@@ -66,6 +66,8 @@ class MainViewModel(private val repository: PostRepository,context: Context):Vie
|
||||
it.apply {
|
||||
it.nowSourceName.postValue(configSp.getString("source_name",null))
|
||||
}
|
||||
|
||||
it.copy(isSafe = configSp.getBoolean("safe_mode",true))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.lsp.view.repository
|
||||
|
||||
import android.os.Handler
|
||||
import com.lsp.view.repository.bean.YandPost
|
||||
|
||||
|
||||
@@ -8,8 +7,7 @@ class PostRepository {
|
||||
private val dataSource = PostDataSource()
|
||||
|
||||
//获取post
|
||||
suspend fun fetchPostData(searchTarget :String?,safe:Boolean,page:Int): ArrayList<YandPost> {
|
||||
|
||||
suspend fun fetchPostData(searchTarget :String?,safe:Boolean,page:Int): List<YandPost> {
|
||||
var target = searchTarget
|
||||
var isNum = true
|
||||
|
||||
@@ -25,8 +23,14 @@ class PostRepository {
|
||||
}
|
||||
|
||||
val load = Load.Builder(target,page,safe)
|
||||
val dataList = dataSource.fetchNewPost(load)
|
||||
|
||||
return if (safe){
|
||||
dataList.filter { it.rating == "s" }
|
||||
}else{
|
||||
dataList
|
||||
}
|
||||
|
||||
return dataSource.fetchNewPost(load)
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.lsp.view.repository.api
|
||||
|
||||
import android.util.Log
|
||||
import com.lsp.view.repository.Load
|
||||
import com.lsp.view.repository.bean.Post
|
||||
import com.lsp.view.repository.bean.YandPost
|
||||
import com.lsp.view.repository.exception.NetworkErrorException
|
||||
import retrofit2.Call
|
||||
import java.net.SocketException
|
||||
|
||||
interface PostApi {
|
||||
private val TAG: String
|
||||
@@ -22,7 +20,6 @@ interface PostApi {
|
||||
val execute = service.execute()
|
||||
return if (execute.isSuccessful) {
|
||||
if (execute.body() != null) {
|
||||
Log.e(TAG, execute.body().toString())
|
||||
execute.body()!!
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user