diff --git a/app/src/main/java/com/lsp/view/common/PreKV.kt b/app/src/main/java/com/lsp/view/common/PreKV.kt new file mode 100644 index 0000000..cc76ad0 --- /dev/null +++ b/app/src/main/java/com/lsp/view/common/PreKV.kt @@ -0,0 +1,9 @@ +package com.lsp.view.common + +object PreKV { + const val SOURCE_NAME = "source_name" +} + +object Pre{ + const val NAME = "com.lsp.view_preferences" +} \ No newline at end of file diff --git a/app/src/main/java/com/lsp/view/repository/network/PostDataSource.kt b/app/src/main/java/com/lsp/view/repository/network/PostDataSource.kt index 7c0c23b..645e87b 100644 --- a/app/src/main/java/com/lsp/view/repository/network/PostDataSource.kt +++ b/app/src/main/java/com/lsp/view/repository/network/PostDataSource.kt @@ -6,8 +6,14 @@ import com.lsp.view.repository.exception.UnableConstructObjectException import com.lsp.view.repository.network.api.PostApi import com.lsp.view.repository.network.api.PostApiImpl import com.lsp.view.bean.YandPost +import com.lsp.view.common.Pre +import com.lsp.view.common.PreKV class PostDataSource { + companion object{ + const val YANDE_RE = "yande.re" + const val KONACHAN = "konachan" + } private val api: PostApi = PostApiImpl() @@ -28,8 +34,8 @@ data class Load( fun Builder(tags: String?, page: Int, safe:Boolean): Load { val sourceNameArray = YandViewApplication.context!!.resources.getStringArray(R.array.pic_source) val sourceUrlArray = YandViewApplication.context!!.resources.getStringArray(R.array.url_source) - val configSp = YandViewApplication.context?.getSharedPreferences("com.lsp.view_preferences", 0) - val nowSourceName: String? = configSp?.getString("source_name",null) + val configSp = YandViewApplication.context?.getSharedPreferences(Pre.NAME, 0) + val nowSourceName: String = configSp?.getString(PreKV.SOURCE_NAME,null) ?: PostDataSource.YANDE_RE val load = Load(tags,page,safe) //初始化数据