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.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
@ -243,14 +244,15 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
try {
Response response = client.newCall(request).execute();
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
if (username == null || Objects.equals(username, "")) {
username = contentsTable.select("tr").first().select("td").last().text();
}
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");
}
{ //Finds personal text
@ -291,8 +293,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
protected void onPostExecute(Boolean result) {
if (!result) { //Parse failed!
Report.d(TAG, "Parse failed!");
Toast.makeText(getBaseContext()
, "Fatal error!\n Aborting...", Toast.LENGTH_LONG).show();
Toast.makeText(getBaseContext(), "Fatal error!\n Aborting..."
, Toast.LENGTH_LONG).show();
finish();
}
//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.support.v4.app.Fragment;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -189,6 +191,16 @@ public class SummaryFragment extends Fragment {
}
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)
entry.setTextColor(getResources().getColor(R.color.primary_text, null));
else

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

@ -1,20 +1,23 @@
package gr.thmmy.mthmmy.utils;
import android.text.TextPaint;
import android.text.style.SuperscriptSpan;
import android.util.Log;
public class CenterVerticalSpan extends SuperscriptSpan {
public CenterVerticalSpan() {
}
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.text.style.ReplacementSpan;
public class CenterVerticalSpan extends ReplacementSpan {
@Override
public void updateDrawState(TextPaint textPaint) {
textPaint.baselineShift -= 7f;
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
text = text.subSequence(start, end);
return (int) paint.measureText(text.toString());
}
@Override
public void updateMeasureState(TextPaint tp) {
updateDrawState(tp);
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
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