All Projects → Tangpj → Mvvmrecurve

Tangpj / Mvvmrecurve

MVVM框架, 这个架构支持RestFul风格的Api和GraphQL,你可以根据自身需求添加recurve-retrofit2-support库(RestFul)或recurve-apollo-support库(GraphQL)实现相应的支持。 该架构同时使用纯Kotlin开发,但是你也可以在Java中使用它。

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Mvvmrecurve

Graphene
GraphQL framework for Python
Stars: ✭ 6,964 (+13554.9%)
Mutual labels:  graphql, framework
Got Auth Service
A professional role-based-authorization(also supports resource and group) service with restful and graphql api for enterprise applications.
Stars: ✭ 12 (-76.47%)
Mutual labels:  graphql, restful
Loxodon Framework
An MVVM & Databinding framework that can use C# and Lua to develop games
Stars: ✭ 802 (+1472.55%)
Mutual labels:  framework, mvvm
Graphql Framework Experiment
Code-First Type-Safe GraphQL Framework
Stars: ✭ 698 (+1268.63%)
Mutual labels:  graphql, framework
Orionjs
A new framework for serverside GraphQL apps
Stars: ✭ 35 (-31.37%)
Mutual labels:  graphql, framework
Jetpack Mvvm Best Practice
是 难得一见 的 Jetpack MVVM 最佳实践!在 以简驭繁 的代码中,对 视图控制器 乃至 标准化开发模式 形成正确、深入的理解!
Stars: ✭ 6,950 (+13527.45%)
Mutual labels:  mvvm, navigation
Blink
A high performance web framework and application server in PHP.
Stars: ✭ 837 (+1541.18%)
Mutual labels:  restful, framework
Dotvvm
Open source MVVM framework for Web Apps
Stars: ✭ 523 (+925.49%)
Mutual labels:  framework, mvvm
Jcnavigator
A decoupled navigator framework of jumping between modules or apps for iOS development.
Stars: ✭ 33 (-35.29%)
Mutual labels:  framework, navigation
Turbulette
😴 Turbulette - A batteries-included framework to build high performance, fully async GraphQL APIs
Stars: ✭ 29 (-43.14%)
Mutual labels:  graphql, framework
Phpboot
☕️ 🚀 tiny & fast PHP framework for building Microservices/RESTful APIs, with useful features: IOC, Hook, ORM, RPC, Swagger, Annotation, Parameters binding, Validation, etc.
Stars: ✭ 638 (+1150.98%)
Mutual labels:  restful, framework
Sesame
Android architecture components made right
Stars: ✭ 48 (-5.88%)
Mutual labels:  mvvm, navigation
Vesper
Vesper is a NodeJS framework that helps you to create scalable, maintainable, extensible, declarative and fast GraphQL-based server applications.
Stars: ✭ 576 (+1029.41%)
Mutual labels:  graphql, framework
Reactiveui
An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
Stars: ✭ 6,709 (+13054.9%)
Mutual labels:  framework, mvvm
Waf
Win Application Framework (WAF) is a lightweight Framework that helps you to create well structured XAML Applications.
Stars: ✭ 539 (+956.86%)
Mutual labels:  framework, mvvm
Api Platform
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
Stars: ✭ 7,144 (+13907.84%)
Mutual labels:  graphql, framework
San
A fast, portable, flexible JavaScript component framework
Stars: ✭ 4,514 (+8750.98%)
Mutual labels:  framework, mvvm
V8 Archive
Directus Database API — Wraps Custom SQL Databases with a REST/GraphQL API
Stars: ✭ 486 (+852.94%)
Mutual labels:  graphql, restful
Recife
A powerful MVC Framework for GraphQL
Stars: ✭ 20 (-60.78%)
Mutual labels:  graphql, framework
Ever
Ever® - Open-Source Commerce Platform for On-Demand Economy and Digital Marketplaces
Stars: ✭ 980 (+1821.57%)
Mutual labels:  graphql, framework

Material Render Phone

MVVMRecurve

🍡Android MVVM快速开发架构,致力于打造一个合理的Android开发架构 。

MVVMRecurve version Author Kotlin kotlinx Gradle

这是一个基于MVVM架构的Android快速开发框架,主要作用是帮助开发者搭建一个合理的MVVM架构的应用。 这个架构支持RestFul风格的Api和GraphQL,你可以根据自身需求添加recurve-retrofit2-support库(RestFul)或recurve-apollo-support库(GraphQL)实现相应的支持。 该架构同时使用纯Kotlin开发,但是你也可以在Java中使用它。

功能模块

  • recurve.core : 核心功能库
  • recurve.retrofit2 : Retrofit2支持库(RestFul)
  • recurve.apollo : Apollo支持库(GraphQL)
  • recurve.dagger2 : Dagger2支持库
  • recurve.module_adapter : 提供模块化RecyclerView Adapter
  • recurve.paging : jetpack Paging分页库支持库
  • recurve.glide : glide支持库
  • recurve.viewpager2_navigation : 实现通过navigation快速生成ViewPager2
  • recurve.bottom_navigation : 实现navigation快速支持BottomNavigation
  • recurve.viewpager2_tablayout : ViewPager2 tablelayout快速支持
  • recurve.navigation_dialog : 通过Navigation把fragment转换成dialog

将Recurve依赖到你的项目中

//project build.gradle
buildscript {
  ext.recurve_version = '1.0.0'
}

//modules build.gradle
implementation "com.recurve:recurve.core:$recurve_version"
implementation "com.recurve:recurve-retrofit2-support:$recurve_version"
implementation "com.recurve:recurve-apollo-support:$recurve_version"
implementation "com.recurve:recurve-dagger2-support:$recurve_version"
implementation "com.recurve:recurve-module-adapter:$recurve_version"
implementation "com.recurve:recurve-module-paging-support:$recurve_version"
implementation "com.recurve:recurve-glide-support:$recurve_version"
implementation "com.recurve:viewpager2-navigation-ktx:$recurve_version"
implementation "com.recurve:bottom-navigation-ktx:$recurve_version"
implementation "com.recurve:viewpager2-tablayout-ktx:$recurve_version"
implementation "com.recurve:navigation-dialog:$recurve_version"

示例代码

一个最简单的MVVM项目应该包含:MVVM架构,网络,缓存功能。所以有两个库recureve库是必须要依赖的,分别是:recurve.core(依赖了recurve.module_adapter库)、recurve.retrofit2。然后在配合Jetpack相关的库就能快速开发一个MVVM架构的项目了。

Repository

class RepoRepository constructor(
        private val db: GithubDb,
        private val githubService: GithubService) {

    val repoRateLimiter = RateLimiter<String>(15, TimeUnit.SECONDS)

    fun search(query: String): LiveData<Resource<List<Repo>>> {
        return object : NetworkBoundResource<List<Repo>, RepoSearchResponse>() {

            override fun saveCallResult(item: RepoSearchResponse) {
                val repoIds = item.items.map { it.id }
                val repoSearchResult = RepoSearchResult(
                        query = query,
                        repoIds = repoIds,
                        totalCount = item.total,
                        next = item.nextPage
                )
                db.runInTransaction {
                    db.repoDao().insertRepos(item.items)
                    db.repoDao().insert(repoSearchResult)
                }
            }

            override fun shouldFetch(data: List<Repo>?) =
                    data == null && repoRateLimiter.shouldFetch(query)

            override fun loadFromDb(): LiveData<List<Repo>> {
                return Transformations.switchMap(db.repoDao().search(query)) { searchData ->
                    if (searchData == null) {
                        AbsentLiveData.create()
                    } else {
                        db.repoDao().loadOrdered(searchData.repoIds)
                    }
                }
            }

            override fun createCall() = githubService.searchRepos(query)

        }.asLiveData()
    }
}

ViewModel

class SearchRepoViewModel : ViewModel(){

    var repoRepository: RepoRepository? = null

    private val _query = MutableLiveData<String>()
    val query : LiveData<String> = _query

    val results = Transformations
            .switchMap<String, Resource<List<Repo>>>(_query) { search ->
                if (search.isNullOrBlank()) {
                    AbsentLiveData.create()
                } else {
                    repoRepository?.search(search)
                }
            }

    fun setQuery(originalInput: String) {
        val input = originalInput.toLowerCase(Locale.getDefault()).trim()
        if (input == _query.value) {
            return
        }
        _query.value = input
    }
}

View

具体的Activit或者Fragment,view层只提供关键示例代码

//query
searchViewModel.setQuery(query)

//result callback
searchViewModel.results.observe(viewLifecycleOwner, Observer { result ->
            result?.data?.let {
                creator.setDataList(it)
            }
        })

更多

sample能的例子比较简单,如果想体验更真实的应用场景的话,欢迎关注GithubRecurve。这是一个使用MvvmRecurve实现的开源Github户端,该项目主要是用来演示MVVMRecurve的,目前只完成了认证,仓库组件(尚未完成),还在不断的完善中。

鸣谢

开发这个框架的初衷是整合Android中的一些优秀的开源库,提供一套合理的Android开发方法论。目前还在不断完善中。本框架参照了大量开源项目的优秀代码,也引用了大量开源项目,可以说是站在了巨人的肩膀上。参照/引用的开源项目主要如下:

因为篇幅关系,其它的开源库就暂不列出了。

License

/*
 * Copyright (C) 2020 Tang
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].