From 03cc7ec475ba55d8d0fe05f5e2117eb8f9ce592b Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sun, 22 Jan 2017 23:05:48 +0200 Subject: [PATCH] User profile dot sign --- .../activities/profile/ProfileActivity.java | 41 +++++++++++++++---- .../profile/summary/SummaryFragment.java | 2 + .../mthmmy/utils/CenterVerticalSpan.java | 20 +++++++++ .../main/res/layout-v21/activity_profile.xml | 1 + app/src/main/res/layout/activity_profile.xml | 1 + app/src/main/res/values/strings.xml | 1 + 6 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java index 19c63ea9..60fea8d3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java @@ -1,6 +1,8 @@ package gr.thmmy.mthmmy.activities.profile; import android.content.Intent; +import android.graphics.Color; +import android.graphics.Typeface; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -12,7 +14,11 @@ import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.content.res.ResourcesCompat; import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; -import android.util.Log; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.Spanned; +import android.text.style.ForegroundColorSpan; +import android.text.style.RelativeSizeSpan; import android.view.View; import android.widget.ImageView; import android.widget.ProgressBar; @@ -24,6 +30,7 @@ import com.squareup.picasso.Picasso; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import java.util.ArrayList; import java.util.List; @@ -39,6 +46,7 @@ import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.ThmmyPage; +import gr.thmmy.mthmmy.utils.CenterVerticalSpan; import gr.thmmy.mthmmy.utils.CircleTransform; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import mthmmy.utils.Report; @@ -128,6 +136,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment .transform(new CircleTransform()) .into(thumbnailView); usernameView = (TextView) findViewById(R.id.profile_activity_username); + usernameView.setTypeface(Typeface.createFromAsset(this.getAssets() + , "fonts/fontawesome-webfont.ttf")); if (username != null && !Objects.equals(username, "")) usernameView.setText(username); personalTextView = (TextView) findViewById(R.id.profile_activity_personal_text); @@ -217,6 +227,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment @SuppressWarnings("unused") private static final String TAG = "ProfileTask"; //Separate tag for AsyncTask Document profilePage; + Spannable usernameSpan; protected void onPreExecute() { progressBar.setVisibility(ProgressBar.VISIBLE); @@ -232,16 +243,14 @@ 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)"); + //Finds username if missing if (username == null || Objects.equals(username, "")) { - username = profilePage. - select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) 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 - Element profileAvatar = profilePage - .select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) img.avatar") - .first(); + Element profileAvatar = contentsTable.select("img.avatar").first(); if (profileAvatar != null) thumbnailUrl = profileAvatar.attr("abs:src"); } { //Finds personal text @@ -255,6 +264,21 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment personalText = null; } } + { //Finds status + usernameSpan = new SpannableString(getResources() + .getString(R.string.fa_circle) + " " + username); + usernameSpan.setSpan(new CenterVerticalSpan(), 0, 2, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + usernameSpan.setSpan(new RelativeSizeSpan(0.45f) + , 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + if (contentsTable.toString().contains("Online") + || contentsTable.toString().contains("Συνδεδεμένος")) { + usernameSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#4CAF50")) + , 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } else + usernameSpan.setSpan(new ForegroundColorSpan(Color.GRAY) + , 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } return true; } catch (SSLHandshakeException e) { Report.w(TAG, "Certificate problem (please switch to unsafe connection)."); @@ -275,7 +299,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(true); progressBar.setVisibility(ProgressBar.INVISIBLE); - if (usernameView.getText() != username) usernameView.setText(username); + if (usernameSpan != null) usernameView.setText(usernameSpan); + else if (usernameView.getText() != username) usernameView.setText(username); if (thumbnailUrl != null && !Objects.equals(thumbnailUrl, "")) //noinspection ConstantConditions Picasso.with(getApplicationContext()) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java index 1236b5a0..a2a0eea9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java @@ -148,6 +148,8 @@ public class SummaryFragment extends Fragment { if (summaryRow.select("td").size() == 1) //Horizontal rule rows pHtml = ""; + else if (summaryRow.text().contains("Current Status") + || summaryRow.text().contains("Κατάσταση")) continue; else if (rowText.contains("Signature") || rowText.contains("Υπογραφή")) { //This needs special handling since it may have css pHtml = ParseHelpers.youtubeEmbeddedFix(summaryRow); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java new file mode 100644 index 00000000..949a9736 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java @@ -0,0 +1,20 @@ +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() { + } + + @Override + public void updateDrawState(TextPaint textPaint) { + textPaint.baselineShift -= 7f; + } + + @Override + public void updateMeasureState(TextPaint tp) { + updateDrawState(tp); + } +} \ No newline at end of file diff --git a/app/src/main/res/layout-v21/activity_profile.xml b/app/src/main/res/layout-v21/activity_profile.xml index 44f5917b..21a187bd 100644 --- a/app/src/main/res/layout-v21/activity_profile.xml +++ b/app/src/main/res/layout-v21/activity_profile.xml @@ -68,6 +68,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" + android:paddingBottom="2dp" android:text="@string/username" android:textColor="@color/accent" android:textSize="25sp"/> diff --git a/app/src/main/res/layout/activity_profile.xml b/app/src/main/res/layout/activity_profile.xml index be02134e..81b3aea7 100644 --- a/app/src/main/res/layout/activity_profile.xml +++ b/app/src/main/res/layout/activity_profile.xml @@ -67,6 +67,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" + android:paddingBottom="2dp" android:text="@string/username" android:textColor="@color/accent" android:textSize="25sp"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1640a038..dffad4fe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -85,4 +85,5 @@ +