添加 RefreshTextView
This commit is contained in:
1 parent
5cdc004829
commit
b0fc8f4c58
6 files changed
+298
-211
No files matched your search
Binary file not shown.
+55
-52
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2014 Hippo Seven
|
||||
<!--
|
||||
Copyright (C) 2014 Hippo Seven
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -12,66 +13,68 @@
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
-->
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/manga_detail_scrollview"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
android:layout_height="fill_parent"
|
||||
android:clipToPadding="false"
|
||||
android:fadingEdge="vertical"
|
||||
android:scrollbars="vertical" >
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/manga_detail_scrollview"
|
||||
<LinearLayout
|
||||
android:id="@+id/manga_detail"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:fadingEdge="vertical"
|
||||
android:scrollbars="vertical"
|
||||
android:clipToPadding="false" >
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/manga_detail"
|
||||
<include
|
||||
android:id="@+id/detail_header"
|
||||
layout="@layout/detail_header" />
|
||||
|
||||
<View
|
||||
android:id="@+id/colorful_bar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical" >
|
||||
android:layout_height="2.0dp" />
|
||||
|
||||
<include
|
||||
android:id="@+id/detail_header"
|
||||
layout="@layout/detail_header" />
|
||||
<!-- TODO maybe viewstub and is better -->
|
||||
|
||||
<View
|
||||
android:id="@+id/colorful_bar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2.0dp" />
|
||||
|
||||
<!-- TODO maybe viewstub and is better -->
|
||||
<include
|
||||
android:id="@+id/manga_detail_normal"
|
||||
layout="@layout/detail_normal"
|
||||
android:visibility="gone" />
|
||||
<include
|
||||
android:id="@+id/manga_detail_normal"
|
||||
layout="@layout/detail_normal"
|
||||
android:visibility="gone" />
|
||||
|
||||
<include
|
||||
android:id="@+id/manga_detail_offensive"
|
||||
layout="@layout/detail_offensive"
|
||||
android:visibility="gone" />
|
||||
<include
|
||||
android:id="@+id/manga_detail_offensive"
|
||||
layout="@layout/detail_offensive"
|
||||
android:visibility="gone" />
|
||||
|
||||
<include
|
||||
android:id="@+id/manga_detail_pining"
|
||||
layout="@layout/detail_pining"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
<include
|
||||
android:id="@+id/manga_detail_pining"
|
||||
layout="@layout/detail_pining"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/detail_wait"
|
||||
style="@style/ProgressBar.Large"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true" />
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/detail_refresh"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="@string/refresh"
|
||||
android:visibility="gone" />
|
||||
<ProgressBar
|
||||
android:id="@+id/detail_wait"
|
||||
style="@style/ProgressBar.Large"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
<Button
|
||||
android:id="@+id/detail_refresh"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/refresh"
|
||||
android:visibility="gone"
|
||||
android:layout_centerInParent="true" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
+4
-24
@@ -28,33 +28,13 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/wait"
|
||||
style="@style/ProgressBar.Large"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/refresh"
|
||||
<com.hippo.ehviewer.widget.RefreshTextView
|
||||
android:id="@+id/refresh_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="@string/refresh" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/sadpanda"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:src="@drawable/sadpanda" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/none"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="@string/none"
|
||||
android:gravity="center_horizontal"
|
||||
android:textColor="@android:color/holo_blue_dark"
|
||||
android:textSize="24sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -19,6 +19,18 @@ package com.hippo.ehviewer.ui;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.AppContext;
|
||||
import com.hippo.ehviewer.ImageLoader;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -32,51 +44,33 @@ import com.hippo.ehviewer.widget.HfListView;
|
||||
import com.hippo.ehviewer.widget.LoadImageView;
|
||||
import com.hippo.ehviewer.widget.OnFitSystemWindowsListener;
|
||||
import com.hippo.ehviewer.widget.RatingView;
|
||||
import com.hippo.ehviewer.widget.SuperToast;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import com.hippo.ehviewer.widget.RefreshTextView;
|
||||
|
||||
public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
implements HfListView.OnFooterRefreshListener,
|
||||
HfListView.OnRefreshListener {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = AbstractGalleryActivity.class.getSimpleName();
|
||||
|
||||
|
||||
private static final int REFRESH = 0x0;
|
||||
private static final int NEXT_PAGE = 0x1;
|
||||
private static final int PRE_PAGE = 0x2;
|
||||
private static final int SOMEWHERE = 0x3;
|
||||
|
||||
|
||||
protected AppContext mAppContext;
|
||||
protected EhClient mClient;
|
||||
private ImageLoader mImageLoader;
|
||||
|
||||
|
||||
private List<GalleryInfo> mGiList;
|
||||
private GalleryAdapter mGalleryAdapter;
|
||||
|
||||
|
||||
private RelativeLayout mMainView;
|
||||
private HfListView mHlv;
|
||||
private ListView mList;
|
||||
private ProgressBar mWaitProgressBar;
|
||||
private Button mFreshButton;
|
||||
private TextView mNoneTextView;
|
||||
private ImageView mSadPanda;
|
||||
|
||||
private RefreshTextView mRefreshTextView;
|
||||
|
||||
private long mTaskStamp;
|
||||
|
||||
|
||||
private int mFirstIndex;
|
||||
private int mLastIndex;
|
||||
private int mCurPage;
|
||||
@@ -90,27 +84,28 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
private String mTargetUrl;
|
||||
private int mPaddingTop;
|
||||
private boolean isFootRefresh = false;
|
||||
|
||||
|
||||
public void setNoneText(CharSequence text) {
|
||||
mNoneTextView.setText(text);
|
||||
mRefreshTextView.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setEmesg(text, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get url string for very page
|
||||
*
|
||||
*
|
||||
* @param targetPage
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getTargetUrl(int targetPage);
|
||||
protected abstract void doGetGallerys(String url, long taskStamp, OnGetListListener listener);
|
||||
|
||||
|
||||
private void getGallerys() {
|
||||
setGallerysLayout();
|
||||
|
||||
|
||||
mTaskStamp = System.currentTimeMillis();
|
||||
doGetGallerys(mTargetUrl, mTaskStamp, mListener);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if (mFirstPage != 0) {
|
||||
@@ -119,7 +114,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
refresh(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onFooterRefresh() {
|
||||
boolean re;
|
||||
@@ -128,58 +123,51 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
isFootRefresh = false;
|
||||
return re;
|
||||
}
|
||||
|
||||
|
||||
public void onlyShowList() {
|
||||
mHlv.setVisibility(View.VISIBLE);
|
||||
mWaitProgressBar.setVisibility(View.GONE);
|
||||
mFreshButton.setVisibility(View.GONE);
|
||||
mNoneTextView.setVisibility(View.GONE);
|
||||
mSadPanda.setVisibility(View.GONE);
|
||||
mRefreshTextView.setRefreshing(false);
|
||||
mRefreshTextView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
public void onlyShowNone() {
|
||||
mHlv.setVisibility(View.GONE);
|
||||
mWaitProgressBar.setVisibility(View.GONE);
|
||||
mFreshButton.setVisibility(View.GONE);
|
||||
mNoneTextView.setVisibility(View.VISIBLE);
|
||||
mSadPanda.setVisibility(View.GONE);
|
||||
mRefreshTextView.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setEmesg(R.string.none, false); // TODO
|
||||
}
|
||||
|
||||
|
||||
protected void firstTimeRefresh() {
|
||||
// set mHlv gone, make wait view show
|
||||
mHlv.setVisibility(View.GONE);
|
||||
|
||||
mRefreshTextView.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setRefreshing(true);
|
||||
|
||||
refresh(true);
|
||||
}
|
||||
|
||||
|
||||
private void setGallerysLayout() {
|
||||
if (mHlv.getVisibility() == View.VISIBLE) {
|
||||
if (!isFootRefresh)
|
||||
mHlv.setRefreshing(true);
|
||||
mWaitProgressBar.setVisibility(View.GONE);
|
||||
mFreshButton.setVisibility(View.GONE);
|
||||
mNoneTextView.setVisibility(View.GONE);
|
||||
mSadPanda.setVisibility(View.GONE);
|
||||
mRefreshTextView.setVisibility(View.GONE);
|
||||
} else {
|
||||
mHlv.setVisibility(View.GONE);
|
||||
mWaitProgressBar.setVisibility(View.VISIBLE);
|
||||
mFreshButton.setVisibility(View.GONE);
|
||||
mNoneTextView.setVisibility(View.GONE);
|
||||
mSadPanda.setVisibility(View.GONE);
|
||||
mRefreshTextView.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setRefreshing(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If can't refresh return false,
|
||||
* if force is true, must return true
|
||||
*
|
||||
*
|
||||
* @param force
|
||||
* @return
|
||||
*/
|
||||
protected boolean refresh(boolean force) {
|
||||
if (!force && isRefreshing())
|
||||
return false;
|
||||
|
||||
|
||||
mGetMode = REFRESH;
|
||||
mTargetPage = 0;
|
||||
mTargetUrl = getTargetUrl(mTargetPage);
|
||||
@@ -187,7 +175,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
getGallerys();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If force is true, will get page when refrshing
|
||||
* @param isKeepPosition
|
||||
@@ -199,7 +187,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
return false;
|
||||
if (mFirstPage == 0)
|
||||
return false;
|
||||
|
||||
|
||||
mGetMode = PRE_PAGE;
|
||||
mTargetPage = mFirstPage - 1;
|
||||
mTargetUrl = getTargetUrl(mTargetPage);
|
||||
@@ -207,7 +195,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
getGallerys();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If force is true, will get page when refrshing
|
||||
* @param isKeepPosition
|
||||
@@ -219,7 +207,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
return false;
|
||||
if (mLastPage >= mMaxPage - 1)
|
||||
return false;
|
||||
|
||||
|
||||
mGetMode = NEXT_PAGE;
|
||||
mTargetPage = mLastPage + 1;
|
||||
mTargetUrl = getTargetUrl(mTargetPage);
|
||||
@@ -227,13 +215,13 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
getGallerys();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected boolean getSomewhere(int page, boolean force) {
|
||||
if (!force && isRefreshing())
|
||||
return false;
|
||||
if (page >= mMaxPage || page < 0)
|
||||
return false;
|
||||
|
||||
|
||||
mGetMode = SOMEWHERE;
|
||||
mTargetPage = page;
|
||||
mTargetUrl = getTargetUrl(mTargetPage);
|
||||
@@ -241,13 +229,13 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
getGallerys();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean jumpTo(int page, boolean force) {
|
||||
if (!force && isRefreshing())
|
||||
return false;
|
||||
if (page >= mMaxPage || page < 0)
|
||||
return false;
|
||||
|
||||
|
||||
if (page >= mFirstPage && page <= mLastPage) {
|
||||
int position = (page - mFirstPage) * mItemPerPage;
|
||||
setListPosition(position);
|
||||
@@ -260,27 +248,24 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
return getSomewhere(page, force);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.list);
|
||||
|
||||
|
||||
mAppContext = (AppContext)getApplication();
|
||||
mClient = mAppContext.getEhClient();
|
||||
mImageLoader = ImageLoader.getInstance(this);
|
||||
|
||||
|
||||
mGiList = new ArrayList<GalleryInfo>();
|
||||
|
||||
|
||||
mMainView = (RelativeLayout)findViewById(R.id.main);
|
||||
mHlv = (HfListView)findViewById(R.id.list);
|
||||
mHlv.setAgainstToChildPadding(true);
|
||||
mList = mHlv.getListView();
|
||||
mWaitProgressBar = (ProgressBar)findViewById(R.id.wait);
|
||||
mFreshButton = (Button)findViewById(R.id.refresh);
|
||||
mNoneTextView = (TextView)findViewById(R.id.none);
|
||||
mSadPanda = (ImageView)findViewById(R.id.sadpanda);
|
||||
|
||||
mRefreshTextView = (RefreshTextView)findViewById(R.id.refresh_text);
|
||||
|
||||
FswView alignment = (FswView)findViewById(R.id.alignment);
|
||||
alignment.addOnFitSystemWindowsListener(
|
||||
new OnFitSystemWindowsListener() {
|
||||
@@ -292,7 +277,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
mList.getPaddingRight(), paddingBottom);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mHlv.setColorScheme(R.color.refresh_color_1,
|
||||
R.color.refresh_color_2,
|
||||
R.color.refresh_color_3,
|
||||
@@ -302,70 +287,69 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
mHlv.setFooterString(getString(R.string.footer_loading),
|
||||
getString(R.string.footer_loaded),
|
||||
getString(R.string.footer_fail));
|
||||
|
||||
|
||||
mGalleryAdapter = new GalleryAdapter();
|
||||
mList.setAdapter(mGalleryAdapter);
|
||||
mList.setOnScrollListener(new ScrollListener());
|
||||
mList.setDivider(null);
|
||||
mList.setSelector(new ColorDrawable(Color.TRANSPARENT));
|
||||
mList.setClipToPadding(false);
|
||||
|
||||
mFreshButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
mRefreshTextView.setOnRefreshListener(new RefreshTextView.OnRefreshListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mFreshButton.setVisibility(View.GONE);
|
||||
mWaitProgressBar.setVisibility(View.VISIBLE);
|
||||
public void onRefresh() {
|
||||
mRefreshTextView.setRefreshing(true);
|
||||
refresh(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return list view
|
||||
*/
|
||||
public ListView getListView() {
|
||||
return mList;
|
||||
}
|
||||
|
||||
|
||||
public RelativeLayout getMainView() {
|
||||
return mMainView;
|
||||
}
|
||||
|
||||
|
||||
public HfListView getHlv() {
|
||||
return mHlv;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return True if actionbar or footer is refreshing
|
||||
*/
|
||||
public boolean isRefreshing() {
|
||||
return mHlv.isRefreshing();
|
||||
}
|
||||
|
||||
|
||||
public boolean isGetGalleryOk() {
|
||||
return mHlv.getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
|
||||
public int getMaxPage() {
|
||||
return mMaxPage;
|
||||
}
|
||||
|
||||
|
||||
public int getCurPage() {
|
||||
return mCurPage;
|
||||
}
|
||||
|
||||
|
||||
public GalleryInfo getGalleryInfo(int position) {
|
||||
return mGiList.get(position);
|
||||
}
|
||||
|
||||
|
||||
public void setGalleryInfos(List<GalleryInfo> gis) {
|
||||
setGalleryInfos(gis, 1);
|
||||
}
|
||||
|
||||
|
||||
public void setGalleryInfos(List<GalleryInfo> gis, int maxPage) {
|
||||
mGiList = gis;
|
||||
mGalleryAdapter.notifyDataSetChanged();
|
||||
|
||||
|
||||
mFirstIndex = 0;
|
||||
mLastIndex = mGiList.size() - 1;
|
||||
mCurPage = 0;
|
||||
@@ -373,19 +357,19 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
mLastPage = 0;
|
||||
mMaxPage = maxPage;
|
||||
mItemPerPage = mGiList.size();
|
||||
|
||||
|
||||
if (mItemPerPage == 0)
|
||||
onlyShowNone();
|
||||
else
|
||||
onlyShowList();
|
||||
}
|
||||
|
||||
|
||||
public void notifyDataSetChanged() {
|
||||
mGalleryAdapter.notifyDataSetChanged();
|
||||
if (mGiList.isEmpty())
|
||||
onlyShowNone();
|
||||
}
|
||||
|
||||
|
||||
protected class GalleryAdapter extends BaseAdapter {
|
||||
@Override
|
||||
public int getCount() {
|
||||
@@ -399,7 +383,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
public String getCountStr(long count) {
|
||||
String str = null;
|
||||
if (count < 0) {
|
||||
@@ -424,7 +408,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
GalleryInfo gi= mGiList.get(position);
|
||||
@@ -434,7 +418,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
}
|
||||
final LoadImageView thumb = (LoadImageView)convertView.findViewById(R.id.cover);
|
||||
if (!String.valueOf(gi.gid).equals(thumb.getKey())) {
|
||||
|
||||
|
||||
thumb.setImageDrawable(null);
|
||||
thumb.setLoadInfo(gi.thumb, String.valueOf(gi.gid));
|
||||
mImageLoader.add(gi.thumb, String.valueOf(gi.gid),
|
||||
@@ -468,16 +452,16 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
} else {
|
||||
count.setVisibility(View.GONE);
|
||||
}
|
||||
return convertView;
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class ScrollListener implements ListView.OnScrollListener {
|
||||
@Override
|
||||
public void onScroll(AbsListView view, int firstVisibleItem,
|
||||
int visibleItemCount, int totalItemCount) {
|
||||
mHlv.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
|
||||
|
||||
|
||||
if (visibleItemCount < 2 || mItemPerPage == 0)
|
||||
return;
|
||||
if (mLastIndex == 0)
|
||||
@@ -487,7 +471,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
if (pageChanged == 0)
|
||||
pageChanged = (firstVisibleItem + visibleItemCount - mLastIndex - 1)
|
||||
/ mItemPerPage;
|
||||
|
||||
|
||||
if (pageChanged != 0) {
|
||||
mCurPage = mCurPage + pageChanged;
|
||||
mFirstIndex += pageChanged * mItemPerPage;
|
||||
@@ -506,46 +490,40 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setListPosition(int position) {
|
||||
if (position == 0)
|
||||
mList.setSelectionFromTop(position, mPaddingTop);
|
||||
else
|
||||
mList.setSelectionFromTop(position, 0);
|
||||
}
|
||||
|
||||
|
||||
public interface OnGetListListener {
|
||||
public void onSuccess(long taskStamp, List<GalleryInfo> gis, int itemPerPage, int maxPage);
|
||||
public void onFailure(long taskStamp, String eMsg);
|
||||
}
|
||||
|
||||
private OnGetListListener mListener = new OnGetListListener() {
|
||||
|
||||
private final OnGetListListener mListener = new OnGetListListener() {
|
||||
@Override
|
||||
public void onSuccess(long taskStamp,
|
||||
List<GalleryInfo> gis, int itemPerPage, int maxPage) {
|
||||
if (mTaskStamp != taskStamp)
|
||||
return;
|
||||
|
||||
|
||||
mMaxPage = maxPage;
|
||||
if (mItemPerPage < itemPerPage)
|
||||
mItemPerPage = itemPerPage;
|
||||
|
||||
mWaitProgressBar.setVisibility(View.GONE);
|
||||
mFreshButton.setVisibility(View.GONE);
|
||||
mSadPanda.setVisibility(View.GONE);
|
||||
|
||||
|
||||
if (mMaxPage == 0) {
|
||||
mNoneTextView.setVisibility(View.VISIBLE);
|
||||
mHlv.setVisibility(View.GONE);
|
||||
|
||||
onlyShowNone();
|
||||
|
||||
mFirstPage = 0;
|
||||
mLastPage = 0;
|
||||
mGiList = new ArrayList<GalleryInfo>();
|
||||
mGalleryAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
mNoneTextView.setVisibility(View.GONE);
|
||||
mHlv.setVisibility(View.VISIBLE);
|
||||
|
||||
onlyShowList();
|
||||
|
||||
switch (mGetMode) {
|
||||
case REFRESH:
|
||||
mFirstPage = 0;
|
||||
@@ -556,15 +534,15 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
mFirstIndex = 0;
|
||||
mLastIndex = gis.size() - 1;
|
||||
mCurPage = 0;
|
||||
|
||||
|
||||
setListPosition(0);
|
||||
break;
|
||||
|
||||
|
||||
case PRE_PAGE:
|
||||
mFirstPage--;
|
||||
mGiList.addAll(0, gis);
|
||||
mGalleryAdapter.notifyDataSetChanged();
|
||||
|
||||
|
||||
if (mIsKeepPosition) {
|
||||
mFirstIndex += gis.size();
|
||||
mLastIndex += gis.size();
|
||||
@@ -578,7 +556,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
setListPosition(0);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NEXT_PAGE:
|
||||
mLastPage++;
|
||||
mGiList.addAll(gis);
|
||||
@@ -590,7 +568,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
setListPosition(mFirstIndex);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case SOMEWHERE:
|
||||
mFirstPage = mTargetPage;
|
||||
mLastPage = mTargetPage;
|
||||
@@ -600,32 +578,28 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
|
||||
mFirstIndex = 0;
|
||||
mLastIndex = gis.size() - 1;
|
||||
mCurPage = mTargetPage;
|
||||
|
||||
|
||||
setListPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mHlv.setAnyRefreshComplete(true);
|
||||
}
|
||||
@Override
|
||||
public void onFailure(long taskStamp, String eMsg) {
|
||||
if (mTaskStamp != taskStamp)
|
||||
return;
|
||||
|
||||
mWaitProgressBar.setVisibility(View.GONE);
|
||||
mNoneTextView.setVisibility(View.GONE);
|
||||
mSadPanda.setVisibility(View.GONE);
|
||||
|
||||
|
||||
switch (mGetMode) {
|
||||
case REFRESH:
|
||||
mHlv.setVisibility(View.GONE);
|
||||
mFreshButton.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setVisibility(View.VISIBLE);
|
||||
mRefreshTextView.setEmesg(eMsg, true);
|
||||
break;
|
||||
default:
|
||||
mFreshButton.setVisibility(View.GONE);
|
||||
mRefreshTextView.setRefreshing(false);
|
||||
mRefreshTextView.setVisibility(View.GONE);
|
||||
}
|
||||
new SuperToast(AbstractGalleryActivity.this,
|
||||
eMsg, SuperToast.WARNING).show();
|
||||
mHlv.setAnyRefreshComplete(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -243,8 +243,10 @@ public class DetailSectionFragment extends Fragment
|
||||
mReadButton = (Button)mHeaderView.findViewById(R.id.detail_read);
|
||||
mRateButton = (Button)mHeaderView.findViewById(R.id.detail_do_rate);
|
||||
mColorfulBar = mRootView.findViewById(R.id.colorful_bar);
|
||||
|
||||
mWaitPb = (ProgressBar)mRootView.findViewById(R.id.detail_wait);
|
||||
mRefreshButton = (Button)mRootView.findViewById(R.id.detail_refresh);
|
||||
|
||||
mNormalView = (ViewGroup)mRootView.findViewById(R.id.manga_detail_normal);
|
||||
mOffensiveView = (ViewGroup)mRootView.findViewById(R.id.manga_detail_offensive);
|
||||
mPiningView = (ViewGroup)mRootView.findViewById(R.id.manga_detail_pining);
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.AppHandler;
|
||||
|
||||
// TODO add animation
|
||||
public class RefreshTextView extends TextView
|
||||
implements View.OnClickListener{
|
||||
|
||||
private volatile boolean mIsRefreshing = false;
|
||||
private volatile boolean mCanRefreshing;
|
||||
private OnRefreshListener mListener;
|
||||
|
||||
private static final String[] REFRESHING_STRINGS = {
|
||||
"(\uFA70π\uFA71)",
|
||||
"(\uFA71π\uFA70)"
|
||||
};
|
||||
|
||||
private static final int mSize = REFRESHING_STRINGS.length;
|
||||
|
||||
public RefreshTextView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public RefreshTextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public RefreshTextView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
Typeface type = Typeface.createFromAsset(getContext().getAssets(),"fonts/face.ttf");
|
||||
setTypeface(type);
|
||||
|
||||
setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void setOnRefreshListener(OnRefreshListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!mIsRefreshing && mCanRefreshing && mListener != null)
|
||||
mListener.onRefresh();
|
||||
}
|
||||
|
||||
public void setRefreshing(boolean refreshing) {
|
||||
if (mIsRefreshing == refreshing) {
|
||||
return;
|
||||
}
|
||||
|
||||
mIsRefreshing = refreshing;
|
||||
if (mIsRefreshing)
|
||||
new RefreshingThread().start();
|
||||
else
|
||||
setText(null);
|
||||
}
|
||||
|
||||
public void setEmesg(int resId, boolean canRefresh) {
|
||||
setEmesg(getContext().getString(resId), canRefresh);
|
||||
}
|
||||
|
||||
public void setEmesg(CharSequence emseg, boolean canRefresh) {
|
||||
mIsRefreshing = false;
|
||||
mCanRefreshing = canRefresh;
|
||||
|
||||
StringBuilder sb = new StringBuilder("==█ \n(>π<)\n\n");
|
||||
sb.append(emseg);
|
||||
if (mCanRefreshing)
|
||||
sb.append("点击重试"); // TODO;
|
||||
|
||||
setText(sb.toString());
|
||||
}
|
||||
|
||||
private class RefreshingThread extends Thread {
|
||||
int mIndex;
|
||||
@Override
|
||||
public void run() {
|
||||
mIndex = 0;
|
||||
while (mIsRefreshing) {
|
||||
AppHandler.getInstance().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mIsRefreshing)
|
||||
RefreshTextView.this.setText(REFRESHING_STRINGS[mIndex]);
|
||||
}
|
||||
});
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {}
|
||||
|
||||
if (++mIndex >= mSize)
|
||||
mIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnRefreshListener {
|
||||
void onRefresh();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user