MediaCache.java
9.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package com.bitstrips.imoji.persistence;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
import android.widget.ImageView;
import com.bitstrips.imoji.injection.ForApplication;
import com.squareup.picasso.Callback;
import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Picasso.Builder;
import com.squareup.picasso.RequestCreator;
import hj;
import hk;
import hk.a;
import hl;
import hm;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class MediaCache
{
@VisibleForTesting
boolean a = false;
@VisibleForTesting
final ConcurrentHashMap<String, String> b = new ConcurrentHashMap();
@VisibleForTesting
hl c;
private final Context d;
private final Picasso e;
private final Handler f;
private final hj g;
@Inject
public MediaCache(@ForApplication Context paramContext)
{
this(paramContext, new hj(paramContext), new Handler(paramContext.getMainLooper()));
}
private MediaCache(Context paramContext, hj paramhj, Handler paramHandler)
{
this.d = paramContext;
this.e = new Picasso.Builder(paramContext).addRequestHandler(new ImageFileRequestHandler(paramContext)).downloader(new hm(this, paramContext)).build();
this.g = paramhj;
this.f = paramHandler;
new a().execute(new Void[0]);
}
public void cancelRequest(ImageView paramImageView)
{
this.e.cancelRequest(paramImageView);
}
public void flush()
{
this.f.post(new Runnable()
{
public final void run()
{
MediaCache.this.b.clear();
if (MediaCache.this.a)
{
hl localhl = MediaCache.this.c;
localhl.c.clear();
localhl.a(new hk(hk.a.c, null, null));
}
}
});
}
@Nullable
public File getCachedImage(@NonNull String paramString)
{
Object localObject = String.valueOf(paramString.hashCode());
if (!paramString.equals((String)this.b.get(localObject))) {
paramString = null;
}
do
{
return paramString;
localObject = new File(this.d.getCacheDir(), (String)localObject);
paramString = (String)localObject;
} while (((File)localObject).exists());
return null;
}
public RequestCreator load(@NonNull Uri paramUri)
{
return load(paramUri.toString());
}
public RequestCreator load(@NonNull String paramString)
{
File localFile = getCachedImage(paramString);
if (localFile != null) {
return this.e.load(localFile);
}
return this.e.load(paramString);
}
public void preload(@NonNull String paramString)
{
preload(paramString, null);
}
public void preload(@NonNull String paramString, @Nullable Callback paramCallback)
{
load(paramString).resize(1, 1).memoryPolicy(MemoryPolicy.NO_STORE, new MemoryPolicy[0]).fetch(paramCallback);
}
public void shutdown()
{
this.f.post(new Runnable()
{
public final void run()
{
if (MediaCache.this.a)
{
hl localhl = MediaCache.this.c;
localhl.d = true;
if (localhl.e == null) {
localhl.a.close();
}
}
}
});
}
@WorkerThread
public File storeMediaData(@NonNull final String paramString, @NonNull InputStream paramInputStream)
{
final String str = String.valueOf(paramString.hashCode());
File localFile = new File(this.d.getCacheDir(), str);
try
{
BufferedOutputStream localBufferedOutputStream = new BufferedOutputStream(new FileOutputStream(localFile, false));
byte[] arrayOfByte = new byte['Ѐ'];
for (;;)
{
int i = paramInputStream.read(arrayOfByte);
if (i == -1) {
break;
}
localBufferedOutputStream.write(arrayOfByte, 0, i);
}
localBufferedOutputStream.close();
this.f.post(new Runnable()
{
public final void run()
{
MediaCache.a(MediaCache.this, str, paramString);
}
});
return localFile;
}
catch (IOException paramString) {}
return null;
}
@VisibleForTesting
final class a
extends AsyncTask<Void, Void, Void>
{
a() {}
/* Error */
private Void a()
{
// Byte code:
// 0: aload_0
// 1: getfield 14 com/bitstrips/imoji/persistence/MediaCache$a:a Lcom/bitstrips/imoji/persistence/MediaCache;
// 4: invokestatic 24 com/bitstrips/imoji/persistence/MediaCache:a (Lcom/bitstrips/imoji/persistence/MediaCache;)Lhj;
// 7: invokevirtual 30 hj:getWritableDatabase ()Landroid/database/sqlite/SQLiteDatabase;
// 10: astore_2
// 11: aload_0
// 12: getfield 14 com/bitstrips/imoji/persistence/MediaCache$a:a Lcom/bitstrips/imoji/persistence/MediaCache;
// 15: invokestatic 24 com/bitstrips/imoji/persistence/MediaCache:a (Lcom/bitstrips/imoji/persistence/MediaCache;)Lhj;
// 18: astore_1
// 19: aload_0
// 20: getfield 14 com/bitstrips/imoji/persistence/MediaCache$a:a Lcom/bitstrips/imoji/persistence/MediaCache;
// 23: getfield 34 com/bitstrips/imoji/persistence/MediaCache:b Ljava/util/concurrent/ConcurrentHashMap;
// 26: astore_3
// 27: aload_2
// 28: aload_1
// 29: getfield 37 hj:a Lcom/bitstrips/imoji/persistence/MediaCacheTable;
// 32: invokevirtual 43 com/bitstrips/imoji/persistence/MediaCacheTable:getName ()Ljava/lang/String;
// 35: getstatic 47 com/bitstrips/imoji/persistence/MediaCacheTable:PROJECTION [Ljava/lang/String;
// 38: aconst_null
// 39: aconst_null
// 40: aconst_null
// 41: aconst_null
// 42: aconst_null
// 43: invokevirtual 53 android/database/sqlite/SQLiteDatabase:query (Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;
// 46: astore_1
// 47: aload_1
// 48: invokeinterface 59 1 0
// 53: ifeq +62 -> 115
// 56: aload_3
// 57: aload_1
// 58: iconst_0
// 59: invokeinterface 63 2 0
// 64: aload_1
// 65: iconst_1
// 66: invokeinterface 63 2 0
// 71: invokeinterface 69 3 0
// 76: pop
// 77: goto -30 -> 47
// 80: astore_3
// 81: aload_1
// 82: ifnull +9 -> 91
// 85: aload_1
// 86: invokeinterface 72 1 0
// 91: aload_0
// 92: getfield 14 com/bitstrips/imoji/persistence/MediaCache$a:a Lcom/bitstrips/imoji/persistence/MediaCache;
// 95: new 74 hl
// 98: dup
// 99: aload_2
// 100: aload_0
// 101: getfield 14 com/bitstrips/imoji/persistence/MediaCache$a:a Lcom/bitstrips/imoji/persistence/MediaCache;
// 104: invokestatic 24 com/bitstrips/imoji/persistence/MediaCache:a (Lcom/bitstrips/imoji/persistence/MediaCache;)Lhj;
// 107: invokespecial 77 hl:<init> (Landroid/database/sqlite/SQLiteDatabase;Lhj;)V
// 110: putfield 81 com/bitstrips/imoji/persistence/MediaCache:c Lhl;
// 113: aconst_null
// 114: areturn
// 115: aload_1
// 116: ifnull -25 -> 91
// 119: aload_1
// 120: invokeinterface 72 1 0
// 125: goto -34 -> 91
// 128: aload_1
// 129: ifnull +9 -> 138
// 132: aload_1
// 133: invokeinterface 72 1 0
// 138: aload_2
// 139: athrow
// 140: astore_2
// 141: goto -13 -> 128
// 144: astore_1
// 145: aconst_null
// 146: astore_1
// 147: goto -66 -> 81
// 150: astore_1
// 151: aconst_null
// 152: areturn
// 153: astore_2
// 154: aconst_null
// 155: astore_1
// 156: goto -28 -> 128
// Local variable table:
// start length slot name signature
// 0 159 0 this a
// 18 115 1 localObject1 Object
// 144 1 1 localSQLiteException1 android.database.sqlite.SQLiteException
// 146 1 1 localObject2 Object
// 150 1 1 localSQLiteException2 android.database.sqlite.SQLiteException
// 155 1 1 localObject3 Object
// 10 129 2 localSQLiteDatabase SQLiteDatabase
// 140 1 2 localObject4 Object
// 153 1 2 localObject5 Object
// 26 31 3 localConcurrentHashMap ConcurrentHashMap
// 80 1 3 localSQLiteException3 android.database.sqlite.SQLiteException
// Exception table:
// from to target type
// 47 77 80 android/database/sqlite/SQLiteException
// 47 77 140 finally
// 27 47 144 android/database/sqlite/SQLiteException
// 0 27 150 android/database/sqlite/SQLiteException
// 85 91 150 android/database/sqlite/SQLiteException
// 91 113 150 android/database/sqlite/SQLiteException
// 119 125 150 android/database/sqlite/SQLiteException
// 132 138 150 android/database/sqlite/SQLiteException
// 138 140 150 android/database/sqlite/SQLiteException
// 27 47 153 finally
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/bitstrips/imoji/persistence/MediaCache.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/