Skip to content

Commit

Permalink
2.0.5-alpha滑动卡片封装实现
Browse files Browse the repository at this point in the history
  • Loading branch information
iLife-yanyu committed Jul 22, 2024
0 parents commit b1869ea
Show file tree
Hide file tree
Showing 50 changed files with 1,691 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
/.idea/
2 changes: 2 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/release
77 changes: 77 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}

ext {
appVersionInt = 4
appVersionString = "1.0.4." + appVersionInt
}

android {
namespace 'com.yanyu.demoapp'
compileSdk target_sdk

defaultConfig {
applicationId "com.yanyu.demoapp"
minSdk min_sdk
targetSdk target_sdk
versionCode appVersionInt
versionName appVersionString

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
annotationProcessorOptions {
// 指定 Room Migration 升级数据库导出的 Schema 文件位置
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
sourceSets {
main {
res.srcDirs 'src/main/res', 'src/main/res-appIcon'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
applicationVariants.configureEach { variant ->
variant.outputs.configureEach { output ->

// 重命名
outputFileName = rootProject.getName() + '_v' + variant.versionName + '.apk'
}
}
}

dependencies {

implementation 'androidx.core:core-ktx:' + core_version
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:' + material_version
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.activity:activity-ktx:1.8.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:' + test_junit_version
androidTestImplementation 'androidx.test.espresso:espresso-core:' + test_espresso_version
def yanyuBase = /* 这个是jitpack仓库 */ "com.github.iLife-yanyu:base-frame"
// def yanyuBase = /* 这个是本地仓库 */ "com.yanyu.libs.android:base-frame"
api "$yanyuBase:2.0.4.1-alpha"
implementation project(':swipe-card')
implementation 'com.squareup.picasso:picasso:2.3.2'
}
126 changes: 126 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

# 混淆通用配置
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

# 混淆时保留所有的注解
-keepattributes *Annotation*

# 混淆时保留实现Parcelable接口的类成员
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

# 混淆时保留Serializable的类成员
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}

# 混淆时保留所有的Enum类成员
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

# 混淆时保留所有View的onClick方法
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

# 混淆时保留所有Drawable的构造函数
-keepclassmembers class * extends android.graphics.drawable.Drawable {
public void setAlpha(int);
}

# 混淆时保留所有自定义View的onSaveInstanceState、onRestoreInstanceState方法
-keepclassmembers class * extends android.view.View {
void onSaveInstanceState(android.util.SparseArray);
void onRestoreInstanceState(android.util.SparseArray);
}

# 混淆时保留所有本地方法不被混淆
-keepclasseswithmembernames class * {
native <methods>;
}

# 混淆时保留所有使用了Android注解的类和类成员
-keep public class * {
public <init>(org.androidannotations.api.AA);
}
-keep public class * extends android.app.Application {
public <init>();
}
-keep public class * extends android.app.Service {
public <init>();
}
-keep public class * extends android.content.BroadcastReceiver {
public <init>();
}
-keep public class * extends android.content.ContentProvider {
public <init>();
}
-keep public class * extends android.app.backup.BackupAgentHelper {
public <init>();
}
-keep public class * extends android.preference.Preference {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
}
-keep public class com.android.vending.licensing.ILicensingService

# 混淆时保留所有ComponentName的构造方法
-keepclassmembers class * {
public void *(android.content.Context, android.util.AttributeSet);
}

# 混淆时保留所有自定义控件类成员
-keepclassmembers class * extends android.widget.TextView {
void setGravity(int);
}

# 混淆时保留所有Parcelable的子类成员
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}

# 混淆时保留所有自定义Enum类成员
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keepclassmembers class com.yanyu.data.room.beans.**

# 混淆时保留所有Json序列化类

-ignorewarnings
-keep class com.huawei.agconnect.**{*;}
29 changes: 29 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".MainApplication"
android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="false" />
<activity
android:name=".BootActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
41 changes: 41 additions & 0 deletions app/src/main/java/com/yanyu/demoapp/BootActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.yanyu.demoapp

import android.view.LayoutInflater
import com.yanyu.demoapp.databinding.ActivityBootBinding
import com.yanyu.libs.baseframe.coroutine.delayMain
import com.yanyu.libs.baseframe.ktx.startActivityClass
import com.yanyu.libs.baseframe.ui.BaseActivity

class BootActivity : BaseActivity<ActivityBootBinding>() {

private var dispatch = false

override fun createViewBinding(layoutInflater: LayoutInflater): ActivityBootBinding {
return ActivityBootBinding.inflate(layoutInflater)
}

override fun initData() {

}

override fun initListeners() {
binding.btnSkip.setOnClickListener {
startMainEvent()
}
}

override fun initViews() {
delayMain(500) {
startMainEvent()
}
}

private fun startMainEvent() {
if (dispatch) {
return
}
dispatch = true
startActivityClass(MainActivity::class.java)
finish()
}
}
70 changes: 70 additions & 0 deletions app/src/main/java/com/yanyu/demoapp/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.yanyu.demoapp

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ItemTouchHelper
import com.squareup.picasso.Picasso
import com.yanyu.demoapp.databinding.ActivityMainBinding
import com.yanyu.demoapp.databinding.ItemSwipeCardBinding
import com.yanyu.libs.baseframe.ktx.inflateItem
import com.yanyu.libs.baseframe.ui.BaseActivity
import com.yanyu.libs.klog.KLog
import com.yanyu.libs.swipecard.CommonAdapter
import com.yanyu.libs.swipecard.CommonViewHolder
import com.yanyu.libs.swipecard.OverLayCardLayoutManager
import com.yanyu.libs.swipecard.SwipeCallback
import com.yanyu.libs.swipecard.SwipeConfig

class MainActivity : BaseActivity<ActivityMainBinding>() {

override fun createViewBinding(layoutInflater: LayoutInflater): ActivityMainBinding {
return ActivityMainBinding.inflate(layoutInflater)
}

override fun initData() {
//初始化配置
val swipeConfig: SwipeConfig = SwipeConfig.Builder(this).build()
binding.rv.layoutManager = OverLayCardLayoutManager(swipeConfig)
val beanList: ArrayList<SwipeCardBean> = SwipeCardBean.initDataList()
KLog.i(logTag, "大小 " + beanList.size)
val swipeAdapter = object : CommonAdapter<SwipeCardBean>(beanList) {
val size = beanList.size

override fun newViewHolder(parent: ViewGroup, viewType: Int): CommonViewHolder<SwipeCardBean> {
return object : CommonViewHolder<SwipeCardBean>(parent.inflateItem(R.layout.item_swipe_card)) {

override fun dispatch(adapter: CommonAdapter<SwipeCardBean>, data: SwipeCardBean, position: Int) {
val binding: ItemSwipeCardBinding = ItemSwipeCardBinding.bind(itemView)
binding.tvName.text = data.name
val sizeText: String = "${data.position}" + " /" + size
binding.tvPrecent.text = sizeText
Picasso.with(binding.root.context).load(data.url).into(binding.iv)
}
}
}
}
binding.rv.adapter = swipeAdapter
val builder = SwipeCallback.Builder<SwipeCardBean>(binding.rv) // 构造器
.setAdapter(swipeAdapter) // 适配器
.setSwipeConfig(swipeConfig) // 卡片配置
.setSwipeLeftRight() // 设置左右滑动
.setSwipeDirectionCallback(object : SwipeCallback.SwipeDirectionCallback<SwipeCardBean>() {
override fun onLeft(data: SwipeCardBean) {
KLog.i(logTag, "左滑")
}

override fun onRight(data: SwipeCardBean) {
KLog.i(logTag, "右滑")
}
})

val itemTouchHelper = ItemTouchHelper(SwipeCallback(builder))
itemTouchHelper.attachToRecyclerView(binding.rv)
}

override fun initListeners() {
}

override fun initViews() {
}
}
18 changes: 18 additions & 0 deletions app/src/main/java/com/yanyu/demoapp/MainApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.yanyu.demoapp

import com.yanyu.demoapp.config.ConsoleConfigImpl
import com.yanyu.demoapp.config.FileConfigImpl
import com.yanyu.libs.baseframe.BaseApplication
import com.yanyu.libs.klog.DeleteLogsTask
import com.yanyu.libs.klog.KLog

class MainApplication : BaseApplication() {

override fun initLogConfig() {
val logPath = KLog.mkdirsOfLog(this)
val console = ConsoleConfigImpl("NotesAnytime")
val file = FileConfigImpl(logPath)
val deleteTask = DeleteLogsTask(logPath)
KLog.init(console, file, deleteTask)
}
}
Loading

0 comments on commit b1869ea

Please sign in to comment.