ผลต่างระหว่างรุ่นของ "Sw-spec/ebook"

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
(หน้าที่ถูกสร้างด้วย 'In this project you will have to develop a simple e-book shop application. == Goals == === Phase 1 === === Phase 2 === === Phase 3 ...')
 
 
(ไม่แสดง 13 รุ่นระหว่างกลางโดยผู้ใช้คนเดียวกัน)
แถว 1: แถว 1:
 
In this project you will have to develop a simple e-book shop application.
 
In this project you will have to develop a simple e-book shop application.
 +
 +
== Your work ==
 +
* Work in pairs and implement the following functionalities (in phases).
 +
* Before actual coding for each use case or feature, sketch a sequence diagram for it first.
 +
* Use github or gitlab to keep your code.  (If you do not know how, please ask.)  You have to submit the final code (that finishes up to at least Phase 3's features) to me as an assignment.
 +
 +
== Functions ==
 +
 +
* List available e-books
 +
* Basic search functionality
 +
* Basic account operations: check fund & add fund
 +
* Buy an e-book
 +
* Show list of user's e-books
 +
* Refund (within 5 minutes)
 +
* Basic book promotions
  
 
== Goals ==
 
== Goals ==
 +
 +
=== Phase 0 ===
 +
* List available e-books (with mock-up data repository)
 +
** The app should show the list of all available book titles with prices (from the mock-up data repository) in a list view with no book cover preview.
 +
** Implementation info:
 +
*** Use repository pattern.
 +
*** Create book repository class that returns mock-up data.
  
 
=== Phase 1 ===
 
=== Phase 1 ===
 +
* List available e-books (real data)
 +
** The app should make an HTTP request to get the JSON book data (see below)
 +
** Implementation info:
 +
*** Extract book repository interface from the mock-up one.
 +
*** Create a real repository that actually makes HTTP requests.  (Watch old clips on how to do that with AsyncTask)
  
 
=== Phase 2 ===
 
=== Phase 2 ===
 +
* Basic search functionality
 +
** The user should be able to search for books by parts of the titles and publication years
 +
** The user should be able to sort the search result by titles and publication years
 +
** Implementation info:
 +
*** The search functionality should be implemented in the repository class.  It might be good to put the code in some concrete parent class that both the real and the mock-up repository classes extend.
  
 
=== Phase 3 ===
 
=== Phase 3 ===
 +
* Basic account operations: check fund & add fund (all mock-up)
 +
* Buy an e-book
 +
** A user can add e-book to the cart
 +
** A user can check-out all e-books in the cart.  Don't forget to check if the user has enough fund in the account.
 +
* Show list of user's e-books
 +
 +
=== Phase 4 ===
 +
* Basic book promotions
 +
** Load promotion data and show promotions (see below)
 +
** The app should only show available promotions (ones where the user can only buy--i.e., if a promotion contains books A, B, and C, but the user has already bought book B, the promotion is not available to the user).
 +
** Buy e-books from the promotion.
 +
 +
=== Phase 5 ===
 +
* Show book information after clicking the book on the list with book cover
 +
* Show book cover (in all book list, and user's collection)
 +
** The image URLs are in the img_url fields
 +
 +
=== Phase 6 ===
 +
* Refund (within 5 minutes)
  
 
== Data ==
 
== Data ==
แถว 13: แถว 64:
 
The book data was scraped from [https://pragprog.com].
 
The book data was scraped from [https://pragprog.com].
  
* '''Books'''
+
* '''Books''': https://theory.cpe.ku.ac.th/~jittat/courses/sw-spec/ebooks/books.json
 +
* '''Promotions''': https://theory.cpe.ku.ac.th/~jittat/courses/sw-spec/ebooks/promotions.json
 +
 
 +
== Android / technical references ==
 +
 
 +
* How to make HTTP requests with AsyncTask
 +
* ListView and ListAdapter
 +
* Custom list items and how to show images
 +
 
 +
== Codes ==
 +
=== Models: Book.kt ===
 +
<pre>
 +
class Book(val id: Int,
 +
          val title: String,
 +
          val price: Double = 0.0,
 +
          val publicationYear: Int = 0,
 +
          val imageURL: String = "") {
 +
 
 +
    override fun toString(): String {
 +
        return "${title} (${price})"
 +
    }
 +
}
 +
</pre>
 +
 
 +
=== Models: BookRepository.kt ===
 +
<pre>
 +
abstract class BookRepository : Observable() {
 +
    abstract fun loadAllBooks()
 +
    abstract fun getBooks(): ArrayList<Book>
 +
}
 +
</pre>
 +
 
 +
=== Models: MockBookRepository.kt ===
 +
<pre>
 +
class MockBookRepository : BookRepository() {
 +
    val bookList = ArrayList<Book>()
 +
    override fun loadAllBooks() {
 +
        bookList.clear()
 +
        bookList.add(Book(1,"How to win BNK election",500.0))
 +
        bookList.add(Book(2,"How to write Android App",199.0))
 +
        bookList.add(Book(5,"Sleep today",39.99))
 +
        setChanged()
 +
        notifyObservers()
 +
    }
 +
 
 +
    override fun getBooks(): ArrayList<Book> {
 +
        return bookList
 +
    }
 +
}
 +
</pre>
 +
 
 +
=== Presenters: BookView ===
 +
<pre>
 +
interface BookView {
 +
    fun setBookList(books: ArrayList<Book>)
 +
}
 +
</pre>
 +
 
 +
=== Presenters: BookPresenter ===
 +
<pre>
 +
class BookPresenter(val view: BookView,
 +
                    val repository: BookRepository): Observer {
 +
    fun start() {
 +
        repository.addObserver(this)
 +
        repository.loadAllBooks()
 +
    }
 +
 
 +
    override fun update(obj: Observable?, arg: Any?) {
 +
        if(obj == repository) {
 +
            view.setBookList(repository.getBooks())
 +
        }
 +
    }
 +
}
 +
</pre>

รุ่นแก้ไขปัจจุบันเมื่อ 04:06, 30 มีนาคม 2561

In this project you will have to develop a simple e-book shop application.

Your work

  • Work in pairs and implement the following functionalities (in phases).
  • Before actual coding for each use case or feature, sketch a sequence diagram for it first.
  • Use github or gitlab to keep your code. (If you do not know how, please ask.) You have to submit the final code (that finishes up to at least Phase 3's features) to me as an assignment.

Functions

  • List available e-books
  • Basic search functionality
  • Basic account operations: check fund & add fund
  • Buy an e-book
  • Show list of user's e-books
  • Refund (within 5 minutes)
  • Basic book promotions

Goals

Phase 0

  • List available e-books (with mock-up data repository)
    • The app should show the list of all available book titles with prices (from the mock-up data repository) in a list view with no book cover preview.
    • Implementation info:
      • Use repository pattern.
      • Create book repository class that returns mock-up data.

Phase 1

  • List available e-books (real data)
    • The app should make an HTTP request to get the JSON book data (see below)
    • Implementation info:
      • Extract book repository interface from the mock-up one.
      • Create a real repository that actually makes HTTP requests. (Watch old clips on how to do that with AsyncTask)

Phase 2

  • Basic search functionality
    • The user should be able to search for books by parts of the titles and publication years
    • The user should be able to sort the search result by titles and publication years
    • Implementation info:
      • The search functionality should be implemented in the repository class. It might be good to put the code in some concrete parent class that both the real and the mock-up repository classes extend.

Phase 3

  • Basic account operations: check fund & add fund (all mock-up)
  • Buy an e-book
    • A user can add e-book to the cart
    • A user can check-out all e-books in the cart. Don't forget to check if the user has enough fund in the account.
  • Show list of user's e-books

Phase 4

  • Basic book promotions
    • Load promotion data and show promotions (see below)
    • The app should only show available promotions (ones where the user can only buy--i.e., if a promotion contains books A, B, and C, but the user has already bought book B, the promotion is not available to the user).
    • Buy e-books from the promotion.

Phase 5

  • Show book information after clicking the book on the list with book cover
  • Show book cover (in all book list, and user's collection)
    • The image URLs are in the img_url fields

Phase 6

  • Refund (within 5 minutes)

Data

The book data was scraped from [1].

Android / technical references

  • How to make HTTP requests with AsyncTask
  • ListView and ListAdapter
  • Custom list items and how to show images

Codes

Models: Book.kt

class Book(val id: Int,
           val title: String,
           val price: Double = 0.0,
           val publicationYear: Int = 0,
           val imageURL: String = "") {

    override fun toString(): String {
        return "${title} (${price})"
    }
}

Models: BookRepository.kt

abstract class BookRepository : Observable() {
    abstract fun loadAllBooks()
    abstract fun getBooks(): ArrayList<Book>
}

Models: MockBookRepository.kt

class MockBookRepository : BookRepository() {
    val bookList = ArrayList<Book>()
    override fun loadAllBooks() {
        bookList.clear()
        bookList.add(Book(1,"How to win BNK election",500.0))
        bookList.add(Book(2,"How to write Android App",199.0))
        bookList.add(Book(5,"Sleep today",39.99))
        setChanged()
        notifyObservers()
    }

    override fun getBooks(): ArrayList<Book> {
        return bookList
    }
}

Presenters: BookView

interface BookView {
    fun setBookList(books: ArrayList<Book>)
}

Presenters: BookPresenter

class BookPresenter(val view: BookView,
                    val repository: BookRepository): Observer {
    fun start() {
        repository.addObserver(this)
        repository.loadAllBooks()
    }

    override fun update(obj: Observable?, arg: Any?) {
        if(obj == repository) {
            view.setBookList(repository.getBooks())
        }
    }
}