use of com.hippo.scene.Announcer in project EhViewer by seven332.
the class GalleryDetailScene method onClick.
@Override
public void onClick(View v) {
Context context = getContext2();
MainActivity activity = getActivity2();
if (null == context || null == activity) {
return;
}
if (mTip == v) {
if (request()) {
adjustViewVisibility(STATE_REFRESH, true);
}
} else if (mOtherActions == v) {
ensurePopMenu();
if (mPopupMenu != null) {
mPopupMenu.show();
}
} else if (mUploader == v) {
String uploader = getUploader();
if (TextUtils.isEmpty(uploader)) {
return;
}
ListUrlBuilder lub = new ListUrlBuilder();
lub.setMode(ListUrlBuilder.MODE_UPLOADER);
lub.setKeyword(uploader);
GalleryListScene.startScene(this, lub);
} else if (mCategory == v) {
int category = getCategory();
if (category == -1) {
return;
}
ListUrlBuilder lub = new ListUrlBuilder();
lub.setCategory(category);
GalleryListScene.startScene(this, lub);
} else if (mDownload == v) {
GalleryInfo galleryInfo = getGalleryInfo();
if (galleryInfo != null) {
CommonOperations.startDownload(activity, galleryInfo, false);
}
} else if (mRead == v) {
GalleryInfo galleryInfo = null;
if (mGalleryInfo != null) {
galleryInfo = mGalleryInfo;
} else if (mGalleryDetail != null) {
galleryInfo = mGalleryDetail;
}
if (galleryInfo != null) {
Intent intent = new Intent(activity, GalleryActivity.class);
intent.setAction(GalleryActivity.ACTION_EH);
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, galleryInfo);
startActivity(intent);
}
} else if (mInfo == v) {
Bundle args = new Bundle();
args.putParcelable(GalleryInfoScene.KEY_GALLERY_DETAIL, mGalleryDetail);
startScene(new Announcer(GalleryInfoScene.class).setArgs(args));
} else if (mHeartGroup == v) {
if (mGalleryDetail != null && !mModifingFavorites) {
boolean remove = false;
if (EhDB.containLocalFavorites(mGalleryDetail.gid)) {
EhDB.removeLocalFavorites(mGalleryDetail.gid);
remove = true;
}
if (mGalleryDetail.isFavorited) {
mModifingFavorites = true;
CommonOperations.removeFromFavorites(activity, mGalleryDetail, new ModifyFavoritesListener(context, activity.getStageId(), getTag(), true));
remove = true;
}
if (!remove) {
mModifingFavorites = true;
CommonOperations.addToFavorites(activity, mGalleryDetail, new ModifyFavoritesListener(context, activity.getStageId(), getTag(), false));
}
// Update UI
updateFavoriteDrawable();
}
} else if (mShare == v) {
String url = getGalleryDetailUrl(false);
if (url != null) {
AppHelper.share(activity, url);
}
} else if (mTorrent == v) {
if (mGalleryDetail != null) {
TorrentListDialogHelper helper = new TorrentListDialogHelper();
Dialog dialog = new AlertDialog.Builder(context).setTitle(R.string.torrents).setView(R.layout.dialog_torrent_list).setOnDismissListener(helper).show();
helper.setDialog(dialog, mGalleryDetail.torrentUrl);
}
} else if (mArchive == v) {
if (mGalleryDetail == null) {
return;
}
if (mGalleryDetail.apiUid < 0) {
showTip(R.string.sign_in_first, LENGTH_SHORT);
return;
}
ArchiveListDialogHelper helper = new ArchiveListDialogHelper();
Dialog dialog = new AlertDialog.Builder(context).setTitle(R.string.dialog_archive_title).setView(R.layout.dialog_archive_list).setOnDismissListener(helper).show();
helper.setDialog(dialog, mGalleryDetail.archiveUrl);
} else if (mRate == v) {
if (mGalleryDetail == null) {
return;
}
if (mGalleryDetail.apiUid < 0) {
showTip(R.string.sign_in_first, LENGTH_SHORT);
return;
}
RateDialogHelper helper = new RateDialogHelper();
Dialog dialog = new AlertDialog.Builder(context).setTitle(R.string.rate).setView(R.layout.dialog_rate).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, helper).show();
helper.setDialog(dialog, mGalleryDetail.rating);
} else if (mSimilar == v) {
showSimilarGalleryList();
} else if (mSearchCover == v) {
showCoverGalleryList();
} else if (mComments == v) {
if (mGalleryDetail == null) {
return;
}
Bundle args = new Bundle();
args.putLong(GalleryCommentsScene.KEY_API_UID, mGalleryDetail.apiUid);
args.putString(GalleryCommentsScene.KEY_API_KEY, mGalleryDetail.apiKey);
args.putLong(GalleryCommentsScene.KEY_GID, mGalleryDetail.gid);
args.putString(GalleryCommentsScene.KEY_TOKEN, mGalleryDetail.token);
args.putParcelableArray(GalleryCommentsScene.KEY_COMMENTS, mGalleryDetail.comments);
startScene(new Announcer(GalleryCommentsScene.class).setArgs(args).setRequestCode(this, REQUEST_CODE_COMMENT_GALLERY));
} else if (mPreviews == v) {
if (null != mGalleryDetail) {
Bundle args = new Bundle();
args.putParcelable(GalleryPreviewsScene.KEY_GALLERY_INFO, mGalleryDetail);
startScene(new Announcer(GalleryPreviewsScene.class).setArgs(args));
}
} else {
Object o = v.getTag(R.id.tag);
if (o instanceof String) {
String tag = (String) o;
ListUrlBuilder lub = new ListUrlBuilder();
lub.setMode(ListUrlBuilder.MODE_TAG);
lub.setKeyword(tag);
GalleryListScene.startScene(this, lub);
return;
}
GalleryInfo galleryInfo = getGalleryInfo();
o = v.getTag(R.id.index);
if (null != galleryInfo && o instanceof Integer) {
int index = (Integer) o;
Intent intent = new Intent(context, GalleryActivity.class);
intent.setAction(GalleryActivity.ACTION_EH);
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, galleryInfo);
intent.putExtra(GalleryActivity.KEY_PAGE, index);
startActivity(intent);
return;
}
}
}
use of com.hippo.scene.Announcer in project EhViewer by seven332.
the class GalleryListScene method onApplySearch.
@Override
public void onApplySearch(String query) {
if (null == mUrlBuilder || null == mHelper || null == mSearchLayout) {
return;
}
if (mState == STATE_SEARCH || mState == STATE_SEARCH_SHOW_LIST) {
if (mSearchLayout.isSpecifyGallery()) {
int index = query.indexOf(' ');
if (index <= 0 || index >= query.length() - 1) {
showTip(R.string.error_invalid_specify_gallery, LENGTH_LONG);
return;
}
long gid;
String token;
try {
gid = Long.parseLong(query.substring(0, index));
} catch (NumberFormatException e) {
showTip(R.string.error_invalid_specify_gallery, LENGTH_LONG);
return;
}
token = query.substring(index + 1);
Bundle args = new Bundle();
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
args.putLong(GalleryDetailScene.KEY_GID, gid);
args.putString(GalleryDetailScene.KEY_TOKEN, token);
startScene(new Announcer(GalleryDetailScene.class).setArgs(args));
return;
} else {
try {
mSearchLayout.formatListUrlBuilder(mUrlBuilder, query);
} catch (EhException e) {
showTip(e.getMessage(), LENGTH_LONG);
return;
}
}
} else {
mUrlBuilder.reset();
mUrlBuilder.setKeyword(query);
}
onUpdateUrlBuilder();
mHelper.refresh();
setState(STATE_NORMAL);
}
use of com.hippo.scene.Announcer in project EhViewer by seven332.
the class SolidScene method startSceneForCheckStep.
public void startSceneForCheckStep(int checkStep, Bundle args) {
switch(checkStep) {
case CHECK_STEP_SECURITY:
if (Settings.getShowWarning()) {
startScene(new Announcer(WarningScene.class).setArgs(args));
break;
}
case CHECK_STEP_WARNING:
if (Settings.getAskAnalytics()) {
startScene(new Announcer(AnalyticsScene.class).setArgs(args));
break;
}
case CHECK_STEP_ANALYTICS:
if (Crash.hasCrashFile()) {
startScene(new Announcer(CrashScene.class).setArgs(args));
break;
}
case CHECK_STEP_CRASH:
if (EhUtils.needSignedIn(getContext2())) {
startScene(new Announcer(SignInScene.class).setArgs(args));
break;
}
case CHECK_STEP_SIGN_IN:
if (Settings.getSelectSite()) {
startScene(new Announcer(SelectSiteScene.class).setArgs(args));
break;
}
case CHECK_STEP_SELECT_SITE:
String targetScene = null;
Bundle targetArgs = null;
if (null != args) {
targetScene = args.getString(KEY_TARGET_SCENE);
targetArgs = args.getBundle(KEY_TARGET_ARGS);
}
Class<?> clazz = null;
if (targetScene != null) {
try {
clazz = Class.forName(targetScene);
} catch (ClassNotFoundException e) {
Log.e(TAG, "Can't find class with name: " + targetScene);
}
}
if (clazz != null) {
startScene(new Announcer(clazz).setArgs(targetArgs));
} else {
Bundle newArgs = new Bundle();
newArgs.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
startScene(new Announcer(GalleryListScene.class).setArgs(newArgs));
}
break;
}
}
use of com.hippo.scene.Announcer in project EhViewer by seven332.
the class UrlOpener method openUrl.
public static void openUrl(@NonNull Context context, String url, boolean ehUrl) {
if (TextUtils.isEmpty(url)) {
return;
}
Intent intent;
Uri uri = Uri.parse(url);
if (ehUrl) {
Announcer announcer = EhUrlOpener.parseUrl(url);
if (null != announcer) {
intent = new Intent(context, MainActivity.class);
intent.setAction(StageActivity.ACTION_START_SCENE);
intent.putExtra(StageActivity.KEY_SCENE_NAME, announcer.getClazz().getName());
intent.putExtra(StageActivity.KEY_SCENE_ARGS, announcer.getArgs());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
return;
}
}
// Intent.ACTION_VIEW
intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(context, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
}
}
use of com.hippo.scene.Announcer in project EhViewer by seven332.
the class EhUrlOpener method parseUrl.
@Nullable
public static Announcer parseUrl(String url) {
if (TextUtils.isEmpty(url)) {
return null;
}
ListUrlBuilder listUrlBuilder = GalleryListUrlParser.parse(url);
if (listUrlBuilder != null) {
Bundle args = new Bundle();
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_LIST_URL_BUILDER);
args.putParcelable(GalleryListScene.KEY_LIST_URL_BUILDER, listUrlBuilder);
return new Announcer(GalleryListScene.class).setArgs(args);
}
GalleryDetailUrlParser.Result result1 = GalleryDetailUrlParser.parse(url);
if (result1 != null) {
Bundle args = new Bundle();
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
args.putLong(GalleryDetailScene.KEY_GID, result1.gid);
args.putString(GalleryDetailScene.KEY_TOKEN, result1.token);
return new Announcer(GalleryDetailScene.class).setArgs(args);
}
GalleryPageUrlParser.Result result2 = GalleryPageUrlParser.parse(url);
if (result2 != null) {
Bundle args = new Bundle();
args.putString(ProgressScene.KEY_ACTION, ProgressScene.ACTION_GALLERY_TOKEN);
args.putLong(ProgressScene.KEY_GID, result2.gid);
args.putString(ProgressScene.KEY_PTOKEN, result2.pToken);
args.putInt(ProgressScene.KEY_PAGE, result2.page);
return new Announcer(ProgressScene.class).setArgs(args);
}
Log.i(TAG, "Can't parse url: " + url);
return null;
}
Aggregations