Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ captures/

# Keystore files
*.jks
/.idea/
39 changes: 25 additions & 14 deletions XYZReader/build.gradle
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
buildscript {
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:4.0.1'
}
}
apply plugin: 'com.android.application'

repositories {
mavenCentral()
jcenter()
}

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 29

defaultConfig {
minSdkVersion 19
targetSdkVersion 25
targetSdkVersion 29
}

buildFeatures {
viewBinding true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile "com.android.support:support-v4:$androidSupportVersion"
compile "com.android.support:support-v13:$androidSupportVersion"
compile "com.android.support:appcompat-v7:$androidSupportVersion"
compile "com.android.support:palette-v7:$androidSupportVersion"
compile "com.android.support:recyclerview-v7:$androidSupportVersion"
compile "com.android.support:cardview-v7:$androidSupportVersion"
compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile files('libs/volley.jar')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.palette:palette:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
implementation files('libs/volley.jar')
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
11 changes: 9 additions & 2 deletions XYZReader/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
android:label="@string/app_name"
android:theme="@style/Theme.Bacon">

<uses-library android:name="org.apache.http.legacy" android:required="false" />

<activity
android:name=".ui.ArticleListActivity"
android:label="@string/app_name">
android:label="@string/app_name"
android:theme="@style/Theme.Bacon">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -25,7 +28,8 @@

<activity
android:name=".ui.ArticleDetailActivity"
android:parentActivityName=".ui.ArticleListActivity">
android:parentActivityName=".ui.ArticleListActivity"
android:theme="@style/Theme.Bacon.Detail">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
Expand All @@ -42,6 +46,9 @@
<provider android:name=".data.ItemsProvider"
android:authorities="com.example.xyzreader"
android:exported="false" />
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v13.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;

import androidx.appcompat.app.AppCompatActivity;
import androidx.legacy.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.xyzreader.R;
import com.example.xyzreader.data.ArticleLoader;
Expand All @@ -23,7 +23,7 @@
/**
* An activity representing a single Article detail screen, letting you swipe between articles.
*/
public class ArticleDetailActivity extends ActionBarActivity
public class ArticleDetailActivity extends AppCompatActivity
implements LoaderManager.LoaderCallbacks<Cursor> {

private Cursor mCursor;
Expand Down Expand Up @@ -87,15 +87,12 @@ public void onClick(View view) {
});

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mUpButtonContainer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
view.onApplyWindowInsets(windowInsets);
mTopInset = windowInsets.getSystemWindowInsetTop();
mUpButtonContainer.setTranslationY(mTopInset);
updateUpButtonPosition();
return windowInsets;
}
mUpButtonContainer.setOnApplyWindowInsetsListener((view, windowInsets) -> {
view.onApplyWindowInsets(windowInsets);
mTopInset = windowInsets.getSystemWindowInsetTop();
mUpButtonContainer.setTranslationY(mTopInset);
updateUpButtonPosition();
return windowInsets;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,29 @@
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

import android.os.Bundle;
import android.support.v4.app.ShareCompat;
import android.support.v7.graphics.Palette;
import android.text.Html;
import android.text.format.DateUtils;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.app.ShareCompat;
import androidx.palette.graphics.Palette;

import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.example.xyzreader.R;
import com.example.xyzreader.data.ArticleLoader;
import com.example.xyzreader.databinding.FragmentArticleDetailBinding;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

/**
* A fragment representing a single Article detail screen. This fragment is
Expand All @@ -46,17 +43,14 @@ public class ArticleDetailFragment extends Fragment implements
public static final String ARG_ITEM_ID = "item_id";
private static final float PARALLAX_FACTOR = 1.25f;

private FragmentArticleDetailBinding binding;

private Cursor mCursor;
private long mItemId;
private View mRootView;
private int mMutedColor = 0xFF333333;
private ObservableScrollView mScrollView;
private DrawInsetsFrameLayout mDrawInsetsFrameLayout;
private ColorDrawable mStatusBarColorDrawable;

private int mTopInset;
private View mPhotoContainerView;
private ImageView mPhotoView;
private int mScrollY;
private boolean mIsCard = false;
private int mStatusBarFullOpacityBottom;
Expand Down Expand Up @@ -114,50 +108,33 @@ public void onActivityCreated(Bundle savedInstanceState) {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.fragment_article_detail, container, false);
mDrawInsetsFrameLayout = (DrawInsetsFrameLayout)
mRootView.findViewById(R.id.draw_insets_frame_layout);
mDrawInsetsFrameLayout.setOnInsetsCallback(new DrawInsetsFrameLayout.OnInsetsCallback() {
@Override
public void onInsetsChanged(Rect insets) {
mTopInset = insets.top;
}
});
binding = FragmentArticleDetailBinding.inflate(inflater, container, false);

mScrollView = (ObservableScrollView) mRootView.findViewById(R.id.scrollview);
mScrollView.setCallbacks(new ObservableScrollView.Callbacks() {
@Override
public void onScrollChanged() {
mScrollY = mScrollView.getScrollY();
getActivityCast().onUpButtonFloorChanged(mItemId, ArticleDetailFragment.this);
mPhotoContainerView.setTranslationY((int) (mScrollY - mScrollY / PARALLAX_FACTOR));
updateStatusBar();
}
});
binding.drawInsetsFrameLayout.setOnInsetsCallback(insets -> mTopInset = insets.top);

mPhotoView = (ImageView) mRootView.findViewById(R.id.photo);
mPhotoContainerView = mRootView.findViewById(R.id.photo_container);
binding.scrollview.setCallbacks(() -> {
mScrollY = binding.scrollview.getScrollY();
getActivityCast().onUpButtonFloorChanged(mItemId, ArticleDetailFragment.this);
binding.photoContainer.setTranslationY((int) (mScrollY - mScrollY / PARALLAX_FACTOR));
updateStatusBar();
});

mStatusBarColorDrawable = new ColorDrawable(0);

mRootView.findViewById(R.id.share_fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
binding.shareFab.setOnClickListener(view ->
startActivity(Intent.createChooser(ShareCompat.IntentBuilder.from(getActivity())
.setType("text/plain")
.setText("Some sample text")
.getIntent(), getString(R.string.action_share)));
}
});
.getIntent(), getString(R.string.action_share))));

bindViews();
updateStatusBar();
return mRootView;
return binding.getRoot();
}

private void updateStatusBar() {
int color = 0;
if (mPhotoView != null && mTopInset != 0 && mScrollY > 0) {
if (mTopInset != 0 && mScrollY > 0) {
float f = progress(mScrollY,
mStatusBarFullOpacityBottom - mTopInset * 3,
mStatusBarFullOpacityBottom - mTopInset);
Expand All @@ -167,7 +144,7 @@ private void updateStatusBar() {
(int) (Color.blue(mMutedColor) * 0.9));
}
mStatusBarColorDrawable.setColor(color);
mDrawInsetsFrameLayout.setInsetBackground(mStatusBarColorDrawable);
binding.drawInsetsFrameLayout.setInsetBackground(mStatusBarColorDrawable);
}

static float progress(float v, float min, float max) {
Expand Down Expand Up @@ -196,26 +173,19 @@ private Date parsePublishedDate() {
}

private void bindViews() {
if (mRootView == null) {
return;
}

TextView titleView = (TextView) mRootView.findViewById(R.id.article_title);
TextView bylineView = (TextView) mRootView.findViewById(R.id.article_byline);
bylineView.setMovementMethod(new LinkMovementMethod());
TextView bodyView = (TextView) mRootView.findViewById(R.id.article_body);

binding.articleByline.setMovementMethod(new LinkMovementMethod());

bodyView.setTypeface(Typeface.createFromAsset(getResources().getAssets(), "Rosario-Regular.ttf"));
//Replaced with downloadable font
//bodyView.setTypeface(Typeface.createFromAsset(getResources().getAssets(), "Rosario-Regular.ttf"));

if (mCursor != null) {
mRootView.setAlpha(0);
mRootView.setVisibility(View.VISIBLE);
mRootView.animate().alpha(1);
titleView.setText(mCursor.getString(ArticleLoader.Query.TITLE));
binding.getRoot().setAlpha(0);
binding.getRoot().setVisibility(View.VISIBLE);
binding.getRoot().animate().alpha(1);
binding.articleTitle.setText(mCursor.getString(ArticleLoader.Query.TITLE));
Date publishedDate = parsePublishedDate();
if (!publishedDate.before(START_OF_EPOCH.getTime())) {
bylineView.setText(Html.fromHtml(
binding.articleByline.setText(Html.fromHtml(
DateUtils.getRelativeTimeSpanString(
publishedDate.getTime(),
System.currentTimeMillis(), DateUtils.HOUR_IN_MILLIS,
Expand All @@ -226,13 +196,13 @@ private void bindViews() {

} else {
// If date is before 1902, just show the string
bylineView.setText(Html.fromHtml(
binding.articleByline.setText(Html.fromHtml(
outputFormat.format(publishedDate) + " by <font color='#ffffff'>"
+ mCursor.getString(ArticleLoader.Query.AUTHOR)
+ "</font>"));

}
bodyView.setText(Html.fromHtml(mCursor.getString(ArticleLoader.Query.BODY).replaceAll("(\r\n|\n)", "<br />")));
binding.articleBody.setText(Html.fromHtml(mCursor.getString(ArticleLoader.Query.BODY).replaceAll("(\r\n|\n)", "<br />")));
ImageLoaderHelper.getInstance(getActivity()).getImageLoader()
.get(mCursor.getString(ArticleLoader.Query.PHOTO_URL), new ImageLoader.ImageListener() {
@Override
Expand All @@ -241,9 +211,8 @@ public void onResponse(ImageLoader.ImageContainer imageContainer, boolean b) {
if (bitmap != null) {
Palette p = Palette.generate(bitmap, 12);
mMutedColor = p.getDarkMutedColor(0xFF333333);
mPhotoView.setImageBitmap(imageContainer.getBitmap());
mRootView.findViewById(R.id.meta_bar)
.setBackgroundColor(mMutedColor);
binding.photo.setImageBitmap(imageContainer.getBitmap());
binding.metaBar.setBackgroundColor(mMutedColor);
updateStatusBar();
}
}
Expand All @@ -254,10 +223,10 @@ public void onErrorResponse(VolleyError volleyError) {
}
});
} else {
mRootView.setVisibility(View.GONE);
titleView.setText("N/A");
bylineView.setText("N/A" );
bodyView.setText("N/A");
binding.getRoot().setVisibility(View.GONE);
binding.articleTitle.setText("N/A");
binding.articleByline.setText("N/A" );
binding.articleBody.setText("N/A");
}
}

Expand Down Expand Up @@ -292,13 +261,13 @@ public void onLoaderReset(Loader<Cursor> cursorLoader) {
}

public int getUpButtonFloor() {
if (mPhotoContainerView == null || mPhotoView.getHeight() == 0) {
if (binding == null || binding.photo.getHeight() == 0) {
return Integer.MAX_VALUE;
}

// account for parallax
return mIsCard
? (int) mPhotoContainerView.getTranslationY() + mPhotoView.getHeight() - mScrollY
: mPhotoView.getHeight() - mScrollY;
? (int) binding.photoContainer.getTranslationY() + binding.photo.getHeight() - mScrollY
: binding.photo.getHeight() - mScrollY;
}
}
Loading