Browse Source

User profile dot sign

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
03cc7ec475
  1. 41
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  2. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java
  3. 20
      app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java
  4. 1
      app/src/main/res/layout-v21/activity_profile.xml
  5. 1
      app/src/main/res/layout/activity_profile.xml
  6. 1
      app/src/main/res/values/strings.xml

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

@ -1,6 +1,8 @@
package gr.thmmy.mthmmy.activities.profile; package gr.thmmy.mthmmy.activities.profile;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; 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.content.res.ResourcesCompat;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar; 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.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -24,6 +30,7 @@ import com.squareup.picasso.Picasso;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.base.BaseActivity;
import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.PostSummary;
import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.ThmmyPage;
import gr.thmmy.mthmmy.utils.CenterVerticalSpan;
import gr.thmmy.mthmmy.utils.CircleTransform; import gr.thmmy.mthmmy.utils.CircleTransform;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import mthmmy.utils.Report; import mthmmy.utils.Report;
@ -128,6 +136,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
.transform(new CircleTransform()) .transform(new CircleTransform())
.into(thumbnailView); .into(thumbnailView);
usernameView = (TextView) findViewById(R.id.profile_activity_username); 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); if (username != null && !Objects.equals(username, "")) usernameView.setText(username);
personalTextView = (TextView) findViewById(R.id.profile_activity_personal_text); personalTextView = (TextView) findViewById(R.id.profile_activity_personal_text);
@ -217,6 +227,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final String TAG = "ProfileTask"; //Separate tag for AsyncTask private static final String TAG = "ProfileTask"; //Separate tag for AsyncTask
Document profilePage; Document profilePage;
Spannable usernameSpan;
protected void onPreExecute() { protected void onPreExecute() {
progressBar.setVisibility(ProgressBar.VISIBLE); progressBar.setVisibility(ProgressBar.VISIBLE);
@ -232,16 +243,14 @@ 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)");
//Finds username if missing //Finds username if missing
if (username == null || Objects.equals(username, "")) { if (username == null || Objects.equals(username, "")) {
username = profilePage. username = contentsTable.select("tr").first().select("td").last().text();
select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) 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 = profilePage Element profileAvatar = contentsTable.select("img.avatar").first();
.select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) 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
@ -255,6 +264,21 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
personalText = null; 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; return true;
} catch (SSLHandshakeException e) { } catch (SSLHandshakeException e) {
Report.w(TAG, "Certificate problem (please switch to unsafe connection)."); 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); if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(true);
progressBar.setVisibility(ProgressBar.INVISIBLE); 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, "")) if (thumbnailUrl != null && !Objects.equals(thumbnailUrl, ""))
//noinspection ConstantConditions //noinspection ConstantConditions
Picasso.with(getApplicationContext()) Picasso.with(getApplicationContext())

2
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 if (summaryRow.select("td").size() == 1) //Horizontal rule rows
pHtml = ""; pHtml = "";
else if (summaryRow.text().contains("Current Status")
|| summaryRow.text().contains("Κατάσταση")) continue;
else if (rowText.contains("Signature") || rowText.contains("Υπογραφή")) { else if (rowText.contains("Signature") || rowText.contains("Υπογραφή")) {
//This needs special handling since it may have css //This needs special handling since it may have css
pHtml = ParseHelpers.youtubeEmbeddedFix(summaryRow); pHtml = ParseHelpers.youtubeEmbeddedFix(summaryRow);

20
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);
}
}

1
app/src/main/res/layout-v21/activity_profile.xml

@ -68,6 +68,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:paddingBottom="2dp"
android:text="@string/username" android:text="@string/username"
android:textColor="@color/accent" android:textColor="@color/accent"
android:textSize="25sp"/> android:textSize="25sp"/>

1
app/src/main/res/layout/activity_profile.xml

@ -67,6 +67,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:paddingBottom="2dp"
android:text="@string/username" android:text="@string/username"
android:textColor="@color/accent" android:textColor="@color/accent"
android:textSize="25sp"/> android:textSize="25sp"/>

1
app/src/main/res/values/strings.xml

@ -85,4 +85,5 @@
<string name="fa_lock">&#xf023;</string> <string name="fa_lock">&#xf023;</string>
<string name="fa_sticky">&#xf249;</string> <string name="fa_sticky">&#xf249;</string>
<string name="fa_folder">&#xf07b;</string> <string name="fa_folder">&#xf07b;</string>
<string name="fa_circle">&#xf111;</string>
</resources> </resources>

Loading…
Cancel
Save