Skip to content

Commit

Permalink
[Add]: [prefixField test]
Browse files Browse the repository at this point in the history
  • Loading branch information
old-traveler committed Dec 23, 2019
1 parent c273ff3 commit 9da92ef
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
12 changes: 11 additions & 1 deletion app/src/main/java/com/hyc/parrot/FourActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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"
}

}
8 changes: 6 additions & 2 deletions app/src/main/java/com/hyc/parrot/ThreeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
});
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_four.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@


<TextView
android:id="@+id/tv_tip"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<TextView
android:layout_marginTop="50dp"
android:id="@+id/tv_user"
android:layout_gravity="center"
android:layout_width="wrap_content"
Expand Down
14 changes: 13 additions & 1 deletion parrot_lib/src/main/java/com/hyc/parrot_lib/CacheAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ class CacheAdapter(private val dataConvert: DataConvert) {
}

fun initCacheParam(
any: Any,
fields: Array<out Field>
) {
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
Expand Down Expand Up @@ -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
}
24 changes: 13 additions & 11 deletions parrot_lib/src/main/java/com/hyc/parrot_lib/Parrot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 9da92ef

Please sign in to comment.