Skip to content

Commit 87579eb

Browse files
committed
broadcast module and bottom nav module updated
1 parent 60131ea commit 87579eb

16 files changed

Lines changed: 374 additions & 116 deletions

File tree

.idea/codeStyles/Project.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/org/wisdomrider/lazylibrarydemo/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class App : LazyApp() {
1212
inject(RecycleModule::class.java)
1313
inject(MapModule::class.java)
1414
inject(BroadCastModule::class.java)
15-
inject(BottomNavigationViewModule::class.java)
15+
inject(BottomNavigationModule::class.java)
1616

1717
api = inject(RetrofitModule::class.java)
1818
.buildRetrofit("https://jsonplaceholder.typicode.com", Api::class.java)
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package org.wisdomrider.lazylibrarydemo
22

3-
import android.content.BroadcastReceiver
4-
import android.content.Context
53
import android.content.Intent
64
import android.os.Bundle
7-
import android.util.Log
85
import android.view.Menu
96
import android.view.MenuItem
107
import org.wisdomrider.lazylibrary.LazyBase
11-
import org.wisdomrider.lazylibrary.modules.reciveLazyBroadCast
12-
import org.wisdomrider.lazylibrary.modules.sendLazyBoradcast
8+
import org.wisdomrider.lazylibrary.modules.receiveBroadcast
9+
import org.wisdomrider.lazylibrary.modules.sendBroadCast
10+
import org.wisdomrider.lazylibrary.modules.toast
1311
import org.wisdomrider.lazylibrarydemo.bottomnavigation.BottomNavigationView
1412
import org.wisdomrider.lazylibrarydemo.fetchdata.FetchindDataFromServer
1513
import org.wisdomrider.lazylibrarydemo.mapactivity.MapActivity
@@ -21,6 +19,7 @@ class MainActivity : LazyBase() {
2119
setContentView(R.layout.activity_main)
2220
}
2321

22+
2423
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
2524
menuInflater.inflate(R.menu.example_menu, menu)
2625
return super.onCreateOptionsMenu(menu)
@@ -35,15 +34,15 @@ class MainActivity : LazyBase() {
3534
openActivity(FetchindDataFromServer::class.java)
3635
}
3736
R.id.action_broad_cast_receiver -> {
38-
// Receiving broad cast Example
39-
reciveLazyBroadCast() { context: Context?, intent: Intent?,reciver: BroadcastReceiver? ->
40-
var msg = intent?.getStringExtra("key")
41-
Log.e("message", msg)
42-
unregisterReceiver(reciver)
37+
// Receiving broad cast Example
38+
receiveBroadcast { it, _ ->
39+
it!!.extras.getString("key").toast().lazy()
40+
true
4341
}.lazy()
44-
var intent = Intent()
45-
intent.putExtra("key", "Hello broad cast")
46-
sendLazyBoradcast(intent).lazy()
42+
val intent = Intent()
43+
intent.putExtra("key", "Hello broadCast !")
44+
intent.sendBroadCast().lazy()
45+
4746
}
4847

4948
R.id.action_bottom_nav_view -> {
@@ -54,8 +53,5 @@ class MainActivity : LazyBase() {
5453
return super.onOptionsItemSelected(item)
5554
}
5655

57-
private fun <T> openActivity(java: Class<T>) {
58-
var intent = Intent(this, java)
59-
startActivity(intent)
60-
}
56+
6157
}
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package org.wisdomrider.lazylibrarydemo.bottomnavigation
2+
23
import android.os.Bundle
34
import kotlinx.android.synthetic.main.activity_bottom_navigation_view.*
45
import org.wisdomrider.lazylibrary.LazyBase
5-
import org.wisdomrider.lazylibrary.modules.addBadge
6-
import org.wisdomrider.lazylibrary.modules.updateNumberOnBadge
6+
import org.wisdomrider.lazylibrary.modules.NavigationItem
7+
import org.wisdomrider.lazylibrary.modules.setBadges
78
import org.wisdomrider.lazylibrarydemo.R
89

910
class BottomNavigationView : LazyBase() {
11+
lateinit var navs: ArrayList<NavigationItem>
1012
override fun onCreate(savedInstanceState: Bundle?) {
1113
super.onCreate(savedInstanceState)
1214
setContentView(R.layout.activity_bottom_navigation_view)
13-
customBottomBar.addBadge(0).lazy()
14-
// Now we can update badges from any where
15-
customBottomBar.updateNumberOnBadge(3).lazy()
15+
supportActionBar!!.title = "Bottom Navigation Module Example"
16+
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
17+
navView.setBadges {
18+
navs = it
19+
}.lazy()
20+
21+
navs[0].setCount(2)
22+
1623
}
17-
}
24+
}
25+

app/src/main/java/org/wisdomrider/lazylibrarydemo/fetchdata/FetchindDataFromServer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class FetchindDataFromServer : LazyBase() {
1616
override fun onCreate(savedInstanceState: Bundle?) {
1717
super.onCreate(savedInstanceState)
1818
setContentView(R.layout.activity_fetchind_data_from_server)
19+
supportActionBar!!.title="Retrofit and Recycler Module Example"
20+
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
1921
var api = (application as App).api
2022
api.list()
2123
.get({

app/src/main/java/org/wisdomrider/lazylibrarydemo/mapactivity/MapActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import org.wisdomrider.lazylibrary.modules.createMapSync
1010
import org.wisdomrider.lazylibrary.modules.toast
1111
import org.wisdomrider.lazylibrarydemo.R
1212

13-
class MapActivity : LazyBase () {
13+
class MapActivity : LazyBase() {
1414

1515
override fun onCreate(savedInstanceState: Bundle?) {
1616
super.onCreate(savedInstanceState)
1717
setContentView(R.layout.activity_map)
18+
supportActionBar!!.title = "Map Module Example"
19+
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
1820
this.createMapSync(R.id.map) {
1921
var lat = 27.712021
2022
var long = 85.312950

app/src/main/res/layout/activity_bottom_navigation_view.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
android:layout_height="match_parent">
2222
<com.google.android.material.bottomnavigation.BottomNavigationView
2323
android:background="#ffffff"
24-
android:id="@+id/customBottomBar"
24+
android:id="@+id/navView"
2525
app:menu= "@menu/bottom_nav_view"
2626
android:layout_width="match_parent"
2727
android:layout_height="62dp"

lazylibrary/src/main/java/org/wisdomrider/lazylibrary/LazyApp.kt

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,9 @@ const val LAZY_BROADCAST = "LAZY_BROADCAST"
1010

1111
open class LazyApp : Application() {
1212

13-
var callIt: ((intent: Intent?) -> Unit)? = null
14-
val filter = IntentFilter(LAZY_BROADCAST)
15-
lateinit var receiver: BroadcastReceiver
1613
private var modules = ArrayList<LazyModule>()
1714

1815

19-
override fun sendBroadcast(intent: Intent) {
20-
intent.action = LAZY_BROADCAST
21-
super.sendBroadcast(intent)
22-
}
23-
24-
25-
2616
protected fun <T> inject(module: Class<T>): T {
2717
try {
2818
val module = (module.newInstance() as LazyModule).setContext(this)
@@ -41,19 +31,6 @@ open class LazyApp : Application() {
4131
}
4232
}
4333

44-
override fun onCreate() {
45-
super.onCreate()
46-
val intentFilter = IntentFilter(
47-
LAZY_BROADCAST
48-
)
49-
receiver = object : BroadcastReceiver() {
50-
override fun onReceive(context: Context?, intent: Intent?) {
51-
if (callIt == null) return
52-
callIt!!(intent)
53-
}
54-
}
55-
registerReceiver(receiver, intentFilter)
56-
}
5734
}
5835

5936

lazylibrary/src/main/java/org/wisdomrider/lazylibrary/LazyBase.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ open class LazyBase : AppCompatActivity() {
1414
override fun onCreate(savedInstanceState: Bundle?) {
1515
super.onCreate(savedInstanceState)
1616
lazy = application as LazyApp
17-
lazy.callIt = {
18-
gotBroadcast(it)
19-
}
17+
2018
}
2119

2220
fun <T> getModule(module: Class<T>): T {
@@ -40,8 +38,15 @@ open class LazyBase : AppCompatActivity() {
4038
return this.function(lazy.getModule(this.java))
4139
}
4240

43-
open fun gotBroadcast(intent: Intent?) {
44-
41+
fun <T> openActivity(java: Class<T>? = null, intent: Intent? = null) {
42+
if (intent == null)
43+
startActivity(Intent(this, java))
44+
else
45+
startActivity(intent)
46+
}
47+
override fun onSupportNavigateUp(): Boolean {
48+
onBackPressed()
49+
return true
4550
}
4651
}
4752

lazylibrary/src/main/java/org/wisdomrider/lazylibrary/LazyModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ open class LazyModule {
1414
fun setContext(lazy: LazyApp): LazyModule {
1515
this.lazy = lazy
1616
this.context = lazy.applicationContext
17+
this.onInit()
1718
return this
1819
}
1920

21+
open fun onInit() {
22+
23+
}
24+
2025

2126
}

0 commit comments

Comments
 (0)