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
|
// 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 {
|
public final static class OpenHistoryInCurrentTab {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package acr.browser.lightning.download;
|
package acr.browser.lightning.download;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DownloadManager;
|
import android.app.DownloadManager;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
@ -35,6 +36,7 @@ import acr.browser.lightning.bus.BrowserEvents;
|
|||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.dialog.BrowserDialog;
|
import acr.browser.lightning.dialog.BrowserDialog;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
|
import acr.browser.lightning.utils.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle download requests
|
* Handle download requests
|
||||||
@ -67,7 +69,7 @@ public class DownloadHandler {
|
|||||||
* @param contentDisposition Content-disposition http header, if present.
|
* @param contentDisposition Content-disposition http header, if present.
|
||||||
* @param mimetype The mimetype of the content reported by the server
|
* @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) {
|
@Nullable String contentDisposition, String mimetype) {
|
||||||
|
|
||||||
Log.d(TAG, "DOWNLOAD: Trying to download from URL: " + url);
|
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
|
* @param mimetype The mimetype of the content reported by the server
|
||||||
*/
|
*/
|
||||||
/* package */
|
/* 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 url, String userAgent,
|
||||||
String contentDisposition, @Nullable String mimetype) {
|
String contentDisposition, @Nullable String mimetype) {
|
||||||
final Bus eventBus = BrowserApp.getBus(context);
|
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
|
// This only happens for very bad urls, we want to catch the
|
||||||
// exception here
|
// exception here
|
||||||
Log.e(TAG, "Exception while trying to parse url '" + url + '\'', e);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +203,7 @@ public class DownloadHandler {
|
|||||||
try {
|
try {
|
||||||
request = new DownloadManager.Request(uri);
|
request = new DownloadManager.Request(uri);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download));
|
Utils.showSnackbar(context, R.string.cannot_download);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,12 +218,12 @@ public class DownloadHandler {
|
|||||||
File dir = new File(downloadFolder.getPath());
|
File dir = new File(downloadFolder.getPath());
|
||||||
if (!dir.isDirectory() && !dir.mkdirs()) {
|
if (!dir.isDirectory() && !dir.mkdirs()) {
|
||||||
// Cannot make the directory
|
// Cannot make the directory
|
||||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
|
Utils.showSnackbar(context, R.string.problem_location_download);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isWriteAccessAvailable(downloadFolder)) {
|
if (!isWriteAccessAvailable(downloadFolder)) {
|
||||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
|
Utils.showSnackbar(context, R.string.problem_location_download);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String newMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(guessFileExtension(filename));
|
String newMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(guessFileExtension(filename));
|
||||||
@ -257,14 +259,13 @@ public class DownloadHandler {
|
|||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// Probably got a bad URL or something
|
// Probably got a bad URL or something
|
||||||
Log.e(TAG, "Unable to enqueue request", e);
|
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) {
|
} catch (SecurityException e) {
|
||||||
// TODO write a download utility that downloads files rather than rely on the system
|
// 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
|
// 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(
|
Utils.showSnackbar(context, context.getString(R.string.download_pending) + ' ' + filename);
|
||||||
context.getString(R.string.download_pending) + ' ' + filename));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package acr.browser.lightning.download;
|
package acr.browser.lightning.download;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.DownloadManager;
|
import android.app.DownloadManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
@ -21,6 +22,7 @@ import java.net.URL;
|
|||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
import acr.browser.lightning.bus.BrowserEvents;
|
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
|
* 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 static final String TAG = FetchUrlMimeType.class.getSimpleName();
|
||||||
|
|
||||||
private final Context mContext;
|
private final Activity mContext;
|
||||||
private final DownloadManager.Request mRequest;
|
private final DownloadManager.Request mRequest;
|
||||||
private final String mUri;
|
private final String mUri;
|
||||||
private final String mCookies;
|
private final String mCookies;
|
||||||
private final String mUserAgent;
|
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) {
|
String cookies, String userAgent) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mRequest = request;
|
mRequest = request;
|
||||||
@ -115,7 +117,7 @@ class FetchUrlMimeType extends Thread {
|
|||||||
Schedulers.main().execute(new Runnable() {
|
Schedulers.main().execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download));
|
Utils.showSnackbar(mContext, R.string.cannot_download);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
@ -124,7 +126,7 @@ class FetchUrlMimeType extends Thread {
|
|||||||
Schedulers.main().execute(new Runnable() {
|
Schedulers.main().execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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() {
|
Schedulers.main().execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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 (mPreferences.getProxyChoice() == Constants.PROXY_I2P) {
|
||||||
if (!mI2PHelper.isI2PAndroidRunning()) {
|
if (!mI2PHelper.isI2PAndroidRunning()) {
|
||||||
mBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.i2p_not_running));
|
Utils.showSnackbar(activity, R.string.i2p_not_running);
|
||||||
return false;
|
return false;
|
||||||
} else if (!mI2PHelper.areTunnelsActive()) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -796,7 +796,7 @@ public class LightningView {
|
|||||||
*/
|
*/
|
||||||
public synchronized void reload() {
|
public synchronized void reload() {
|
||||||
// Check if configured proxy is available
|
// Check if configured proxy is available
|
||||||
if (!mProxyUtils.isProxyReady()) {
|
if (!mProxyUtils.isProxyReady(mActivity)) {
|
||||||
// User has been notified
|
// User has been notified
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1052,7 +1052,7 @@ public class LightningView {
|
|||||||
*/
|
*/
|
||||||
public synchronized void loadUrl(@NonNull String url) {
|
public synchronized void loadUrl(@NonNull String url) {
|
||||||
// Check if configured proxy is available
|
// Check if configured proxy is available
|
||||||
if (!mProxyUtils.isProxyReady()) {
|
if (!mProxyUtils.isProxyReady(mActivity)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ public class LightningWebClient extends WebViewClient {
|
|||||||
|
|
||||||
private boolean shouldOverrideLoading(WebView view, String url) {
|
private boolean shouldOverrideLoading(WebView view, String url) {
|
||||||
// Check if configured proxy is available
|
// Check if configured proxy is available
|
||||||
if (!mProxyUtils.isProxyReady()) {
|
if (!mProxyUtils.isProxyReady(mActivity)) {
|
||||||
// User has been notified
|
// User has been notified
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user