private void setInfo(JSONObject json) { try { if (json == null) { String data = BLSharePreferences.getUserInfo(context); json = new JSONObject(data); } Log.i(TAG, "setInfo:" + json.toString()); lblName.setText(json.optString("Nickname")); tvTitlebar.setText(json.optString("Nickname")); // lblAge.setText(", " + json.optString("age")); lblAge.setText(", " + getAge(Long.valueOf(json.optString("Birthday")) * 1000)); String description = json.optString(Prefs.Summary); lblDescription.setText( (description == null || description.equals("null")) ? "" : description); String nationality = json.optString(Prefs.Nationality, null); if (nationality != null && countryDB.containsId(nationality)) { Country c = countryDB.getCountryByCode(nationality); lblNation.setText(c.Country); picasso.load(c.Flag).into(imageFrag); } String urlAvatar = json.optString(Prefs.Avatar, null); if (urlAvatar != null) picasso.load(urlAvatar).placeholder(R.drawable.ic_avatar_traveler).into(ivAvatar); } catch (Exception e) { Logs.log(e); } }
@Override public View getView(final int position, View convertView, ViewGroup parent) { final ViewHolder vh; if (convertView == null) { View view = mInflater.inflate(R.layout.item_my_article, parent, false); vh = ViewHolder.create(view); view.setTag(vh); } else { vh = (ViewHolder) convertView.getTag(); } final Article item = objects.get(position); try { vh.lblName.setText(item.AuthorID.Nickname); vh.lblAge.setText(", " + item.AuthorID.age); // vh.lblNumberFollower.setText(item.AuthorID.follower + " followers"); vh.lblNumberFollower.setText( item.AuthorID.follower + " follower" + (item.AuthorID.follower > 1 ? "s" : "")); vh.lblContent.setText(item.ArticleText); imageLoader.displayImage(item.AuthorID.Avatar, vh.icon, options); vh.lblTitle.setText(item.Title); // vh.lblTip.setText("Tip " + (position + 1) + " out of " + // item.Collection.ArticleCountTip + ","); vh.lblTip.setText("Tip " + (position + 1) + " out of " + objects.size() + ","); vh.lblCollection.setText(item.Collection.Name); vh.lblTime.setText( DateUtils.formatTimeStamp(item.Date_modified * 1000, Contains.FORMAT_TIME)); } catch (Exception e) { Logs.log(e); } vh.buttonEdit.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, AddTipActivity.class); intent.putExtra(Contains.PARAM_ARTICLE, item.toJSON()); intent.putExtra(Contains.PARAM_EDIT, true); ((HomeActivity) context).startActivityForResult(intent, Contains.REQUEST_EDIT); } }); vh.buttonShare.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, item.Title); intent.putExtra(Intent.EXTRA_TEXT, item.ArticleText); context.startActivity( Intent.createChooser(intent, context.getString(R.string.app_name))); } }); return vh.rootView; }
public Country getCountryByCode(String id) { String QUERY = "SELECT * FROM " + TAG_TABLE_NAME + " WHERE " + KEY_ID + " = '" + id + "'"; Cursor cursor = db.rawQuery(QUERY, null); Country c = new Country(); try { if (cursor != null) cursor.moveToFirst(); c.PhoneCode = cursor.getString(cursor.getColumnIndex(KEY_PHONE_CODE)); c.Flag = cursor.getString(cursor.getColumnIndex(KEY_FLAG)); c.Country = cursor.getString(cursor.getColumnIndex(KEY_COUNTRY)); return c; } catch (Exception e) { Logs.log(e); } return null; }
private void requestGetUserInfo() { CallService customPost = new CallService( CallMethod.POST, "getUserInfo", mActivity.getUserId(), mActivity.getToken(), mActivity.getDeviceId(), mActivity.getVersion(), mActivity.getLocale(), new JsonCallBackListener() { @Override public void handleData(String mCmd, JSONObject json) throws JSONException { // if (mActivity != null) { // mActivity.hideLoading(); // } if (json != null) { int status = json.getInt("StatusCode"); if (status == 1) { JSONObject userInfo = json.getJSONArray("Data").getJSONObject(0); BLSharePreferences.setUserInfo(context, userInfo.toString()); setInfo(userInfo); sendBroadcastUpdateProfile(); } } hideLoading(); } }); try { String url = Webservice.makeGetProfileURL(userID); customPost.execute(url); } catch (Exception e) { hideLoading(); Logs.log(e); // if (mActivity != null) { // mActivity.hideLoading(); // } } }