Browse Source

Bookmarks work for guests too, minor tweaks.

pull/24/head
Ezerous 8 years ago
parent
commit
5c6a7d03d8
  1. 181
      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. 56
      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

181
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;
public class BookmarkActivity extends BaseActivity {
private TextView boardsTitle;
private TextView topicsTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -43,93 +45,100 @@ public class BookmarkActivity extends BaseActivity {
LinearLayout bookmarksLinearView = (LinearLayout) findViewById(R.id.bookmarks_container);
LayoutInflater layoutInflater = getLayoutInflater();
TextView tmp = new TextView(this);
tmp.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT));
tmp.setText(getString(R.string.board_bookmarks_title));
tmp.setTypeface(tmp.getTypeface(), Typeface.BOLD);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
tmp.setTextColor(getColor(R.color.primary_text));
} else {
//noinspection deprecation
tmp.setTextColor(getResources().getColor(R.color.primary_text));
}
tmp.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tmp.setTextSize(20f);
bookmarksLinearView.addView(tmp);
if(!getBoardsBookmarked().isEmpty()) {
boardsTitle = new TextView(this);
boardsTitle.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT));
boardsTitle.setText(getString(R.string.board_bookmarks_title));
boardsTitle.setTypeface(boardsTitle.getTypeface(), Typeface.BOLD);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
boardsTitle.setTextColor(getColor(R.color.primary_text));
} else {
//noinspection deprecation
boardsTitle.setTextColor(getResources().getColor(R.color.primary_text));
}
boardsTitle.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
boardsTitle.setTextSize(20f);
bookmarksLinearView.addView(boardsTitle);
for (final Bookmark bookmarkedBoard : getBoardsBookmarked()) {
if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate(
R.layout.activity_bookmark_row, bookmarksLinearView, false);
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(BookmarkActivity.this, BoardActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_BOARD_URL, "https://www.thmmy.gr/smf/index.php?board="
+ bookmarkedBoard.getId() + ".0");
extras.putString(BUNDLE_BOARD_TITLE, bookmarkedBoard.getTitle());
intent.putExtras(extras);
startActivity(intent);
finish();
}
});
((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedBoard.getTitle());
(row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
removeBookmark(bookmarkedBoard);
row.setVisibility(View.GONE);
}
});
bookmarksLinearView.addView(row);
for (final Bookmark bookmarkedBoard : getBoardsBookmarked()) {
if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate(
R.layout.activity_bookmark_row, bookmarksLinearView, false);
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(BookmarkActivity.this, BoardActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_BOARD_URL, "https://www.thmmy.gr/smf/index.php?board="
+ bookmarkedBoard.getId() + ".0");
extras.putString(BUNDLE_BOARD_TITLE, bookmarkedBoard.getTitle());
intent.putExtras(extras);
startActivity(intent);
finish();
}
});
((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedBoard.getTitle());
(row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
removeBookmark(bookmarkedBoard);
row.setVisibility(View.GONE);
updateTitles();
}
});
bookmarksLinearView.addView(row);
}
}
}
tmp = new TextView(this);
tmp.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT));
tmp.setText(getString(R.string.topic_bookmarks_title));
tmp.setTypeface(tmp.getTypeface(), Typeface.BOLD);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
tmp.setTextColor(getColor(R.color.primary_text));
} else {
//noinspection deprecation
tmp.setTextColor(getResources().getColor(R.color.primary_text));
}
tmp.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tmp.setTextSize(20f);
bookmarksLinearView.addView(tmp);
for (final Bookmark bookmarkedTopic : getTopicsBookmarked()) {
if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate(
R.layout.activity_bookmark_row, bookmarksLinearView, false);
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(BookmarkActivity.this, TopicActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_TOPIC_URL, "https://www.thmmy.gr/smf/index.php?topic="
+ bookmarkedTopic.getId() + "." + 2147483647);
extras.putString(BUNDLE_TOPIC_TITLE, bookmarkedTopic.getTitle());
intent.putExtras(extras);
startActivity(intent);
finish();
}
});
((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedTopic.getTitle());
(row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
removeBookmark(bookmarkedTopic);
row.setVisibility(View.GONE);
}
});
bookmarksLinearView.addView(row);
if(!getTopicsBookmarked().isEmpty()) {
topicsTitle = new TextView(this);
topicsTitle.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT));
topicsTitle.setText(getString(R.string.topic_bookmarks_title));
topicsTitle.setTypeface(topicsTitle.getTypeface(), Typeface.BOLD);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
topicsTitle.setTextColor(getColor(R.color.primary_text));
} else {
//noinspection deprecation
topicsTitle.setTextColor(getResources().getColor(R.color.primary_text));
}
topicsTitle.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
topicsTitle.setTextSize(20f);
bookmarksLinearView.addView(topicsTitle);
for (final Bookmark bookmarkedTopic : getTopicsBookmarked()) {
if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate(
R.layout.activity_bookmark_row, bookmarksLinearView, false);
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(BookmarkActivity.this, TopicActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_TOPIC_URL, "https://www.thmmy.gr/smf/index.php?topic="
+ bookmarkedTopic.getId() + "." + 2147483647);
extras.putString(BUNDLE_TOPIC_TITLE, bookmarkedTopic.getTitle());
intent.putExtras(extras);
startActivity(intent);
finish();
}
});
((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedTopic.getTitle());
(row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
removeBookmark(bookmarkedTopic);
row.setVisibility(View.GONE);
updateTitles();
}
});
bookmarksLinearView.addView(row);
}
}
}
}
@ -139,4 +148,12 @@ public class BookmarkActivity extends BaseActivity {
drawer.setSelection(BOOKMARKS_ID);
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.activities.main.MainActivity;
import gr.thmmy.mthmmy.base.BaseActivity;
import timber.log.Timber;
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.ThmmyPage;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Request;
import okhttp3.Response;
import timber.log.Timber;

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

@ -210,13 +210,12 @@ public class ForumFragment extends BaseFragment
fetchedCategories.add(category);
}
categories.clear();
categories.addAll(fetchedCategories);
fetchedCategories.clear();
}
else
throw new ParseException("Parsing failed");
categories.clear();
categories.addAll(fetchedCategories);
fetchedCategories.clear();
}
@Override

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");
if (!recent.isEmpty()) {
topicSummaries.clear();
for (int i = 0; i < recent.size(); i += 3) {
String link = recent.get(i).child(0).attr("href");
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));
}
return;
}
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.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.widget.ImageView;
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.CircleTransform;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Request;
import okhttp3.Response;
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.utils.ParseHelpers;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Request;
import okhttp3.Response;
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.base.BaseActivity;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Request;
import okhttp3.Response;
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.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -25,7 +24,6 @@ import java.util.Objects;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.utils.ParseHelpers;
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.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.MotionEvent;
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.ThmmyPage;
import gr.thmmy.mthmmy.utils.CircleTransform;
import timber.log.Timber;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

56
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";
protected Bookmark thisPageBookmark;
private MenuItem thisPageBookmarkMenuButton;
private ImageButton thisPageBookmarkImageButton;
private SharedPreferences bookmarksFile;
private ArrayList<Bookmark> topicsBookmarked;
private ArrayList<Bookmark> boardsBookmarked;
@ -86,25 +85,23 @@ public abstract class BaseActivity extends AppCompatActivity {
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();
}
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
@ -221,14 +218,6 @@ 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)
@ -237,6 +226,15 @@ public abstract class BaseActivity extends AppCompatActivity {
.withIcon(loginIcon)
.withSelectable(false);
bookmarksItem = new PrimaryDrawerItem()
.withTextColor(primaryColor)
.withSelectedColor(selectedPrimaryColor)
.withSelectedTextColor(selectedSecondaryColor)
.withIdentifier(BOOKMARKS_ID)
.withName(R.string.bookmark)
.withIcon(bookmarksIcon)
.withSelectedIcon(bookmarksIconSelected);
aboutItem = new PrimaryDrawerItem()
.withTextColor(primaryColor)
.withSelectedColor(selectedPrimaryColor)
@ -333,7 +331,7 @@ public abstract class BaseActivity extends AppCompatActivity {
if (sessionManager.isLoggedIn())
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, loginLogoutItem, aboutItem);
else
drawerBuilder.addDrawerItems(homeItem, loginLogoutItem, aboutItem);
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, loginLogoutItem, aboutItem);
drawer = drawerBuilder.build();
@ -352,7 +350,6 @@ public abstract class BaseActivity extends AppCompatActivity {
if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
{
drawer.removeItem(DOWNLOADS_ID);
drawer.removeItem(BOOKMARKS_ID);
loginLogoutItem.withName(R.string.login).withIcon(loginIcon); //Swap logout with login
profileDrawerItem.withName(sessionManager.getUsername()).withIcon(new IconicsDrawable(this)
.icon(FontAwesome.Icon.faw_user)
@ -432,7 +429,6 @@ public abstract class BaseActivity extends AppCompatActivity {
}
protected void setBoardBookmark(final ImageButton thisPageBookmarkImageButton) {
this.thisPageBookmarkImageButton = thisPageBookmarkImageButton;
if (thisPageBookmark.matchExists(boardsBookmarked)) {
thisPageBookmarkImageButton.setImageDrawable(bookmarked);
} 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 gr.thmmy.mthmmy.R;
import timber.log.Timber;
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.receiver.Receiver;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

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

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

Loading…
Cancel
Save