mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1246239 - Show "saved offline" snackbar when readermode page is bookmarked r=sebastian
MozReview-Commit-ID: IC33HwSClcI --HG-- extra : rebase_source : 673e2632a433366fb1c3fd18eeba0080399fd6b6
This commit is contained in:
parent
67a2976dc3
commit
e2de073003
@ -7,16 +7,16 @@ package org.mozilla.gecko;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.DownloadManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.WorkerThread;
|
||||
import org.json.JSONArray;
|
||||
import org.mozilla.gecko.adjust.AdjustHelperInterface;
|
||||
import org.mozilla.gecko.annotation.RobocopTarget;
|
||||
import org.mozilla.gecko.AppConstants.Versions;
|
||||
import org.mozilla.gecko.DynamicToolbar.VisibilityTransition;
|
||||
import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
|
||||
import org.mozilla.gecko.Tabs.TabEvents;
|
||||
import org.mozilla.gecko.animation.PropertyAnimator;
|
||||
import org.mozilla.gecko.animation.ViewHelper;
|
||||
@ -25,10 +25,8 @@ import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.db.SuggestedSites;
|
||||
import org.mozilla.gecko.distribution.Distribution;
|
||||
import org.mozilla.gecko.distribution.Distribution.DistributionDescriptor;
|
||||
import org.mozilla.gecko.distribution.DistributionStoreCallback;
|
||||
import org.mozilla.gecko.dlc.DownloadContentService;
|
||||
import org.mozilla.gecko.dlc.catalog.DownloadContent;
|
||||
import org.mozilla.gecko.favicons.Favicons;
|
||||
import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
|
||||
import org.mozilla.gecko.favicons.decoders.IconDirectoryEntry;
|
||||
@ -86,6 +84,7 @@ import org.mozilla.gecko.trackingprotection.TrackingProtectionPrompt;
|
||||
import org.mozilla.gecko.updater.UpdateServiceHelper;
|
||||
import org.mozilla.gecko.util.ActivityUtils;
|
||||
import org.mozilla.gecko.util.Clipboard;
|
||||
import org.mozilla.gecko.util.DrawableUtil;
|
||||
import org.mozilla.gecko.util.EventCallback;
|
||||
import org.mozilla.gecko.util.Experiments;
|
||||
import org.mozilla.gecko.util.FloatUtils;
|
||||
@ -130,6 +129,7 @@ import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
@ -363,7 +363,15 @@ public class BrowserApp extends GeckoApp
|
||||
tab.loadFavicon();
|
||||
break;
|
||||
case BOOKMARK_ADDED:
|
||||
showBookmarkAddedSnackbar();
|
||||
// We always show the special offline snackbar whenever we bookmark a reader page.
|
||||
// It's possible that the page is already stored offline, however this is highly
|
||||
// unlikely, and even so it is probably nicer to show the same offline notification
|
||||
// every time we bookmark an about:reader page.
|
||||
if (!AboutPages.isAboutReader(tab.getURL())) {
|
||||
showBookmarkAddedSnackbar();
|
||||
} else {
|
||||
showReaderModeBookmarkAddedSnackbar();
|
||||
}
|
||||
break;
|
||||
case BOOKMARK_REMOVED:
|
||||
showBookmarkRemovedSnackbar();
|
||||
@ -442,6 +450,26 @@ public class BrowserApp extends GeckoApp
|
||||
callback);
|
||||
}
|
||||
|
||||
private void showReaderModeBookmarkAddedSnackbar() {
|
||||
final Drawable iconDownloaded = DrawableUtil.tintDrawable(getContext(), R.drawable.status_icon_readercache, Color.WHITE);
|
||||
|
||||
final SnackbarHelper.SnackbarCallback callback = new SnackbarHelper.SnackbarCallback() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openUrlAndStopEditing("about:home?panel=" + HomeConfig.getIdForBuiltinPanelType(PanelType.BOOKMARKS));
|
||||
}
|
||||
};
|
||||
|
||||
SnackbarHelper.showSnackbarWithActionAndColors(this,
|
||||
getResources().getString(R.string.reader_saved_offline),
|
||||
Snackbar.LENGTH_LONG,
|
||||
getResources().getString(R.string.reader_switch_to_bookmarks),
|
||||
callback,
|
||||
iconDownloaded,
|
||||
ContextCompat.getColor(this, R.color.link_blue),
|
||||
Color.WHITE);
|
||||
}
|
||||
|
||||
private void showBookmarkRemovedSnackbar() {
|
||||
SnackbarHelper.showSnackbar(this, getResources().getString(R.string.bookmark_removed), Snackbar.LENGTH_LONG);
|
||||
}
|
||||
|
@ -9,10 +9,14 @@ import org.mozilla.gecko.util.EventCallback;
|
||||
import org.mozilla.gecko.util.NativeJSObject;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.InsetDrawable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
@ -98,15 +102,46 @@ public class SnackbarHelper {
|
||||
* @param callback Callback to be invoked when the action is clicked or the snackbar is dismissed.
|
||||
*/
|
||||
public static void showSnackbarWithAction(Activity activity, String message, int duration, String action, SnackbarCallback callback) {
|
||||
showSnackbarWithActionAndColors(activity, message, duration, action, callback, null, null, null);
|
||||
}
|
||||
|
||||
|
||||
public static void showSnackbarWithActionAndColors(Activity activity,
|
||||
String message,
|
||||
int duration,
|
||||
String action,
|
||||
SnackbarCallback callback,
|
||||
Drawable icon,
|
||||
Integer backgroundColor,
|
||||
Integer actionColor) {
|
||||
final View parentView = findBestParentView(activity);
|
||||
final Snackbar snackbar = Snackbar.make(parentView, message, duration);
|
||||
|
||||
if (callback != null && !TextUtils.isEmpty(action)) {
|
||||
snackbar.setAction(action, callback);
|
||||
snackbar.setActionTextColor(ContextCompat.getColor(activity, R.color.fennec_ui_orange));
|
||||
if (actionColor == null) {
|
||||
ContextCompat.getColor(activity, R.color.fennec_ui_orange);
|
||||
} else {
|
||||
snackbar.setActionTextColor(actionColor);
|
||||
}
|
||||
snackbar.setCallback(callback);
|
||||
}
|
||||
|
||||
if (icon != null) {
|
||||
int leftPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, activity.getResources().getDisplayMetrics());
|
||||
|
||||
final InsetDrawable paddedIcon = new InsetDrawable(icon, 0, 0, leftPadding, 0);
|
||||
|
||||
paddedIcon.setBounds(0, 0, leftPadding + icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
|
||||
|
||||
TextView textView = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
|
||||
textView.setCompoundDrawables(paddedIcon, null, null, null);
|
||||
}
|
||||
|
||||
if (backgroundColor != null) {
|
||||
snackbar.getView().setBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
snackbar.show();
|
||||
|
||||
synchronized (currentSnackbarLock) {
|
||||
|
@ -145,7 +145,7 @@ class SearchEngineRow extends AnimatedHeightLayout {
|
||||
mUserEnteredView.setOnClickListener(mClickListener);
|
||||
|
||||
mUserEnteredTextView = (TextView) findViewById(R.id.suggestion_text);
|
||||
mSearchHistorySuggestionIcon = DrawableUtil.tintDrawable(getContext(), R.drawable.icon_most_recent_empty, R.color.tabs_tray_icon_grey);
|
||||
mSearchHistorySuggestionIcon = DrawableUtil.tintDrawableWithColorRes(getContext(), R.drawable.icon_most_recent_empty, R.color.tabs_tray_icon_grey);
|
||||
|
||||
// Suggestion limits
|
||||
mMaxSavedSuggestions = getResources().getInteger(R.integer.max_saved_suggestions);
|
||||
|
@ -150,10 +150,10 @@ public class ToolbarEditLayout extends ThemedLinearLayout {
|
||||
final int searchDrawableId = R.drawable.search_icon_active;
|
||||
final Drawable searchDrawable;
|
||||
if (!isActive) {
|
||||
searchDrawable = DrawableUtil.tintDrawable(getContext(), searchDrawableId, R.color.placeholder_grey);
|
||||
searchDrawable = DrawableUtil.tintDrawableWithColorRes(getContext(), searchDrawableId, R.color.placeholder_grey);
|
||||
} else {
|
||||
if (isPrivateMode()) {
|
||||
searchDrawable = DrawableUtil.tintDrawable(getContext(), searchDrawableId, R.color.tabs_tray_icon_grey);
|
||||
searchDrawable = DrawableUtil.tintDrawableWithColorRes(getContext(), searchDrawableId, R.color.tabs_tray_icon_grey);
|
||||
} else {
|
||||
searchDrawable = getResources().getDrawable(searchDrawableId);
|
||||
}
|
||||
|
@ -7,8 +7,10 @@ package org.mozilla.gecko.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.CheckResult;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
@ -21,14 +23,25 @@ public class DrawableUtil {
|
||||
* Tints the given drawable with the given color and returns it.
|
||||
*/
|
||||
@CheckResult
|
||||
public static Drawable tintDrawable(@NonNull final Context context, @DrawableRes final int drawableID,
|
||||
@ColorRes final int colorID) {
|
||||
public static Drawable tintDrawable(@NonNull final Context context,
|
||||
@DrawableRes final int drawableID,
|
||||
@ColorInt final int color) {
|
||||
final Drawable icon = DrawableCompat.wrap(
|
||||
ContextCompat.getDrawable(context, drawableID).mutate());
|
||||
DrawableCompat.setTint(icon, ContextCompat.getColor(context, colorID));
|
||||
DrawableCompat.setTint(icon, color);
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tints the given drawable with the given color and returns it.
|
||||
*/
|
||||
@CheckResult
|
||||
public static Drawable tintDrawableWithColorRes(@NonNull final Context context,
|
||||
@DrawableRes final int drawableID,
|
||||
@ColorRes final int colorID) {
|
||||
return tintDrawable(context, drawableID, ContextCompat.getColor(context, colorID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tints the given drawable with the given tint list and returns it. Note that you
|
||||
* should no longer use the argument Drawable because the argument is not mutated
|
||||
|
@ -70,6 +70,12 @@
|
||||
<!ENTITY screenshot_folder_label_in_bookmarks "Screenshots">
|
||||
<!ENTITY readinglist_smartfolder_label_in_bookmarks "Reading List">
|
||||
|
||||
<!ENTITY reader_saved_offline "Saved offline">
|
||||
<!-- Localization note (reader_switch_to_bookmarks) : This
|
||||
string is used as an action in a snackbar - it lets you
|
||||
"switch" to the bookmarks (saved items) panel. -->
|
||||
<!ENTITY reader_switch_to_bookmarks "Switch">
|
||||
|
||||
<!ENTITY history_today_section "Today">
|
||||
<!ENTITY history_yesterday_section "Yesterday">
|
||||
<!ENTITY history_week_section3 "Last 7 days">
|
||||
|
@ -92,6 +92,9 @@
|
||||
<string name="screenshot_folder_label_in_bookmarks">&screenshot_folder_label_in_bookmarks;</string>
|
||||
<string name="readinglist_smartfolder_label_in_bookmarks">&readinglist_smartfolder_label_in_bookmarks;</string>
|
||||
|
||||
<string name="reader_saved_offline">&reader_saved_offline;</string>
|
||||
<string name="reader_switch_to_bookmarks">&reader_switch_to_bookmarks;</string>
|
||||
|
||||
<string name="history_today_section">&history_today_section;</string>
|
||||
<string name="history_yesterday_section">&history_yesterday_section;</string>
|
||||
<string name="history_week_section">&history_week_section3;</string>
|
||||
|
Loading…
Reference in New Issue
Block a user