Obey checkstyle rule preventing 'm' prefix for member variables

Required a couple of undesirable changes, such as:
 * sCollated -> collated
 * mFDroidApp -> fdroidApp (note the lower case 'd')

Otherwise it was relatively minor given how many member variables there are
in the code base.
This commit is contained in:
Peter Serwylo 2016-12-05 22:46:07 +11:00
parent 4f7116fcfb
commit a00534c7c7
12 changed files with 317 additions and 317 deletions

View File

@ -158,7 +158,7 @@ public class AppDetails extends AppCompatActivity {
class ApkListAdapter extends ArrayAdapter<Apk> { class ApkListAdapter extends ArrayAdapter<Apk> {
private final LayoutInflater mInflater = (LayoutInflater) context.getSystemService( private final LayoutInflater inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE); Context.LAYOUT_INFLATER_SERVICE);
ApkListAdapter(Context context, App app) { ApkListAdapter(Context context, App app) {
@ -204,7 +204,7 @@ public class AppDetails extends AppCompatActivity {
ViewHolder holder; ViewHolder holder;
if (convertView == null) { if (convertView == null) {
convertView = mInflater.inflate(R.layout.apklistitem, parent, false); convertView = inflater.inflate(R.layout.apklistitem, parent, false);
holder = new ViewHolder(); holder = new ViewHolder();
holder.version = (TextView) convertView.findViewById(R.id.version); holder.version = (TextView) convertView.findViewById(R.id.version);
@ -1157,7 +1157,7 @@ public class AppDetails extends AppCompatActivity {
} }
}; };
private final View.OnClickListener mOnClickListener = new View.OnClickListener() { private final View.OnClickListener onClickListener = new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
String url = null; String url = null;
App app = appDetails.getApp(); App app = appDetails.getApp();
@ -1268,7 +1268,7 @@ public class AppDetails extends AppCompatActivity {
// Website button // Website button
View tv = view.findViewById(R.id.website); View tv = view.findViewById(R.id.website);
if (!TextUtils.isEmpty(app.webURL)) { if (!TextUtils.isEmpty(app.webURL)) {
tv.setOnClickListener(mOnClickListener); tv.setOnClickListener(onClickListener);
} else { } else {
tv.setVisibility(View.GONE); tv.setVisibility(View.GONE);
} }
@ -1276,7 +1276,7 @@ public class AppDetails extends AppCompatActivity {
// Email button // Email button
tv = view.findViewById(R.id.email); tv = view.findViewById(R.id.email);
if (!TextUtils.isEmpty(app.email)) { if (!TextUtils.isEmpty(app.email)) {
tv.setOnClickListener(mOnClickListener); tv.setOnClickListener(onClickListener);
} else { } else {
tv.setVisibility(View.GONE); tv.setVisibility(View.GONE);
} }
@ -1284,7 +1284,7 @@ public class AppDetails extends AppCompatActivity {
// Source button // Source button
tv = view.findViewById(R.id.source); tv = view.findViewById(R.id.source);
if (!TextUtils.isEmpty(app.sourceURL)) { if (!TextUtils.isEmpty(app.sourceURL)) {
tv.setOnClickListener(mOnClickListener); tv.setOnClickListener(onClickListener);
} else { } else {
tv.setVisibility(View.GONE); tv.setVisibility(View.GONE);
} }
@ -1292,7 +1292,7 @@ public class AppDetails extends AppCompatActivity {
// Issues button // Issues button
tv = view.findViewById(R.id.issues); tv = view.findViewById(R.id.issues);
if (!TextUtils.isEmpty(app.trackerURL)) { if (!TextUtils.isEmpty(app.trackerURL)) {
tv.setOnClickListener(mOnClickListener); tv.setOnClickListener(onClickListener);
} else { } else {
tv.setVisibility(View.GONE); tv.setVisibility(View.GONE);
} }
@ -1300,7 +1300,7 @@ public class AppDetails extends AppCompatActivity {
// Changelog button // Changelog button
tv = view.findViewById(R.id.changelog); tv = view.findViewById(R.id.changelog);
if (!TextUtils.isEmpty(app.changelogURL)) { if (!TextUtils.isEmpty(app.changelogURL)) {
tv.setOnClickListener(mOnClickListener); tv.setOnClickListener(onClickListener);
} else { } else {
tv.setVisibility(View.GONE); tv.setVisibility(View.GONE);
} }
@ -1308,7 +1308,7 @@ public class AppDetails extends AppCompatActivity {
// Donate button // Donate button
tv = view.findViewById(R.id.donate); tv = view.findViewById(R.id.donate);
if (!TextUtils.isEmpty(app.donateURL)) { if (!TextUtils.isEmpty(app.donateURL)) {
tv.setOnClickListener(mOnClickListener); tv.setOnClickListener(onClickListener);
} else { } else {
tv.setVisibility(View.GONE); tv.setVisibility(View.GONE);
} }
@ -1316,7 +1316,7 @@ public class AppDetails extends AppCompatActivity {
// Bitcoin // Bitcoin
tv = view.findViewById(R.id.bitcoin); tv = view.findViewById(R.id.bitcoin);
if (!TextUtils.isEmpty(app.bitcoinAddr)) { if (!TextUtils.isEmpty(app.bitcoinAddr)) {
tv.setOnClickListener(mOnClickListener); tv.setOnClickListener(onClickListener);
} else { } else {
tv.setVisibility(View.GONE); tv.setVisibility(View.GONE);
} }
@ -1324,7 +1324,7 @@ public class AppDetails extends AppCompatActivity {
// Litecoin // Litecoin
tv = view.findViewById(R.id.litecoin); tv = view.findViewById(R.id.litecoin);
if (!TextUtils.isEmpty(app.litecoinAddr)) { if (!TextUtils.isEmpty(app.litecoinAddr)) {
tv.setOnClickListener(mOnClickListener); tv.setOnClickListener(onClickListener);
} else { } else {
tv.setVisibility(View.GONE); tv.setVisibility(View.GONE);
} }
@ -1332,7 +1332,7 @@ public class AppDetails extends AppCompatActivity {
// Flattr // Flattr
tv = view.findViewById(R.id.flattr); tv = view.findViewById(R.id.flattr);
if (!TextUtils.isEmpty(app.flattrID)) { if (!TextUtils.isEmpty(app.flattrID)) {
tv.setOnClickListener(mOnClickListener); tv.setOnClickListener(onClickListener);
} else { } else {
tv.setVisibility(View.GONE); tv.setVisibility(View.GONE);
} }
@ -1620,7 +1620,7 @@ public class AppDetails extends AppCompatActivity {
NfcHelper.disableAndroidBeam(appDetails); NfcHelper.disableAndroidBeam(appDetails);
// Set Install button and hide second button // Set Install button and hide second button
btMain.setText(R.string.menu_install); btMain.setText(R.string.menu_install);
btMain.setOnClickListener(mOnClickListener); btMain.setOnClickListener(onClickListener);
btMain.setEnabled(true); btMain.setEnabled(true);
} else if (app.isInstalled()) { } else if (app.isInstalled()) {
// If App is installed // If App is installed
@ -1638,7 +1638,7 @@ public class AppDetails extends AppCompatActivity {
btMain.setText(R.string.menu_uninstall); btMain.setText(R.string.menu_uninstall);
} }
} }
btMain.setOnClickListener(mOnClickListener); btMain.setOnClickListener(onClickListener);
btMain.setEnabled(true); btMain.setEnabled(true);
} }
TextView author = (TextView) view.findViewById(R.id.author); TextView author = (TextView) view.findViewById(R.id.author);
@ -1656,7 +1656,7 @@ public class AppDetails extends AppCompatActivity {
} }
private final View.OnClickListener mOnClickListener = new View.OnClickListener() { private final View.OnClickListener onClickListener = new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
App app = appDetails.getApp(); App app = appDetails.getApp();
AppDetails activity = (AppDetails) getActivity(); AppDetails activity = (AppDetails) getActivity();

View File

@ -57,17 +57,17 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
private static final int REQUEST_PERMISSION_DIALOG = 3; private static final int REQUEST_PERMISSION_DIALOG = 3;
private static final int REQUEST_UNINSTALL_DIALOG = 4; private static final int REQUEST_UNINSTALL_DIALOG = 4;
private FDroidApp mFDroidApp; private FDroidApp fdroidApp;
private App mApp; private App app;
private RecyclerView mRecyclerView; private RecyclerView recyclerView;
private AppDetailsRecyclerViewAdapter mAdapter; private AppDetailsRecyclerViewAdapter adapter;
private LocalBroadcastManager mLocalBroadcastManager; private LocalBroadcastManager localBroadcastManager;
private String mActiveDownloadUrlString; private String activeDownloadUrlString;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
mFDroidApp = (FDroidApp) getApplication(); fdroidApp = (FDroidApp) getApplication();
//mFDroidApp.applyTheme(this); //fdroidApp.applyTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.app_details2); setContentView(R.layout.app_details2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
@ -80,17 +80,17 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
return; return;
} }
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); localBroadcastManager = LocalBroadcastManager.getInstance(this);
mRecyclerView = (RecyclerView) findViewById(R.id.rvDetails); recyclerView = (RecyclerView) findViewById(R.id.rvDetails);
mAdapter = new AppDetailsRecyclerViewAdapter(this, mApp, this); adapter = new AppDetailsRecyclerViewAdapter(this, app, this);
LinearLayoutManager lm = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); LinearLayoutManager lm = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
lm.setStackFromEnd(false); lm.setStackFromEnd(false);
mRecyclerView.setLayoutManager(lm); recyclerView.setLayoutManager(lm);
mRecyclerView.setAdapter(mAdapter); recyclerView.setAdapter(adapter);
// Load the feature graphic, if present // Load the feature graphic, if present
if (!TextUtils.isEmpty(mApp.iconUrlLarge)) { if (!TextUtils.isEmpty(app.iconUrlLarge)) {
ImageView ivFeatureGraphic = (ImageView) findViewById(R.id.feature_graphic); ImageView ivFeatureGraphic = (ImageView) findViewById(R.id.feature_graphic);
DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder() DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()
.cacheInMemory(false) .cacheInMemory(false)
@ -98,7 +98,7 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
.imageScaleType(ImageScaleType.NONE) .imageScaleType(ImageScaleType.NONE)
.bitmapConfig(Bitmap.Config.RGB_565) .bitmapConfig(Bitmap.Config.RGB_565)
.build(); .build();
ImageLoader.getInstance().displayImage(mApp.iconUrlLarge, ivFeatureGraphic, displayImageOptions); ImageLoader.getInstance().displayImage(app.iconUrlLarge, ivFeatureGraphic, displayImageOptions);
} }
} }
@ -120,7 +120,7 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
finish(); finish();
return; return;
} }
mApp = newApp; app = newApp;
} }
@Override @Override
@ -135,17 +135,17 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
if (mApp == null) { if (app == null) {
return true; return true;
} }
MenuItem itemIgnoreAll = menu.findItem(R.id.action_ignore_all); MenuItem itemIgnoreAll = menu.findItem(R.id.action_ignore_all);
if (itemIgnoreAll != null) { if (itemIgnoreAll != null) {
itemIgnoreAll.setChecked(mApp.getPrefs(this).ignoreAllUpdates); itemIgnoreAll.setChecked(app.getPrefs(this).ignoreAllUpdates);
} }
MenuItem itemIgnoreThis = menu.findItem(R.id.action_ignore_this); MenuItem itemIgnoreThis = menu.findItem(R.id.action_ignore_this);
if (itemIgnoreThis != null) { if (itemIgnoreThis != null) {
itemIgnoreThis.setVisible(mApp.hasUpdates()); itemIgnoreThis.setVisible(app.hasUpdates());
itemIgnoreThis.setChecked(mApp.getPrefs(this).ignoreThisUpdate >= mApp.suggestedVersionCode); itemIgnoreThis.setChecked(app.getPrefs(this).ignoreThisUpdate >= app.suggestedVersionCode);
} }
return true; return true;
} }
@ -155,25 +155,25 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
if (item.getItemId() == R.id.action_share) { if (item.getItemId() == R.id.action_share) {
Intent shareIntent = new Intent(Intent.ACTION_SEND); Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain"); shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, mApp.name); shareIntent.putExtra(Intent.EXTRA_SUBJECT, app.name);
shareIntent.putExtra(Intent.EXTRA_TEXT, mApp.name + " (" + mApp.summary + ") - https://f-droid.org/app/" + mApp.packageName); shareIntent.putExtra(Intent.EXTRA_TEXT, app.name + " (" + app.summary + ") - https://f-droid.org/app/" + app.packageName);
boolean showNearbyItem = mApp.isInstalled() && mFDroidApp.bluetoothAdapter != null; boolean showNearbyItem = app.isInstalled() && fdroidApp.bluetoothAdapter != null;
ShareChooserDialog.createChooser((CoordinatorLayout) findViewById(R.id.rootCoordinator), this, this, shareIntent, showNearbyItem); ShareChooserDialog.createChooser((CoordinatorLayout) findViewById(R.id.rootCoordinator), this, this, shareIntent, showNearbyItem);
return true; return true;
} else if (item.getItemId() == R.id.action_ignore_all) { } else if (item.getItemId() == R.id.action_ignore_all) {
mApp.getPrefs(this).ignoreAllUpdates ^= true; app.getPrefs(this).ignoreAllUpdates ^= true;
item.setChecked(mApp.getPrefs(this).ignoreAllUpdates); item.setChecked(app.getPrefs(this).ignoreAllUpdates);
AppPrefsProvider.Helper.update(this, mApp, mApp.getPrefs(this)); AppPrefsProvider.Helper.update(this, app, app.getPrefs(this));
return true; return true;
} else if (item.getItemId() == R.id.action_ignore_this) { } else if (item.getItemId() == R.id.action_ignore_this) {
if (mApp.getPrefs(this).ignoreThisUpdate >= mApp.suggestedVersionCode) { if (app.getPrefs(this).ignoreThisUpdate >= app.suggestedVersionCode) {
mApp.getPrefs(this).ignoreThisUpdate = 0; app.getPrefs(this).ignoreThisUpdate = 0;
} else { } else {
mApp.getPrefs(this).ignoreThisUpdate = mApp.suggestedVersionCode; app.getPrefs(this).ignoreThisUpdate = app.suggestedVersionCode;
} }
item.setChecked(mApp.getPrefs(this).ignoreThisUpdate > 0); item.setChecked(app.getPrefs(this).ignoreThisUpdate > 0);
AppPrefsProvider.Helper.update(this, mApp, mApp.getPrefs(this)); AppPrefsProvider.Helper.update(this, app, app.getPrefs(this));
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
@ -198,7 +198,7 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) { switch (requestCode) {
case REQUEST_ENABLE_BLUETOOTH: case REQUEST_ENABLE_BLUETOOTH:
mFDroidApp.sendViaBluetooth(this, resultCode, mApp.packageName); fdroidApp.sendViaBluetooth(this, resultCode, app.packageName);
break; break;
case REQUEST_PERMISSION_DIALOG: case REQUEST_PERMISSION_DIALOG:
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
@ -244,8 +244,8 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
alert.show(); alert.show();
return; return;
} }
if (mApp.installedSig != null && apk.sig != null if (app.installedSig != null && apk.sig != null
&& !apk.sig.equals(mApp.installedSig)) { && !apk.sig.equals(app.installedSig)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.SignatureMismatch).setPositiveButton( builder.setMessage(R.string.SignatureMismatch).setPositiveButton(
R.string.ok, R.string.ok,
@ -276,39 +276,39 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
} }
private void startInstall(Apk apk) { private void startInstall(Apk apk) {
mActiveDownloadUrlString = apk.getUrl(); activeDownloadUrlString = apk.getUrl();
registerDownloaderReceiver(); registerDownloaderReceiver();
InstallManagerService.queue(this, mApp, apk); InstallManagerService.queue(this, app, apk);
} }
private void startUninstall() { private void startUninstall() {
registerUninstallReceiver(); registerUninstallReceiver();
InstallerService.uninstall(this, mApp.installedApk); InstallerService.uninstall(this, app.installedApk);
} }
private void registerUninstallReceiver() { private void registerUninstallReceiver() {
mLocalBroadcastManager.registerReceiver(uninstallReceiver, localBroadcastManager.registerReceiver(uninstallReceiver,
Installer.getUninstallIntentFilter(mApp.packageName)); Installer.getUninstallIntentFilter(app.packageName));
} }
private void unregisterUninstallReceiver() { private void unregisterUninstallReceiver() {
mLocalBroadcastManager.unregisterReceiver(uninstallReceiver); localBroadcastManager.unregisterReceiver(uninstallReceiver);
} }
private void registerDownloaderReceiver() { private void registerDownloaderReceiver() {
if (mActiveDownloadUrlString != null) { // if a download is active if (activeDownloadUrlString != null) { // if a download is active
String url = mActiveDownloadUrlString; String url = activeDownloadUrlString;
mLocalBroadcastManager.registerReceiver(downloadReceiver, localBroadcastManager.registerReceiver(downloadReceiver,
DownloaderService.getIntentFilter(url)); DownloaderService.getIntentFilter(url));
} }
} }
private void unregisterDownloaderReceiver() { private void unregisterDownloaderReceiver() {
mLocalBroadcastManager.unregisterReceiver(downloadReceiver); localBroadcastManager.unregisterReceiver(downloadReceiver);
} }
private void unregisterInstallReceiver() { private void unregisterInstallReceiver() {
mLocalBroadcastManager.unregisterReceiver(installReceiver); localBroadcastManager.unregisterReceiver(installReceiver);
} }
private final BroadcastReceiver downloadReceiver = new BroadcastReceiver() { private final BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
@ -316,16 +316,16 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) { switch (intent.getAction()) {
case Downloader.ACTION_STARTED: case Downloader.ACTION_STARTED:
mAdapter.setProgress(-1, -1, R.string.download_pending); adapter.setProgress(-1, -1, R.string.download_pending);
break; break;
case Downloader.ACTION_PROGRESS: case Downloader.ACTION_PROGRESS:
mAdapter.setProgress(intent.getIntExtra(Downloader.EXTRA_BYTES_READ, -1), adapter.setProgress(intent.getIntExtra(Downloader.EXTRA_BYTES_READ, -1),
intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, -1), 0); intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, -1), 0);
break; break;
case Downloader.ACTION_COMPLETE: case Downloader.ACTION_COMPLETE:
// Starts the install process once the download is complete. // Starts the install process once the download is complete.
cleanUpFinishedDownload(); cleanUpFinishedDownload();
mLocalBroadcastManager.registerReceiver(installReceiver, localBroadcastManager.registerReceiver(installReceiver,
Installer.getInstallIntentFilter(intent.getData())); Installer.getInstallIntentFilter(intent.getData()));
break; break;
case Downloader.ACTION_INTERRUPTED: case Downloader.ACTION_INTERRUPTED:
@ -350,15 +350,15 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) { switch (intent.getAction()) {
case Installer.ACTION_INSTALL_STARTED: case Installer.ACTION_INSTALL_STARTED:
mAdapter.setProgress(-1, -1, R.string.installing); adapter.setProgress(-1, -1, R.string.installing);
break; break;
case Installer.ACTION_INSTALL_COMPLETE: case Installer.ACTION_INSTALL_COMPLETE:
mAdapter.clearProgress(); adapter.clearProgress();
unregisterInstallReceiver(); unregisterInstallReceiver();
onAppChanged(); onAppChanged();
break; break;
case Installer.ACTION_INSTALL_INTERRUPTED: case Installer.ACTION_INSTALL_INTERRUPTED:
mAdapter.clearProgress(); adapter.clearProgress();
onAppChanged(); onAppChanged();
String errorMessage = String errorMessage =
@ -369,7 +369,7 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
String title = String.format( String title = String.format(
getString(R.string.install_error_notify_title), getString(R.string.install_error_notify_title),
mApp.name); app.name);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(AppDetails2.this); AlertDialog.Builder alertBuilder = new AlertDialog.Builder(AppDetails2.this);
alertBuilder.setTitle(title); alertBuilder.setTitle(title);
@ -401,15 +401,15 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) { switch (intent.getAction()) {
case Installer.ACTION_UNINSTALL_STARTED: case Installer.ACTION_UNINSTALL_STARTED:
mAdapter.setProgress(-1, -1, R.string.uninstalling); adapter.setProgress(-1, -1, R.string.uninstalling);
break; break;
case Installer.ACTION_UNINSTALL_COMPLETE: case Installer.ACTION_UNINSTALL_COMPLETE:
mAdapter.clearProgress(); adapter.clearProgress();
onAppChanged(); onAppChanged();
unregisterUninstallReceiver(); unregisterUninstallReceiver();
break; break;
case Installer.ACTION_UNINSTALL_INTERRUPTED: case Installer.ACTION_UNINSTALL_INTERRUPTED:
mAdapter.clearProgress(); adapter.clearProgress();
String errorMessage = String errorMessage =
intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE); intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE);
@ -458,13 +458,13 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
} }
setApp(newApp); setApp(newApp);
return this.mApp != null; return this.app != null;
} }
private void calcActiveDownloadUrlString(String packageName) { private void calcActiveDownloadUrlString(String packageName) {
String urlString = getPreferences(MODE_PRIVATE).getString(packageName, null); String urlString = getPreferences(MODE_PRIVATE).getString(packageName, null);
if (DownloaderService.isQueuedOrActive(urlString)) { if (DownloaderService.isQueuedOrActive(urlString)) {
mActiveDownloadUrlString = urlString; activeDownloadUrlString = urlString;
} else { } else {
// this URL is no longer active, remove it // this URL is no longer active, remove it
getPreferences(MODE_PRIVATE).edit().remove(packageName).apply(); getPreferences(MODE_PRIVATE).edit().remove(packageName).apply();
@ -475,21 +475,21 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
* Remove progress listener, suppress progress bar, set downloadHandler to null. * Remove progress listener, suppress progress bar, set downloadHandler to null.
*/ */
private void cleanUpFinishedDownload() { private void cleanUpFinishedDownload() {
mActiveDownloadUrlString = null; activeDownloadUrlString = null;
mAdapter.clearProgress(); adapter.clearProgress();
unregisterDownloaderReceiver(); unregisterDownloaderReceiver();
} }
private void onAppChanged() { private void onAppChanged() {
mRecyclerView.post(new Runnable() { recyclerView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!reset(mApp.packageName)) { if (!reset(app.packageName)) {
AppDetails2.this.finish(); AppDetails2.this.finish();
return; return;
} }
AppDetailsRecyclerViewAdapter adapter = (AppDetailsRecyclerViewAdapter) mRecyclerView.getAdapter(); AppDetailsRecyclerViewAdapter adapter = (AppDetailsRecyclerViewAdapter) recyclerView.getAdapter();
adapter.updateItems(mApp); adapter.updateItems(app);
supportInvalidateOptionsMenu(); supportInvalidateOptionsMenu();
} }
}); });
@ -497,12 +497,12 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
@Override @Override
public boolean isAppDownloading() { public boolean isAppDownloading() {
return !TextUtils.isEmpty(mActiveDownloadUrlString); return !TextUtils.isEmpty(activeDownloadUrlString);
} }
@Override @Override
public void enableAndroidBeam() { public void enableAndroidBeam() {
NfcHelper.setAndroidBeam(this, mApp.packageName); NfcHelper.setAndroidBeam(this, app.packageName);
} }
@Override @Override
@ -524,39 +524,39 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog
@Override @Override
public void installCancel() { public void installCancel() {
if (!TextUtils.isEmpty(mActiveDownloadUrlString)) { if (!TextUtils.isEmpty(activeDownloadUrlString)) {
InstallManagerService.cancel(this, mActiveDownloadUrlString); InstallManagerService.cancel(this, activeDownloadUrlString);
} }
} }
@Override @Override
public void launchApk() { public void launchApk() {
Intent intent = getPackageManager().getLaunchIntentForPackage(mApp.packageName); Intent intent = getPackageManager().getLaunchIntentForPackage(app.packageName);
startActivity(intent); startActivity(intent);
} }
@Override @Override
public void installApk() { public void installApk() {
Apk apkToInstall = ApkProvider.Helper.findApkFromAnyRepo(this, mApp.packageName, mApp.suggestedVersionCode); Apk apkToInstall = ApkProvider.Helper.findApkFromAnyRepo(this, app.packageName, app.suggestedVersionCode);
installApk(apkToInstall); installApk(apkToInstall);
} }
@Override @Override
public void upgradeApk() { public void upgradeApk() {
Apk apkToInstall = ApkProvider.Helper.findApkFromAnyRepo(this, mApp.packageName, mApp.suggestedVersionCode); Apk apkToInstall = ApkProvider.Helper.findApkFromAnyRepo(this, app.packageName, app.suggestedVersionCode);
installApk(apkToInstall); installApk(apkToInstall);
} }
@Override @Override
public void uninstallApk() { public void uninstallApk() {
Apk apk = mApp.installedApk; Apk apk = app.installedApk;
if (apk == null) { if (apk == null) {
// TODO ideally, app would be refreshed immediately after install, then this // TODO ideally, app would be refreshed immediately after install, then this
// workaround would be unnecessary // workaround would be unnecessary
try { try {
PackageInfo pi = getPackageManager().getPackageInfo(mApp.packageName, 0); PackageInfo pi = getPackageManager().getPackageInfo(app.packageName, 0);
apk = ApkProvider.Helper.findApkFromAnyRepo(this, pi.packageName, pi.versionCode); apk = ApkProvider.Helper.findApkFromAnyRepo(this, pi.packageName, pi.versionCode);
mApp.installedApk = apk; app.installedApk = apk;
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
return; // not installed return; // not installed

View File

@ -202,7 +202,7 @@ public final class PRNGFixes {
* each instance needs to seed itself if the client does not explicitly * each instance needs to seed itself if the client does not explicitly
* seed it. * seed it.
*/ */
private boolean mSeeded; private boolean seeded;
@Override @Override
protected void engineSetSeed(byte[] bytes) { protected void engineSetSeed(byte[] bytes) {
@ -218,13 +218,13 @@ public final class PRNGFixes {
// Log and ignore. // Log and ignore.
Log.w(TAG, "Failed to mix seed into " + URANDOM_FILE); Log.w(TAG, "Failed to mix seed into " + URANDOM_FILE);
} finally { } finally {
mSeeded = true; seeded = true;
} }
} }
@Override @Override
protected void engineNextBytes(byte[] bytes) { protected void engineNextBytes(byte[] bytes) {
if (!mSeeded) { if (!seeded) {
// Mix in the device- and invocation-specific seed. // Mix in the device- and invocation-specific seed.
engineSetSeed(generateSeed()); engineSetSeed(generateSeed());
} }

View File

@ -46,7 +46,7 @@ final class BonjourFinder extends PeerFinder implements ServiceListener {
private JmDNS jmdns; private JmDNS jmdns;
private WifiManager wifiManager; private WifiManager wifiManager;
private WifiManager.MulticastLock mMulticastLock; private WifiManager.MulticastLock multicastLock;
private BonjourFinder(Context context, Subscriber<? super Peer> subscriber) { private BonjourFinder(Context context, Subscriber<? super Peer> subscriber) {
super(context, subscriber); super(context, subscriber);
@ -58,8 +58,8 @@ final class BonjourFinder extends PeerFinder implements ServiceListener {
if (wifiManager == null) { if (wifiManager == null) {
wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mMulticastLock = wifiManager.createMulticastLock(context.getPackageName()); multicastLock = wifiManager.createMulticastLock(context.getPackageName());
mMulticastLock.setReferenceCounted(false); multicastLock.setReferenceCounted(false);
} }
if (isScanning) { if (isScanning) {
@ -68,7 +68,7 @@ final class BonjourFinder extends PeerFinder implements ServiceListener {
} }
isScanning = true; isScanning = true;
mMulticastLock.acquire(); multicastLock.acquire();
try { try {
Utils.debugLog(TAG, "Searching for Bonjour (mDNS) clients..."); Utils.debugLog(TAG, "Searching for Bonjour (mDNS) clients...");
@ -146,8 +146,8 @@ final class BonjourFinder extends PeerFinder implements ServiceListener {
private void cancel() { private void cancel() {
Utils.debugLog(TAG, "Cancelling BonjourFinder, releasing multicast lock, removing jmdns service listeners"); Utils.debugLog(TAG, "Cancelling BonjourFinder, releasing multicast lock, removing jmdns service listeners");
if (mMulticastLock != null) { if (multicastLock != null) {
mMulticastLock.release(); multicastLock.release();
} }
isScanning = false; isScanning = false;

View File

@ -129,7 +129,7 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
* 1. Check for root access * 1. Check for root access
*/ */
private final AsyncTask<Void, Void, Boolean> checkRootTask = new AsyncTask<Void, Void, Boolean>() { private final AsyncTask<Void, Void, Boolean> checkRootTask = new AsyncTask<Void, Void, Boolean>() {
ProgressDialog mProgressDialog; ProgressDialog progressDialog;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
@ -139,11 +139,11 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
ContextThemeWrapper theme = new ContextThemeWrapper(InstallExtensionDialogActivity.this, ContextThemeWrapper theme = new ContextThemeWrapper(InstallExtensionDialogActivity.this,
FDroidApp.getCurThemeResId()); FDroidApp.getCurThemeResId());
mProgressDialog = new ProgressDialog(theme); progressDialog = new ProgressDialog(theme);
mProgressDialog.setMessage(getString(R.string.requesting_root_access_body)); progressDialog.setMessage(getString(R.string.requesting_root_access_body));
mProgressDialog.setIndeterminate(true); progressDialog.setIndeterminate(true);
mProgressDialog.setCancelable(false); progressDialog.setCancelable(false);
mProgressDialog.show(); progressDialog.show();
} }
@Override @Override
@ -155,7 +155,7 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
protected void onPostExecute(Boolean rootGranted) { protected void onPostExecute(Boolean rootGranted) {
super.onPostExecute(rootGranted); super.onPostExecute(rootGranted);
mProgressDialog.dismiss(); progressDialog.dismiss();
if (rootGranted) { if (rootGranted) {
// root access granted // root access granted
@ -193,7 +193,7 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
* 2. Install into system * 2. Install into system
*/ */
private final AsyncTask<Void, Void, Void> installTask = new AsyncTask<Void, Void, Void>() { private final AsyncTask<Void, Void, Void> installTask = new AsyncTask<Void, Void, Void>() {
ProgressDialog mProgressDialog; ProgressDialog progressDialog;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
@ -203,11 +203,11 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
ContextThemeWrapper theme = new ContextThemeWrapper(InstallExtensionDialogActivity.this, ContextThemeWrapper theme = new ContextThemeWrapper(InstallExtensionDialogActivity.this,
FDroidApp.getCurThemeResId()); FDroidApp.getCurThemeResId());
mProgressDialog = new ProgressDialog(theme); progressDialog = new ProgressDialog(theme);
mProgressDialog.setMessage(InstallExtension.create(getApplicationContext()).getInstallingString()); progressDialog.setMessage(InstallExtension.create(getApplicationContext()).getInstallingString());
mProgressDialog.setIndeterminate(true); progressDialog.setIndeterminate(true);
mProgressDialog.setCancelable(false); progressDialog.setCancelable(false);
mProgressDialog.show(); progressDialog.show();
} }
@Override @Override
@ -298,7 +298,7 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
} }
private final AsyncTask<Void, Void, Void> uninstallTask = new AsyncTask<Void, Void, Void>() { private final AsyncTask<Void, Void, Void> uninstallTask = new AsyncTask<Void, Void, Void>() {
ProgressDialog mProgressDialog; ProgressDialog progressDialog;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
@ -308,11 +308,11 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
ContextThemeWrapper theme = new ContextThemeWrapper(InstallExtensionDialogActivity.this, ContextThemeWrapper theme = new ContextThemeWrapper(InstallExtensionDialogActivity.this,
FDroidApp.getCurThemeResId()); FDroidApp.getCurThemeResId());
mProgressDialog = new ProgressDialog(theme); progressDialog = new ProgressDialog(theme);
mProgressDialog.setMessage(getString(R.string.system_install_uninstalling)); progressDialog.setMessage(getString(R.string.system_install_uninstalling));
mProgressDialog.setIndeterminate(true); progressDialog.setIndeterminate(true);
mProgressDialog.setCancelable(false); progressDialog.setCancelable(false);
mProgressDialog.show(); progressDialog.show();
} }
@Override @Override
@ -325,7 +325,7 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
protected void onPostExecute(Void unused) { protected void onPostExecute(Void unused) {
super.onPostExecute(unused); super.onPostExecute(unused);
mProgressDialog.dismiss(); progressDialog.dismiss();
// app is uninstalled but still display, kill it! // app is uninstalled but still display, kill it!
System.exit(0); System.exit(0);

View File

@ -90,7 +90,7 @@ public class AppSecurityPermissions {
// PermissionGroupInfo implements Parcelable but its Parcel constructor is private and thus cannot be extended. // PermissionGroupInfo implements Parcelable but its Parcel constructor is private and thus cannot be extended.
@SuppressLint("ParcelCreator") @SuppressLint("ParcelCreator")
static class MyPermissionGroupInfo extends PermissionGroupInfo { static class MyPermissionGroupInfo extends PermissionGroupInfo {
CharSequence mLabel; CharSequence label;
final List<MyPermissionInfo> newPermissions = new ArrayList<>(); final List<MyPermissionInfo> newPermissions = new ArrayList<>();
final List<MyPermissionInfo> allPermissions = new ArrayList<>(); final List<MyPermissionInfo> allPermissions = new ArrayList<>();
@ -185,7 +185,7 @@ public class AppSecurityPermissions {
} }
PackageManager pm = getContext().getPackageManager(); PackageManager pm = getContext().getPackageManager();
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(group.mLabel); builder.setTitle(group.label);
if (perm.descriptionRes != 0) { if (perm.descriptionRes != 0) {
builder.setMessage(perm.loadDescription(pm)); builder.setMessage(perm.loadDescription(pm));
} else { } else {
@ -431,22 +431,22 @@ public class AppSecurityPermissions {
private static class PermissionGroupInfoComparator implements Comparator<MyPermissionGroupInfo> { private static class PermissionGroupInfoComparator implements Comparator<MyPermissionGroupInfo> {
private final Collator sCollator = Collator.getInstance(); private final Collator collator = Collator.getInstance();
public final int compare(MyPermissionGroupInfo a, MyPermissionGroupInfo b) { public final int compare(MyPermissionGroupInfo a, MyPermissionGroupInfo b) {
return sCollator.compare(a.mLabel, b.mLabel); return collator.compare(a.label, b.label);
} }
} }
private static class PermissionInfoComparator implements Comparator<MyPermissionInfo> { private static class PermissionInfoComparator implements Comparator<MyPermissionInfo> {
private final Collator sCollator = Collator.getInstance(); private final Collator collator = Collator.getInstance();
PermissionInfoComparator() { PermissionInfoComparator() {
} }
public final int compare(MyPermissionInfo a, MyPermissionInfo b) { public final int compare(MyPermissionInfo a, MyPermissionInfo b) {
return sCollator.compare(a.label, b.label); return collator.compare(a.label, b.label);
} }
} }
@ -482,13 +482,13 @@ public class AppSecurityPermissions {
for (MyPermissionGroupInfo pgrp : permGroups.values()) { for (MyPermissionGroupInfo pgrp : permGroups.values()) {
if (pgrp.labelRes != 0 || pgrp.nonLocalizedLabel != null) { if (pgrp.labelRes != 0 || pgrp.nonLocalizedLabel != null) {
pgrp.mLabel = pgrp.loadLabel(pm); pgrp.label = pgrp.loadLabel(pm);
} else { } else {
try { try {
ApplicationInfo app = pm.getApplicationInfo(pgrp.packageName, 0); ApplicationInfo app = pm.getApplicationInfo(pgrp.packageName, 0);
pgrp.mLabel = app.loadLabel(pm); pgrp.label = app.loadLabel(pm);
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
pgrp.mLabel = pgrp.loadLabel(pm); pgrp.label = pgrp.loadLabel(pm);
} }
} }
permGroupsList.add(pgrp); permGroupsList.add(pgrp);

View File

@ -85,40 +85,40 @@ public class AppDetailsRecyclerViewAdapter
private static final int VIEWTYPE_VERSIONS = 6; private static final int VIEWTYPE_VERSIONS = 6;
private static final int VIEWTYPE_VERSION = 7; private static final int VIEWTYPE_VERSION = 7;
private final Context mContext; private final Context context;
@NonNull @NonNull
private App mApp; private App app;
private final AppDetailsRecyclerViewAdapterCallbacks mCallbacks; private final AppDetailsRecyclerViewAdapterCallbacks callbacks;
private RecyclerView mRecyclerView; private RecyclerView recyclerView;
private ArrayList<Object> mItems; private ArrayList<Object> items;
private ArrayList<Apk> mVersions; private ArrayList<Apk> versions;
private boolean mShowVersions; private boolean showVersions;
private HeaderViewHolder mHeaderView; private HeaderViewHolder headerView;
public AppDetailsRecyclerViewAdapter(Context context, @NonNull App app, AppDetailsRecyclerViewAdapterCallbacks callbacks) { public AppDetailsRecyclerViewAdapter(Context context, @NonNull App app, AppDetailsRecyclerViewAdapterCallbacks callbacks) {
mContext = context; this.context = context;
mCallbacks = callbacks; this.callbacks = callbacks;
mApp = app; this.app = app;
updateItems(app); updateItems(app);
} }
public void updateItems(@NonNull App app) { public void updateItems(@NonNull App app) {
mApp = app; this.app = app;
// Get versions // Get versions
mVersions = new ArrayList<>(); versions = new ArrayList<>();
final List<Apk> apks = ApkProvider.Helper.findByPackageName(mContext, mApp.packageName); final List<Apk> apks = ApkProvider.Helper.findByPackageName(context, this.app.packageName);
for (final Apk apk : apks) { for (final Apk apk : apks) {
if (apk.compatible || Preferences.get().showIncompatibleVersions()) { if (apk.compatible || Preferences.get().showIncompatibleVersions()) {
mVersions.add(apk); versions.add(apk);
} }
} }
if (mItems == null) { if (items == null) {
mItems = new ArrayList<>(); items = new ArrayList<>();
} else { } else {
mItems.clear(); items.clear();
} }
addItem(VIEWTYPE_HEADER); addItem(VIEWTYPE_HEADER);
addItem(VIEWTYPE_SCREENSHOTS); addItem(VIEWTYPE_SCREENSHOTS);
@ -132,10 +132,10 @@ public class AppDetailsRecyclerViewAdapter
} }
private void setShowVersions(boolean showVersions) { private void setShowVersions(boolean showVersions) {
mShowVersions = showVersions; this.showVersions = showVersions;
mItems.removeAll(mVersions); items.removeAll(versions);
if (showVersions) { if (showVersions) {
mItems.addAll(mItems.indexOf(VIEWTYPE_VERSIONS) + 1, mVersions); items.addAll(items.indexOf(VIEWTYPE_VERSIONS) + 1, versions);
} }
notifyDataSetChanged(); notifyDataSetChanged();
} }
@ -148,28 +148,28 @@ public class AppDetailsRecyclerViewAdapter
} else if (item == VIEWTYPE_PERMISSIONS && !shouldShowPermissions()) { } else if (item == VIEWTYPE_PERMISSIONS && !shouldShowPermissions()) {
return; return;
} }
mItems.add(item); items.add(item);
} }
private boolean shouldShowPermissions() { private boolean shouldShowPermissions() {
// Figure out if we should show permissions section // Figure out if we should show permissions section
Apk curApk = null; Apk curApk = null;
for (int i = 0; i < mVersions.size(); i++) { for (int i = 0; i < versions.size(); i++) {
final Apk apk = mVersions.get(i); final Apk apk = versions.get(i);
if (apk.versionCode == mApp.suggestedVersionCode) { if (apk.versionCode == app.suggestedVersionCode) {
curApk = apk; curApk = apk;
break; break;
} }
} }
final boolean curApkCompatible = curApk != null && curApk.compatible; final boolean curApkCompatible = curApk != null && curApk.compatible;
return mVersions.size() > 0 && (curApkCompatible || Preferences.get().showIncompatibleVersions()); return versions.size() > 0 && (curApkCompatible || Preferences.get().showIncompatibleVersions());
} }
private boolean shouldShowDonate() { private boolean shouldShowDonate() {
return uriIsSetAndCanBeOpened(mApp.donateURL) || return uriIsSetAndCanBeOpened(app.donateURL) ||
uriIsSetAndCanBeOpened(mApp.getBitcoinUri()) || uriIsSetAndCanBeOpened(app.getBitcoinUri()) ||
uriIsSetAndCanBeOpened(mApp.getLitecoinUri()) || uriIsSetAndCanBeOpened(app.getLitecoinUri()) ||
uriIsSetAndCanBeOpened(mApp.getFlattrUri()); uriIsSetAndCanBeOpened(app.getFlattrUri());
} }
public void clearProgress() { public void clearProgress() {
@ -177,8 +177,8 @@ public class AppDetailsRecyclerViewAdapter
} }
public void setProgress(int bytesDownloaded, int totalBytes, int resIdString) { public void setProgress(int bytesDownloaded, int totalBytes, int resIdString) {
if (mHeaderView != null) { if (headerView != null) {
mHeaderView.setProgress(bytesDownloaded, totalBytes, resIdString); headerView.setProgress(bytesDownloaded, totalBytes, resIdString);
} }
} }
@ -218,7 +218,7 @@ public class AppDetailsRecyclerViewAdapter
int viewType = getItemViewType(position); int viewType = getItemViewType(position);
if (viewType == VIEWTYPE_HEADER) { if (viewType == VIEWTYPE_HEADER) {
HeaderViewHolder header = (HeaderViewHolder) holder; HeaderViewHolder header = (HeaderViewHolder) holder;
mHeaderView = header; headerView = header;
header.bindModel(); header.bindModel();
} else if (viewType == VIEWTYPE_SCREENSHOTS) { } else if (viewType == VIEWTYPE_SCREENSHOTS) {
((ScreenShotsViewHolder) holder).bindModel(); ((ScreenShotsViewHolder) holder).bindModel();
@ -233,7 +233,7 @@ public class AppDetailsRecyclerViewAdapter
} else if (viewType == VIEWTYPE_VERSIONS) { } else if (viewType == VIEWTYPE_VERSIONS) {
((VersionsViewHolder) holder).bindModel(); ((VersionsViewHolder) holder).bindModel();
} else if (viewType == VIEWTYPE_VERSION) { } else if (viewType == VIEWTYPE_VERSION) {
final Apk apk = (Apk) mItems.get(position); final Apk apk = (Apk) items.get(position);
((VersionViewHolder) holder).bindModel(apk); ((VersionViewHolder) holder).bindModel(apk);
} }
} }
@ -241,22 +241,22 @@ public class AppDetailsRecyclerViewAdapter
@Override @Override
public void onViewRecycled(RecyclerView.ViewHolder holder) { public void onViewRecycled(RecyclerView.ViewHolder holder) {
if (holder instanceof HeaderViewHolder) { if (holder instanceof HeaderViewHolder) {
mHeaderView = null; headerView = null;
} }
super.onViewRecycled(holder); super.onViewRecycled(holder);
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return mItems.size(); return items.size();
} }
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (mItems.get(position) instanceof Apk) { if (items.get(position) instanceof Apk) {
return VIEWTYPE_VERSION; return VIEWTYPE_VERSION;
} }
return (Integer) mItems.get(position); return (Integer) items.get(position);
} }
public class HeaderViewHolder extends RecyclerView.ViewHolder { public class HeaderViewHolder extends RecyclerView.ViewHolder {
@ -308,12 +308,12 @@ public class AppDetailsRecyclerViewAdapter
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// Remember current scroll position so that we can restore it // Remember current scroll position so that we can restore it
LinearLayoutManager lm = (LinearLayoutManager) mRecyclerView.getLayoutManager(); LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager();
int pos = lm.findFirstVisibleItemPosition(); int pos = lm.findFirstVisibleItemPosition();
int posOffset = 0; int posOffset = 0;
if (pos != RecyclerView.NO_POSITION) { if (pos != RecyclerView.NO_POSITION) {
View firstChild = mRecyclerView.getChildAt(0); View firstChild = recyclerView.getChildAt(0);
posOffset = (firstChild == null) ? 0 : (firstChild.getTop()); // - mRecyclerView.getPaddingTop()); posOffset = (firstChild == null) ? 0 : (firstChild.getTop()); // - recyclerView.getPaddingTop());
} }
if (TextViewCompat.getMaxLines(descriptionView) != MAX_LINES) { if (TextViewCompat.getMaxLines(descriptionView) != MAX_LINES) {
descriptionView.setMaxLines(MAX_LINES); descriptionView.setMaxLines(MAX_LINES);
@ -367,16 +367,16 @@ public class AppDetailsRecyclerViewAdapter
} }
public void bindModel() { public void bindModel() {
ImageLoader.getInstance().displayImage(mApp.iconUrlLarge, iconView, displayImageOptions); ImageLoader.getInstance().displayImage(app.iconUrlLarge, iconView, displayImageOptions);
titleView.setText(mApp.name); titleView.setText(app.name);
if (!TextUtils.isEmpty(mApp.author)) { if (!TextUtils.isEmpty(app.author)) {
authorView.setText(mContext.getString(R.string.by_author) + " " + mApp.author); authorView.setText(context.getString(R.string.by_author) + " " + app.author);
authorView.setVisibility(View.VISIBLE); authorView.setVisibility(View.VISIBLE);
} else { } else {
authorView.setVisibility(View.GONE); authorView.setVisibility(View.GONE);
} }
summaryView.setText(mApp.summary); summaryView.setText(app.summary);
final Spanned desc = Html.fromHtml(mApp.description, null, new Utils.HtmlTagHandler()); final Spanned desc = Html.fromHtml(app.description, null, new Utils.HtmlTagHandler());
descriptionView.setMovementMethod(LinkMovementMethod.getInstance()); descriptionView.setMovementMethod(LinkMovementMethod.getInstance());
descriptionView.setText(trimTrailingNewlines(desc)); descriptionView.setText(trimTrailingNewlines(desc));
if (descriptionView.getText() instanceof Spannable) { if (descriptionView.getText() instanceof Spannable) {
@ -403,36 +403,36 @@ public class AppDetailsRecyclerViewAdapter
} }
}); });
buttonSecondaryView.setText(R.string.menu_uninstall); buttonSecondaryView.setText(R.string.menu_uninstall);
buttonSecondaryView.setVisibility(mApp.isInstalled() ? View.VISIBLE : View.INVISIBLE); buttonSecondaryView.setVisibility(app.isInstalled() ? View.VISIBLE : View.INVISIBLE);
buttonSecondaryView.setOnClickListener(mOnUnInstallClickListener); buttonSecondaryView.setOnClickListener(onUnInstallClickListener);
buttonPrimaryView.setText(R.string.menu_install); buttonPrimaryView.setText(R.string.menu_install);
buttonPrimaryView.setVisibility(mVersions.size() > 0 ? View.VISIBLE : View.GONE); buttonPrimaryView.setVisibility(versions.size() > 0 ? View.VISIBLE : View.GONE);
if (mCallbacks.isAppDownloading()) { if (callbacks.isAppDownloading()) {
buttonPrimaryView.setText(R.string.downloading); buttonPrimaryView.setText(R.string.downloading);
buttonPrimaryView.setEnabled(false); buttonPrimaryView.setEnabled(false);
} else if (!mApp.isInstalled() && mApp.suggestedVersionCode > 0 && mVersions.size() > 0) { } else if (!app.isInstalled() && app.suggestedVersionCode > 0 && versions.size() > 0) {
// Check count > 0 due to incompatible apps resulting in an empty list. // Check count > 0 due to incompatible apps resulting in an empty list.
mCallbacks.disableAndroidBeam(); callbacks.disableAndroidBeam();
// Set Install button and hide second button // Set Install button and hide second button
buttonPrimaryView.setText(R.string.menu_install); buttonPrimaryView.setText(R.string.menu_install);
buttonPrimaryView.setOnClickListener(mOnInstallClickListener); buttonPrimaryView.setOnClickListener(onInstallClickListener);
buttonPrimaryView.setEnabled(true); buttonPrimaryView.setEnabled(true);
} else if (mApp.isInstalled()) { } else if (app.isInstalled()) {
mCallbacks.enableAndroidBeam(); callbacks.enableAndroidBeam();
if (mApp.canAndWantToUpdate(mContext)) { if (app.canAndWantToUpdate(context)) {
buttonPrimaryView.setText(R.string.menu_upgrade); buttonPrimaryView.setText(R.string.menu_upgrade);
buttonPrimaryView.setOnClickListener(mOnUpgradeClickListener); buttonPrimaryView.setOnClickListener(onUpgradeClickListener);
} else { } else {
if (mContext.getPackageManager().getLaunchIntentForPackage(mApp.packageName) != null) { if (context.getPackageManager().getLaunchIntentForPackage(app.packageName) != null) {
buttonPrimaryView.setText(R.string.menu_launch); buttonPrimaryView.setText(R.string.menu_launch);
buttonPrimaryView.setOnClickListener(mOnLaunchClickListener); buttonPrimaryView.setOnClickListener(onLaunchClickListener);
} else { } else {
buttonPrimaryView.setVisibility(View.GONE); buttonPrimaryView.setVisibility(View.GONE);
} }
} }
buttonPrimaryView.setEnabled(true); buttonPrimaryView.setEnabled(true);
} }
if (mCallbacks.isAppDownloading()) { if (callbacks.isAppDownloading()) {
buttonLayout.setVisibility(View.GONE); buttonLayout.setVisibility(View.GONE);
progressLayout.setVisibility(View.VISIBLE); progressLayout.setVisibility(View.VISIBLE);
} else { } else {
@ -442,7 +442,7 @@ public class AppDetailsRecyclerViewAdapter
progressCancel.setOnClickListener(new View.OnClickListener() { progressCancel.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mCallbacks.installCancel(); callbacks.installCancel();
} }
}); });
@ -452,12 +452,12 @@ public class AppDetailsRecyclerViewAdapter
@Override @Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) { public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView); super.onAttachedToRecyclerView(recyclerView);
mRecyclerView = recyclerView; this.recyclerView = recyclerView;
} }
@Override @Override
public void onDetachedFromRecyclerView(RecyclerView recyclerView) { public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
mRecyclerView = null; this.recyclerView = null;
super.onDetachedFromRecyclerView(recyclerView); super.onDetachedFromRecyclerView(recyclerView);
} }
@ -471,9 +471,9 @@ public class AppDetailsRecyclerViewAdapter
} }
public void bindModel() { public void bindModel() {
LinearLayoutManager lm = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false); LinearLayoutManager lm = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(lm); recyclerView.setLayoutManager(lm);
ScreenShotsRecyclerViewAdapter adapter = new ScreenShotsRecyclerViewAdapter(itemView.getContext(), mApp); ScreenShotsRecyclerViewAdapter adapter = new ScreenShotsRecyclerViewAdapter(itemView.getContext(), app);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
recyclerView.setHasFixedSize(true); recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false); recyclerView.setNestedScrollingEnabled(false);
@ -513,23 +513,23 @@ public class AppDetailsRecyclerViewAdapter
contentView.removeAllViews(); contentView.removeAllViews();
// Donate button // Donate button
if (uriIsSetAndCanBeOpened(mApp.donateURL)) { if (uriIsSetAndCanBeOpened(app.donateURL)) {
addLinkItemView(contentView, R.string.menu_donate, R.drawable.ic_donate, mApp.donateURL); addLinkItemView(contentView, R.string.menu_donate, R.drawable.ic_donate, app.donateURL);
} }
// Bitcoin // Bitcoin
if (uriIsSetAndCanBeOpened(mApp.getBitcoinUri())) { if (uriIsSetAndCanBeOpened(app.getBitcoinUri())) {
addLinkItemView(contentView, R.string.menu_bitcoin, R.drawable.ic_bitcoin, mApp.getBitcoinUri()); addLinkItemView(contentView, R.string.menu_bitcoin, R.drawable.ic_bitcoin, app.getBitcoinUri());
} }
// Litecoin // Litecoin
if (uriIsSetAndCanBeOpened(mApp.getLitecoinUri())) { if (uriIsSetAndCanBeOpened(app.getLitecoinUri())) {
addLinkItemView(contentView, R.string.menu_litecoin, R.drawable.ic_litecoin, mApp.getLitecoinUri()); addLinkItemView(contentView, R.string.menu_litecoin, R.drawable.ic_litecoin, app.getLitecoinUri());
} }
// Flattr // Flattr
if (uriIsSetAndCanBeOpened(mApp.getFlattrUri())) { if (uriIsSetAndCanBeOpened(app.getFlattrUri())) {
addLinkItemView(contentView, R.string.menu_flattr, R.drawable.ic_flattr, mApp.getFlattrUri()); addLinkItemView(contentView, R.string.menu_flattr, R.drawable.ic_flattr, app.getFlattrUri());
} }
} }
} }
@ -555,11 +555,11 @@ public class AppDetailsRecyclerViewAdapter
itemView.setOnClickListener(new View.OnClickListener() { itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
setShowVersions(!mShowVersions); setShowVersions(!showVersions);
} }
}); });
headerView.setText(R.string.versions); headerView.setText(R.string.versions);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(headerView, R.drawable.ic_access_time_24dp_grey600, 0, mShowVersions ? R.drawable.ic_expand_less_grey600 : R.drawable.ic_expand_more_grey600, 0); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(headerView, R.drawable.ic_access_time_24dp_grey600, 0, showVersions ? R.drawable.ic_expand_less_grey600 : R.drawable.ic_expand_more_grey600, 0);
} }
} }
@ -581,8 +581,8 @@ public class AppDetailsRecyclerViewAdapter
headerView.setText(R.string.permissions); headerView.setText(R.string.permissions);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(headerView, R.drawable.ic_lock_24dp_grey600, 0, R.drawable.ic_expand_more_grey600, 0); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(headerView, R.drawable.ic_lock_24dp_grey600, 0, R.drawable.ic_expand_more_grey600, 0);
contentView.removeAllViews(); contentView.removeAllViews();
AppDiff appDiff = new AppDiff(mContext.getPackageManager(), mVersions.get(0)); AppDiff appDiff = new AppDiff(context.getPackageManager(), versions.get(0));
AppSecurityPermissions perms = new AppSecurityPermissions(mContext, appDiff.pkgInfo); AppSecurityPermissions perms = new AppSecurityPermissions(context, appDiff.pkgInfo);
contentView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_ALL)); contentView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_ALL));
} }
} }
@ -607,28 +607,28 @@ public class AppDetailsRecyclerViewAdapter
contentView.removeAllViews(); contentView.removeAllViews();
// Source button // Source button
if (uriIsSetAndCanBeOpened(mApp.sourceURL)) { if (uriIsSetAndCanBeOpened(app.sourceURL)) {
addLinkItemView(contentView, R.string.menu_source, R.drawable.ic_source_code, mApp.sourceURL); addLinkItemView(contentView, R.string.menu_source, R.drawable.ic_source_code, app.sourceURL);
} }
// Issues button // Issues button
if (uriIsSetAndCanBeOpened(mApp.trackerURL)) { if (uriIsSetAndCanBeOpened(app.trackerURL)) {
addLinkItemView(contentView, R.string.menu_issues, R.drawable.ic_issues, mApp.trackerURL); addLinkItemView(contentView, R.string.menu_issues, R.drawable.ic_issues, app.trackerURL);
} }
// Changelog button // Changelog button
if (uriIsSetAndCanBeOpened(mApp.changelogURL)) { if (uriIsSetAndCanBeOpened(app.changelogURL)) {
addLinkItemView(contentView, R.string.menu_changelog, R.drawable.ic_changelog, mApp.changelogURL); addLinkItemView(contentView, R.string.menu_changelog, R.drawable.ic_changelog, app.changelogURL);
} }
// Website button // Website button
if (uriIsSetAndCanBeOpened(mApp.webURL)) { if (uriIsSetAndCanBeOpened(app.webURL)) {
addLinkItemView(contentView, R.string.menu_website, R.drawable.ic_website, mApp.webURL); addLinkItemView(contentView, R.string.menu_website, R.drawable.ic_website, app.webURL);
} }
// Email button // Email button
final String subject = Uri.encode(mContext.getString(R.string.app_details_subject, mApp.name)); final String subject = Uri.encode(context.getString(R.string.app_details_subject, app.name));
String emailUrl = mApp.email == null ? null : ("mailto:" + mApp.email + "?subject=" + subject); String emailUrl = app.email == null ? null : ("mailto:" + app.email + "?subject=" + subject);
if (uriIsSetAndCanBeOpened(emailUrl)) { if (uriIsSetAndCanBeOpened(emailUrl)) {
addLinkItemView(contentView, R.string.menu_email, R.drawable.ic_email, emailUrl); addLinkItemView(contentView, R.string.menu_email, R.drawable.ic_email, emailUrl);
} }
@ -658,22 +658,22 @@ public class AppDetailsRecyclerViewAdapter
added = (TextView) view.findViewById(R.id.added); added = (TextView) view.findViewById(R.id.added);
nativecode = (TextView) view.findViewById(R.id.nativecode); nativecode = (TextView) view.findViewById(R.id.nativecode);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.layout_horizontal_margin); int margin = context.getResources().getDimensionPixelSize(R.dimen.layout_horizontal_margin);
int padding = mContext.getResources().getDimensionPixelSize(R.dimen.details_activity_padding); int padding = context.getResources().getDimensionPixelSize(R.dimen.details_activity_padding);
ViewCompat.setPaddingRelative(view, margin + padding + ViewCompat.getPaddingStart(view), view.getPaddingTop(), ViewCompat.getPaddingEnd(view), view.getPaddingBottom()); ViewCompat.setPaddingRelative(view, margin + padding + ViewCompat.getPaddingStart(view), view.getPaddingTop(), ViewCompat.getPaddingEnd(view), view.getPaddingBottom());
} }
public void bindModel(final Apk apk) { public void bindModel(final Apk apk) {
java.text.DateFormat df = DateFormat.getDateFormat(mContext); java.text.DateFormat df = DateFormat.getDateFormat(context);
version.setText(mContext.getString(R.string.version) version.setText(context.getString(R.string.version)
+ " " + apk.versionName + " " + apk.versionName
+ (apk.versionCode == mApp.suggestedVersionCode ? "" : "")); + (apk.versionCode == app.suggestedVersionCode ? "" : ""));
status.setText(getInstalledStatus(apk)); status.setText(getInstalledStatus(apk));
repository.setText(mContext.getString(R.string.repo_provider, repository.setText(context.getString(R.string.repo_provider,
RepoProvider.Helper.findById(mContext, apk.repo).getName())); RepoProvider.Helper.findById(context, apk.repo).getName()));
if (apk.size > 0) { if (apk.size > 0) {
size.setText(Utils.getFriendlySize(apk.size)); size.setText(Utils.getFriendlySize(apk.size));
@ -685,16 +685,16 @@ public class AppDetailsRecyclerViewAdapter
if (!Preferences.get().expertMode()) { if (!Preferences.get().expertMode()) {
api.setVisibility(View.GONE); api.setVisibility(View.GONE);
} else if (apk.minSdkVersion > 0 && apk.maxSdkVersion < Apk.SDK_VERSION_MAX_VALUE) { } else if (apk.minSdkVersion > 0 && apk.maxSdkVersion < Apk.SDK_VERSION_MAX_VALUE) {
api.setText(mContext.getString(R.string.minsdk_up_to_maxsdk, api.setText(context.getString(R.string.minsdk_up_to_maxsdk,
Utils.getAndroidVersionName(apk.minSdkVersion), Utils.getAndroidVersionName(apk.minSdkVersion),
Utils.getAndroidVersionName(apk.maxSdkVersion))); Utils.getAndroidVersionName(apk.maxSdkVersion)));
api.setVisibility(View.VISIBLE); api.setVisibility(View.VISIBLE);
} else if (apk.minSdkVersion > 0) { } else if (apk.minSdkVersion > 0) {
api.setText(mContext.getString(R.string.minsdk_or_later, api.setText(context.getString(R.string.minsdk_or_later,
Utils.getAndroidVersionName(apk.minSdkVersion))); Utils.getAndroidVersionName(apk.minSdkVersion)));
api.setVisibility(View.VISIBLE); api.setVisibility(View.VISIBLE);
} else if (apk.maxSdkVersion > 0) { } else if (apk.maxSdkVersion > 0) {
api.setText(mContext.getString(R.string.up_to_maxsdk, api.setText(context.getString(R.string.up_to_maxsdk,
Utils.getAndroidVersionName(apk.maxSdkVersion))); Utils.getAndroidVersionName(apk.maxSdkVersion)));
api.setVisibility(View.VISIBLE); api.setVisibility(View.VISIBLE);
} }
@ -706,7 +706,7 @@ public class AppDetailsRecyclerViewAdapter
} }
if (apk.added != null) { if (apk.added != null) {
added.setText(mContext.getString(R.string.added_on, added.setText(context.getString(R.string.added_on,
df.format(apk.added))); df.format(apk.added)));
added.setVisibility(View.VISIBLE); added.setVisibility(View.VISIBLE);
} else { } else {
@ -722,7 +722,7 @@ public class AppDetailsRecyclerViewAdapter
if (apk.incompatibleReasons != null) { if (apk.incompatibleReasons != null) {
incompatibleReasons.setText( incompatibleReasons.setText(
mContext.getResources().getString( context.getResources().getString(
R.string.requires_features, R.string.requires_features,
TextUtils.join(", ", apk.incompatibleReasons))); TextUtils.join(", ", apk.incompatibleReasons)));
incompatibleReasons.setVisibility(View.VISIBLE); incompatibleReasons.setVisibility(View.VISIBLE);
@ -748,7 +748,7 @@ public class AppDetailsRecyclerViewAdapter
itemView.setOnClickListener(new View.OnClickListener() { itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mCallbacks.installApk(apk); callbacks.installApk(apk);
} }
}); });
} }
@ -769,60 +769,60 @@ public class AppDetailsRecyclerViewAdapter
private String getInstalledStatus(final Apk apk) { private String getInstalledStatus(final Apk apk) {
// Definitely not installed. // Definitely not installed.
if (apk.versionCode != mApp.installedVersionCode) { if (apk.versionCode != app.installedVersionCode) {
return mContext.getString(R.string.app_not_installed); return context.getString(R.string.app_not_installed);
} }
// Definitely installed this version. // Definitely installed this version.
if (apk.sig != null && apk.sig.equals(mApp.installedSig)) { if (apk.sig != null && apk.sig.equals(app.installedSig)) {
return mContext.getString(R.string.app_installed); return context.getString(R.string.app_installed);
} }
// Installed the same version, but from someplace else. // Installed the same version, but from someplace else.
final String installerPkgName; final String installerPkgName;
try { try {
installerPkgName = mContext.getPackageManager().getInstallerPackageName(mApp.packageName); installerPkgName = context.getPackageManager().getInstallerPackageName(app.packageName);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.w("AppDetailsAdapter", "Application " + mApp.packageName + " is not installed anymore"); Log.w("AppDetailsAdapter", "Application " + app.packageName + " is not installed anymore");
return mContext.getString(R.string.app_not_installed); return context.getString(R.string.app_not_installed);
} }
if (TextUtils.isEmpty(installerPkgName)) { if (TextUtils.isEmpty(installerPkgName)) {
return mContext.getString(R.string.app_inst_unknown_source); return context.getString(R.string.app_inst_unknown_source);
} }
final String installerLabel = InstalledAppProvider final String installerLabel = InstalledAppProvider
.getApplicationLabel(mContext, installerPkgName); .getApplicationLabel(context, installerPkgName);
return mContext.getString(R.string.app_inst_known_source, installerLabel); return context.getString(R.string.app_inst_known_source, installerLabel);
} }
private void onLinkClicked(String url) { private void onLinkClicked(String url) {
if (!TextUtils.isEmpty(url)) { if (!TextUtils.isEmpty(url)) {
mCallbacks.openUrl(url); callbacks.openUrl(url);
} }
} }
private final View.OnClickListener mOnInstallClickListener = new View.OnClickListener() { private final View.OnClickListener onInstallClickListener = new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mCallbacks.installApk(); callbacks.installApk();
} }
}; };
private final View.OnClickListener mOnUnInstallClickListener = new View.OnClickListener() { private final View.OnClickListener onUnInstallClickListener = new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mCallbacks.uninstallApk(); callbacks.uninstallApk();
} }
}; };
private final View.OnClickListener mOnUpgradeClickListener = new View.OnClickListener() { private final View.OnClickListener onUpgradeClickListener = new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mCallbacks.upgradeApk(); callbacks.upgradeApk();
} }
}; };
private final View.OnClickListener mOnLaunchClickListener = new View.OnClickListener() { private final View.OnClickListener onLaunchClickListener = new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mCallbacks.launchApk(); callbacks.launchApk();
} }
}; };
@ -831,7 +831,7 @@ public class AppDetailsRecyclerViewAdapter
return false; return false;
} }
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(s)); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
return intent.resolveActivity(mContext.getPackageManager()) != null; return intent.resolveActivity(context.getPackageManager()) != null;
} }
/** /**

View File

@ -18,7 +18,7 @@ import org.fdroid.fdroid.data.App;
public abstract class AppListAdapter extends CursorAdapter { public abstract class AppListAdapter extends CursorAdapter {
private LayoutInflater mInflater; private LayoutInflater inflater;
private DisplayImageOptions displayImageOptions; private DisplayImageOptions displayImageOptions;
private String upgradeFromTo; private String upgradeFromTo;
@ -44,7 +44,7 @@ public abstract class AppListAdapter extends CursorAdapter {
} }
private void init(Context context) { private void init(Context context) {
mInflater = (LayoutInflater) context.getSystemService( inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE); Context.LAYOUT_INFLATER_SERVICE);
displayImageOptions = Utils.getImageLoadingOptions().build(); displayImageOptions = Utils.getImageLoadingOptions().build();
upgradeFromTo = context.getResources().getString(R.string.upgrade_from_to); upgradeFromTo = context.getResources().getString(R.string.upgrade_from_to);
@ -64,7 +64,7 @@ public abstract class AppListAdapter extends CursorAdapter {
@Override @Override
public View newView(Context context, Cursor cursor, ViewGroup parent) { public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = mInflater.inflate(R.layout.applistitem, parent, false); View view = inflater.inflate(R.layout.applistitem, parent, false);
ViewHolder holder = new ViewHolder(); ViewHolder holder = new ViewHolder();
holder.name = (TextView) view.findViewById(R.id.name); holder.name = (TextView) view.findViewById(R.id.name);

View File

@ -9,8 +9,8 @@ import android.view.View;
public class LinearLayoutManagerSnapHelper extends LinearSnapHelper { public class LinearLayoutManagerSnapHelper extends LinearSnapHelper {
private View mLastSavedTarget; private View lastSavedTarget;
private int mLastSavedDistance; private int lastSavedDistance;
public interface LinearSnapHelperListener { public interface LinearSnapHelperListener {
/** /**
@ -21,17 +21,17 @@ public class LinearLayoutManagerSnapHelper extends LinearSnapHelper {
void onSnappedToView(View view, int position); void onSnappedToView(View view, int position);
} }
private final LinearLayoutManager mLlm; private final LinearLayoutManager layoutManager;
private final OrientationHelper mOrientationHelper; private final OrientationHelper orientationHelper;
private LinearSnapHelperListener mListener; private LinearSnapHelperListener listener;
public LinearLayoutManagerSnapHelper(LinearLayoutManager llm) { public LinearLayoutManagerSnapHelper(LinearLayoutManager layoutManager) {
this.mLlm = llm; this.layoutManager = layoutManager;
this.mOrientationHelper = OrientationHelper.createHorizontalHelper(mLlm); this.orientationHelper = OrientationHelper.createHorizontalHelper(this.layoutManager);
} }
public void setLinearSnapHelperListener(LinearSnapHelperListener listener) { public void setLinearSnapHelperListener(LinearSnapHelperListener listener) {
mListener = listener; this.listener = listener;
} }
@Override @Override
@ -39,7 +39,7 @@ public class LinearLayoutManagerSnapHelper extends LinearSnapHelper {
View snappedView = super.findSnapView(layoutManager); View snappedView = super.findSnapView(layoutManager);
if (snappedView != null && layoutManager.canScrollHorizontally()) { if (snappedView != null && layoutManager.canScrollHorizontally()) {
if (layoutManager instanceof LinearLayoutManager) { if (layoutManager instanceof LinearLayoutManager) {
mLastSavedTarget = null; lastSavedTarget = null;
int distSnap = super.calculateDistanceToFinalSnap(layoutManager, snappedView)[0]; int distSnap = super.calculateDistanceToFinalSnap(layoutManager, snappedView)[0];
@ -55,10 +55,10 @@ public class LinearLayoutManagerSnapHelper extends LinearSnapHelper {
} }
} }
int snapPositionFirst = mOrientationHelper.getDecoratedMeasurement(((LinearLayoutManager) layoutManager).findViewByPosition(firstChild)) / 2; int snapPositionFirst = orientationHelper.getDecoratedMeasurement(((LinearLayoutManager) layoutManager).findViewByPosition(firstChild)) / 2;
int snapPositionLast = mOrientationHelper.getTotalSpace() - mOrientationHelper.getDecoratedMeasurement(((LinearLayoutManager) layoutManager).findViewByPosition(lastChild)) / 2; int snapPositionLast = orientationHelper.getTotalSpace() - orientationHelper.getDecoratedMeasurement(((LinearLayoutManager) layoutManager).findViewByPosition(lastChild)) / 2;
int centerSnapPosition = mOrientationHelper.getTotalSpace() / 2; int centerSnapPosition = orientationHelper.getTotalSpace() / 2;
if (idxSnap != -1) { if (idxSnap != -1) {
int currentSmallestDistance = Integer.MAX_VALUE; int currentSmallestDistance = Integer.MAX_VALUE;
@ -73,7 +73,7 @@ public class LinearLayoutManagerSnapHelper extends LinearSnapHelper {
currentSmallestDistance = dist; currentSmallestDistance = dist;
currentSmallestDistanceView = view; currentSmallestDistanceView = view;
} }
} else if (i > idxSnap && lastChild == (mLlm.getItemCount() - 1)) { } else if (i > idxSnap && lastChild == (this.layoutManager.getItemCount() - 1)) {
int snapPosition = snapPositionLast - (lastChild - i) * (snapPositionLast - centerSnapPosition) / (lastChild - idxSnap); int snapPosition = snapPositionLast - (lastChild - i) * (snapPositionLast - centerSnapPosition) / (lastChild - idxSnap);
int viewPosition = view.getLeft() + view.getWidth() / 2; int viewPosition = view.getLeft() + view.getWidth() / 2;
int dist = snapPosition - viewPosition; int dist = snapPosition - viewPosition;
@ -85,27 +85,27 @@ public class LinearLayoutManagerSnapHelper extends LinearSnapHelper {
} }
if (Math.abs(distSnap) > Math.abs(currentSmallestDistance)) { if (Math.abs(distSnap) > Math.abs(currentSmallestDistance)) {
snappedView = currentSmallestDistanceView; snappedView = currentSmallestDistanceView;
mLastSavedTarget = currentSmallestDistanceView; lastSavedTarget = currentSmallestDistanceView;
mLastSavedDistance = -currentSmallestDistance; lastSavedDistance = -currentSmallestDistance;
} }
} }
} }
} }
if (mListener != null) { if (listener != null) {
int snappedPosition = 0; int snappedPosition = 0;
if (snappedView != null) { if (snappedView != null) {
snappedPosition = mLlm.getPosition(snappedView); snappedPosition = this.layoutManager.getPosition(snappedView);
} }
mListener.onSnappedToView(snappedView, snappedPosition); listener.onSnappedToView(snappedView, snappedPosition);
} }
return snappedView; return snappedView;
} }
@Override @Override
public int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager layoutManager, @NonNull View targetView) { public int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager layoutManager, @NonNull View targetView) {
if (targetView == mLastSavedTarget) { if (targetView == lastSavedTarget) {
int[] out = new int[2]; int[] out = new int[2];
out[0] = mLastSavedDistance; out[0] = lastSavedDistance;
out[1] = 0; out[1] = 0;
return out; return out;
} }

View File

@ -36,11 +36,11 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
private static final int VIEWTYPE_SWAP = 1; private static final int VIEWTYPE_SWAP = 1;
private static final int VIEWTYPE_INTENT = 0; private static final int VIEWTYPE_INTENT = 0;
private RecyclerView mRecyclerView; private RecyclerView recyclerView;
private ArrayList<ResolveInfo> mTargets; private ArrayList<ResolveInfo> targets;
private int mParentWidth; private int parentWidth;
private Intent mShareIntent; private Intent shareIntent;
private boolean mShowNearby; private boolean showNearby;
public interface ShareChooserDialogListener { public interface ShareChooserDialogListener {
@ -50,25 +50,25 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
} }
private ShareChooserDialogListener mListener; private ShareChooserDialogListener listener;
private void setListener(ShareChooserDialogListener listener) { private void setListener(ShareChooserDialogListener listener) {
mListener = listener; this.listener = listener;
} }
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mParentWidth = getArguments().getInt(ARG_WIDTH, 640); parentWidth = getArguments().getInt(ARG_WIDTH, 640);
mShareIntent = getArguments().getParcelable(ARG_INTENT); shareIntent = getArguments().getParcelable(ARG_INTENT);
mShowNearby = getArguments().getBoolean(ARG_SHOW_NEARBY, false); showNearby = getArguments().getBoolean(ARG_SHOW_NEARBY, false);
mTargets = new ArrayList<>(); targets = new ArrayList<>();
List<ResolveInfo> resInfo = getContext().getPackageManager().queryIntentActivities(mShareIntent, 0); List<ResolveInfo> resInfo = getContext().getPackageManager().queryIntentActivities(shareIntent, 0);
if (resInfo != null && resInfo.size() > 0) { if (resInfo != null && resInfo.size() > 0) {
for (ResolveInfo resolveInfo : resInfo) { for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName; String packageName = resolveInfo.activityInfo.packageName;
if (!packageName.equals(BuildConfig.APPLICATION_ID)) { // Remove ourselves if (!packageName.equals(BuildConfig.APPLICATION_ID)) { // Remove ourselves
mTargets.add(resolveInfo); targets.add(resolveInfo);
} }
} }
} }
@ -83,7 +83,7 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
public void onShow(DialogInterface dialogInterface) { public void onShow(DialogInterface dialogInterface) {
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setLayout( dialog.getWindow().setLayout(
mParentWidth - Utils.dpToPx(0, getContext()), // Set margins here! parentWidth - Utils.dpToPx(0, getContext()), // Set margins here!
ViewGroup.LayoutParams.MATCH_PARENT); ViewGroup.LayoutParams.MATCH_PARENT);
} }
}); });
@ -98,19 +98,19 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
} }
private void setupView(View v) { private void setupView(View v) {
mRecyclerView = (RecyclerView) v.findViewById(R.id.recycler_view_apps); recyclerView = (RecyclerView) v.findViewById(R.id.recycler_view_apps);
// Figure out how many columns that fit in the given parent width. Give them 100dp. // Figure out how many columns that fit in the given parent width. Give them 100dp.
int appWidth = Utils.dpToPx(80, getContext()); int appWidth = Utils.dpToPx(80, getContext());
final int nCols = (mParentWidth - /* padding */ Utils.dpToPx(8, getContext())) / appWidth; final int nCols = (parentWidth - /* padding */ Utils.dpToPx(8, getContext())) / appWidth;
GridLayoutManager glm = new GridLayoutManager(getContext(), nCols); GridLayoutManager glm = new GridLayoutManager(getContext(), nCols);
// Ensure that if available, the "Nearby Swap" item spans the entire width. // Ensure that if available, the "Nearby Swap" item spans the entire width.
glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override @Override
public int getSpanSize(int position) { public int getSpanSize(int position) {
if (mRecyclerView.getAdapter() != null) { if (recyclerView.getAdapter() != null) {
if (mRecyclerView.getAdapter().getItemViewType(position) == VIEWTYPE_SWAP) { if (recyclerView.getAdapter().getItemViewType(position) == VIEWTYPE_SWAP) {
return nCols; return nCols;
} }
return 1; return 1;
@ -118,7 +118,7 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
return 0; return 0;
} }
}); });
mRecyclerView.setLayoutManager(glm); recyclerView.setLayoutManager(glm);
class VH extends RecyclerView.ViewHolder { class VH extends RecyclerView.ViewHolder {
public final ImageView icon; public final ImageView icon;
@ -131,24 +131,24 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
} }
} }
mRecyclerView.setAdapter(new RecyclerView.Adapter<VH>() { recyclerView.setAdapter(new RecyclerView.Adapter<VH>() {
private ArrayList<ResolveInfo> mIntents; private ArrayList<ResolveInfo> intents;
RecyclerView.Adapter init(List<ResolveInfo> targetedShareIntents) { RecyclerView.Adapter init(List<ResolveInfo> targetedShareIntents) {
mIntents = new ArrayList<>(); intents = new ArrayList<>();
if (mShowNearby) { if (showNearby) {
mIntents.add(null); intents.add(null);
} }
for (ResolveInfo ri : targetedShareIntents) { for (ResolveInfo ri : targetedShareIntents) {
mIntents.add(ri); intents.add(ri);
} }
return this; return this;
} }
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (mIntents.get(position) == null) { if (intents.get(position) == null) {
return VIEWTYPE_SWAP; return VIEWTYPE_SWAP;
} }
return VIEWTYPE_INTENT; return VIEWTYPE_INTENT;
@ -166,26 +166,26 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
holder.itemView.setOnClickListener(new View.OnClickListener() { holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (mListener != null) { if (listener != null) {
mListener.onNearby(); listener.onNearby();
} }
dismiss(); dismiss();
} }
}); });
return; return;
} }
final ResolveInfo ri = mIntents.get(position); final ResolveInfo ri = intents.get(position);
holder.icon.setImageDrawable(ri.loadIcon(getContext().getPackageManager())); holder.icon.setImageDrawable(ri.loadIcon(getContext().getPackageManager()));
holder.label.setText(ri.loadLabel(getContext().getPackageManager())); holder.label.setText(ri.loadLabel(getContext().getPackageManager()));
holder.itemView.setOnClickListener(new View.OnClickListener() { holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (mListener != null) { if (listener != null) {
Intent intent = new Intent(mShareIntent); Intent intent = new Intent(shareIntent);
ComponentName name = new ComponentName(ri.activityInfo.applicationInfo.packageName, ComponentName name = new ComponentName(ri.activityInfo.applicationInfo.packageName,
ri.activityInfo.name); ri.activityInfo.name);
intent.setComponent(name); intent.setComponent(name);
mListener.onResolvedShareIntent(intent); listener.onResolvedShareIntent(intent);
} }
dismiss(); dismiss();
} }
@ -194,9 +194,9 @@ public class ShareChooserDialog extends BottomSheetDialogFragment {
@Override @Override
public int getItemCount() { public int getItemCount() {
return mIntents.size(); return intents.size();
} }
}.init(mTargets)); }.init(targets));
} }

View File

@ -71,7 +71,7 @@ public class SelectAppsView extends ListView implements
private static final int LOADER_INSTALLED_APPS = 253341534; private static final int LOADER_INSTALLED_APPS = 253341534;
private AppListAdapter adapter; private AppListAdapter adapter;
private String mCurrentFilterString; private String currentFilterString;
@Override @Override
protected void onFinishInflate() { protected void onFinishInflate() {
@ -154,10 +154,10 @@ public class SelectAppsView extends ListView implements
@Override @Override
public CursorLoader onCreateLoader(int id, Bundle args) { public CursorLoader onCreateLoader(int id, Bundle args) {
Uri uri; Uri uri;
if (TextUtils.isEmpty(mCurrentFilterString)) { if (TextUtils.isEmpty(currentFilterString)) {
uri = InstalledAppProvider.getContentUri(); uri = InstalledAppProvider.getContentUri();
} else { } else {
uri = InstalledAppProvider.getSearchUri(mCurrentFilterString); uri = InstalledAppProvider.getSearchUri(currentFilterString);
} }
return new CursorLoader( return new CursorLoader(
getActivity(), getActivity(),
@ -192,13 +192,13 @@ public class SelectAppsView extends ListView implements
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
String newFilter = !TextUtils.isEmpty(newText) ? newText : null; String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
if (mCurrentFilterString == null && newFilter == null) { if (currentFilterString == null && newFilter == null) {
return true; return true;
} }
if (mCurrentFilterString != null && mCurrentFilterString.equals(newFilter)) { if (currentFilterString != null && currentFilterString.equals(newFilter)) {
return true; return true;
} }
mCurrentFilterString = newFilter; currentFilterString = newFilter;
getActivity().getSupportLoaderManager().restartLoader(LOADER_INSTALLED_APPS, null, this); getActivity().getSupportLoaderManager().restartLoader(LOADER_INSTALLED_APPS, null, this);
return true; return true;
} }

View File

@ -89,7 +89,7 @@ public class SwapAppsView extends ListView implements
private Repo repo; private Repo repo;
private AppListAdapter adapter; private AppListAdapter adapter;
private String mCurrentFilterString; private String currentFilterString;
@Override @Override
protected void onFinishInflate() { protected void onFinishInflate() {
@ -190,9 +190,9 @@ public class SwapAppsView extends ListView implements
@Override @Override
public CursorLoader onCreateLoader(int id, Bundle args) { public CursorLoader onCreateLoader(int id, Bundle args) {
Uri uri = TextUtils.isEmpty(mCurrentFilterString) Uri uri = TextUtils.isEmpty(currentFilterString)
? AppProvider.getRepoUri(repo) ? AppProvider.getRepoUri(repo)
: AppProvider.getSearchUri(repo, mCurrentFilterString); : AppProvider.getSearchUri(repo, currentFilterString);
return new CursorLoader(getActivity(), uri, AppMetadataTable.Cols.ALL, null, null, AppMetadataTable.Cols.NAME); return new CursorLoader(getActivity(), uri, AppMetadataTable.Cols.ALL, null, null, AppMetadataTable.Cols.NAME);
} }
@ -210,13 +210,13 @@ public class SwapAppsView extends ListView implements
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
String newFilter = !TextUtils.isEmpty(newText) ? newText : null; String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
if (mCurrentFilterString == null && newFilter == null) { if (currentFilterString == null && newFilter == null) {
return true; return true;
} }
if (mCurrentFilterString != null && mCurrentFilterString.equals(newFilter)) { if (currentFilterString != null && currentFilterString.equals(newFilter)) {
return true; return true;
} }
mCurrentFilterString = newFilter; currentFilterString = newFilter;
getActivity().getSupportLoaderManager().restartLoader(LOADER_SWAPABLE_APPS, null, this); getActivity().getSupportLoaderManager().restartLoader(LOADER_SWAPABLE_APPS, null, this);
return true; return true;
} }