public void onCreate(final Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    OptionsMenuUtility.fixActionBar(this, getString(R.string.app_name));

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    final boolean solidblack =
        PrefsUtility.appearance_solidblack(this, sharedPreferences)
            && PrefsUtility.appearance_theme(this, sharedPreferences)
                == PrefsUtility.AppearanceTheme.NIGHT;

    // TODO load from savedInstanceState

    final View layout = getLayoutInflater().inflate(R.layout.main_single, null);
    if (solidblack) layout.setBackgroundColor(Color.BLACK);
    setContentView(layout);
    mPane = (FrameLayout) layout.findViewById(R.id.main_single_frame);

    RedditAccountManager.getInstance(this).addUpdateListener(this);

    if (getIntent() != null) {

      final Intent intent = getIntent();

      final ArrayList<String> urls = intent.getStringArrayListExtra("urls");

      for (final String url : urls) {
        final RedditURLParser.RedditURL redditURL =
            RedditURLParser.parseProbableCommentListing(Uri.parse(url));
        if (redditURL != null) {
          mUrls.add(redditURL);
        }
      }

      doRefresh(RefreshableFragment.COMMENTS, false);

    } else {
      throw new RuntimeException("Nothing to show! (should load from bundle)"); // TODO
    }
  }
예제 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    PrefsUtility.applyTheme(this);

    if (getActionBar() != null) {
      getActionBar().setHomeButtonEnabled(true);
      getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean solidblack =
        PrefsUtility.appearance_solidblack(this, sharedPreferences)
            && PrefsUtility.appearance_theme(this, sharedPreferences)
                == PrefsUtility.AppearanceTheme.NIGHT;

    if (solidblack) getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));

    final Intent intent = getIntent();

    mUrl = intent.getDataString();

    if (mUrl == null) {
      finish();
      return;
    }

    final Matcher matchImgur = LinkHandler.imgurAlbumPattern.matcher(mUrl);
    final String albumId;

    if (matchImgur.find()) {
      albumId = matchImgur.group(2);
    } else {
      Log.e("AlbumListingActivity", "URL match failed");
      revertToWeb();
      return;
    }

    Log.i("AlbumListingActivity", "Loading URL " + mUrl + ", album id " + albumId);

    final ProgressBar progressBar =
        new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);

    final LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(progressBar);

    ImgurAPI.getAlbumInfo(
        this,
        albumId,
        Constants.Priority.IMAGE_VIEW,
        0,
        new GetAlbumInfoListener() {

          @Override
          public void onFailure(
              final RequestFailureType type,
              final Throwable t,
              final StatusLine status,
              final String readableMessage) {
            Log.e("AlbumListingActivity", "getAlbumInfo call failed: " + type);

            if (status != null) Log.e("AlbumListingActivity", "status was: " + status.toString());
            if (t != null) Log.e("AlbumListingActivity", "exception was: ", t);

            // It might be a single image, not an album

            ImgurAPI.getImageInfo(
                AlbumListingActivity.this,
                albumId,
                Constants.Priority.IMAGE_VIEW,
                0,
                new GetImageInfoListener() {
                  @Override
                  public void onFailure(
                      final RequestFailureType type,
                      final Throwable t,
                      final StatusLine status,
                      final String readableMessage) {
                    Log.e("AlbumListingActivity", "Image info request also failed: " + type);
                    revertToWeb();
                  }

                  @Override
                  public void onSuccess(final ImgurAPI.ImageInfo info) {
                    Log.i("AlbumListingActivity", "Link was actually an image.");
                    LinkHandler.onLinkClicked(AlbumListingActivity.this, info.urlOriginal);
                    finish();
                  }

                  @Override
                  public void onNotAnImage() {
                    Log.i("AlbumListingActivity", "Not an image either");
                    revertToWeb();
                  }
                });
          }

          @Override
          public void onSuccess(final ImgurAPI.AlbumInfo info) {
            Log.i("AlbumListingActivity", "Got album, " + info.images.size() + " image(s)");

            AndroidApi.UI_THREAD_HANDLER.post(
                new Runnable() {
                  @Override
                  public void run() {

                    if (info.title != null && !info.title.trim().isEmpty()) {
                      OptionsMenuUtility.fixActionBar(
                          AlbumListingActivity.this, "Imgur album: " + info.title);
                    } else {
                      OptionsMenuUtility.fixActionBar(AlbumListingActivity.this, "Imgur album");
                    }

                    layout.removeAllViews();

                    final ListView listView = new ListView(AlbumListingActivity.this);
                    listView.setAdapter(new AlbumAdapter(info));
                    layout.addView(listView);

                    listView.setOnItemClickListener(
                        new AdapterView.OnItemClickListener() {
                          @Override
                          public void onItemClick(
                              final AdapterView<?> parent,
                              final View view,
                              final int position,
                              final long id) {

                            LinkHandler.onLinkClicked(
                                AlbumListingActivity.this, info.images.get(position).urlOriginal);
                          }
                        });
                  }
                });
          }
        });

    setContentView(layout);
  }
예제 #3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);
    super.onCreate(savedInstanceState);

    final RRThemeAttributes theme = new RRThemeAttributes(this);

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    editor = sharedPreferences.edit();
    final boolean solidblack =
        PrefsUtility.appearance_solidblack(this, sharedPreferences)
            && PrefsUtility.appearance_theme(this, sharedPreferences)
                == PrefsUtility.AppearanceTheme.NIGHT;

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final String title;

    isModmail = getIntent() != null && getIntent().getBooleanExtra("modmail", false);
    onlyUnread = sharedPreferences.getBoolean("onlyUnread", false);

    if (!isModmail) {
      title = getString(R.string.mainmenu_inbox);
    } else {
      title = getString(R.string.mainmenu_modmail);
    }

    OptionsMenuUtility.fixActionBar(this, title);

    final LinearLayout outer = new LinearLayout(this);
    outer.setOrientation(android.widget.LinearLayout.VERTICAL);

    if (solidblack) {
      outer.setBackgroundColor(Color.BLACK);
    }

    loadingView = new LoadingView(this, getString(R.string.download_waiting), true, true);

    notifications = new LinearLayout(this);
    notifications.setOrientation(android.widget.LinearLayout.VERTICAL);
    notifications.addView(loadingView);

    final ListView lv = new ListView(this);

    lv.setSmoothScrollbarEnabled(false);
    lv.setVerticalFadingEdgeEnabled(false);

    lv.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            final Object item = lv.getAdapter().getItem(position);

            if (item != null && item instanceof RedditRenderableInboxItem) {
              ((RedditRenderableInboxItem) item).handleInboxClick(InboxListingActivity.this);
            }
          }
        });

    adapter = new InboxListingAdapter(this, theme);
    lv.setAdapter(adapter);

    registerForContextMenu(lv);

    outer.addView(notifications);
    outer.addView(lv);

    makeFirstRequest(this);

    setContentView(outer);
  }