2 Star 6 Fork 1

Zeulion / AndroidKotlinSimple

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

AndroidKotlinSimple

介绍

Android工程模板,包含基础工具,包括图片缓存、网络请求、日志、推送、相机、二维码等。 会存在Java、kotlin混合开发的情况

软件架构

工程使用多模块设计,每个模块尽量坚持单一功能原则。

  • lib-application

    • 全局Application,必须继承ExampleApplication
    • 包含一些常用的资源读取方法,如getString()、getColor()等
  • lib-glide

    • 图片缓存,使用Glide框架
    • 设置了全局的加载时error和placeholder图片
    • 使用了OkhttpClient替代默认的HttpUrlConnection
    • 做了https忽略
    • 缓存忽略URL中的token
  • lib-http

    • 网络请求,使用Retrofit+协程

    • 自定义Retrofit使用单例,初始化参数配置,并可通过create方法快速创建Service请求接口实体类

    • RetrofitManager第一次使用前需要调用init方法,可在此时设置拦截器用于填充token参数等

    • SSL忽略,可根据需要自行修改

    • 请求数据基类ApiBase,成功请求的返回基本格式,可根据需要自行修改

    • 请求状态基类ApiStatus,包含请求失败的返回数据格式

    • 分页请求数据基类ApiPage,分页成功请求的返回基本格式,属于ApiBase的data,可根据需要自行修改

    • 返回ApiStatus的请求方法

      viewModelScope.launch { 
          val result = apiCall {
              RetrofitManager.create(Login::class.java).login()
          }
          when(result){
              is ApiStatus.Success ->{}
              is ApiStatus.Error ->{}
              is ApiStatus.Canceled ->{}
          }
      }
    • 通过try catch的请求方法

      viewModelScope.launch { 
          try{
              val result = apiCallExp {
                  RetrofitManager.create(Login::class.java).login()
              }
          } catch(e: ApiExeptions){
              when(e){
                  is ApiExeptions.Canceled ->{}
                  else ->{}
              }
          }
          
      }
    • 自定义URL拼接工具类,可自动进行URLEncoder并进行拼接

  • lib-logger

    • 日志,使用Timber
    • 自定义日志保存
  • lib-push

    • 全局初始化方法
    • 小米推送
    • 华为推送
    • OPPO推送
    • VIVO推送
    • 魅族推送
  • lib-camera

    • 基于CJT2325的CameraView,支持拍照和小视频
      ExampleCamera.from(this)
                  .feature(ExampleCamera.Feature.BUTTON_STATE_BOTH)
                  .savePath(filesDir.absolutePath)
                  .forResult(1)
    • 内置权限申请,但仅包括相机和麦克风,需要存储到外部目录的需要提前申请或修改代码
  • lib-qrcode

    • 二维码扫描,使用ZXing框架,支持条形码二维码扫描
      new IntentIntegrator(context)
              .setBarcodeImageEnabled(false)
              .setBeepEnabled(true)
              .setCaptureActivity(CaptureActivity.class)
              .setDesiredBarcodeFormats(IntentIntegrator.QR_CODE)
              .setOrientationLocked(true)
              .addExtra(Intents.Scan.CHARACTER_SET, "UTF-8")
              .initiateScan();
  • lib-widget

    • 自定义控件,一些常用的自定义控件,如头部导航、底部导航、表单控件等

安装教程

  • BASE_URL在com.simple.lib.http.RequestUrl 中修改 BASE_FILE_URL是文件上传下载的

  • 网络请求需要先调用RetrofitManager.init()方法进行初始化,可添加拦截器

  • Timber需要先绑定Tree

    Timber.plant(Timber.DebugTree())

使用说明

  1. xxxx
  2. xxxx
  3. xxxx

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

特技

  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/
MIT License Copyright (c) 2021 Zeulion Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Android工程模板,包含基础工具,包括网络请求、日志、推送、相机、二维码等。 会存在Java、kotlin混合开发的情况 展开 收起
Kotlin 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Kotlin
1
https://gitee.com/zeulion/android-kotlin-simple.git
git@gitee.com:zeulion/android-kotlin-simple.git
zeulion
android-kotlin-simple
AndroidKotlinSimple
master

搜索帮助