Search in sources :

Example 1 with CardAdapter

use of com.chrishoekstra.trello.adapter.CardAdapter in project Trello-Android by chrisHoekstra.

the class BoardListActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.board_list);
    // Instantiate view items
    mCardList = (ListView) findViewById(R.id.card_list);
    mBoardListText = (TextView) findViewById(R.id.board_list);
    mAddCardEdit = (EditText) findViewById(R.id.add_card_edit);
    mAddCardButton = (Button) findViewById(R.id.add_card);
    mAddButton = (Button) findViewById(R.id.add);
    mCancelButton = (Button) findViewById(R.id.cancel);
    mAddCardLayout = (RelativeLayout) findViewById(R.id.add_card_layout);
    // Instantiate models
    mModel = TrelloModel.getInstance();
    // Instantiate controllers
    mController = TrelloController.getInstance();
    // Create listeners
    mOnCardsReceivedListener = new TrelloModel.OnCardsReceivedListener() {

        @Override
        public void onCardsRecivedEvent(TrelloModel model, String boardListId, ArrayList<CardVO> result) {
            mCardAdapter = new CardAdapter(BoardListActivity.this, R.id.name, result, model);
            mCardList.setAdapter(mCardAdapter);
        }
    };
    mOnCardAddedListener = new TrelloModel.OnCardAddedListener() {

        @Override
        public void onCardAddedEvent(TrelloModel model, Boolean result) {
            if (result) {
                Toast.makeText(BoardListActivity.this, "Card added!", Toast.LENGTH_SHORT).show();
                mController.getCardsByList(mBoardListId);
            } else {
                Toast.makeText(BoardListActivity.this, "Card addition failed!", Toast.LENGTH_SHORT).show();
            }
            endAddCard();
        }
    };
    mCardList.setOnItemClickListener(new ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
            Intent intent = new Intent(getParent(), CardActivity.class);
            intent.putExtra(BundleKeys.CARD_ID, mCardAdapter.getItem(position).id);
            intent.putExtra(BundleKeys.BOARD_LIST_ID, mBoardListId);
            ((TabActivityGroup) getParent()).startChildActivity("CardActivity", intent);
        }
    });
    mAddCardButton.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            beginAddCard();
        }
    });
    mCancelButton.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            endAddCard();
        }
    });
    mAddButton.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            mController.addCard(mBoardListId, mAddCardEdit.getText().toString());
        }
    });
    // Add listeners
    mModel.addListener(mOnCardsReceivedListener);
    mModel.addListener(mOnCardAddedListener);
    // Get bundle extras
    getBundleExtras((savedInstanceState != null) ? savedInstanceState : getIntent().getExtras());
    // Instantiate activity variables
    mController.getCardsByList(mBoardListId);
    populateView();
}
Also used : CardVO(com.chrishoekstra.trello.vo.CardVO) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) Button(android.widget.Button) TrelloModel(com.chrishoekstra.trello.model.TrelloModel) CardAdapter(com.chrishoekstra.trello.adapter.CardAdapter)

Aggregations

Intent (android.content.Intent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 CardAdapter (com.chrishoekstra.trello.adapter.CardAdapter)1 TrelloModel (com.chrishoekstra.trello.model.TrelloModel)1 CardVO (com.chrishoekstra.trello.vo.CardVO)1