Skip to content

Commit

Permalink
modify logic about keep titlebar
Browse files Browse the repository at this point in the history
  • Loading branch information
KingJA committed Oct 30, 2017
1 parent b0309c1 commit fccf574
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class KeepTitleFragment extends Fragment {
@BindView(R.id.iv_back)
ImageView mIvBack;
private Unbinder unBinder;
private ViewGroup rootView;

@OnClick(R.id.iv_back)
public void onBack() {
Expand All @@ -44,40 +45,28 @@ public void onBack() {
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mIvBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().finish();
}
});
PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1200);
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.title_title_bar, container, false);
unBinder = ButterKnife.bind(this, rootView);
RelativeLayout titleBarView = (RelativeLayout) rootView.findViewById(R.id.rl_titleBar);
LinearLayout contentView = (LinearLayout) rootView.findViewById(R.id.ll_content);
rootView.removeView(contentView);
LoadSir loadSir = new LoadSir.Builder()
.addCallback(new EmptyCallback())
.addCallback(new LoadingCallback())
.setDefaultCallback(LoadingCallback.class)
.build();


loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
@Override
public void onReload(View v) {
loadService.showSuccess();
}

});
PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1200);
}

return loadService.getTitleLoadLayout(getContext(), rootView, titleBarView);
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
savedInstanceState) {
rootView = (ViewGroup) inflater.inflate(R.layout.title_title_bar, container, false);
unBinder = ButterKnife.bind(this, rootView);
return rootView;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_best_practices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onLottie"
android:text="Lottie"
android:text="LoadSir + Lottie"
android:textAllCaps="false"/>

<Button
Expand Down
44 changes: 19 additions & 25 deletions docs/FAQ-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,26 @@ in Fragment
```

### #2 如果保留原布局的标题栏(toolbar,或者titileView)?
在Activity,只要注册toolbar,或者titileView以下的布局View即可,这样LoadSir就会保留标题栏。
在Fragment,情况稍微复杂点,请看模板代码:
在Activity,在Fragment中,只要注册toolbar,或者titileView以下的布局View即可,这样LoadSir就会保留标题栏。
在Fragment,请看参考代码:
```java
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.title_title_bar, container, false);
unBinder = ButterKnife.bind(this, rootView);
RelativeLayout titleBarView = (RelativeLayout) rootView.findViewById(R.id.rl_titleBar);
LinearLayout contentView = (LinearLayout) rootView.findViewById(R.id.ll_content);
rootView.removeView(contentView);
LoadSir loadSir = new LoadSir.Builder()
.addCallback(new EmptyCallback())
.addCallback(new LoadingCallback())
.setDefaultCallback(LoadingCallback.class)
.build();
loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
@Override
public void onReload(View v) {
loadService.showSuccess();
}

});
return loadService.getTitleLoadLayout(getContext(), rootView, titleBarView);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
LinearLayout contentView = (LinearLayout) rootView.findViewById(R.id.ll_content);
LoadSir loadSir = new LoadSir.Builder()
.addCallback(new EmptyCallback())
.addCallback(new LoadingCallback())
.setDefaultCallback(LoadingCallback.class)
.build();
loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
@Override
public void onReload(View v) {
loadService.showSuccess();
}
});
PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1200);
}
```


Expand Down
41 changes: 18 additions & 23 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,24 @@ public class BufferKnifeActivity extends AppCompatActivity {

### #2 How to keep the toolbar in Fragment?
```java
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.title_title_bar, container, false);
unBinder = ButterKnife.bind(this, rootView);
RelativeLayout titleBarView = (RelativeLayout) rootView.findViewById(R.id.rl_titleBar);
LinearLayout contentView = (LinearLayout) rootView.findViewById(R.id.ll_content);
rootView.removeView(contentView);
LoadSir loadSir = new LoadSir.Builder()
.addCallback(new EmptyCallback())
.addCallback(new LoadingCallback())
.setDefaultCallback(LoadingCallback.class)
.build();
loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
@Override
public void onReload(View v) {
loadService.showSuccess();
}

});
return loadService.getTitleLoadLayout(getContext(), rootView, titleBarView);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//fetch contentView View,the View except toolbar or titleView.
LinearLayout contentView = (LinearLayout) rootView.findViewById(R.id.ll_content);
LoadSir loadSir = new LoadSir.Builder()
.addCallback(new EmptyCallback())
.addCallback(new LoadingCallback())
.setDefaultCallback(LoadingCallback.class)
.build();
loadService = loadSir.register(contentView, new Callback.OnReloadListener() {
@Override
public void onReload(View v) {
loadService.showSuccess();
}
});
PostUtil.postCallbackDelayed(loadService, EmptyCallback.class, 1200);
}
```

If you have a better idea, please let me know. I'm very interested to improve LoadSir in any way. Thanks for your help.
Expand Down

0 comments on commit fccf574

Please sign in to comment.