All Projects → czh235285 → Anko Core

czh235285 / Anko Core

基于Kotlin+Anko+协程+Retrofit2的demo,完全采用anko DSL布局,也可以作为Android快速开发框架,大量常用工具类,扩展函数

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Anko Core

Coolweather
Weather App that uses Android best practices. Android Jetpack, clean architecture. Written in Kotlin
Stars: ✭ 154 (-18.52%)
Mutual labels:  coroutines, mvvm, retrofit2, glide
The Movie Db Kotlin
The Movie DB app using Kotlin with updated Android features
Stars: ✭ 176 (-6.88%)
Mutual labels:  coroutines, mvvm, retrofit2, glide
GitHubApplication
GitHubApplication 📱 is an Android application built to demonstrate the use of modern Android development tools - (Kotlin, Coroutines, Hilt, LiveData, View binding, Data Store, Architecture components, MVVM, Room, Retrofit, Navigation).
Stars: ✭ 11 (-94.18%)
Mutual labels:  coroutines, mvvm, glide, retrofit2
Mvvmarchitecture
MVVM 框架,采用 Kotlin+Jetpack,可自由配置功能,欢迎 star,fork,issue
Stars: ✭ 159 (-15.87%)
Mutual labels:  mvvm, retrofit2, glide
Jetpack github
基于Kotlin + Jetpack全家桶 + Coroutines(协程) + Flutter等架构实现的一款精简版Github客户端项目,望与广大小伙伴一起成长,欢迎start or fork!
Stars: ✭ 314 (+66.14%)
Mutual labels:  mvvm, retrofit2, glide
Androidproject
Android 技术中台,但愿人长久,搬砖不再有
Stars: ✭ 4,398 (+2226.98%)
Mutual labels:  mvvm, retrofit2, glide
Kotlin Modular Tdd Coroutines Mvvm
A sample Kotlin app which was built with modular structure, Kotlin DSL, Kotlin Coroutines, TDD and MVVM patterns.
Stars: ✭ 256 (+35.45%)
Mutual labels:  coroutines, retrofit2, glide
Playandroid
🔥🔥🔥 Kotlin + MVVM + LCE版玩安卓,暗黑模式、横竖屏、无网、弱网、无数据、加载失败等等各种情况,协程、Room、Hilt、DataStore、LiveData、Retrofit、屏幕适配、本地缓存、多语言切换、多 lib,你想要的我都有!!!
Stars: ✭ 414 (+119.05%)
Mutual labels:  coroutines, mvvm, retrofit2
Wanandroid
🏄 基于Architecture Components dependencies (Lifecycles,LiveData,ViewModel,Room)构建的WanAndroid开源项目。 你值得拥有的MVVM快速开发框架:https://github.com/jenly1314/MVVMFrame
Stars: ✭ 410 (+116.93%)
Mutual labels:  mvvm, retrofit2, glide
Gallerit
A sample Android gallery to search images posted on Reddit built using modern Android development tools (Architecture Components, MVVM, Coroutines, Flow, Navigation, Retrofit, Room, Koin)
Stars: ✭ 153 (-19.05%)
Mutual labels:  coroutines, mvvm, retrofit2
Mvvm Kotlin Android Architecture
MVVM + Kotlin + Retrofit2 + Hilt + Coroutines + Kotlin Flow + mockK + Espresso + Junit5
Stars: ✭ 1,014 (+436.51%)
Mutual labels:  coroutines, mvvm, retrofit2
Foodium
It simply loads Posts data from API and stores it in persistence storage (i.e. SQLite Database). Posts will be always loaded from local database. Remote data (from API) and Local data is always synchronized.
Stars: ✭ 1,940 (+926.46%)
Mutual labels:  coroutines, mvvm, retrofit2
Clean Mvvm Archcomponents
👽 Android app consuming Star Wars API.Built with clean architecture ,MVVM pattern, Koin , Coroutines + Flows ,Architecture Components, Data Binding , Firebase , Unit/UI Tests ,Motion Layout
Stars: ✭ 285 (+50.79%)
Mutual labels:  coroutines, mvvm, retrofit2
Mvvmsmart
基于谷歌最新AAC架构,MVVM设计模式的一套快速开发库,整合ViewModel+Lifecycles+Navigation+DataBinding+LiveData+Okhttp+Retrofit+RxJava+Glide等主流模块,满足日常开发需求。使用该框架可以快速开发高质量、易维护的Android应用。 项目组会持续维护,请放心使用.欢迎Start并Fork交流.
Stars: ✭ 382 (+102.12%)
Mutual labels:  mvvm, retrofit2, glide
Kotlinjetpackinaction
🔥🔥 Kotlin Jetpack zero to hero. 新手到高手
Stars: ✭ 264 (+39.68%)
Mutual labels:  coroutines, mvvm, retrofit2
Marvelheroes
❤️ A sample Marvel heroes application based on MVVM (ViewModel, Coroutines, LiveData, Room, Repository, Koin) architecture.
Stars: ✭ 826 (+337.04%)
Mutual labels:  coroutines, mvvm, retrofit2
Movietray
Its a playground application focusing on Paging3, MVVM architecture, Kotlin Extension functions, Retrofit, DSL, Navigation component, MotionLayout, SharedElementTransition, Single Activity Architecture, DataStore etc.
Stars: ✭ 78 (-58.73%)
Mutual labels:  coroutines, mvvm, retrofit2
RickAndMorty-AndroidMVVMSample
An android sample project using Jetpack libraries and MVVM design pattern
Stars: ✭ 17 (-91.01%)
Mutual labels:  mvvm, glide, retrofit2
Mvvmhabit
goldze: 本人喜欢尝试新的技术,以后发现有好用的东西,我将会在企业项目中实战,没有问题了就会把它引入到MVVMHabit中,一直维护着这套框架,谢谢各位朋友的支持。如果觉得这套框架不错的话,麻烦点个 star,你的支持则是我前进的动力!
Stars: ✭ 6,789 (+3492.06%)
Mutual labels:  mvvm, retrofit2, glide
Sample Code Movies
This repository contains sample code. Its purpose being, to quickly demonstrate Android and software development in general, clean code, best practices, testing and all those other must know goodies.
Stars: ✭ 81 (-57.14%)
Mutual labels:  coroutines, mvvm, glide

Anko-Core

用于自己快速开发的框架,加入了许多项目通用的东西,免去重复造轮子,持续完善中...

主要集成谷歌推荐jetpack组件库。(抛弃了xml,采用anko dsl布局)

关于Anko

优点
  • 页面构建速度快,已经使用anko做过几个完整项目,性能肉眼可见的比xml快几倍 使用Anko创建快400%的布局
  • 比xml更简单的屏幕适配
  • 代码布局更好的利用kotlin的扩展函数
  • 可以在构建布局时就加入逻辑判断
缺点
  • 不能预览,Android Studio3.3以前可以下插件预览,不过开发工具我基本都更新到最新的稳定版了
  • 学习成本较高,熟练后开发速度比xml更快,不熟的话很慢
  • Anko库已经停止维护。(ps:停止维护不是因为不好,而是因为打算推compose)
我选择Anko的理由
  • 性能,当测试、产品说你做的app比IOS的还流畅,你心里不爽吗?

  • 优点真的太多了,就不说了, 说说针对它的缺点处理。首先,不能预览这个问题,由于超简单的适配方案,完全对着设计图一把梭,也不太需要预览,后面我会介绍适配方案。学习成本问题,作为程序员我觉得只有愿意和不愿意学的区别。停止维护,这个可能很多人比较介意,其实,Anko主要也就是一个扩展库,让动态布局变成dsl的写法,对于各种控件的扩展,Anko库里还是support包的,可以直接不引入,只引入基础库支持dsl布局,然后自己去扩展控件,我这边就这样做的了~

介绍

  • demo只有几个简单的页面,仅供参考学习。

  • 网络请求 retrofit2.6+ViewModel+协程

  • 大量扩展函数,提高开发速度

  • 下拉刷新:谷歌原生SwipeRefreshLayout

  • adapter 自己封装的,支持空布局,header,footer,加载更多,多type。demo里有针对通用列表界面进行二次封装。

  • 主要用于自己开发所用,第三方依赖全是自己常用的框架整合一起了,耦合较高,不建议直接使用,仅供参考,如果框架和我用的差不多,也可以直接用~

使用

use Gradle:

repositories {
        maven { url "https://jitpack.io" }
        google()
        jcenter()
}
dependencies {
  implementation 'c.core:Anko-Core:1.0.0'
}

扩展函数

最基本的shape,命名参数可以不写的,这里写出来方便理解

view.commonShape(
                solidColor = "#f2f2f2".color,
                radius = 2.pxf,
                strokeColor = "#e5e5e5".color,
                strokeWidth = 2
            )               

更多定制化的shape,边框/4个圆角大小不一样/渐变色

view.buildShape {
          shapeStroke {
              width = 2
              color = "#ff0000".color
          }
          shapeRadius {
              topLeft = 10.pxf
              topRight = 20.pxf
              bottomRight = 30.pxf
              bottomLeft = 40.pxf
          }
          shapeGradient {
              orientation = GradientDrawable.Orientation.LEFT_RIGHT
              startColor = "#ffffff".color
              endColor = "#333333".color
          }
}

selector扩展,shapeDrawable中也可以直接使用上面buildShape中的方法,还有其他状态的就不全写了。

view.stateListDrawable {
                    defaultState {
                        shapeDrawable {
                            shapeSolidColor = "#ffffff".color
                        }
                    }
                    pressedState {
                        shapeDrawable {
                            shapeSolidColor = "#ff0000".color
                        }
                    }
                    unPressedState {
                        shapeDrawable {
                            shapeSolidColor = "#00ff00".color
                        }
                    }
                }

还有很多实用的扩展函数,直接看源码吧~

Anko超简单的适配方案

适配原理

网上各种开源适配方案,目的基本都是让不同手机展示一样的内容,也就是进行百分比适配。

UI设计图上控件的宽度 / UI设计图宽度=设备上控件的真实宽度 / 设备的宽度

也就是

设备上控件的真实宽度 = UI设计图上控件的宽度 * (设备的宽度/ UI设计图宽度)

由于anko是代码布局,设备的宽度可以直接获取的,一个扩展函数就可以直接计算了,控件宽高直接按设计图上写即可。简单粗暴吧

举例

class MainActivityUI : AnkoComponent<MainActivity> {
    lateinit var magicIndicator: MagicIndicator
    lateinit var viewPager: ViewPager

    override fun createView(ui: AnkoContext<MainActivity>) = with(ui) {
        verticalLayout {
            viewPager = noScrollViewPager {
                id = Ids.viewPager
            }.lparams(-1, 0, 1f)
            line {}.lparams(-1, 1)
            magicIndicator = magicIndicator {
            }.lparams(-1, 133.px)
        }
    }
}

这是我demo中首页的布局代码。这个133.px后面的.px就是自己扩展的方法。

具体扩展方法看 DimensionEx

我这里设计图宽高默认是750*1334,配置方法

android {
    defaultConfig {
        manifestPlaceholders = [
                designWidth: 750,
                designHeight: 1334,
        ]
    }
}
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].