use of com.hippo.scene.Announcer in project EhViewer by seven332.
the class MainActivity method onUnrecognizedIntent.
@Override
protected void onUnrecognizedIntent(@Nullable Intent intent) {
Class<?> clazz = getTopSceneClass();
if (clazz != null && SolidScene.class.isAssignableFrom(clazz)) {
// TODO the intent lost
return;
}
if (!handleIntent(intent)) {
boolean handleUrl = false;
if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
handleUrl = true;
Toast.makeText(this, R.string.error_cannot_parse_the_url, Toast.LENGTH_SHORT).show();
}
if (0 == getSceneCount()) {
if (handleUrl) {
finish();
} else {
Bundle args = new Bundle();
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
startScene(processAnnouncer(new Announcer(GalleryListScene.class).setArgs(args)));
}
}
}
}
use of com.hippo.scene.Announcer in project EhViewer by seven332.
the class MainActivity method onNavigationItemSelected.
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Don't select twice
if (item.isChecked()) {
return false;
}
int id = item.getItemId();
if (id == R.id.nav_homepage) {
Bundle args = new Bundle();
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
startSceneFirstly(new Announcer(GalleryListScene.class).setArgs(args));
} else if (id == R.id.nav_whats_hot) {
Bundle args = new Bundle();
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_WHATS_HOT);
startSceneFirstly(new Announcer(GalleryListScene.class).setArgs(args));
} else if (id == R.id.nav_favourite) {
startScene(new Announcer(FavoritesScene.class));
} else if (id == R.id.nav_history) {
startScene(new Announcer(HistoryScene.class));
} else if (id == R.id.nav_downloads) {
startScene(new Announcer(DownloadsScene.class));
} else if (id == R.id.nav_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivityForResult(intent, REQUEST_CODE_SETTINGS);
}
if (id != R.id.nav_stub && mDrawerLayout != null) {
mDrawerLayout.closeDrawers();
}
return true;
}
use of com.hippo.scene.Announcer in project EhViewer by seven332.
the class MainActivity method processAnnouncer.
// Sometimes scene can't show directly
private Announcer processAnnouncer(Announcer announcer) {
if (0 == getSceneCount()) {
if (!TextUtils.isEmpty(Settings.getSecurity())) {
Bundle newArgs = new Bundle();
newArgs.putString(SecurityScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(SecurityScene.KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(SecurityScene.class).setArgs(newArgs);
} else if (Settings.getShowWarning()) {
Bundle newArgs = new Bundle();
newArgs.putString(WarningScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(WarningScene.KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(WarningScene.class).setArgs(newArgs);
} else if (Settings.getAskAnalytics()) {
Bundle newArgs = new Bundle();
newArgs.putString(AnalyticsScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(AnalyticsScene.KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(AnalyticsScene.class).setArgs(newArgs);
} else if (Crash.hasCrashFile()) {
Bundle newArgs = new Bundle();
newArgs.putString(CrashScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(CrashScene.KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(CrashScene.class).setArgs(newArgs);
} else if (EhUtils.needSignedIn(this)) {
Bundle newArgs = new Bundle();
newArgs.putString(SignInScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(SignInScene.KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(SignInScene.class).setArgs(newArgs);
} else if (Settings.getSelectSite()) {
Bundle newArgs = new Bundle();
newArgs.putString(SelectSiteScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(SelectSiteScene.KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(SelectSiteScene.class).setArgs(newArgs);
}
}
return announcer;
}
use of com.hippo.scene.Announcer in project EhViewer by seven332.
the class MainActivity method handleIntent.
private boolean handleIntent(Intent intent) {
if (intent == null) {
return false;
}
String action = intent.getAction();
if (Intent.ACTION_VIEW.equals(action)) {
Announcer announcer = EhUrlOpener.parseUrl(intent.getData().toString());
if (announcer != null) {
startScene(processAnnouncer(announcer));
return true;
}
} else if (Intent.ACTION_SEND.equals(action)) {
String type = intent.getType();
if ("text/plain".equals(type)) {
ListUrlBuilder builder = new ListUrlBuilder();
builder.setKeyword(intent.getStringExtra(Intent.EXTRA_TEXT));
startScene(processAnnouncer(GalleryListScene.getStartAnnouncer(builder)));
return true;
} else if (type.startsWith("image/")) {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (null != uri) {
UniFile file = UniFile.fromUri(this, uri);
File temp = saveImageToTempFile(file);
if (null != temp) {
ListUrlBuilder builder = new ListUrlBuilder();
builder.setMode(ListUrlBuilder.MODE_IMAGE_SEARCH);
builder.setImagePath(temp.getPath());
builder.setUseSimilarityScan(true);
builder.setShowExpunged(true);
startScene(processAnnouncer(GalleryListScene.getStartAnnouncer(builder)));
return true;
}
}
}
}
return false;
}
use of com.hippo.scene.Announcer in project EhViewer by seven332.
the class DownloadsScene method onCreateDrawerView.
@Override
public View onCreateDrawerView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.drawer_list, container, false);
final Context context = getContext2();
Assert.assertNotNull(context);
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.download_labels);
toolbar.inflateMenu(R.menu.drawer_download);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
switch(id) {
case R.id.action_settings:
startScene(new Announcer(DownloadLabelsScene.class));
return true;
case R.id.action_default_download_label:
DownloadManager dm = mDownloadManager;
if (null == dm) {
return true;
}
List<DownloadLabel> list = dm.getLabelList();
final String[] items = new String[list.size() + 2];
items[0] = getString(R.string.let_me_select);
items[1] = getString(R.string.default_download_label_name);
for (int i = 0, n = list.size(); i < n; i++) {
items[i + 2] = list.get(i).getLabel();
}
new AlertDialog.Builder(context).setTitle(R.string.default_download_label).setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
Settings.putHasDefaultDownloadLabel(false);
} else {
Settings.putHasDefaultDownloadLabel(true);
String label;
if (which == 1) {
label = null;
} else {
label = items[which];
}
Settings.putDefaultDownloadLabel(label);
}
}
}).show();
return true;
}
return false;
}
});
List<DownloadLabel> list = EhApplication.getDownloadManager(context).getLabelList();
final List<String> labels = new ArrayList<>(list.size() + 1);
// Add default label name
labels.add(getString(R.string.default_download_label_name));
for (DownloadLabel raw : list) {
labels.add(raw.getLabel());
}
// TODO handle download label items update
ListView listView = (ListView) view.findViewById(R.id.list_view);
listView.setAdapter(new ArrayAdapter<>(context, R.layout.item_simple_list, labels));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String label;
if (position == 0) {
label = null;
} else {
label = labels.get(position);
}
if (!ObjectUtils.equal(label, mLabel)) {
mLabel = label;
updateForLabel();
updateView();
closeDrawer(Gravity.RIGHT);
}
}
});
return view;
}
Aggregations