Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
56ccf574
authored
Jul 15, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加本地存储类
parent
77586532
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
+71
-0
app/src/main/java/com/bgycc/smartcanteen/Storage/PayStorage.java
+57
-0
app/src/main/java/com/bgycc/smartcanteen/Storage/Storage.java
+14
-0
No files found.
app/src/main/java/com/bgycc/smartcanteen/Storage/PayStorage.java
0 → 100644
View file @
56ccf574
package
com
.
bgycc
.
smartcanteen
.
Storage
;
import
android.content.Context
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
public
class
PayStorage
extends
Storage
{
static
final
String
TAG
=
PayStorage
.
class
.
getSimpleName
();
enum
Key
{
PAY_LIST
}
static
PayStorage
sInstance
;
public
static
void
initialize
(
Context
context
)
{
sInstance
=
new
PayStorage
(
context
);
}
public
static
PayStorage
getInstance
()
{
return
sInstance
;
}
JSONArray
mPayList
=
new
JSONArray
();
PayStorage
(
Context
context
)
{
super
(
TAG
,
context
);
try
{
String
tmp
=
mSharedPreferences
.
getString
(
Key
.
PAY_LIST
.
name
(),
"[]"
);
mPayList
=
new
JSONArray
(
tmp
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
public
synchronized
void
add
(
JSONObject
payInfo
)
{
mPayList
.
put
(
payInfo
);
}
public
synchronized
JSONArray
getPayList
()
{
return
mPayList
;
}
public
synchronized
void
savePayList
()
{
mSharedPreferences
.
edit
()
.
putString
(
Key
.
PAY_LIST
.
name
(),
mPayList
.
toString
())
.
apply
();
}
public
synchronized
void
clearPayList
()
{
mPayList
=
new
JSONArray
();
mSharedPreferences
.
edit
()
.
remove
(
Key
.
PAY_LIST
.
name
())
.
apply
();
}
}
app/src/main/java/com/bgycc/smartcanteen/Storage/Storage.java
0 → 100644
View file @
56ccf574
package
com
.
bgycc
.
smartcanteen
.
Storage
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
public
abstract
class
Storage
{
SharedPreferences
mSharedPreferences
;
protected
Storage
(
String
name
,
Context
context
)
{
mSharedPreferences
=
context
.
getSharedPreferences
(
name
,
Context
.
MODE_PRIVATE
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment