forked from nickbutcher/plaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continue decoupling of search data provisioning
* Introduce new FOREGROUND_SERVICE permission. * Use BroadcastReceiver to allow components to sign up. * Remove reflection from registry. To use the features introduced here, extend SearchBroadcastReceiver and FactoryRegistrationService. Then add them to your feature module's AndroidManifest. Also add the intent-filter io.plaidapp.register.SEARCH_FACTORY to the BroadcastReceiver. SearchActivity fires the required broadcast.
- Loading branch information
1 parent
9f4feb1
commit 52a6068
Showing
16 changed files
with
261 additions
and
41 deletions.
There are no files selected for viewing
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
56 changes: 56 additions & 0 deletions
56
app/src/main/java/io/plaidapp/registry/FactoryRegistrationService.kt
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,56 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
package io.plaidapp.registry | ||
|
||
import android.app.Notification | ||
import android.app.Service | ||
import android.content.Intent | ||
import android.os.Build | ||
import android.os.IBinder | ||
import io.plaidapp.core.interfaces.SearchDataSourceFactory | ||
import io.plaidapp.ui.PlaidApplication | ||
|
||
/** | ||
* Enable registering #SearchDataSourceFactory. | ||
*/ | ||
abstract class FactoryRegistrationService : Service() { | ||
|
||
override fun onBind(intent: Intent?): IBinder? { | ||
TODO("not implemented") | ||
} | ||
|
||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
// TODO create an actual notification | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
startForeground( | ||
1, | ||
Notification.Builder(this, "Plaid").setContentTitle( | ||
"Registering Search Service" | ||
).build() | ||
) | ||
} | ||
registerFactory() | ||
return super.onStartCommand(intent, flags, startId) | ||
} | ||
|
||
abstract fun getFactory(): SearchDataSourceFactory | ||
|
||
private fun registerFactory() { | ||
PlaidApplication.coreComponent(this).registry().add(getFactory()) | ||
stopSelf() | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/io/plaidapp/registry/SearchBroadcastReceiver.kt
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,46 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
package io.plaidapp.registry | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Build | ||
|
||
/** | ||
* Extend this receiver to enable hooking into Plaid's #SearchDataSourceFactoriesRegistry. | ||
*/ | ||
abstract class SearchBroadcastReceiver( | ||
private val target: Class<out FactoryRegistrationService> | ||
) : BroadcastReceiver() { | ||
|
||
override fun onReceive(context: Context?, intent: Intent?) { | ||
// TODO handle intent | ||
if (context != null) { | ||
val startRegistrationService = Intent(context, target) | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
context.startForegroundService(startRegistrationService) | ||
} else { | ||
context.startService(startRegistrationService) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val ACTION = "io.plaidapp.register.SEARCH_FACTORY" | ||
} | ||
} |
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
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
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,45 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
package io.plaidapp.core.ui | ||
|
||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.content.Context | ||
import android.content.Context.NOTIFICATION_SERVICE | ||
import android.os.Build | ||
|
||
class Notifications { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun registerChannel(context: Context) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
// Create the NotificationChannel | ||
val name = "Plaid" | ||
val descriptionText = "Plaid default notification registerChannel" | ||
val importance = NotificationManager.IMPORTANCE_DEFAULT | ||
val mChannel = NotificationChannel(name, name, importance) | ||
mChannel.description = descriptionText | ||
// Register the registerChannel with the system; you can't change the importance | ||
// or other notification behaviors after this | ||
val notificationManager = context.getSystemService(NOTIFICATION_SERVICE) as | ||
NotificationManager | ||
notificationManager.createNotificationChannel(mChannel) | ||
} | ||
} | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...gnernews/src/main/java/io/plaidapp/designernews/DesignerNewsFactoryRegistrationService.kt
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,34 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
package io.plaidapp.designernews | ||
|
||
import io.plaidapp.core.dagger.SharedPreferencesModule | ||
import io.plaidapp.core.designernews.data.login.LoginLocalDataSource | ||
import io.plaidapp.core.interfaces.SearchDataSourceFactory | ||
import io.plaidapp.designernews.dagger.DaggerDesignerNewsSearchComponent | ||
import io.plaidapp.registry.FactoryRegistrationService | ||
|
||
class DesignerNewsFactoryRegistrationService : FactoryRegistrationService() { | ||
|
||
override fun getFactory(): SearchDataSourceFactory { | ||
return DaggerDesignerNewsSearchComponent.builder() | ||
.sharedPreferencesModule( | ||
SharedPreferencesModule(this, LoginLocalDataSource.DESIGNER_NEWS_PREF) | ||
).build() | ||
.factory() | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
designernews/src/main/java/io/plaidapp/designernews/DesignerNewsSearchBroadcastReceiver.kt
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,22 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
package io.plaidapp.designernews | ||
|
||
import io.plaidapp.registry.SearchBroadcastReceiver | ||
|
||
class DesignerNewsSearchBroadcastReceiver : | ||
SearchBroadcastReceiver(DesignerNewsFactoryRegistrationService::class.java) |
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
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.