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 f7aa90ee..8ce5d4fc 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 @@ -4,13 +4,16 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v4.content.res.ResourcesCompat; import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; import android.text.Html; +import android.util.Log; import android.view.View; +import android.webkit.WebView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; @@ -66,15 +69,15 @@ public class ProfileActivity extends BaseActivity { PACKAGE_NAME = getApplicationContext().getPackageName(); Bundle extras = getIntent().getExtras(); - //username = getIntent().getExtras().getString("TOPIC_TITLE"); //Initialize toolbar, drawer and ProgressBar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(null); setSupportActionBar(toolbar); - getSupportActionBar().setDisplayShowTitleEnabled(false); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayShowTitleEnabled(false); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } createDrawer(); @@ -148,8 +151,7 @@ public class ProfileActivity extends BaseActivity { protected Boolean doInBackground(String... strings) { Document document; - String pageUrl = strings[0]; //This page's url - + String pageUrl = strings[0] + ";wap"; //Profile's page wap url Request request = new Request.Builder() .url(pageUrl) @@ -184,6 +186,7 @@ public class ProfileActivity extends BaseActivity { private void populateLayout() { if (parsedProfileData.get(THUMBNAIL_URL) != null) + //noinspection ConstantConditions Picasso.with(this) .load(parsedProfileData.get(THUMBNAIL_URL)) .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) @@ -194,7 +197,9 @@ public class ProfileActivity extends BaseActivity { , R.drawable.ic_default_user_thumbnail, null)) .transform(new CircleTransform()) .into(userThumbnail); + userName.setText(parsedProfileData.get(NAME_INDEX)); + if (parsedProfileData.get(PERSONAL_TEXT_INDEX) != null) { personalText.setVisibility(View.VISIBLE); personalText.setText(parsedProfileData.get(PERSONAL_TEXT_INDEX)); @@ -202,11 +207,30 @@ public class ProfileActivity extends BaseActivity { personalText.setVisibility(View.GONE); } - for (int i = PERSONAL_TEXT_INDEX; i < parsedProfileData.size(); ++i) { + for (int i = PERSONAL_TEXT_INDEX + 1; i < parsedProfileData.size(); ++i) { + if (parsedProfileData.get(i).contains("Signature") + || parsedProfileData.get(i).contains("Υπογραφή")) { + WebView signatureEntry = new WebView(this); + signatureEntry.loadDataWithBaseURL("file:///android_asset/", parsedProfileData.get(i), "text/html", "UTF-8", null); + } TextView entry = new TextView(this); - entry.setTextColor(getResources().getColor(R.color.primary_text)); - entry.setText(Html.fromHtml(parsedProfileData.get(i))); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + entry.setTextColor(getResources().getColor(R.color.primary_text, null)); + } else { + //noinspection deprecation + entry.setTextColor(getResources().getColor(R.color.primary_text)); + + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + entry.setText(Html.fromHtml(parsedProfileData.get(i), Html.FROM_HTML_MODE_LEGACY)); + } else { + //noinspection deprecation + entry.setText(Html.fromHtml(parsedProfileData.get(i))); + } + mainContent.addView(entry); + Log.d(TAG, "new: " + parsedProfileData.get(i)); } } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileParser.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileParser.java index 29a7e934..adffccc8 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileParser.java @@ -10,10 +10,6 @@ import java.util.Objects; import mthmmy.utils.Report; class ProfileParser { - //Parsing variables - private static String nameSelect; - private static String signatureSelect; - //Other variables @SuppressWarnings("unused") private static final String TAG = "ProfileParser"; @@ -22,13 +18,11 @@ class ProfileParser { static final int PERSONAL_TEXT_INDEX = 2; static ArrayList parseProfile(Document doc) { - defineLanguage(doc); - //Method's variables ArrayList returnArray = new ArrayList<>(); //Contains all summary's rows - Elements summaryRows = doc.select("td.windowbg:nth-child(1)"); + Elements summaryRows = doc.select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tr"); { //Find thumbnail url Element tmpEl = doc.select(".bordercolor img.avatar").first(); @@ -39,7 +33,7 @@ class ProfileParser { } { //Find username - Element tmpEl = summaryRows.select("tr:contains(" + nameSelect + ")").first(); + Element tmpEl = summaryRows.first(); if (tmpEl != null) { returnArray.add(NAME_INDEX, tmpEl.select("td").get(1).text()); } else { @@ -54,40 +48,52 @@ class ProfileParser { returnArray.add(PERSONAL_TEXT_INDEX, tmpPersonalText); } - for (Element row : summaryRows.select("tr")) { - String rowText = row.text(), tmpHtml = ""; + for (Element row : summaryRows) { + String rowText = row.text(), pHtml = ""; if (row.select("td").size() == 1) - tmpHtml = ""; - else if (rowText.contains(signatureSelect)) { - tmpHtml = row.html(); - } else if (!rowText.contains(nameSelect)) { + pHtml = ""; + else if (rowText.contains("Signature") || rowText.contains("Υπογραφή")) { + { //Fix embedded videos + Elements noembedTag = row.select("noembed"); + ArrayList embededVideosUrls = new ArrayList<>(); + + for (Element _noembed : noembedTag) { + embededVideosUrls.add(_noembed.text().substring(_noembed.text() + .indexOf("href=\"https://www.youtube.com/watch?") + 38 + , _noembed.text().indexOf("target") - 2)); + } + + pHtml = row.html(); + + int tmp_counter = 0; + while (pHtml.contains(" embededVideosUrls.size()) + break; + pHtml = pHtml.replace( + pHtml.substring(pHtml.indexOf("") + 9) + , "
" + + "" + + "\"\"" + + "" + //+ "" + + "
"); + } + } + + //Add stuff to make it work in WebView + //style.css + pHtml = ("" + pHtml); + } else if (!rowText.contains("Name") && !rowText.contains("Όνομα")) { if (Objects.equals(row.select("td").get(1).text(), "")) continue; - tmpHtml = "" + row.select("td").first().text() + " " + pHtml = "" + row.select("td").first().text() + " " + row.select("td").get(1).text(); } - returnArray.add(tmpHtml); + returnArray.add(pHtml); } return returnArray; } - - private static void defineLanguage(Document doc) { - //English parsing variables - final String en_nameSelect = "Name"; - final String en_signatureSelect = "Signature"; - - //Greek parsing variables - final String gr_nameSelect = "Όνομα"; - final String gr_signatureSelect = "Υπογραφή"; - - if (doc.select("h3").text().contains("Καλώς ορίσατε")) { - nameSelect = gr_nameSelect; - signatureSelect = gr_signatureSelect; - - } else { //Default is english (eg. guest's language) - nameSelect = en_nameSelect; - signatureSelect = en_signatureSelect; - } - } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index 23e613d1..a3148293 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -52,7 +52,7 @@ import static gr.thmmy.mthmmy.session.SessionManager.LOGIN_STATUS; @SuppressWarnings("unchecked") public class TopicActivity extends BaseActivity { -//-----------------------------------------CLASS VARIABLES------------------------------------------ + //-----------------------------------------CLASS VARIABLES------------------------------------------ private TopicTask topicTask; /* --Posts-- */ @@ -106,8 +106,10 @@ public class TopicActivity extends BaseActivity { toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(topicTitle); setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setDisplayShowHomeEnabled(true); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + } createDrawer(); @@ -207,7 +209,7 @@ public class TopicActivity extends BaseActivity { @Override protected void onDestroy() { super.onDestroy(); - if(topicTask!=null&&topicTask.getStatus()!= AsyncTask.Status.RUNNING) + if (topicTask != null && topicTask.getStatus() != AsyncTask.Status.RUNNING) topicTask.cancel(true); } @@ -314,7 +316,7 @@ public class TopicActivity extends BaseActivity { private void changePage(int pageRequested) { if (pageRequested != thisPage - 1) { - if(topicTask!=null&&topicTask.getStatus()!= AsyncTask.Status.RUNNING) + if (topicTask != null && topicTask.getStatus() != AsyncTask.Status.RUNNING) topicTask.cancel(true); topicTask = new TopicTask(); @@ -324,7 +326,7 @@ public class TopicActivity extends BaseActivity { } //------------------------------------BOTTOM NAV BAR METHODS END------------------------------------ -//---------------------------------------TOPIC ASYNC TASK------------------------------------------- + //---------------------------------------TOPIC ASYNC TASK------------------------------------------- public class TopicTask extends AsyncTask { //Class variables private static final String TAG = "TopicTask"; //Separate tag for AsyncTask @@ -364,7 +366,7 @@ public class TopicActivity extends BaseActivity { parse(document); //Parse data return SUCCESS; } catch (IOException e) { - Report.i(TAG, "IO Exception",e); + Report.i(TAG, "IO Exception", e); return NETWORK_ERROR; } catch (Exception e) { Report.e(TAG, "Exception", e); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index fd7cf4d4..7e973ff3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -196,7 +196,11 @@ class TopicAdapter extends RecyclerView.Adapter { if (currentPost.getAttachedFiles().size() != 0) { holder.bodyFooterDivider.setVisibility(View.VISIBLE); - int filesTextColor = context.getResources().getColor(R.color.accent); + int filesTextColor = 0; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { + filesTextColor = context.getResources().getColor(R.color.accent, null); + } else //noinspection deprecation + filesTextColor = context.getResources().getColor(R.color.accent); for (final String[] attachedFile : currentPost.getAttachedFiles()) { final TextView attached = new TextView(context); @@ -297,7 +301,7 @@ class TopicAdapter extends RecyclerView.Adapter { intent.setFlags(FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); //((Activity) context).overridePendingTransition( - //R.anim.push_right_in, R.anim.push_left_out); + //R.anim.push_right_in, R.anim.push_left_out); } //Change post's viewProperties accordingly @@ -500,6 +504,7 @@ class TopicAdapter extends RecyclerView.Adapter { } //Handle url clicks + @SuppressWarnings("SameReturnValue") private boolean handleUri(final Uri uri) { //Method always returns true as we don't want any url to be loaded in WebViews diff --git a/app/src/main/res/drawable/ic_add_fab.xml b/app/src/main/res/drawable/ic_add_fab.xml index 91b1ae99..6b6146ec 100644 --- a/app/src/main/res/drawable/ic_add_fab.xml +++ b/app/src/main/res/drawable/ic_add_fab.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/app/src/main/res/drawable/ic_pm_fab.xml b/app/src/main/res/drawable/ic_pm_fab.xml new file mode 100644 index 00000000..efa4deda --- /dev/null +++ b/app/src/main/res/drawable/ic_pm_fab.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout-v21/activity_profile.xml b/app/src/main/res/layout-v21/activity_profile.xml new file mode 100644 index 00000000..41f9f8e4 --- /dev/null +++ b/app/src/main/res/layout-v21/activity_profile.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout-v21/activity_topic_post_row.xml b/app/src/main/res/layout-v21/activity_topic_post_row.xml new file mode 100644 index 00000000..6ba494ff --- /dev/null +++ b/app/src/main/res/layout-v21/activity_topic_post_row.xml @@ -0,0 +1,246 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_profile.xml b/app/src/main/res/layout/activity_profile.xml index 61058489..f2b7e281 100644 --- a/app/src/main/res/layout/activity_profile.xml +++ b/app/src/main/res/layout/activity_profile.xml @@ -42,7 +42,6 @@ android:contentDescription="@string/thumbnail" android:fitsSystemWindows="true" android:src="@drawable/ic_default_user_thumbnail" - android:transitionName="user_thumbnail" app:layout_collapseMode="parallax"/> + app:srcCompat="@drawable/ic_pm_fab"/> diff --git a/app/src/main/res/layout/activity_topic_post_row.xml b/app/src/main/res/layout/activity_topic_post_row.xml index c7ebf7c4..9e28f47b 100644 --- a/app/src/main/res/layout/activity_topic_post_row.xml +++ b/app/src/main/res/layout/activity_topic_post_row.xml @@ -1,10 +1,12 @@ + android:paddingStart="4dp" + tools:ignore="SmallSp"> + android:textSize="8sp"/> + android:src="@drawable/ic_default_user_thumbnail"/> #3C3F41 #8B8B8B - #00000000 #FFFFFF - #000000 #CCCCCC #E7E7E7 #80BF4040