mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Convert CommonsDaggerBroadcastReceiver to kotlin
This commit is contained in:
		
							parent
							
								
									36f3475a9b
								
							
						
					
					
						commit
						04bee0ed01
					
				
					 2 changed files with 25 additions and 35 deletions
				
			
		|  | @ -1,35 +0,0 @@ | |||
| package fr.free.nrw.commons.di; | ||||
| 
 | ||||
| import android.content.BroadcastReceiver; | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| 
 | ||||
| import dagger.android.AndroidInjector; | ||||
| 
 | ||||
| /** | ||||
|  * Receives broadcast then injects it's instance to the broadcastReceiverInjector method of  | ||||
|  * ApplicationlessInjection class | ||||
|  */ | ||||
| public abstract class CommonsDaggerBroadcastReceiver extends BroadcastReceiver { | ||||
| 
 | ||||
|     public CommonsDaggerBroadcastReceiver() { | ||||
|         super(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void onReceive(Context context, Intent intent) { | ||||
|         inject(context); | ||||
|     } | ||||
| 
 | ||||
|     private void inject(Context context) { | ||||
|         ApplicationlessInjection injection = ApplicationlessInjection.getInstance(context.getApplicationContext()); | ||||
| 
 | ||||
|         AndroidInjector<BroadcastReceiver> serviceInjector = injection.broadcastReceiverInjector(); | ||||
| 
 | ||||
|         if (serviceInjector == null) { | ||||
|             throw new NullPointerException("ApplicationlessInjection.broadcastReceiverInjector() returned null"); | ||||
|         } | ||||
|         serviceInjector.inject(this); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,25 @@ | |||
| package fr.free.nrw.commons.di | ||||
| 
 | ||||
| import android.content.BroadcastReceiver | ||||
| import android.content.Context | ||||
| import android.content.Intent | ||||
| import fr.free.nrw.commons.di.ApplicationlessInjection.Companion.getInstance | ||||
| 
 | ||||
| /** | ||||
|  * Receives broadcast then injects it's instance to the broadcastReceiverInjector method of | ||||
|  * ApplicationlessInjection class | ||||
|  */ | ||||
| abstract class CommonsDaggerBroadcastReceiver : BroadcastReceiver() { | ||||
|     override fun onReceive(context: Context, intent: Intent) { | ||||
|         inject(context) | ||||
|     } | ||||
| 
 | ||||
|     private fun inject(context: Context) { | ||||
|         val injection = getInstance(context.applicationContext) | ||||
| 
 | ||||
|         val serviceInjector = injection.broadcastReceiverInjector() | ||||
|                 ?: throw NullPointerException("ApplicationlessInjection.broadcastReceiverInjector() returned null") | ||||
| 
 | ||||
|         serviceInjector.inject(this) | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Paul Hawke
						Paul Hawke