Skip to content

Instantly share code, notes, and snippets.

View PetarMarijanovic's full-sized avatar

Petar Marijanović PetarMarijanovic

  • Bellabeat
  • Zagreb, Croatia
View GitHub Profile
public Single<ActivityResult> start(Intent intent) {
return fragment.start(intent);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
resultSubject.onNext(Pair.create(requestCode, new ActivityResult(resultCode, data)));
}
public Single<ActivityResult> start(final Intent intent) {
int requestCode = RequestCodeGenerator.generate();
startActivityForResult(intent, requestCode);
return resultSubject
.filter(isRequestCodeEqual(requestCode))
.map(toActivityResult())
.firstOrError();
}
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();
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))
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?) {
class MyApplication : Application() {
@Inject lateinit var configs: Set<@JvmSuppressWildcards ApplicationConfig>
override fun onCreate() {
super.onCreate()
DaggerAppComponent.builder().build().inject(this)
configs.forEach { it.configure() }
}
@Module
class ConfigModule {
@Provides @IntoSet
@Singleton
fun timberConfig(): ApplicationConfig = TimberConfig()
@Provides @IntoSet
@Singleton
fun crashlyticsConfig(context: Context): ApplicationConfig = CrashlyticsConfig(context)
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
class MyApplication : Application() {
@Inject lateinit var firebaseDatabase: FirebaseDatabase
@Inject lateinit var firebaseAuth: FirebaseAuth
override fun onCreate() {
super.onCreate()
DaggerAppComponent.builder().build().inject(this)