Skip to content

Commit cf4e73b

Browse files
committed
impl module added
1 parent d425782 commit cf4e73b

File tree

22 files changed

+180
-49
lines changed

22 files changed

+180
-49
lines changed

.idea/gradle.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ android {
2323
}
2424

2525
dependencies {
26-
implementation fileTree(dir: 'libs', include: ['*.jar'])
26+
implementation fileTree(include: ['*.jar'], dir: 'libs')
2727
implementation 'com.android.support:appcompat-v7:27.0.2'
28-
implementation project(":safefragmenttransaction")
28+
implementation project(':impl')
29+
implementation project(':lib')
2930
}

app/src/main/java/com/zuluft/sample/MainActivity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.zuluft.sample;
22

33
import android.os.Bundle;
4+
import android.view.View;
5+
6+
import com.zuluft.impl.SafeFragmentTransactorActivity;
47

5-
import com.zuluft.safeFragmentTransaction.components.SafeFragmentTransactorActivity;
68

79
public class MainActivity
810
extends
@@ -22,4 +24,12 @@ private void drawFragment() {
2224
fragmentManager.beginTransaction().add(R.id.flMainContent, new MainFragment())
2325
.commit());
2426
}
27+
28+
public void onNextClicked(View view) {
29+
getSafeFragmentTransaction().registerFragmentTransition(fragmentManager ->
30+
fragmentManager.beginTransaction().replace(R.id.flMainContent,
31+
TestFragment.newInstance(), "TAG2")
32+
.addToBackStack(null)
33+
.commit());
34+
}
2535
}

app/src/main/java/com/zuluft/sample/MainFragment.java

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,46 @@
44
import android.os.Handler;
55
import android.support.annotation.NonNull;
66
import android.support.annotation.Nullable;
7-
import android.support.v4.app.Fragment;
7+
import android.util.Log;
88
import android.view.LayoutInflater;
99
import android.view.View;
1010
import android.view.ViewGroup;
1111

12-
import com.zuluft.safeFragmentTransaction.SafeFragmentTransaction;
12+
import com.zuluft.impl.SafeFragmentTransactorFragment;
13+
1314

1415
public class MainFragment
1516
extends
16-
Fragment {
17-
18-
private SafeFragmentTransaction mSafeFragmentTransaction;
17+
SafeFragmentTransactorFragment {
1918

20-
@Override
21-
public void onCreate(@Nullable Bundle savedInstanceState) {
22-
super.onCreate(savedInstanceState);
23-
setRetainInstance(true);
24-
}
25-
26-
@Override
27-
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
28-
super.onActivityCreated(savedInstanceState);
29-
if (mSafeFragmentTransaction == null) {
30-
mSafeFragmentTransaction = SafeFragmentTransaction
31-
.createInstance();
32-
}
33-
mSafeFragmentTransaction.attachLifecycle(getLifecycle(), getChildFragmentManager());
34-
}
19+
private static final String TAG = "MainFragment";
3520

3621
@Nullable
3722
@Override
3823
public View onCreateView(@NonNull LayoutInflater inflater,
3924
@Nullable ViewGroup container,
4025
@Nullable Bundle savedInstanceState) {
41-
4226
return inflater.inflate(R.layout.fragment_main, container, false);
4327
}
4428

4529
@Override
4630
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
4731
super.onViewCreated(view, savedInstanceState);
48-
if (savedInstanceState == null) {
49-
new Handler().postDelayed(this::drawFragment, 5000);
50-
}
32+
Log.d(TAG, "onViewCreated: ");
5133

34+
}
5235

36+
@Override
37+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
38+
super.onActivityCreated(savedInstanceState);
39+
if (getChildFragmentManager().findFragmentById(R.id.flChildContent) == null) {
40+
new Handler().postDelayed(this::drawFragment, 5000);
41+
}
5342
}
5443

5544
private void drawFragment() {
56-
mSafeFragmentTransaction.registerFragmentTransition(fragmentManager ->
45+
getSafeFragmentTransaction().registerFragmentTransition(fragmentManager ->
5746
fragmentManager.beginTransaction().add(R.id.flChildContent, new ChildFragment())
5847
.commit());
5948
}
60-
61-
@Override
62-
public void onDestroyView() {
63-
mSafeFragmentTransaction.detachLifecycle();
64-
super.onDestroyView();
65-
}
6649
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.zuluft.sample;
2+
3+
4+
import android.os.Bundle;
5+
import android.support.annotation.NonNull;
6+
import android.support.annotation.Nullable;
7+
import android.support.v4.app.Fragment;
8+
import android.view.LayoutInflater;
9+
import android.view.View;
10+
import android.view.ViewGroup;
11+
12+
public class TestFragment
13+
extends
14+
Fragment {
15+
16+
@Nullable
17+
@Override
18+
public View onCreateView(@NonNull LayoutInflater inflater,
19+
@Nullable ViewGroup container, Bundle savedInstanceState) {
20+
return inflater.inflate(R.layout.fragment_main, container, false);
21+
}
22+
23+
public static TestFragment newInstance() {
24+
Bundle args = new Bundle();
25+
TestFragment fragment = new TestFragment();
26+
fragment.setArguments(args);
27+
return fragment;
28+
}
29+
}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4-
android:id="@+id/flMainContent"
54
android:layout_width="match_parent"
65
android:layout_height="match_parent"
76
tools:context="com.zuluft.sample.MainActivity">
87

8+
<FrameLayout
9+
android:id="@+id/flMainContent"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent" />
12+
13+
<Button
14+
android:layout_width="100dp"
15+
android:layout_height="40dp"
16+
android:onClick="onNextClicked"
17+
android:text="NEXT"
18+
tools:ignore="HardcodedText" />
19+
920

1021
</FrameLayout>

impl/build.gradle

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'com.github.dcendents.android-maven'
3+
4+
group = 'com.github.Zuluft'
5+
6+
android {
7+
compileSdkVersion 27
8+
9+
defaultConfig {
10+
minSdkVersion 14
11+
targetSdkVersion 27
12+
versionCode 1
13+
versionName "1.0"
14+
}
15+
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
}
23+
24+
dependencies {
25+
implementation fileTree(include: ['*.jar'], dir: 'libs')
26+
implementation 'com.android.support:appcompat-v7:27.0.2'
27+
implementation project(':lib')
28+
}
File renamed without changes.

0 commit comments

Comments
 (0)