sockeqwe / mosby

A Model-View-Presenter / Model-View-Intent library for modern Android apps
http://hannesdorfmann.com/mosby/
Apache License 2.0
5.49k stars 841 forks source link

loadData() gets called when orientation changes with setRetainInstance(true) #61

Closed pkliang closed 9 years ago

pkliang commented 9 years ago

Hi, I am now learning using MvpLceViewStateFragment with MvpLceRxPresenter, I notice that even setRetainInstance(true), loadData() still gets called if viewstate is "showLoading" when orientation changes

@Override
    public LceViewState<List<LogRecord>, HistoryView> createViewState() {
        return new RetainingFragmentLceViewState<>(this);
    }

log

V/HistoryFragment2﹕ ⇢ onRefresh()  <----- SwipeRefreshLayout.OnRefreshListener
V/HistoryFragment2﹕ ⇢ loadData(pullToRefresh=true)
V/HistoryPresenter﹕ ⇢ refresh(pullToRefresh=true)
V/HistoryPresenter﹕ ⇠ refresh [0ms]
D/Retrofit﹕ ---> HTTP POST
D/HistoryFragment2﹕ fragment: HistoryFragment2{83e3df4 #0 id=0x7f0e00a6}
V/HistoryFragment2﹕ ⇠ loadData [4ms]
V/HistoryFragment2﹕ ⇠ onRefresh [5ms]

V/HistoryFragment2﹕ ⇢ onDestroyView()  <-----orientation changes
V/HistoryPresenter﹕ ⇢ detachView(retainInstance=true)
V/HistoryPresenter﹕ ⇠ detachView [0ms]
V/HistoryFragment2﹕ ⇠ onDestroyView [1ms]
V/HistoryPresenter﹕ ⇢ attachView(view=HistoryFragment2{83e3df4 #0 id=0x7f0e00a6}) <----same instance of Fragment as above
V/HistoryPresenter﹕ ⇠ attachView [0ms]
V/HistoryFragment2﹕ ⇢ loadData(pullToRefresh=true) <----still gets called after orientation changed
V/HistoryPresenter﹕ ⇢ refresh(pullToRefresh=true)
V/HistoryPresenter﹕ ⇠ refresh [0ms]
D/HistoryFragment2﹕ fragment: HistoryFragment2{83e3df4 #0 id=0x7f0e00a6}
V/HistoryFragment2﹕ ⇠ loadData [1ms]
D/Retrofit﹕ ---> HTTP POST
sockeqwe commented 9 years ago

Yes, you are right, there is a bug introduced with latest Internal delegate implementation change. I will fix it soon

pkliang commented 9 years ago

Hi, I have updated the log

sockeqwe commented 9 years ago

Thanks for reporting. The bug is fixed. I have pushed 1.1.1-SNAPSHOT containing the bugfix to sontype's snapshot repository.

allprojects {
  ... 

repositories {
    maven{
      url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }

   ...
}

Please let me know if this SNAPSHOT version fixes that problem for you as well.

pkliang commented 9 years ago

Great! Thanks, problem fixed.

sockeqwe commented 9 years ago

@pkliang Please let me know if it works as expected now, once you have time to check your app with the latest snapshot.

pkliang commented 9 years ago

@sockeqwe I have my app tested with the latest snapshot, it works as expected now.

sockeqwe commented 9 years ago

Thanks!

Liang Song notifications@github.com schrieb am Di., 7. Juli 2015 um 15:32 Uhr:

@sockeqwe https://github.com/sockeqwe I have my app tested with the latest snapshot, it works as expected now.

— Reply to this email directly or view it on GitHub https://github.com/sockeqwe/mosby/issues/61#issuecomment-119203188.

sockeqwe commented 9 years ago

@pkliang fyi: I have released mosby 1.1.1 containing this bugfix.