Esempio n. 1
0
  @Override
  public void onClickFullText() {
    final BaseActivity activity = (BaseActivity) getActivity();

    if (activity.getProgressBar().getVisibility() != View.VISIBLE) {
      Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
      final boolean alreadyMobilized = !cursor.isNull(mMobilizedHtmlPos);

      if (alreadyMobilized) {
        activity.runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                mPreferFullText = true;
                mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true);
              }
            });
      } else {
        ConnectivityManager connectivityManager =
            (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
        final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

        // since we have acquired the networkInfo, we use it for basic checks
        if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED) {
          FetcherService.addEntriesToMobilize(new long[] {mEntriesIds[mCurrentPagerPos]});
          activity.startService(
              new Intent(activity, FetcherService.class)
                  .setAction(FetcherService.ACTION_MOBILIZE_FEEDS));
          activity.runOnUiThread(
              new Runnable() {
                @Override
                public void run() {
                  activity.getProgressBar().setVisibility(View.VISIBLE);
                }
              });
        } else {
          activity.runOnUiThread(
              new Runnable() {
                @Override
                public void run() {
                  Toast.makeText(activity, R.string.network_error, Toast.LENGTH_LONG).show();
                }
              });
        }
      }
    }
  }
Esempio n. 2
0
  private void refreshUI(Cursor entryCursor) {
    if (entryCursor != null) {
      String feedTitle =
          entryCursor.isNull(mFeedNamePos)
              ? entryCursor.getString(mFeedUrlPos)
              : entryCursor.getString(mFeedNamePos);
      BaseActivity activity = (BaseActivity) getActivity();
      activity.setTitle(feedTitle);

      byte[] iconBytes = entryCursor.getBlob(mFeedIconPos);
      Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24);
      if (bitmap != null) {
        activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap));
      } else {
        activity.getActionBar().setIcon(R.drawable.icon);
      }

      mFavorite = entryCursor.getInt(mIsFavoritePos) == 1;
      activity.invalidateOptionsMenu();

      // Listen the mobilizing task
      boolean isRefreshing = FetcherService.hasTasks(mEntriesIds[mCurrentPagerPos]);
      activity.getProgressBar().setVisibility(isRefreshing ? View.VISIBLE : View.GONE);

      // Mark the article as read
      if (entryCursor.getInt(mIsReadPos) != 1) {
        final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
        new Thread(
                new Runnable() {
                  @Override
                  public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getReadContentValues(), null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                  }
                })
            .start();
      }
    }
  }