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
public Single<ActivityResult> start(Intent intent) { | |
return fragment.start(intent); | |
} |
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
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
resultSubject.onNext(Pair.create(requestCode, new ActivityResult(resultCode, data))); | |
} |
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
public Single<ActivityResult> start(final Intent intent) { | |
int requestCode = RequestCodeGenerator.generate(); | |
startActivityForResult(intent, requestCode); | |
return resultSubject | |
.filter(isRequestCodeEqual(requestCode)) | |
.map(toActivityResult()) | |
.firstOrError(); | |
} |
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
public RxActivityResult(@NonNull Activity activity) { | |
FragmentManager manager = activity.getFragmentManager(); | |
RxActivityResultFragment attachedFragment = | |
(RxActivityResultFragment) manager.findFragmentByTag(FRAGMENT_TAG); | |
// If there is no RxActivityResultFragment already attached | |
if (attachedFragment == null) { | |
// Create new one | |
attachedFragment = new RxActivityResultFragment(); |
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
class BluetoothActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
enable_bluetooth.setOnClickListener { enableBluetooth() } | |
} | |
private fun enableBluetooth() { | |
RxActivityResult(this) | |
.start(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)) |
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
class BluetoothActivity : AppCompatActivity() { | |
private val BT_REQUEST_CODE = 123 | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
enable_bluetooth.setOnClickListener { enableBluetooth() } | |
} | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
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
class MyApplication : Application() { | |
@Inject lateinit var configs: Set<@JvmSuppressWildcards ApplicationConfig> | |
override fun onCreate() { | |
super.onCreate() | |
DaggerAppComponent.builder().build().inject(this) | |
configs.forEach { it.configure() } | |
} |
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
@Module | |
class ConfigModule { | |
@Provides @IntoSet | |
@Singleton | |
fun timberConfig(): ApplicationConfig = TimberConfig() | |
@Provides @IntoSet | |
@Singleton | |
fun crashlyticsConfig(context: Context): ApplicationConfig = CrashlyticsConfig(context) |
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
class TimberConfig : ApplicationConfig { | |
override fun configure() { | |
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree()) | |
else Timber.plant(CrashlyticsTree()) | |
} | |
inner class CrashlyticsTree : Timber.Tree() { | |
override fun log(priority: Int, tag: String, message: String, throwable: Throwable?) { | |
if (priority == Log.VERBOSE || priority == Log.DEBUG) return |
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
class MyApplication : Application() { | |
@Inject lateinit var firebaseDatabase: FirebaseDatabase | |
@Inject lateinit var firebaseAuth: FirebaseAuth | |
override fun onCreate() { | |
super.onCreate() | |
DaggerAppComponent.builder().build().inject(this) | |