Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding subheader support for last updated times #65

Merged
merged 2 commits into from

2 participants

@smpete

This was originally made to have the ability to show the last updated time underneath the the pull to refresh label. I decided to just make it a generic string for this pull request so the app can deal with formatting the date (or displaying something else). Here's the date code I was using just in case it would be preferable to restrict the user to a date:

 public void setUpdateTime(Date date) {
    if (date == null) {
        headerUpdateText.setVisibility(View.GONE);
    } else {
        headerUpdateText.setVisibility(View.VISIBLE);
        SimpleDateFormat df;
        Calendar currentCal = Calendar.getInstance();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        if (cal.get(Calendar.YEAR) == currentCal.get(Calendar.YEAR) 
                && cal.get(Calendar.DAY_OF_YEAR) == currentCal.get(Calendar.DAY_OF_YEAR)) {
            df = new SimpleDateFormat("'<b>LAST UPDATED</b> TODAY AT' hh:mm a");
        } else {
            df = new SimpleDateFormat("'<b>LAST UPDATED</b>' M/d/yy 'AT' hh:mm a");
        }

        headerUpdateText.setText(Html.fromHtml(df.format(date)));
    }
} 

I also changed all the TextView.setText(String s) calls in the LoadingLayout to call Html.fromHtml(String s) on the text passed. This will allow part of the string to be bold, italic, etc.

Both of these additions should have no different effect if they are not used, it should behave as normal.

Peter Elliott added some commits
Peter Elliott Adding sub header functionality for displaying last updated time. Kee…
…p it generic and pass a string so the app can easily format the date however it wants to.
1dbe652
Peter Elliott Set header text from html to allow for bolding of parts of the string bab19e1
@chrisbanes chrisbanes merged commit e403f03 into chrisbanes:dev
@chrisbanes chrisbanes referenced this pull request from a commit
@chrisbanes Tweak Peter Elliott's Pull #65 886b544
@chrisbanes
Owner

Thanks for this. I tweaked your code a bit in 886b544, but it's working great.

@cfgxy cfgxy referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ncoolz ncoolz referenced this pull request from a commit in naver/android-pull-to-refresh
@chrisbanes Tweak Peter Elliott's Pull #65 ea2892f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 20, 2012
  1. Adding sub header functionality for displaying last updated time. Kee…

    Peter Elliott authored
    …p it generic and pass a string so the app can easily format the date however it wants to.
This page is out of date. Refresh to see the latest.
View
33 library/res/layout/pull_to_refresh_header.xml
@@ -5,15 +5,32 @@
android:paddingTop="10dp"
android:paddingBottom="10dip">
- <TextView
- android:id="@+id/pull_to_refresh_text"
- android:text="@string/pull_to_refresh_pull_label"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:textStyle="bold"
+ <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_centerInParent="true" />
-
+ android:layout_centerInParent="true"
+ android:orientation="vertical"
+ android:gravity="center">
+
+ <TextView
+ android:id="@+id/pull_to_refresh_text"
+ android:text="@string/pull_to_refresh_pull_label"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textStyle="bold"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerInParent="true" />
+
+ <TextView
+ android:id="@+id/pull_to_refresh_sub_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textSize="11sp"
+ android:visibility="gone" />
+
+ </LinearLayout>
+
<ProgressBar
android:id="@+id/pull_to_refresh_progress"
android:indeterminate="true"
@@ -33,6 +50,4 @@
android:layout_marginRight="20dip"
android:layout_centerVertical="true" />
-
-
</RelativeLayout>
View
4 library/src/com/handmark/pulltorefresh/library/PullToRefreshBase.java
@@ -855,4 +855,8 @@ private boolean isReadyForPull() {
public void setLongClickable(boolean longClickable) {
getRefreshableView().setLongClickable(longClickable);
}
+
+ public void setSubHeaderText(String text) {
+ mHeaderLayout.setSubHeaderText(text);
+ }
}
View
29 library/src/com/handmark/pulltorefresh/library/internal/LoadingLayout.java
@@ -3,6 +3,8 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
+import android.text.Html;
+import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -25,6 +27,7 @@
private final ImageView mHeaderImage;
private final ProgressBar mHeaderProgress;
private final TextView mHeaderText;
+ private final TextView mSubHeaderText;
private String mPullLabel;
private String mRefreshingLabel;
@@ -37,6 +40,7 @@ public LoadingLayout(Context context, final int mode, String releaseLabel, Strin
super(context);
ViewGroup header = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header, this);
mHeaderText = (TextView) header.findViewById(R.id.pull_to_refresh_text);
+ mSubHeaderText = (TextView) header.findViewById(R.id.pull_to_refresh_sub_text);
mHeaderImage = (ImageView) header.findViewById(R.id.pull_to_refresh_image);
mHeaderProgress = (ProgressBar) header.findViewById(R.id.pull_to_refresh_progress);
@@ -74,13 +78,18 @@ public LoadingLayout(Context context, final int mode, String releaseLabel, Strin
}
public void reset() {
- mHeaderText.setText(mPullLabel);
+ mHeaderText.setText(Html.fromHtml(mPullLabel));
mHeaderImage.setVisibility(View.VISIBLE);
mHeaderProgress.setVisibility(View.GONE);
+ if (TextUtils.isEmpty(mSubHeaderText.getText())) {
+ mSubHeaderText.setVisibility(View.GONE);
+ } else {
+ mSubHeaderText.setVisibility(View.VISIBLE);
+ }
}
public void releaseToRefresh() {
- mHeaderText.setText(mReleaseLabel);
+ mHeaderText.setText(Html.fromHtml(mReleaseLabel));
mHeaderImage.clearAnimation();
mHeaderImage.startAnimation(mRotateAnimation);
}
@@ -90,10 +99,11 @@ public void setPullLabel(String pullLabel) {
}
public void refreshing() {
- mHeaderText.setText(mRefreshingLabel);
+ mHeaderText.setText(Html.fromHtml(mRefreshingLabel));
mHeaderImage.clearAnimation();
mHeaderImage.setVisibility(View.INVISIBLE);
mHeaderProgress.setVisibility(View.VISIBLE);
+ mSubHeaderText.setVisibility(View.GONE);
}
public void setRefreshingLabel(String refreshingLabel) {
@@ -105,13 +115,22 @@ public void setReleaseLabel(String releaseLabel) {
}
public void pullToRefresh() {
- mHeaderText.setText(mPullLabel);
+ mHeaderText.setText(Html.fromHtml(mPullLabel));
mHeaderImage.clearAnimation();
mHeaderImage.startAnimation(mResetRotateAnimation);
}
public void setTextColor(int color) {
mHeaderText.setTextColor(color);
+ mSubHeaderText.setTextColor(color);
+ }
+
+ public void setSubHeaderText(String text) {
+ mSubHeaderText.setText(Html.fromHtml(text));
+ if (TextUtils.isEmpty(text)) {
+ mSubHeaderText.setVisibility(View.GONE);
+ } else {
+ mSubHeaderText.setVisibility(View.VISIBLE);
+ }
}
-
}
Something went wrong with that request. Please try again.