<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="th">
	<id>https://theory.cpe.ku.ac.th/wiki/index.php?action=history&amp;feed=atom&amp;title=Sw-spec%2Feasy-card-ver1</id>
	<title>Sw-spec/easy-card-ver1 - ประวัติรุ่นแก้ไข</title>
	<link rel="self" type="application/atom+xml" href="https://theory.cpe.ku.ac.th/wiki/index.php?action=history&amp;feed=atom&amp;title=Sw-spec%2Feasy-card-ver1"/>
	<link rel="alternate" type="text/html" href="https://theory.cpe.ku.ac.th/wiki/index.php?title=Sw-spec/easy-card-ver1&amp;action=history"/>
	<updated>2026-04-22T00:56:25Z</updated>
	<subtitle>ประวัติรุ่นแก้ไขของหน้านี้ในวิกิ</subtitle>
	<generator>MediaWiki 1.33.1</generator>
	<entry>
		<id>https://theory.cpe.ku.ac.th/wiki/index.php?title=Sw-spec/easy-card-ver1&amp;diff=57628&amp;oldid=prev</id>
		<title>Jittat: หน้าที่ถูกสร้างด้วย &#039;== CardView == &lt;syntaxhighlight lang=&quot;java&quot;&gt; package com.example.jittat.easycard.card;  /**  * Created by jittat on 16/3/2560.  */  pub...&#039;</title>
		<link rel="alternate" type="text/html" href="https://theory.cpe.ku.ac.th/wiki/index.php?title=Sw-spec/easy-card-ver1&amp;diff=57628&amp;oldid=prev"/>
		<updated>2017-03-16T06:50:31Z</updated>

		<summary type="html">&lt;p&gt;หน้าที่ถูกสร้างด้วย &amp;#039;== CardView == &amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt; package com.example.jittat.easycard.card;  &lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;*  * Created by jittat on 16/3/2560.: &lt;/span&gt;  pub...&amp;#039;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;หน้าใหม่&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== CardView ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
package com.example.jittat.easycard.card;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Created by jittat on 16/3/2560.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
public interface CardView {&lt;br /&gt;
    void setCardLocation(int number, int numberOfCards);&lt;br /&gt;
&lt;br /&gt;
    void setCardTitle(String title);&lt;br /&gt;
&lt;br /&gt;
    void setCardDescription(String description);&lt;br /&gt;
&lt;br /&gt;
    void hideCardDescription();&lt;br /&gt;
    void showCardDescription();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== CardPresenter ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
package com.example.jittat.easycard.card;&lt;br /&gt;
&lt;br /&gt;
import com.example.jittat.easycard.data.Card;&lt;br /&gt;
import com.example.jittat.easycard.data.CardRepository;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Created by jittat on 16/3/2560.&lt;br /&gt;
 */&lt;br /&gt;
public class CardPresenter {&lt;br /&gt;
    private int currentCardIndex;&lt;br /&gt;
    private CardRepository repository;&lt;br /&gt;
    private CardView view;&lt;br /&gt;
    private boolean isDescriptionShown;&lt;br /&gt;
&lt;br /&gt;
    public CardPresenter(CardRepository repository, CardView view) {&lt;br /&gt;
        this.repository = repository;&lt;br /&gt;
        this.view = view;&lt;br /&gt;
&lt;br /&gt;
        currentCardIndex = 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void start() {&lt;br /&gt;
        currentCardIndex = 0;&lt;br /&gt;
        Card currentCard = repository.getCardAt(currentCardIndex);&lt;br /&gt;
&lt;br /&gt;
        isDescriptionShown = false;&lt;br /&gt;
        updateCardIndex();&lt;br /&gt;
        updateCardTitleAndDescription(currentCard);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private void updateCardTitleAndDescription(Card currentCard) {&lt;br /&gt;
        view.setCardTitle(currentCard.getTitle());&lt;br /&gt;
        view.setCardDescription(currentCard.getDescription());&lt;br /&gt;
        view.hideCardDescription();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private void updateCardIndex() {&lt;br /&gt;
        int numberOfCards = repository.getCardCount();&lt;br /&gt;
        view.setCardLocation(currentCardIndex + 1,&lt;br /&gt;
                numberOfCards);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void onCardClick() {&lt;br /&gt;
        if(isDescriptionShown) {&lt;br /&gt;
            view.hideCardDescription();&lt;br /&gt;
        } else {&lt;br /&gt;
            view.showCardDescription();&lt;br /&gt;
        }&lt;br /&gt;
        isDescriptionShown = !isDescriptionShown;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void nextCard() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void previousCard() {&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== CardActivity ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
package com.example.jittat.easycard.card;&lt;br /&gt;
&lt;br /&gt;
import android.support.v7.app.AppCompatActivity;&lt;br /&gt;
import android.os.Bundle;&lt;br /&gt;
import android.view.View;&lt;br /&gt;
import android.widget.TextView;&lt;br /&gt;
&lt;br /&gt;
import com.example.jittat.easycard.R;&lt;br /&gt;
import com.example.jittat.easycard.data.CardRepository;&lt;br /&gt;
&lt;br /&gt;
public class CardActivity extends AppCompatActivity implements CardView {&lt;br /&gt;
    private CardPresenter presenter;&lt;br /&gt;
    private CardRepository cardRepository;&lt;br /&gt;
&lt;br /&gt;
    private TextView locationTextView;&lt;br /&gt;
    private TextView titleTextView;&lt;br /&gt;
    private TextView descriptionTextView;&lt;br /&gt;
&lt;br /&gt;
    private String currentDescription;&lt;br /&gt;
&lt;br /&gt;
    @Override&lt;br /&gt;
    protected void onCreate(Bundle savedInstanceState) {&lt;br /&gt;
        super.onCreate(savedInstanceState);&lt;br /&gt;
        setContentView(R.layout.activity_card);&lt;br /&gt;
&lt;br /&gt;
        cardRepository = CardRepository.getInstance();&lt;br /&gt;
        presenter = new CardPresenter(cardRepository, this);&lt;br /&gt;
&lt;br /&gt;
        initViewHolders();&lt;br /&gt;
&lt;br /&gt;
        presenter.start();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private void initViewHolders() {&lt;br /&gt;
        locationTextView = (TextView) findViewById(R.id.textview_card_index);&lt;br /&gt;
        titleTextView = (TextView) findViewById(R.id.textview_card_title);&lt;br /&gt;
        descriptionTextView = (TextView) findViewById(R.id.textview_card_description);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    @Override&lt;br /&gt;
    public void setCardLocation(int number, int numberOfCards) {&lt;br /&gt;
        locationTextView.setText(&amp;quot;&amp;quot; + number + &amp;quot;/&amp;quot; + numberOfCards);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    @Override&lt;br /&gt;
    public void setCardTitle(String title) {&lt;br /&gt;
        titleTextView.setText(title);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    @Override&lt;br /&gt;
    public void setCardDescription(String description) {&lt;br /&gt;
        currentDescription = description;&lt;br /&gt;
        descriptionTextView.setText(currentDescription);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    @Override&lt;br /&gt;
    public void hideCardDescription() {&lt;br /&gt;
        descriptionTextView.setText(&amp;quot;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    @Override&lt;br /&gt;
    public void showCardDescription() {&lt;br /&gt;
        descriptionTextView.setText(currentDescription);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void onCardClick(View view) {&lt;br /&gt;
        presenter.onCardClick();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== CardPresenterTest ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
package com.example.jittat.easycard.card;&lt;br /&gt;
&lt;br /&gt;
import com.example.jittat.easycard.data.Card;&lt;br /&gt;
import com.example.jittat.easycard.data.CardRepository;&lt;br /&gt;
&lt;br /&gt;
import org.junit.Before;&lt;br /&gt;
import org.junit.Test;&lt;br /&gt;
import org.mockito.Mock;&lt;br /&gt;
import org.mockito.MockitoAnnotations;&lt;br /&gt;
&lt;br /&gt;
import static org.mockito.Mockito.times;&lt;br /&gt;
import static org.mockito.Mockito.verify;&lt;br /&gt;
import static org.mockito.Mockito.when;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Created by jittat on 16/3/2560.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
public class CardPresenterTest {&lt;br /&gt;
    @Mock&lt;br /&gt;
    CardRepository cardRepository;&lt;br /&gt;
&lt;br /&gt;
    @Mock&lt;br /&gt;
    CardView cardView;&lt;br /&gt;
&lt;br /&gt;
    private CardPresenter presenter;&lt;br /&gt;
&lt;br /&gt;
    @Before&lt;br /&gt;
    public void setUp() {&lt;br /&gt;
        MockitoAnnotations.initMocks(this);&lt;br /&gt;
        presenter = new CardPresenter(cardRepository, cardView);&lt;br /&gt;
&lt;br /&gt;
        when(cardRepository.getCardCount())&lt;br /&gt;
                .thenReturn(5);&lt;br /&gt;
        when(cardRepository.getCardAt(0))&lt;br /&gt;
                .thenReturn(new Card(&amp;quot;DOG&amp;quot;,&amp;quot;little animal&amp;quot;));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    @Test&lt;br /&gt;
    public void testStart() {&lt;br /&gt;
        presenter.start();&lt;br /&gt;
&lt;br /&gt;
        verify(cardRepository).getCardCount();&lt;br /&gt;
        verify(cardView).setCardLocation(1,5);&lt;br /&gt;
        verify(cardView).setCardTitle(&amp;quot;DOG&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    @Test&lt;br /&gt;
    public void testShowAndHideDescription() {&lt;br /&gt;
        presenter.start();&lt;br /&gt;
        verify(cardView).hideCardDescription();&lt;br /&gt;
&lt;br /&gt;
        presenter.onCardClick();&lt;br /&gt;
        verify(cardView).showCardDescription();&lt;br /&gt;
&lt;br /&gt;
        presenter.onCardClick();&lt;br /&gt;
        verify(cardView, times(1)).showCardDescription();&lt;br /&gt;
        verify(cardView, times(2)).hideCardDescription();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jittat</name></author>
		
	</entry>
</feed>