-
Notifications
You must be signed in to change notification settings - Fork 265
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
Showing
4 changed files
with
42 additions
and
40 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import android.support.annotation.LayoutRes; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.content.ContextCompat; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
@@ -15,45 +16,46 @@ | |
* Base fragment. | ||
* | ||
* @author JingYeoh | ||
* <a href="mailto:[email protected]">Email me</a> | ||
* <a href="https://github.com/justkiddingbaby">Github</a> | ||
* <a href="http://blog.justkiddingbaby.com">Blog</a> | ||
* <a href="mailto:[email protected]">Email me</a> | ||
* <a href="https://github.com/justkiddingbaby">Github</a> | ||
* <a href="http://blog.justkiddingbaby.com">Blog</a> | ||
* @since Nov 22,2017 | ||
*/ | ||
@Puppet | ||
public abstract class BaseFragment extends Fragment { | ||
|
||
protected static final String BUNDLE_KEY = "/bundle/key"; | ||
protected View mContentView; | ||
protected Context mContext; | ||
|
||
@Override | ||
public void onAttach(Context context) { | ||
super.onAttach(context); | ||
mContext = context; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
super.onCreateView(inflater, container, savedInstanceState); | ||
mContentView = inflater.inflate(getContentView(), container, false); | ||
return mContentView; | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
init(savedInstanceState); | ||
} | ||
|
||
@LayoutRes | ||
protected abstract int getContentView(); | ||
|
||
protected abstract void init(Bundle savedInstanceState); | ||
|
||
protected View findViewById(@IdRes int id) { | ||
return mContentView.findViewById(id); | ||
} | ||
protected static final String BUNDLE_KEY = "/bundle/key"; | ||
protected View mContentView; | ||
protected Context mContext; | ||
|
||
@Override | ||
public void onAttach(Context context) { | ||
super.onAttach(context); | ||
mContext = context; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
super.onCreateView(inflater, container, savedInstanceState); | ||
mContentView = inflater.inflate(getContentView(), container, false); | ||
mContentView.setBackgroundColor(ContextCompat.getColor(mContext, android.R.color.white)); | ||
return mContentView; | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
init(savedInstanceState); | ||
} | ||
|
||
@LayoutRes | ||
protected abstract int getContentView(); | ||
|
||
protected abstract void init(Bundle savedInstanceState); | ||
|
||
protected View findViewById(@IdRes int id) { | ||
return mContentView.findViewById(id); | ||
} | ||
} |
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