/** * Tries to get the info of the group from the db, if there isn't info, makes a request to the * 'google+ people' api to retrieve te about info of the gdg g+ profile and save it in the app db. */ private void initApi() { dbHandler = new DBHandler(getActivity()); try { GroupInfo groupInfo = dbHandler.getAllElements(GroupInfo.class, null, null, false).get(0); if (baseLayout.getVisibility() == View.GONE) baseLayout.setVisibility(View.VISIBLE); fillAboutUIElements(groupInfo); Url[] urls = (Url[]) dbHandler.getAllElements(Url.class, null, null, false).toArray(); fillUrlsLayout(urls); } catch (IndexOutOfBoundsException e) { ApiHandler apiHandler = new ApiHandler(getActivity()); apiHandler.getGdgAboutInfo(plusPersonData); d("[DEBUG] fucverg.saulmm.gdg.gui.fragments.GroupFragment.initApi ", "Making request..."); progressBarSpinner.setVisibility(View.VISIBLE); } }
/** * Parse a html tag <a href="www.example.com">example</a> and linkifies to 'example' then put that * text in a text view and appends it to the ulr viewgroup. * * @param urls: urls to linkify. */ private void fillUrlsLayout(Url[] urls) { if (getActivity() != null) { for (Url link : urls) { String url = "<a href=\"" + link.getValue() + "\"> - " + link.getLabel() + "</a>\n"; TextView urlTextView = new TextView(getActivity()); urlTextView.setText(Html.fromHtml(url)); urlTextView.setMovementMethod(LinkMovementMethod.getInstance()); urlTextView.setTextAppearance(getActivity(), R.style.LinkStyle); groupURLLayout.addView(urlTextView, GuiUtils.getLinkParams()); Url urlEnt = new Url(); urlEnt.setGroup_id(Configuration.GROUP_ID); urlEnt.setLabel(link.getLabel()); urlEnt.setValue(link.getValue()); dbHandler.insertElement(Url.class, urlEnt.getFields()); } } }
@Override public void onCompleted(Exception e, PlusPerson plusPerson) { progressBarSpinner.setVisibility(View.GONE); d( "[DEBUG] fucverg.saulmm.gdg.gui.fragments.GroupFragment.onCompleted ", "Posts completed..."); if (plusPerson != null) { baseLayout.setVisibility(View.VISIBLE); scrollView.setVisibility(View.VISIBLE); errorLayout.setVisibility(View.INVISIBLE); String content = plusPerson.getAboutMe().replaceAll("<br />", ""); fillUrlsLayout(plusPerson.getUrls()); GroupInfo apiGroupInfo = new GroupInfo(); apiGroupInfo.setAbout(content); apiGroupInfo.setId(plusPerson.getId()); apiGroupInfo.setTagLine(plusPerson.getTagline()); apiGroupInfo.setName(plusPerson.getDisplayName()); fillAboutUIElements(apiGroupInfo); dbHandler.insertElement(GroupInfo.class, apiGroupInfo.getFields()); } else { e( "[ERROR] fucverg.saulmm.gdg.gui.fragments.AboutFragment.onCompleted ", "Error retrieving the gdg about data."); errorLayout.setVisibility(View.VISIBLE); scrollView.setVisibility(View.INVISIBLE); GuiUtils.showShortToast(getActivity(), "No hay red"); } }