From b4931c6d367bb46be7735d28b0369d43150ef7dd Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sun, 10 Feb 2019 22:19:49 +0000 Subject: [PATCH] Add a floating action button to open the item link --- .idea/assetWizardSettings.xml | 35 ++++++++++++++++++- .../java/com/readrops/app/ItemActivity.java | 17 +++++++++ .../readrops/app/database/dao/ItemDao.java | 2 +- .../res/drawable/ic_open_in_browser_white.xml | 5 +++ app/src/main/res/layout/activity_item.xml | 12 +++++++ 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/ic_open_in_browser_white.xml diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index 6b96cf0c..7a027e00 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -5,7 +5,40 @@ - + + + diff --git a/app/src/main/java/com/readrops/app/ItemActivity.java b/app/src/main/java/com/readrops/app/ItemActivity.java index 766fe144..137e959b 100644 --- a/app/src/main/java/com/readrops/app/ItemActivity.java +++ b/app/src/main/java/com/readrops/app/ItemActivity.java @@ -2,10 +2,13 @@ package com.readrops.app; import android.arch.lifecycle.ViewModelProvider; import android.content.Intent; +import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.Color; +import android.net.Uri; import android.support.design.widget.AppBarLayout; import android.support.design.widget.CollapsingToolbarLayout; +import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.Toolbar; @@ -45,11 +48,13 @@ public class ItemActivity extends AppCompatActivity { private CollapsingToolbarLayout toolbarLayout; private Toolbar toolbar; + private FloatingActionButton actionButton; private ReadropsWebView webView; public static final String ITEM_ID = "itemId"; public static final String IMAGE_URL = "imageUrl"; + private ItemWithFeed itemWithFeed; @Override protected void onCreate(Bundle savedInstanceState) { @@ -71,12 +76,14 @@ public class ItemActivity extends AppCompatActivity { ImageView imageView = findViewById(R.id.collapsing_layout_image); View scrim = findViewById(R.id.collapsing_layout_scrim); + actionButton = findViewById(R.id.activity_item_fab); 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); @@ -97,9 +104,15 @@ public class ItemActivity extends AppCompatActivity { viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(ItemViewModel.class); viewModel.getItemById(itemId).observe(this, this::bindUI); + + actionButton.setOnClickListener(v -> { + Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(itemWithFeed.getItem().getLink())); + startActivity(urlIntent); + }); } private void bindUI(ItemWithFeed itemWithFeed) { + this.itemWithFeed = itemWithFeed; Item item = itemWithFeed.getItem(); if (item.getImageLink() == null) @@ -132,10 +145,14 @@ public class ItemActivity extends AppCompatActivity { toolbarLayout.setBackgroundColor(itemWithFeed.getBgColor()); toolbarLayout.setContentScrimColor(itemWithFeed.getBgColor()); toolbarLayout.setStatusBarScrimColor(itemWithFeed.getBgColor()); + + actionButton.setBackgroundTintList(ColorStateList.valueOf(itemWithFeed.getBgColor())); } else if (itemWithFeed.getColor() != 0) { toolbarLayout.setBackgroundColor(itemWithFeed.getColor()); toolbarLayout.setContentScrimColor(itemWithFeed.getColor()); toolbarLayout.setStatusBarScrimColor(itemWithFeed.getColor()); + + actionButton.setBackgroundTintList(ColorStateList.valueOf(itemWithFeed.getColor())); } webView.setItem(itemWithFeed, Utils.getDeviceWidth(this)); diff --git a/app/src/main/java/com/readrops/app/database/dao/ItemDao.java b/app/src/main/java/com/readrops/app/database/dao/ItemDao.java index 54b8fcf9..97673ce7 100644 --- a/app/src/main/java/com/readrops/app/database/dao/ItemDao.java +++ b/app/src/main/java/com/readrops/app/database/dao/ItemDao.java @@ -32,6 +32,6 @@ public interface ItemDao { @Insert void insertAll(List items); - @Query("Select title, Item.description, content, pub_date, image_link, author, text_color, background_color, read_time, name, siteUrl from Item Inner Join Feed on Item.feed_id = Feed.id And Item.id = :id") + @Query("Select title, Item.description, content, link, pub_date, image_link, author, text_color, background_color, read_time, name, siteUrl from Item Inner Join Feed on Item.feed_id = Feed.id And Item.id = :id") LiveData getItemById(int id); } diff --git a/app/src/main/res/drawable/ic_open_in_browser_white.xml b/app/src/main/res/drawable/ic_open_in_browser_white.xml new file mode 100644 index 00000000..3fb9799c --- /dev/null +++ b/app/src/main/res/drawable/ic_open_in_browser_white.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_item.xml b/app/src/main/res/layout/activity_item.xml index 77f27c80..88b327a4 100644 --- a/app/src/main/res/layout/activity_item.xml +++ b/app/src/main/res/layout/activity_item.xml @@ -46,6 +46,17 @@ + +