-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
274 additions
and
220 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
app/src/main/java/com/bugrui/livedatabus/Main2Activity.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
65
app/src/main/java/com/bugrui/livedatabus/MainActivity.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.