From 893f7d5b35924231473781bd25773d4f52b363cd Mon Sep 17 00:00:00 2001 From: Abhijeet Singh Date: Fri, 29 May 2020 20:55:57 +0530 Subject: [PATCH] Current Status: ArticleList Layout optimised and made readable and beautiful --- XYZReader/build.gradle | 1 + .../xyzreader/ui/ArticleListActivity.java | 42 +++++++------------ .../res/layout/fragment_article_detail.xml | 4 +- .../src/main/res/layout/list_item_article.xml | 37 ++++++---------- XYZReader/src/main/res/values/colors.xml | 9 ++++ 5 files changed, 41 insertions(+), 52 deletions(-) diff --git a/XYZReader/build.gradle b/XYZReader/build.gradle index 3e60f77..c699518 100755 --- a/XYZReader/build.gradle +++ b/XYZReader/build.gradle @@ -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') } diff --git a/XYZReader/src/main/java/com/example/xyzreader/ui/ArticleListActivity.java b/XYZReader/src/main/java/com/example/xyzreader/ui/ArticleListActivity.java index d50b4cb..7ffece0 100755 --- a/XYZReader/src/main/java/com/example/xyzreader/ui/ArticleListActivity.java +++ b/XYZReader/src/main/java/com/example/xyzreader/ui/ArticleListActivity.java @@ -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; @@ -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; @@ -114,8 +118,8 @@ public void onLoadFinished(Loader 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); } @@ -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() - + "
" + " by " - + mCursor.getString(ArticleLoader.Query.AUTHOR))); - } else { - holder.subtitleView.setText(Html.fromHtml( - outputFormat.format(publishedDate) - + "
" + " 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 @@ -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); } } } diff --git a/XYZReader/src/main/res/layout/fragment_article_detail.xml b/XYZReader/src/main/res/layout/fragment_article_detail.xml index e5daf05..545ded8 100755 --- a/XYZReader/src/main/res/layout/fragment_article_detail.xml +++ b/XYZReader/src/main/res/layout/fragment_article_detail.xml @@ -1,5 +1,5 @@ - diff --git a/XYZReader/src/main/res/layout/list_item_article.xml b/XYZReader/src/main/res/layout/list_item_article.xml index 752f4f1..3c7829e 100755 --- a/XYZReader/src/main/res/layout/list_item_article.xml +++ b/XYZReader/src/main/res/layout/list_item_article.xml @@ -1,25 +1,23 @@ + android:focusable="true"> - + android:layout_height="wrap_content"> - + android:textColor="@color/white" /> - - + diff --git a/XYZReader/src/main/res/values/colors.xml b/XYZReader/src/main/res/values/colors.xml index 247642b..d6884d4 100755 --- a/XYZReader/src/main/res/values/colors.xml +++ b/XYZReader/src/main/res/values/colors.xml @@ -22,4 +22,13 @@ #04561A #04561A #ffe0e0e0 + + #607D8B + #455A64 + #FF9800 + + #FFFFFF + #424242 + #000000 +