Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-android
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c2a1fef9
authored
Jul 15, 2021
by
amateur
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
ee9add31
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
13 deletions
app/src/main/java/com/polysoft/nafmii/bean/AdvertisementBean.java
app/src/main/java/com/polysoft/nafmii/net/RequestBack.java
app/src/main/java/com/polysoft/nafmii/viewmodel/AdvertisementViewModel.java
app/src/main/java/com/polysoft/nafmii/bean/AdvertisementBean.java
0 → 100644
View file @
c2a1fef
package
com
.
polysoft
.
nafmii
.
bean
;
import
com.alibaba.fastjson.annotation.JSONField
;
public
class
AdvertisementBean
{
@JSONField
(
name
=
"picUrl"
)
String
picUrl
;
@JSONField
(
name
=
"linkUrl"
)
String
linkUrl
;
@JSONField
(
name
=
"linkType"
)
String
linkType
;
@JSONField
(
name
=
"isShare"
)
int
isShare
;
@JSONField
(
name
=
"isLogin"
)
int
isLogin
;
public
String
getPicUrl
()
{
return
picUrl
;
}
public
String
getLinkUrl
()
{
return
linkUrl
;
}
public
String
getLinkType
()
{
return
linkType
;
}
public
int
getIsShare
()
{
return
isShare
;
}
public
int
getIsLogin
()
{
return
isLogin
;
}
public
void
setPicUrl
(
String
picUrl
)
{
this
.
picUrl
=
picUrl
;
}
public
void
setLinkUrl
(
String
linkUrl
)
{
this
.
linkUrl
=
linkUrl
;
}
public
void
setLinkType
(
String
linkType
)
{
this
.
linkType
=
linkType
;
}
public
void
setIsShare
(
int
isShare
)
{
this
.
isShare
=
isShare
;
}
public
void
setIsLogin
(
int
isLogin
)
{
this
.
isLogin
=
isLogin
;
}
}
app/src/main/java/com/polysoft/nafmii/net/RequestBack.java
View file @
c2a1fef
...
...
@@ -45,8 +45,8 @@ public abstract class RequestBack<T> {
}
JSONObject
res
=
JSON
.
parseObject
(
string
);
int
status
=
res
.
getInteger
(
"status"
);
if
(
status
==
200
)
{
String
status
=
res
.
getString
(
"status"
);
if
(
"0"
.
equals
(
status
)
)
{
String
json
=
res
.
getString
(
"data"
);
Log
.
d
(
"onParseResponse"
,
"onParseResponse: "
+
json
);
Type
type
=
this
.
getClass
().
getGenericSuperclass
();
...
...
app/src/main/java/com/polysoft/nafmii/viewmodel/AdvertisementViewModel.java
View file @
c2a1fef
...
...
@@ -13,12 +13,16 @@ import androidx.lifecycle.ViewModel;
import
androidx.lifecycle.ViewModelProvider
;
import
androidx.lifecycle.ViewModelStoreOwner
;
import
com.polysoft.nafmii.bean.AdvertisementBean
;
import
com.polysoft.nafmii.constants.ServerApi
;
import
com.polysoft.nafmii.enums.StateEnum
;
import
com.polysoft.nafmii.net.RequestBack
;
import
com.polysoft.nafmii.utils.TimerUtils
;
import
com.whaty.nafmii.BuildConfig
;
public
class
AdvertisementViewModel
extends
ViewModel
{
private
MutableLiveData
<
LiveData
>
data
=
new
MutableLiveData
<>();
private
MutableLiveData
<
LiveData
>
data
Model
=
new
MutableLiveData
<>();
private
final
LifecycleOwner
owner
;
public
static
AdvertisementViewModel
newInstance
(
FragmentActivity
owner
)
{
...
...
@@ -35,27 +39,40 @@ public class AdvertisementViewModel extends ViewModel {
AdvertisementViewModel
(
LifecycleOwner
owner
)
{
this
.
owner
=
owner
;
System
.
out
.
println
(
"=====================>>>>>AdvertisementViewModel"
);
TimerUtils
.
setTimeOut
(
msg
->
{
this
.
data
.
setValue
(
new
LiveData
());
return
false
;
},
1000
);
this
.
fetchData
();
}
public
void
observe
(
Observer
<
LiveData
>
observer
)
{
this
.
data
.
observe
(
this
.
owner
,
observer
);
this
.
dataModel
.
observe
(
this
.
owner
,
observer
);
}
private
void
fetchData
()
{
ServerApi
.
postAdvertisement
(
new
RequestBack
<
AdvertisementBean
>()
{
@Override
protected
void
onResponse
(
StateEnum
state
,
AdvertisementBean
data
,
String
message
)
{
if
(
state
.
state
==
StateEnum
.
OK
.
state
)
{
dataModel
.
setValue
(
new
LiveData
(
data
));
}
else
{
dataModel
.
setValue
(
new
LiveData
(
null
));
}
}
});
}
public
static
class
LiveData
{
public
String
json
;
public
final
AdvertisementBean
data
;
LiveData
(
AdvertisementBean
data
)
{
this
.
data
=
data
;
}
public
boolean
empty
()
{
if
(
BuildConfig
.
DEBUG
)
{
return
tru
e
;
return
fals
e
;
}
return
TextUtils
.
isEmpty
(
json
);
return
null
==
this
.
data
||
TextUtils
.
isEmpty
(
this
.
data
.
getPicUrl
()
);
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment