Skip to content

Commit

Permalink
Current Status: ArticleList Layout optimised and made readable and be…
Browse files Browse the repository at this point in the history
…autiful
  • Loading branch information
thatsabhi22 committed May 29, 2020
1 parent 34bf72a commit 893f7d5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 52 deletions.
1 change: 1 addition & 0 deletions XYZReader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.squareup.okhttp3:okhttp:3.14.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation files('libs/volley.jar')
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
Expand All @@ -18,12 +20,14 @@
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xyzreader.R;
import com.example.xyzreader.data.ArticleLoader;
import com.example.xyzreader.data.ItemsContract;
import com.example.xyzreader.data.UpdaterService;
import com.squareup.picasso.Picasso;

import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -114,8 +118,8 @@ public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
adapter.setHasStableIds(true);
mRecyclerView.setAdapter(adapter);
int columnCount = getResources().getInteger(R.integer.list_column_count);
StaggeredGridLayoutManager sglm =
new StaggeredGridLayoutManager(columnCount, StaggeredGridLayoutManager.VERTICAL);
GridLayoutManager sglm =
new GridLayoutManager(this,columnCount);
mRecyclerView.setLayoutManager(sglm);
}

Expand Down Expand Up @@ -166,26 +170,11 @@ private Date parsePublishedDate() {
public void onBindViewHolder(ViewHolder holder, int position) {
mCursor.moveToPosition(position);
holder.titleView.setText(mCursor.getString(ArticleLoader.Query.TITLE));
Date publishedDate = parsePublishedDate();
if (!publishedDate.before(START_OF_EPOCH.getTime())) {

holder.subtitleView.setText(Html.fromHtml(
DateUtils.getRelativeTimeSpanString(
publishedDate.getTime(),
System.currentTimeMillis(), DateUtils.HOUR_IN_MILLIS,
DateUtils.FORMAT_ABBREV_ALL).toString()
+ "<br/>" + " by "
+ mCursor.getString(ArticleLoader.Query.AUTHOR)));
} else {
holder.subtitleView.setText(Html.fromHtml(
outputFormat.format(publishedDate)
+ "<br/>" + " by "
+ mCursor.getString(ArticleLoader.Query.AUTHOR)));
}
holder.thumbnailView.setImageUrl(
mCursor.getString(ArticleLoader.Query.THUMB_URL),
ImageLoaderHelper.getInstance(ArticleListActivity.this).getImageLoader());
holder.thumbnailView.setAspectRatio(mCursor.getFloat(ArticleLoader.Query.ASPECT_RATIO));
Picasso.get()
.load(mCursor.getString(ArticleLoader.Query.THUMB_URL))
.resize(450, 300)
.centerCrop()
.into(holder.thumbnailView);
}

@Override
Expand All @@ -195,15 +184,16 @@ public int getItemCount() {
}

public static class ViewHolder extends RecyclerView.ViewHolder {
public DynamicHeightNetworkImageView thumbnailView;
public ImageView thumbnailView;
public TextView titleView;
public TextView subtitleView;

public ViewHolder(View view) {
super(view);
thumbnailView = (DynamicHeightNetworkImageView) view.findViewById(R.id.thumbnail);
titleView = (TextView) view.findViewById(R.id.article_title);
subtitleView = (TextView) view.findViewById(R.id.article_subtitle);
thumbnailView = view.findViewById(R.id.thumbnail);
thumbnailView.setScaleType(ImageView.ScaleType.FIT_XY);
titleView = view.findViewById(R.id.article_title);
//subtitleView = (TextView) view.findViewById(R.id.article_subtitle);
}
}
}
4 changes: 2 additions & 2 deletions XYZReader/src/main/res/layout/fragment_article_detail.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<com.example.xyzreader.ui.DrawInsetsFrameLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
<com.example.xyzreader.ui.DrawInsetsFrameLayout
xmlns:android="http:https://schemas.android.com/apk/res/android"
android:id="@+id/draw_insets_frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand Down
37 changes: 13 additions & 24 deletions XYZReader/src/main/res/layout/list_item_article.xml
Original file line number Diff line number Diff line change
@@ -1,51 +1,40 @@
<androidx.cardview.widget.CardView xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground">
android:focusable="true">

<LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="wrap_content">

<!--suppress AndroidLintContentDescription -->
<com.example.xyzreader.ui.DynamicHeightNetworkImageView
<ImageView
android:id="@+id/thumbnail"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/photo_placeholder" />

<TextView
android:id="@+id/article_title"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end|bottom"
android:layout_alignParentBottom="true"
android:ellipsize="end"
android:maxLines="4"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingBottom="4dp"
android:textColor="@color/ltgray"
android:ellipsize="end"
android:maxLines="4" />
android:textColor="@color/white" />

<TextView
android:id="@+id/article_subtitle"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
android:textColor="#6000"
android:maxLines="2"
android:ellipsize="end" />
</LinearLayout>
</RelativeLayout>

</androidx.cardview.widget.CardView>
9 changes: 9 additions & 0 deletions XYZReader/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@
<color name="theme_primary_dark">#04561A</color>
<color name="theme_accent">#04561A</color>
<color name="ltgray">#ffe0e0e0</color>

<color name="colorPrimary">#607D8B</color>
<color name="colorPrimaryDark">#455A64</color>
<color name="colorAccent">#FF9800</color>

<color name="white">#FFFFFF</color>
<color name="grey">#424242</color>
<color name="black">#000000</color>

</resources>

0 comments on commit 893f7d5

Please sign in to comment.