dr0pdb / My-Companion

:computer: :notebook_with_decorative_cover: Android app that caters to the need of an undergraduate student
18 stars 37 forks source link

Separate UI Layer with Data Layer #7

Open vincent-paing opened 7 years ago

vincent-paing commented 7 years ago

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 commented 7 years ago

@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. :smile: