-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
puy
committed
Aug 19, 2019
1 parent
3165f7c
commit c3f858e
Showing
1 changed file
with
163 additions
and
0 deletions.
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
puymvpjava/src/main/java/com/android/puy/puymvpjava/mvp/XBackFragmentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package com.android.puy.puymvpjava.mvp; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import androidx.annotation.Nullable; | ||
import butterknife.Unbinder; | ||
import com.android.puy.puymvpjava.XDroidConf; | ||
import com.android.puy.puymvpjava.customs.material.MaterialRippleLayout; | ||
import com.android.puy.puymvpjava.event.BusProvider; | ||
import com.android.puy.puymvpjava.kit.KnifeKit; | ||
import com.tbruyelle.rxpermissions2.RxPermissions; | ||
import me.yokeyword.fragmentation_swipeback.SwipeBackFragment; | ||
import org.greenrobot.eventbus.EventBus; | ||
|
||
|
||
public abstract class XBackFragmentation<P extends IPresent> extends SwipeBackFragment implements IView<P> { | ||
|
||
private VDelegate vDelegate; | ||
private P p; | ||
protected Activity context; | ||
private View rootView; | ||
protected LayoutInflater layoutInflater; | ||
|
||
private RxPermissions rxPermissions; | ||
|
||
private Unbinder unbinder; | ||
|
||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
layoutInflater = inflater; | ||
if (rootView == null && getLayoutId() > 0) { | ||
rootView = inflater.inflate(getLayoutId(), null); | ||
bindUI(rootView); | ||
} else { | ||
ViewGroup viewGroup = (ViewGroup) rootView.getParent(); | ||
if (viewGroup != null) { | ||
viewGroup.removeView(rootView); | ||
} | ||
} | ||
return rootView; | ||
} | ||
|
||
|
||
@Override | ||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
if (useRxBus()) { | ||
BusProvider.getBus().register(this); | ||
} | ||
if (useEventBus()) { | ||
EventBus.getDefault().register(this); | ||
} | ||
bindEvent(); | ||
initData(savedInstanceState); | ||
} | ||
|
||
@Override | ||
public void bindUI(View rootView) { | ||
unbinder = KnifeKit.bind(this, rootView); | ||
} | ||
|
||
protected VDelegate getvDelegate() { | ||
if (vDelegate == null) { | ||
vDelegate = VDelegateBase.create(context); | ||
} | ||
return vDelegate; | ||
} | ||
|
||
protected P getP() { | ||
if (p == null) { | ||
p = newP(); | ||
if (p != null) { | ||
p.attachV(this); | ||
} | ||
} | ||
return p; | ||
} | ||
|
||
@Override | ||
public void onAttach(Context context) { | ||
super.onAttach(context); | ||
if (context instanceof Activity) { | ||
this.context = (Activity) context; | ||
} | ||
} | ||
|
||
@Override | ||
public void onDetach() { | ||
super.onDetach(); | ||
context = null; | ||
} | ||
|
||
@Override | ||
public boolean useEventBus() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean useRxBus() { | ||
return false; | ||
} | ||
|
||
|
||
@Override | ||
public void onDestroyView() { | ||
super.onDestroyView(); | ||
if (useRxBus()) { | ||
BusProvider.getBus().unregister(this); | ||
} | ||
if (useEventBus()) { | ||
EventBus.getDefault().unregister(this); | ||
} | ||
if (getP() != null) { | ||
getP().detachV(); | ||
} | ||
getvDelegate().destory(); | ||
|
||
p = null; | ||
vDelegate = null; | ||
} | ||
|
||
protected RxPermissions getRxPermissions() { | ||
rxPermissions = new RxPermissions(getActivity()); | ||
rxPermissions.setLogging(XDroidConf.DEV); | ||
return rxPermissions; | ||
} | ||
|
||
@Override | ||
public int getOptionsMenuId() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void bindEvent() { | ||
|
||
} | ||
|
||
public void setMaterialRipple(View... views) { | ||
for (View view : views) { | ||
MaterialRippleLayout.on(view) | ||
.rippleColor(Color.BLACK) | ||
.create(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onSupportVisible() { | ||
super.onSupportVisible(); | ||
//在onSupportVisible实现沉浸式 | ||
initImmersionBar(); | ||
} | ||
|
||
public void initImmersionBar() { | ||
} | ||
|
||
} |