Browse Source

Bookmarks finalization.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
45af916332
  1. 106
      app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java
  2. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  3. 5
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  4. 32
      app/src/main/res/layout/activity_bookmark_row.xml
  5. 7
      app/src/main/res/values/strings.xml

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

@ -1,16 +1,29 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.board.BoardActivity;
import gr.thmmy.mthmmy.activities.topic.TopicActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.Bookmark;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL;
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 { public class BookmarkActivity extends BaseActivity {
ProgressBar progressBar; ProgressBar progressBar;
@ -30,32 +43,103 @@ public class BookmarkActivity extends BaseActivity {
createDrawer(); createDrawer();
drawer.setSelection(BOOKMARKS_ID); drawer.setSelection(BOOKMARKS_ID);
progressBar = (MaterialProgressBar) findViewById(R.id.progressBar); progressBar = (MaterialProgressBar) findViewById(R.id.progressBar);
LinearLayout bookmarksLinearView = (LinearLayout) findViewById(R.id.bookmarks_container); LinearLayout bookmarksLinearView = (LinearLayout) findViewById(R.id.bookmarks_container);
LayoutInflater layoutInflater = getLayoutInflater();
TextView tmp = new TextView(this); TextView tmp = new TextView(this);
tmp.setText("Your bookmarked boards:"); 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); bookmarksLinearView.addView(tmp);
for (Bookmark bookmarkedBoard : getBoardsBookmarked()) { for (final Bookmark bookmarkedBoard : getBoardsBookmarked()) {
if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) { if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) {
TextView bookmarkedBoardView = new TextView(this); Log.d("TAG", bookmarkedBoard.getTitle() + " - " + bookmarkedBoard.getId());
bookmarkedBoardView.setText(bookmarkedBoard.getTitle()); final LinearLayout row = (LinearLayout) layoutInflater.inflate(
bookmarksLinearView.addView(bookmarkedBoardView); R.layout.activity_bookmark_row, bookmarksLinearView, false);
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("TAG", "https://www.thmmy.gr/smf/index.php?board="
+ bookmarkedBoard.getId() + ".0");
Log.d("TAG", bookmarkedBoard.getTitle());
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);
} }
} }
tmp = new TextView(this); tmp = new TextView(this);
tmp.setText("Your bookmarked topics:"); 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); bookmarksLinearView.addView(tmp);
for (Bookmark bookmarkedTopic : getTopicsBookmarked()) { for (final Bookmark bookmarkedTopic : getTopicsBookmarked()) {
if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) { if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) {
TextView bookmarkedTopicView = new TextView(this); Log.d("TAG", bookmarkedTopic.getTitle() + " - " + bookmarkedTopic.getId());
bookmarkedTopicView.setText(bookmarkedTopic.getTitle()); final LinearLayout row = (LinearLayout) layoutInflater.inflate(
bookmarksLinearView.addView(bookmarkedTopicView); 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() + ".0");
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);
} }
} }
} }

2
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

@ -91,7 +91,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
} }
thisPageBookmark = new Bookmark(boardTitle, boardUrl); thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl));
thisPageBookmarkButton = (ImageButton) findViewById(R.id.bookmark); thisPageBookmarkButton = (ImageButton) findViewById(R.id.bookmark);
setBoardBookmark(); setBoardBookmark();
createDrawer(); createDrawer();

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

@ -498,6 +498,11 @@ public abstract class BaseActivity extends AppCompatActivity {
SharedPreferences.Editor editor = bookmarksFile.edit(); SharedPreferences.Editor editor = bookmarksFile.edit();
editor.putString(BOOKMARKED_TOPICS_KEY, tmpString).apply(); editor.putString(BOOKMARKED_TOPICS_KEY, tmpString).apply();
} }
protected void removeBookmark(Bookmark bookmark) {
if (bookmark.matchExists(boardsBookmarked)) toggleBoardToBookmarks(bookmark);
else if (bookmark.matchExists(topicsBookmarked)) toggleTopicToBookmarks(bookmark);
}
//-------------------------------------------BOOKMARKS END------------------------------------------ //-------------------------------------------BOOKMARKS END------------------------------------------
//-------PERMS--------- //-------PERMS---------

32
app/src/main/res/layout/activity_bookmark_row.xml

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bookmark_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:paddingEnd="16dp"
android:paddingStart="16dp">
<TextView
android:id="@+id/bookmark_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="2dp"
android:textColor="@color/primary_text"
android:textSize="18sp"/>
<ImageButton
android:id="@+id/remove_bookmark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/remove_bookmark"
android:src="@drawable/ic_remove_circle"/>
</LinearLayout>

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

@ -56,7 +56,12 @@
<!--About Activity--> <!--About Activity-->
<string name="version">v%1$s</string> <string name="version">v%1$s</string>
<string name="logo">Logo</string> <string name="logo">Logo</string>
<string name="trollPic">You should watch a funny pic!</string> <string name="trollPic">You should see a funny pic!</string>
<!--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>
<!--Licences--> <!--Licences-->
<string name="libraries">Libraries</string> <string name="libraries">Libraries</string>

Loading…
Cancel
Save