Add a floating action button to open the item link

This commit is contained in:
Shinokuni 2019-02-10 22:19:49 +00:00
parent c9b3e3f09f
commit b4931c6d36
5 changed files with 69 additions and 2 deletions

View File

@ -5,7 +5,40 @@
<map>
<entry key="vectorWizard">
<value>
<PersistentState />
<PersistentState>
<option name="children">
<map>
<entry key="vectorAssetStep">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="clipartAsset">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="url" value="jar:file:/Applications/Android%20Studio.app/Contents/plugins/android/lib/android.jar!/images/material_design_icons/action/ic_open_in_browser_black_24dp.xml" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
<option name="values">
<map>
<entry key="color" value="ffffff" />
<entry key="outputName" value="ic_open_in_browser_white" />
<entry key="sourceFile" value="$USER_HOME$" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</PersistentState>
</value>
</entry>
</map>

View File

@ -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));

View File

@ -32,6 +32,6 @@ public interface ItemDao {
@Insert
void insertAll(List<Item> 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<ItemWithFeed> getItemById(int id);
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,4L5,4c-1.11,0 -2,0.9 -2,2v12c0,1.1 0.89,2 2,2h4v-2L5,18L5,8h14v10h-4v2h4c1.1,0 2,-0.9 2,-2L21,6c0,-1.1 -0.89,-2 -2,-2zM12,10l-4,4h3v6h2v-6h3l-4,-4z"/>
</vector>

View File

@ -46,6 +46,17 @@
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/activity_item_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_open_in_browser_white"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -54,6 +65,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:padding="10dp">
<RelativeLayout