Esempio n. 1
0
  public static void addFavorite(Context context, MashableNewsItem newsItem) {

    Realm realm = Realm.getInstance(context);
    realm.beginTransaction();

    Favorites favorite = realm.createObject(Favorites.class); // Create a new object
    favorite.setAuthor(newsItem.author);
    favorite.setImage(newsItem.image);
    favorite.setLink(newsItem.link);
    favorite.setTitle(newsItem.title);

    realm.commitTransaction();
  }
Esempio n. 2
0
  private void buildFavoriteGroupsMenu(Favorites favorites, Menu menu, Set<Integer> groupIds) {

    if (groupIds.isEmpty()) {
      menu.setItems();
      return;
    }

    List<MenuItem> items = new ArrayList<MenuItem>(groupIds.size());

    for (final Integer groupId : groupIds) {
      ResourceGroupComposite groupComposite = favorites.getGroupComposite(groupId);
      if (null == groupComposite) {
        // if the resource group is gone just skip it
        continue;
      }
      final ResourceGroup group = groupComposite.getResourceGroup();

      MenuItem item = new MenuItem(String.valueOf(groupId));
      item.setTitle(group.getName());
      item.setIcon(
          ImageManager.getGroupIcon(
              group.getGroupCategory(), groupComposite.getExplicitAvailabilityType()));

      item.addClickHandler(
          new com.smartgwt.client.widgets.menu.events.ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
              CoreGUI.goToView(LinkManager.getResourceGroupLink(group));
            }
          });
      items.add(item);
    }
    menu.setItems(items.toArray(new MenuItem[items.size()]));
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.pager_layout, container, false);
    // Get Favorites &&
    mFav = Favorites.getFavoriteList(this.getActivity());
    // mSharedPreferences = getActivity().getPreferences(Activity.MODE_PRIVATE);
    setHasOptionsMenu(true);
    if (MainActivity.sProgress != null) {
      MainActivity.sProgress.dismiss();
      MainActivity.sProgress = null;
    }
    mActionBar = ((MainActivity) getActivity()).getSupportActionBar();
    assert mActionBar != null;

    // Setup ViewPager, alt TextView
    mPagerAdapter = new FavoritesPagerAdapter(getActivity());
    mPager = (HackyViewPager) v.findViewById(R.id.pager);
    setupPager(mPager);
    if (savedInstanceState != null) {
      sFavoriteIndex = savedInstanceState.getInt(LAST_FAV);
      getActivity().invalidateOptionsMenu();
    }
    // Update the pager
    if (mFav != null) {
      new pagerUpdate().execute();
    }
    return v;
  }
 @Override
 protected Void doInBackground(Integer... pos) {
   if (!MainActivity.fullOffline) {
     getActivity().deleteFile(String.valueOf(pos[0]));
   }
   Favorites.removeFavoriteItem(getActivity(), String.valueOf(pos[0]));
   return null;
 }
 @Override
 protected void onPostExecute(Void v) {
   String[] fav = Favorites.getFavoriteList(getActivity());
   if (fav.length == 0) {
     // If there are no favorites left, show ComicBrowserFragment
     MenuItem mBrowser =
         ((MainActivity) getActivity()).mNavView.getMenu().findItem(R.id.nav_browser);
     ((MainActivity) getActivity()).selectDrawerItem(mBrowser);
     return;
   }
   refresh();
 }
 public void refresh() {
   // Updates favorite list, pager and alt TextView
   mFav = Favorites.getFavoriteList(this.getActivity());
   mComicMap.clear();
   if (mFav.length != 0) {
     if (sFavoriteIndex == mFav.length) {
       sFavoriteIndex--;
     }
     new pagerUpdate().execute();
   }
   // tvAlt.setText(mSharedPreferences.getString(("title" +
   // String.valueOf(sFavorites[sFavoriteIndex])), ""));
 }
Esempio n. 7
0
  private void buildFavoriteResourcesMenu(
      Favorites favorites,
      Menu menu,
      Set<Integer> resourceIds,
      AncestryUtil.MapWrapper typesWrapper) {

    if (resourceIds.isEmpty()) {
      menu.setItems();
      return;
    }

    List<MenuItem> items = new ArrayList<MenuItem>(resourceIds.size());

    for (final Integer resourceId : resourceIds) {
      Resource resource = favorites.getResource(resourceId);
      if (null == resource) {
        // if the resource is gone just skip it
        continue;
      }

      MenuItem item = new MenuItem(resource.getName());
      item.setIcon(ImageManager.getResourceIcon(resource));

      // build a subMenu to display a disambiguated resource
      item.setAttribute(AncestryUtil.RESOURCE_ID, resourceId);
      item.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry());
      item.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper);
      Menu ancestryMenu = new Menu();
      MenuItem ancestryItem = new MenuItem(AncestryUtil.getAncestryHoverHTML(item, -1));
      ancestryItem.setEnabled(false);
      ancestryMenu.setItems(ancestryItem);
      ancestryMenu.setSubmenuDirection("left");
      ancestryMenu.setAutoWidth();
      item.setSubmenu(ancestryMenu);

      item.addClickHandler(
          new com.smartgwt.client.widgets.menu.events.ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
              CoreGUI.goToView(LinkManager.getResourceLink(resourceId));
            }
          });

      items.add(item);
    }

    menu.setCanSelectParentItems(Boolean.TRUE);
    menu.setItems(items.toArray(new MenuItem[items.size()]));
  }
Esempio n. 8
0
  private void buildRecentlyViewedMenu(
      Favorites favorites,
      Menu menu,
      List<Integer> recentResourceIds,
      List<Integer> recentGroupIds,
      AncestryUtil.MapWrapper typesWrapper) {

    if (recentResourceIds.isEmpty() && recentGroupIds.isEmpty()) {
      return;
    }
    List<MenuItem> items =
        new ArrayList<MenuItem>(recentResourceIds.size() + recentGroupIds.size() + 1);

    for (final Integer resourceId : recentResourceIds) {
      Resource resource = favorites.getResource(resourceId);
      if (null == resource) {
        // if the resource is gone just skip it
        continue;
      }

      MenuItem item = new MenuItem(resource.getName());
      item.setIcon(ImageManager.getResourceIcon(resource));

      // build a subMenu to display a disambiguated resource
      item.setAttribute(AncestryUtil.RESOURCE_ID, resourceId);
      item.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry());
      item.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper);

      Menu ancestryMenu = new Menu();
      MenuItem ancestryItem = new MenuItem(AncestryUtil.getAncestryHoverHTML(item, -1));
      ancestryItem.setEnabled(false);
      ancestryMenu.setItems(ancestryItem);
      ancestryMenu.setSubmenuDirection("left");
      ancestryMenu.setAutoWidth();
      item.setSubmenu(ancestryMenu);

      item.addClickHandler(
          new com.smartgwt.client.widgets.menu.events.ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
              CoreGUI.goToView(LinkManager.getResourceLink(resourceId));
            }
          });

      items.add(item);
    }

    if (!recentResourceIds.isEmpty() && !recentGroupIds.isEmpty()) {
      items.add(new MenuItemSeparator());
    }

    for (final Integer groupId : recentGroupIds) {
      ResourceGroupComposite groupComposite = favorites.getGroupComposite(groupId);
      if (null == groupComposite) {
        // if the resource group is gone just skip it
        continue;
      }
      final ResourceGroup group = groupComposite.getResourceGroup();

      MenuItem item = new MenuItem(String.valueOf(groupId));
      item.setTitle(group.getName());
      item.setIcon(
          ImageManager.getGroupIcon(
              group.getGroupCategory(), groupComposite.getExplicitAvailabilityType()));

      item.addClickHandler(
          new com.smartgwt.client.widgets.menu.events.ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
              CoreGUI.goToView(LinkManager.getResourceGroupLink(group));
            }
          });
      items.add(item);
    }

    menu.setCanSelectParentItems(Boolean.TRUE);
    menu.setItems(items.toArray(new MenuItem[items.size()]));
  }
Esempio n. 9
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
      ComicBrowserFragment.sLastComicNumber = (getNumberFromUrl(getIntent().getDataString()));
    }
    // On Lollipop, change the app's icon in the recents app screen
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
        && !getIntent().getAction().equals(Intent.ACTION_VIEW)) {
      TypedValue typedValue = new TypedValue();
      Resources.Theme theme = getTheme();
      theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
      int color = typedValue.data;

      Bitmap ic = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_easy_xkcd_recents);
      ActivityManager.TaskDescription description =
          new ActivityManager.TaskDescription("Easy xkcd", ic, color);
      setTaskDescription(description);

      if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("prev_navbar", false)) {
        // getWindow().setNavigationBarColor(getResources().getColor(R.color.ColorPrimary));
        Log.d("color set", "color set");
      }
    }
    // Setup Toolbar, NavDrawer, FAB
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    sDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    sDrawer.setDrawerListener(mDrawerToggle);
    mDrawerToggle = setupDrawerToggle();
    sNavView = (NavigationView) findViewById(R.id.nvView);
    setupDrawerContent(sNavView);

    mFab = (FloatingActionButton) findViewById(R.id.fab);
    setupFab(mFab);

    // Load fragment
    if (isOnline()) {
      MenuItem item;
      if (savedInstanceState != null) {
        // Get last loaded fragment
        sCurrentFragment = savedInstanceState.getInt("CurrentFragment");
        item = sNavView.getMenu().findItem(sCurrentFragment);
      } else {
        // Load ComicBrowserFragment by default
        sProgress =
            ProgressDialog.show(
                this, "", this.getResources().getString(R.string.loading_comics), true);
        item = sNavView.getMenu().findItem(R.id.nav_browser);
      }
      selectDrawerItem(item);
    } else if (sCurrentFragment
        != R.id
            .nav_favorites) { // Don't show the dialog if the user is currently browsing his
                              // favorites
      Log.d("test", "test");
      android.support.v7.app.AlertDialog.Builder mDialog =
          new android.support.v7.app.AlertDialog.Builder(this);
      mDialog
          .setMessage(R.string.no_connection)
          .setPositiveButton(
              R.string.no_connection_retry,
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                  finish();
                  startActivity(getIntent());
                }
              })
          .setCancelable(false);
      if (Favorites.getFavoriteList(this).length != 0) {
        mDialog.setNegativeButton(
            R.string.no_connection_favorites,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {

                MenuItem m = sNavView.getMenu().findItem(R.id.nav_favorites);
                selectDrawerItem(m);
              }
            });
      }
      mDialog.show();
    }
  }
Esempio n. 10
0
  public void selectDrawerItem(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
      case R.id.nav_browser:
        // Check if the device is online
        if (!isOnline()) {
          Toast toast = Toast.makeText(this, R.string.no_connection, Toast.LENGTH_SHORT);
          toast.show();
          MenuItem m = sNavView.getMenu().findItem(R.id.nav_favorites);
          m.setChecked(true);
          sDrawer.closeDrawers();
          return;
        }
        // showComicBrowserFragment
        showFragment("pref_random_comics", menuItem.getItemId(), "Comics", "browser", "favorites");
        break;
      case R.id.nav_favorites:
        // Check if there are any Favorites
        if (Favorites.getFavoriteList(this).length == 0) {
          Toast toast = Toast.makeText(this, R.string.no_favorites, Toast.LENGTH_SHORT);
          toast.show();
          MenuItem m = sNavView.getMenu().findItem(R.id.nav_browser);
          m.setChecked(true);
          sDrawer.closeDrawers();
          return;
        }
        // showFavoritesFragment
        showFragment(
            "pref_random_favorites",
            menuItem.getItemId(),
            getResources().getString(R.string.nv_favorites),
            "favorites",
            "browser");
        break;

      case R.id.nav_settings:
        sDrawer.closeDrawer(sNavView);
        // Add delay so that the Drawer is closed before the Settings Activity is launched
        new Handler()
            .postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    Intent i = new Intent(MainActivity.this, SettingsActivity.class);
                    startActivity(i);
                  }
                },
                200);
        return;

      case R.id.nav_feedback:
        sDrawer.closeDrawer(sNavView);
        new Handler()
            .postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    Intent i =
                        new Intent(
                            Intent.ACTION_SENDTO,
                            Uri.fromParts("mailto", "*****@*****.**", null));
                    startActivity(
                        Intent.createChooser(
                            i, getResources().getString(R.string.nav_feedback_send)));
                  }
                },
                200);
        return;

      case R.id.nav_about:
        sDrawer.closeDrawer(sNavView);
        new Handler()
            .postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    Intent i = new Intent(MainActivity.this, AboutActivity.class);
                    startActivity(i);
                  }
                },
                250);
        return;
    }
    menuItem.setChecked(true);
    sDrawer.closeDrawers();
    sCurrentFragment = menuItem.getItemId();
    invalidateOptionsMenu();
  }
Esempio n. 11
0
 public void removeFavorite(EarthWallpaper earthWallpaper) {
   Favorites.getFavorites(context).removeFavorite(earthWallpaper);
 }
Esempio n. 12
0
 public boolean isFavorite(EarthWallpaper earthWallpaper) {
   return Favorites.getFavorites(context).isFavorite(earthWallpaper);
 }
Esempio n. 13
0
 public void addFavorite(EarthWallpaper earthWallpaper) {
   Favorites.getFavorites(context).addFavorite(earthWallpaper);
 }