团队冲刺2.7

1.评论区继续了解

部分代码:

title = getIntent().getStringExtra("title");
author_name = getIntent().getStringExtra("author_name");
date = getIntent().getStringExtra("date");
pic_url = getIntent().getStringExtra("pic_url");
content_url = getIntent().getStringExtra("content_url");
num = getIntent().getIntExtra("num",1);
//初始化布局
Toolbar toolbar = (Toolbar) findViewById(R.id.browse_toolbar);
setSupportActionBar(toolbar);
browseDL = (DrawerLayout) findViewById(R.id.browse_drawer);
ActionBar actionBar = getSupportActionBar();
if (actionBar!=null){
actionBar.setDisplayHomeAsUpEnabled(true);
}
webView = (WebView)findViewById(R.id.webView);
FAB = (FloatingActionButton) findViewById(R.id.float_collection);
if (num%2==0){
ColorStateList colorStateList = ContextCompat.getColorStateList(getApplicationContext(),R.color.colorPrimary);
FAB.setBackgroundTintList(colorStateList);
}
//收藏
news = DataSupport.findAll(Colltects.class);
FAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (num%2==1){
ColorStateList colorStateList = ContextCompat.getColorStateList(getApplicationContext(),R.color.colorPrimary);
FAB.setBackgroundTintList(colorStateList);
num++;
for (Colltects conew:news){
if (title.equals(conew.getTitle())&&author_name.equals(conew.getAuthor_name())){
flag = false;
Toast.makeText(BrowseNewsActivity.this, "已收藏", Toast.LENGTH_SHORT).show();
}
}
if (flag){
Colltects coll = new Colltects(title,author_name,date,content_url);
coll.save();
Toast.makeText(BrowseNewsActivity.this, "已收藏", Toast.LENGTH_SHORT).show();
}

}else {
ColorStateList colorStateList = ContextCompat.getColorStateList(getApplicationContext(),R.color.colorAccent);
FAB.setBackgroundTintList(colorStateList);
num++;
DataSupport.deleteAll(Colltects.class,"title = ? and author_name = ?",title,author_name);
Toast.makeText(BrowseNewsActivity.this, "取消收藏", Toast.LENGTH_SHORT).show();
}
}
});
webView.loadUrl(content_url);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
posted @ 2021-06-03 13:24  chenghaixinag  阅读(23)  评论(0编辑  收藏  举报