Giter Club home page Giter Club logo

flickrandroid's Introduction

Demo

Demo

Download an apk

flickr.apk

Languages, libraries and tools used

Architecture

Demo

UI

FlickrSearchFragment onViewCreated 에서 FlickrSearchViewModel results observe 합니다.

Loading, Success, Error 에 따라 UI 를 구현합니다.

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        viewModel.results.observe(this, Observer {
            Timber.i("status: [${it.status}]\ndata: [${it.data?.size}]\nerror: [${it.message}]")
            when {
                it.status == Status.LOADING -> {
                    ...
                }
                it.data != null -> {
                    ...
                }
                it.message != null -> {
                   ...
                }
            }
        })
    }

Presentation

안드로이드 프레임워크에 깊게 의존하지 않으며 사용자 인터페이스가 어떻게 표현될지를 담당합니다. 현재 프로젝트에서는 Loading, Succes, error 의 데이터로 표현하고 있습니다.

FlickrSearchViewModelresults 는 Query로 조회되는 데이터가 변경되었을 경우 변경된 데이터를 전달합니다.

FlickrSearchViewModel 의 3가지 함수가 있습니다.

  • fun search(keyword: String) // Parameter keyword의 첫 페이지의 데이터를 가져옵니다.
  • fun refresh() // 현재 Keyword의 첫 페이지 데이터를 Network 로 부터 가져옵니다.
  • fun loadNextPage() // 현재 Keyword의 다음 페이지 데이터를 Network로 부터 가져옵니다.

Test Codes:

Data

DataSources(Network, Local DB)를 가지고 있으며 조건에 따라 DataSoruces 로 데이터를 가져오고 DB에 저장합니다.

PhotoRepository 의 2가지 함수가 있습니다.

  • fun searchPhotos(keyword: String): LiveData<Resource<List<Photo>>> // Parameter keyword의 첫 페이지 데이터를 검색하고 그 결과로 LiveData를 반환합니다.
  • fun searchNextPhotos(keyword: String): LiveData<Resource<Boolean>> // Parameter keyword의 다음 페이지 데이터를 검색하고 Local DB에 저장합니다. 다음 페이지 존재 유무의 LiveData를 반환합니다. (Next page 가 존재한다면 true, 존재하지 않으면 false)

Test Codes: PhotoRepositoryTest // searchPhotos, searchNextPhotos 검증

Data layer의 데이터를 가져오는 조건

Demo

DataSources

FlickrApi

FlickrApi Network로 부터 데이터를 가져옵니다.

FlickrDatabase

FlickrDatabase Local Db 입니다.

FlickrDao

Scheme

Queries
@Query("SELECT * FROM photos WHERE photo_id in (:photoIds) ORDER BY dateTaken DESC")
abstract fun searchPhotosByIds(photoIds: List<Long>): LiveData<List<Photo>>

@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insertPhotos(items: List<Photo>): List<Long>

@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insertSearchResult(photoSearchResult: PhotoSearchResult)

@Query("SELECT * FROM photo_search_results WHERE keyword = :keyword LIMIT 1")
abstract fun searchResult(keyword: String): LiveData<PhotoSearchResult>

@Query("SELECT * FROM photo_search_results WHERE keyword = :keyword  LIMIT 1")
abstract fun unitSearchResult(keyword: String): PhotoSearchResult?

flickrandroid's People

Contributors

kimtaesu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.