Browse Source

Version 1.6.1

master v1.6.1
Ezerous 6 years ago
parent
commit
fb2a5ccda1
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 8
      app/build.gradle
  2. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java
  3. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksBoardFragment.java
  4. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksTopicFragment.java
  5. 15
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java
  6. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java
  7. 12
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java
  8. 13
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  9. 10
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  10. 4
      app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java
  11. 44
      app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java
  12. 12
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java

8
app/build.gradle

@ -13,8 +13,8 @@ android {
applicationId "gr.thmmy.mthmmy" applicationId "gr.thmmy.mthmmy"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 28 targetSdkVersion 28
versionCode 15 versionCode 16
versionName "1.6.0" versionName "1.6.1"
archivesBaseName = "mTHMMY-v$versionName" archivesBaseName = "mTHMMY-v$versionName"
buildConfigField "String", "CURRENT_BRANCH", "\"" + getCurrentBranch() + "\"" buildConfigField "String", "CURRENT_BRANCH", "\"" + getCurrentBranch() + "\""
buildConfigField "String", "COMMIT_HASH", "\"" + getCommitHash() + "\"" buildConfigField "String", "COMMIT_HASH", "\"" + getCommitHash() + "\""
@ -62,7 +62,7 @@ tasks.whenTaskAdded { task ->
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.preference:preference:1.1.0-alpha01' implementation 'androidx.preference:preference:1.1.0-alpha02'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0' implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
@ -72,7 +72,7 @@ dependencies {
implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-core:16.0.6' implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4' implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
implementation 'com.squareup.okhttp3:okhttp:3.12.0' implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.squareup.picasso:picasso:2.5.2' implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'

4
app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksActivity.java

@ -47,8 +47,8 @@ public class BookmarksActivity extends BaseActivity {
//Creates the adapter that will return a fragment for each section of the activity //Creates the adapter that will return a fragment for each section of the activity
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
sectionsPagerAdapter.addFragment(BookmarksTopicFragment.newInstance(1, Bookmark.arrayToString(getTopicsBookmarked())), "Topics"); sectionsPagerAdapter.addFragment(BookmarksTopicFragment.newInstance(1, Bookmark.arrayListToString(getTopicsBookmarked())), "Topics");
sectionsPagerAdapter.addFragment(BookmarksBoardFragment.newInstance(2, Bookmark.arrayToString(getBoardsBookmarked())), "Boards"); sectionsPagerAdapter.addFragment(BookmarksBoardFragment.newInstance(2, Bookmark.arrayListToString(getBoardsBookmarked())), "Boards");
//Sets up the ViewPager with the sections adapter. //Sets up the ViewPager with the sections adapter.
ViewPager viewPager = findViewById(R.id.bookmarks_container); ViewPager viewPager = findViewById(R.id.bookmarks_container);

2
app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksBoardFragment.java

@ -62,7 +62,7 @@ public class BookmarksBoardFragment extends Fragment {
if (getArguments() != null) { if (getArguments() != null) {
String bundledBoardBookmarks = getArguments().getString(ARG_BOARD_BOOKMARKS); String bundledBoardBookmarks = getArguments().getString(ARG_BOARD_BOOKMARKS);
if (bundledBoardBookmarks != null) { if (bundledBoardBookmarks != null) {
boardBookmarks = Bookmark.arrayFromString(bundledBoardBookmarks); boardBookmarks = Bookmark.stringToArrayList(bundledBoardBookmarks);
} }
} }

2
app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarksTopicFragment.java

@ -63,7 +63,7 @@ public class BookmarksTopicFragment extends Fragment {
if (getArguments() != null) { if (getArguments() != null) {
String bundledTopicBookmarks = getArguments().getString(ARG_TOPIC_BOOKMARKS); String bundledTopicBookmarks = getArguments().getString(ARG_TOPIC_BOOKMARKS);
if (bundledTopicBookmarks != null) { if (bundledTopicBookmarks != null) {
topicBookmarks = Bookmark.arrayFromString(bundledTopicBookmarks); topicBookmarks = Bookmark.stringToArrayList(bundledTopicBookmarks);
} }
} }

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

@ -56,13 +56,12 @@ public class StatsFragment extends Fragment {
private ProfileStatsTask profileStatsTask; private ProfileStatsTask profileStatsTask;
private LinearLayout mainContent; private LinearLayout mainContent;
private MaterialProgressBar progressBar; private MaterialProgressBar progressBar;
private boolean haveParsed = false;
private boolean userHasPosts = true; private boolean userHasPosts = true;
private String generalStatisticsTitle = "", generalStatistics = "", postingActivityByTimeTitle = "", mostPopularBoardsByPostsTitle = "", mostPopularBoardsByActivityTitle = ""; private String generalStatisticsTitle = "", generalStatistics = "", postingActivityByTimeTitle = "", mostPopularBoardsByPostsTitle = "", mostPopularBoardsByActivityTitle = "";
final private List<Entry> postingActivityByTime = new ArrayList<>(); private final List<Entry> postingActivityByTime = new ArrayList<>();
final private List<BarEntry> mostPopularBoardsByPosts = new ArrayList<>(), mostPopularBoardsByActivity = new ArrayList<>(); private final List<BarEntry> mostPopularBoardsByPosts = new ArrayList<>(), mostPopularBoardsByActivity = new ArrayList<>();
final private ArrayList<String> mostPopularBoardsByPostsLabels = new ArrayList<>(), mostPopularBoardsByActivityLabels = new ArrayList<>(); private final ArrayList<String> mostPopularBoardsByPostsLabels = new ArrayList<>(), mostPopularBoardsByActivityLabels = new ArrayList<>();
public StatsFragment() { public StatsFragment() {
// Required empty public constructor // Required empty public constructor
@ -95,7 +94,7 @@ public class StatsFragment extends Fragment {
final View rootView = inflater.inflate(R.layout.fragment_stats, container, false); final View rootView = inflater.inflate(R.layout.fragment_stats, container, false);
mainContent = rootView.findViewById(R.id.main_content); mainContent = rootView.findViewById(R.id.main_content);
progressBar = rootView.findViewById(R.id.progressBar); progressBar = rootView.findViewById(R.id.progressBar);
if (haveParsed) if (profileStatsTask!=null && profileStatsTask.getStatus() == AsyncTask.Status.FINISHED)
populateLayout(); populateLayout();
return rootView; return rootView;
} }
@ -103,7 +102,7 @@ public class StatsFragment extends Fragment {
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
if (!haveParsed) { if (profileStatsTask==null) {
profileStatsTask = new ProfileStatsTask(); profileStatsTask = new ProfileStatsTask();
profileStatsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileUrl + ";sa=statPanel"); profileStatsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, profileUrl + ";sa=statPanel");
} }
@ -130,7 +129,6 @@ public class StatsFragment extends Fragment {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
progressBar.setVisibility(ProgressBar.VISIBLE); progressBar.setVisibility(ProgressBar.VISIBLE);
haveParsed = true;
} }
@Override @Override
@ -159,7 +157,6 @@ public class StatsFragment extends Fragment {
getActivity().finish(); getActivity().finish();
} }
//Parse was successful //Parse was successful
progressBar.setVisibility(ProgressBar.INVISIBLE);
populateLayout(); populateLayout();
} }
@ -233,6 +230,7 @@ public class StatsFragment extends Fragment {
} }
private void populateLayout() { private void populateLayout() {
progressBar.setVisibility(ProgressBar.VISIBLE);
((TextView) mainContent.findViewById(R.id.general_statistics_title)) ((TextView) mainContent.findViewById(R.id.general_statistics_title))
.setText(generalStatisticsTitle); .setText(generalStatisticsTitle);
((TextView) mainContent.findViewById(R.id.general_statistics)) ((TextView) mainContent.findViewById(R.id.general_statistics))
@ -358,6 +356,7 @@ public class StatsFragment extends Fragment {
mostPopularBoardsByActivityData.setValueTextColor(Color.WHITE); mostPopularBoardsByActivityData.setValueTextColor(Color.WHITE);
mostPopularBoardsByActivityChart.setData(mostPopularBoardsByActivityData); mostPopularBoardsByActivityChart.setData(mostPopularBoardsByActivityData);
mostPopularBoardsByActivityChart.invalidate(); mostPopularBoardsByActivityChart.invalidate();
progressBar.setVisibility(ProgressBar.INVISIBLE);
} }
private class MyXAxisValueFormatter implements IAxisValueFormatter { private class MyXAxisValueFormatter implements IAxisValueFormatter {

10
app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java

@ -26,12 +26,10 @@ public class ShoutboxActivity extends BaseActivity {
createDrawer(); createDrawer();
drawer.setSelection(SHOUTBOX_ID); drawer.setSelection(SHOUTBOX_ID);
if (savedInstanceState == null) { shoutboxFragment = ShoutboxFragment.newInstance();
shoutboxFragment = ShoutboxFragment.newInstance(); getSupportFragmentManager().beginTransaction()
getSupportFragmentManager().beginTransaction() .replace(R.id.container, shoutboxFragment)
.replace(R.id.container, shoutboxFragment) .commitNow();
.commitNow();
}
} }
@Override @Override

12
app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java

@ -1,7 +1,6 @@
package gr.thmmy.mthmmy.activities.shoutbox; package gr.thmmy.mthmmy.activities.shoutbox;
import android.app.Activity; import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -22,7 +21,6 @@ import gr.thmmy.mthmmy.editorview.EditorView;
import gr.thmmy.mthmmy.editorview.EmojiKeyboard; import gr.thmmy.mthmmy.editorview.EmojiKeyboard;
import gr.thmmy.mthmmy.model.Shout; import gr.thmmy.mthmmy.model.Shout;
import gr.thmmy.mthmmy.model.Shoutbox; import gr.thmmy.mthmmy.model.Shoutbox;
import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.CustomRecyclerView; import gr.thmmy.mthmmy.utils.CustomRecyclerView;
import gr.thmmy.mthmmy.utils.NetworkResultCodes; import gr.thmmy.mthmmy.utils.NetworkResultCodes;
import gr.thmmy.mthmmy.viewmodel.ShoutboxViewModel; import gr.thmmy.mthmmy.viewmodel.ShoutboxViewModel;
@ -32,7 +30,6 @@ import timber.log.Timber;
public class ShoutboxFragment extends Fragment { public class ShoutboxFragment extends Fragment {
private MaterialProgressBar progressBar; private MaterialProgressBar progressBar;
private ShoutboxTask shoutboxTask;
private ShoutAdapter shoutAdapter; private ShoutAdapter shoutAdapter;
private EmojiKeyboard emojiKeyboard; private EmojiKeyboard emojiKeyboard;
private EditorView editorView; private EditorView editorView;
@ -90,7 +87,7 @@ public class ShoutboxFragment extends Fragment {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_refresh) { if (item.getItemId() == R.id.menu_refresh) {
shoutboxViewModel.loadShoutbox(); shoutboxViewModel.loadShoutbox(true);
return true; return true;
} else { } else {
return false; return false;
@ -100,7 +97,7 @@ public class ShoutboxFragment extends Fragment {
@Override @Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) { public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
shoutboxViewModel = ViewModelProviders.of(this).get(ShoutboxViewModel.class); shoutboxViewModel = ViewModelProviders.of(getActivity()).get(ShoutboxViewModel.class);
shoutboxViewModel.getShoutboxMutableLiveData().observe(this, shoutbox -> { shoutboxViewModel.getShoutboxMutableLiveData().observe(this, shoutbox -> {
if (shoutbox != null) { if (shoutbox != null) {
Timber.i("Shoutbox loaded successfully"); Timber.i("Shoutbox loaded successfully");
@ -113,7 +110,7 @@ public class ShoutboxFragment extends Fragment {
shoutboxViewModel.setOnSendShoutTaskStarted(this::onSendShoutTaskStarted); shoutboxViewModel.setOnSendShoutTaskStarted(this::onSendShoutTaskStarted);
shoutboxViewModel.setOnSendShoutTaskFinished(this::onSendShoutTaskFinished); shoutboxViewModel.setOnSendShoutTaskFinished(this::onSendShoutTaskFinished);
shoutboxViewModel.loadShoutbox(); shoutboxViewModel.loadShoutbox(false);
} }
private void onShoutboxTaskSarted() { private void onShoutboxTaskSarted() {
@ -137,8 +134,7 @@ public class ShoutboxFragment extends Fragment {
if (resultCode == NetworkResultCodes.SUCCESSFUL) { if (resultCode == NetworkResultCodes.SUCCESSFUL) {
Timber.i("Shout was sent successfully"); Timber.i("Shout was sent successfully");
editorView.getEditText().getText().clear(); editorView.getEditText().getText().clear();
shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); shoutboxViewModel.loadShoutbox(true);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Failed to send shout"); Timber.w("Failed to send shout");
Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show();

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

@ -275,6 +275,13 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
} else { } else {
// Showing results // Showing results
holder.optionsLayout.setVisibility(View.GONE); holder.optionsLayout.setVisibility(View.GONE);
if (poll.getSelectedEntryIndex() != -1) {
holder.selectedEntry.setText("You voted \"" +
poll.getEntries()[poll.getSelectedEntryIndex()].getEntryName() + "\"");
holder.selectedEntry.setVisibility(View.VISIBLE);
}
Arrays.sort(entries, (p1, p2) -> p1.getVotes() - p2.getVotes()); Arrays.sort(entries, (p1, p2) -> p1.getVotes() - p2.getVotes());
List<BarEntry> valuesToCompare = new ArrayList<>(); List<BarEntry> valuesToCompare = new ArrayList<>();
int totalVotes = 0; int totalVotes = 0;
@ -320,12 +327,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
holder.voteChart.setMinimumHeight((int) (chartHeightDp * (metrics.densityDpi / 160f))); holder.voteChart.setMinimumHeight((int) (chartHeightDp * (metrics.densityDpi / 160f)));
holder.voteChart.invalidate(); holder.voteChart.invalidate();
holder.voteChart.setVisibility(View.VISIBLE); holder.voteChart.setVisibility(View.VISIBLE);
if (poll.getSelectedEntryIndex() != -1) {
holder.selectedEntry.setText("You voted \"" +
poll.getEntries()[poll.getSelectedEntryIndex()].getEntryName() + "\"");
holder.selectedEntry.setVisibility(View.VISIBLE);
}
} }
if (poll.getRemoveVoteUrl() != null) { if (poll.getRemoveVoteUrl() != null) {
holder.removeVotesButton.setOnClickListener(v -> viewModel.removeVote()); holder.removeVotesButton.setOnClickListener(v -> viewModel.removeVote());

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

@ -85,7 +85,7 @@ public abstract class BaseActivity extends AppCompatActivity {
//Bookmarks //Bookmarks
public static final String BOOKMARKS_SHARED_PREFS = "bookmarksSharedPrefs"; public static final String BOOKMARKS_SHARED_PREFS = "bookmarksSharedPrefs";
public static final String BOOKMARKED_TOPICS_KEY = "bookmarkedTopicsKey"; public static final String BOOKMARKED_TOPICS_KEY = "bookmarkedTopicsKey";
private static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey"; public static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey";
protected Bookmark thisPageBookmark; protected Bookmark thisPageBookmark;
private MenuItem thisPageBookmarkMenuButton; private MenuItem thisPageBookmarkMenuButton;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
@ -584,13 +584,13 @@ public abstract class BaseActivity extends AppCompatActivity {
private void loadSavedBookmarks() { private void loadSavedBookmarks() {
String tmpString = bookmarksFile.getString(BOOKMARKED_TOPICS_KEY, null); String tmpString = bookmarksFile.getString(BOOKMARKED_TOPICS_KEY, null);
if (tmpString != null) if (tmpString != null)
topicsBookmarked = Bookmark.arrayFromString(tmpString); topicsBookmarked = Bookmark.stringToArrayList(tmpString);
else else
topicsBookmarked = new ArrayList<>(); topicsBookmarked = new ArrayList<>();
tmpString = bookmarksFile.getString(BOOKMARKED_BOARDS_KEY, null); tmpString = bookmarksFile.getString(BOOKMARKED_BOARDS_KEY, null);
if (tmpString != null) if (tmpString != null)
boardsBookmarked = Bookmark.arrayFromString(tmpString); boardsBookmarked = Bookmark.stringToArrayList(tmpString);
else { else {
boardsBookmarked = new ArrayList<>(); boardsBookmarked = new ArrayList<>();
} }
@ -622,14 +622,14 @@ public abstract class BaseActivity extends AppCompatActivity {
private void updateBoardBookmarks() { private void updateBoardBookmarks() {
String tmpString; String tmpString;
tmpString = Bookmark.arrayToString(boardsBookmarked); tmpString = Bookmark.arrayListToString(boardsBookmarked);
SharedPreferences.Editor editor = bookmarksFile.edit(); SharedPreferences.Editor editor = bookmarksFile.edit();
editor.putString(BOOKMARKED_BOARDS_KEY, tmpString).apply(); editor.putString(BOOKMARKED_BOARDS_KEY, tmpString).apply();
} }
private void updateTopicBookmarks() { private void updateTopicBookmarks() {
String tmpString; String tmpString;
tmpString = Bookmark.arrayToString(topicsBookmarked); tmpString = Bookmark.arrayListToString(topicsBookmarked);
SharedPreferences.Editor editor = bookmarksFile.edit(); SharedPreferences.Editor editor = bookmarksFile.edit();
editor.putString(BOOKMARKED_TOPICS_KEY, tmpString).apply(); editor.putString(BOOKMARKED_TOPICS_KEY, tmpString).apply();
} }

4
app/src/main/java/gr/thmmy/mthmmy/model/Bookmark.java

@ -69,7 +69,7 @@ public class Bookmark implements java.io.Serializable {
} }
@Nullable @Nullable
public static String arrayToString(@NonNull ArrayList<Bookmark> arrayList) { public static String arrayListToString(@NonNull ArrayList<Bookmark> arrayList) {
String returnString = ""; String returnString = "";
for (Bookmark bookmark : arrayList) { for (Bookmark bookmark : arrayList) {
if (bookmark != null) { if (bookmark != null) {
@ -82,7 +82,7 @@ public class Bookmark implements java.io.Serializable {
else return null; else return null;
} }
public static ArrayList<Bookmark> arrayFromString(@NonNull String string) { public static ArrayList<Bookmark> stringToArrayList(@NonNull String string) {
ArrayList<Bookmark> returnArray = new ArrayList<>(); ArrayList<Bookmark> returnArray = new ArrayList<>();
String[] lines = string.split("\n"); String[] lines = string.split("\n");
for (String line : lines) { for (String line : lines) {

44
app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java

@ -19,6 +19,10 @@ import com.google.firebase.messaging.RemoteMessage;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -36,6 +40,7 @@ import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SELECTED_RING
import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SETTINGS_SHARED_PREFS; import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SETTINGS_SHARED_PREFS;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; 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;
import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKED_BOARDS_KEY;
import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKED_TOPICS_KEY; import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKED_TOPICS_KEY;
import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKS_SHARED_PREFS; import static gr.thmmy.mthmmy.base.BaseActivity.BOOKMARKS_SHARED_PREFS;
import static gr.thmmy.mthmmy.model.Bookmark.matchExistsById; import static gr.thmmy.mthmmy.model.Bookmark.matchExistsById;
@ -61,15 +66,27 @@ public class NotificationService extends FirebaseMessagingService {
Timber.i("FCM BOARD type message detected."); Timber.i("FCM BOARD type message detected.");
SharedPreferences bookmarksFile = getSharedPreferences(BOOKMARKS_SHARED_PREFS, Context.MODE_PRIVATE); SharedPreferences bookmarksFile = getSharedPreferences(BOOKMARKS_SHARED_PREFS, Context.MODE_PRIVATE);
String tmpString = bookmarksFile.getString(BOOKMARKED_TOPICS_KEY, null); String bookmarkedTopicsString = bookmarksFile.getString(BOOKMARKED_TOPICS_KEY, null);
if (tmpString != null){ if (bookmarkedTopicsString != null && matchExistsById(Bookmark.stringToArrayList(bookmarkedTopicsString), topicId)){
if(matchExistsById(Bookmark.arrayFromString(tmpString), topicId)){ Timber.i("Board notification suppressed (already subscribed to topic).");
Timber.i("Board notification suppressed (already subscribed to topic)."); return;
return;
}
} }
boardId = Integer.parseInt(json.getString("boardId")); boardId = Integer.parseInt(json.getString("boardId"));
String bookmarkedBoardsString = bookmarksFile.getString(BOOKMARKED_BOARDS_KEY, null);
if (bookmarkedBoardsString != null){
ArrayList<Bookmark> boardBookmarks = Bookmark.stringToArrayList(bookmarkedBoardsString);
ArrayList<Integer> subBoardIds = getSubBoardIds(json.getString("boardIds"), boardId);
//TODO: Also suppress if user has chosen to be notified only for direct children of boardId && !subBoardIds.isEmpty()
for(int subId:subBoardIds){
if(matchExistsById(boardBookmarks, subId)){
Timber.i("Board notification suppressed (already subscribed to a subBoard).");
return;
}
}
}
boardTitle = json.getString("boardTitle"); boardTitle = json.getString("boardTitle");
} }
else else
@ -88,6 +105,21 @@ public class NotificationService extends FirebaseMessagingService {
} }
} }
private static ArrayList<Integer> getSubBoardIds(String boardIdsString, int boardId){
ArrayList<Integer> subBoardIds = new ArrayList<>();
Pattern p = Pattern.compile("(\\d+)");
Matcher m = p.matcher(boardIdsString);
boolean boardIdfound=false;
while (m.find()){
int subBoardId = Integer.parseInt(m.group());
if(boardIdfound)
subBoardIds.add(subBoardId);
else if(boardId==subBoardId)
boardIdfound=true;
}
return subBoardIds;
}
private static final String CHANNEL_ID = "Posts"; private static final String CHANNEL_ID = "Posts";
private static final String CHANNEL_NAME = "New Posts"; private static final String CHANNEL_NAME = "New Posts";
private static final String GROUP_KEY = "PostsGroup"; private static final String GROUP_KEY = "PostsGroup";

12
app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java

@ -17,11 +17,13 @@ public class ShoutboxViewModel extends ViewModel {
private SendShoutTask.OnTaskStartedListener onSendShoutTaskStarted; private SendShoutTask.OnTaskStartedListener onSendShoutTaskStarted;
private SendShoutTask.OnNetworkTaskFinishedListener<Void> onSendShoutTaskFinished; private SendShoutTask.OnNetworkTaskFinishedListener<Void> onSendShoutTaskFinished;
public void loadShoutbox() { public void loadShoutbox(boolean force) {
if (shoutboxTask != null && shoutboxTask.getStatus() == AsyncTask.Status.RUNNING) if (shoutboxMutableLiveData.getValue() == null || force) {
shoutboxTask.cancel(true); if (shoutboxTask != null && shoutboxTask.getStatus() == AsyncTask.Status.RUNNING)
shoutboxTask = new ShoutboxTask(onShoutboxTaskStarted, onShoutboxTaskFinished); shoutboxTask.cancel(true);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); shoutboxTask = new ShoutboxTask(onShoutboxTaskStarted, onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
}
} }
public void sendShout(String shout) { public void sendShout(String shout) {

Loading…
Cancel
Save