Skip to content

Commit 4d54175

Browse files
committed
升级 Kotlin 版本库及一些方法的优化,fix 接口改动问题。
1 parent 1fff1f8 commit 4d54175

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

app/src/main/java/com/hazz/kotlinmvp/ui/activity/WatchHistoryActivity.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.hazz.kotlinmvp.R
77
import com.hazz.kotlinmvp.base.BaseActivity
88
import com.hazz.kotlinmvp.mvp.model.bean.HomeBean
99
import com.hazz.kotlinmvp.ui.adapter.WatchHistoryAdapter
10+
import com.hazz.kotlinmvp.utils.Preference
1011
import com.hazz.kotlinmvp.utils.StatusBarUtil
1112
import com.hazz.kotlinmvp.utils.WatchHistoryUtils
1213
import kotlinx.android.synthetic.main.activity_about.*
@@ -25,7 +26,7 @@ class WatchHistoryActivity : BaseActivity() {
2526
private var itemListData = ArrayList<HomeBean.Issue.Item>()
2627

2728
companion object {
28-
private val HISTORY_MAX = 20
29+
private const val HISTORY_MAX = 20
2930
}
3031

3132
override fun layoutId(): Int = R.layout.layout_watch_history
@@ -78,7 +79,7 @@ class WatchHistoryActivity : BaseActivity() {
7879
WatchHistoryUtils.getObject(Constants.FILE_WATCH_HISTORY_NAME, MyApplication.context,
7980
keys[keyLength - it] as String) as HomeBean.Issue.Item
8081
}
81-
82+
8283
return watchList
8384
}
8485

app/src/main/java/com/hazz/kotlinmvp/utils/Preference.kt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,28 @@ class Preference<T>(val name:String, private val default:T) {
1616

1717
companion object {
1818
private const val file_name = "kotlin_mvp_file"
19-
}
2019

21-
private val prefs: SharedPreferences by lazy {
22-
MyApplication.context.getSharedPreferences(file_name, Context.MODE_PRIVATE)
20+
private val prefs: SharedPreferences by lazy {
21+
MyApplication.context.getSharedPreferences(file_name, Context.MODE_PRIVATE)
22+
}
23+
/**
24+
* 删除全部数据
25+
*/
26+
fun clearPreference(){
27+
prefs.edit().clear().apply()
28+
}
29+
30+
/**
31+
* 根据key删除存储数据
32+
*/
33+
fun clearPreference(key : String){
34+
prefs.edit().remove(key).apply()
35+
}
2336
}
2437

2538

39+
40+
2641
operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
2742
return getSharedPreferences(name, default)
2843
}
@@ -56,19 +71,7 @@ class Preference<T>(val name:String, private val default:T) {
5671
return res as T
5772
}
5873

59-
/**
60-
* 删除全部数据
61-
*/
62-
fun clearPreference(){
63-
prefs.edit().clear().apply()
64-
}
6574

66-
/**
67-
* 根据key删除存储数据
68-
*/
69-
fun clearPreference(key : String){
70-
prefs.edit().remove(key).apply()
71-
}
7275

7376
/**
7477
* 序列化对象

config.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ ext{
55
buildToolsVersion: "27.0.3",
66
minSdkVersion : 19,
77
targetSdkVersion : 27,
8-
versionCode : 5,
9-
versionName : "1.2.2"
8+
versionCode : 6,
9+
versionName : "1.3.0"
1010
]
1111

1212
dependVersion = [

0 commit comments

Comments
 (0)