Add date to the item activity layout and start adding a share button to the same activity (not finished though)

This commit is contained in:
Shinokuni 2019-02-11 17:38:54 +00:00
parent 62c3da343d
commit 385dc05691
9 changed files with 64 additions and 5 deletions

View File

@ -18,7 +18,7 @@
<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" />
<entry key="url" value="jar:file:/Applications/Android%20Studio.app/Contents/plugins/android/lib/android.jar!/images/material_design_icons/social/ic_share_black_24dp.xml" />
</map>
</option>
</PersistentState>
@ -29,7 +29,7 @@
<option name="values">
<map>
<entry key="color" value="ffffff" />
<entry key="outputName" value="ic_open_in_browser_white" />
<entry key="outputName" value="ic_share_white" />
<entry key="sourceFile" value="$USER_HOME$" />
</map>
</option>

View File

@ -9,11 +9,15 @@ 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.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.ShareActionProvider;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
@ -23,6 +27,7 @@ import android.widget.TextView;
import com.readrops.app.database.ItemWithFeed;
import com.readrops.app.database.entities.Item;
import com.readrops.app.utils.DateUtils;
import com.readrops.app.utils.GlideApp;
import com.readrops.app.utils.ReadropsWebView;
import com.readrops.app.utils.Utils;
@ -40,6 +45,7 @@ import okhttp3.internal.Util;
public class ItemActivity extends AppCompatActivity {
private ItemViewModel viewModel;
private TextView date;
private TextView title;
private TextView author;
private TextView readTime;
@ -56,6 +62,8 @@ public class ItemActivity extends AppCompatActivity {
private ItemWithFeed itemWithFeed;
private ShareActionProvider shareActionProvider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -78,6 +86,7 @@ public class ItemActivity extends AppCompatActivity {
View scrim = findViewById(R.id.collapsing_layout_scrim);
actionButton = findViewById(R.id.activity_item_fab);
webView = findViewById(R.id.item_webview);
date = findViewById(R.id.activity_item_date);
title = findViewById(R.id.activity_item_title);
author = findViewById(R.id.activity_item_author);
readTime = findViewById(R.id.activity_item_readtime);
@ -115,6 +124,8 @@ public class ItemActivity extends AppCompatActivity {
this.itemWithFeed = itemWithFeed;
Item item = itemWithFeed.getItem();
date.setText(DateUtils.formatedDateByLocal(item.getPubDate()));
if (item.getImageLink() == null)
toolbar.setTitle(itemWithFeed.getFeedName());
else
@ -157,4 +168,24 @@ public class ItemActivity extends AppCompatActivity {
webView.setItem(itemWithFeed, Utils.getDeviceWidth(this));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.item_menu, menu);
MenuItem menuItem = menu.findItem(R.id.item_share);
shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item_share:
//shareActionProvider.set
break;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -15,12 +15,11 @@ public final class DateUtils {
public static LocalDateTime stringToDateTime(String value, String pattern) throws ParseException {
DateFormat formatter = new SimpleDateFormat(pattern, Locale.ENGLISH);
return new LocalDateTime(formatter.parse(value));
}
public static String formatedDateByLocal(LocalDateTime dateTime) {
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
return df.format(dateTime.toDate());
}

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="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>

View File

@ -65,7 +65,6 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:padding="10dp">
<RelativeLayout
@ -73,10 +72,19 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/activity_item_date"
style="@style/Base.TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="10 february 2019" />
<TextView
android:id="@+id/activity_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/activity_item_date"
android:layout_marginTop="6dp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Headline"
tools:text="This is a title" />

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/item_share"
android:title="@string/share"
android:icon="@drawable/ic_share_white"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider" />
</menu>

View File

@ -20,5 +20,6 @@
<string name="read_time">%1$s min</string>
<string name="read_time_lower_than_1">Moins d\'une minute</string>
<string name="read_time_one_minute">1 min</string>
<string name="share">Partager</string>
</resources>

View File

@ -16,6 +16,7 @@
display: inline;
height: auto;
max-width: 100%%;
margin-top: 10px;
}
body {

View File

@ -22,4 +22,5 @@
<string name="read_time_lower_than_1">Less than a minute</string>
<string name="read_time_one_minute">1 min</string>
<string name="interpoint" translatable="false">·</string>
<string name="share">Share</string>
</resources>