diff --git a/app/src/main/java/com/hyc/parrot/FourActivity.kt b/app/src/main/java/com/hyc/parrot/FourActivity.kt
index b929523..d5d4120 100644
--- a/app/src/main/java/com/hyc/parrot/FourActivity.kt
+++ b/app/src/main/java/com/hyc/parrot/FourActivity.kt
@@ -2,6 +2,8 @@ package com.hyc.parrot
import android.os.Bundle
import com.hyc.parrot_lib.InitCache
+import com.hyc.parrot_lib.InitParam
+import kotlinx.android.synthetic.main.activity_four.tv_tip
import kotlinx.android.synthetic.main.activity_four.tv_user
/**
@@ -11,14 +13,22 @@ import kotlinx.android.synthetic.main.activity_four.tv_user
*/
class FourActivity : BaseActivity() {
- @InitCache("curUser", onlyRead = true)
+ @InitCache("curUser", onlyRead = true, spName = "user")
private lateinit var curUser: UserBean
+ @InitParam("date")
+ private lateinit var date: String
+
+ @InitCache("loginCount", prefixField = "date")
+ private var loginCount = 0
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_four)
tv_user.text = curUser.toString()
+ loginCount++
curUser = UserBean("李四", "123", 0, 0.0f)
+ tv_tip.text = "$date 登录人数:$loginCount"
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/hyc/parrot/ThreeActivity.java b/app/src/main/java/com/hyc/parrot/ThreeActivity.java
index df36b6d..fd90de2 100644
--- a/app/src/main/java/com/hyc/parrot/ThreeActivity.java
+++ b/app/src/main/java/com/hyc/parrot/ThreeActivity.java
@@ -13,6 +13,8 @@
import com.hyc.parrot_lib.InitClassParam;
import com.hyc.parrot_lib.InitDataStructure;
import com.hyc.parrot_lib.InitParam;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -64,7 +66,7 @@ public class ThreeActivity extends BaseActivity {
@InitCache(value = "clickCount", prefixKey = MyPrefixProvider.DATE)
private int clickCount = 0;
- @InitCache("curUser")
+ @InitCache(value = "curUser",spName = "user")
private UserBean curUser;
private EditText etAccount;
@@ -105,7 +107,9 @@ public void onClick(View v) {
}
curUser =
new UserBean(etAccount.getText().toString(), etPassword.getText().toString(), 0, 0);
- startActivity(new Intent(ThreeActivity.this,FourActivity.class));
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+ String date = format.format(new Date());
+ startActivity(new Intent(ThreeActivity.this,FourActivity.class).putExtra("date",date));
}
});
}
diff --git a/app/src/main/res/layout/activity_four.xml b/app/src/main/res/layout/activity_four.xml
index 4867b17..6d6feea 100644
--- a/app/src/main/res/layout/activity_four.xml
+++ b/app/src/main/res/layout/activity_four.xml
@@ -5,6 +5,13 @@
+
+
+ ) {
+ fields.forEach { field ->
+ isCacheParam { field }?.let {
+ initCacheParam(any, field, it)
+ logD("init cache field : ${field.name}")
+ }
+ }
+ }
+
+ private fun initCacheParam(
any: Any,
field: Field,
initCache: InitCache
@@ -301,5 +313,5 @@ class CacheAdapter(private val dataConvert: DataConvert) {
}
interface PrefixProvider {
- fun getKeyPrefix(key: String,prefixKey : String): String
+ fun getKeyPrefix(key: String, prefixKey: String): String
}
\ No newline at end of file
diff --git a/parrot_lib/src/main/java/com/hyc/parrot_lib/Parrot.kt b/parrot_lib/src/main/java/com/hyc/parrot_lib/Parrot.kt
index 6af5ea0..6fc013f 100644
--- a/parrot_lib/src/main/java/com/hyc/parrot_lib/Parrot.kt
+++ b/parrot_lib/src/main/java/com/hyc/parrot_lib/Parrot.kt
@@ -138,20 +138,22 @@ object Parrot {
}
}
}
- cacheAdapter.isCacheParam { if (initCacheParam) field else null }?.let {
- cacheAdapter.initCacheParam(any, field, it)
- logD("init cache field : ${field.name}")
- }
}
//打印未处理的key
- recursiveSet ?: keyMap.forEach {
- if (!it.value) {
- logE(
- "key: ${it.key} not deal in ${any::class.java.name} data : ${bundle.get(
- it.key
- )}"
- )
+ recursiveSet ?: let {
+ keyMap.forEach {
+ if (!it.value) {
+ logE(
+ "key: ${it.key} not deal in ${any::class.java.name} data : ${bundle.get(
+ it.key
+ )}"
+ )
+ }
+ }
+
+ if (initCacheParam) {
+ cacheAdapter.initCacheParam(any, fields)
}
}
}