From a78a4320889e6febc7e2595478034290b047e372 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 21 Jan 2017 02:44:38 +0200 Subject: [PATCH] Bookmarks init and fixes. --- app/src/main/AndroidManifest.xml | 15 +- .../mthmmy/activities/BookmarkActivity.java | 62 +++++ .../activities/board/BoardActivity.java | 15 +- .../downloads/DownloadsActivity.java | 16 +- .../activities/profile/ProfileActivity.java | 13 +- .../activities/topic/TopicActivity.java | 38 ++- .../mthmmy/activities/topic/TopicAdapter.java | 10 +- .../gr/thmmy/mthmmy/base/BaseActivity.java | 227 +++++++++++++++++- .../java/gr/thmmy/mthmmy/model/Bookmark.java | 18 ++ .../model/{LinkTarget.java => ThmmyPage.java} | 47 ++-- .../thmmy/mthmmy/utils/ObjectSerializer.java | 69 ++++++ .../res/drawable-hdpi/ic_bookmark_false.png | Bin 0 -> 293 bytes .../res/drawable-hdpi/ic_bookmark_true.png | Bin 0 -> 230 bytes .../res/drawable-mdpi/ic_bookmark_false.png | Bin 0 -> 203 bytes .../res/drawable-mdpi/ic_bookmark_true.png | Bin 0 -> 161 bytes .../res/drawable-xhdpi/ic_bookmark_false.png | Bin 0 -> 336 bytes .../res/drawable-xhdpi/ic_bookmark_true.png | Bin 0 -> 261 bytes .../res/drawable-xxhdpi/ic_bookmark_false.png | Bin 0 -> 478 bytes .../res/drawable-xxhdpi/ic_bookmark_true.png | Bin 0 -> 362 bytes .../drawable-xxxhdpi/ic_bookmark_false.png | Bin 0 -> 620 bytes .../res/drawable-xxxhdpi/ic_bookmark_true.png | Bin 0 -> 473 bytes app/src/main/res/layout/activity_board.xml | 10 + app/src/main/res/layout/activity_bookmark.xml | 57 +++++ app/src/main/res/layout/activity_topic.xml | 10 + app/src/main/res/values/strings.xml | 7 +- 25 files changed, 541 insertions(+), 73 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java create mode 100644 app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java rename app/src/main/java/gr/thmmy/mthmmy/model/{LinkTarget.java => ThmmyPage.java} (77%) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/ObjectSerializer.java create mode 100644 app/src/main/res/drawable-hdpi/ic_bookmark_false.png create mode 100644 app/src/main/res/drawable-hdpi/ic_bookmark_true.png create mode 100644 app/src/main/res/drawable-mdpi/ic_bookmark_false.png create mode 100644 app/src/main/res/drawable-mdpi/ic_bookmark_true.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_bookmark_false.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_bookmark_true.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_bookmark_false.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_bookmark_true.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_bookmark_false.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_bookmark_true.png create mode 100644 app/src/main/res/layout/activity_bookmark.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 20248cb4..a2dfc7ee 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,7 +15,6 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> - - - - - - - + + + toQuoteList = new ArrayList<>(); //Topic's pages private int thisPage = 1; - public static String base_url = ""; private int numberOfPages = 1; private final SparseArray pagesUrls = new SparseArray<>(); //Page select @@ -88,9 +88,10 @@ public class TopicActivity extends BaseActivity { private ImageButton nextPage; private ImageButton lastPage; //Other variables + private FloatingActionButton replyFAB; private MaterialProgressBar progressBar; + public static String base_url = ""; private String topicTitle; - private FloatingActionButton replyFAB; private String parsedTitle; private RecyclerView recyclerView; private String loadedPageUrl = ""; @@ -104,10 +105,11 @@ public class TopicActivity extends BaseActivity { Bundle extras = getIntent().getExtras(); topicTitle = extras.getString(BUNDLE_TOPIC_TITLE); - LinkTarget.Target target = LinkTarget.resolveLinkTarget( - Uri.parse(extras.getString(BUNDLE_TOPIC_URL))); - if (!target.is(LinkTarget.Target.TOPIC)) { - Report.e(TAG, "Bundle came with a non topic url!\nUrl:\n" + extras.getString(BUNDLE_TOPIC_URL)); + String topicPageUrl = extras.getString(BUNDLE_TOPIC_URL); + ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory( + Uri.parse(topicPageUrl)); + if (!target.is(ThmmyPage.PageCategory.TOPIC)) { + Report.e(TAG, "Bundle came with a non topic url!\nUrl:\n" + topicPageUrl); Toast.makeText(this, "An error has occurred\n Aborting.", Toast.LENGTH_SHORT).show(); finish(); } @@ -121,6 +123,8 @@ public class TopicActivity extends BaseActivity { getSupportActionBar().setDisplayShowHomeEnabled(true); } + setTopicBookmark((ImageButton) findViewById(R.id.bookmark), + new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl))); createDrawer(); progressBar = (MaterialProgressBar) findViewById(R.id.progressBar); @@ -458,14 +462,25 @@ public class TopicActivity extends BaseActivity { } //Checks if the page to be loaded is the one already shown - if (!Objects.equals(loadedPageUrl, "") && !loadedPageUrl.contains(base_url)) { + if (!Objects.equals(loadedPageUrl, "") && loadedPageUrl.contains(base_url)) { if (newPageUrl.contains("topicseen#new")) - if (Integer.parseInt(loadedPageUrl.substring(base_url.length())) == numberOfPages) + if (thisPage == numberOfPages) return SAME_PAGE; + if (newPageUrl.contains("msg")) { + String tmpUrlSbstr = newPageUrl.substring(newPageUrl.indexOf("msg") + 3); + if (tmpUrlSbstr.contains("msg")) + tmpUrlSbstr = tmpUrlSbstr.substring(0, tmpUrlSbstr.indexOf("msg") - 1); + int testAgainst = Integer.parseInt(tmpUrlSbstr); + for (Post post : postsList) { + if (post.getPostIndex() == testAgainst) { + return SAME_PAGE; + } + } + } if (Objects.equals(loadedPageUrl.substring(base_url.length()) , newPageUrl.substring(base_url.length()))) return SAME_PAGE; - } + } else topicTitle = null; loadedPageUrl = newPageUrl; Request request = new Request.Builder() @@ -496,6 +511,9 @@ public class TopicActivity extends BaseActivity { switch (parseResult) { case SUCCESS: + setTopicBookmark((ImageButton) findViewById(R.id.bookmark), + new Bookmark(parsedTitle, ThmmyPage.getTopicId(loadedPageUrl))); + progressBar.setVisibility(ProgressBar.INVISIBLE); topicAdapter.customNotifyDataSetChanged(new TopicTask()); if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true); 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 d93d09a5..9919719e 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 @@ -43,8 +43,8 @@ import java.util.Objects; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; -import gr.thmmy.mthmmy.model.LinkTarget; import gr.thmmy.mthmmy.model.Post; +import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.utils.CircleTransform; import gr.thmmy.mthmmy.utils.FileManager.ThmmyFile; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; @@ -552,8 +552,8 @@ class TopicAdapter extends RecyclerView.Adapter { private boolean handleUri(final Uri uri) { final String uriString = uri.toString(); - LinkTarget.Target target = LinkTarget.resolveLinkTarget(uri); - if (target.is(LinkTarget.Target.TOPIC)) { + ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(uri); + if (target.is(ThmmyPage.PageCategory.TOPIC)) { //This url points to a topic //Checks if this is the current topic if (Objects.equals(uriString.substring(0, uriString.lastIndexOf(".")), base_url)) { @@ -574,7 +574,7 @@ class TopicAdapter extends RecyclerView.Adapter { } topicTask.execute(uri.toString()); return true; - } else if (target.is(LinkTarget.Target.BOARD)) { + } else if (target.is(ThmmyPage.PageCategory.BOARD)) { Intent intent = new Intent(context, BoardActivity.class); Bundle extras = new Bundle(); extras.putString(BUNDLE_BOARD_URL, uriString); @@ -583,7 +583,7 @@ class TopicAdapter extends RecyclerView.Adapter { intent.setFlags(FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return true; - } else if (target.is(LinkTarget.Target.PROFILE)) { + } else if (target.is(ThmmyPage.PageCategory.PROFILE)) { Intent intent = new Intent(context, ProfileActivity.class); Bundle extras = new Bundle(); extras.putString(BUNDLE_PROFILE_URL, uriString); diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 814d2224..5086e812 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -1,13 +1,18 @@ package gr.thmmy.mthmmy.base; import android.app.ProgressDialog; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.drawable.Drawable; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; +import android.widget.ImageButton; import android.widget.Toast; import com.mikepenz.fontawesome_typeface_library.FontAwesome; @@ -21,13 +26,20 @@ import com.mikepenz.materialdrawer.model.ProfileDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IProfile; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Objects; + import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.AboutActivity; +import gr.thmmy.mthmmy.activities.BookmarkActivity; import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity; +import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.session.SessionManager; +import gr.thmmy.mthmmy.utils.ObjectSerializer; import okhttp3.OkHttpClient; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; @@ -44,6 +56,16 @@ public abstract class BaseActivity extends AppCompatActivity { //SessionManager protected static SessionManager sessionManager; + //Bookmarks + private static final String BOOKMARKS_SHARED_PREFS = "bookmarksSharedPrefs"; + private static final String BOOKMARKED_TOPICS_KEY = "bookmarkedTopicsKey"; + private static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey"; + protected static SharedPreferences bookmarksFile; + protected static ArrayList topicsBookmarked; + protected static ArrayList boardsBookmarked; + protected static Drawable bookmarked; + protected static Drawable notBookmarked; + //Common UI elements protected Toolbar toolbar; protected Drawer drawer; @@ -56,6 +78,25 @@ public abstract class BaseActivity extends AppCompatActivity { // they become null when app restarts after crash if (sessionManager == null) sessionManager = BaseApplication.getInstance().getSessionManager(); + + if (sessionManager.isLoggedIn()) { + if (bookmarked == null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + bookmarked = getResources().getDrawable(R.drawable.ic_bookmark_true, null); + } else //noinspection deprecation + bookmarked = getResources().getDrawable(R.drawable.ic_bookmark_true); + } + if (notBookmarked == null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + notBookmarked = getResources().getDrawable(R.drawable.ic_bookmark_false, null); + } else //noinspection deprecation + notBookmarked = getResources().getDrawable(R.drawable.ic_bookmark_false); + } + if (topicsBookmarked == null || boardsBookmarked == null) { + bookmarksFile = getSharedPreferences(BOOKMARKS_SHARED_PREFS, Context.MODE_PRIVATE); + loadSavedBookmarks(); + } + } } @Override @@ -84,14 +125,16 @@ public abstract class BaseActivity extends AppCompatActivity { //------------------------------------------DRAWER STUFF---------------------------------------- protected static final int HOME_ID = 0; protected static final int DOWNLOADS_ID = 1; - protected static final int LOG_ID = 2; - protected static final int ABOUT_ID = 3; + protected static final int BOOKMARKS_ID = 2; + protected static final int LOG_ID = 3; + protected static final int ABOUT_ID = 4; private AccountHeader accountHeader; private ProfileDrawerItem profileDrawerItem; - private PrimaryDrawerItem homeItem, downloadsItem, loginLogoutItem, aboutItem; - private IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, loginIcon, logoutIcon, - aboutIcon, aboutIconSelected; + private PrimaryDrawerItem homeItem, downloadsItem, bookmarksItem, loginLogoutItem, aboutItem; + private IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, + bookmarksIcon, bookmarksIconSelected, loginIcon, logoutIcon, aboutIcon, + aboutIconSelected; /** * Call only after initializing Toolbar @@ -118,6 +161,14 @@ public abstract class BaseActivity extends AppCompatActivity { .icon(FontAwesome.Icon.faw_download) .color(selectedSecondaryColor); + bookmarksIcon = new IconicsDrawable(this) + .icon(FontAwesome.Icon.faw_bookmark) + .color(primaryColor); + + bookmarksIconSelected = new IconicsDrawable(this) + .icon(FontAwesome.Icon.faw_bookmark) + .color(selectedSecondaryColor); + loginIcon = new IconicsDrawable(this) .icon(FontAwesome.Icon.faw_sign_in) .color(primaryColor); @@ -162,6 +213,14 @@ public abstract class BaseActivity extends AppCompatActivity { .withName(R.string.downloads) .withIcon(downloadsIcon) .withSelectedIcon(downloadsIconSelected); + bookmarksItem = new PrimaryDrawerItem() + .withTextColor(primaryColor) + .withSelectedColor(selectedPrimaryColor) + .withSelectedTextColor(selectedSecondaryColor) + .withIdentifier(BOOKMARKS_ID) + .withName(R.string.bookmark) + .withIcon(bookmarksIcon) + .withSelectedIcon(bookmarksIconSelected); } else loginLogoutItem = new PrimaryDrawerItem() .withTextColor(primaryColor) @@ -228,8 +287,7 @@ public abstract class BaseActivity extends AppCompatActivity { startActivity(i); } } else if (drawerItem.equals(DOWNLOADS_ID)) { - if (!(BaseActivity.this instanceof DownloadsActivity)) //When logged out or if user is guest - { + if (!(BaseActivity.this instanceof DownloadsActivity)) { Intent i = new Intent(BaseActivity.this, DownloadsActivity.class); Bundle extras = new Bundle(); extras.putString(BUNDLE_DOWNLOADS_URL, ""); @@ -237,6 +295,11 @@ public abstract class BaseActivity extends AppCompatActivity { i.putExtras(extras); startActivity(i); } + } else if (drawerItem.equals(BOOKMARKS_ID)) { + if (!(BaseActivity.this instanceof BookmarkActivity)) { + Intent i = new Intent(BaseActivity.this, BookmarkActivity.class); + startActivity(i); + } } else if (drawerItem.equals(LOG_ID)) { if (!sessionManager.isLoggedIn()) //When logged out or if user is guest { @@ -260,7 +323,7 @@ public abstract class BaseActivity extends AppCompatActivity { }); if (sessionManager.isLoggedIn()) - drawerBuilder.addDrawerItems(homeItem, downloadsItem, loginLogoutItem, aboutItem); + drawerBuilder.addDrawerItems(homeItem, downloadsItem, bookmarksItem, loginLogoutItem, aboutItem); else drawerBuilder.addDrawerItems(homeItem, loginLogoutItem, aboutItem); @@ -298,7 +361,7 @@ public abstract class BaseActivity extends AppCompatActivity { } - //-------------------------------------------LOGOUT------------------------------------------------- +//-------------------------------------------LOGOUT------------------------------------------------- /** * Result toast will always display a success, because when user chooses logout all data are @@ -328,5 +391,151 @@ public abstract class BaseActivity extends AppCompatActivity { } //-----------------------------------------LOGOUT END----------------------------------------------- +//---------------------------------------------BOOKMARKS-------------------------------------------- + + protected ArrayList getBoardsBookmarked() { + return boardsBookmarked; + } + + protected ArrayList getTopicsBookmarked() { + return topicsBookmarked; + } + protected void setTopicBookmark(ImageButton bookmarkView, final Bookmark bookmark) { + if (matchExists(bookmark, topicsBookmarked)) { + bookmarkView.setImageDrawable(bookmarked); + } else { + bookmarkView.setImageDrawable(notBookmarked); + } + bookmarkView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (matchExists(bookmark, topicsBookmarked)) { + ((ImageButton) view).setImageDrawable(notBookmarked); + toggleTopicToBookmarks(bookmark); + Toast.makeText(BaseActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); + } else { + ((ImageButton) view).setImageDrawable(bookmarked); + toggleTopicToBookmarks(bookmark); + Toast.makeText(BaseActivity.this, "Bookmark added", Toast.LENGTH_SHORT).show(); + } + } + }); + } + + protected void setBoardBookmark(ImageButton bookmarkView, final Bookmark bookmark) { + if (matchExists(bookmark, boardsBookmarked)) { + bookmarkView.setImageDrawable(bookmarked); + } else { + bookmarkView.setImageDrawable(notBookmarked); + } + bookmarkView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (matchExists(bookmark, boardsBookmarked)) { + ((ImageButton) view).setImageDrawable(notBookmarked); + toggleBoardToBookmarks(bookmark); + Toast.makeText(BaseActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); + } else { + ((ImageButton) view).setImageDrawable(bookmarked); + toggleBoardToBookmarks(bookmark); + Toast.makeText(BaseActivity.this, "Bookmark added", Toast.LENGTH_SHORT).show(); + } + } + }); + } + + private void loadSavedBookmarks() { + String tmpString = bookmarksFile.getString(BOOKMARKED_TOPICS_KEY, null); + if (tmpString != null) + try { + topicsBookmarked = (ArrayList) ObjectSerializer.deserialize(tmpString); + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + } + else { + topicsBookmarked = new ArrayList<>(); + topicsBookmarked.add(null); + } + + tmpString = bookmarksFile.getString(BOOKMARKED_BOARDS_KEY, null); + if (tmpString != null) + try { + boardsBookmarked = (ArrayList) ObjectSerializer.deserialize(tmpString); + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + } + else { + boardsBookmarked = new ArrayList<>(); + boardsBookmarked.add(null); + } + } + + private void toggleBoardToBookmarks(Bookmark bookmark) { + if (boardsBookmarked == null) return; + if (matchExists(bookmark, boardsBookmarked)) { + if (boardsBookmarked.size() == 1) boardsBookmarked.set(0, null); + else boardsBookmarked.remove(findIndex(bookmark, boardsBookmarked)); + } else boardsBookmarked.add(bookmark); + updateBoardBookmarks(); + } + + private void toggleTopicToBookmarks(Bookmark bookmark) { + if (topicsBookmarked == null) return; + if (matchExists(bookmark, topicsBookmarked)) + topicsBookmarked.remove(findIndex(bookmark, topicsBookmarked)); + else topicsBookmarked.add(bookmark); + updateTopicBookmarks(); + } + + private void updateBoardBookmarks() { + String tmpString = null; + if (!(boardsBookmarked.size() == 1 && boardsBookmarked.get(0) == null)) { + try { + tmpString = ObjectSerializer.serialize(boardsBookmarked); + } catch (IOException e) { + e.printStackTrace(); + } + } + SharedPreferences.Editor editor = bookmarksFile.edit(); + editor.putString(BOOKMARKED_BOARDS_KEY, tmpString).apply(); + } + + private void updateTopicBookmarks() { + String tmpString = null; + if (!(topicsBookmarked.size() == 1 && topicsBookmarked.get(0) == null)) { + try { + tmpString = ObjectSerializer.serialize(topicsBookmarked); + } catch (IOException e) { + e.printStackTrace(); + } + } + SharedPreferences.Editor editor = bookmarksFile.edit(); + editor.putString(BOOKMARKED_TOPICS_KEY, tmpString).apply(); + } + + private boolean matchExists(Bookmark bookmark, ArrayList array) { + if (!array.isEmpty()) { + for (Bookmark b : array) { + if (b != null) { + return Objects.equals(b.getId(), bookmark.getId()) + && Objects.equals(b.getTitle(), bookmark.getTitle()); + } + } + } + return false; + } + + private int findIndex(Bookmark bookmark, ArrayList 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 0000000000000000000000000000000000000000..afb6271f66ef5b49256dcf339099b3eedb33f809 GIT binary patch literal 293 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbB-gvq=hE&{oJ7Xj7Ap-$dS(S)J zABSFz8%-Qp(;66gW;QUcaOld|?4)7LQX1C4wQs3&5o71cn~V#!z+P<9gLdewW z?N$ASE-&O;l_oIoUYeGpq5OzzW`oQf+ll6$rktvBsq@ZQINjpXl2F!OBXd^JYwdz5 zg^_cMT|8Rg=uT7Hk?XC;9&qG6;NmN}wlaWU=fKW1UsLHvbF!K_-yV>PvAZ$f_ib0z zUhchzdbF5>l@@Q_HBZ4w^v1rOCk(%a#&S$e;QYnc|EnR(`@Yk+h+F&G-xO|YQ8QtR jzyHoK_0)ZSL9S!Wd>?rDZ*SuR1qg$utDnm{r-UW|L-ul^ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..ce6dd7a93d93ab29cba4acf530322173258dfd0e GIT binary patch literal 230 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbB)_S@)hE&{24v04EPBcht3uNbY zXE$WpC@*lGsgQZ*4!$fl<)wT~k{jeY{s(ieSAU}6#P@0OqU3}d(}mctUOM2ob&AD` zMmD}IiP8%zn%!hgUM&b@@3qRf;<%Vk3M9mK&e6WHf>U6&<42(t5_e_4$aK7JjF9P; z<6N=t`ImwVo(g?zNnuJ>Gjam9s;_*j@FYWVdv}k_ToKC?98#=TUhVdFI4dLjSE5wl btO0}c4zY{QvlhJsI-J4N)z4*}Q$iB}VyIHP literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..7915747460f3186dd0f319bc24af296c57724b74 GIT binary patch literal 203 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjlRRA}12Sl57H%^<8cq2-H zyQaIKKqq}%XtzQZ1tjYn#fSBm-T?;OXk;vd$@?2>{{i BNvQw; literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..06eba446284093c1eccf813132963f9da105a6f6 GIT binary patch literal 161 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`Gj8J;eVAr-fh1ES5k8>h`kyb&e9 zaYVoIhyBDKq5{7sCoyWa9sb}Qr1QgHO>S$#m8L*$H(iNKVt-g3sXFAa9ra$2Boh5W zrsH*EgiN;-r$S!CD#e>klO1GukF0UI5|tCMRoy*ou8%1X!=i>H~atq literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..cded6d6083ea3e83cf4913acb10142b53c6be595 GIT binary patch literal 336 zcmV-W0k8gvP)aQm0pN^d@=MX>u0r>(n&=Q@HA8{A7Mon9QIyzW*@XwAq2pzy8hKGN*vH{q~ z2sqmS+&?yn`UB~ktgo}dg8%{uAb@~e1D*sBKmY**=`do%YT)(xEnKm2zKG$gwmFlBilD45{HFb}Anfk7ej z05_PS!V7W{5IATx?AE$+ChSJ~Ty~i&PQ6+C^t;&vkp-0ZsU_z&tfp!=tb%k_BX-r>mdKI;Vst07~s- AhyVZp literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..a837b04d311ada9e64097ac3831e7805f12b9ff6 GIT binary patch literal 478 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@Zgyv2U|j0y;uunK>+S8mUWWr@+CDl3 zzP#oen7)_!rRWRZ9bcJbTuKVB`Q{(sJLkHGN#9YxHSoo{$=yv0I)ZX*n3qQ^>GUm{ zG`T;$Vw#D3yZql^F3YV;CqI^AWoL3=U}O;h5doW)U7fZoVEw7$EA6|2th3bg9X`K0 zrsx$=o^{Z4!vC{7&nceU5WU$g-C?%nG0AOjgbkZ3)hf~8>oS{5{~uzqU1e)({p?c>+djZ+e;H`kk;{PC3S#4(AbhIQu} zFG(oRe*BzAquX$kVOoab;k%F)(<#`njxgN@xNAx>CZ} literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..0253be0232aad62dda91a5524c7decb52c0bea2d GIT binary patch literal 362 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@Zgyv2U^Mh}aSW-r_4c+e-@yQpwnSl_ zMuY7vvtJ6i++cidkf-CS)UtsyxYNZWVEM`1qy?Ae-<}s;%l_Ww&r{F+4>NhDb+a91 zXL4X*WDx)n0sEpZMMQavYX-bh%U!ziN*U`4^|zvdkF30Ea~FI#dDF5(xYXc(AaBMK z1HUUS!Wp5A3wqTq>|}BX_g&!5+Q8(yKpk!t*gye?rObO7m^c&~kO(bV4F*&Zkb*3( zlIb;>8K2H(Z)LagG+z1n>F(W^?(A7!=J4?56m?T!xib~djO%&7ST0_(e|l-1AM@W? zf!8jbJMX!`#Q0S4`e`Y3=NN9z2o(Gr%&wK>X7+qJTgb7VoHPBK3*J3r1iL_~fnn2a Z>HR5DD|dIF6$FMMgQu&X%Q~loCIF3yg027n literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..d65bb47d00bc840daf64d5d7ae0f6ba26138201a GIT binary patch literal 620 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7Ro>U^4b}aSW-r_4dw2Z>B(*1BIMj zF?W_62+iZ%r1^*WPImq~{tW)CEPV~<6`rs7U+}NEYTBMrkXLw8_3V{8cK;5Iz1Ht- z-|zh{yHBCy-rjQgAB_U~;&)7ow(P0kWMFVWMtzKLJW5}NN_kA~F%QV*y&khsG9fn0 zBbhtySAA>t{;=weTnaHC79Z9BSMI+{poB5T^2?{?S92L}Y^r&4M#^1On&F&m&Cknv zxeOI$5)Y2DHI%nA{xW0u@;pcBwSAwO+V%Cx%*;TKA;1Ca27d$($N~x|q6j>YJs^%Q zz=0z0fiHmvC?IjeA(Zg)RB3aLX{`p=tFiYX+Si zjZGygrAgsOv&(*Jz9viB6jnfngDRUIFql{}S8-_Lr@P-s43 zI^WW=gm+I?Z>vhXm)sjTC*&}@yLECEyBDgWVKe6lUeH&mYClGXj4nr~Ol zYTQ}8axYuOWWOc7_VadY&Rvzw;IVUBiNad9ihr|qZDVz)N>+OrRnnvWoH4C;=8~nB z^X9O27^h8|cC4a^OQF{=xyr_paY6E#8B+dX%rhj6cO9Qx%5Yl7*y`A1Q-(+>U|ito;uunK>+M}bKPE?swnV93 z^9#ZkA`+ga+VsR7bTYhhBs;@9JK3gjtL%cN%_lEOsCuPM|C>Jl(Oa{diSwRlPe1sf z&gjCwB2ESd4xn)i3JeS^3=Le&7T&$V`YTe8oAoIUx`^}soKiW2JioCU%e^+ zn$O7^Ap1k{!_oTp8#P;&G30UY`s4dpgJJo>^z_>@y-Ex*;uSw<=P5DRi1K`pVSKPQ zp`ntcq4FTZYYql(pzGn_3ts}zYB*@P$GC?X&SPL$P|hHa#ASFPdq5qTU&X$G35oCU zp5YpZ8(`+})wV11)t)@7ocGeAd)X>{W0&>SSG@OpwW^NI;aS?s?kfl7@6|`xTQg6{ zPb;(a7XBP!b70%dn_K664$(PKpO$vL=uB`RgJs&Xx0PB<3p!_JX3ukC-ePF%dp_8r zq4u1Q@MjUW1>VM!i|1MKUwAt6q@n-66Kj{m0A0hx-~bKG1!BLMtY$7`tSWGl0XfUl L)z4*}Q$iB}OaGl` literal 0 HcmV?d00001 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!