收藏相关(文章检查是否修改未完成)
This commit is contained in:
@ -19,12 +19,17 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.CheckLoginUtils;
|
||||
import com.gh.common.util.CollectionUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.gamecenter.db.CollectionDao;
|
||||
import com.gh.gamecenter.entity.CommentnumEntity;
|
||||
import com.gh.gamecenter.entity.ToolBoxEntity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.google.gson.Gson;
|
||||
import com.jakewharton.rxbinding.view.RxView;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
@ -61,8 +66,11 @@ public class WebActivity extends BaseActivity {
|
||||
private int commentNum;
|
||||
|
||||
private boolean mIsTools;
|
||||
private boolean mIsCollectionTools;
|
||||
private ToolBoxEntity mToolBoxEntity;
|
||||
|
||||
private CollectionDao mCollectionDao;
|
||||
|
||||
@NonNull
|
||||
public static Intent getWebIntent(Context context) {
|
||||
Intent intent = new Intent(context, WebActivity.class);
|
||||
@ -71,6 +79,17 @@ public class WebActivity extends BaseActivity {
|
||||
return intent;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static void startWebByCollectionTools(Context context, ToolBoxEntity toolBoxEntity) {
|
||||
Intent intent = new Intent(context, WebActivity.class);
|
||||
intent.putExtra("url", toolBoxEntity.getUrl());
|
||||
intent.putExtra("isTools", true);
|
||||
intent.putExtra("gameName", toolBoxEntity.getName());
|
||||
intent.putExtra("ToolBoxEntity", toolBoxEntity);
|
||||
intent.putExtra("isCollectionTools", true);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_web;
|
||||
@ -106,9 +125,12 @@ public class WebActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
if (mIsTools) {
|
||||
mCollectionDao = new CollectionDao(this);
|
||||
mToolBoxEntity = getIntent().getParcelableExtra("ToolBoxEntity");
|
||||
mIsCollectionTools = getIntent().getBooleanExtra("isCollectionTools", false);
|
||||
mShareIv.setVisibility(View.VISIBLE);
|
||||
mCollectionIv.setVisibility(View.VISIBLE);
|
||||
initCollection();
|
||||
} else {
|
||||
mShareIv.setVisibility(View.GONE);
|
||||
mCollectionIv.setVisibility(View.GONE);
|
||||
@ -177,7 +199,6 @@ public class WebActivity extends BaseActivity {
|
||||
newsTitle.setPadding(DisplayUtils.dip2px(getApplication(), 30), 0, DisplayUtils.dip2px(getApplication(), 30), 0);
|
||||
newsTitle.setSingleLine();
|
||||
newsTitle.setText(title);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -196,6 +217,47 @@ public class WebActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (mIsCollectionTools && mToolBoxEntity != null) {
|
||||
getToolsById(); // 对比查看是否修改
|
||||
}
|
||||
}
|
||||
|
||||
private void initCollection() {
|
||||
if (mToolBoxEntity != null) {
|
||||
boolean exist = mCollectionDao.isExist(mToolBoxEntity.getId());
|
||||
mCollectionIv.setVisibility(View.VISIBLE);
|
||||
if (exist) {
|
||||
mCollectionIv.setImageResource(R.drawable.detail_collection_select);
|
||||
} else {
|
||||
mCollectionIv.setImageResource(R.drawable.detail_collection_unselect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void getToolsById() {
|
||||
RetrofitManager
|
||||
.getApi()
|
||||
.getToolBoxById(mToolBoxEntity.getId())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<ToolBoxEntity>>() {
|
||||
@Override
|
||||
public void onResponse(List<ToolBoxEntity> response) {
|
||||
super.onResponse(response);
|
||||
if (response.size() == 0) return;
|
||||
|
||||
ToolBoxEntity toolBoxEntity = response.get(0);
|
||||
Gson gson = new Gson();
|
||||
|
||||
String newEntity = gson.toJson(toolBoxEntity);
|
||||
String entity = gson.toJson(mToolBoxEntity);
|
||||
if (!newEntity.equals(entity)) {
|
||||
CollectionUtils.INSTANCE.patchCollection(WebActivity.this, toolBoxEntity.getId(), CollectionUtils.CollectionTag.tools);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getNewsCommentNum() {
|
||||
@ -225,7 +287,49 @@ public class WebActivity extends BaseActivity {
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, mEntrance + "+(光环浏览器)");
|
||||
startActivityForResult(intent, 1001);
|
||||
} else if (v == mCollectionIv) {
|
||||
// TODO 收藏
|
||||
CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() {
|
||||
@Override
|
||||
public void onLoggedIn() {
|
||||
mCollectionIv.setEnabled(false);
|
||||
if (mCollectionDao.isExist(mToolBoxEntity.getId())) {
|
||||
CollectionUtils.INSTANCE.deleteCollection(WebActivity.this, mToolBoxEntity.getId(),
|
||||
CollectionUtils.CollectionTag.tools,
|
||||
new CollectionUtils.OnCollectionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
mCollectionDao.delete(mToolBoxEntity.getId());
|
||||
mCollectionIv.setEnabled(true);
|
||||
mCollectionIv.setImageResource(R.drawable.detail_collection_unselect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
mCollectionIv.setEnabled(true);
|
||||
toast("取消收藏失败");
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
String content = new Gson().toJson(mToolBoxEntity);
|
||||
CollectionUtils.INSTANCE.postCollection(WebActivity.this, content,
|
||||
CollectionUtils.CollectionTag.tools,
|
||||
new CollectionUtils.OnCollectionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
mCollectionDao.add(mToolBoxEntity.getId());
|
||||
mCollectionIv.setEnabled(true);
|
||||
mCollectionIv.setImageResource(R.drawable.detail_collection_select);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
mCollectionIv.setEnabled(true);
|
||||
toast("收藏失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user