mirror of https://github.com/readrops/Readrops.git
Improving item activity code and toolbar status when no header image is available
This commit is contained in:
parent
b7ac444be0
commit
017ce251fa
|
@ -10,6 +10,7 @@ import android.support.v7.app.AppCompatActivity;
|
|||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
@ -41,8 +42,12 @@ public class ItemActivity extends AppCompatActivity {
|
|||
private RelativeLayout readTimeLayout;
|
||||
|
||||
private CollapsingToolbarLayout toolbarLayout;
|
||||
private Toolbar toolbar;
|
||||
private ReadropsWebView webView;
|
||||
|
||||
public static final String ITEM_ID = "itemId";
|
||||
public static final String IMAGE_URL = "imageUrl";
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -50,10 +55,10 @@ public class ItemActivity extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_item);
|
||||
|
||||
Intent intent = getIntent();
|
||||
int itemId = intent.getIntExtra("itemId", 0);
|
||||
String imageUrl = intent.getStringExtra("imageUrl");
|
||||
int itemId = intent.getIntExtra(ITEM_ID, 0);
|
||||
String imageUrl = intent.getStringExtra(IMAGE_URL);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.collasping_layout_toolbar);
|
||||
toolbar = findViewById(R.id.collasping_layout_toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
if (getSupportActionBar() != null)
|
||||
|
@ -61,21 +66,29 @@ public class ItemActivity extends AppCompatActivity {
|
|||
|
||||
toolbarLayout = findViewById(R.id.collapsing_layout);
|
||||
AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout);
|
||||
if (imageUrl == null)
|
||||
appBarLayout.setExpanded(false);
|
||||
|
||||
ImageView imageView = findViewById(R.id.collapsing_layout_image);
|
||||
|
||||
GlideApp.with(this)
|
||||
.load(imageUrl)
|
||||
.into(imageView);
|
||||
|
||||
webView = findViewById(R.id.item_webview);
|
||||
title = findViewById(R.id.activity_item_title);
|
||||
author = findViewById(R.id.activity_item_author);
|
||||
readTime = findViewById(R.id.activity_item_readtime);
|
||||
readTimeLayout = findViewById(R.id.activity_item_readtime_layout);
|
||||
|
||||
if (imageUrl == null) {
|
||||
appBarLayout.setExpanded(false);
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
toolbarLayout.setTitleEnabled(false);
|
||||
|
||||
toolbar.setTitleTextColor(Color.WHITE);
|
||||
} else {
|
||||
appBarLayout.setExpanded(true);
|
||||
toolbarLayout.setTitleEnabled(true);
|
||||
|
||||
GlideApp.with(this)
|
||||
.load(imageUrl)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(ItemViewModel.class);
|
||||
viewModel.getItemById(itemId).observe(this, this::bindUI);
|
||||
}
|
||||
|
@ -83,7 +96,11 @@ public class ItemActivity extends AppCompatActivity {
|
|||
private void bindUI(ItemWithFeed itemWithFeed) {
|
||||
Item item = itemWithFeed.getItem();
|
||||
|
||||
toolbarLayout.setTitle(itemWithFeed.getFeedName());
|
||||
if (item.getImageLink() == null)
|
||||
toolbar.setTitle(itemWithFeed.getFeedName());
|
||||
else
|
||||
toolbarLayout.setTitle(itemWithFeed.getFeedName());
|
||||
|
||||
title.setText(item.getTitle());
|
||||
|
||||
if (item.getAuthor() != null) {
|
||||
|
|
|
@ -127,8 +127,8 @@ public class MainActivity extends AppCompatActivity implements SimpleCallback, S
|
|||
adapter = new MainItemListAdapter(GlideApp.with(this), preloadSizeProvider);
|
||||
adapter.setOnItemClickListener(itemWithFeed -> {
|
||||
Intent intent = new Intent(this, ItemActivity.class);
|
||||
intent.putExtra("itemId", itemWithFeed.getItem().getId());
|
||||
intent.putExtra("imageUrl", itemWithFeed.getItem().getImageLink());
|
||||
intent.putExtra(ItemActivity.ITEM_ID, itemWithFeed.getItem().getId());
|
||||
intent.putExtra(ItemActivity.IMAGE_URL, itemWithFeed.getItem().getImageLink());
|
||||
|
||||
startActivity(intent);
|
||||
});
|
||||
|
|
|
@ -32,6 +32,6 @@ public interface ItemDao {
|
|||
@Insert
|
||||
void insertAll(List<Item> items);
|
||||
|
||||
@Query("Select title, Item.description, content, pub_date, author, 0 as color, read_time, name from Item Inner Join Feed on Item.feed_id = Feed.id And Item.id = :id")
|
||||
@Query("Select title, Item.description, content, pub_date, image_link, author, 0 as color, read_time, name from Item Inner Join Feed on Item.feed_id = Feed.id And Item.id = :id")
|
||||
LiveData<ItemWithFeed> getItemById(int id);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue