Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Here is another version with guard clauses:

private void setupListener(final ImageView image, final String platform, 
 final String urlLink) {
 image.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 if (!platform.equalsIgnoreCase(PLATFORM_ANDROID)) {
 startInBroswer();
 return;
 }
 final String packageName = extractPackageName(urlLink);
 if (packageName == null) {
 startInBroswer();
 return;
 }
 try {
 final Intent market = new Intent(Intent.ACTION_VIEW);
 market.setData(Uri.parse("market://details?id=" + packageName));
 activity.startActivity(market);
 } catch (final Exception e) {
 // TODO: log the exception
 startInBroswer();
 }
 }
 private void startInBroswer() {
 final Intent browser = new Intent(Intent.ACTION_VIEW, 
 Uri.parse(urlLink));
 activity.startActivity(browser);
 }
 });
}

Two things to notice:

  1. I've removed the urlLink parameter of the startInBroswer method.

  2. It is a bad idea to use printStackTrace() in Android exceptions bad idea to use printStackTrace() in Android exceptions.

Here is another version with guard clauses:

private void setupListener(final ImageView image, final String platform, 
 final String urlLink) {
 image.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 if (!platform.equalsIgnoreCase(PLATFORM_ANDROID)) {
 startInBroswer();
 return;
 }
 final String packageName = extractPackageName(urlLink);
 if (packageName == null) {
 startInBroswer();
 return;
 }
 try {
 final Intent market = new Intent(Intent.ACTION_VIEW);
 market.setData(Uri.parse("market://details?id=" + packageName));
 activity.startActivity(market);
 } catch (final Exception e) {
 // TODO: log the exception
 startInBroswer();
 }
 }
 private void startInBroswer() {
 final Intent browser = new Intent(Intent.ACTION_VIEW, 
 Uri.parse(urlLink));
 activity.startActivity(browser);
 }
 });
}

Two things to notice:

  1. I've removed the urlLink parameter of the startInBroswer method.

  2. It is a bad idea to use printStackTrace() in Android exceptions.

Here is another version with guard clauses:

private void setupListener(final ImageView image, final String platform, 
 final String urlLink) {
 image.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 if (!platform.equalsIgnoreCase(PLATFORM_ANDROID)) {
 startInBroswer();
 return;
 }
 final String packageName = extractPackageName(urlLink);
 if (packageName == null) {
 startInBroswer();
 return;
 }
 try {
 final Intent market = new Intent(Intent.ACTION_VIEW);
 market.setData(Uri.parse("market://details?id=" + packageName));
 activity.startActivity(market);
 } catch (final Exception e) {
 // TODO: log the exception
 startInBroswer();
 }
 }
 private void startInBroswer() {
 final Intent browser = new Intent(Intent.ACTION_VIEW, 
 Uri.parse(urlLink));
 activity.startActivity(browser);
 }
 });
}

Two things to notice:

  1. I've removed the urlLink parameter of the startInBroswer method.

  2. It is a bad idea to use printStackTrace() in Android exceptions.

Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157

Here is another version with guard clauses:

private void setupListener(final ImageView image, final String platform, 
 final String urlLink) {
 image.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 if (!platform.equalsIgnoreCase(PLATFORM_ANDROID)) {
 startInBroswer();
 return;
 }
 final String packageName = extractPackageName(urlLink);
 if (packageName == null) {
 startInBroswer();
 return;
 }
 try {
 final Intent market = new Intent(Intent.ACTION_VIEW);
 market.setData(Uri.parse("market://details?id=" + packageName));
 activity.startActivity(market);
 } catch (final Exception e) {
 // TODO: log the exception
 startInBroswer();
 }
 }
 private void startInBroswer() {
 final Intent browser = new Intent(Intent.ACTION_VIEW, 
 Uri.parse(urlLink));
 activity.startActivity(browser);
 }
 });
}

Two things to notice:

  1. I've removed the urlLink parameter of the startInBroswer method.

  2. It is a bad idea to use printStackTrace() in Android exceptions.

lang-java

AltStyle によって変換されたページ (->オリジナル) /