Ejemplo n.º 1
0
 public static boolean shouldLoadThumbnails(Activity activity, RedditSettings settings) {
   // check for wifi connection and wifi thumbnail setting
   boolean thumbOkay = true;
   if (settings.isLoadThumbnailsOnlyWifi()) {
     thumbOkay = false;
     ConnectivityManager connMan =
         (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
     NetworkInfo netInfo = connMan.getActiveNetworkInfo();
     if (netInfo != null
         && netInfo.getType() == ConnectivityManager.TYPE_WIFI
         && netInfo.isConnected()) {
       thumbOkay = true;
     }
   }
   return settings.isLoadThumbnails() && thumbOkay;
 }
  void resetUI(PickSubredditAdapter adapter) {
    setTheme(mSettings.getTheme());
    setContentView(R.layout.pick_subreddit_view);
    registerForContextMenu(getListView());

    synchronized (ADAPTER_LOCK) {
      if (adapter == null) {
        // Reset the list to be empty.
        mSubredditsList = new ArrayList<String>();
        mSubredditsAdapter = new PickSubredditAdapter(this, mSubredditsList);
      } else {
        mSubredditsAdapter = adapter;
      }
      setListAdapter(mSubredditsAdapter);
      mSubredditsAdapter.mLoading = false;
      mSubredditsAdapter.notifyDataSetChanged(); // Just in case
    }
    Common.updateListDrawables(this, mSettings.getTheme());

    // Set the EditText to do same thing as onListItemClick
    mEt = (EditText) findViewById(R.id.pick_subreddit_input);
    if (mEt != null) {
      mEt.setOnKeyListener(
          new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
              if ((event.getAction() == KeyEvent.ACTION_DOWN)
                  && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                returnSubreddit(mEt.getText().toString().trim());
                return true;
              }
              return false;
            }
          });
      mEt.setFocusableInTouchMode(true);
    }
    Button goButton = (Button) findViewById(R.id.pick_subreddit_button);
    if (goButton != null) {
      goButton.setOnClickListener(
          new OnClickListener() {
            public void onClick(View v) {
              returnSubreddit(mEt.getText().toString().trim());
            }
          });
    }

    getListView().requestFocus();
  }
 private void enableLoadingScreen() {
   if (Util.isLightTheme(mSettings.getTheme())) {
     setContentView(R.layout.loading_light);
   } else {
     setContentView(R.layout.loading_dark);
   }
   synchronized (ADAPTER_LOCK) {
     if (mSubredditsAdapter != null) mSubredditsAdapter.mLoading = true;
   }
   getWindow().setFeatureInt(Window.FEATURE_PROGRESS, 0);
 }
Ejemplo n.º 4
0
  static void clearCookies(RedditSettings settings, HttpClient client, Context context) {
    settings.setRedditSessionCookie(null);

    RedditIsFunHttpClientFactory.getCookieStore().clear();
    CookieSyncManager.getInstance().sync();

    SharedPreferences sessionPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sessionPrefs.edit();
    editor.remove("reddit_sessionValue");
    editor.remove("reddit_sessionDomain");
    editor.remove("reddit_sessionPath");
    editor.remove("reddit_sessionExpiryDate");
    editor.commit();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    CookieSyncManager.createInstance(getApplicationContext());

    mSettings.loadRedditPreferences(this, mClient);
    setRequestedOrientation(mSettings.getRotation());
    requestWindowFeature(Window.FEATURE_PROGRESS);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    resetUI(null);

    mSubredditsList = cacheSubredditsList(mSubredditsList);

    if (CollectionUtils.isEmpty(mSubredditsList)) restoreLastNonConfigurationInstance();

    if (CollectionUtils.isEmpty(mSubredditsList)) {
      new DownloadRedditsTask().execute();
    } else {
      addFakeSubredditsUnlessSuppressed();
      resetUI(new PickSubredditAdapter(this, mSubredditsList));
    }
  }
 @Override
 public void onCreate() {
   mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
   mSettings.loadRedditPreferences(this, mClient);
   new PeekEnvelopeServiceTask(this, mClient, mSettings.getMailNotificationStyle()).execute();
 }
Ejemplo n.º 7
0
 public static void doLogout(RedditSettings settings, HttpClient client, Context context) {
   clearCookies(settings, client, context);
   CacheInfo.invalidateAllCaches(context);
   settings.setUsername(null);
 }
Ejemplo n.º 8
0
  public static void updateNextPreviousButtons(
      ListActivity act,
      View nextPreviousView,
      String after,
      String before,
      int count,
      RedditSettings settings,
      OnClickListener downloadAfterOnClickListener,
      OnClickListener downloadBeforeOnClickListener) {
    boolean shouldShow = after != null || before != null;
    Button nextButton = null;
    Button previousButton = null;

    // If alwaysShowNextPrevious, use the navbar
    if (settings.isAlwaysShowNextPrevious()) {
      nextPreviousView = act.findViewById(R.id.next_previous_layout);
      if (nextPreviousView == null) return;
      View nextPreviousBorder = act.findViewById(R.id.next_previous_border_top);

      if (shouldShow) {
        if (nextPreviousView != null && nextPreviousBorder != null) {
          if (Util.isLightTheme(settings.getTheme())) {
            nextPreviousView.setBackgroundResource(android.R.color.background_light);
            nextPreviousBorder.setBackgroundResource(R.color.black);
          } else {
            nextPreviousBorder.setBackgroundResource(R.color.white);
          }
          nextPreviousView.setVisibility(View.VISIBLE);
        }
        // update the "next 25" and "prev 25" buttons
        nextButton = (Button) act.findViewById(R.id.next_button);
        previousButton = (Button) act.findViewById(R.id.previous_button);
      } else {
        nextPreviousView.setVisibility(View.GONE);
      }
    }
    // Otherwise we are using the ListView footer
    else {
      if (nextPreviousView == null) return;
      if (shouldShow && nextPreviousView.getVisibility() != View.VISIBLE) {
        nextPreviousView.setVisibility(View.VISIBLE);
      } else if (!shouldShow && nextPreviousView.getVisibility() == View.VISIBLE) {
        nextPreviousView.setVisibility(View.GONE);
      }
      // update the "next 25" and "prev 25" buttons
      nextButton = (Button) nextPreviousView.findViewById(R.id.next_button);
      previousButton = (Button) nextPreviousView.findViewById(R.id.previous_button);
    }
    if (nextButton != null) {
      if (after != null) {
        nextButton.setVisibility(View.VISIBLE);
        nextButton.setOnClickListener(downloadAfterOnClickListener);
      } else {
        nextButton.setVisibility(View.INVISIBLE);
      }
    }
    if (previousButton != null) {
      if (before != null && count != Constants.DEFAULT_THREAD_DOWNLOAD_LIMIT) {
        previousButton.setVisibility(View.VISIBLE);
        previousButton.setOnClickListener(downloadBeforeOnClickListener);
      } else {
        previousButton.setVisibility(View.INVISIBLE);
      }
    }
  }