package de.philipphager.disclosure.feature.navigation;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import de.philipphager.disclosure.database.app.model.App;
import de.philipphager.disclosure.database.library.model.Library;
import de.philipphager.disclosure.feature.app.detail.DetailActivity;
import de.philipphager.disclosure.feature.app.overview.search.SearchActivity;
import de.philipphager.disclosure.feature.home.HomeActivity;
import de.philipphager.disclosure.feature.library.detail.LibraryDetailActivity;
import de.philipphager.disclosure.feature.library.category.LibraryCategoryDetailActivity;
import de.philipphager.disclosure.feature.library.category.usecase.LibraryCategory;
import javax.inject.Inject;

public class Navigator {
  private Activity activity;

  @SuppressWarnings("PMD.UnnecessaryConstructor") @Inject public Navigator() {
    // Needed for dagger injection.
  }

  public void setActivity(Activity activity) {
    this.activity = activity;
  }

  public void toHome() {
    activity.startActivity(HomeActivity.launch(activity));
  }

  public void toSearch() {
    activity.startActivity(SearchActivity.launch(activity));
  }

  public void toAppDetail(App app) {
    activity.startActivity(DetailActivity.launch(activity, app));
  }

  public void toLibraryDetail(Library library) {
    activity.startActivity(LibraryDetailActivity.launch(activity, library));
  }

  public void toCategoryDetail(LibraryCategory libraryCategory) {
    activity.startActivity(LibraryCategoryDetailActivity.launch(activity, libraryCategory));
  }

  public void toAppSystemSettings(String packageName) {
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
        Uri.fromParts("package", packageName, null));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    activity.startActivity(intent);
  }

  public void toSystemUpdates() {
    Intent intent = new Intent("android.settings.SYSTEM_UPDATE_SETTINGS");
    activity.startActivity(intent);
  }
}

@@ -503,88 +503,8 @@
 ty;%0A
-import de.philipphager.disclosure.feature.library.detail.LibraryDetailActivity;%0A
 impo
@@ -669,24 +669,104 @@
 ryCategory;%0A
+import de.philipphager.disclosure.feature.library.detail.LibraryDetailActivity;%0A
 import javax
@@ -2052,11 +2052,446 @@
 nt);%0A  %7D
+%0A%0A  public void toGooglePlay(String packageName) %7B%0A    try %7B%0A      Uri appUri = Uri.parse(%22market://details?id=%22 + packageName);%0A      activity.startActivity(new Intent(Intent.ACTION_VIEW, appUri));%0A    %7D catch (android.content.ActivityNotFoundException anfe) %7B%0A      Uri appUri = Uri.parse(%22https://play.google.com/store/apps/details?id=%22 + packageName);%0A      activity.startActivity(new Intent(Intent.ACTION_VIEW, appUri));%0A    %7D%0A  %7D
 %0A%7D%0A

Add navigation to GooglePlay