Use SnackBar
This commit is contained in:
1 parent
cd016a126c
commit
b09b261098
11 files changed
+117
-56
No files matched your search
@@ -24,7 +24,9 @@ import android.os.PersistableBundle;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
@@ -37,7 +39,6 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUrlOpener;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.ui.annotation.WholeLifeCircle;
|
||||
import com.hippo.ehviewer.ui.scene.AnalyticsScene;
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene;
|
||||
import com.hippo.ehviewer.ui.scene.DownloadLabelScene;
|
||||
@@ -73,14 +74,14 @@ public final class MainActivity extends StageActivity
|
||||
public static final String KEY_TARGET_SCENE = "target_scene";
|
||||
public static final String KEY_TARGET_ARGS = "target_args";
|
||||
|
||||
/*---------------
|
||||
Whole life cycle
|
||||
---------------*/
|
||||
@Nullable
|
||||
@WholeLifeCircle
|
||||
private DrawerLayout mDrawerLayout;
|
||||
@Nullable
|
||||
@WholeLifeCircle
|
||||
private NavigationView mNavView;
|
||||
@Nullable
|
||||
@WholeLifeCircle
|
||||
private FrameLayout mRightDrawer;
|
||||
|
||||
private int mNavCheckedItem = 0;
|
||||
@@ -357,6 +358,23 @@ public final class MainActivity extends StageActivity
|
||||
}
|
||||
}
|
||||
|
||||
public void showTip(@StringRes int id, int length) {
|
||||
showTip(getString(id), length);
|
||||
}
|
||||
|
||||
/**
|
||||
* If activity is running, show snack bar, otherwise show toast
|
||||
*/
|
||||
public void showTip(CharSequence message, int length) {
|
||||
if (null != mDrawerLayout) {
|
||||
Snackbar.make(mDrawerLayout, message,
|
||||
length == BaseScene.LENGTH_LONG ? Snackbar.LENGTH_LONG : Snackbar.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, message,
|
||||
length == BaseScene.LENGTH_LONG ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mDrawerLayout != null && (mDrawerLayout.isDrawerOpen(Gravity.LEFT) ||
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.hippo.ehviewer.ui.scene;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.view.Gravity;
|
||||
@@ -32,6 +33,9 @@ import com.hippo.util.ActivityHelper;
|
||||
|
||||
public abstract class BaseScene extends SceneFragment {
|
||||
|
||||
public static final int LENGTH_SHORT = 0;
|
||||
public static final int LENGTH_LONG = 1;
|
||||
|
||||
private boolean mViewCreated;
|
||||
|
||||
public void setDrawerLockMode(int lockMode, int edgeGravity) {
|
||||
@@ -81,6 +85,20 @@ public abstract class BaseScene extends SceneFragment {
|
||||
}
|
||||
}
|
||||
|
||||
public void showTip(CharSequence message, int length) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
((MainActivity) activity).showTip(message, length);
|
||||
}
|
||||
}
|
||||
|
||||
public void showTip(@StringRes int id, int length) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
((MainActivity) activity).showTip(id, length);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean needShowLeftDrawer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,12 @@
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
|
||||
@@ -41,6 +44,10 @@ public abstract class EhCallback<E extends SceneFragment, T> implements EhClient
|
||||
return mApplication;
|
||||
}
|
||||
|
||||
public StageActivity getStageActivity() {
|
||||
return mApplication.findStageActivityById(mStageId);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public E getScene() {
|
||||
StageActivity stage = mApplication.findStageActivityById(mStageId);
|
||||
@@ -54,4 +61,14 @@ public abstract class EhCallback<E extends SceneFragment, T> implements EhClient
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void showTip(@StringRes int id, int length) {
|
||||
StageActivity activity = getStageActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
((MainActivity) activity).showTip(id, length);
|
||||
} else {
|
||||
Toast.makeText(getApplication(), id,
|
||||
length == BaseScene.LENGTH_LONG ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,6 @@ import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.annotation.Implemented;
|
||||
import com.hippo.drawable.DrawerArrowDrawable;
|
||||
@@ -848,7 +847,6 @@ public class FavoritesScene extends BaseScene implements
|
||||
dstCat = which - 1;
|
||||
}
|
||||
if (srcCat == dstCat) {
|
||||
Toast.makeText(getContext(), "src and dst in the same", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
|
||||
@@ -410,8 +409,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public void onSuccess(GalleryComment[] result) {
|
||||
// Show toast
|
||||
Toast.makeText(getApplication(), R.string.comment_successfully, Toast.LENGTH_SHORT).show();
|
||||
showTip(R.string.comment_successfully, LENGTH_SHORT);
|
||||
|
||||
GalleryCommentsScene scene = getScene();
|
||||
if (scene != null) {
|
||||
@@ -421,8 +419,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
// Show toast
|
||||
Toast.makeText(getApplication(), R.string.comment_failed, Toast.LENGTH_SHORT).show();
|
||||
showTip(R.string.comment_failed, LENGTH_SHORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,7 +53,6 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RatingBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.drawable.RoundSideRectDrawable;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
@@ -1338,8 +1337,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
Toast.makeText(getContext(), mAddOrRemove ? R.string.remove_from_favorite_success :
|
||||
R.string.add_to_favorite_success, Toast.LENGTH_SHORT).show();
|
||||
showTip(mAddOrRemove ? R.string.remove_from_favorite_success :
|
||||
R.string.add_to_favorite_success, LENGTH_SHORT);
|
||||
GalleryDetailScene scene = getScene();
|
||||
if (scene != null) {
|
||||
scene.onModifyFavoritesSuccess(mAddOrRemove);
|
||||
@@ -1348,8 +1347,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
Toast.makeText(getContext(), mAddOrRemove ? R.string.remove_from_favorite_failure :
|
||||
R.string.add_to_favorite_failure, Toast.LENGTH_SHORT).show();
|
||||
showTip(mAddOrRemove ? R.string.remove_from_favorite_failure :
|
||||
R.string.add_to_favorite_failure, LENGTH_SHORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1564,8 +1563,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
@Override
|
||||
public void onSuccess(RateGalleryParser.Result result) {
|
||||
// Show toast
|
||||
Toast.makeText(getApplication(), R.string.rate_successfully, Toast.LENGTH_SHORT).show();
|
||||
showTip(R.string.rate_successfully, LENGTH_SHORT);
|
||||
|
||||
GalleryDetailScene scene = getScene();
|
||||
if (scene != null) {
|
||||
@@ -1583,8 +1581,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
e.printStackTrace();
|
||||
// Show toast
|
||||
Toast.makeText(getApplication(), R.string.rate_failed, Toast.LENGTH_SHORT).show();
|
||||
showTip(R.string.rate_failed, LENGTH_SHORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,7 +29,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
|
||||
@@ -176,7 +175,7 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
if (position != 0 && mValues != null) {
|
||||
ClipboardManager cmb = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setPrimaryClip(ClipData.newPlainText(null, mValues.get(position)));
|
||||
Toast.makeText(getContext(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
|
||||
showTip(R.string.copied_to_clipboard, LENGTH_SHORT);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -44,7 +44,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.drawable.AddDeleteDrawable;
|
||||
import com.hippo.drawable.DrawerArrowDrawable;
|
||||
@@ -372,7 +371,7 @@ public final class GalleryListScene extends BaseScene
|
||||
if (time - mPressBackTime > BACK_PRESSED_INTERVAL) {
|
||||
// It is the last scene
|
||||
mPressBackTime = time;
|
||||
Toast.makeText(getContext(), R.string.press_twice_exit, Toast.LENGTH_SHORT).show();
|
||||
showTip(R.string.press_twice_exit, LENGTH_SHORT);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -466,7 +465,9 @@ public final class GalleryListScene extends BaseScene
|
||||
CommonOperations.startDownload(getActivity(), gi);
|
||||
break;
|
||||
case 1: // Favorites
|
||||
CommonOperations.addToFavorites(getActivity(), gi, new addToFavoriteListener());
|
||||
CommonOperations.addToFavorites(getActivity(), gi,
|
||||
new addToFavoriteListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -616,7 +617,7 @@ public final class GalleryListScene extends BaseScene
|
||||
if (mSearchLayout.isSpecifyGallery()) {
|
||||
int index = query.indexOf(' ');
|
||||
if (index <= 0 || index >= query.length() - 1) {
|
||||
Toast.makeText(getContext(), "Error", Toast.LENGTH_SHORT).show(); // TODO
|
||||
showTip(R.string.error_invalid_specify_gallery, LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -625,7 +626,7 @@ public final class GalleryListScene extends BaseScene
|
||||
try {
|
||||
gid = Long.parseLong(query.substring(0, index));
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(getContext(), "Error", Toast.LENGTH_SHORT).show(); // TODO
|
||||
showTip(R.string.error_invalid_specify_gallery, LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
token = query.substring(index + 1);
|
||||
@@ -953,19 +954,28 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
}
|
||||
|
||||
private class addToFavoriteListener implements EhClient.Callback<Void> {
|
||||
private static class addToFavoriteListener extends EhCallback<GalleryListScene, Void> {
|
||||
|
||||
public addToFavoriteListener(Context context, int stageId, String sceneTag) {
|
||||
super(context, stageId, sceneTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
Toast.makeText(getContext(), R.string.add_to_favorite_success, Toast.LENGTH_SHORT).show();
|
||||
showTip(R.string.add_to_favorite_success, LENGTH_SHORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
Toast.makeText(getContext(), R.string.add_to_favorite_failure, Toast.LENGTH_SHORT).show();
|
||||
showTip(R.string.add_to_favorite_failure, LENGTH_SHORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {}
|
||||
|
||||
@Override
|
||||
public boolean isInstance(SceneFragment scene) {
|
||||
return scene instanceof GalleryListScene;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,6 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.MarginItemDecoration;
|
||||
@@ -408,7 +407,7 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
mDialog = null;
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getContext(), R.string.error_out_of_range, Toast.LENGTH_SHORT).show();
|
||||
showTip(R.string.error_out_of_range, LENGTH_SHORT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,37 +15,44 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<android.support.v4.widget.DrawerLayout
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/draw_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.hippo.scene.StageLayout
|
||||
android:id="@+id/fragment_container"
|
||||
<android.support.v4.widget.DrawerLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/draw_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"/>
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<android.support.design.widget.NavigationView
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="left"
|
||||
android:maxWidth="@dimen/drawer_max_width"
|
||||
android:fitsSystemWindows="true"
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:menu="@menu/nav_drawer_main"/>
|
||||
<com.hippo.scene.StageLayout
|
||||
android:id="@+id/fragment_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"/>
|
||||
|
||||
<com.hippo.widget.DrawView
|
||||
android:id="@+id/right_drawer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="right"
|
||||
android:maxWidth="@dimen/drawer_max_width"
|
||||
android:background="@color/background_light"
|
||||
android:clickable="true"/>
|
||||
<android.support.design.widget.NavigationView
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="left"
|
||||
android:maxWidth="@dimen/drawer_max_width"
|
||||
android:fitsSystemWindows="true"
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:menu="@menu/nav_drawer_main"/>
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
<com.hippo.widget.DrawView
|
||||
android:id="@+id/right_drawer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="right"
|
||||
android:maxWidth="@dimen/drawer_max_width"
|
||||
android:background="@color/background_light"
|
||||
android:clickable="true"/>
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
@@ -94,6 +94,7 @@
|
||||
<string name="error_509">509</string>
|
||||
<string name="error_invalid_url">Invalid url</string>
|
||||
<string name="error_get_ptoken_error">Get pToken error</string>
|
||||
<string name="error_invalid_specify_gallery">Keyword should looks like \"618395 0439fa3666\" for specify gallery</string>
|
||||
|
||||
<string name="app_waring">The content of this application is from the Internet. Some of it may do physical or mental harm to you. You have learnt the risks above and would like to undertake them. Do you want to use this application?</string>
|
||||
<string name="error_username_cannot_empty">Username cannot be an empty string</string>
|
||||
|
||||
Reference in new issue
Block a user