Пример #1
0
  @Override
  public void onRefreshStarted(View view) {
    if (Utils.isOnline(getActivity())) {
      new Builder<String, ActivityFeed>(String.class, ActivityFeed.class)
          .addParameter(getArguments().getString("plus_id"))
          .setOnPreExecuteListener(
              new CommonAsyncTask.OnPreExecuteListener() {
                @Override
                public void onPreExecute() {
                  setIsLoading(true);
                }
              })
          .setOnBackgroundExecuteListener(
              new CommonAsyncTask.OnBackgroundExecuteListener<String, ActivityFeed>() {
                @Override
                public ActivityFeed doInBackground(String... params) {
                  try {

                    Plus.Activities.List request = mClient.activities().list(params[0], "public");
                    request.setMaxResults(10L);
                    request.setFields(
                        "nextPageToken,items(id,published,url,object/content,verb,object/attachments,annotation,object(plusoners,replies,resharers))");
                    ActivityFeed feed = request.execute();

                    App.getInstance()
                        .getModelCache()
                        .put("news_" + params[0], feed, DateTime.now().plusHours(1));

                    return feed;
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                  return null;
                }
              })
          .setOnPostExecuteListener(
              new CommonAsyncTask.OnPostExecuteListener<ActivityFeed>() {
                @Override
                public void onPostExecute(ActivityFeed activityFeed) {
                  if (activityFeed != null) {
                    mAdapter.replaceAll(activityFeed.getItems(), 0);
                    setIsLoading(false);

                    if (getActivity() != null)
                      ((GdgActivity) getActivity()).getPullToRefreshHelper().setRefreshComplete();
                  }
                }
              })
          .buildAndExecute();
    }
  }
Пример #2
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(
        view,
        savedInstanceState); // To change body of overridden methods use File | Settings | File
    // Templates.

    InputStream is = null;
    try {
      is = getResources().getAssets().open("changelog.html");
      mChangelog.setText(Html.fromHtml(Utils.inputStreamToString(is)));
    } catch (IOException e) {
      e.printStackTrace(); // To change body of catch statement use File | Settings | File
      // Templates.
    }
  }
Пример #3
0
  /**
   * Called when the activity is first created.
   *
   * @param savedInstanceState If the activity is being re-initialized after previously being shut
   *     down then this Bundle contains the data it most recently supplied in
   *     onSaveInstanceState(Bundle). <b>Note: Otherwise it is null.</b>
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Timber.i("onCreate");
    setContentView(R.layout.activity_main);

    mClient = new GroupDirectory();

    mLocationComparator = new ChapterComparator(mPreferences);

    mIndicator.setOnPageChangeListener(this);

    mViewPagerAdapter = new MyAdapter(this, getSupportFragmentManager());
    mSpinnerAdapter = new ChapterAdapter(MainActivity.this, android.R.layout.simple_list_item_1);
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    getSupportActionBar().setListNavigationCallbacks(mSpinnerAdapter, MainActivity.this);

    mFetchChaptersTask =
        mClient.getDirectory(
            new Response.Listener<Directory>() {
              @Override
              public void onResponse(final Directory directory) {
                getSupportActionBar()
                    .setListNavigationCallbacks(mSpinnerAdapter, MainActivity.this);
                App.getInstance()
                    .getModelCache()
                    .putAsync(
                        "chapter_list",
                        directory,
                        DateTime.now().plusDays(1),
                        new ModelCache.CachePutListener() {
                          @Override
                          public void onPutIntoCache() {
                            ArrayList<Chapter> chapters = directory.getGroups();

                            initChapters(chapters);
                          }
                        });
              }
            },
            new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError volleyError) {
                Crouton.makeText(
                        MainActivity.this, getString(R.string.fetch_chapters_failed), Style.ALERT)
                    .show();
                Timber.e("Could'nt fetch chapter list", volleyError);
              }
            });

    if (savedInstanceState == null) {

      if (Utils.isOnline(this)) {
        App.getInstance()
            .getModelCache()
            .getAsync(
                "chapter_list",
                new ModelCache.CacheListener() {
                  @Override
                  public void onGet(Object item) {
                    Directory directory = (Directory) item;
                    initChapters(directory.getGroups());
                  }

                  @Override
                  public void onNotFound(String key) {
                    mFetchChaptersTask.execute();
                  }
                });
      } else {

        App.getInstance()
            .getModelCache()
            .getAsync(
                "chapter_list",
                false,
                new ModelCache.CacheListener() {
                  @Override
                  public void onGet(Object item) {
                    Directory directory = (Directory) item;
                    initChapters(directory.getGroups());
                  }

                  @Override
                  public void onNotFound(String key) {
                    Crouton.makeText(
                            MainActivity.this, getString(R.string.offline_alert), Style.ALERT)
                        .show();
                  }
                });
      }
    } else {

      if (savedInstanceState.containsKey("chapters")) {
        ArrayList<Chapter> chapters = savedInstanceState.getParcelableArrayList("chapters");
        mSpinnerAdapter.clear();
        mSpinnerAdapter.addAll(chapters);

        if (savedInstanceState.containsKey("selected_chapter")) {
          Chapter selectedChapter = savedInstanceState.getParcelable("selected_chapter");
          selectChapter(selectedChapter);
        } else {
          mViewPagerAdapter.setSelectedChapter(chapters.get(0));
        }

        mViewPager.setAdapter(mViewPagerAdapter);
        mIndicator.setViewPager(mViewPager);
      } else {
        mFetchChaptersTask.execute();
      }
    }

    Intent intent = getIntent();
    if (intent != null
        && intent.getAction() != null
        && intent.getAction().equals("finish_first_start")) {
      Timber.d("Completed FirstStartWizard");

      if (mPreferences.getBoolean(Const.SETTINGS_SIGNED_IN, false)) {
        mFirstStart = true;
      }

      Chapter homeGdgd = getIntent().getParcelableExtra("selected_chapter");
      getSupportActionBar().setSelectedNavigationItem(mSpinnerAdapter.getPosition(homeGdgd));
      mViewPagerAdapter.setSelectedChapter(homeGdgd);
    }

    Time now = new Time();
    now.setToNow();
    if ((mPreferences.getInt(Const.SETTINGS_SEASONS_GREETINGS, now.year - 1) < now.year)
        && (now.yearDay >= 354 && now.yearDay <= 366)) {
      mPreferences.edit().putInt(Const.SETTINGS_SEASONS_GREETINGS, now.year).commit();
      SeasonsGreetingsFragment seasonsGreetings = new SeasonsGreetingsFragment();
      seasonsGreetings.show(getSupportFragmentManager(), "dialog");
    }
  }
Пример #4
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Log.d(LOG_TAG, "onActivityCreated()");

    mClient =
        new Plus.Builder(mTransport, mJsonFactory, null)
            .setGoogleClientRequestInitializer(
                new CommonGoogleJsonClientRequestInitializer(
                    getString(R.string.ip_simple_api_access_key)))
            .build();

    PlusClient plusClient = null;
    if (((GdgActivity) getActivity()).getPlayServicesHelper() != null) {
      plusClient = ((GdgActivity) getActivity()).getPlayServicesHelper().getPlusClient();
    }
    mAdapter = new NewsAdapter(getActivity(), plusClient);
    setListAdapter(mAdapter);

    registerForContextMenu(getListView());

    ((GdgActivity) getActivity())
        .getPullToRefreshHelper()
        .addRefreshableView(
            getListView(),
            new PullToRefreshAttacher.ViewDelegate() {
              @Override
              public boolean isScrolledToTop(View view) {
                AbsListView absListView = (AbsListView) view;
                if (absListView.getCount() == 0) {
                  return true;
                } else if (absListView.getFirstVisiblePosition() == 0) {
                  final View firstVisibleChild = absListView.getChildAt(0);
                  return firstVisibleChild != null && firstVisibleChild.getTop() >= 0;
                }
                return false;
              }
            },
            this);

    if (getListView() instanceof ListView) {
      ListView listView = (ListView) getListView();
      listView.setDivider(null);
      listView.setDividerHeight(0);
    }

    if (Utils.isOnline(getActivity())) {
      new Builder<String, ActivityFeed>(String.class, ActivityFeed.class)
          .addParameter(getArguments().getString("plus_id"))
          .setOnPreExecuteListener(
              new CommonAsyncTask.OnPreExecuteListener() {
                @Override
                public void onPreExecute() {
                  setIsLoading(true);
                }
              })
          .setOnBackgroundExecuteListener(
              new CommonAsyncTask.OnBackgroundExecuteListener<String, ActivityFeed>() {
                @Override
                public ActivityFeed doInBackground(String... params) {
                  try {

                    ActivityFeed feed =
                        (ActivityFeed) App.getInstance().getModelCache().get("news_" + params[0]);

                    if (feed == null) {
                      Plus.Activities.List request = mClient.activities().list(params[0], "public");
                      request.setMaxResults(10L);
                      request.setFields(
                          "nextPageToken,items(id,published,url,object/content,verb,object/attachments,object/actor,annotation,object(plusoners,replies,resharers))");
                      feed = request.execute();

                      App.getInstance()
                          .getModelCache()
                          .put("news_" + params[0], feed, DateTime.now().plusHours(1));
                    }

                    return feed;
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                  return null;
                }
              })
          .setOnPostExecuteListener(
              new CommonAsyncTask.OnPostExecuteListener<ActivityFeed>() {
                @Override
                public void onPostExecute(ActivityFeed activityFeed) {
                  if (activityFeed != null) {
                    mAdapter.addAll(activityFeed.getItems());
                    setIsLoading(false);
                  }
                }
              })
          .buildAndExecute();
    } else {
      App.getInstance()
          .getModelCache()
          .getAsync(
              "news_" + getArguments().getString("plus_id"),
              false,
              new ModelCache.CacheListener() {
                @Override
                public void onGet(Object item) {
                  ActivityFeed feed = (ActivityFeed) item;

                  if (isAdded())
                    Crouton.makeText(getActivity(), getString(R.string.cached_content), Style.INFO)
                        .show();

                  mAdapter.addAll(feed.getItems());
                  setIsLoading(false);
                }

                @Override
                public void onNotFound(String key) {
                  if (isAdded())
                    Crouton.makeText(getActivity(), getString(R.string.offline_alert), Style.ALERT)
                        .show();
                }
              });
    }
  }