Revision 7fe62d1f
Added by Leszek Koltunski about 2 years ago
src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.dialogs; |
21 | 21 |
|
22 |
import java.lang.ref.WeakReference; |
|
23 |
|
|
22 | 24 |
import android.app.Activity; |
23 | 25 |
import android.graphics.Bitmap; |
24 | 26 |
import android.graphics.Color; |
... | ... | |
36 | 38 |
import org.distorted.external.RubikUpdates; |
37 | 39 |
import org.distorted.objects.RubikObjectList; |
38 | 40 |
|
39 |
import java.io.IOException; |
|
40 |
import java.lang.ref.WeakReference; |
|
41 |
|
|
42 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
43 | 42 |
|
44 | 43 |
public class RubikDialogUpdateView implements RubikNetwork.Downloadee |
... | ... | |
48 | 47 |
private ProgressBar mBar; |
49 | 48 |
private Button mButton; |
50 | 49 |
private TextView mDescription; |
51 |
|
|
52 | 50 |
private WeakReference<Activity> mAct; |
51 |
private boolean mIconSaved; |
|
53 | 52 |
|
54 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 54 |
|
56 | 55 |
public View createView(Activity act, RubikUpdates.UpdateInfo info, int fontSize, int padding, |
57 | 56 |
LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt ) |
58 | 57 |
{ |
58 |
mIconSaved=false; |
|
59 | 59 |
mAct = new WeakReference<>(act); |
60 | 60 |
mInfo = info; |
61 | 61 |
final RubikNetwork.Downloadee downloadee = this; |
... | ... | |
111 | 111 |
|
112 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
113 | 113 |
|
114 |
void setIcon(Bitmap icon) |
|
114 |
void setIcon(Bitmap icon, boolean downloaded)
|
|
115 | 115 |
{ |
116 | 116 |
mIcon.setImageBitmap(icon); |
117 |
|
|
118 |
if( downloaded ) |
|
119 |
{ |
|
120 |
String name = mInfo.mObjectShortName + ".png"; |
|
121 |
Activity act = mAct.get(); |
|
122 |
RubikFiles files = RubikFiles.getInstance(); |
|
123 |
mIconSaved = files.saveIcon(act,mInfo.mIcon, name); |
|
124 |
} |
|
117 | 125 |
} |
118 | 126 |
|
119 | 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
141 | 149 |
mDescription.setText(R.string.installing); |
142 | 150 |
|
143 | 151 |
RubikFiles files = RubikFiles.getInstance(); |
144 |
boolean iSuccess=true,oSuccess=true, eSuccess=true; |
|
145 |
|
|
146 |
if( mInfo.mIcon!=null ) |
|
147 |
{ |
|
148 |
String name = mInfo.mObjectShortName + ".png"; |
|
149 |
Activity act = mAct.get(); |
|
150 |
iSuccess = files.saveFile(act,mInfo.mIcon, name); |
|
151 |
} |
|
152 |
boolean oSuccess=true, eSuccess=true; |
|
152 | 153 |
|
153 | 154 |
if( mInfo.mObjectStream!=null ) |
154 | 155 |
{ |
... | ... | |
164 | 165 |
eSuccess = files.saveFile(act,mInfo.mExtrasStream, name); |
165 | 166 |
} |
166 | 167 |
|
167 |
if( iSuccess && oSuccess )
|
|
168 |
if( mIconSaved || oSuccess || eSuccess )
|
|
168 | 169 |
{ |
169 | 170 |
mBar.setProgress(75); |
170 | 171 |
mDescription.setText(R.string.configuring); |
171 |
RubikObjectList.addDownloadedObject(mInfo.mObjectShortName,iSuccess,oSuccess,eSuccess);
|
|
172 |
RubikObjectList.addDownloadedObject(mInfo.mObjectShortName,mIconSaved,oSuccess,eSuccess);
|
|
172 | 173 |
mBar.setProgress(100); |
173 | 174 |
mDescription.setText(R.string.success); |
174 | 175 |
|
Also available in: Unified diff
Download the icons only once and save to local storage.