fdroidclient / F-Droid / src / org / fdroid / fdroid / AppDetails.java @ 9b7c4c7b
History | View | Annotate | Download (67.6 KB)
1 |
/*
|
---|---|
2 |
* Copyright (C) 2010-12 Ciaran Gultnieks, ciaran@ciarang.com
|
3 |
* Copyright (C) 2013-15 Daniel Martí <mvdan@mvdan.cc>
|
4 |
* Copyright (C) 2013 Stefan Völkel, bd@bc-bd.org
|
5 |
* Copyright (C) 2015 Nico Alt, nicoalt@posteo.org
|
6 |
*
|
7 |
* This program is free software; you can redistribute it and/or
|
8 |
* modify it under the terms of the GNU General Public License
|
9 |
* as published by the Free Software Foundation; either version 3
|
10 |
* of the License, or (at your option) any later version.
|
11 |
*
|
12 |
* This program is distributed in the hope that it will be useful,
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
* GNU General Public License for more details.
|
16 |
*
|
17 |
* You should have received a copy of the GNU General Public License
|
18 |
* along with this program; if not, write to the Free Software
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
20 |
*/
|
21 |
|
22 |
package org.fdroid.fdroid; |
23 |
|
24 |
import android.app.Activity; |
25 |
import android.app.DownloadManager; |
26 |
import android.bluetooth.BluetoothAdapter; |
27 |
import android.content.ActivityNotFoundException; |
28 |
import android.content.BroadcastReceiver; |
29 |
import android.content.ContentValues; |
30 |
import android.content.Context; |
31 |
import android.content.DialogInterface; |
32 |
import android.content.Intent; |
33 |
import android.content.IntentFilter; |
34 |
import android.content.pm.PackageInfo; |
35 |
import android.content.pm.PackageManager; |
36 |
import android.content.pm.Signature; |
37 |
import android.database.ContentObserver; |
38 |
import android.database.Cursor; |
39 |
import android.graphics.Bitmap; |
40 |
import android.net.Uri; |
41 |
import android.os.Bundle; |
42 |
import android.os.Handler; |
43 |
import android.support.annotation.NonNull; |
44 |
import android.support.annotation.Nullable; |
45 |
import android.support.v4.app.Fragment; |
46 |
import android.support.v4.app.ListFragment; |
47 |
import android.support.v4.app.NavUtils; |
48 |
import android.support.v4.content.LocalBroadcastManager; |
49 |
import android.support.v4.view.MenuItemCompat; |
50 |
import android.support.v7.app.AlertDialog; |
51 |
import android.support.v7.app.AppCompatActivity; |
52 |
import android.text.Html; |
53 |
import android.text.Layout; |
54 |
import android.text.Selection; |
55 |
import android.text.Spannable; |
56 |
import android.text.Spanned; |
57 |
import android.text.TextUtils; |
58 |
import android.text.format.DateFormat; |
59 |
import android.text.method.LinkMovementMethod; |
60 |
import android.text.style.ClickableSpan; |
61 |
import android.util.Log; |
62 |
import android.view.LayoutInflater; |
63 |
import android.view.Menu; |
64 |
import android.view.MenuItem; |
65 |
import android.view.MotionEvent; |
66 |
import android.view.View; |
67 |
import android.view.ViewGroup; |
68 |
import android.view.Window; |
69 |
import android.widget.ArrayAdapter; |
70 |
import android.widget.Button; |
71 |
import android.widget.FrameLayout; |
72 |
import android.widget.ImageButton; |
73 |
import android.widget.ImageView; |
74 |
import android.widget.LinearLayout; |
75 |
import android.widget.ListView; |
76 |
import android.widget.ProgressBar; |
77 |
import android.widget.TextView; |
78 |
import android.widget.Toast; |
79 |
|
80 |
import com.nostra13.universalimageloader.core.DisplayImageOptions; |
81 |
import com.nostra13.universalimageloader.core.ImageLoader; |
82 |
import com.nostra13.universalimageloader.core.assist.ImageScaleType; |
83 |
|
84 |
import org.fdroid.fdroid.Utils.CommaSeparatedList; |
85 |
import org.fdroid.fdroid.compat.PackageManagerCompat; |
86 |
import org.fdroid.fdroid.data.Apk; |
87 |
import org.fdroid.fdroid.data.ApkProvider; |
88 |
import org.fdroid.fdroid.data.App; |
89 |
import org.fdroid.fdroid.data.AppProvider; |
90 |
import org.fdroid.fdroid.data.InstalledAppProvider; |
91 |
import org.fdroid.fdroid.data.Repo; |
92 |
import org.fdroid.fdroid.data.RepoProvider; |
93 |
import org.fdroid.fdroid.installer.Installer; |
94 |
import org.fdroid.fdroid.installer.Installer.AndroidNotCompatibleException; |
95 |
import org.fdroid.fdroid.installer.Installer.InstallerCallback; |
96 |
import org.fdroid.fdroid.net.ApkDownloader; |
97 |
import org.fdroid.fdroid.net.AsyncDownloader; |
98 |
import org.fdroid.fdroid.net.Downloader; |
99 |
|
100 |
import java.io.File; |
101 |
import java.security.NoSuchAlgorithmException; |
102 |
import java.text.DecimalFormat; |
103 |
import java.util.Iterator; |
104 |
import java.util.List; |
105 |
|
106 |
interface AppDetailsData { |
107 |
App getApp(); |
108 |
AppDetails.ApkListAdapter getApks(); |
109 |
Signature getInstalledSignature();
|
110 |
String getInstalledSignatureId();
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* Interface which allows the apk list fragment to communicate with the activity when
|
115 |
* a user requests to install/remove an apk by clicking on an item in the list.
|
116 |
*
|
117 |
* NOTE: This is <em>not</em> to do with with the sudo/packagemanager/other installer
|
118 |
* stuff which allows multiple ways to install apps. It is only here to make fragment-
|
119 |
* activity communication possible.
|
120 |
*/
|
121 |
interface AppInstallListener { |
122 |
void install(final Apk apk); |
123 |
void removeApk(String packageName); |
124 |
} |
125 |
|
126 |
public class AppDetails extends AppCompatActivity implements ProgressListener, AppDetailsData, AppInstallListener { |
127 |
|
128 |
private static final String TAG = "AppDetails"; |
129 |
|
130 |
public static final int REQUEST_ENABLE_BLUETOOTH = 2; |
131 |
|
132 |
public static final String EXTRA_APPID = "appid"; |
133 |
public static final String EXTRA_FROM = "from"; |
134 |
|
135 |
private FDroidApp fdroidApp;
|
136 |
private ApkListAdapter adapter;
|
137 |
|
138 |
private static class ViewHolder { |
139 |
TextView version; |
140 |
TextView status; |
141 |
TextView size; |
142 |
TextView api; |
143 |
TextView incompatibleReasons; |
144 |
TextView buildtype; |
145 |
TextView added; |
146 |
TextView nativecode; |
147 |
} |
148 |
|
149 |
// observer to update view when package has been installed/deleted
|
150 |
AppObserver myAppObserver; |
151 |
|
152 |
class AppObserver extends ContentObserver { |
153 |
|
154 |
public AppObserver(Handler handler) { |
155 |
super(handler);
|
156 |
} |
157 |
|
158 |
@Override
|
159 |
public void onChange(boolean selfChange) { |
160 |
onChange(selfChange, null);
|
161 |
} |
162 |
|
163 |
@Override
|
164 |
public void onChange(boolean selfChange, Uri uri) { |
165 |
onAppChanged(); |
166 |
} |
167 |
|
168 |
} |
169 |
|
170 |
class ApkListAdapter extends ArrayAdapter<Apk> { |
171 |
|
172 |
private final LayoutInflater mInflater = (LayoutInflater) mctx.getSystemService( |
173 |
Context.LAYOUT_INFLATER_SERVICE);
|
174 |
|
175 |
public ApkListAdapter(Context context, App app) { |
176 |
super(context, 0); |
177 |
final List<Apk> apks = ApkProvider.Helper.findByApp(context, app.id); |
178 |
for (final Apk apk : apks) { |
179 |
if (apk.compatible || Preferences.get().showIncompatibleVersions()) { |
180 |
add(apk); |
181 |
} |
182 |
} |
183 |
} |
184 |
|
185 |
private String getInstalledStatus(final Apk apk) { |
186 |
// Definitely not installed.
|
187 |
if (apk.vercode != app.installedVersionCode) {
|
188 |
return getString(R.string.not_inst);
|
189 |
} |
190 |
// Definitely installed this version.
|
191 |
if (mInstalledSigID != null && apk.sig != null |
192 |
&& apk.sig.equals(mInstalledSigID)) { |
193 |
return getString(R.string.inst);
|
194 |
} |
195 |
// Installed the same version, but from someplace else.
|
196 |
final String installerPkgName; |
197 |
try {
|
198 |
installerPkgName = mPm.getInstallerPackageName(app.id); |
199 |
} catch (IllegalArgumentException e) { |
200 |
Log.w(TAG, "Application " + app.id + " is not installed anymore"); |
201 |
return getString(R.string.not_inst);
|
202 |
} |
203 |
if (TextUtils.isEmpty(installerPkgName)) {
|
204 |
return getString(R.string.inst_unknown_source);
|
205 |
} |
206 |
final String installerLabel = InstalledAppProvider |
207 |
.getApplicationLabel(mctx, installerPkgName); |
208 |
return getString(R.string.inst_known_source, installerLabel);
|
209 |
} |
210 |
|
211 |
@Override
|
212 |
public View getView(int position, View convertView, ViewGroup parent) { |
213 |
|
214 |
java.text.DateFormat df = DateFormat.getDateFormat(mctx);
|
215 |
final Apk apk = getItem(position);
|
216 |
ViewHolder holder; |
217 |
|
218 |
if (convertView == null) { |
219 |
convertView = mInflater.inflate(R.layout.apklistitem, parent, false);
|
220 |
|
221 |
holder = new ViewHolder();
|
222 |
holder.version = (TextView) convertView.findViewById(R.id.version); |
223 |
holder.status = (TextView) convertView.findViewById(R.id.status); |
224 |
holder.size = (TextView) convertView.findViewById(R.id.size); |
225 |
holder.api = (TextView) convertView.findViewById(R.id.api); |
226 |
holder.incompatibleReasons = (TextView) convertView.findViewById(R.id.incompatible_reasons); |
227 |
holder.buildtype = (TextView) convertView.findViewById(R.id.buildtype); |
228 |
holder.added = (TextView) convertView.findViewById(R.id.added); |
229 |
holder.nativecode = (TextView) convertView.findViewById(R.id.nativecode); |
230 |
|
231 |
convertView.setTag(holder); |
232 |
} else {
|
233 |
holder = (ViewHolder) convertView.getTag(); |
234 |
} |
235 |
|
236 |
holder.version.setText(getString(R.string.version) |
237 |
+ " " + apk.version
|
238 |
+ (apk.vercode == app.suggestedVercode ? " ☆" : "")); |
239 |
|
240 |
holder.status.setText(getInstalledStatus(apk)); |
241 |
|
242 |
if (apk.size > 0) { |
243 |
holder.size.setText(Utils.getFriendlySize(apk.size)); |
244 |
holder.size.setVisibility(View.VISIBLE);
|
245 |
} else {
|
246 |
holder.size.setVisibility(View.GONE);
|
247 |
} |
248 |
|
249 |
if (!Preferences.get().expertMode()) { |
250 |
holder.api.setVisibility(View.GONE);
|
251 |
} else if (apk.minSdkVersion > 0 && apk.maxSdkVersion > 0) { |
252 |
holder.api.setText(getString(R.string.minsdk_up_to_maxsdk, |
253 |
Utils.getAndroidVersionName(apk.minSdkVersion), |
254 |
Utils.getAndroidVersionName(apk.maxSdkVersion))); |
255 |
holder.api.setVisibility(View.VISIBLE);
|
256 |
} else if (apk.minSdkVersion > 0) { |
257 |
holder.api.setText(getString(R.string.minsdk_or_later, |
258 |
Utils.getAndroidVersionName(apk.minSdkVersion))); |
259 |
holder.api.setVisibility(View.VISIBLE);
|
260 |
} else if (apk.maxSdkVersion > 0) { |
261 |
holder.api.setText(getString(R.string.up_to_maxsdk, |
262 |
Utils.getAndroidVersionName(apk.maxSdkVersion))); |
263 |
holder.api.setVisibility(View.VISIBLE);
|
264 |
} |
265 |
|
266 |
if (apk.srcname != null) { |
267 |
holder.buildtype.setText("source");
|
268 |
} else {
|
269 |
holder.buildtype.setText("bin");
|
270 |
} |
271 |
|
272 |
if (apk.added != null) { |
273 |
holder.added.setText(getString(R.string.added_on, |
274 |
df.format(apk.added))); |
275 |
holder.added.setVisibility(View.VISIBLE);
|
276 |
} else {
|
277 |
holder.added.setVisibility(View.GONE);
|
278 |
} |
279 |
|
280 |
if (Preferences.get().expertMode() && apk.nativecode != null) { |
281 |
holder.nativecode.setText(apk.nativecode.toString().replaceAll(","," ")); |
282 |
holder.nativecode.setVisibility(View.VISIBLE);
|
283 |
} else {
|
284 |
holder.nativecode.setVisibility(View.GONE);
|
285 |
} |
286 |
|
287 |
if (apk.incompatible_reasons != null) { |
288 |
holder.incompatibleReasons.setText( |
289 |
getResources().getString( |
290 |
R.string.requires_features, |
291 |
apk.incompatible_reasons.toPrettyString())); |
292 |
holder.incompatibleReasons.setVisibility(View.VISIBLE);
|
293 |
} else {
|
294 |
holder.incompatibleReasons.setVisibility(View.GONE);
|
295 |
} |
296 |
|
297 |
// Disable it all if it isn't compatible...
|
298 |
final View[] views = { |
299 |
convertView, |
300 |
holder.version, |
301 |
holder.status, |
302 |
holder.size, |
303 |
holder.api, |
304 |
holder.buildtype, |
305 |
holder.added, |
306 |
holder.nativecode |
307 |
}; |
308 |
|
309 |
for (final View v : views) { |
310 |
v.setEnabled(apk.compatible); |
311 |
} |
312 |
|
313 |
return convertView;
|
314 |
} |
315 |
} |
316 |
|
317 |
private static final int INSTALL = Menu.FIRST; |
318 |
private static final int UNINSTALL = Menu.FIRST + 1; |
319 |
private static final int IGNOREALL = Menu.FIRST + 2; |
320 |
private static final int IGNORETHIS = Menu.FIRST + 3; |
321 |
private static final int LAUNCH = Menu.FIRST + 4; |
322 |
private static final int SHARE = Menu.FIRST + 5; |
323 |
private static final int SEND_VIA_BLUETOOTH = Menu.FIRST + 6; |
324 |
|
325 |
private App app;
|
326 |
private PackageManager mPm;
|
327 |
private ApkDownloader downloadHandler;
|
328 |
private LocalBroadcastManager localBroadcastManager;
|
329 |
|
330 |
private boolean startingIgnoreAll; |
331 |
private int startingIgnoreThis; |
332 |
|
333 |
private final Context mctx = this; |
334 |
private Installer installer;
|
335 |
|
336 |
|
337 |
private AppDetailsHeaderFragment mHeaderFragment;
|
338 |
|
339 |
/**
|
340 |
* Stores relevant data that we want to keep track of when destroying the activity
|
341 |
* with the expectation of it being recreated straight away (e.g. after an
|
342 |
* orientation change). One of the major things is that we want the download thread
|
343 |
* to stay active, but for it not to trigger any UI stuff (e.g. progress bar)
|
344 |
* between the activity being destroyed and recreated.
|
345 |
*/
|
346 |
private static class ConfigurationChangeHelper { |
347 |
|
348 |
public final ApkDownloader downloader; |
349 |
public final App app; |
350 |
|
351 |
public ConfigurationChangeHelper(ApkDownloader downloader, App app) {
|
352 |
this.downloader = downloader;
|
353 |
this.app = app;
|
354 |
} |
355 |
} |
356 |
|
357 |
private boolean inProcessOfChangingConfiguration = false; |
358 |
|
359 |
/**
|
360 |
* Attempt to extract the appId from the intent which launched this activity.
|
361 |
* @return May return null, if we couldn't find the appId. This should
|
362 |
* never happen as AppDetails is only to be called by the FDroid activity
|
363 |
* and not externally.
|
364 |
*/
|
365 |
private String getAppIdFromIntent() { |
366 |
Intent i = getIntent(); |
367 |
if (!i.hasExtra(EXTRA_APPID)) {
|
368 |
Log.e(TAG, "No application ID found in the intent!");
|
369 |
return null; |
370 |
} |
371 |
|
372 |
return i.getStringExtra(EXTRA_APPID);
|
373 |
} |
374 |
|
375 |
@Override
|
376 |
protected void onCreate(Bundle savedInstanceState) { |
377 |
|
378 |
fdroidApp = ((FDroidApp) getApplication()); |
379 |
fdroidApp.applyTheme(this);
|
380 |
|
381 |
super.onCreate(savedInstanceState);
|
382 |
|
383 |
// Must be called *after* super.onCreate(), as that is where the action bar
|
384 |
// compat implementation is assigned in the ActionBarActivity base class.
|
385 |
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
386 |
|
387 |
if (getIntent().hasExtra(EXTRA_FROM)) {
|
388 |
setTitle(getIntent().getStringExtra(EXTRA_FROM)); |
389 |
} |
390 |
|
391 |
mPm = getPackageManager(); |
392 |
|
393 |
installer = Installer.getActivityInstaller(this, mPm, myInstallerCallback);
|
394 |
|
395 |
// Get the preferences we're going to use in this Activity...
|
396 |
ConfigurationChangeHelper previousData = (ConfigurationChangeHelper)getLastCustomNonConfigurationInstance(); |
397 |
if (previousData != null) { |
398 |
Utils.DebugLog(TAG, "Recreating view after configuration change.");
|
399 |
downloadHandler = previousData.downloader; |
400 |
if (downloadHandler != null) { |
401 |
Utils.DebugLog(TAG, "Download was in progress before the configuration change, so we will start to listen to its events again.");
|
402 |
} |
403 |
app = previousData.app; |
404 |
setApp(app); |
405 |
} else {
|
406 |
if (!reset(getAppIdFromIntent())) {
|
407 |
finish(); |
408 |
return;
|
409 |
} |
410 |
} |
411 |
|
412 |
// Set up the list...
|
413 |
adapter = new ApkListAdapter(this, app); |
414 |
|
415 |
// Wait until all other intialization before doing this, because it will create the
|
416 |
// fragments, which rely on data from the activity that is set earlier in this method.
|
417 |
setContentView(R.layout.app_details); |
418 |
|
419 |
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
420 |
|
421 |
// Check for the presence of a view which only exists in the landscape view.
|
422 |
// This seems to be the preferred way to interrogate the view, rather than
|
423 |
// to check the orientation. I guess this is because views can be dynamically
|
424 |
// chosen based on more than just orientation (e.g. large screen sizes).
|
425 |
View onlyInLandscape = findViewById(R.id.app_summary_container);
|
426 |
|
427 |
AppDetailsListFragment listFragment = |
428 |
(AppDetailsListFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_app_list); |
429 |
if (onlyInLandscape == null) { |
430 |
listFragment.setupSummaryHeader(); |
431 |
} else {
|
432 |
listFragment.removeSummaryHeader(); |
433 |
} |
434 |
|
435 |
localBroadcastManager = LocalBroadcastManager.getInstance(this);
|
436 |
|
437 |
// Check if a download is running for this app
|
438 |
if (AsyncDownloader.isDownloading(this, app.id) >= 0) { |
439 |
// call install() to re-setup the listeners and downloaders
|
440 |
// the AsyncDownloader will not restart the download since the download is running,
|
441 |
// and thus the version we pass to install() is not important
|
442 |
refreshHeader(); |
443 |
refreshApkList(); |
444 |
final Apk apkToInstall = ApkProvider.Helper.find(this, app.id, app.suggestedVercode); |
445 |
install(apkToInstall); |
446 |
} |
447 |
|
448 |
} |
449 |
|
450 |
// The signature of the installed version.
|
451 |
private Signature mInstalledSignature; |
452 |
private String mInstalledSigID; |
453 |
|
454 |
@Override
|
455 |
protected void onStart() { |
456 |
super.onStart();
|
457 |
// register observer to know when install status changes
|
458 |
myAppObserver = new AppObserver(new Handler()); |
459 |
getContentResolver().registerContentObserver( |
460 |
AppProvider.getContentUri(app.id), |
461 |
true,
|
462 |
myAppObserver); |
463 |
} |
464 |
|
465 |
@Override
|
466 |
protected void onResumeFragments() { |
467 |
super.onResumeFragments();
|
468 |
refreshApkList(); |
469 |
refreshHeader(); |
470 |
supportInvalidateOptionsMenu(); |
471 |
|
472 |
if (downloadHandler != null) { |
473 |
if (downloadHandler.isComplete()) {
|
474 |
downloadCompleteInstallApk(); |
475 |
} else {
|
476 |
localBroadcastManager.registerReceiver(downloaderProgressReceiver, |
477 |
new IntentFilter(Downloader.LOCAL_ACTION_PROGRESS));
|
478 |
downloadHandler.setProgressListener(this);
|
479 |
|
480 |
if (downloadHandler.getTotalBytes() == 0) |
481 |
mHeaderFragment.startProgress(); |
482 |
else
|
483 |
mHeaderFragment.updateProgress(downloadHandler.getBytesRead(), downloadHandler.getTotalBytes()); |
484 |
} |
485 |
} |
486 |
} |
487 |
|
488 |
/**
|
489 |
* Remove progress listener, suppress progress bar, set downloadHandler to null.
|
490 |
*/
|
491 |
private void cleanUpFinishedDownload() { |
492 |
if (downloadHandler != null) { |
493 |
downloadHandler.removeProgressListener(); |
494 |
mHeaderFragment.removeProgress(); |
495 |
downloadHandler = null;
|
496 |
} |
497 |
} |
498 |
|
499 |
/**
|
500 |
* Once the download completes successfully, call this method to start the install process
|
501 |
* with the file that was downloaded.
|
502 |
*/
|
503 |
private void downloadCompleteInstallApk() { |
504 |
if (downloadHandler != null) { |
505 |
installApk(downloadHandler.localFile()); |
506 |
cleanUpFinishedDownload(); |
507 |
} |
508 |
} |
509 |
|
510 |
protected void onStop() { |
511 |
super.onStop();
|
512 |
getContentResolver().unregisterContentObserver(myAppObserver); |
513 |
} |
514 |
|
515 |
@Override
|
516 |
protected void onPause() { |
517 |
super.onPause();
|
518 |
if (app != null && (app.ignoreAllUpdates != startingIgnoreAll |
519 |
|| app.ignoreThisUpdate != startingIgnoreThis)) { |
520 |
Utils.DebugLog(TAG, "Updating 'ignore updates', as it has changed since we started the activity...");
|
521 |
setIgnoreUpdates(app.id, app.ignoreAllUpdates, app.ignoreThisUpdate); |
522 |
} |
523 |
|
524 |
localBroadcastManager.unregisterReceiver(downloaderProgressReceiver); |
525 |
if (downloadHandler != null) { |
526 |
downloadHandler.removeProgressListener(); |
527 |
} |
528 |
|
529 |
mHeaderFragment.removeProgress(); |
530 |
} |
531 |
|
532 |
private final BroadcastReceiver downloaderProgressReceiver = new BroadcastReceiver() { |
533 |
@Override
|
534 |
public void onReceive(Context context, Intent intent) { |
535 |
if (mHeaderFragment != null) |
536 |
mHeaderFragment.updateProgress(intent.getIntExtra(Downloader.EXTRA_BYTES_READ, -1),
|
537 |
intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, -1));
|
538 |
} |
539 |
}; |
540 |
|
541 |
private void onAppChanged() { |
542 |
if (!reset(app.id)) {
|
543 |
AppDetails.this.finish(); |
544 |
return;
|
545 |
} |
546 |
|
547 |
refreshApkList(); |
548 |
refreshHeader(); |
549 |
supportInvalidateOptionsMenu(); |
550 |
} |
551 |
|
552 |
public void setIgnoreUpdates(String appId, boolean ignoreAll, int ignoreVersionCode) { |
553 |
|
554 |
Uri uri = AppProvider.getContentUri(appId); |
555 |
|
556 |
ContentValues values = new ContentValues(2); |
557 |
values.put(AppProvider.DataColumns.IGNORE_ALLUPDATES, ignoreAll ? 1 : 0); |
558 |
values.put(AppProvider.DataColumns.IGNORE_THISUPDATE, ignoreVersionCode); |
559 |
|
560 |
getContentResolver().update(uri, values, null, null); |
561 |
|
562 |
} |
563 |
|
564 |
|
565 |
@Override
|
566 |
public Object onRetainCustomNonConfigurationInstance() { |
567 |
inProcessOfChangingConfiguration = true;
|
568 |
return new ConfigurationChangeHelper(downloadHandler, app); |
569 |
} |
570 |
|
571 |
@Override
|
572 |
protected void onDestroy() { |
573 |
if (downloadHandler != null) { |
574 |
if (!inProcessOfChangingConfiguration) {
|
575 |
downloadHandler.cancel(false);
|
576 |
cleanUpFinishedDownload(); |
577 |
} |
578 |
} |
579 |
inProcessOfChangingConfiguration = false;
|
580 |
super.onDestroy();
|
581 |
} |
582 |
|
583 |
// Reset the display and list contents. Used when entering the activity, and
|
584 |
// also when something has been installed/uninstalled.
|
585 |
// Return true if the app was found, false otherwise.
|
586 |
private boolean reset(String appId) { |
587 |
|
588 |
Utils.DebugLog(TAG, "Getting application details for " + appId);
|
589 |
App newApp = null;
|
590 |
|
591 |
if (!TextUtils.isEmpty(appId)) {
|
592 |
newApp = AppProvider.Helper.findById(getContentResolver(), appId); |
593 |
} |
594 |
|
595 |
setApp(newApp); |
596 |
|
597 |
return this.app != null; |
598 |
} |
599 |
|
600 |
/**
|
601 |
* If passed null, this will show a message to the user ("Could not find app ..." or something
|
602 |
* like that) and then finish the activity.
|
603 |
*/
|
604 |
private void setApp(App newApp) { |
605 |
|
606 |
if (newApp == null) { |
607 |
Toast.makeText(this, R.string.no_such_app, Toast.LENGTH_LONG).show();
|
608 |
finish(); |
609 |
return;
|
610 |
} |
611 |
|
612 |
app = newApp; |
613 |
|
614 |
startingIgnoreAll = app.ignoreAllUpdates; |
615 |
startingIgnoreThis = app.ignoreThisUpdate; |
616 |
|
617 |
// Get the signature of the installed package...
|
618 |
mInstalledSignature = null;
|
619 |
mInstalledSigID = null;
|
620 |
|
621 |
if (app.isInstalled()) {
|
622 |
PackageManager pm = getPackageManager(); |
623 |
try {
|
624 |
PackageInfo pi = pm.getPackageInfo(app.id, PackageManager.GET_SIGNATURES); |
625 |
mInstalledSignature = pi.signatures[0];
|
626 |
Hasher hash = new Hasher("MD5", mInstalledSignature.toCharsString().getBytes()); |
627 |
mInstalledSigID = hash.getHash(); |
628 |
} catch (PackageManager.NameNotFoundException e) {
|
629 |
Log.w(TAG, "Failed to get installed signature");
|
630 |
} catch (NoSuchAlgorithmException e) { |
631 |
Log.w(TAG, "Failed to calculate signature MD5 sum");
|
632 |
mInstalledSignature = null;
|
633 |
} |
634 |
} |
635 |
} |
636 |
|
637 |
private void refreshApkList() { |
638 |
adapter.notifyDataSetChanged(); |
639 |
} |
640 |
|
641 |
private void refreshHeader() { |
642 |
mHeaderFragment = (AppDetailsHeaderFragment) |
643 |
getSupportFragmentManager().findFragmentById(R.id.header); |
644 |
mHeaderFragment.updateViews(); |
645 |
} |
646 |
|
647 |
@Override
|
648 |
public boolean onPrepareOptionsMenu(Menu menu) { |
649 |
super.onPrepareOptionsMenu(menu);
|
650 |
menu.clear(); |
651 |
if (app == null) |
652 |
return true; |
653 |
|
654 |
MenuItemCompat.setShowAsAction(menu.add( |
655 |
Menu.NONE, SHARE, 1, R.string.menu_share) |
656 |
.setIcon(R.drawable.ic_share_white), |
657 |
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | |
658 |
MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); |
659 |
|
660 |
if (app.isInstalled()) {
|
661 |
MenuItemCompat.setShowAsAction(menu.add( |
662 |
Menu.NONE, UNINSTALL, 1, R.string.menu_uninstall) |
663 |
.setIcon(R.drawable.ic_delete_white), |
664 |
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | |
665 |
MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); |
666 |
} |
667 |
|
668 |
if (mPm.getLaunchIntentForPackage(app.id) != null && app.canAndWantToUpdate()) { |
669 |
MenuItemCompat.setShowAsAction(menu.add( |
670 |
Menu.NONE, LAUNCH, 1, R.string.menu_launch) |
671 |
.setIcon(R.drawable.ic_play_arrow_white), |
672 |
MenuItemCompat.SHOW_AS_ACTION_ALWAYS | |
673 |
MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); |
674 |
} |
675 |
|
676 |
menu.add(Menu.NONE, IGNOREALL, 2, R.string.menu_ignore_all) |
677 |
.setIcon(R.drawable.ic_do_not_disturb_white) |
678 |
.setCheckable(true)
|
679 |
.setChecked(app.ignoreAllUpdates); |
680 |
|
681 |
if (app.hasUpdates()) {
|
682 |
menu.add(Menu.NONE, IGNORETHIS, 2, R.string.menu_ignore_this) |
683 |
.setIcon(R.drawable.ic_do_not_disturb_white) |
684 |
.setCheckable(true)
|
685 |
.setChecked(app.ignoreThisUpdate >= app.suggestedVercode); |
686 |
} |
687 |
|
688 |
// Ignore on devices without Bluetooth
|
689 |
if (app.isInstalled() && fdroidApp.bluetoothAdapter != null) { |
690 |
menu.add(Menu.NONE, SEND_VIA_BLUETOOTH, 3, R.string.send_via_bluetooth) |
691 |
.setIcon(R.drawable.ic_bluetooth_white); |
692 |
} |
693 |
return true; |
694 |
} |
695 |
|
696 |
|
697 |
private void tryOpenUri(String s) { |
698 |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
|
699 |
if (intent.resolveActivity(getPackageManager()) == null) { |
700 |
Toast.makeText(this,
|
701 |
getString(R.string.no_handler_app, intent.getDataString()), |
702 |
Toast.LENGTH_LONG).show(); |
703 |
return;
|
704 |
} |
705 |
startActivity(intent); |
706 |
} |
707 |
|
708 |
private static class SafeLinkMovementMethod extends LinkMovementMethod { |
709 |
|
710 |
private static SafeLinkMovementMethod instance; |
711 |
|
712 |
private final Context ctx; |
713 |
|
714 |
private SafeLinkMovementMethod(Context ctx) { |
715 |
this.ctx = ctx;
|
716 |
} |
717 |
|
718 |
public static SafeLinkMovementMethod getInstance(Context ctx) { |
719 |
if (instance == null) { |
720 |
instance = new SafeLinkMovementMethod(ctx);
|
721 |
} |
722 |
return instance;
|
723 |
} |
724 |
|
725 |
private static CharSequence getLink(TextView widget, Spannable buffer, |
726 |
MotionEvent event) { |
727 |
int x = (int) event.getX(); |
728 |
int y = (int) event.getY(); |
729 |
x -= widget.getTotalPaddingLeft(); |
730 |
y -= widget.getTotalPaddingTop(); |
731 |
x += widget.getScrollX(); |
732 |
y += widget.getScrollY(); |
733 |
|
734 |
Layout layout = widget.getLayout(); |
735 |
final int line = layout.getLineForVertical(y); |
736 |
final int off = layout.getOffsetForHorizontal(line, x); |
737 |
final ClickableSpan[] links = buffer.getSpans(off, off, ClickableSpan.class); |
738 |
|
739 |
if (links.length > 0) { |
740 |
final ClickableSpan link = links[0]; |
741 |
final Spanned s = (Spanned) widget.getText();
|
742 |
return s.subSequence(s.getSpanStart(link), s.getSpanEnd(link));
|
743 |
} |
744 |
return "null"; |
745 |
} |
746 |
|
747 |
@Override
|
748 |
public boolean onTouchEvent(@NonNull TextView widget, @NonNull Spannable buffer, |
749 |
@NonNull MotionEvent event) {
|
750 |
try {
|
751 |
return super.onTouchEvent(widget, buffer, event); |
752 |
} catch (ActivityNotFoundException ex) {
|
753 |
Selection.removeSelection(buffer); |
754 |
final CharSequence link = getLink(widget, buffer, event); |
755 |
Toast.makeText(ctx, |
756 |
ctx.getString(R.string.no_handler_app, link), |
757 |
Toast.LENGTH_LONG).show(); |
758 |
return true; |
759 |
} |
760 |
} |
761 |
|
762 |
} |
763 |
|
764 |
protected void navigateUp() { |
765 |
NavUtils.navigateUpFromSameTask(this);
|
766 |
} |
767 |
|
768 |
@Override
|
769 |
public boolean onOptionsItemSelected(MenuItem item) { |
770 |
|
771 |
switch (item.getItemId()) {
|
772 |
|
773 |
case android.R.id.home:
|
774 |
navigateUp(); |
775 |
return true; |
776 |
|
777 |
case LAUNCH:
|
778 |
launchApk(app.id); |
779 |
return true; |
780 |
|
781 |
case SHARE:
|
782 |
shareApp(app); |
783 |
return true; |
784 |
|
785 |
case INSTALL:
|
786 |
// Note that this handles updating as well as installing.
|
787 |
if (app.suggestedVercode > 0) { |
788 |
final Apk apkToInstall = ApkProvider.Helper.find(this, app.id, app.suggestedVercode); |
789 |
install(apkToInstall); |
790 |
} |
791 |
return true; |
792 |
|
793 |
case UNINSTALL:
|
794 |
removeApk(app.id); |
795 |
return true; |
796 |
|
797 |
case IGNOREALL:
|
798 |
app.ignoreAllUpdates ^= true;
|
799 |
item.setChecked(app.ignoreAllUpdates); |
800 |
return true; |
801 |
|
802 |
case IGNORETHIS:
|
803 |
if (app.ignoreThisUpdate >= app.suggestedVercode)
|
804 |
app.ignoreThisUpdate = 0;
|
805 |
else
|
806 |
app.ignoreThisUpdate = app.suggestedVercode; |
807 |
item.setChecked(app.ignoreThisUpdate > 0);
|
808 |
return true; |
809 |
|
810 |
case SEND_VIA_BLUETOOTH:
|
811 |
/*
|
812 |
* If Bluetooth has not been enabled/turned on, then
|
813 |
* enabling device discoverability will automatically enable Bluetooth
|
814 |
*/
|
815 |
Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
|
816 |
discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121);
|
817 |
startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH); |
818 |
// if this is successful, the Bluetooth transfer is started
|
819 |
return true; |
820 |
|
821 |
} |
822 |
return super.onOptionsItemSelected(item); |
823 |
} |
824 |
|
825 |
// Install the version of this app denoted by 'app.curApk'.
|
826 |
@Override
|
827 |
public void install(final Apk apk) { |
828 |
// Ignore call if another download is running.
|
829 |
if (downloadHandler != null && !downloadHandler.isComplete()) |
830 |
return;
|
831 |
|
832 |
final String repoaddress = getRepoAddress(apk); |
833 |
if (repoaddress == null) return; |
834 |
|
835 |
if (!apk.compatible) {
|
836 |
AlertDialog.Builder ask_alrt = new AlertDialog.Builder(this); |
837 |
ask_alrt.setMessage(R.string.installIncompatible); |
838 |
ask_alrt.setPositiveButton(R.string.yes, |
839 |
new DialogInterface.OnClickListener() {
|
840 |
@Override
|
841 |
public void onClick(DialogInterface dialog, |
842 |
int whichButton) {
|
843 |
startDownload(apk, repoaddress); |
844 |
} |
845 |
}); |
846 |
ask_alrt.setNegativeButton(R.string.no, |
847 |
new DialogInterface.OnClickListener() {
|
848 |
@Override
|
849 |
public void onClick(DialogInterface dialog, |
850 |
int whichButton) {
|
851 |
} |
852 |
}); |
853 |
AlertDialog alert = ask_alrt.create(); |
854 |
alert.show(); |
855 |
return;
|
856 |
} |
857 |
if (mInstalledSigID != null && apk.sig != null |
858 |
&& !apk.sig.equals(mInstalledSigID)) { |
859 |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
860 |
builder.setMessage(R.string.SignatureMismatch).setPositiveButton( |
861 |
R.string.ok, |
862 |
new DialogInterface.OnClickListener() {
|
863 |
@Override
|
864 |
public void onClick(DialogInterface dialog, int id) { |
865 |
dialog.cancel(); |
866 |
} |
867 |
}); |
868 |
AlertDialog alert = builder.create(); |
869 |
alert.show(); |
870 |
return;
|
871 |
} |
872 |
startDownload(apk, repoaddress); |
873 |
} |
874 |
|
875 |
@Nullable
|
876 |
private String getRepoAddress(Apk apk) { |
877 |
final String[] projection = { RepoProvider.DataColumns.ADDRESS }; |
878 |
Repo repo = RepoProvider.Helper.findById(this, apk.repo, projection);
|
879 |
if (repo == null || repo.address == null) { |
880 |
return null; |
881 |
} |
882 |
return repo.address;
|
883 |
} |
884 |
|
885 |
private void startDownload(Apk apk, String repoAddress) { |
886 |
downloadHandler = new ApkDownloader(getBaseContext(), app, apk, repoAddress);
|
887 |
localBroadcastManager.registerReceiver(downloaderProgressReceiver, |
888 |
new IntentFilter(Downloader.LOCAL_ACTION_PROGRESS));
|
889 |
downloadHandler.setProgressListener(this);
|
890 |
if (downloadHandler.download()) {
|
891 |
mHeaderFragment.startProgress(); |
892 |
} |
893 |
} |
894 |
|
895 |
private void installApk(File file) { |
896 |
try {
|
897 |
installer.installPackage(file); |
898 |
} catch (AndroidNotCompatibleException e) {
|
899 |
Log.e(TAG, "Android not compatible with this Installer!", e);
|
900 |
} |
901 |
} |
902 |
|
903 |
@Override
|
904 |
public void removeApk(String packageName) { |
905 |
try {
|
906 |
installer.deletePackage(packageName); |
907 |
} catch (AndroidNotCompatibleException e) {
|
908 |
Log.e(TAG, "Android not compatible with this Installer!", e);
|
909 |
} |
910 |
} |
911 |
|
912 |
final Installer.InstallerCallback myInstallerCallback = new Installer.InstallerCallback() { |
913 |
|
914 |
@Override
|
915 |
public void onSuccess(final int operation) { |
916 |
runOnUiThread(new Runnable() { |
917 |
@Override
|
918 |
public void run() { |
919 |
if (operation == Installer.InstallerCallback.OPERATION_INSTALL) {
|
920 |
PackageManagerCompat.setInstaller(mPm, app.id); |
921 |
} |
922 |
|
923 |
onAppChanged(); |
924 |
} |
925 |
}); |
926 |
} |
927 |
|
928 |
@Override
|
929 |
public void onError(int operation, final int errorCode) { |
930 |
if (errorCode == InstallerCallback.ERROR_CODE_CANCELED) {
|
931 |
return;
|
932 |
} |
933 |
final int title, body; |
934 |
if (operation == InstallerCallback.OPERATION_INSTALL) {
|
935 |
title = R.string.install_error_title; |
936 |
switch (errorCode) {
|
937 |
case ERROR_CODE_CANNOT_PARSE:
|
938 |
body = R.string.install_error_cannot_parse; |
939 |
break;
|
940 |
default: // ERROR_CODE_OTHER |
941 |
body = R.string.install_error_unknown; |
942 |
break;
|
943 |
} |
944 |
} else { // InstallerCallback.OPERATION_DELETE |
945 |
title = R.string.uninstall_error_title; |
946 |
switch (errorCode) {
|
947 |
default: // ERROR_CODE_OTHER |
948 |
body = R.string.install_error_unknown; |
949 |
break;
|
950 |
} |
951 |
} |
952 |
runOnUiThread(new Runnable() { |
953 |
@Override
|
954 |
public void run() { |
955 |
onAppChanged(); |
956 |
|
957 |
Log.e(TAG, "Installer aborted with errorCode: " + errorCode);
|
958 |
|
959 |
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(AppDetails.this);
|
960 |
alertBuilder.setTitle(title); |
961 |
alertBuilder.setMessage(body); |
962 |
alertBuilder.setNeutralButton(android.R.string.ok, null);
|
963 |
alertBuilder.create().show(); |
964 |
} |
965 |
}); |
966 |
} |
967 |
}; |
968 |
|
969 |
private void launchApk(String id) { |
970 |
Intent intent = mPm.getLaunchIntentForPackage(id); |
971 |
startActivity(intent); |
972 |
} |
973 |
|
974 |
private void shareApp(App app) { |
975 |
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
976 |
shareIntent.setType("text/plain");
|
977 |
|
978 |
shareIntent.putExtra(Intent.EXTRA_SUBJECT, app.name); |
979 |
shareIntent.putExtra(Intent.EXTRA_TEXT, app.name + " (" + app.summary + ") - https://f-droid.org/app/" + app.id); |
980 |
|
981 |
startActivity(Intent.createChooser(shareIntent, getString(R.string.menu_share))); |
982 |
} |
983 |
|
984 |
@Override
|
985 |
public void onProgress(Event event) { |
986 |
if (downloadHandler == null || !downloadHandler.isEventFromThis(event)) { |
987 |
// Choose not to respond to events from previous downloaders.
|
988 |
// We don't even care if we receive "cancelled" events or the like, because
|
989 |
// we dealt with cancellations in the onCancel listener of the dialog,
|
990 |
// rather than waiting to receive the event here. We try and be careful in
|
991 |
// the download thread to make sure that we check for cancellations before
|
992 |
// sending events, but it is not possible to be perfect, because the interruption
|
993 |
// which triggers the download can happen after the check to see if
|
994 |
Utils.DebugLog(TAG, "Discarding downloader event \"" + event.type + "\" as it is from an old (probably cancelled) downloader."); |
995 |
return;
|
996 |
} |
997 |
|
998 |
boolean finished = false; |
999 |
switch (event.type) {
|
1000 |
case ApkDownloader.EVENT_ERROR:
|
1001 |
final int res; |
1002 |
if (event.getData().getInt(ApkDownloader.EVENT_DATA_ERROR_TYPE) == ApkDownloader.ERROR_HASH_MISMATCH)
|
1003 |
res = R.string.corrupt_download; |
1004 |
else
|
1005 |
res = R.string.details_notinstalled; |
1006 |
// this must be on the main UI thread
|
1007 |
Toast.makeText(this, res, Toast.LENGTH_LONG).show();
|
1008 |
cleanUpFinishedDownload(); |
1009 |
finished = true;
|
1010 |
break;
|
1011 |
case ApkDownloader.EVENT_APK_DOWNLOAD_COMPLETE:
|
1012 |
downloadCompleteInstallApk(); |
1013 |
finished = true;
|
1014 |
break;
|
1015 |
} |
1016 |
|
1017 |
if (finished) {
|
1018 |
if (mHeaderFragment != null) |
1019 |
mHeaderFragment.removeProgress(); |
1020 |
downloadHandler = null;
|
1021 |
} |
1022 |
} |
1023 |
|
1024 |
@Override
|
1025 |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
1026 |
// handle cases for install manager first
|
1027 |
if (installer.handleOnActivityResult(requestCode, resultCode, data)) {
|
1028 |
return;
|
1029 |
} |
1030 |
|
1031 |
switch (requestCode) {
|
1032 |
case REQUEST_ENABLE_BLUETOOTH:
|
1033 |
fdroidApp.sendViaBluetooth(this, resultCode, app.id);
|
1034 |
break;
|
1035 |
} |
1036 |
} |
1037 |
|
1038 |
@Override
|
1039 |
public App getApp() { return app; } |
1040 |
|
1041 |
@Override
|
1042 |
public ApkListAdapter getApks() { return adapter; } |
1043 |
|
1044 |
@Override
|
1045 |
public Signature getInstalledSignature() { return mInstalledSignature; } |
1046 |
|
1047 |
@Override
|
1048 |
public String getInstalledSignatureId() { return mInstalledSigID; } |
1049 |
|
1050 |
public static class AppDetailsSummaryFragment extends Fragment { |
1051 |
|
1052 |
protected final Preferences prefs; |
1053 |
private AppDetailsData data;
|
1054 |
private static final int MAX_LINES = 5; |
1055 |
private static boolean view_all_description; |
1056 |
private static boolean view_all_information; |
1057 |
private static boolean view_all_permissions; |
1058 |
private static LinearLayout ll_view_more_description; |
1059 |
private static LinearLayout ll_view_more_information; |
1060 |
private static LinearLayout ll_view_more_permissions; |
1061 |
|
1062 |
public AppDetailsSummaryFragment() {
|
1063 |
prefs = Preferences.get();
|
1064 |
} |
1065 |
|
1066 |
@Override
|
1067 |
public void onAttach(Activity activity) { |
1068 |
super.onAttach(activity);
|
1069 |
data = (AppDetailsData)activity; |
1070 |
} |
1071 |
|
1072 |
protected App getApp() { return data.getApp(); } |
1073 |
|
1074 |
protected ApkListAdapter getApks() { return data.getApks(); } |
1075 |
|
1076 |
protected Signature getInstalledSignature() { return data.getInstalledSignature(); } |
1077 |
|
1078 |
protected String getInstalledSignatureId() { return data.getInstalledSignatureId(); } |
1079 |
|
1080 |
@Override
|
1081 |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
1082 |
super.onCreateView(inflater, container, savedInstanceState);
|
1083 |
View summaryView = inflater.inflate(R.layout.app_details_summary, container, false); |
1084 |
setupView(summaryView); |
1085 |
return summaryView;
|
1086 |
} |
1087 |
|
1088 |
@Override
|
1089 |
public void onResume() { |
1090 |
super.onResume();
|
1091 |
updateViews(getView()); |
1092 |
} |
1093 |
|
1094 |
private void setupView(final View view) { |
1095 |
// Expandable description
|
1096 |
final TextView description = (TextView) view.findViewById(R.id.description);
|
1097 |
final Spanned desc = Html.fromHtml(getApp().description, null, new Utils.HtmlTagHandler()); |
1098 |
description.setMovementMethod(SafeLinkMovementMethod.getInstance(getActivity())); |
1099 |
description.setText(desc.subSequence(0, desc.length() - 2)); |
1100 |
final ImageView view_more_description = (ImageView) view.findViewById(R.id.view_more_description); |
1101 |
description.post(new Runnable() { |
1102 |
@Override
|
1103 |
public void run() { |
1104 |
// If description has more than five lines
|
1105 |
if (description.getLineCount() > MAX_LINES) {
|
1106 |
description.setMaxLines(MAX_LINES); |
1107 |
description.setOnClickListener(expander_description); |
1108 |
view_all_description = true;
|
1109 |
|
1110 |
ll_view_more_description = (LinearLayout) view.findViewById(R.id.ll_description); |
1111 |
ll_view_more_description.setOnClickListener(expander_description); |
1112 |
|
1113 |
view_more_description.setImageResource(R.drawable.ic_expand_more_grey600); |
1114 |
view_more_description.setOnClickListener(expander_description); |
1115 |
} else {
|
1116 |
view_more_description.setVisibility(View.GONE);
|
1117 |
} |
1118 |
} |
1119 |
}); |
1120 |
|
1121 |
// App ID
|
1122 |
final TextView appIdView = (TextView) view.findViewById(R.id.appid);
|
1123 |
if (prefs.expertMode())
|
1124 |
appIdView.setText(getApp().id); |
1125 |
else
|
1126 |
appIdView.setVisibility(View.GONE);
|
1127 |
|
1128 |
// Expandable information
|
1129 |
ll_view_more_information = (LinearLayout) view.findViewById(R.id.ll_information); |
1130 |
final TextView information = (TextView) view.findViewById(R.id.information);
|
1131 |
final LinearLayout ll_view_more_information_content = (LinearLayout) view.findViewById(R.id.ll_information_content);
|
1132 |
ll_view_more_information_content.setVisibility(View.GONE);
|
1133 |
view_all_information = true;
|
1134 |
information.setCompoundDrawablesWithIntrinsicBounds(null, null, getActivity().getResources().getDrawable(R.drawable.ic_expand_more_grey600), null); |
1135 |
|
1136 |
ll_view_more_information.setOnClickListener(expander_information); |
1137 |
information.setOnClickListener(expander_information); |
1138 |
|
1139 |
// Summary
|
1140 |
final TextView summaryView = (TextView) view.findViewById(R.id.summary);
|
1141 |
summaryView.setText(getApp().summary); |
1142 |
|
1143 |
// Website button
|
1144 |
TextView tv = (TextView) view.findViewById(R.id.website); |
1145 |
if (!TextUtils.isEmpty(getApp().webURL))
|
1146 |
tv.setOnClickListener(mOnClickListener); |
1147 |
else
|
1148 |
tv.setVisibility(View.GONE);
|
1149 |
|
1150 |
// Source button
|
1151 |
tv = (TextView) view.findViewById(R.id.source); |
1152 |
if (!TextUtils.isEmpty(getApp().sourceURL))
|
1153 |
tv.setOnClickListener(mOnClickListener); |
1154 |
else
|
1155 |
tv.setVisibility(View.GONE);
|
1156 |
|
1157 |
// Issues button
|
1158 |
tv = (TextView) view.findViewById(R.id.issues); |
1159 |
if (!TextUtils.isEmpty(getApp().trackerURL))
|
1160 |
tv.setOnClickListener(mOnClickListener); |
1161 |
else
|
1162 |
tv.setVisibility(View.GONE);
|
1163 |
|
1164 |
// Changelog button
|
1165 |
tv = (TextView) view.findViewById(R.id.changelog); |
1166 |
if (!TextUtils.isEmpty(getApp().changelogURL))
|
1167 |
tv.setOnClickListener(mOnClickListener); |
1168 |
else
|
1169 |
tv.setVisibility(View.GONE);
|
1170 |
|
1171 |
// Donate button
|
1172 |
tv = (TextView) view.findViewById(R.id.donate); |
1173 |
if (!TextUtils.isEmpty(getApp().donateURL))
|
1174 |
tv.setOnClickListener(mOnClickListener); |
1175 |
else
|
1176 |
tv.setVisibility(View.GONE);
|
1177 |
|
1178 |
// Bitcoin
|
1179 |
tv = (TextView) view.findViewById(R.id.bitcoin); |
1180 |
if (!TextUtils.isEmpty(getApp().bitcoinAddr))
|
1181 |
tv.setOnClickListener(mOnClickListener); |
1182 |
else
|
1183 |
tv.setVisibility(View.GONE);
|
1184 |
|
1185 |
// Litecoin
|
1186 |
tv = (TextView) view.findViewById(R.id.litecoin); |
1187 |
if (!TextUtils.isEmpty(getApp().litecoinAddr))
|
1188 |
tv.setOnClickListener(mOnClickListener); |
1189 |
else
|
1190 |
tv.setVisibility(View.GONE);
|
1191 |
|
1192 |
// Dogecoin
|
1193 |
tv = (TextView) view.findViewById(R.id.dogecoin); |
1194 |
if (!TextUtils.isEmpty(getApp().dogecoinAddr))
|
1195 |
tv.setOnClickListener(mOnClickListener); |
1196 |
else
|
1197 |
tv.setVisibility(View.GONE);
|
1198 |
|
1199 |
// Flattr
|
1200 |
tv = (TextView) view.findViewById(R.id.flattr); |
1201 |
if (!TextUtils.isEmpty(getApp().flattrID))
|
1202 |
tv.setOnClickListener(mOnClickListener); |
1203 |
else
|
1204 |
tv.setVisibility(View.GONE);
|
1205 |
|
1206 |
// Categories TextView
|
1207 |
final TextView categories = (TextView) view.findViewById(R.id.categories);
|
1208 |
if (prefs.expertMode() && getApp().categories != null) |
1209 |
categories.setText(getApp().categories.toString().replaceAll(",", ", ")); |
1210 |
else
|
1211 |
categories.setVisibility(View.GONE);
|
1212 |
|
1213 |
Apk curApk = null;
|
1214 |
for (int i = 0; i < getApks().getCount(); i++) { |
1215 |
final Apk apk = getApks().getItem(i);
|
1216 |
if (apk.vercode == getApp().suggestedVercode) {
|
1217 |
curApk = apk; |
1218 |
break;
|
1219 |
} |
1220 |
} |
1221 |
|
1222 |
// Expandable permissions
|
1223 |
ll_view_more_permissions = (LinearLayout) view.findViewById(R.id.ll_permissions); |
1224 |
final TextView permissionHeader = (TextView) view.findViewById(R.id.permissions);
|
1225 |
final TextView permissionListView = (TextView) view.findViewById(R.id.permissions_list);
|
1226 |
permissionListView.setVisibility(View.GONE);
|
1227 |
view_all_permissions = true;
|
1228 |
|
1229 |
final boolean curApkCompatible = curApk != null && curApk.compatible; |
1230 |
if (!getApks().isEmpty() && (curApkCompatible || prefs.showIncompatibleVersions())) {
|
1231 |
permissionHeader.setText(getString(R.string.permissions_for_long, getApks().getItem(0).version));
|
1232 |
permissionHeader.setCompoundDrawablesWithIntrinsicBounds(null, null, getActivity().getResources().getDrawable(R.drawable.ic_expand_more_grey600), null); |
1233 |
|
1234 |
ll_view_more_permissions.setOnClickListener(expander_permissions); |
1235 |
permissionHeader.setOnClickListener(expander_permissions); |
1236 |
} else {
|
1237 |
permissionHeader.setVisibility(View.GONE);
|
1238 |
permissionHeader.setCompoundDrawables(null, null, null, null); |
1239 |
} |
1240 |
|
1241 |
// Anti features
|
1242 |
final TextView antiFeaturesView = (TextView) view.findViewById(R.id.antifeatures);
|
1243 |
if (getApp().antiFeatures != null) { |
1244 |
StringBuilder sb = new StringBuilder(); |
1245 |
for (final String af : getApp().antiFeatures) { |
1246 |
final String afdesc = descAntiFeature(af); |
1247 |
if (afdesc != null) { |
1248 |
sb.append("\t• ").append(afdesc).append('\n'); |
1249 |
} |
1250 |
} |
1251 |
if (sb.length() > 0) { |
1252 |
sb.setLength(sb.length() - 1);
|
1253 |
antiFeaturesView.setText(sb.toString()); |
1254 |
} else {
|
1255 |
antiFeaturesView.setVisibility(View.GONE);
|
1256 |
} |
1257 |
} else {
|
1258 |
antiFeaturesView.setVisibility(View.GONE);
|
1259 |
} |
1260 |
|
1261 |
updateViews(view); |
1262 |
} |
1263 |
|
1264 |
private final View.OnClickListener mOnClickListener = new View.OnClickListener() { |
1265 |
public void onClick(View v) { |
1266 |
switch (v.getId()) {
|
1267 |
case R.id.website:
|
1268 |
((AppDetails) getActivity()).tryOpenUri(getApp().webURL); |
1269 |
break;
|
1270 |
|
1271 |
case R.id.source:
|
1272 |
((AppDetails) getActivity()).tryOpenUri(getApp().sourceURL); |
1273 |
break;
|
1274 |
|
1275 |
case R.id.issues:
|
1276 |
((AppDetails) getActivity()).tryOpenUri(getApp().trackerURL); |
1277 |
break;
|
1278 |
|
1279 |
case R.id.changelog:
|
1280 |
((AppDetails) getActivity()).tryOpenUri(getApp().changelogURL); |
1281 |
break;
|
1282 |
|
1283 |
case R.id.donate:
|
1284 |
((AppDetails) getActivity()).tryOpenUri(getApp().donateURL); |
1285 |
break;
|
1286 |
|
1287 |
case R.id.bitcoin:
|
1288 |
((AppDetails) getActivity()).tryOpenUri("bitcoin:" + getApp().bitcoinAddr);
|
1289 |
break;
|
1290 |
|
1291 |
case R.id.litecoin:
|
1292 |
((AppDetails) getActivity()).tryOpenUri("litecoin:" + getApp().litecoinAddr);
|
1293 |
break;
|
1294 |
|
1295 |
case R.id.dogecoin:
|
1296 |
((AppDetails) getActivity()).tryOpenUri("dogecoin:" + getApp().dogecoinAddr);
|
1297 |
break;
|
1298 |
|
1299 |
case R.id.flattr:
|
1300 |
((AppDetails) getActivity()).tryOpenUri("https://flattr.com/thing/" + getApp().flattrID);
|
1301 |
break;
|
1302 |
} |
1303 |
} |
1304 |
}; |
1305 |
|
1306 |
private final View.OnClickListener expander_description = new View.OnClickListener() { |
1307 |
public void onClick(View v) { |
1308 |
final TextView description = (TextView) ll_view_more_description.findViewById(R.id.description);
|
1309 |
final ImageView view_more_permissions = (ImageView) ll_view_more_description.findViewById(R.id.view_more_description); |
1310 |
if (!view_all_description) {
|
1311 |
view_all_description = true;
|
1312 |
description.setMaxLines(MAX_LINES); |
1313 |
view_more_permissions.setImageResource(R.drawable.ic_expand_more_grey600); |
1314 |
} else {
|
1315 |
view_all_description = false;
|
1316 |
description.setMaxLines(Integer.MAX_VALUE);
|
1317 |
view_more_permissions.setImageResource(R.drawable.ic_expand_less_grey600); |
1318 |
} |
1319 |
} |
1320 |
}; |
1321 |
|
1322 |
private final View.OnClickListener expander_information = new View.OnClickListener() { |
1323 |
public void onClick(View v) { |
1324 |
final TextView informationHeader = (TextView) ll_view_more_information.findViewById(R.id.information);
|
1325 |
final LinearLayout information_content = (LinearLayout) ll_view_more_information.findViewById(R.id.ll_information_content);
|
1326 |
if (!view_all_information) {
|
1327 |
view_all_information = true;
|
1328 |
information_content.setVisibility(View.GONE);
|
1329 |
informationHeader.setCompoundDrawablesWithIntrinsicBounds(null, null, getActivity().getResources().getDrawable(R.drawable.ic_expand_more_grey600), null); |
1330 |
} else {
|
1331 |
view_all_information = false;
|
1332 |
information_content.setVisibility(View.VISIBLE);
|
1333 |
informationHeader.setCompoundDrawablesWithIntrinsicBounds(null, null, getActivity().getResources().getDrawable(R.drawable.ic_expand_less_grey600), null); |
1334 |
} |
1335 |
} |
1336 |
}; |
1337 |
|
1338 |
private final View.OnClickListener expander_permissions = new View.OnClickListener() { |
1339 |
public void onClick(View v) { |
1340 |
final TextView permissionHeader = (TextView) ll_view_more_permissions.findViewById(R.id.permissions);
|
1341 |
final TextView permissionListView = (TextView) ll_view_more_permissions.findViewById(R.id.permissions_list);
|
1342 |
if (!view_all_permissions) {
|
1343 |
view_all_permissions = true;
|
1344 |
permissionListView.setVisibility(View.GONE);
|
1345 |
permissionHeader.setCompoundDrawablesWithIntrinsicBounds(null, null, getActivity().getResources().getDrawable(R.drawable.ic_expand_more_grey600), null); |
1346 |
} else {
|
1347 |
view_all_permissions = false;
|
1348 |
CommaSeparatedList permsList = getApks().getItem(0).permissions;
|
1349 |
if (permsList == null) { |
1350 |
permissionListView.setText(R.string.no_permissions); |
1351 |
} else {
|
1352 |
Iterator<String> permissions = permsList.iterator(); |
1353 |
StringBuilder sb = new StringBuilder(); |
1354 |
while (permissions.hasNext()) {
|
1355 |
final String permissionName = permissions.next(); |
1356 |
try {
|
1357 |
final Permission permission = new Permission(getActivity(), permissionName); |
1358 |
// TODO: Make this list RTL friendly
|
1359 |
sb.append("\t• ").append(permission.getName()).append('\n'); |
1360 |
} catch (PackageManager.NameNotFoundException e) {
|
1361 |
Log.e(TAG, "Permission not yet available: " + permissionName);
|
1362 |
} |
1363 |
} |
1364 |
if (sb.length() > 0) { |
1365 |
sb.setLength(sb.length() - 1);
|
1366 |
} |
1367 |
permissionListView.setText(sb.toString()); |
1368 |
} |
1369 |
permissionListView.setVisibility(View.VISIBLE);
|
1370 |
permissionHeader.setCompoundDrawablesWithIntrinsicBounds(null, null, getActivity().getResources().getDrawable(R.drawable.ic_expand_less_grey600), null); |
1371 |
} |
1372 |
} |
1373 |
}; |
1374 |
|
1375 |
private String descAntiFeature(String af) { |
1376 |
switch (af) {
|
1377 |
case "Ads": |
1378 |
return getString(R.string.antiadslist);
|
1379 |
case "Tracking": |
1380 |
return getString(R.string.antitracklist);
|
1381 |
case "NonFreeNet": |
1382 |
return getString(R.string.antinonfreenetlist);
|
1383 |
case "NonFreeAdd": |
1384 |
return getString(R.string.antinonfreeadlist);
|
1385 |
case "NonFreeDep": |
1386 |
return getString(R.string.antinonfreedeplist);
|
1387 |
case "UpstreamNonFree": |
1388 |
return getString(R.string.antiupstreamnonfreelist);
|
1389 |
} |
1390 |
return null; |
1391 |
} |
1392 |
|
1393 |
public void updateViews(View view) { |
1394 |
|
1395 |
if (view == null) { |
1396 |
Log.e(TAG, "AppDetailsSummaryFragment.updateViews(): view == null. Oops.");
|
1397 |
return;
|
1398 |
} |
1399 |
|
1400 |
TextView signatureView = (TextView) view.findViewById(R.id.signature); |
1401 |
if (prefs.expertMode() && getInstalledSignature() != null) { |
1402 |
signatureView.setVisibility(View.VISIBLE);
|
1403 |
signatureView.setText("Signed: " + getInstalledSignatureId());
|
1404 |
} else {
|
1405 |
signatureView.setVisibility(View.GONE);
|
1406 |
} |
1407 |
|
1408 |
} |
1409 |
} |
1410 |
|
1411 |
public static class AppDetailsHeaderFragment extends Fragment implements View.OnClickListener { |
1412 |
|
1413 |
private AppDetailsData data;
|
1414 |
private Button btMain; |
1415 |
private ProgressBar progressBar;
|
1416 |
private TextView progressSize;
|
1417 |
private TextView progressPercent;
|
1418 |
private ImageButton cancelButton;
|
1419 |
protected final DisplayImageOptions displayImageOptions; |
1420 |
public static boolean installed = false; |
1421 |
public static boolean updateWanted = false; |
1422 |
|
1423 |
public AppDetailsHeaderFragment() {
|
1424 |
displayImageOptions = new DisplayImageOptions.Builder()
|
1425 |
.cacheInMemory(true)
|
1426 |
.cacheOnDisk(true)
|
1427 |
.imageScaleType(ImageScaleType.NONE) |
1428 |
.showImageOnLoading(R.drawable.ic_repo_app_default) |
1429 |
.showImageForEmptyUri(R.drawable.ic_repo_app_default) |
1430 |
.bitmapConfig(Bitmap.Config.RGB_565) |
1431 |
.build(); |
1432 |
} |
1433 |
|
1434 |
private App getApp() { return data.getApp(); } |
1435 |
|
1436 |
private ApkListAdapter getApks() { return data.getApks(); } |
1437 |
|
1438 |
@Override
|
1439 |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
1440 |
View view = inflater.inflate(R.layout.app_details_header, container, false); |
1441 |
setupView(view); |
1442 |
return view;
|
1443 |
} |
1444 |
|
1445 |
@Override
|
1446 |
public void onAttach(Activity activity) { |
1447 |
super.onAttach(activity);
|
1448 |
data = (AppDetailsData)activity; |
1449 |
} |
1450 |
|
1451 |
private void setupView(View view) { |
1452 |
|
1453 |
// Set the icon...
|
1454 |
ImageView iv = (ImageView) view.findViewById(R.id.icon); |
1455 |
ImageLoader.getInstance().displayImage(getApp().iconUrlLarge, iv, |
1456 |
displayImageOptions); |
1457 |
|
1458 |
// Set the title
|
1459 |
TextView tv = (TextView) view.findViewById(R.id.title); |
1460 |
tv.setText(getApp().name); |
1461 |
|
1462 |
btMain = (Button) view.findViewById(R.id.btn_main);
|
1463 |
progressBar = (ProgressBar) view.findViewById(R.id.progress_bar); |
1464 |
progressSize = (TextView) view.findViewById(R.id.progress_size); |
1465 |
progressPercent = (TextView) view.findViewById(R.id.progress_percentage); |
1466 |
cancelButton = (ImageButton) view.findViewById(R.id.cancel); |
1467 |
progressBar.setIndeterminate(false);
|
1468 |
cancelButton.setOnClickListener(this);
|
1469 |
|
1470 |
updateViews(view); |
1471 |
} |
1472 |
|
1473 |
@Override
|
1474 |
public void onResume() { |
1475 |
super.onResume();
|
1476 |
updateViews(); |
1477 |
} |
1478 |
|
1479 |
/**
|
1480 |
* Displays empty, indeterminate progress bar and related views.
|
1481 |
*/
|
1482 |
public void startProgress() { |
1483 |
setProgressVisible(true);
|
1484 |
progressBar.setIndeterminate(true);
|
1485 |
progressSize.setText("");
|
1486 |
progressPercent.setText("");
|
1487 |
updateViews(); |
1488 |
} |
1489 |
|
1490 |
/**
|
1491 |
* Updates progress bar and captions to new values (in bytes).
|
1492 |
*/
|
1493 |
public void updateProgress(long progress, long total) { |
1494 |
long percent = progress * 100 / total; |
1495 |
setProgressVisible(true);
|
1496 |
progressBar.setIndeterminate(false);
|
1497 |
progressBar.setProgress((int) percent);
|
1498 |
progressBar.setMax(100);
|
1499 |
progressSize.setText(readableFileSize(progress) + " / " + readableFileSize(total));
|
1500 |
progressPercent.setText(Long.toString(percent) + " %"); |
1501 |
} |
1502 |
|
1503 |
/**
|
1504 |
* Converts a number of bytes to a human readable file size (eg 3.5 GiB).
|
1505 |
*
|
1506 |
* Based on http://stackoverflow.com/a/5599842
|
1507 |
*/
|
1508 |
public String readableFileSize(long bytes) { |
1509 |
final String[] units = getResources().getStringArray(R.array.file_size_units); |
1510 |
if (bytes <= 0) return "0 " + units[0]; |
1511 |
int digitGroups = (int) (Math.log10(bytes) / Math.log10(1024)); |
1512 |
return new DecimalFormat("#,##0.#") |
1513 |
.format(bytes / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; |
1514 |
} |
1515 |
|
1516 |
/**
|
1517 |
* Shows or hides progress bar and related views.
|
1518 |
*/
|
1519 |
private void setProgressVisible(boolean visible) { |
1520 |
int state = (visible) ? View.VISIBLE : View.GONE; |
1521 |
progressBar.setVisibility(state); |
1522 |
progressSize.setVisibility(state); |
1523 |
progressPercent.setVisibility(state); |
1524 |
cancelButton.setVisibility(state); |
1525 |
} |
1526 |
|
1527 |
/**
|
1528 |
* Removes progress bar and related views, invokes {@link #updateViews()}.
|
1529 |
*/
|
1530 |
public void removeProgress() { |
1531 |
setProgressVisible(false);
|
1532 |
updateViews(); |
1533 |
} |
1534 |
|
1535 |
/**
|
1536 |
* Cancels download and hides progress bar.
|
1537 |
*/
|
1538 |
@Override
|
1539 |
public void onClick(View view) { |
1540 |
AppDetails activity = (AppDetails) getActivity(); |
1541 |
if (activity == null || activity.downloadHandler == null) |
1542 |
return;
|
1543 |
|
1544 |
activity.downloadHandler.cancel(true);
|
1545 |
activity.cleanUpFinishedDownload(); |
1546 |
setProgressVisible(false);
|
1547 |
updateViews(); |
1548 |
} |
1549 |
|
1550 |
public void updateViews() { |
1551 |
updateViews(getView()); |
1552 |
} |
1553 |
|
1554 |
public void updateViews(View view) { |
1555 |
TextView statusView = (TextView) view.findViewById(R.id.status); |
1556 |
btMain.setVisibility(View.VISIBLE);
|
1557 |
|
1558 |
AppDetails activity = (AppDetails) getActivity(); |
1559 |
if (activity.downloadHandler != null) { |
1560 |
btMain.setText(R.string.downloading); |
1561 |
btMain.setEnabled(false);
|
1562 |
// Check count > 0 due to incompatible apps resulting in an empty list.
|
1563 |
// If App isn't installed
|
1564 |
} else if (!getApp().isInstalled() && getApp().suggestedVercode > 0 && |
1565 |
((AppDetails)getActivity()).adapter.getCount() > 0) {
|
1566 |
installed = false;
|
1567 |
statusView.setText(R.string.details_notinstalled); |
1568 |
NfcHelper.disableAndroidBeam(getActivity()); |
1569 |
// Set Install button and hide second button
|
1570 |
btMain.setText(R.string.menu_install); |
1571 |
btMain.setOnClickListener(mOnClickListener); |
1572 |
btMain.setEnabled(true);
|
1573 |
// If App is installed
|
1574 |
} else if (getApp().isInstalled()) { |
1575 |
installed = true;
|
1576 |
statusView.setText(getString(R.string.details_installed, getApp().installedVersionName)); |
1577 |
NfcHelper.setAndroidBeam(getActivity(), getApp().id); |
1578 |
if (getApp().canAndWantToUpdate()) {
|
1579 |
updateWanted = true;
|
1580 |
btMain.setText(R.string.menu_upgrade); |
1581 |
} else {
|
1582 |
updateWanted = false;
|
1583 |
if (((AppDetails)getActivity()).mPm.getLaunchIntentForPackage(getApp().id) != null){ |
1584 |
btMain.setText(R.string.menu_launch); |
1585 |
} else {
|
1586 |
btMain.setText(R.string.menu_uninstall); |
1587 |
if (!getApp().uninstallable) {
|
1588 |
btMain.setVisibility(View.GONE);
|
1589 |
} |
1590 |
} |
1591 |
} |
1592 |
btMain.setOnClickListener(mOnClickListener); |
1593 |
btMain.setEnabled(true);
|
1594 |
} |
1595 |
TextView currentVersion = (TextView) view.findViewById(R.id.current_version); |
1596 |
if (!getApks().isEmpty()) {
|
1597 |
currentVersion.setText(getApks().getItem(0).version);
|
1598 |
} else {
|
1599 |
currentVersion.setVisibility(View.GONE);
|
1600 |
btMain.setVisibility(View.GONE);
|
1601 |
} |
1602 |
|
1603 |
} |
1604 |
|
1605 |
private final View.OnClickListener mOnClickListener = new View.OnClickListener() { |
1606 |
public void onClick(View v) { |
1607 |
if (updateWanted) {
|
1608 |
if (getApp().suggestedVercode > 0) { |
1609 |
final Apk apkToInstall = ApkProvider.Helper.find(getActivity(), getApp().id, getApp().suggestedVercode);
|
1610 |
((AppDetails)getActivity()).install(apkToInstall); |
1611 |
return;
|
1612 |
} |
1613 |
} |
1614 |
// If installed
|
1615 |
if (installed) {
|
1616 |
// If "launchable", launch
|
1617 |
if (((AppDetails)getActivity()).mPm.getLaunchIntentForPackage(getApp().id) != null) { |
1618 |
((AppDetails)getActivity()).launchApk(getApp().id); |
1619 |
} else {
|
1620 |
((AppDetails)getActivity()).removeApk(getApp().id); |
1621 |
} |
1622 |
// If not installed, install
|
1623 |
} else if (getApp().suggestedVercode > 0) { |
1624 |
btMain.setEnabled(false);
|
1625 |
btMain.setText(R.string.system_install_installing); |
1626 |
final Apk apkToInstall = ApkProvider.Helper.find(getActivity(), getApp().id, getApp().suggestedVercode);
|
1627 |
((AppDetails)getActivity()).install(apkToInstall); |
1628 |
} |
1629 |
} |
1630 |
}; |
1631 |
} |
1632 |
|
1633 |
public static class AppDetailsListFragment extends ListFragment { |
1634 |
|
1635 |
private final String SUMMARY_TAG = "summary"; |
1636 |
|
1637 |
private AppDetailsData data;
|
1638 |
private AppInstallListener installListener;
|
1639 |
private AppDetailsSummaryFragment summaryFragment = null; |
1640 |
|
1641 |
private FrameLayout headerView;
|
1642 |
|
1643 |
@Override
|
1644 |
public void onAttach(Activity activity) { |
1645 |
super.onAttach(activity);
|
1646 |
data = (AppDetailsData)activity; |
1647 |
installListener = (AppInstallListener)activity; |
1648 |
} |
1649 |
|
1650 |
protected void install(final Apk apk) { |
1651 |
installListener.install(apk); |
1652 |
} |
1653 |
|
1654 |
protected void remove() { |
1655 |
installListener.removeApk(getApp().id); |
1656 |
} |
1657 |
|
1658 |
protected App getApp() { return data.getApp(); } |
1659 |
|
1660 |
protected ApkListAdapter getApks() { return data.getApks(); } |
1661 |
|
1662 |
@Override
|
1663 |
public void onViewCreated(View view, Bundle savedInstanceState) { |
1664 |
// A bit of a hack, but we can't add the header view in setupSummaryHeader(),
|
1665 |
// due to the fact it needs to happen before setListAdapter(). Also, seeing
|
1666 |
// as we may never add a summary header (i.e. in landscape), this is probably
|
1667 |
// the last opportunity to set the list adapter. As such, we use the headerView
|
1668 |
// as a mechanism to optionally allow adding a header in the future.
|
1669 |
if (headerView == null) { |
1670 |
headerView = new FrameLayout(getActivity());
|
1671 |
headerView.setId(R.id.appDetailsSummaryHeader); |
1672 |
} else {
|
1673 |
Fragment summaryFragment = getChildFragmentManager().findFragmentByTag(SUMMARY_TAG); |
1674 |
if (summaryFragment != null) { |
1675 |
getChildFragmentManager().beginTransaction().remove(summaryFragment).commit(); |
1676 |
} |
1677 |
} |
1678 |
|
1679 |
setListAdapter(null);
|
1680 |
getListView().addHeaderView(headerView); |
1681 |
setListAdapter(getApks()); |
1682 |
} |
1683 |
|
1684 |
@Override
|
1685 |
public void onListItemClick(ListView l, View v, int position, long id) { |
1686 |
final Apk apk = getApks().getItem(position - l.getHeaderViewsCount());
|
1687 |
if (getApp().installedVersionCode == apk.vercode) {
|
1688 |
remove(); |
1689 |
} else if (getApp().installedVersionCode > apk.vercode) { |
1690 |
AlertDialog.Builder ask_alrt = new AlertDialog.Builder(getActivity());
|
1691 |
ask_alrt.setMessage(R.string.installDowngrade); |
1692 |
ask_alrt.setPositiveButton(R.string.yes, |
1693 |
new DialogInterface.OnClickListener() {
|
1694 |
@Override
|
1695 |
public void onClick(DialogInterface dialog, |
1696 |
int whichButton) {
|
1697 |
install(apk); |
1698 |
} |
1699 |
}); |
1700 |
ask_alrt.setNegativeButton(R.string.no, |
1701 |
new DialogInterface.OnClickListener() {
|
1702 |
@Override
|
1703 |
public void onClick(DialogInterface dialog, |
1704 |
int whichButton) {
|
1705 |
} |
1706 |
}); |
1707 |
AlertDialog alert = ask_alrt.create(); |
1708 |
alert.show(); |
1709 |
} else {
|
1710 |
install(apk); |
1711 |
} |
1712 |
} |
1713 |
|
1714 |
public void removeSummaryHeader() { |
1715 |
Fragment summary = getChildFragmentManager().findFragmentByTag(SUMMARY_TAG); |
1716 |
if (summary != null) { |
1717 |
getChildFragmentManager().beginTransaction().remove(summary).commit(); |
1718 |
headerView.removeAllViews(); |
1719 |
headerView.setVisibility(View.GONE);
|
1720 |
summaryFragment = null;
|
1721 |
} |
1722 |
} |
1723 |
|
1724 |
public void setupSummaryHeader() { |
1725 |
Fragment fragment = getChildFragmentManager().findFragmentByTag(SUMMARY_TAG); |
1726 |
if (fragment != null) { |
1727 |
summaryFragment = (AppDetailsSummaryFragment)fragment; |
1728 |
} else {
|
1729 |
summaryFragment = new AppDetailsSummaryFragment();
|
1730 |
} |
1731 |
getChildFragmentManager().beginTransaction().replace(headerView.getId(), summaryFragment, SUMMARY_TAG).commit(); |
1732 |
headerView.setVisibility(View.VISIBLE);
|
1733 |
} |
1734 |
} |
1735 |
|
1736 |
} |