Ejemplo n.º 1
0
 @Override
 public void onResume() {
   super.onResume();
   // 开始加载数据
   swipeRefreshView.postDelayed(
       new Runnable() {
         @Override
         public void run() {
           attemptMessages();
         }
       },
       10);
 }
Ejemplo n.º 2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_active_message, container, false);
    this.swipeRefreshView = (SwipeRefreshView) rootView.findViewById(R.id.swipeRefreshView);
    swipeRefreshView.setColorSchemeResources(
        android.R.color.holo_blue_bright,
        android.R.color.holo_green_light,
        android.R.color.holo_orange_light,
        android.R.color.holo_red_light);
    swipeRefreshView.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            swipeRefreshView.setRefreshing(true);
            (new Handler())
                .postDelayed(
                    new Runnable() {
                      @Override
                      public void run() {
                        attemptMessages();
                      }
                    },
                    10);
          }
        });
    swipeRefreshView.setOnLoadListener(
        new SwipeRefreshView.OnLoadListener() {
          @Override
          public void onLoad() {
            (new Handler())
                .postDelayed(
                    new Runnable() {
                      @Override
                      public void run() {
                        attemptRefreshMessages();
                      }
                    },
                    10);
          }
        });
    this.lvmessage = (ListView) rootView.findViewById(R.id.lv_message);
    this.mSimpleCursorAdapter =
        new SimpleCursorAdapter(
            getActivity(),
            R.layout.fragment_active_message_item,
            null,
            new String[] {
              SmartKidContract.Message.COLUMN_NIKE,
              SmartKidContract.Message.COLUMN_DATE,
              SmartKidContract.Message.COLUMN_REPLYCONTEXT
            },
            new int[] {
              R.id.tv_header_up_name, R.id.tv_header_down_text01, R.id.tv_center_content01
            },
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) {
          @Override
          public void bindView(View view, Context context, Cursor cursor) {
            // 设置我的主题
            ((TextView) view.findViewById(R.id.tv_center_content02))
                .setText(
                    "回复我的主题:"
                        + cursor.getString(
                            cursor.getColumnIndex(SmartKidContract.Message.COLUMN_TITLE)));
            // 加载头像
            ImageLoaderTools.LoadHeadImage(
                cursor.getString(
                    cursor.getColumnIndex(SmartKidContract.Message.COLUMN_USERSMALLHEADIMG)),
                ((RoundedImageView) view.findViewById(R.id.riv_head)));
            long[] ranks =
                RankTools.gradeDispose(
                    cursor.getInt(
                        cursor.getColumnIndex(SmartKidContract.Message.COLUMN_LOGINTIMES)));

            ((ImageView) view.findViewById(R.id.iv_header_up_icon1))
                .setImageResource((int) ranks[1]);
            ((ImageView) view.findViewById(R.id.iv_header_up_icon2))
                .setImageResource((int) ranks[2]);
            super.bindView(view, context, cursor);
          }
        };
    this.lvmessage.setAdapter(this.mSimpleCursorAdapter);
    this.lvmessage.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor cursor = (Cursor) mSimpleCursorAdapter.getItem(position);
            cursor.moveToPosition(position);
            if (cursor
                .getString(cursor.getColumnIndex(SmartKidContract.Message.COLUMN_PORTNAME))
                .contains("wonderful")) {
              Intent intent = new Intent(getActivity(), PostWonderfulDetailActivity.class);
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_ID,
                  cursor.getString(cursor.getColumnIndex(SmartKidContract.Message.COLUMN_ID)));
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_NIKE,
                  cursor.getString(cursor.getColumnIndex(SmartKidContract.Message.COLUMN_NIKE)));
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_AREATYPE,
                  cursor.getString(
                      cursor.getColumnIndex(SmartKidContract.Message.COLUMN_AREATYPE)));
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_TYPE,
                  cursor.getString(
                      cursor.getColumnIndex(SmartKidContract.Message.COLUMN_PLATETYPE)));
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_USERID,
                  cursor.getInt(cursor.getColumnIndex(SmartKidContract.Message.COLUMN_USERID)));
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_PORTCONNECTOR,
                  cursor.getString(
                      cursor.getColumnIndex(SmartKidContract.Message.COLUMN_PORTNAME)));
              // 头像
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_USERSMALLHEADIMG,
                  cursor.getString(
                      cursor.getColumnIndex(SmartKidContract.Message.COLUMN_USERSMALLHEADIMG)));
              // 收藏表示
              intent.putExtra(SmartKidContract.PostModelWonderfulList.COLUMN_STORE, -1);

              // 昵称
              intent.putExtra(
                  SmartKidContract.PostModelWonderfulList.COLUMN_NIKE,
                  cursor.getString(
                      cursor.getColumnIndex(SmartKidContract.PostModelWonderfulList.COLUMN_NIKE)));
              // 是否是达人
              intent.putExtra(
                  SmartKidContract.PostModelWonderfulList.COLUMN_EREDAR,
                  cursor.getInt(
                      cursor.getColumnIndex(
                          SmartKidContract.PostModelWonderfulList.COLUMN_EREDAR)));
              // 达人类型
              intent.putExtra(
                  SmartKidContract.PostModelWonderfulList.COLUMN_EREDARNAME,
                  cursor.getString(
                      cursor.getColumnIndex(
                          SmartKidContract.PostModelWonderfulList.COLUMN_EREDARNAME)));
              // 等级
              intent.putExtra(
                  SmartKidContract.PostModelWonderfulList.COLUMN_LOGINTIMES,
                  cursor.getInt(
                      cursor.getColumnIndex(
                          SmartKidContract.PostModelWonderfulList.COLUMN_LOGINTIMES)));

              startActivity(intent);
            } else {
              Intent intent = new Intent(getActivity(), PostDetailActivity.class);
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_ID,
                  cursor.getString(cursor.getColumnIndex(SmartKidContract.Message.COLUMN_ID)));
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_AREATYPE,
                  cursor.getString(
                      cursor.getColumnIndex(SmartKidContract.Message.COLUMN_AREATYPE)));
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_TYPE,
                  cursor.getString(
                      cursor.getColumnIndex(SmartKidContract.Message.COLUMN_PLATETYPE)));
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_USERID,
                  cursor.getInt(cursor.getColumnIndex(SmartKidContract.Message.COLUMN_USERID)));
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_PORTCONNECTOR,
                  cursor.getString(
                      cursor.getColumnIndex(SmartKidContract.Message.COLUMN_PORTNAME)));
              // 头像
              intent.putExtra(
                  SmartKidContract.HomeSameAgeList.COLUMN_USERSMALLHEADIMG,
                  cursor.getString(
                      cursor.getColumnIndex(SmartKidContract.Message.COLUMN_USERSMALLHEADIMG)));
              // 收藏表示
              intent.putExtra(SmartKidContract.HomeSameAgeList.COLUMN_STORE, -1);
              // 昵称
              intent.putExtra(
                  SmartKidContract.PostModelWonderfulList.COLUMN_NIKE,
                  cursor.getString(
                      cursor.getColumnIndex(SmartKidContract.PostModelWonderfulList.COLUMN_NIKE)));
              // 是否是达人
              intent.putExtra(
                  SmartKidContract.PostModelWonderfulList.COLUMN_EREDAR,
                  cursor.getInt(
                      cursor.getColumnIndex(
                          SmartKidContract.PostModelWonderfulList.COLUMN_EREDAR)));
              // 达人类型
              intent.putExtra(
                  SmartKidContract.PostModelWonderfulList.COLUMN_EREDARNAME,
                  cursor.getString(
                      cursor.getColumnIndex(
                          SmartKidContract.PostModelWonderfulList.COLUMN_EREDARNAME)));
              // 等级
              intent.putExtra(
                  SmartKidContract.PostModelWonderfulList.COLUMN_LOGINTIMES,
                  cursor.getInt(
                      cursor.getColumnIndex(
                          SmartKidContract.PostModelWonderfulList.COLUMN_LOGINTIMES)));

              startActivity(intent);
            }
          }
        });
    return rootView;
  }