Remove more uses of the static context from BrowserApp
This commit is contained in:
parent
a434c0af68
commit
930880b339
@ -196,7 +196,7 @@ public class ProxyUtils {
|
||||
break;
|
||||
|
||||
case Constants.PROXY_I2P:
|
||||
I2PAndroidHelper ih = new I2PAndroidHelper(BrowserApp.getContext());
|
||||
I2PAndroidHelper ih = new I2PAndroidHelper(BrowserApp.get(activity));
|
||||
if (!ih.isI2PAndroidInstalled()) {
|
||||
choice = Constants.NO_PROXY;
|
||||
ih.promptToInstall(activity);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package acr.browser.lightning.async;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
@ -23,13 +24,16 @@ import acr.browser.lightning.utils.Utils;
|
||||
public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
|
||||
|
||||
private static final String TAG = ImageDownloadTask.class.getSimpleName();
|
||||
private static final File mCacheDir = BrowserApp.getContext().getCacheDir();
|
||||
private final File mCacheDir;
|
||||
private final WeakReference<ImageView> bmImage;
|
||||
private final HistoryItem mWeb;
|
||||
private final String mUrl;
|
||||
private final Bitmap mDefaultBitmap;
|
||||
|
||||
public ImageDownloadTask(@NonNull ImageView bmImage, @NonNull HistoryItem web, @NonNull Bitmap defaultBitmap) {
|
||||
public ImageDownloadTask(@NonNull ImageView bmImage,
|
||||
@NonNull HistoryItem web,
|
||||
@NonNull Bitmap defaultBitmap,
|
||||
@NonNull Context context) {
|
||||
// Set a tag on the ImageView so we know if the view
|
||||
// has gone out of scope and should not be used
|
||||
bmImage.setTag(web.getUrl().hashCode());
|
||||
@ -37,6 +41,7 @@ public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
|
||||
this.mWeb = web;
|
||||
this.mUrl = web.getUrl();
|
||||
this.mDefaultBitmap = defaultBitmap;
|
||||
this.mCacheDir = BrowserApp.get(context).getCacheDir();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -368,7 +368,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
holder.favicon.setImageBitmap(mFolderBitmap);
|
||||
} else if (web.getBitmap() == null) {
|
||||
holder.favicon.setImageBitmap(mWebpageBitmap);
|
||||
new ImageDownloadTask(holder.favicon, web, mWebpageBitmap)
|
||||
new ImageDownloadTask(holder.favicon, web, mWebpageBitmap, context)
|
||||
.executeOnExecutor(AsyncExecutor.getInstance());
|
||||
} else {
|
||||
holder.favicon.setImageBitmap(web.getBitmap());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package acr.browser.lightning.object;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@ -93,7 +94,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
||||
mSearchSubtitle = mContext.getString(R.string.suggestion);
|
||||
mDarkTheme = dark || incognito;
|
||||
mIncognito = incognito;
|
||||
Thread delete = new Thread(new ClearCacheRunnable());
|
||||
Thread delete = new Thread(new ClearCacheRunnable(context));
|
||||
mSearchDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_search, mDarkTheme);
|
||||
mBookmarkDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_bookmark, mDarkTheme);
|
||||
mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme);
|
||||
@ -105,18 +106,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteOldCacheFiles() {
|
||||
File dir = new File(BrowserApp.getContext().getCacheDir().toString());
|
||||
String[] fileList = dir.list(new NameFilter());
|
||||
long earliestTimeAllowed = System.currentTimeMillis() - INTERVAL_DAY;
|
||||
for (String fileName : fileList) {
|
||||
File file = new File(dir.getPath() + fileName);
|
||||
if (earliestTimeAllowed > file.lastModified()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class NameFilter implements FilenameFilter {
|
||||
|
||||
@Override
|
||||
@ -220,9 +209,23 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
||||
|
||||
private static class ClearCacheRunnable implements Runnable {
|
||||
|
||||
private Context context;
|
||||
|
||||
public ClearCacheRunnable(Context context) {
|
||||
this.context = BrowserApp.get(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
deleteOldCacheFiles();
|
||||
File dir = new File(context.getCacheDir().toString());
|
||||
String[] fileList = dir.list(new NameFilter());
|
||||
long earliestTimeAllowed = System.currentTimeMillis() - INTERVAL_DAY;
|
||||
for (String fileName : fileList) {
|
||||
File file = new File(dir.getPath() + fileName);
|
||||
if (earliestTimeAllowed > file.lastModified()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -310,7 +313,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
File cache = downloadSuggestionsForQuery(query, mLanguage);
|
||||
File cache = downloadSuggestionsForQuery(query, mLanguage, BrowserApp.get(mContext));
|
||||
if (!cache.exists()) {
|
||||
return filter;
|
||||
}
|
||||
@ -372,12 +375,12 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
||||
* @param query the query to get suggestions for
|
||||
* @return the cache file containing the suggestions
|
||||
*/
|
||||
private static File downloadSuggestionsForQuery(String query, String language) {
|
||||
File cacheFile = new File(BrowserApp.getContext().getCacheDir(), query.hashCode() + CACHE_FILE_TYPE);
|
||||
private static File downloadSuggestionsForQuery(String query, String language, Application app) {
|
||||
File cacheFile = new File(app.getCacheDir(), query.hashCode() + CACHE_FILE_TYPE);
|
||||
if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) {
|
||||
return cacheFile;
|
||||
}
|
||||
if (!isNetworkConnected(BrowserApp.getContext())) {
|
||||
if (!isNetworkConnected(app)) {
|
||||
return cacheFile;
|
||||
}
|
||||
InputStream in = null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user