Remove snackbar event bus message
This commit is contained in:
parent
3d0788e650
commit
a6b755e6c4
@ -2247,13 +2247,5 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void displayInSnackbar(final BrowserEvents.ShowSnackBarMessage event) {
|
||||
if (event.message != null) {
|
||||
Utils.showSnackbar(BrowserActivity.this, event.message);
|
||||
} else {
|
||||
Utils.showSnackbar(BrowserActivity.this, event.stringRes);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -9,25 +9,6 @@ public final class BrowserEvents {
|
||||
// No instances
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the Browser to display a SnackBar in the main activity
|
||||
*/
|
||||
public static class ShowSnackBarMessage {
|
||||
@Nullable public final String message;
|
||||
@StringRes
|
||||
public final int stringRes;
|
||||
|
||||
public ShowSnackBarMessage(@Nullable final String message) {
|
||||
this.message = message;
|
||||
this.stringRes = -1;
|
||||
}
|
||||
|
||||
public ShowSnackBarMessage(@StringRes final int stringRes) {
|
||||
this.message = null;
|
||||
this.stringRes = stringRes;
|
||||
}
|
||||
}
|
||||
|
||||
public final static class OpenHistoryInCurrentTab {
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
*/
|
||||
package acr.browser.lightning.download;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@ -35,6 +36,7 @@ import acr.browser.lightning.bus.BrowserEvents;
|
||||
import acr.browser.lightning.constant.Constants;
|
||||
import acr.browser.lightning.dialog.BrowserDialog;
|
||||
import acr.browser.lightning.preference.PreferenceManager;
|
||||
import acr.browser.lightning.utils.Utils;
|
||||
|
||||
/**
|
||||
* Handle download requests
|
||||
@ -67,7 +69,7 @@ public class DownloadHandler {
|
||||
* @param contentDisposition Content-disposition http header, if present.
|
||||
* @param mimetype The mimetype of the content reported by the server
|
||||
*/
|
||||
public static void onDownloadStart(@NonNull Context context, @NonNull PreferenceManager manager, String url, String userAgent,
|
||||
public static void onDownloadStart(@NonNull Activity context, @NonNull PreferenceManager manager, String url, String userAgent,
|
||||
@Nullable String contentDisposition, String mimetype) {
|
||||
|
||||
Log.d(TAG, "DOWNLOAD: Trying to download from URL: " + url);
|
||||
@ -153,7 +155,7 @@ public class DownloadHandler {
|
||||
* @param mimetype The mimetype of the content reported by the server
|
||||
*/
|
||||
/* package */
|
||||
private static void onDownloadStartNoStream(@NonNull final Context context, @NonNull PreferenceManager preferences,
|
||||
private static void onDownloadStartNoStream(@NonNull final Activity context, @NonNull PreferenceManager preferences,
|
||||
String url, String userAgent,
|
||||
String contentDisposition, @Nullable String mimetype) {
|
||||
final Bus eventBus = BrowserApp.getBus(context);
|
||||
@ -191,7 +193,7 @@ public class DownloadHandler {
|
||||
// This only happens for very bad urls, we want to catch the
|
||||
// exception here
|
||||
Log.e(TAG, "Exception while trying to parse url '" + url + '\'', e);
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_download));
|
||||
Utils.showSnackbar(context, R.string.problem_download);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -201,7 +203,7 @@ public class DownloadHandler {
|
||||
try {
|
||||
request = new DownloadManager.Request(uri);
|
||||
} catch (IllegalArgumentException e) {
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download));
|
||||
Utils.showSnackbar(context, R.string.cannot_download);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -216,12 +218,12 @@ public class DownloadHandler {
|
||||
File dir = new File(downloadFolder.getPath());
|
||||
if (!dir.isDirectory() && !dir.mkdirs()) {
|
||||
// Cannot make the directory
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
|
||||
Utils.showSnackbar(context, R.string.problem_location_download);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isWriteAccessAvailable(downloadFolder)) {
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
|
||||
Utils.showSnackbar(context, R.string.problem_location_download);
|
||||
return;
|
||||
}
|
||||
String newMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(guessFileExtension(filename));
|
||||
@ -257,14 +259,13 @@ public class DownloadHandler {
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Probably got a bad URL or something
|
||||
Log.e(TAG, "Unable to enqueue request", e);
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download));
|
||||
Utils.showSnackbar(context, R.string.cannot_download);
|
||||
} catch (SecurityException e) {
|
||||
// TODO write a download utility that downloads files rather than rely on the system
|
||||
// because the system can only handle Environment.getExternal... as a path
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
|
||||
Utils.showSnackbar(context, R.string.problem_location_download);
|
||||
}
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(
|
||||
context.getString(R.string.download_pending) + ' ' + filename));
|
||||
Utils.showSnackbar(context, context.getString(R.string.download_pending) + ' ' + filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
*/
|
||||
package acr.browser.lightning.download;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
@ -21,6 +22,7 @@ import java.net.URL;
|
||||
import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.app.BrowserApp;
|
||||
import acr.browser.lightning.bus.BrowserEvents;
|
||||
import acr.browser.lightning.utils.Utils;
|
||||
|
||||
/**
|
||||
* This class is used to pull down the http headers of a given URL so that we
|
||||
@ -34,13 +36,13 @@ class FetchUrlMimeType extends Thread {
|
||||
|
||||
private static final String TAG = FetchUrlMimeType.class.getSimpleName();
|
||||
|
||||
private final Context mContext;
|
||||
private final Activity mContext;
|
||||
private final DownloadManager.Request mRequest;
|
||||
private final String mUri;
|
||||
private final String mCookies;
|
||||
private final String mUserAgent;
|
||||
|
||||
public FetchUrlMimeType(Context context, DownloadManager.Request request, String uri,
|
||||
public FetchUrlMimeType(Activity context, DownloadManager.Request request, String uri,
|
||||
String cookies, String userAgent) {
|
||||
mContext = context;
|
||||
mRequest = request;
|
||||
@ -115,7 +117,7 @@ class FetchUrlMimeType extends Thread {
|
||||
Schedulers.main().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download));
|
||||
Utils.showSnackbar(mContext, R.string.cannot_download);
|
||||
}
|
||||
});
|
||||
} catch (SecurityException e) {
|
||||
@ -124,7 +126,7 @@ class FetchUrlMimeType extends Thread {
|
||||
Schedulers.main().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
|
||||
Utils.showSnackbar(mContext, R.string.problem_location_download);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -133,7 +135,7 @@ class FetchUrlMimeType extends Thread {
|
||||
Schedulers.main().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(mContext.getString(R.string.download_pending) + ' ' + file));
|
||||
Utils.showSnackbar(mContext, mContext.getString(R.string.download_pending) + ' ' + file);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -146,13 +146,13 @@ public class ProxyUtils {
|
||||
|
||||
}
|
||||
|
||||
public boolean isProxyReady() {
|
||||
public boolean isProxyReady(@NonNull Activity activity) {
|
||||
if (mPreferences.getProxyChoice() == Constants.PROXY_I2P) {
|
||||
if (!mI2PHelper.isI2PAndroidRunning()) {
|
||||
mBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.i2p_not_running));
|
||||
Utils.showSnackbar(activity, R.string.i2p_not_running);
|
||||
return false;
|
||||
} else if (!mI2PHelper.areTunnelsActive()) {
|
||||
mBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.i2p_tunnels_not_ready));
|
||||
Utils.showSnackbar(activity, R.string.i2p_tunnels_not_ready);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -796,7 +796,7 @@ public class LightningView {
|
||||
*/
|
||||
public synchronized void reload() {
|
||||
// Check if configured proxy is available
|
||||
if (!mProxyUtils.isProxyReady()) {
|
||||
if (!mProxyUtils.isProxyReady(mActivity)) {
|
||||
// User has been notified
|
||||
return;
|
||||
}
|
||||
@ -1052,7 +1052,7 @@ public class LightningView {
|
||||
*/
|
||||
public synchronized void loadUrl(@NonNull String url) {
|
||||
// Check if configured proxy is available
|
||||
if (!mProxyUtils.isProxyReady()) {
|
||||
if (!mProxyUtils.isProxyReady(mActivity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -292,7 +292,7 @@ public class LightningWebClient extends WebViewClient {
|
||||
|
||||
private boolean shouldOverrideLoading(WebView view, String url) {
|
||||
// Check if configured proxy is available
|
||||
if (!mProxyUtils.isProxyReady()) {
|
||||
if (!mProxyUtils.isProxyReady(mActivity)) {
|
||||
// User has been notified
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user