Skip to content

Commit 7389f96

Browse files
author
Alex
committed
[update] 增加基础账户。
1 parent 7a38328 commit 7389f96

File tree

2 files changed

+170
-2
lines changed

2 files changed

+170
-2
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id 'com.android.application' version '7.4.0' apply false
4-
id 'com.android.library' version '7.4.0' apply false
3+
id 'com.android.application' version '7.4.1' apply false
4+
id 'com.android.library' version '7.4.1' apply false
55
}
66

77
task clean(type: Delete) {
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
* Copyright (C) 2022 AlexMofer
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.am.tool.support.accounts;
17+
18+
import android.accounts.Account;
19+
import android.accounts.AccountManager;
20+
21+
import com.am.tool.support.utils.UserDataUtils;
22+
23+
/**
24+
* 基础账户
25+
* Created by Alex on 2023/2/18.
26+
*/
27+
public class BaseAccount {
28+
29+
private final AccountManager mManager;
30+
private final Account mAccount;
31+
32+
public BaseAccount(AccountManager manager, Account account) {
33+
mManager = manager;
34+
mAccount = account;
35+
}
36+
37+
/**
38+
* 保存用户数据
39+
*
40+
* @param key 数据Key
41+
* @param value 数据值
42+
* @return 保存成功时返回true
43+
*/
44+
protected boolean setUserData(String key, String value) {
45+
return UserDataUtils.setUserData(mManager, mAccount, key, value);
46+
}
47+
48+
/**
49+
* 获取用户数据
50+
*
51+
* @param key 数据Key
52+
* @param defaultValue 数据默认值
53+
* @return 数据值
54+
*/
55+
protected String getUserData(String key, String defaultValue) {
56+
return UserDataUtils.getUserData(mManager, mAccount, key, defaultValue);
57+
}
58+
59+
/**
60+
* 保存用户数据
61+
*
62+
* @param key 数据Key
63+
* @param value 数据值
64+
* @return 保存成功时返回true
65+
*/
66+
protected boolean setUserData(String key, int value) {
67+
return UserDataUtils.setUserData(mManager, mAccount, key, value);
68+
}
69+
70+
/**
71+
* 获取用户数据
72+
*
73+
* @param key 数据Key
74+
* @param defaultValue 数据默认值
75+
* @return 数据值
76+
*/
77+
protected int getUserData(String key, int defaultValue) {
78+
return UserDataUtils.getUserData(mManager, mAccount, key, defaultValue);
79+
}
80+
81+
/**
82+
* 保存用户数据
83+
*
84+
* @param key 数据Key
85+
* @param value 数据值
86+
* @return 保存成功时返回true
87+
*/
88+
protected boolean setUserData(String key, long value) {
89+
return UserDataUtils.setUserData(mManager, mAccount, key, value);
90+
}
91+
92+
/**
93+
* 获取用户数据
94+
*
95+
* @param key 数据Key
96+
* @param defaultValue 数据默认值
97+
* @return 数据值
98+
*/
99+
protected long getUserData(String key, long defaultValue) {
100+
return UserDataUtils.getUserData(mManager, mAccount, key, defaultValue);
101+
}
102+
103+
/**
104+
* 保存用户数据
105+
*
106+
* @param key 数据Key
107+
* @param value 数据值
108+
* @return 保存成功时返回true
109+
*/
110+
protected boolean setUserData(String key, float value) {
111+
return UserDataUtils.setUserData(mManager, mAccount, key, value);
112+
}
113+
114+
/**
115+
* 获取用户数据
116+
*
117+
* @param key 数据Key
118+
* @param defaultValue 数据默认值
119+
* @return 数据值
120+
*/
121+
protected float getUserData(String key, float defaultValue) {
122+
return UserDataUtils.getUserData(mManager, mAccount, key, defaultValue);
123+
}
124+
125+
/**
126+
* 保存用户数据
127+
*
128+
* @param key 数据Key
129+
* @param value 数据值
130+
* @return 保存成功时返回true
131+
*/
132+
protected boolean setUserData(String key, double value) {
133+
return UserDataUtils.setUserData(mManager, mAccount, key, value);
134+
}
135+
136+
/**
137+
* 获取用户数据
138+
*
139+
* @param key 数据Key
140+
* @param defaultValue 数据默认值
141+
* @return 数据值
142+
*/
143+
protected double getUserData(String key, double defaultValue) {
144+
return UserDataUtils.getUserData(mManager, mAccount, key, defaultValue);
145+
}
146+
147+
/**
148+
* 保存用户数据
149+
*
150+
* @param key 数据Key
151+
* @param value 数据值
152+
* @return 保存成功时返回true
153+
*/
154+
protected boolean setUserData(String key, boolean value) {
155+
return UserDataUtils.setUserData(mManager, mAccount, key, value);
156+
}
157+
158+
/**
159+
* 获取用户数据
160+
*
161+
* @param key 数据Key
162+
* @param defaultValue 数据默认值
163+
* @return 数据值
164+
*/
165+
protected boolean getUserData(String key, boolean defaultValue) {
166+
return UserDataUtils.getUserData(mManager, mAccount, key, defaultValue);
167+
}
168+
}

0 commit comments

Comments
 (0)