AttachmentDownloader.java
6.29 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
package net.hockeyapp.android.tasks;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Message;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.LinkedList;
import java.util.Queue;
import net.hockeyapp.android.Constants;
import net.hockeyapp.android.objects.FeedbackAttachment;
import net.hockeyapp.android.utils.AsyncTaskUtils;
import net.hockeyapp.android.utils.HockeyLog;
import net.hockeyapp.android.utils.ImageUtils;
import net.hockeyapp.android.views.AttachmentView;
public class AttachmentDownloader
{
private Queue<b> a = new LinkedList();
private boolean b = false;
private void a()
{
if (this.b) {}
do
{
return;
localObject = (b)this.a.peek();
} while (localObject == null);
Object localObject = new c((b)localObject, new Handler()
{
public final void handleMessage(final Message paramAnonymousMessage)
{
paramAnonymousMessage = (AttachmentDownloader.b)AttachmentDownloader.a(AttachmentDownloader.this).poll();
if (!paramAnonymousMessage.c)
{
i = paramAnonymousMessage.d - 1;
paramAnonymousMessage.d = i;
if (i >= 0) {
break label78;
}
}
label78:
for (int i = 0;; i = 1)
{
if (i != 0) {
postDelayed(new Runnable()
{
public final void run()
{
AttachmentDownloader.a(AttachmentDownloader.this).add(paramAnonymousMessage);
AttachmentDownloader.b(AttachmentDownloader.this);
}
}, 3000L);
}
AttachmentDownloader.c(AttachmentDownloader.this);
AttachmentDownloader.b(AttachmentDownloader.this);
return;
}
}
});
this.b = true;
AsyncTaskUtils.execute((AsyncTask)localObject);
}
public static AttachmentDownloader getInstance()
{
return a.a;
}
public void download(FeedbackAttachment paramFeedbackAttachment, AttachmentView paramAttachmentView)
{
this.a.add(new b(paramFeedbackAttachment, paramAttachmentView, (byte)0));
a();
}
static final class a
{
public static final AttachmentDownloader a = new AttachmentDownloader((byte)0);
}
static final class b
{
final FeedbackAttachment a;
final AttachmentView b;
boolean c;
int d;
private b(FeedbackAttachment paramFeedbackAttachment, AttachmentView paramAttachmentView)
{
this.a = paramFeedbackAttachment;
this.b = paramAttachmentView;
this.c = false;
this.d = 2;
}
}
static final class c
extends AsyncTask<Void, Integer, Boolean>
{
private final AttachmentDownloader.b a;
private final Handler b;
private File c;
private Bitmap d;
private int e;
public c(AttachmentDownloader.b paramb, Handler paramHandler)
{
this.a = paramb;
this.b = paramHandler;
this.c = Constants.getHockeyAppStorageDir();
this.d = null;
this.e = 0;
}
private Boolean a()
{
FeedbackAttachment localFeedbackAttachment = this.a.a;
if (localFeedbackAttachment.isAvailableInCache())
{
HockeyLog.error("Cached...");
b();
return Boolean.valueOf(true);
}
HockeyLog.error("Downloading...");
boolean bool = a(localFeedbackAttachment.getUrl(), localFeedbackAttachment.getCacheId());
if (bool) {
b();
}
return Boolean.valueOf(bool);
}
private boolean a(String paramString1, String paramString2)
{
long l;
try
{
paramString1 = (HttpURLConnection)new URL(paramString1).openConnection();
paramString1.addRequestProperty("User-Agent", "HockeySDK/Android");
paramString1.setInstanceFollowRedirects(true);
if (Build.VERSION.SDK_INT <= 9) {
paramString1.setRequestProperty("connection", "close");
}
paramString1.connect();
int i = paramString1.getContentLength();
Object localObject = paramString1.getHeaderField("Status");
if ((localObject != null) && (!((String)localObject).startsWith("200"))) {
return false;
}
paramString2 = new File(this.c, paramString2);
paramString1 = new BufferedInputStream(paramString1.getInputStream());
paramString2 = new FileOutputStream(paramString2);
localObject = new byte['Ѐ'];
l = 0L;
for (;;)
{
int j = paramString1.read((byte[])localObject);
if (j == -1) {
break;
}
l += j;
publishProgress(new Integer[] { Integer.valueOf((int)(100L * l / i)) });
paramString2.write((byte[])localObject, 0, j);
}
paramString2.flush();
}
catch (IOException paramString1)
{
paramString1.printStackTrace();
return false;
}
paramString2.close();
paramString1.close();
return l > 0L;
}
private void b()
{
try
{
String str = this.a.a.getCacheId();
AttachmentView localAttachmentView = this.a.b;
this.e = ImageUtils.determineOrientation(new File(this.c, str));
int i;
if (this.e == 1)
{
i = localAttachmentView.getWidthLandscape();
if (this.e != 1) {
break label98;
}
}
label98:
for (int j = localAttachmentView.getMaxHeightLandscape();; j = localAttachmentView.getMaxHeightPortrait())
{
this.d = ImageUtils.decodeSampledBitmap(new File(this.c, str), i, j);
return;
i = localAttachmentView.getWidthPortrait();
break;
}
return;
}
catch (IOException localIOException)
{
localIOException.printStackTrace();
this.d = null;
}
}
protected final void onPreExecute() {}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/net/hockeyapp/android/tasks/AttachmentDownloader.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/