Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version: 1.1.7
Once root fragment is restored, it should notify all nested fragments they are not managed by the root fragment any more
Fix issue that nested fragments of popping out fragment won't call onReturnFromBackground incorrectly

Version: 1.1.6
Fix issue that onViewReady is called with incorrect reason - RESTORE which should be FIRST_TIME when the fragment is a page and recreated by FragmentStatePagerAdapter

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ The library is currently release to jCenter and MavenCentral
<dependency>
<groupId>com.shipdream</groupId>
<artifactId>android-mvc</artifactId>
<version>1.1.6</version>
<version>1.1.7</version>
</dependency>
```

**Gradle:**
```groovy
compile "com.shipdream:android-mvc:1.1.6"
compile "com.shipdream:android-mvc:1.1.7"
```

## Dependency injection with reference count
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ ext {
version = [
major: 1,
minor: 1,
patch : 6
patch : 7
]
libGroup = 'com.shipdream'
libVersion = "${version.major}.${version.minor}.${version.patch}"
shouldPublish = false

androidMinSdkVersion = 14
androidCompileSdkVersion = 22
supportLibVersion = "22.2.0"
supportLibVersion = "22.2.1"
androidTargetSdkVersion = androidCompileSdkVersion
lib = [
androidMinSdk: 'com.google.android:android:4.0.1.2',
Expand All @@ -95,7 +95,7 @@ ext {
slf4jLog: "org.slf4j:slf4j-log4j12:$log4jVersion",
logbackAndroidCore: "com.github.tony19:logback-android-core:$logbackAndroidVersion",
logbackAndroidClassic: "com.github.tony19:logback-android-classic:$logbackAndroidVersion",
robolectric: "org.robolectric:robolectric:3.0-rc3"
robolectric: "org.robolectric:robolectric:3.0"
]
}

Expand Down
4 changes: 2 additions & 2 deletions documents/sites/Site-MarkDown.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ The library is currently release to jCenter and MavenCentral
<dependency>
<groupId>com.shipdream</groupId>
<artifactId>android-mvc</artifactId>
<version>1.1.6</version>
<version>1.1.7</version>
</dependency>
```

**Gradle:**
```groovy
compile "com.shipdream:android-mvc:1.1.6"
compile "com.shipdream:android-mvc:1.1.7"
```

## Samples
Expand Down
1 change: 1 addition & 0 deletions library/android-mvc-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
androidTestCompile "com.android.support:support-annotations:$rootProject.supportLibVersion"
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package com.shipdream.lib.android.mvc.view.viewpager;

import android.util.Log;

import com.shipdream.lib.android.mvc.view.BaseTestCase;
import com.shipdream.lib.android.mvc.view.LifeCycle;
import com.shipdream.lib.android.mvc.view.test.R;

import org.junit.Test;
Expand Down Expand Up @@ -56,5 +59,72 @@ public void should_restore_controller_of_tab_a_after_swipe_away_then_swipe_back_
onView(withText(TabFragmentA.RESTORE_TEXT)).check(matches(isDisplayed()));
}

@Test
public void should_call_onViewReady_in_tab_fragments_when_restored_hosting_fragment_pops_out() throws Throwable {
if (!isDontKeepActivities()) {
Log.i(getClass().getSimpleName(), "TestFragmentsInViewPager not tested as Don't Keep Activities setting is disabled");
return;
}

//=============================> At Home
lifeCycleValidator.expect(LifeCycle.onCreateNull, LifeCycle.onCreateViewNull,
LifeCycle.onViewCreatedNull, LifeCycle.onViewReadyFirstTime);

lifeCycleValidatorA.expect(LifeCycle.onCreateNull, LifeCycle.onCreateViewNull,
LifeCycle.onViewCreatedNull, LifeCycle.onViewReadyFirstTime);

lifeCycleValidatorB.expect(LifeCycle.onCreateNull, LifeCycle.onCreateViewNull,
LifeCycle.onViewCreatedNull, LifeCycle.onViewReadyFirstTime);

lifeCycleValidatorC.expect();

//=============================> At Sub Fragment
navigationController.navigateTo(this, SubFragment.class.getSimpleName());
waitTest(1200);

lifeCycleValidator.expect(LifeCycle.onPushingToBackStack, LifeCycle.onDestroyView);
lifeCycleValidatorA.expect(LifeCycle.onDestroyView);
lifeCycleValidatorB.expect(LifeCycle.onDestroyView);
lifeCycleValidatorC.expect();

pressHome();
waitTest(1200);

bringBack();
waitTest(1200);
lifeCycleValidator.expect(
LifeCycle.onDestroy,
LifeCycle.onCreateNotNull);

lifeCycleValidatorA.expect(
LifeCycle.onDestroy,
LifeCycle.onCreateNotNull);

lifeCycleValidatorB.expect(
LifeCycle.onDestroy,
LifeCycle.onCreateNotNull);

lifeCycleValidatorC.expect();

//=============================> At A
navigationController.navigateBack(this);
waitTest(1200);
lifeCycleValidator.expect(
LifeCycle.onCreateViewNotNull,
LifeCycle.onViewCreatedNotNull,
LifeCycle.onViewReadyRestore,
LifeCycle.onPoppedOutToFront);

lifeCycleValidatorA.expect(
LifeCycle.onCreateViewNotNull,
LifeCycle.onViewCreatedNotNull,
LifeCycle.onViewReadyRestore);

lifeCycleValidatorB.expect(
LifeCycle.onCreateViewNotNull,
LifeCycle.onViewCreatedNotNull,
LifeCycle.onViewReadyRestore);

lifeCycleValidatorC.expect();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.shipdream.lib.android.mvc.view.viewpager;

import android.os.Bundle;
import android.view.View;

import com.shipdream.lib.android.mvc.view.MvcFragment;
import com.shipdream.lib.android.mvc.view.help.LifeCycleMonitor;

public abstract class BaseTabFragment extends MvcFragment {
protected abstract LifeCycleMonitor getLifeCycleMonitor();

@Override
public void onViewReady(View view, Bundle savedInstanceState, MvcFragment.Reason reason) {
getLifeCycleMonitor().onCreateView(view, savedInstanceState);
getLifeCycleMonitor().onViewCreated(view, savedInstanceState);
super.onViewReady(view, savedInstanceState, reason);
getLifeCycleMonitor().onViewReady(view, savedInstanceState, reason);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getLifeCycleMonitor().onCreate(savedInstanceState);
}

@Override
public void onResume() {
super.onResume();
getLifeCycleMonitor().onResume();
}

@Override
protected void onReturnForeground() {
super.onReturnForeground();
getLifeCycleMonitor().onReturnForeground();
}

@Override
protected void onPushingToBackStack() {
super.onPushingToBackStack();
getLifeCycleMonitor().onPushingToBackStack();
}

@Override
protected void onPoppedOutToFront() {
super.onPoppedOutToFront();
getLifeCycleMonitor().onPoppedOutToFront();
}

@Override
protected void onOrientationChanged(int lastOrientation, int currentOrientation) {
super.onOrientationChanged(lastOrientation, currentOrientation);
getLifeCycleMonitor().onOrientationChanged(lastOrientation, currentOrientation);
}

@Override
public void onDestroyView() {
super.onDestroyView();
getLifeCycleMonitor().onDestroyView();
}

@Override
public void onDestroy() {
getLifeCycleMonitor().onDestroy();
super.onDestroy();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.shipdream.lib.android.mvc.view.viewpager;

import com.shipdream.lib.android.mvc.view.MvcFragment;
import com.shipdream.lib.android.mvc.view.test.R;

public class SubFragment extends MvcFragment {
@Override
protected int getLayoutResId() {
return R.layout.fragment_view_pager_sub;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import android.view.View;
import android.widget.TextView;

import com.shipdream.lib.android.mvc.view.MvcFragment;
import com.shipdream.lib.android.mvc.controller.NavigationController;
import com.shipdream.lib.android.mvc.view.MvcApp;
import com.shipdream.lib.android.mvc.view.help.LifeCycleMonitor;
import com.shipdream.lib.android.mvc.view.test.R;
import com.shipdream.lib.android.mvc.view.viewpager.controller.TabController;

import javax.inject.Inject;

public class TabFragmentA extends MvcFragment {
public class TabFragmentA extends BaseTabFragment {
static final String INIT_TEXT = "Tab A";
static final String RESTORE_TEXT = "Restored TabA";

Expand All @@ -19,11 +21,19 @@ public class TabFragmentA extends MvcFragment {

private TextView textView;

@Inject
private NavigationController navigationController;

@Override
protected int getLayoutResId() {
return R.layout.fragment_view_pager_tab;
}

@Override
protected LifeCycleMonitor getLifeCycleMonitor() {
return MvcApp.lifeCycleMonitorFactory.provideLifeCycleMonitorA();
}

@Override
public void onViewReady(View view, Bundle savedInstanceState, Reason reason) {
super.onViewReady(view, savedInstanceState, reason);
Expand All @@ -35,6 +45,13 @@ public void onViewReady(View view, Bundle savedInstanceState, Reason reason) {
} else if (reason == Reason.RESTORE) {
textView.setText(tabController.getModel().getName());
}

textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
navigationController.navigateTo(v, SubFragment.class.getSimpleName());
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
import android.view.View;
import android.widget.TextView;

import com.shipdream.lib.android.mvc.view.MvcFragment;
import com.shipdream.lib.android.mvc.view.MvcApp;
import com.shipdream.lib.android.mvc.view.help.LifeCycleMonitor;
import com.shipdream.lib.android.mvc.view.test.R;

public class TabFragmentB extends MvcFragment {
public class TabFragmentB extends BaseTabFragment {
private TextView textView;

@Override
protected int getLayoutResId() {
return R.layout.fragment_view_pager_tab;
}

@Override
protected LifeCycleMonitor getLifeCycleMonitor() {
return MvcApp.lifeCycleMonitorFactory.provideLifeCycleMonitorB();
}

@Override
public void onViewReady(View view, Bundle savedInstanceState, Reason reason) {
super.onViewReady(view, savedInstanceState, reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
import android.view.View;
import android.widget.TextView;

import com.shipdream.lib.android.mvc.view.MvcFragment;
import com.shipdream.lib.android.mvc.view.MvcApp;
import com.shipdream.lib.android.mvc.view.help.LifeCycleMonitor;
import com.shipdream.lib.android.mvc.view.test.R;

public class TabFragmentC extends MvcFragment {
public class TabFragmentC extends BaseTabFragment {
private TextView textView;

@Override
protected int getLayoutResId() {
return R.layout.fragment_view_pager_tab;
}

@Override
protected LifeCycleMonitor getLifeCycleMonitor() {
return MvcApp.lifeCycleMonitorFactory.provideLifeCycleMonitorC();
}

@Override
public void onViewReady(View view, Bundle savedInstanceState, Reason reason) {
super.onViewReady(view, savedInstanceState, reason);
Expand Down
Loading