Exemplo n.º 1
0
    @Override
    public void run() {
      if (!SettingUtility.getEnableAutoRefresh()) {
        return;
      }

      if (!Utility.isTaskStopped(dbTask)) {
        return;
      }

      if (!allowRefresh()) {
        return;
      }

      if (!Utility.isWifi(getActivity())) {
        return;
      }

      if (isListViewFling()
          || !isVisible()
          || ((MainTimeLineActivity) getActivity()).getSlidingMenu().isMenuShowing()) {
        return;
      }

      Bundle bundle = new Bundle();
      bundle.putBoolean(BundleArgsConstants.SCROLL_TO_TOP, false);
      bundle.putBoolean(BundleArgsConstants.AUTO_REFRESH, true);
      getLoaderManager().restartLoader(NEW_MSG_LOADER_ID, bundle, msgAsyncTaskLoaderCallback);
    }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {

    commander = ((AbstractAppActivity) getActivity()).getBitmapDownloader();

    switch (getCurrentState(savedInstanceState)) {
      case FIRST_TIME_START:
        if (Utility.isTaskStopped(dbTask)) {
          dbTask = new DBCacheTask();
          dbTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
        }
        break;
      case SCREEN_ROTATE:
        // nothing
        refreshLayout(getList());
        break;
      case ACTIVITY_DESTROY_AND_CREATE:
        getList().addNewData((MessageListBean) savedInstanceState.getSerializable("bean"));
        userBean = (UserBean) savedInstanceState.getSerializable("userBean");
        token = savedInstanceState.getString("token");
        getAdapter().notifyDataSetChanged();
        refreshLayout(bean);
        break;
    }

    super.onActivityCreated(savedInstanceState);
  }
 public void clear() {
   ArrayList<String> deletedList = new ArrayList<String>();
   deletedList.addAll(list);
   list.clear();
   adapter.notifyDataSetChanged();
   if (Utility.isTaskStopped(removeTask)) {
     removeTask = new RemoveFilterDBTask(deletedList);
     removeTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
   }
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       Intent intent = new Intent(this, AccountActivity.class);
       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
       intent.putExtra("launcher", false);
       startActivity(intent);
       return true;
     case R.id.menu_login:
       if (Utility.isTaskStopped(loginTask)) {
         loginTask = new LoginTask();
         loginTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
       }
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
Exemplo n.º 5
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {

    switch (getCurrentState(savedInstanceState)) {
      case FIRST_TIME_START:
        if (Utility.isTaskStopped(dbTask) && getList().getSize() == 0) {
          dbTask = new DBCacheTask(this, accountBean.getUid());
          dbTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
          GroupInfoTask groupInfoTask =
              new GroupInfoTask(
                  GlobalContext.getInstance().getSpecialToken(),
                  GlobalContext.getInstance().getCurrentAccountId());
          groupInfoTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
        } else {
          getAdapter().notifyDataSetChanged();
          refreshLayout(getList());
        }

        groupDataCache.put(ALL_GROUP_ID, new MessageListBean());
        groupDataCache.put(BILATERAL_GROUP_ID, new MessageListBean());

        if (getList().getSize() > 0) {
          groupDataCache.put(ALL_GROUP_ID, getList().copy());
        }
        buildActionBarNav();

        break;
      case SCREEN_ROTATE:
        // nothing
        refreshLayout(getList());
        buildActionBarNav();
        setListViewPositionFromPositionsCache();
        break;
      case ACTIVITY_DESTROY_AND_CREATE:
        userBean = savedInstanceState.getParcelable("userBean");
        accountBean = savedInstanceState.getParcelable("account");
        token = savedInstanceState.getString("token");

        if (Utility.isTaskStopped(dbTask) && getList().getSize() == 0) {
          dbTask = new DBCacheTask(this, accountBean.getUid());
          dbTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
          GroupInfoTask groupInfoTask =
              new GroupInfoTask(
                  GlobalContext.getInstance().getSpecialToken(),
                  GlobalContext.getInstance().getCurrentAccountId());
          groupInfoTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
        } else {
          getAdapter().notifyDataSetChanged();
          refreshLayout(getList());
        }

        groupDataCache.put(ALL_GROUP_ID, new MessageListBean());
        groupDataCache.put(BILATERAL_GROUP_ID, new MessageListBean());

        if (getList().getSize() > 0) {
          groupDataCache.put(ALL_GROUP_ID, getList().copy());
        }
        buildActionBarNav();

        break;
    }

    super.onActivityCreated(savedInstanceState);
  }