I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 293e51c1 authored by zzz's avatar zzz
Browse files

- Reverse content URI back to I2P URI in WVC so we can load it

  there instead of via the provider
- Several reload fixes
parent 448d74e1
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ import android.widget.Toast;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
......@@ -46,6 +47,15 @@ class I2PWebViewClient extends WebViewClient {
view.stopLoading();
Uri uri = Uri.parse(url);
if (CONTENT.equals(uri.getScheme())) {
try {
//reverse back to a i2p URI so we can load it here and not in ContentProvider
uri = CacheProvider.getI2PUri(uri);
url = uri.toString();
Util.e("Reversed content uri back to " + url);
AppCache.getInstance(view.getContext()).removeCacheFile(uri);
} catch (FileNotFoundException fnfe) {}
}
String s = uri.getScheme();
if (s == null) {
fail(view, "Bad URL " + url);
......@@ -162,10 +172,17 @@ class I2PWebViewClient extends WebViewClient {
String url = view.getUrl();
Uri uri = Uri.parse(url);
if (CONTENT.equals(uri.getScheme())) {
// this actually only deletes the row in the provider,
// not the actual file, but it will be overwritten in the reload.
Util.e("clearing provider entry for current page " + url);
view.getContext().getContentResolver().delete(uri, null, null);
try {
//reverse back to a i2p URI so we can delete it from the AppCache
uri = CacheProvider.getI2PUri(uri);
Util.e("clearing AppCache entry for current page " + uri);
AppCache.getInstance(view.getContext()).removeCacheFile(uri);
} catch (FileNotFoundException fnfe) {
// this actually only deletes the row in the provider,
// not the actual file, but it will be overwritten in the reload.
Util.e("clearing provider entry for current page " + url);
view.getContext().getContentResolver().delete(uri, null, null);
}
}
}
......
......@@ -100,9 +100,16 @@ public class WebActivity extends I2PActivityBase {
case R.id.menu_reload:
_wvClient.cancelAll();
wv.stopLoading();
_wvClient.deleteCurrentPageCache(wv);
// should go through the WVC instead??
wv.reload();
String url = wv.getUrl();
Uri uri = Uri.parse(url);
if ("data".equals(uri.getScheme())) {
// welcome page... or just do nothing ?
wv.reload();
} else {
// wv.reload() doesn't call shouldOverrideUrlLoading(), so do it this way
_wvClient.deleteCurrentPageCache(wv);
_wvClient.shouldOverrideUrlLoading(wv, url);
}
return true;
default:
......
......@@ -137,7 +137,7 @@ public class CacheProvider extends ContentProvider {
* @return non-null
* @throws FNFE on error
*/
private static Uri getI2PUri(Uri uri) throws FileNotFoundException {
public static Uri getI2PUri(Uri uri) throws FileNotFoundException {
String resPath = uri.getEncodedPath();
if (resPath == null)
throw new FileNotFoundException("Bad uri no path? " + uri);
......
......@@ -17,6 +17,7 @@ import java.util.List;
import java.util.Map;
import net.i2p.android.router.provider.CacheProvider;
import net.i2p.android.router.util.Util;
/**
* A least recently used cache with a max number of entries
......@@ -286,11 +287,12 @@ public class AppCache {
@Override
public Object remove(Object key) {
Object rv = super.remove(key);
if (rv != null && key instanceof Integer) {
if ( /* rv != null && */ key instanceof Integer) {
File f = toFile(((Integer)key).intValue());
if (f.exists()) {
_totalSize -= f.length();
f.delete();
Util.e("AppCache deleted file " + f);
}
}
return rv;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment