完善 Activity 跳转

This commit is contained in:
seven332 committed 2014-06-28 20:24:18 +08:00
1 parent db3fe7e446
commit 6b7f314e9f
8 files changed
+192 -142

No files matched your search

+2 -1
View File
@@ -65,7 +65,8 @@
android:name="com.hippo.ehviewer.ui.MangaDetailActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|adjustUnspecified|stateHidden"
android:configChanges="orientation|screenSize" >
android:configChanges="orientation|screenSize"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
+2 -1
View File
@@ -72,7 +72,8 @@
android:layout_alignParentBottom="true"
android:layout_marginBottom="10.0dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp" />
android:layout_marginRight="12dp"
android:background="@android:color/transparent" />
<!-- Need to make button do rate and read the same width
Disable is before make sure it is normal -->
+5 -3
View File
@@ -19,6 +19,9 @@ package com.hippo.ehviewer;
import java.io.File;
import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -35,6 +38,7 @@ import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.widget.LoadImageView;
import android.app.Application;
import android.widget.ScrollView;
public class AppContext extends Application implements UncaughtExceptionHandler {
@@ -75,9 +79,7 @@ public class AppContext extends Application implements UncaughtExceptionHandler
} else {
try {
nomedia.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {}
}
}
@@ -40,6 +40,8 @@ public class GalleryDetail extends GalleryInfo{
public PreviewList[] previewLists;
public List<Comment> comments;
public GalleryDetail() {}
public GalleryDetail(GalleryInfo galleryInfo) {
gid = galleryInfo.gid;
token = galleryInfo.token;
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.ui;
import java.util.List;
import com.hippo.ehviewer.ListUrls;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.data.Comment;
import com.hippo.ehviewer.widget.DialogBuilder;
@@ -149,12 +150,12 @@ public class CommentsSectionFragment extends Fragment
break;
case 1:
Intent intent = new Intent();
intent.putExtra(MangaListActivity.KEY_MODE,
MangaListActivity.MODE_UPLOADER);
intent.putExtra(MangaListActivity.KEY_UPLOADER, c.user);
mActivity.setResult(Activity.RESULT_OK, intent);
mActivity.finish();
Intent intent = new Intent(mActivity, MangaListActivity.class);
intent.setAction(MangaListActivity.ACTION_GALLERY_LIST);
intent.putExtra(MangaListActivity.KEY_MODE, ListUrls.POPULAR);
intent.putExtra(MangaListActivity.KEY_UPLOADER, c.user);
startActivity(intent);
break;
}
}
@@ -24,11 +24,11 @@ import java.util.Map.Entry;
import com.hippo.ehviewer.AppContext;
import com.hippo.ehviewer.ImageLoader;
import com.hippo.ehviewer.ListUrls;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.data.Comment;
import com.hippo.ehviewer.data.Data;
import com.hippo.ehviewer.data.GalleryDetail;
import com.hippo.ehviewer.data.GalleryInfo;
import com.hippo.ehviewer.data.PreviewList;
import com.hippo.ehviewer.ehclient.DetailParser;
import com.hippo.ehviewer.ehclient.EhClient;
@@ -73,12 +73,12 @@ import android.widget.RatingBar;
import android.widget.ScrollView;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;
import android.widget.ViewSwitcher;
public class DetailSectionFragment extends Fragment
implements View.OnClickListener, PreviewList.PreviewHolder,
View.OnLayoutChangeListener {
private static final String TAG = "DetailSectionFragment";
View.OnLayoutChangeListener, ViewSwitcher.ViewFactory {
private static final String TAG = DetailSectionFragment.class.getSimpleName();
private AppContext mAppContext;
private MangaDetailActivity mActivity;
@@ -89,6 +89,10 @@ public class DetailSectionFragment extends Fragment
private View mRootView;
private ScrollView mScrollView;
private LoadImageView mThumb;
private TextView mTitle;
private TextView mUploader;
private TextView mCategory;
private Button mReadButton;
private Button mRateButton;
private ProgressBar mWaitPb;
@@ -115,6 +119,7 @@ public class DetailSectionFragment extends Fragment
private int mCurPage;
private boolean mShowPreview = false;
private boolean isSetViewFactory = false;
private ShapeDrawable getArrowShapeDrawable(int color, boolean isToLeft) {
Path path = new Path();
@@ -169,6 +174,65 @@ public class DetailSectionFragment extends Fragment
}
@Override
public View makeView() {
LayoutInflater inflater = LayoutInflater.from(mActivity);
return inflater.inflate(R.layout.detail_avg_text, null);
}
public void handleDetail(GalleryDetail gd) {
mGalleryDetail = gd;
mUrl = EhClient.getDetailUrl(
mGalleryDetail.gid, mGalleryDetail.token);
mThumb.setImageDrawable(null);
if (mGalleryDetail.thumb != null) {
mThumb.setLoadInfo(mGalleryDetail.thumb, String.valueOf(mGalleryDetail.gid));
ImageLoader.getInstance(mActivity).add(mGalleryDetail.thumb, String.valueOf(mGalleryDetail.gid),
new LoadImageView.SimpleImageGetListener(mThumb).setTransitabled(false));
mTitle.setText(mGalleryDetail.title);
mUploader.setText(mGalleryDetail.uploader);
mCategory.setText(Ui.getCategoryText(mGalleryDetail.category));
mCategory.setBackgroundColor(Ui.getCategoryColor(mGalleryDetail.category));
} else {
mThumb.setLoadInfo(null, null);
mTitle.setText(null);
mUploader.setText(null);
mCategory.setText(null);
mCategory.setBackgroundColor(0);
}
// Make rate and read button same width
// Disable them for temp
Ui.measureView(mReadButton);
Ui.measureView(mRateButton);
int readbw = mReadButton.getMeasuredWidth();
int ratebw = mRateButton.getMeasuredWidth();
if (readbw > ratebw) {
mRateButton.setWidth(readbw);
} else if (ratebw > readbw) {
mReadButton.setWidth(ratebw);
}
mReadButton.setEnabled(false);
mRateButton.setEnabled(false);
if (mGalleryDetail.size == null) {
mRefreshButton.setVisibility(View.GONE);
mWaitPb.setVisibility(View.VISIBLE);
mNormalView.setVisibility(View.GONE);
mOffensiveView.setVisibility(View.GONE);
mPiningView.setVisibility(View.GONE);
mClient.getGDetail(mUrl, mGalleryDetail, new GDetailGetListener());
} else {
mRefreshButton.setVisibility(View.GONE);
mWaitPb.setVisibility(View.GONE);
mNormalView.setVisibility(View.VISIBLE);
mOffensiveView.setVisibility(View.GONE);
mPiningView.setVisibility(View.GONE);
layout(mGalleryDetail);
}
}
@SuppressWarnings("deprecation")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@@ -178,15 +242,13 @@ public class DetailSectionFragment extends Fragment
mClient = mAppContext.getEhClient();
mData = mAppContext.getData();
GalleryInfo galleryInfo = mActivity.getGalleryInfo();
mActivity.mGalleryDetail = new GalleryDetail(galleryInfo);
mGalleryDetail = mActivity.mGalleryDetail;
mUrl = EhClient.getDetailUrl(
mGalleryDetail.gid, mGalleryDetail.token);
mRootView = inflater.inflate(
R.layout.detail, container, false);
mScrollView = (ScrollView)mRootView.findViewById(R.id.manga_detail_scrollview);
mThumb = (LoadImageView)mRootView.findViewById(R.id.detail_cover);
mTitle = (TextView)mRootView.findViewById(R.id.detail_title);
mUploader = (TextView)mRootView.findViewById(R.id.detail_uploader);
mCategory = (TextView)mRootView.findViewById(R.id.detail_category);
mReadButton = (Button)mRootView.findViewById(R.id.detail_read);
mRateButton = (Button)mRootView.findViewById(R.id.detail_do_rate);
mWaitPb = (ProgressBar)mRootView.findViewById(R.id.detail_wait);
@@ -253,37 +315,8 @@ public class DetailSectionFragment extends Fragment
mScrollView.addOnLayoutChangeListener(this);
LoadImageView thumb = (LoadImageView)mRootView.findViewById(R.id.detail_cover);
thumb.setImageDrawable(null);
thumb.setLoadInfo(mGalleryDetail.thumb, String.valueOf(mGalleryDetail.gid));
ImageLoader.getInstance(mActivity).add(mGalleryDetail.thumb, String.valueOf(mGalleryDetail.gid),
new LoadImageView.SimpleImageGetListener(thumb).setTransitabled(false));
TextView title = (TextView)mRootView.findViewById(R.id.detail_title);
title.setText(mGalleryDetail.title);
TextView uploader = (TextView)mRootView.findViewById(R.id.detail_uploader);
uploader.setText(mGalleryDetail.uploader);
TextView category = (TextView)mRootView.findViewById(R.id.detail_category);
category.setText(Ui.getCategoryText(mGalleryDetail.category));
category.setBackgroundColor(Ui.getCategoryColor(mGalleryDetail.category));
// Make rate and read button same width
// Disable them for temp
Ui.measureView(mReadButton);
Ui.measureView(mRateButton);
int readbw = mReadButton.getMeasuredWidth();
int ratebw = mRateButton.getMeasuredWidth();
if (readbw > ratebw) {
mRateButton.setWidth(readbw);
} else if (ratebw > readbw) {
mReadButton.setWidth(ratebw);
}
mReadButton.setEnabled(false);
mRateButton.setEnabled(false);
mClient.getGDetail(mUrl, mGalleryDetail, new GDetailGetListener());
// Load first detail
mActivity.loadDetail();
return mRootView;
}
@@ -446,13 +479,13 @@ public class DetailSectionFragment extends Fragment
@Override
public void onClick(View v) {
mTagDialog.dismiss();
Intent intent = new Intent();
intent.putExtra(MangaListActivity.KEY_MODE,
MangaListActivity.MODE_TAG);
intent.putExtra(MangaListActivity.KEY_GROUP, groupName);
intent.putExtra(MangaListActivity.KEY_TAG, tagText);
mActivity.setResult(Activity.RESULT_OK, intent);
mActivity.finish();
Intent intent = new Intent(mActivity,MangaListActivity.class);
intent.setAction(MangaListActivity.ACTION_GALLERY_LIST);
intent.putExtra(MangaListActivity.KEY_MODE,
ListUrls.TAG);
intent.putExtra(MangaListActivity.KEY_TAG, groupName + ":" + tagText);
startActivity(intent);
}
});
mTagDialog = new ButtonsDialogBuilder(mActivity).setTitle(tagText)
@@ -515,6 +548,17 @@ public class DetailSectionFragment extends Fragment
mKnownButton.setOnClickListener(this);
}
else {
// Set unset info
if (mThumb.getUrl() == null) {
mThumb.setLoadInfo(mGalleryDetail.thumb, String.valueOf(mGalleryDetail.gid));
ImageLoader.getInstance(mActivity).add(mGalleryDetail.thumb, String.valueOf(mGalleryDetail.gid),
new LoadImageView.SimpleImageGetListener(mThumb).setTransitabled(false));
mTitle.setText(mGalleryDetail.title);
mUploader.setText(mGalleryDetail.uploader);
mCategory.setText(Ui.getCategoryText(mGalleryDetail.category));
mCategory.setBackgroundColor(Ui.getCategoryColor(mGalleryDetail.category));
}
// Enable button
mReadButton.setEnabled(true);
mReadButton.setOnClickListener(this);
@@ -525,13 +569,10 @@ public class DetailSectionFragment extends Fragment
rate.setRating(mGalleryDetail.rating);
TextSwitcher averagePeople = (TextSwitcher)mRootView.findViewById(R.id.detail_average_people);
averagePeople.setFactory(new ViewFactory() {
@Override
public View makeView() {
LayoutInflater inflater = LayoutInflater.from(mActivity);
return inflater.inflate(R.layout.detail_avg_text, null);
}
});
if (!isSetViewFactory) {
averagePeople.setFactory(this);
isSetViewFactory = true;
}
averagePeople.setCurrentText(String.format("%.2f (%d)",
mGalleryDetail.rating, mGalleryDetail.people));
@@ -571,12 +612,12 @@ public class DetailSectionFragment extends Fragment
}
mCurPage = 0;
mPreviewListLayout.removeAllViews();
mGalleryDetail.previewLists[0].setData(this, mActivity, mGalleryDetail, 0);
mGalleryDetail.previewLists[0].addPreview(mPreviewListLayout);
} else
new SuperToast(mActivity)
.setMessage(R.string.detail_preview_error)
.show();
} else {
new SuperToast(mActivity, R.string.detail_preview_error, SuperToast.WARNING);
}
// Set comments
mActivity.setComments(mGalleryDetail.comments);
@@ -16,7 +16,9 @@
package com.hippo.ehviewer.ui;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import org.json.JSONException;
import org.json.JSONObject;
@@ -75,8 +77,8 @@ public class MangaDetailActivity extends AbstractFragmentActivity
public static final String KEY_G_INFO = "gallery_info";
private ViewPager mViewPager;
private GalleryInfo mGalleryInfo;
public GalleryDetail mGalleryDetail;
private Stack<GalleryDetail> mGdList;
private GalleryDetail mGalleryDetail;
private DetailSectionFragment mDetailFragment;
private CommentsSectionFragment mCommentsFragment;
@@ -96,39 +98,48 @@ public class MangaDetailActivity extends AbstractFragmentActivity
unbindService(mServiceConn);
}
private void handleIntent(Intent intent) {
private GalleryDetail handleIntent(Intent intent) {
GalleryDetail gi = null;
if (intent.getAction() == "android.intent.action.VIEW") {
DetailUrlParser parser = new DetailUrlParser();
if (parser.parser(intent.getData().getPath())) {
mGalleryInfo = new GalleryInfo();
mGalleryInfo.gid = parser.gid;
mGalleryInfo.token = parser.token;
// TODO get all information from detail page
// then update all view
mGalleryInfo.title = "haha";
mGalleryInfo.uploader = "haha";
gi = new GalleryDetail();
gi.gid = parser.gid;
gi.token = parser.token;
} else {
// TODO
}
// TODO reset views
new SuperToast(this)
.setIcon(R.drawable.ic_warning)
.setMessage(R.string.unfinished).show();
} else {
mGalleryInfo = intent.getParcelableExtra(KEY_G_INFO);
gi = new GalleryDetail((GalleryInfo)
(intent.getParcelableExtra(KEY_G_INFO)));
}
// Analytics
Analytics.openGallery(this, mGalleryInfo.gid, mGalleryInfo.token);
if (gi != null)
Analytics.openGallery(this, gi.gid, gi.token);
return gi;
}
@Override
protected void onNewIntent(Intent intent) {
protected void onNewIntent(Intent intent) {
mGdList.push(mGalleryDetail);
setIntent(intent);
handleIntent(intent);
// TODO set up a stack to store detail list
// override on back press
mGalleryDetail = handleIntent(intent);
loadDetail();
}
public void loadDetail() {
mDetailFragment.handleDetail(mGalleryDetail);
getActionBar().setSelectedNavigationItem(0);
}
@Override
public void onBackPressed() {
if (!mGdList.isEmpty()) {
mGalleryDetail = mGdList.pop();
loadDetail();
} else {
finish();
}
}
@Override
@@ -136,7 +147,8 @@ public class MangaDetailActivity extends AbstractFragmentActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.viewpager);
handleIntent(getIntent());
mGdList = new Stack<GalleryDetail>();
mGalleryDetail = handleIntent(getIntent());
final ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
@@ -170,7 +182,7 @@ public class MangaDetailActivity extends AbstractFragmentActivity
Intent it = new Intent(MangaDetailActivity.this, DownloadService.class);
bindService(it, mServiceConn, BIND_AUTO_CREATE);
setTitle(String.valueOf(mGalleryInfo.gid));
setTitle(String.valueOf(mGalleryDetail.gid));
}
@Override
@@ -192,10 +204,6 @@ public class MangaDetailActivity extends AbstractFragmentActivity
return true;
}
public GalleryInfo getGalleryInfo() {
return mGalleryInfo;
}
public List<Comment> getComments() {
if (mDetailFragment == null)
return null;
@@ -219,15 +227,15 @@ public class MangaDetailActivity extends AbstractFragmentActivity
int defaultFavorite = Config.getDefaultFavorite();
switch (defaultFavorite) {
case -2:
Favorite.getAddToFavoriteDialog(this, mGalleryInfo).show();
Favorite.getAddToFavoriteDialog(this, mGalleryDetail).show();
break;
case -1:
((AppContext)getApplication()).getData().addLocalFavourite(mGalleryInfo);
((AppContext)getApplication()).getData().addLocalFavourite(mGalleryDetail);
new SuperToast(this).setMessage(R.string.toast_add_favourite).show();
break;
default:
((AppContext)getApplication()).getEhClient().addToFavorite(mGalleryInfo.gid,
mGalleryInfo.token, defaultFavorite, null, new EhClient.OnAddToFavoriteListener() {
((AppContext)getApplication()).getEhClient().addToFavorite(mGalleryDetail.gid,
mGalleryDetail.token, defaultFavorite, null, new EhClient.OnAddToFavoriteListener() {
@Override
public void onSuccess() {
new SuperToast(MangaDetailActivity.this).setMessage(R.string.toast_add_favourite).show();
@@ -298,7 +306,7 @@ public class MangaDetailActivity extends AbstractFragmentActivity
((AlertButton)v).dialog.dismiss();
String comment = et.getText().toString();
((AppContext)getApplication()).getEhClient()
.comment(EhClient.getDetailUrl(mGalleryInfo.gid, mGalleryInfo.token),
.comment(EhClient.getDetailUrl(mGalleryDetail.gid, mGalleryDetail.token),
comment, new EhClient.OnCommentListener() {
@Override
public void onSuccess(List<Comment> comments) {
@@ -34,6 +34,7 @@ import com.hippo.ehviewer.service.DownloadService;
import com.hippo.ehviewer.service.DownloadServiceConnection;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Favorite;
import com.hippo.ehviewer.util.Log;
import com.hippo.ehviewer.util.Theme;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.util.Util;
@@ -120,13 +121,10 @@ public class MangaListActivity extends AbstractGalleryActivity
private static final String TAG = "MangaListActivity";
public static final int DETAIL_CODE = 0x123;
public static final int MODE_TAG = 0x0;
public static final int MODE_UPLOADER = 0x1;
public static final String ACTION_GALLERY_LIST = "com.hippo.ehviewer.intent.action.GALLERY_LIST";
public static final String KEY_MODE = "mode";
public static final String KEY_GROUP = "group";
public static final String KEY_CATEGORY = "category";
public static final String KEY_TAG = "tag";
public static final String KEY_UPLOADER = "uploader";
@@ -868,12 +866,40 @@ public class MangaListActivity extends AbstractGalleryActivity
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String action = intent.getAction();
if (Intent.ACTION_SEARCH.equals(action)) {
String query =
intent.getStringExtra(SearchManager.QUERY);
mSearchView.setQuery(query, true);
}
}
} else if (ACTION_GALLERY_LIST.equals(action)) {
int mode = intent.getIntExtra(MangaListActivity.KEY_MODE, -1);
switch(mode) {
case ListUrls.TAG:
lus = new ListUrls();
String tag = intent.getStringExtra(KEY_TAG);
lus.setTag(tag);
mTitle = tag;
setTitle(mTitle);
refresh(true);
break;
case ListUrls.UPLOADER:
String uploader = "uploader:" + intent.getStringExtra(KEY_UPLOADER);
lus = new ListUrls(ListUrls.ALL_TYPE, uploader);
lus.setMode(ListUrls.UPLOADER);
mTitle = uploader;
setTitle(mTitle);
refresh(true);
break;
default:
// TODO just do somthing
break;
}
} else {
// TODO just do somthing
}
}
@Override
protected void onNewIntent(Intent intent) {
@@ -1164,8 +1190,7 @@ public class MangaListActivity extends AbstractGalleryActivity
GalleryInfo gi = getGalleryInfo(position);
intent.putExtra("url", EhClient.getDetailUrl(gi.gid, gi.token));
intent.putExtra(MangaDetailActivity.KEY_G_INFO, gi);
// Maybe shoud use other method
startActivityForResult(intent, DETAIL_CODE);
startActivity(intent);
}
});
mList.setOnItemLongClickListener(new OnItemLongClickListener() {
@@ -1348,37 +1373,6 @@ public class MangaListActivity extends AbstractGalleryActivity
createJumpDialog().show();
}
// TODO when it is refreshing
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == DETAIL_CODE
&& resultCode == RESULT_OK) {
switch (data.getIntExtra(KEY_MODE, -1)) {
case MODE_TAG:
lus = new ListUrls();
String tag = data.getStringExtra(KEY_GROUP)
+ ":" + data.getStringExtra(KEY_TAG);
lus.setTag(tag);
mTitle = tag;
setTitle(mTitle);
refresh(false);
break;
case MODE_UPLOADER:
String uploader = "uploader:" + data.getStringExtra(KEY_UPLOADER);
lus = new ListUrls(ListUrls.ALL_TYPE, uploader);
lus.setMode(ListUrls.UPLOADER);
mTitle = uploader;
setTitle(mTitle);
refresh(false);
break;
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection