Browse Source

Bookmarks work for guests too, minor tweaks.

pull/24/head
Ezerous 8 years ago
parent
commit
5c6a7d03d8
  1. 53
      app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java
  2. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  3. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java
  4. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java
  5. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java
  6. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  7. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java
  8. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java
  9. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java
  10. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  11. 24
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  12. 1
      app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java
  13. 1
      app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java
  14. 4
      app/src/main/res/values/strings.xml

53
app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java

@ -22,6 +22,8 @@ import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL;
public class BookmarkActivity extends BaseActivity { public class BookmarkActivity extends BaseActivity {
private TextView boardsTitle;
private TextView topicsTitle;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -43,21 +45,22 @@ public class BookmarkActivity extends BaseActivity {
LinearLayout bookmarksLinearView = (LinearLayout) findViewById(R.id.bookmarks_container); LinearLayout bookmarksLinearView = (LinearLayout) findViewById(R.id.bookmarks_container);
LayoutInflater layoutInflater = getLayoutInflater(); LayoutInflater layoutInflater = getLayoutInflater();
TextView tmp = new TextView(this); if(!getBoardsBookmarked().isEmpty()) {
tmp.setLayoutParams(new LinearLayout.LayoutParams( boardsTitle = new TextView(this);
boardsTitle.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT)); , LinearLayout.LayoutParams.WRAP_CONTENT));
tmp.setText(getString(R.string.board_bookmarks_title)); boardsTitle.setText(getString(R.string.board_bookmarks_title));
tmp.setTypeface(tmp.getTypeface(), Typeface.BOLD); boardsTitle.setTypeface(boardsTitle.getTypeface(), Typeface.BOLD);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
tmp.setTextColor(getColor(R.color.primary_text)); boardsTitle.setTextColor(getColor(R.color.primary_text));
} else { } else {
//noinspection deprecation //noinspection deprecation
tmp.setTextColor(getResources().getColor(R.color.primary_text)); boardsTitle.setTextColor(getResources().getColor(R.color.primary_text));
} }
tmp.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); boardsTitle.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tmp.setTextSize(20f); boardsTitle.setTextSize(20f);
bookmarksLinearView.addView(tmp); bookmarksLinearView.addView(boardsTitle);
for (final Bookmark bookmarkedBoard : getBoardsBookmarked()) { for (final Bookmark bookmarkedBoard : getBoardsBookmarked()) {
if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) { if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) {
@ -82,27 +85,31 @@ public class BookmarkActivity extends BaseActivity {
public void onClick(View view) { public void onClick(View view) {
removeBookmark(bookmarkedBoard); removeBookmark(bookmarkedBoard);
row.setVisibility(View.GONE); row.setVisibility(View.GONE);
updateTitles();
} }
}); });
bookmarksLinearView.addView(row); bookmarksLinearView.addView(row);
} }
} }
}
tmp = new TextView(this); if(!getTopicsBookmarked().isEmpty()) {
tmp.setLayoutParams(new LinearLayout.LayoutParams( topicsTitle = new TextView(this);
topicsTitle.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT)); , LinearLayout.LayoutParams.WRAP_CONTENT));
tmp.setText(getString(R.string.topic_bookmarks_title)); topicsTitle.setText(getString(R.string.topic_bookmarks_title));
tmp.setTypeface(tmp.getTypeface(), Typeface.BOLD); topicsTitle.setTypeface(topicsTitle.getTypeface(), Typeface.BOLD);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
tmp.setTextColor(getColor(R.color.primary_text)); topicsTitle.setTextColor(getColor(R.color.primary_text));
} else { } else {
//noinspection deprecation //noinspection deprecation
tmp.setTextColor(getResources().getColor(R.color.primary_text)); topicsTitle.setTextColor(getResources().getColor(R.color.primary_text));
} }
tmp.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); topicsTitle.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tmp.setTextSize(20f); topicsTitle.setTextSize(20f);
bookmarksLinearView.addView(tmp); bookmarksLinearView.addView(topicsTitle);
for (final Bookmark bookmarkedTopic : getTopicsBookmarked()) { for (final Bookmark bookmarkedTopic : getTopicsBookmarked()) {
if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) { if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) {
@ -127,16 +134,26 @@ public class BookmarkActivity extends BaseActivity {
public void onClick(View view) { public void onClick(View view) {
removeBookmark(bookmarkedTopic); removeBookmark(bookmarkedTopic);
row.setVisibility(View.GONE); row.setVisibility(View.GONE);
updateTitles();
} }
}); });
bookmarksLinearView.addView(row); bookmarksLinearView.addView(row);
} }
} }
} }
}
@Override @Override
protected void onResume() { protected void onResume() {
drawer.setSelection(BOOKMARKS_ID); drawer.setSelection(BOOKMARKS_ID);
super.onResume(); super.onResume();
} }
private void updateTitles()
{
if(getBoardsBookmarked().isEmpty())
boardsTitle.setVisibility(View.GONE);
if(getTopicsBookmarked().isEmpty())
topicsTitle.setVisibility(View.GONE);
}
} }

1
app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java

@ -14,7 +14,6 @@ import android.widget.Toast;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.main.MainActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.session.SessionManager.CONNECTION_ERROR; import static gr.thmmy.mthmmy.session.SessionManager.CONNECTION_ERROR;

1
app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java

@ -27,7 +27,6 @@ import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.model.Download; import gr.thmmy.mthmmy.model.Download;
import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.ThmmyPage;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import timber.log.Timber; import timber.log.Timber;

7
app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java

@ -210,14 +210,13 @@ public class ForumFragment extends BaseFragment
fetchedCategories.add(category); fetchedCategories.add(category);
} }
}
else
throw new ParseException("Parsing failed");
categories.clear(); categories.clear();
categories.addAll(fetchedCategories); categories.addAll(fetchedCategories);
fetchedCategories.clear(); fetchedCategories.clear();
} }
else
throw new ParseException("Parsing failed");
}
@Override @Override
protected void postParsing(ParseTask.ResultCode result) { protected void postParsing(ParseTask.ResultCode result) {

2
app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java

@ -147,7 +147,6 @@ public class RecentFragment extends BaseFragment {
Elements recent = document.select("#block8 :first-child div"); Elements recent = document.select("#block8 :first-child div");
if (!recent.isEmpty()) { if (!recent.isEmpty()) {
topicSummaries.clear(); topicSummaries.clear();
for (int i = 0; i < recent.size(); i += 3) { for (int i = 0; i < recent.size(); i += 3) {
String link = recent.get(i).child(0).attr("href"); String link = recent.get(i).child(0).attr("href");
String title = recent.get(i).child(0).attr("title"); String title = recent.get(i).child(0).attr("title");
@ -170,7 +169,6 @@ public class RecentFragment extends BaseFragment {
topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime)); topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime));
} }
return; return;
} }
throw new ParseException("Parsing failed"); throw new ParseException("Parsing failed");

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

@ -19,7 +19,6 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan; 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;
@ -50,7 +49,6 @@ import gr.thmmy.mthmmy.model.ThmmyPage;
import gr.thmmy.mthmmy.utils.CenterVerticalSpan; 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 okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import timber.log.Timber; import timber.log.Timber;

1
app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java

@ -26,7 +26,6 @@ import gr.thmmy.mthmmy.base.BaseFragment;
import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.PostSummary;
import gr.thmmy.mthmmy.utils.ParseHelpers; import gr.thmmy.mthmmy.utils.ParseHelpers;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import timber.log.Timber; import timber.log.Timber;

1
app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java

@ -41,7 +41,6 @@ import javax.net.ssl.SSLHandshakeException;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import timber.log.Timber; import timber.log.Timber;

2
app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java

@ -7,7 +7,6 @@ import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -25,7 +24,6 @@ import java.util.Objects;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.utils.ParseHelpers; import gr.thmmy.mthmmy.utils.ParseHelpers;
import timber.log.Timber; import timber.log.Timber;

2
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -18,7 +18,6 @@ import android.support.v7.widget.RecyclerView;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -54,7 +53,6 @@ import gr.thmmy.mthmmy.model.Post;
import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.model.ThmmyFile;
import gr.thmmy.mthmmy.model.ThmmyPage; import gr.thmmy.mthmmy.model.ThmmyPage;
import gr.thmmy.mthmmy.utils.CircleTransform; import gr.thmmy.mthmmy.utils.CircleTransform;
import timber.log.Timber; import timber.log.Timber;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

24
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -65,7 +65,6 @@ public abstract class BaseActivity extends AppCompatActivity {
private static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey"; private static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey";
protected Bookmark thisPageBookmark; protected Bookmark thisPageBookmark;
private MenuItem thisPageBookmarkMenuButton; private MenuItem thisPageBookmarkMenuButton;
private ImageButton thisPageBookmarkImageButton;
private SharedPreferences bookmarksFile; private SharedPreferences bookmarksFile;
private ArrayList<Bookmark> topicsBookmarked; private ArrayList<Bookmark> topicsBookmarked;
private ArrayList<Bookmark> boardsBookmarked; private ArrayList<Bookmark> boardsBookmarked;
@ -86,8 +85,6 @@ public abstract class BaseActivity extends AppCompatActivity {
if (sessionManager == null) if (sessionManager == null)
sessionManager = BaseApplication.getInstance().getSessionManager(); sessionManager = BaseApplication.getInstance().getSessionManager();
if (sessionManager.isLoggedIn()) {
if (bookmarked == null) { if (bookmarked == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
bookmarked = getResources().getDrawable(R.drawable.ic_bookmark_true, null); bookmarked = getResources().getDrawable(R.drawable.ic_bookmark_true, null);
@ -104,7 +101,7 @@ public abstract class BaseActivity extends AppCompatActivity {
bookmarksFile = getSharedPreferences(BOOKMARKS_SHARED_PREFS, Context.MODE_PRIVATE); bookmarksFile = getSharedPreferences(BOOKMARKS_SHARED_PREFS, Context.MODE_PRIVATE);
loadSavedBookmarks(); loadSavedBookmarks();
} }
}
} }
@Override @Override
@ -221,6 +218,14 @@ public abstract class BaseActivity extends AppCompatActivity {
.withName(R.string.downloads) .withName(R.string.downloads)
.withIcon(downloadsIcon) .withIcon(downloadsIcon)
.withSelectedIcon(downloadsIconSelected); .withSelectedIcon(downloadsIconSelected);
} else
loginLogoutItem = new PrimaryDrawerItem()
.withTextColor(primaryColor)
.withSelectedColor(selectedSecondaryColor)
.withIdentifier(LOG_ID).withName(R.string.login)
.withIcon(loginIcon)
.withSelectable(false);
bookmarksItem = new PrimaryDrawerItem() bookmarksItem = new PrimaryDrawerItem()
.withTextColor(primaryColor) .withTextColor(primaryColor)
.withSelectedColor(selectedPrimaryColor) .withSelectedColor(selectedPrimaryColor)
@ -229,13 +234,6 @@ public abstract class BaseActivity extends AppCompatActivity {
.withName(R.string.bookmark) .withName(R.string.bookmark)
.withIcon(bookmarksIcon) .withIcon(bookmarksIcon)
.withSelectedIcon(bookmarksIconSelected); .withSelectedIcon(bookmarksIconSelected);
} else
loginLogoutItem = new PrimaryDrawerItem()
.withTextColor(primaryColor)
.withSelectedColor(selectedSecondaryColor)
.withIdentifier(LOG_ID).withName(R.string.login)
.withIcon(loginIcon)
.withSelectable(false);
aboutItem = new PrimaryDrawerItem() aboutItem = new PrimaryDrawerItem()
.withTextColor(primaryColor) .withTextColor(primaryColor)
@ -333,7 +331,7 @@ public abstract class BaseActivity extends AppCompatActivity {
if (sessionManager.isLoggedIn()) if (sessionManager.isLoggedIn())
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, loginLogoutItem, aboutItem); drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, loginLogoutItem, aboutItem);
else else
drawerBuilder.addDrawerItems(homeItem, loginLogoutItem, aboutItem); drawerBuilder.addDrawerItems(homeItem, bookmarksItem, loginLogoutItem, aboutItem);
drawer = drawerBuilder.build(); drawer = drawerBuilder.build();
@ -352,7 +350,6 @@ public abstract class BaseActivity extends AppCompatActivity {
if (!sessionManager.isLoggedIn()) //When logged out or if user is guest if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
{ {
drawer.removeItem(DOWNLOADS_ID); drawer.removeItem(DOWNLOADS_ID);
drawer.removeItem(BOOKMARKS_ID);
loginLogoutItem.withName(R.string.login).withIcon(loginIcon); //Swap logout with login loginLogoutItem.withName(R.string.login).withIcon(loginIcon); //Swap logout with login
profileDrawerItem.withName(sessionManager.getUsername()).withIcon(new IconicsDrawable(this) profileDrawerItem.withName(sessionManager.getUsername()).withIcon(new IconicsDrawable(this)
.icon(FontAwesome.Icon.faw_user) .icon(FontAwesome.Icon.faw_user)
@ -432,7 +429,6 @@ public abstract class BaseActivity extends AppCompatActivity {
} }
protected void setBoardBookmark(final ImageButton thisPageBookmarkImageButton) { protected void setBoardBookmark(final ImageButton thisPageBookmarkImageButton) {
this.thisPageBookmarkImageButton = thisPageBookmarkImageButton;
if (thisPageBookmark.matchExists(boardsBookmarked)) { if (thisPageBookmark.matchExists(boardsBookmarked)) {
thisPageBookmarkImageButton.setImageDrawable(bookmarked); thisPageBookmarkImageButton.setImageDrawable(bookmarked);
} else { } else {

1
app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java

@ -14,7 +14,6 @@ import android.webkit.MimeTypeMap;
import java.io.File; import java.io.File;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.services.DownloadService.ACTION_DOWNLOAD; import static gr.thmmy.mthmmy.services.DownloadService.ACTION_DOWNLOAD;

1
app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java

@ -13,7 +13,6 @@ import java.io.IOException;
import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.receiver.Receiver; import gr.thmmy.mthmmy.receiver.Receiver;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;

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

@ -63,8 +63,8 @@
<!--Bookmarks--> <!--Bookmarks-->
<string name="remove_bookmark">Remove</string> <string name="remove_bookmark">Remove</string>
<string name="board_bookmarks_title">Your bookmarked boards:</string> <string name="board_bookmarks_title">Boards</string>
<string name="topic_bookmarks_title">Your bookmarked topics:</string> <string name="topic_bookmarks_title">Topics</string>
<!--Licences--> <!--Licences-->
<string name="libraries">Libraries</string> <string name="libraries">Libraries</string>

Loading…
Cancel
Save