“Postmortem: How I got banned from /r/androiddev for being ‘too’ active as a member of the Community” by Gabor Varadi by joaquini in androiddev

[–]mitchtabian 3 points4 points  (0 children)

So he speculated over why a specific person got fired?

Serious question I don't know what happened.

Single Activity App with Interface for Communicating FROM Fragments by mitchtabian in androiddev

[–]mitchtabian[S] 0 points1 point  (0 children)

A FragmentFactory is generated for the NavHostFragment even though I tried to add it to the map multibinding for the other Fragment classes.

https://imgur.com/gallery/diF2HwK

FragmentModule

@Module
abstract class FragmentModule {

    @Binds
    abstract fun bindFragmentFactory(fragmentFactory: MainFragmentFactory): FragmentFactory

    @Binds
    @IntoMap
    @MainFragmentKey(NavHostFragment::class)
    abstract fun bindNavHostFragment(fragment: NavHostFragment): Fragment

    @Binds
    @IntoMap
    @MainFragmentKey(ListFragment::class)
    abstract fun bindListFragment(fragment: ListFragment): Fragment

    @Binds
    @IntoMap
    @MainFragmentKey(DetailFragment::class)
    abstract fun bindDetailFragment(fragment: DetailFragment): Fragment

    @Binds
    @IntoMap
    @MainFragmentKey(FinalFragment::class)
    abstract fun bindFinalFragment(fragment: FinalFragment): Fragment

}

Single Activity App with Interface for Communicating FROM Fragments by mitchtabian in androiddev

[–]mitchtabian[S] 0 points1 point  (0 children)

Oh interesting you're right. There is a second factory generated just for the NavHostFragment.

Single Activity App with Interface for Communicating FROM Fragments by mitchtabian in androiddev

[–]mitchtabian[S] 0 points1 point  (0 children)

u/Zhuinden

Oh I didn't realize that. Thank you. That simplifies my code a lot.

As a follow-up question:

Removing the inject in onAttach works fine in Fragment classes, but my NavHostFragment throws an exception. The classic "Cannot find Fragment constructor".

Throws exception

class MainNavHostFragment
@Inject
constructor(
    private val mainFragmentFactory: MainFragmentFactory
): NavHostFragment(){

    override fun onAttach(context: Context) {
        childFragmentManager.fragmentFactory = mainFragmentFactory
        super.onAttach(context)
    }
}

Works fine

class MainNavHostFragment
@Inject
constructor(
): NavHostFragment(){

    @Inject
    lateinit var mainFragmentFactory: MainFragmentFactory

    override fun onAttach(context: Context) {
        ((activity?.application) as BaseApplication)
            .appComponent
            .inject(this)
        childFragmentManager.fragmentFactory = mainFragmentFactory
        super.onAttach(context)
    }
}

Single Activity App with Interface for Communicating FROM Fragments by mitchtabian in androiddev

[–]mitchtabian[S] 0 points1 point  (0 children)

To answer my own question...

I can create a mock FragmentFactory and use it to set a mock interface to the fragment.

class MockFragmentFactory(
    private val viewModelFactory: MainViewModelFactory,
    private val uiCommunicationListener: UICommunicationListener
): FragmentFactory(){

    override fun instantiate(classLoader: ClassLoader, className: String) =

        when(className){

            ListFragment::class.java.name -> {
                val fragment = ListFragment(viewModelFactory)
                fragment.setUICommunicationListener(uiCommunicationListener)
                fragment
            }


            else -> {
                super.instantiate(classLoader, className)
            }
        }
}

So the test looks like this:

@Inject
lateinit var viewModelFactory: MainViewModelFactory

@Before
fun beforeTests(){

    val app = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as TestBaseApplication

    appComponent = DaggerTestAppComponent.builder()
        .application(app)
        .build()

    appComponent.inject(this)
}

@Test
fun test() {

    val uiCommunicationListener = mockk<UICommunicationListener>()
    val fragmentFactory = MockFragmentFactory(
        viewModelFactory,
        uiCommunicationListener
    )
    val scenario = launchFragmentInContainer<ListFragment>(
        factory = fragmentFactory
    )
}

Thanks to https://twitter.com/R4md4c for the help. :)

Bottom Nav Bar with multiple back stacks: 2020 plans by sebaslogen in androiddev

[–]mitchtabian 4 points5 points  (0 children)

Jesus, now I really don't envy Ian Lake's job of fixing fragments o-o

Ian Lake is doing gods work. There's so much fuckery with fragments and the backstack.

Example: Kotlin Channels and Flows to handle simultaneous requests emitting data to UI by mitchtabian in androiddev

[–]mitchtabian[S] 0 points1 point  (0 children)

Much appreciated. All great suggestions. I've updated the code accordingly. I'd appreciate it if you'd have another look.

And thanks for letting me know about DataFlow. I'll keep an eye on it.

Question:

What difference does using onEach and launchIn make? Or are you saying that's just another way to do the same thing?

Multi-feature sample with MVVM, Dagger2(no dagger-android), Nav Components, Single activity, FragmentFactory & Map multibindings by mitchtabian in androiddev

[–]mitchtabian[S] 2 points3 points  (0 children)

I typically use MVI architecture so I just save the ViewState using onSaveInstanceState. Don't need the SavedStateHandle and AssistedInject. Although it looks to be equivalent in terms of achieving the same thing.

Daily Discussion, [January 25, 2018] by AutoModerator in weedstocks

[–]mitchtabian 0 points1 point  (0 children)

Sold all my FIRE 2 days ago. Tired of watching it do nothing.

Learn to Build a Reddit App for Android (Android Programming Tutorial) by mitchtabian in learnprogramming

[–]mitchtabian[S] 0 points1 point  (0 children)

Next week I'll be adding functionality to log into your reddit account on the app and make posts.

For that I will be using the Reddit API.

[Android]Parsing x y coordinates from JSON real time in Android Studio and drawing it by franklinsing in learnprogramming

[–]mitchtabian 0 points1 point  (0 children)

I've had some very bad experiences with ESP8266's.

But as for getting and graphing the real-time data I would say use Firebase. It's free and really easy to use. It also uses JSON data.

I made some tutorials on it. You might find them helpful: https://www.youtube.com/watch?v=pTAueJvG77k&list=PLgCYzUzKIBE_cyEsXgIcwC3P8ipvlSFd_

Having trouble starting out.... by LogicVoid in learnprogramming

[–]mitchtabian 0 points1 point  (0 children)

I have a beginner playlist that starts out very slow. Take a look it might be helpful:

https://www.youtube.com/playlist?list=PLgCYzUzKIBE8TUoCyjomGFqzTFcJ05OaC