Browse Source

Shoutbox improvements

pull/61/merge
Apostolos Fanakis 6 years ago
parent
commit
7199c982c6
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutAdapter.java
  2. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java
  3. 5
      app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java
  4. 1
      app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java
  5. 10
      app/src/main/res/layout/fragment_shoutbox.xml
  6. 22
      app/src/main/res/layout/fragment_shoutbox_shout_row.xml

2
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutAdapter.java

@ -48,7 +48,7 @@ public class ShoutAdapter extends CustomRecyclerView.Adapter<ShoutAdapter.ShoutV
@Override
public ShoutViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.shout, parent, false);
.inflate(R.layout.fragment_shoutbox_shout_row, parent, false);
return new ShoutViewHolder(view);
}

7
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java

@ -17,6 +17,7 @@ import gr.thmmy.mthmmy.editorview.EditorView;
import gr.thmmy.mthmmy.editorview.EmojiKeyboard;
import gr.thmmy.mthmmy.model.Shout;
import gr.thmmy.mthmmy.model.Shoutbox;
import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.CustomRecyclerView;
import gr.thmmy.mthmmy.utils.NetworkResultCodes;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
@ -57,7 +58,7 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
if (resultCode == NetworkResultCodes.SUCCESSFUL) {
editorView.getEditText().getText().clear();
shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished);
shoutboxTask.execute("https://www.thmmy.gr/smf/index.php?action=forum");
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show();
}
@ -90,14 +91,14 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
layoutManager.setReverseLayout(true);
recyclerView.setLayoutManager(layoutManager);
shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished);
shoutboxTask.execute("https://www.thmmy.gr/smf/index.php?action=forum");
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
swipeRefreshLayout = rootView.findViewById(R.id.swiperefresh);
swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.primary);
swipeRefreshLayout.setColorSchemeResources(R.color.accent);
swipeRefreshLayout.setOnRefreshListener(() -> {
shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished);
shoutboxTask.execute("https://www.thmmy.gr/smf/index.php?action=forum");
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
});
emojiKeyboard = rootView.findViewById(R.id.emoji_keyboard);

5
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java

@ -21,8 +21,8 @@ public class ShoutboxTask extends NewParseTask<Shoutbox> {
@Override
protected Shoutbox parse(Document document, Response response) throws ParseException {
// shout container: document.select("div[class=smalltext]" && div.text().contains("Τελευταίες 75 φωνές:") η στα αγγλικα
Element shoutboxContainer = document.select("div[style=width: 99%; height: 600px; overflow: auto;]").first();
// fragment_shoutbox_shout_row container: document.select("div[class=smalltext]" && div.text().contains("Τελευταίες 75 φωνές:") η στα αγγλικα
Element shoutboxContainer = document.select("table.windowbg").first();
ArrayList<Shout> shouts = new ArrayList<>();
for (Element shout : shoutboxContainer.select("div[style=margin: 4px;]")) {
Element user = shout.child(0);
@ -35,6 +35,7 @@ public class ShoutboxTask extends NewParseTask<Shoutbox> {
String dateString = date.text();
Element content = shout.child(2);
content.removeAttr("style");
String shoutContent = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" +
ParseHelpers.youtubeEmbeddedFix(content);
shouts.add(new Shout(profileName, profileUrl, dateString, shoutContent, memberOfTheMonth));

1
app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java

@ -37,6 +37,7 @@ public class SessionManager {
public static final HttpUrl forumUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=forum;theme=4");
private static final HttpUrl loginUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=login2");
public static final HttpUrl unreadUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=unread;all;start=0;theme=4");
public static final HttpUrl shoutboxUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=tpmod;sa=shoutbox;theme=4");
private static final String guestName = "Guest";
//Response Codes

10
app/src/main/res/layout/fragment_shoutbox.xml

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@ -27,7 +26,7 @@
android:id="@+id/shoutbox_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/shout"/>
tools:listitem="@layout/fragment_shoutbox_shout_row" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
@ -36,7 +35,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"/>
android:layout_marginEnd="8dp"
android:paddingTop="8dp" />
<gr.thmmy.mthmmy.editorview.EmojiKeyboard
android:id="@+id/emoji_keyboard"

22
app/src/main/res/layout/shout.xml → app/src/main/res/layout/fragment_shoutbox_shout_row.xml

@ -1,14 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:foreground="?android:attr/selectableItemBackground"
android:orientation="vertical"
card_view:cardBackgroundColor="@color/card_background"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="2dp"
@ -19,15 +18,17 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/author_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textColor="@color/accent"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="1"
android:paddingTop="9dp"
android:textColor="@color/accent"
android:textStyle="bold"
tools:text="author" />
<TextView
@ -35,18 +36,18 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textSize="11sp"
android:textColor="@color/primary_text"
android:textSize="11sp"
tools:text="date &amp; time" />
<View
android:id="@+id/header_body_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="9dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="5dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="9dp"
android:background="@color/divider" />
<WebView
@ -59,8 +60,13 @@
android:background="@color/card_background"
android:clickable="true"
android:focusable="true"
android:scrollbars="none"
android:text="@string/post"
tools:ignore="WebViewLayout" />
<View
android:layout_width="match_parent"
android:layout_height="9dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
Loading…
Cancel
Save