mirror of https://github.com/readrops/Readrops.git
Add item details below the collapsing toolbar layout. Improving general UI
This commit is contained in:
parent
9042b9a039
commit
8bf62465ff
|
@ -3,6 +3,7 @@ package com.readrops.app;
|
|||
import android.app.Application;
|
||||
import android.arch.lifecycle.LiveData;
|
||||
|
||||
import com.readrops.app.database.ItemWithFeed;
|
||||
import com.readrops.app.database.entities.Item;
|
||||
import com.readrops.readropslibrary.ParsingResult;
|
||||
|
||||
|
@ -12,7 +13,7 @@ public class BasedRepository extends ARepository {
|
|||
super(application);
|
||||
}
|
||||
|
||||
public LiveData<Item> getItemById(int id) {
|
||||
public LiveData<ItemWithFeed> getItemById(int id) {
|
||||
return database.itemDao().getItemById(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,18 +3,27 @@ package com.readrops.app;
|
|||
import android.arch.lifecycle.ViewModelProvider;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.design.widget.CollapsingToolbarLayout;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.readrops.app.database.entities.Item;
|
||||
import com.readrops.app.utils.GlideApp;
|
||||
import com.readrops.app.utils.ReadropsWebView;
|
||||
import com.readrops.app.utils.Utils;
|
||||
import com.readrops.readropslibrary.Utils.LibUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
@ -22,6 +31,9 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||
public class ItemActivity extends AppCompatActivity {
|
||||
|
||||
private ItemViewModel viewModel;
|
||||
private TextView title;
|
||||
private TextView author;
|
||||
private TextView readTime;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -39,7 +51,9 @@ public class ItemActivity extends AppCompatActivity {
|
|||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
CollapsingToolbarLayout toolbarLayout = findViewById(R.id.collapsing_layout);
|
||||
toolbarLayout.setTitle("");
|
||||
AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout);
|
||||
if (imageUrl == null)
|
||||
appBarLayout.setExpanded(false);
|
||||
|
||||
ImageView imageView = findViewById(R.id.collapsing_layout_image);
|
||||
|
||||
|
@ -47,11 +61,20 @@ public class ItemActivity extends AppCompatActivity {
|
|||
.load(imageUrl)
|
||||
.into(imageView);
|
||||
|
||||
WebView webView = findViewById(R.id.item_webview);
|
||||
ReadropsWebView 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);
|
||||
|
||||
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(ItemViewModel.class);
|
||||
viewModel.getItemById(itemId).observe(this, item -> {
|
||||
webView.loadData(item.getContent(), LibUtils.HTML_CONTENT_TYPE, "utf-8");
|
||||
viewModel.getItemById(itemId).observe(this, itemWithFeed -> {
|
||||
Item item = itemWithFeed.getItem();
|
||||
|
||||
toolbarLayout.setTitle(itemWithFeed.getFeedName());
|
||||
toolbar.setTitle(itemWithFeed.getFeedName());
|
||||
title.setText(item.getTitle());
|
||||
|
||||
webView.setItem(itemWithFeed);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.arch.lifecycle.LiveData;
|
|||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.readrops.app.database.Database;
|
||||
import com.readrops.app.database.ItemWithFeed;
|
||||
import com.readrops.app.database.entities.Item;
|
||||
|
||||
public class ItemViewModel extends AndroidViewModel {
|
||||
|
@ -18,7 +19,7 @@ public class ItemViewModel extends AndroidViewModel {
|
|||
repository = new BasedRepository(application);
|
||||
}
|
||||
|
||||
public LiveData<Item> getItemById(int id) {
|
||||
public LiveData<ItemWithFeed> getItemById(int id) {
|
||||
return repository.getItemById(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
|
|||
}
|
||||
}
|
||||
|
||||
dbItem.setDescription(Jsoup.parse(dbItem.getDescription()).text());
|
||||
dbItem.setCleanDescription(Jsoup.parse(dbItem.getDescription()).text());
|
||||
}
|
||||
|
||||
database.itemDao().insert(dbItem);
|
||||
|
|
|
@ -175,9 +175,9 @@ public class MainItemListAdapter extends ListAdapter<ItemWithFeed, MainItemListA
|
|||
date.setText(DateUtils.formatedDateByLocal(item.getPubDate()));
|
||||
feedName.setText(itemWithFeed.getFeedName());
|
||||
|
||||
if (item.getDescription() != null) {
|
||||
if (item.getCleanDescription() != null) {
|
||||
itemDescription.setVisibility(View.VISIBLE);
|
||||
itemDescription.setText(item.getDescription());
|
||||
itemDescription.setText(item.getCleanDescription());
|
||||
} else
|
||||
itemDescription.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public interface ItemDao {
|
|||
@Query("Select * from Item Order By pub_date DESC")
|
||||
LiveData<List<Item>> getAll();
|
||||
|
||||
@Query("Select Item.id, title, Item.description, image_link, pub_date, name, color, icon_url from Item Inner Join Feed on Item.feed_id = Feed.id Order By Item.id DESC")
|
||||
@Query("Select Item.id, title, clean_description, image_link, pub_date, name, color, icon_url from Item Inner Join Feed on Item.feed_id = Feed.id Order By Item.id DESC")
|
||||
LiveData<List<ItemWithFeed>> getAllItemWithFeeds();
|
||||
|
||||
@Query("Select case When :guid In (Select guid from Item) Then 'true' else 'false' end")
|
||||
|
@ -32,6 +32,6 @@ public interface ItemDao {
|
|||
@Insert
|
||||
void insertAll(List<Item> items);
|
||||
|
||||
@Query("Select * from Item Where id = :id")
|
||||
LiveData<Item> getItemById(int id);
|
||||
@Query("Select title, Item.description, content, pub_date, author, 0 as color, name from Item Inner Join Feed on Item.feed_id = Feed.id And Item.id = :id")
|
||||
LiveData<ItemWithFeed> getItemById(int id);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@ public class Item {
|
|||
|
||||
private String description;
|
||||
|
||||
@ColumnInfo(name = "clean_description")
|
||||
private String cleanDescription;
|
||||
|
||||
private String link;
|
||||
|
||||
@ColumnInfo(name = "image_link")
|
||||
|
@ -68,6 +71,14 @@ public class Item {
|
|||
this.description = description;
|
||||
}
|
||||
|
||||
public String getCleanDescription() {
|
||||
return cleanDescription;
|
||||
}
|
||||
|
||||
public void setCleanDescription(String cleanDescription) {
|
||||
this.cleanDescription = cleanDescription;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
@ -128,6 +139,13 @@ public class Item {
|
|||
return getImageLink() != null;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
if (content != null)
|
||||
return content;
|
||||
else
|
||||
return description;
|
||||
}
|
||||
|
||||
public static List<Item> itemsFromRSS(List<RSSItem> items, Feed feed) throws ParseException {
|
||||
List<Item> dbItems = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package com.readrops.app.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.readrops.app.R;
|
||||
import com.readrops.app.database.ItemWithFeed;
|
||||
import com.readrops.app.database.entities.Item;
|
||||
import com.readrops.readropslibrary.Utils.LibUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
public class ReadropsWebView extends WebView {
|
||||
|
||||
private ItemWithFeed itemWithFeed;
|
||||
|
||||
public ReadropsWebView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
public void setItem(ItemWithFeed itemWithFeed) {
|
||||
this.itemWithFeed = itemWithFeed;
|
||||
loadData(getText(), LibUtils.HTML_CONTENT_TYPE, "utf-8");
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
private void init() {
|
||||
WebSettings settings = getSettings();
|
||||
|
||||
settings.setJavaScriptEnabled(true);
|
||||
setBackgroundColor(getResources().getColor(R.color.colorBackground));
|
||||
}
|
||||
|
||||
private String getText() {
|
||||
Document document = Jsoup.parse(itemWithFeed.getItem().getText());
|
||||
|
||||
document.head().append("<style>img{display: inline;height: auto;max-width: 100%;}</style>");
|
||||
|
||||
return document.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,10 +1,13 @@
|
|||
package com.readrops.app.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -45,4 +48,11 @@ public final class Utils {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static int getDeviceWidth(Activity activity) {
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||||
|
||||
return displayMetrics.widthPixels;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
tools:context=".ItemActivity">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/app_bar_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/Widget.AppCompat.Light.ActionBar">
|
||||
|
@ -39,14 +40,56 @@
|
|||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/item_webview"
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/activity_item_details_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="6dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/activity_item_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/Base.TextAppearance.AppCompat.Headline"
|
||||
tools:text="This is a title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/activity_item_author"
|
||||
style="@style/Base.TextAppearance.AppCompat.Body1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/activity_item_title"
|
||||
android:layout_marginTop="8dp"
|
||||
android:visibility="gone"
|
||||
tools:text="By Santa Klaus" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/activity_item_readtime"
|
||||
style="@style/Base.TextAppearance.AppCompat.Body1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/activity_item_title"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginTop="8dp"
|
||||
android:visibility="gone"
|
||||
tools:text="3 minutes reading" />
|
||||
</RelativeLayout>
|
||||
|
||||
<com.readrops.app.utils.ReadropsWebView
|
||||
android:id="@+id/item_webview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/activity_item_details_layout"
|
||||
android:layout_marginTop="6dp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
||||
|
|
|
@ -16,4 +16,10 @@
|
|||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.Design.CollapsingToolbar.Expanded.Custom" parent="TextAppearance.Design.CollapsingToolbar.Expanded">
|
||||
<item name="android:textSize">12sp</item>
|
||||
<item name="android:color">@color/colorBackground</item>
|
||||
<item name="android:layout_margin">14dp</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue