GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - themores/KotlinDemo: Android kotlin学习demo rxkotlin rxjava2.0+mvp

BranchesTags
Open more actions menu

Latest commit

 

History

10 Commits
10 Commits

Folders and files

NameName
Last commit message
Last commit date
menus
menus
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

KotlinDemo

关于kotlin学习过程中,使用到的一些基础控件,以及kotlin基本用法。

你见过最多的MVP

项目架构

整体流程

项目结构

demo核心代码

利用rxkotlin2.0=rxjava2.0 和lambda结合使用,应用场景是,第一步显示数据库中或者其他缓存,然后在显示网络中拉取的数据

private val onSaveDbStub: (Any) -> Unit = {}
private val onErrorStub: (Throwable) -> Unit = { throw OnErrorNotImplementedException(it) }
private val onFinallyStub: () -> Unit = {}
private val getDataFromDb: () -> Flowable<Any> = { Flowable.concat { } }
private val getDataFromNet: () -> Flowable<Any> = { Flowable.concat { } }


fun <T : Any> getData(db: Flowable<T> = getDataFromDb() as Flowable<T>,
                      net: Flowable<T> = getDataFromNet() as Flowable<T>,
                      onSuccess: (T) -> Unit,
                      onError: (Throwable) -> Unit = onErrorStub,
                      onFinally: () -> Unit = onFinallyStub,
                      onSaveDb: (T) -> Unit = onSaveDbStub): Disposable {
    return Flowable.just(db, net.doAfterNext { onSaveDb(it) })
            .flatMap { it }
            .doAfterTerminate { onFinally }
            .defaultSchedulers()
            .subscribeBy(
                    onNext = {
                        onSuccess(it)
                    },
                    onError = {
                        onError(it)
                    })
}

调用demo

1:
        //1. from the db  2.from the net
        userDao = UserDao()
        userRequest = UserRequest()
        getData(db = userDao.getUsers(),
                net = userRequest.getUsers(),
                onSuccess = {
                    view.onGetUsers(it)
                })

    
2:
 
        getData(net = userRequest.getUsers(),
                onSuccess = {
                    view.onGetUsers(it)
                },
                onSaveDb = {
                    userDao.insertUser(User(it[0].username, it[0].userAge))
                })

具体请看demo

菜单栏(menus文件夹)

底部菜单

利用Fragment show和hide 来实现底部tab 的切换
使用到的关键控件:CardView,ViewPager

侧边菜单

利用Fragment show和hide 来实现侧面内容 的切换
使用到的关键控件:DrawerLayout,NavigationView,CoordinatorLayout,AppBarLayout,Toolbar,FloatingActionButton

顶部菜单

使用到的关键控件:ViewPager,TabLayout

下拉菜单

使用到的关键控件:menu 菜单

About

Android kotlin学习demo rxkotlin rxjava2.0+mvp

Resources

Readme
Apache-2.0 license
Activity

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.