Last active
August 29, 2015 14:11
-
-
Save px-amaac/a50aa1b6fdd359e347c9 to your computer and use it in GitHub Desktop.
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
public class FeaturedFragment extends BaseStaggeredGridFragment<Offer> { | |
private static final String TAG = FeaturedFragment.class.getSimpleName(); | |
private static final String SAVED_BANNER_TAG = FeaturedFragment.class.getSimpleName() + "_BANNER"; | |
public static final int POSITION = 0; | |
private Market mMarket; | |
private View mHeader = null; | |
private WebView mWebView; | |
public static FeaturedFragment newInstance(Market market) { | |
FeaturedFragment newFrag = new FeaturedFragment(); | |
Bundle args = new Bundle(); | |
args.putParcelable(MARKET_DATA_KEY, market); | |
newFrag.setArguments(args); | |
return newFrag; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View root = super.onCreateView(inflater, container, savedInstanceState); | |
if(mAdapter == null) { | |
mAdapter = new StaggeredBaseAdapter<Offer>(getActivity(), Picasso.with(getActivity()), R.layout.offer_leaf ); | |
} | |
mHeader = inflater.inflate(R.layout.featured_header, null); | |
mWebView = (WebView) mHeader.findViewById(R.id.banner_web_view); | |
mGridView.addHeaderView(mHeader); | |
setupBannerWebView(); | |
mWebView.loadUrl(NotificationHelper.appendContextParamsForCampaign(getActivity(), getActivity().getString(R.string.banner_url))); | |
url = mWebView.getUrl(); | |
mGridView.setAdapter(mAdapter); | |
url = mWebView.getUrl(); | |
mAppState = getResources().getStringArray(R.array.main_activity_tracking)[POSITION]; | |
mTabPosition = POSITION; | |
return root; | |
} | |
@Override | |
public void onPause() { | |
super.onPause(); | |
mWebView.onPause(); | |
} | |
@Override | |
public void onResume() { | |
mWebView.onResume(); | |
super.onResume(); | |
Bundle bundle = getArguments(); | |
mMarket = bundle.getParcelable(MARKET_DATA_KEY); | |
if(mMarket != null) { | |
if (mData != null && !mData.isEmpty()) { | |
checkAdapter(); | |
} else if(!mHasRequestedMore) { | |
offset = 0; | |
featuredAPICall(offset); | |
mHasRequestedMore = true; | |
} | |
} | |
} | |
@Override | |
public void onDestroy() { | |
if (mWebView != null) { | |
mWebView.destroy(); | |
mWebView = null; | |
} | |
super.onDestroy(); | |
} | |
private void setupBannerWebView() { | |
WebSettings settings = mWebView.getSettings(); | |
settings.setLoadsImagesAutomatically(true); | |
settings.setJavaScriptEnabled(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment