Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Separate UI Layer with Data Layer #7

Open
vincent-paing opened this issue Oct 8, 2017 · 1 comment
Open

Separate UI Layer with Data Layer #7

vincent-paing opened this issue Oct 8, 2017 · 1 comment

Comments

@vincent-paing
Copy link

vincent-paing commented Oct 8, 2017

Currently, the project structure is too coupled to make modifications, for example, you have the following code inside your ViewHolder

        public void onClick(View v) {
            int position = getAdapterPosition();
            mCursor.moveToPosition(position);

            int topicNameIndex = mCursor.getColumnIndex(DatabaseContract.FlashCardsEntry.FLASH_CARD_TOPIC_NAME);
            int questionIndex = mCursor.getColumnIndex(DatabaseContract.FlashCardsEntry.FLASH_CARD_QUESTION);
            int answerIndex = mCursor.getColumnIndex(DatabaseContract.FlashCardsEntry.FLASH_CARD_ANSWER);

            String topicName = mCursor.getString(topicNameIndex);
            String question = mCursor.getString(questionIndex);
            String answer = mCursor.getString(answerIndex);

            flashCardsRecyclerViewCursorAdapterOnClickListener.onFlashCardClicked(new FlashCard(topicName,question,answer));
        }

A ViewHolder shouldn't know that we're using Cursors for storing data, Instead it should only deals with a DTO and do the conversion to cursor inside a helper class for loading/saving.

@dr0pdb
Copy link
Owner

dr0pdb commented Oct 9, 2017

@vincent-paing Yeah i do agree with your suggestions. This coupling may be present in more than one place but we should take one at a time starting from this one. You can definitely go ahead and fix it. 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants