Skip to content

Commit

Permalink
v1.1.0代码从java转kotlin,添加粘性事件
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiLi5 committed May 6, 2020
1 parent ed64022 commit d06d18f
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 220 deletions.
10 changes: 7 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.bugrui.livedatabus"
minSdkVersion 19
targetSdkVersion 29
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"
}
Expand All @@ -20,8 +21,12 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:$rootProject.appcompatVersion"
implementation "androidx.core:core-ktx:$rootProject.corektxVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutinesVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutinesVersion"
implementation project(path: ':buslib')
}
10 changes: 6 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.bugrui.livedatabus">

<application
Expand All @@ -8,13 +9,14 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".Main2Activity"
android:name="com.bugrui.livedatabus.Main2Activity"
android:label="@string/title_activity_main2"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".MainActivity"
android:name="com.bugrui.livedatabus.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
Expand Down
33 changes: 0 additions & 33 deletions app/src/main/java/com/bugrui/livedatabus/Main2Activity.java

This file was deleted.

36 changes: 36 additions & 0 deletions app/src/main/java/com/bugrui/livedatabus/Main2Activity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.bugrui.livedatabus

import android.os.Bundle

import com.bugrui.buslib.LiveDataBus
import com.google.android.material.floatingactionbutton.FloatingActionButton

import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.lifecycle.Observer


class Main2Activity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main2)
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)

val fab = findViewById<FloatingActionButton>(R.id.fab)
fab.setOnClickListener {
LiveDataBus.send(10010, "10010")
finish()
}

LiveDataBus.withStickiness(10086)
.observe(this, Observer {
toast("收到粘性事件消息:${it.toString()}")
})

}

}


65 changes: 0 additions & 65 deletions app/src/main/java/com/bugrui/livedatabus/MainActivity.java

This file was deleted.

55 changes: 55 additions & 0 deletions app/src/main/java/com/bugrui/livedatabus/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.bugrui.livedatabus

import android.content.Intent
import android.os.Bundle

import com.bugrui.buslib.LiveDataBus
import com.google.android.material.floatingactionbutton.FloatingActionButton

import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.lifecycle.Observer

import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import java.sql.DriverManager.println

class MainActivity : AppCompatActivity() {

private var fab: FloatingActionButton? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)

fab = findViewById(R.id.fab)
fab!!.setOnClickListener { startActivity(Intent(this@MainActivity, Main2Activity::class.java)) }

LiveDataBus.with(10010)
.observe(this, Observer {
toast("收到普通事件消息:${it.toString()}")
})

}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_main, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {

val id = item.itemId

if (id == R.id.action_settings) {
LiveDataBus.sendStickiness(10086, "10086")
return true
}

return super.onOptionsItemSelected(item)
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/bugrui/livedatabus/TaostExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bugrui.livedatabus

import android.content.Context
import android.widget.Toast

fun Context.toast(text: CharSequence, duration: Int = Toast.LENGTH_SHORT) {
Toast.makeText(this, text, duration).show()
}
19 changes: 17 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'

classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -25,3 +27,16 @@ allprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}

ext {

compileSdkVersion = 29 //编译版本
buildToolsVersion = '29.0.2' //构建工具版本
minSdkVersion = 19 //最低支持版本
targetSdkVersion = 29 //目标版本

appcompatVersion = '1.1.0'
corektxVersion = '1.2.0'
coroutinesVersion = '1.3.3'

}
25 changes: 16 additions & 9 deletions buslib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"


compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 2
versionName "1.0.1"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 3
versionName "1.1.0"
}

buildTypes {
Expand All @@ -23,5 +23,12 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:$rootProject.appcompatVersion"
implementation "androidx.core:core-ktx:$rootProject.corektxVersion"
}
repositories {
mavenCentral()
}


Loading

0 comments on commit d06d18f

Please sign in to comment.