Giter Site home page Giter Site logo

fmzwy / fragmject Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miaowmiaow/fragmject

0.0 0.0 0.0 5.27 MB

一个入门级的项目,通过对Kotlin和Jetpack全家桶的系统运用,实现的一个功能完备符合主流市场标准App。 代码简单,内容全面,知识详细,快速上手,对理解其他项目设计**和封装技巧也很有帮助。

Kotlin 83.58% Java 5.98% JavaScript 2.23% HTML 1.12% CSS 0.01% Groovy 7.08%

fragmject's Introduction

前言

刚开始学习Kotlin其实挺痛苦的,相关的书籍或视频偏向于知识点的讲解看完好像还是不会做项目,开源的项目内容太多用来上手实在不合适。
多希望有个代码简单,内容全面,知识详细,快速上手的项目,于是便有了fragmject项目。 在此感谢玩Android 提供的开放API

简介

一个入门级的项目,通过对KotlinJetpack全家桶的系统运用,实现的一个功能完备符合主流市场标准App。 代码简单,内容全面,知识详细,快速上手,对理解其他项目设计**和封装技巧也很有帮助。
学习本项目你将有如下收获:

  • Kotlin(函数进阶,泛型,反射,协程...)
  • MVVM(ViewModel,LiveData...)
  • 单Activity应用架构(Navigation)
  • 屏幕录制、图片编辑、字节码插桩...

截图展示

1.jpg 2.jpg
3.jpg 4.jpg

项目目录结构

├── app                                  app
|   └── src 
|       └── main 
|       |   └── java                     源码目录
|       |   |   ├── activity             Activity目录
|       |   |   |   └── MainActivity     项目唯一Activity
|       |   |   ├── adapter              Adapter目录
|       |   |   ├── fragment             Fragment目录
|       |   |   ├── model                ViewModel目录
|       |   |   └── App                  Application
|       |   |
|       |   └── res                      资源目录
|       |   |   └── navigation           导航图目录
|       |   |
|       |   └── AndroidManifest.xml      配置文件
|       |
|       └── build.gradle                 模块构建配置
|       └── channel                      渠道配置文件
|       └── dictionary                   自定义混淆字典
|       └── proguard-rules.pro           代码混淆配置文件
| 
├── library-base                         基础library(存放通用的封装源码)
|   └── src 
|       └── main 
|       |   ├── assets                   原生文件目录
|       |   └── java                     源码目录
|       |       ├── bus                  消息总线目录
|       |       ├── db                   Database目录
|       |       ├── dialog               Dialog目录
|       |       ├── http                 网络请求目录
|       |       ├── provider             ContentProvider目录
|       |       ├── utils                工具类目录
|       |       └── view                 自定义view目录
|       | 
|       └── build.gradle                 模块构建配置
| 
├── library-common                       公共library(存放各个 module 公共的源码及资源)
|   └── src 
|       └── main 
|       |   └── java                     源码目录
|       |       ├── bean                 实体类目录
|       |       └── constant             常量配置目录
|       | 
|       └── build.gradle                 模块构建配置
| 
├── miaow-picture                        图片编辑器(目录同app,不再展开)
├── module-user                          用户模块(目录同app,不再展开)
├── module-wan                           玩Android功能模块(目录同app,不再展开)
| 
├── plugin-statistic                     统计插件模块
|   └── src 
|       └── main 
|           └── groovy                   源码目录
|           |   ├── bp                   埋点统计目录
|           |   └── mt                   耗时统计目录
|           | 
|           └── resources                配置目录
|               └── statistic.properties 插件配置
| 
├── repos                                统计插件生成目录
|
├── build.gradle                         项目构建配置
├── config.gradle                        gradle编译文件 gradle依赖配置
├── config.properties                    项目配置
├── gradle.properties                    gradle配置
└── settings.gradle                      项目依赖配置

Kotlin

Kotlin是一种富有表现力且简洁的编程语言,不仅可以减少常见代码错误,还可以轻松集成到现有应用中。

ViewBinding

通过视图绑定功能,您可以更轻松地编写可与视图交互的代码。与使用findViewById相比,视图绑定具有 Null安全类型安全 等很显著的优点。

LiveData

LiveData是一种可观察的数据存储器类,它具有生命周期感知能力,这种感知能力可确保LiveData仅更新处于活跃生命周期状态的应用组件观察者。并且它具有 确保界面符合数据状态不会发生内存泄漏不会因Activity停止而导致崩溃不再需要手动处理生命周期数据始终保持最新状态适当的配置更改共享资源 等优势。

ViewModel

ViewModel类旨在以注重生命周期的方式存储和管理界面相关的数据。ViewModel类让数据可在发生屏幕旋转等配置更改后继续留存。

协程

协程是一种并发设计模式,您可以在 Android 平台上使用它来简化异步执行的代码。它包括 轻量内存泄漏更少内置取消支持Jetpack集成 等特点。

Navigation

Navigation是 Android Jetpack 组件之一,主要是用于Fragment路由导航的框架,通过Navigation我们可以设计出单Activity应用架构。

WebView优化及H5秒开实践

基于RoomDatabase封装的KVDatabase

通过键值对的方式来存储数据,不用再去关心RoomDatabase的复杂操作。

快速使用

// 存储数据
KVDatabase.set(key: String, value: String)

// 获取数据
KVDatabase.get(key: String)

基于SharedFlow封装的消息总线SharedFlowBus

快速使用

// 发送消息
SharedFlowBus.with(objectKey: Class<T>).tryEmit(value: T)
// 发送粘性消息
SharedFlowBus.withSticky(objectKey: Class<T>).tryEmit(value: T)

// 订阅消息
SharedFlowBus.on(objectKey: Class<T>).observe(owner){ it ->
    println(it)
}
// 订阅粘性消息
SharedFlowBus.onSticky(objectKey: Class<T>).observe(owner){ it ->
    println(it)
}

动态权限申请

字节码插桩

图片编辑器

截图展示

5.gif 6.gif 7.gif

接入

第 1 步:在工程的build.gradle中添加:

allprojects {
    repositories {
		...
		mavenCentral()
	}
}

第2步:在应用的build.gradle中添加:

dependencies {
    implementation 'com.github.miaowmiaow.fragmject:miaow-picture:1.2.6'
}

快速使用

PictureEditorDialog.newInstance()
    .setBitmapPath(path)
    .setEditorFinishCallback(object : EditorFinishCallback {
        override fun onFinish(path: String) {
            val bitmap = BitmapFactory.decodeFile(path, BitmapFactory.Options())
        }
    })
    .show(childFragmentManager)

如上所示:

  1. 通过PictureEditorDialog调用图片编辑器
  2. 通过setBitmapPath(path)传入图片路径
  3. 通过setEditorFinishCallback(callback)获取编辑后的图片地址

如果觉得PictureEditorDialog不能满足需求,还可以通过PictureEditorView来自定义样式

自定义使用

<com.example.miaow.picture.editor.PictureEditorView
    android:id="@+id/pic_editor"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
picEditor.setBitmapPath(path)
picEditor.setMode(PictureEditorView.Mode.STICKER)
picEditor.setGraffitiColor(Color.parseColor("#ffffff"))
picEditor.setSticker(StickerAttrs(bitmap))
picEditor.graffitiUndo()
picEditor.mosaicUndo()
picEditor.saveBitmap()

如上所示:

  1. 通过setBitmapPath(path)传入图片路径
  2. 通过setMode(mode)设置编辑模式,分别有:涂鸦,橡皮擦,马赛克,贴纸
  3. 通过setGraffitiColor(color)设置涂鸦画笔颜色
  4. 通过setSticker(StickerAttrs(bitmap))设置贴纸
  5. 通过graffitiUndo()涂鸦撤销
  6. 通过mosaicUndo()马赛克撤销
  7. 通过saveBitmap()保存编辑图片

PictureEditorView就介绍到这里,具体使用请查看PictureEditorDialog

图片裁剪

<com.example.miaow.picture.editor.PictureClipView
    android:id="@+id/clip"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
clip.setBitmapResource(bitmap)
clip.rotate()
clip.reset()
clip.saveBitmap()

如上所示:

  1. 通过setBitmapResource(bitmap)传入裁剪图片
  2. 通过clip.rotate()图片旋转
  3. 通过clip.reset()图片重置
  4. 通过clip.saveBitmap()保存裁剪框内图片

PictureClipView就介绍到这里,具体使用请查看PictureClipDialog

讲在最后,如无法加载图片,请确认存储权限

主要开源框架

Thanks

感谢所有优秀的开源项目 ^^
如果喜欢的话希望给个 Star 或 Fork ^
^
谢谢~~

LICENSE

Copyright 2021 miaowmiaow

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

   https://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.

fragmject's People

Contributors

miaowmiaow 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.