array) {
+ if (array.size() == 1 && array.get(0) == null) return -1;
+ if (!array.isEmpty()) {
+ for (int i = 0; i < array.size(); ++i) {
+ if (array.get(i) != null && Objects.equals(array.get(i).getId(), bookmark.getId())
+ && Objects.equals(array.get(i).getTitle(), bookmark.getTitle()))
+ return i;
+ }
+ }
+ return -1;
+ }
+//-------------------------------------------BOOKMARKS END------------------------------------------
}
diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java b/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java
new file mode 100644
index 00000000..88cc97d5
--- /dev/null
+++ b/app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java
@@ -0,0 +1,18 @@
+package gr.thmmy.mthmmy.model;
+
+public class Bookmark {
+ private final String title, id;
+
+ public Bookmark(String title, String id) {
+ this.title = title;
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getId() {
+ return id;
+ }
+}
diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java b/app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java
similarity index 77%
rename from app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java
rename to app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java
index 991c79bb..758f9765 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/model/LinkTarget.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java
@@ -11,7 +11,7 @@ import mthmmy.utils.Report;
* classes). It can be used to resolve link targets as to whether they are pointing to the forum and
* where in the forum they may point.
*/
-public class LinkTarget {
+public class ThmmyPage {
/**
* Debug Tag for logging debug output to LogCat
*/
@@ -32,7 +32,7 @@ public class LinkTarget {
* {@link #PROFILE}
*
*/
- public enum Target {
+ public enum PageCategory {
/**
* Link doesn't point to thmmy.
*/
@@ -87,7 +87,7 @@ public class LinkTarget {
DOWNLOADS;
/**
- * This method defines a custom equality check for {@link Target} enums. It does not check
+ * This method defines a custom equality check for {@link PageCategory} enums. It does not check
* whether a url is equal to another.
* Method returns true if parameter's Target is the same as the object and in the specific
* cases described below, false otherwise.
@@ -106,7 +106,7 @@ public class LinkTarget {
* @param other another Target
* @return true if enums are equal, false otherwise
*/
- public boolean is(Target other) {
+ public boolean is(PageCategory other) {
return ((this == PROFILE_LATEST_POSTS || this == PROFILE_STATS || this == PROFILE_SUMMARY)
&& other == PROFILE)
|| ((this == DOWNLOADS_FILE || this == DOWNLOADS_CATEGORY) && other == DOWNLOADS)
@@ -122,7 +122,7 @@ public class LinkTarget {
* @return true if url is pointing to thmmy, false otherwise
*/
public static boolean isThmmy(Uri uri) {
- return resolveLinkTarget(uri) != Target.NOT_THMMY;
+ return resolvePageCategory(uri) != PageCategory.NOT_THMMY;
}
/**
@@ -131,28 +131,43 @@ public class LinkTarget {
* @param uri url to resolve
* @return resolved target
*/
- public static Target resolveLinkTarget(Uri uri) {
+ public static PageCategory resolvePageCategory(Uri uri) {
final String host = uri.getHost();
final String uriString = uri.toString();
if (Objects.equals(host, "www.thmmy.gr")) {
- if (uriString.contains("topic=")) return Target.TOPIC;
- else if (uriString.contains("board=")) return Target.BOARD;
+ if (uriString.contains("topic=")) return PageCategory.TOPIC;
+ else if (uriString.contains("board=")) return PageCategory.BOARD;
else if (uriString.contains("action=profile")) {
if (uriString.contains(";sa=showPosts"))
- return Target.PROFILE_LATEST_POSTS;
+ return PageCategory.PROFILE_LATEST_POSTS;
else if (uriString.contains(";sa=statPanel"))
- return Target.PROFILE_STATS;
- else return Target.PROFILE_SUMMARY;
+ return PageCategory.PROFILE_STATS;
+ else return PageCategory.PROFILE_SUMMARY;
} else if (uriString.contains("action=unread"))
- return Target.UNREAD_POSTS;
+ return PageCategory.UNREAD_POSTS;
else if (uriString.contains("action=tpmod;dl=item"))
- return Target.DOWNLOADS_FILE;
+ return PageCategory.DOWNLOADS_FILE;
else if (uriString.contains("action=tpmod;dl"))
- return Target.DOWNLOADS_CATEGORY;
+ return PageCategory.DOWNLOADS_CATEGORY;
Report.v(TAG, "Unknown thmmy link found, link: " + uriString);
- return Target.UNKNOWN_THMMY;
+ return PageCategory.UNKNOWN_THMMY;
}
- return Target.NOT_THMMY;
+ return PageCategory.NOT_THMMY;
+ }
+
+ public static String getBoardId(String boardUrl) {
+ if (resolvePageCategory(Uri.parse(boardUrl)) == PageCategory.BOARD) {
+ return boardUrl.substring(boardUrl.indexOf("board=") + 6, boardUrl.lastIndexOf("."));
+ }
+ return null;
+ }
+
+ public static String getTopicId(String topicUrl) {
+ if (resolvePageCategory(Uri.parse(topicUrl)) == PageCategory.TOPIC) {
+ String tmp = topicUrl.substring(topicUrl.indexOf("topic=") + 6);
+ return tmp.substring(0, tmp.indexOf("."));
+ }
+ return null;
}
}
diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ObjectSerializer.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ObjectSerializer.java
new file mode 100644
index 00000000..ce3dbda6
--- /dev/null
+++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ObjectSerializer.java
@@ -0,0 +1,69 @@
+package gr.thmmy.mthmmy.utils;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//copied from http://github.com/apache/pig/blob/89c2e8e76c68d0d0abe6a36b4e08ddc56979796f/src/org/apache/pig/impl/util/ObjectSerializer.java
+//package org.apache.pig.impl.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+public class ObjectSerializer {
+
+ public static String serialize(Serializable obj) throws IOException {
+ if (obj == null) return "";
+ ByteArrayOutputStream serialObj = new ByteArrayOutputStream();
+ ObjectOutputStream objStream = new ObjectOutputStream(serialObj);
+ objStream.writeObject(obj);
+ objStream.close();
+ return encodeBytes(serialObj.toByteArray());
+ }
+
+ public static Object deserialize(String str) throws IOException, ClassNotFoundException {
+ if (str == null || str.length() == 0) return null;
+ ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str));
+ ObjectInputStream objStream = new ObjectInputStream(serialObj);
+ return objStream.readObject();
+ }
+
+ public static String encodeBytes(byte[] bytes) {
+ StringBuffer strBuf = new StringBuffer();
+
+ for (int i = 0; i < bytes.length; i++) {
+ strBuf.append((char) (((bytes[i] >> 4) & 0xF) + ((int) 'a')));
+ strBuf.append((char) (((bytes[i]) & 0xF) + ((int) 'a')));
+ }
+
+ return strBuf.toString();
+ }
+
+ public static byte[] decodeBytes(String str) {
+ byte[] bytes = new byte[str.length() / 2];
+ for (int i = 0; i < str.length(); i += 2) {
+ char c = str.charAt(i);
+ bytes[i / 2] = (byte) ((c - 'a') << 4);
+ c = str.charAt(i + 1);
+ bytes[i / 2] += (c - 'a');
+ }
+ return bytes;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable-hdpi/ic_bookmark_false.png b/app/src/main/res/drawable-hdpi/ic_bookmark_false.png
new file mode 100644
index 00000000..afb6271f
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_bookmark_false.png differ
diff --git a/app/src/main/res/drawable-hdpi/ic_bookmark_true.png b/app/src/main/res/drawable-hdpi/ic_bookmark_true.png
new file mode 100644
index 00000000..ce6dd7a9
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_bookmark_true.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_bookmark_false.png b/app/src/main/res/drawable-mdpi/ic_bookmark_false.png
new file mode 100644
index 00000000..79157474
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_bookmark_false.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_bookmark_true.png b/app/src/main/res/drawable-mdpi/ic_bookmark_true.png
new file mode 100644
index 00000000..06eba446
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_bookmark_true.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_bookmark_false.png b/app/src/main/res/drawable-xhdpi/ic_bookmark_false.png
new file mode 100644
index 00000000..cded6d60
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_bookmark_false.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_bookmark_true.png b/app/src/main/res/drawable-xhdpi/ic_bookmark_true.png
new file mode 100644
index 00000000..368c9ead
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_bookmark_true.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_bookmark_false.png b/app/src/main/res/drawable-xxhdpi/ic_bookmark_false.png
new file mode 100644
index 00000000..a837b04d
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_bookmark_false.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_bookmark_true.png b/app/src/main/res/drawable-xxhdpi/ic_bookmark_true.png
new file mode 100644
index 00000000..0253be02
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_bookmark_true.png differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_bookmark_false.png b/app/src/main/res/drawable-xxxhdpi/ic_bookmark_false.png
new file mode 100644
index 00000000..d65bb47d
Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_bookmark_false.png differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_bookmark_true.png b/app/src/main/res/drawable-xxxhdpi/ic_bookmark_true.png
new file mode 100644
index 00000000..59c96d06
Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_bookmark_true.png differ
diff --git a/app/src/main/res/layout/activity_board.xml b/app/src/main/res/layout/activity_board.xml
index 4c0684f7..5d3d7a3d 100644
--- a/app/src/main/res/layout/activity_board.xml
+++ b/app/src/main/res/layout/activity_board.xml
@@ -22,6 +22,16 @@
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ToolbarTheme">
+
+
diff --git a/app/src/main/res/layout/activity_bookmark.xml b/app/src/main/res/layout/activity_bookmark.xml
new file mode 100644
index 00000000..b2fa6e33
--- /dev/null
+++ b/app/src/main/res/layout/activity_bookmark.xml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_topic.xml b/app/src/main/res/layout/activity_topic.xml
index 8d2993ef..d7de516f 100644
--- a/app/src/main/res/layout/activity_topic.xml
+++ b/app/src/main/res/layout/activity_topic.xml
@@ -22,6 +22,16 @@
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ToolbarTheme">
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 86d8cf67..06d28a45 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -5,7 +5,10 @@
Login
Authenticating…
Logout
+ Downloads
+ About
Home
+ Bookmarks
thmmy.gr
@@ -50,11 +53,7 @@
Most Popular Boards By Posts
Most Popular Boards By Activity
-
- Downloads
-
- About
v%1$s
Logo
You should watch a funny pic!