初始化关注
This commit is contained in:
@ -34,6 +34,7 @@ import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DeviceUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
@ -429,6 +430,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
if (isNewFirstLaunch) {
|
||||
getPluginUpdate();
|
||||
initConcern(); // 初始化关注
|
||||
sp.edit().putBoolean("isNewFirstLaunch", false).apply();
|
||||
}
|
||||
|
||||
@ -463,6 +465,80 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
|
||||
}
|
||||
|
||||
//初始化关注
|
||||
private void initConcern() {
|
||||
final List<String> arrGameId = new ArrayList<>();
|
||||
final String getConcernUrl = Config.HOST + "device/" + TokenUtils.getDeviceId(MainActivity.this) + "/concern";
|
||||
ConcernUtils.loadConcernData(getConcernUrl, new ConcernUtils.DownJsonListener() {
|
||||
@Override
|
||||
public void downSucced(String str) {
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(str);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
String gameId = (String) jsonArray.get(i);
|
||||
arrGameId.add(gameId);
|
||||
}
|
||||
|
||||
getConcernDigest(arrGameId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downFailed() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private int initConcernCount;
|
||||
|
||||
private void addInitConcernCount() {
|
||||
synchronized (MainActivity.class) {
|
||||
initConcernCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void getConcernDigest(final List<String> arrGameId) {
|
||||
final ArrayList<GameEntity> concernDigest = new ArrayList<>();
|
||||
|
||||
final int size = arrGameId.size();
|
||||
initConcernCount = 0;
|
||||
for (String gameId : arrGameId) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "game/" + gameId + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
concernDigest.add(gameEntity);
|
||||
}
|
||||
|
||||
addInitConcernCount();
|
||||
if (size == initConcernCount && concernDigest.size() != 0) {
|
||||
concernManager.addByList(concernDigest);
|
||||
Utils.log("初始化关注成功==");
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addInitConcernCount();
|
||||
if (size == initConcernCount && concernDigest.size() != 0) {
|
||||
concernManager.addByList(concernDigest);
|
||||
Utils.log("初始化关注--有一个以上的游戏无法添加");
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
home1Layout = (LinearLayout) findViewById(R.id.main_ll_game);
|
||||
home2Layout = (LinearLayout) findViewById(R.id.main_ll_news);
|
||||
|
||||
Reference in New Issue
Block a user