Browse Source

Profile fixes and additions.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
1e17210321
  1. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  2. 12
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java
  3. 25
      app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java

10
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java

@ -19,6 +19,7 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan; import android.text.style.RelativeSizeSpan;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -243,14 +244,15 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
profilePage = Jsoup.parse(response.body().string()); profilePage = Jsoup.parse(response.body().string());
Elements contentsTable = profilePage.select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2)"); Elements contentsTable = profilePage.
select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tbody");
//Finds username if missing //Finds username if missing
if (username == null || Objects.equals(username, "")) { if (username == null || Objects.equals(username, "")) {
username = contentsTable.select("tr").first().select("td").last().text(); username = contentsTable.select("tr").first().select("td").last().text();
} }
if (thumbnailUrl == null || Objects.equals(thumbnailUrl, "")) { //Maybe there is an avatar if (thumbnailUrl == null || Objects.equals(thumbnailUrl, "")) { //Maybe there is an avatar
Element profileAvatar = contentsTable.select("img.avatar").first(); Element profileAvatar = profilePage.select("img.avatar").first();
if (profileAvatar != null) thumbnailUrl = profileAvatar.attr("abs:src"); if (profileAvatar != null) thumbnailUrl = profileAvatar.attr("abs:src");
} }
{ //Finds personal text { //Finds personal text
@ -291,8 +293,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
if (!result) { //Parse failed! if (!result) { //Parse failed!
Report.d(TAG, "Parse failed!"); Report.d(TAG, "Parse failed!");
Toast.makeText(getBaseContext() Toast.makeText(getBaseContext(), "Fatal error!\n Aborting..."
, "Fatal error!\n Aborting...", Toast.LENGTH_LONG).show(); , Toast.LENGTH_LONG).show();
finish(); finish();
} }
//Parse was successful //Parse was successful

12
app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java

@ -6,6 +6,8 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -189,6 +191,16 @@ public class SummaryFragment extends Fragment {
} }
TextView entry = new TextView(this.getContext()); TextView entry = new TextView(this.getContext());
if (profileSummaryRow.contains("@") &&
(profileSummaryRow.contains("Email") || profileSummaryRow.contains("E-mail"))) {
Log.d(TAG, "mpika");
Log.d(TAG, profileSummaryRow);
String email = profileSummaryRow.substring(profileSummaryRow.indexOf(":</b> ") + 6);
profileSummaryRow = profileSummaryRow.replace(email,
"<a href=\"mailto:" + email + "\">" + email + "</a>");
entry.setMovementMethod(LinkMovementMethod.getInstance());
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
entry.setTextColor(getResources().getColor(R.color.primary_text, null)); entry.setTextColor(getResources().getColor(R.color.primary_text, null));
else else

25
app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java

@ -1,20 +1,23 @@
package gr.thmmy.mthmmy.utils; package gr.thmmy.mthmmy.utils;
import android.text.TextPaint; import android.graphics.Canvas;
import android.text.style.SuperscriptSpan; import android.graphics.Paint;
import android.util.Log; import android.graphics.Rect;
import android.support.annotation.NonNull;
public class CenterVerticalSpan extends SuperscriptSpan { import android.text.style.ReplacementSpan;
public CenterVerticalSpan() {
}
public class CenterVerticalSpan extends ReplacementSpan {
@Override @Override
public void updateDrawState(TextPaint textPaint) { public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
textPaint.baselineShift -= 7f; text = text.subSequence(start, end);
return (int) paint.measureText(text.toString());
} }
@Override @Override
public void updateMeasureState(TextPaint tp) { public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
updateDrawState(tp); text = text.subSequence(start, end);
Rect charSize = new Rect();
paint.getTextBounds(text.toString(), 0, 1, charSize);
canvas.drawText(text.toString(), x, (bottom + charSize.height()) / 2f, paint);
} }
} }
Loading…
Cancel
Save