From f51787cc4da29f55700ecc9d24add82ac009e465 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sun, 22 Jan 2017 13:29:29 +0200 Subject: [PATCH 1/6] Notifications fix --- .../main/java/gr/thmmy/mthmmy/receiver/Receiver.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java b/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java index 3f76766e..573ab018 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java +++ b/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java @@ -65,14 +65,15 @@ public class Receiver extends BroadcastReceiver { String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension( MimeTypeMap.getFileExtensionFromUrl(file.getAbsolutePath())); - Intent chooser = new Intent(); - chooser.setAction(android.content.Intent.ACTION_VIEW); - chooser.setDataAndType(Uri.fromFile(file), type); - chooser.setFlags(FLAG_ACTIVITY_NEW_TASK); - chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + Intent chooserIntent = new Intent(Intent.ACTION_VIEW); + chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + chooserIntent.setDataAndType(Uri.fromFile(file), type); + Intent chooser = Intent.createChooser(chooserIntent, "Open With..."); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, chooser, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(pendingIntent); + } else Report.w(TAG, "File doesn't exist."); } From 9dc2064ac1fbf33dcdcebe753d5f255a7602556a Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sun, 22 Jan 2017 15:16:39 +0200 Subject: [PATCH 2/6] Improved Report system, minor fixed in SessionManager, tiny tweaks --- .../main/recent/RecentFragment.java | 30 +++++------ .../gr/thmmy/mthmmy/receiver/Receiver.java | 5 +- .../mthmmy/services/DownloadService.java | 22 ++++---- .../thmmy/mthmmy/session/SessionManager.java | 51 ++++++++++--------- .../utils/exceptions/ParseException.java | 13 +++++ .../utils/exceptions/UnknownException.java | 14 +++++ app/src/release/java/mthmmy.utils/Report.java | 4 ++ 7 files changed, 84 insertions(+), 55 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/ParseException.java create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/UnknownException.java diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 546b2db3..7cd9ef63 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -27,6 +27,7 @@ import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.utils.CustomRecyclerView; +import gr.thmmy.mthmmy.utils.exceptions.ParseException; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import mthmmy.utils.Report; import okhttp3.HttpUrl; @@ -159,12 +160,15 @@ public class RecentFragment extends BaseFragment { document = Jsoup.parse(response.body().string()); parse(document); return 0; - } catch (IOException e) { - Report.d(TAG, "Network Error", e); + } catch (ParseException e) { + Report.e(TAG, "ParseException", e); return 1; - } catch (Exception e) { - Report.d(TAG, "Exception", e); + } catch (IOException e) { + Report.i(TAG, "Network Error", e); return 2; + } catch (Exception e) { + Report.e(TAG, "Exception", e); + return 3; } } @@ -174,14 +178,14 @@ public class RecentFragment extends BaseFragment { if (result == 0) recentAdapter.notifyDataSetChanged(); - else if (result == 1) + else if (result == 2) Toast.makeText(getActivity(), "Network error", Toast.LENGTH_SHORT).show(); progressBar.setVisibility(ProgressBar.INVISIBLE); swipeRefreshLayout.setRefreshing(false); } - private void parse(Document document) { + private void parse(Document document) throws ParseException { Elements recent = document.select("#block8 :first-child div"); if (!recent.isEmpty()) { topicSummaries.clear(); @@ -195,27 +199,23 @@ public class RecentFragment extends BaseFragment { Matcher matcher = pattern.matcher(lastUser); if (matcher.find()) lastUser = matcher.group(1); - else { - Report.e(TAG, "Parsing failed (lastUser)!"); - return; - } + else + throw new ParseException("Parsing failed (lastUser)"); String dateTime = recent.get(i + 2).text(); pattern = Pattern.compile("\\[(.*)\\]"); matcher = pattern.matcher(dateTime); if (matcher.find()) dateTime = matcher.group(1); - else { - Report.e(TAG, "Parsing failed (dateTime)!"); - return; - } + else + throw new ParseException("Parsing failed (dateTime)"); topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime)); } return; } - Report.e(TAG, "Parsing failed!"); + throw new ParseException("Parsing failed"); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java b/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java index 573ab018..3e811134 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java +++ b/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java @@ -16,12 +16,10 @@ import java.io.File; import gr.thmmy.mthmmy.R; import mthmmy.utils.Report; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static gr.thmmy.mthmmy.services.DownloadService.ACTION_DOWNLOAD; import static gr.thmmy.mthmmy.services.DownloadService.COMPLETED; import static gr.thmmy.mthmmy.services.DownloadService.EXTRA_DOWNLOAD_ID; import static gr.thmmy.mthmmy.services.DownloadService.EXTRA_DOWNLOAD_STATE; -import static gr.thmmy.mthmmy.services.DownloadService.EXTRA_FILE_EXTENSION; import static gr.thmmy.mthmmy.services.DownloadService.EXTRA_FILE_NAME; import static gr.thmmy.mthmmy.services.DownloadService.EXTRA_NOTIFICATION_TEXT; import static gr.thmmy.mthmmy.services.DownloadService.EXTRA_NOTIFICATION_TICKER; @@ -51,14 +49,13 @@ public class Receiver extends BroadcastReceiver { builder.setContentTitle(title) .setContentText(text) .setTicker(ticker) - .setAutoCancel(true) //??? + .setAutoCancel(true) .setSmallIcon(R.mipmap.ic_launcher); if (state.equals(STARTED)) builder.setOngoing(true); else if (state.equals(COMPLETED)) { String fileName = extras.getString(EXTRA_FILE_NAME, "NONE"); - String extension = extras.getString(EXTRA_FILE_EXTENSION, "extension"); File file = new File(SAVE_DIR, fileName); if (file.exists()) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java index 5eca8376..7339fa73 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java @@ -38,7 +38,6 @@ public class DownloadService extends IntentService { public static final String EXTRA_DOWNLOAD_ID = "gr.thmmy.mthmmy.services.extra.DOWNLOAD_ID"; public static final String EXTRA_DOWNLOAD_STATE = "gr.thmmy.mthmmy.services.extra.DOWNLOAD_STATE"; public static final String EXTRA_FILE_NAME = "gr.thmmy.mthmmy.services.extra.FILE_NAME"; - public static final String EXTRA_FILE_EXTENSION = "gr.thmmy.mthmmy.services.extra.FILE_EXTENSION"; public static final String EXTRA_NOTIFICATION_TITLE = "gr.thmmy.mthmmy.services.extra.NOTIFICATION_TITLE"; public static final String EXTRA_NOTIFICATION_TEXT = "gr.thmmy.mthmmy.services.extra.NOTIFICATION_TEXT"; public static final String EXTRA_NOTIFICATION_TICKER = "gr.thmmy.mthmmy.services.extra.NOTIFICATION_TICKER"; @@ -100,7 +99,7 @@ public class DownloadService extends IntentService { OkHttpClient client = BaseApplication.getInstance().getClient(); BufferedSink sink = null; String fileName = "file"; - String extension = "extension"; + int downloadId = sDownloadId; sDownloadId++; @@ -132,10 +131,8 @@ public class DownloadService extends IntentService { nameFormat = fileName + "(%d)"; } else - { nameFormat = tokens[0] + "(%d)." + tokens[1]; - extension = tokens[1]; - } + @@ -152,26 +149,26 @@ public class DownloadService extends IntentService { fileName = file.getName(); Report.v(TAG, "Started saving file " + fileName); - sendNotification(downloadId, STARTED, fileName, extension); + sendNotification(downloadId, STARTED, fileName); sink = Okio.buffer(Okio.sink(file)); sink.writeAll(response.body().source()); sink.flush(); Report.i(TAG, "Download OK!"); - sendNotification(downloadId, COMPLETED, fileName, extension); + sendNotification(downloadId, COMPLETED, fileName); } else Report.e(TAG, "Response not a binary file!"); } catch (FileNotFoundException e){ - Report.e(TAG, "FileNotFound", e); Report.i(TAG, "Download failed..."); - sendNotification(downloadId, FAILED, fileName, extension); + Report.e(TAG, "FileNotFound", e); + sendNotification(downloadId, FAILED, fileName); } catch (IOException e){ - Report.e(TAG, "IOException", e); Report.i(TAG, "Download failed..."); - sendNotification(downloadId, FAILED, fileName, extension); + Report.e(TAG, "IOException", e); + sendNotification(downloadId, FAILED, fileName); } finally { if (sink!= null) { try { @@ -183,7 +180,7 @@ public class DownloadService extends IntentService { } } - private void sendNotification(int downloadId, String type, @NonNull String fileName, String fileExtension) + private void sendNotification(int downloadId, String type, @NonNull String fileName) { Intent intent = new Intent(ACTION_DOWNLOAD); switch (type) { @@ -213,7 +210,6 @@ public class DownloadService extends IntentService { intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId); intent.putExtra(EXTRA_DOWNLOAD_STATE, type); intent.putExtra(EXTRA_FILE_NAME, fileName); - intent.putExtra(EXTRA_FILE_EXTENSION, fileExtension); sendBroadcast(intent); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java index d47e4969..2321b88a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java +++ b/app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import gr.thmmy.mthmmy.utils.exceptions.ParseException; import mthmmy.utils.Report; import okhttp3.Cookie; import okhttp3.FormBody; @@ -56,12 +57,12 @@ public class SessionManager { //Shared Preferences & its keys private SharedPreferences sharedPrefs; - public static final String USERNAME = "Username"; - public static final String AVATAR_LINK = "AvatarLink"; - public static final String HAS_AVATAR = "HasAvatar"; - public static final String LOGOUT_LINK = "LogoutLink"; - public static final String LOGGED_IN = "LoggedIn"; - public static final String LOGIN_SCREEN_AS_DEFAULT = "LoginScreenAsDefault"; + private static final String USERNAME = "Username"; + private static final String AVATAR_LINK = "AvatarLink"; + private static final String HAS_AVATAR = "HasAvatar"; + private static final String LOGOUT_LINK = "LogoutLink"; + private static final String LOGGED_IN = "LoggedIn"; + private static final String LOGIN_SCREEN_AS_DEFAULT = "LoginScreenAsDefault"; //Constructor public SessionManager(OkHttpClient client, PersistentCookieJar cookieJar, @@ -290,10 +291,11 @@ public class SessionManager { Report.i(TAG, "Session data cleared."); } - @Nullable - private String extractUserName(@NonNull Document doc) { + @NonNull + private String extractUserName(@NonNull Document doc){ //Scribbles2 Theme Elements user = doc.select("div[id=myuser] > h3"); + String userName = null; if (user.size() == 1) { String txt = user.first().ownText(); @@ -301,26 +303,26 @@ public class SessionManager { Pattern pattern = Pattern.compile(", (.*?),"); Matcher matcher = pattern.matcher(txt); if (matcher.find()) - return matcher.group(1); + userName = matcher.group(1); } - else - { + else { //Helios_Multi and SMF_oneBlue user = doc.select("td.smalltext[width=100%] b"); if (user.size() == 1) - return user.first().ownText(); - else - { + userName = user.first().ownText(); + else { //SMF Default Theme user = doc.select("td.titlebg2[height=32] b"); if (user.size() == 1) - return user.first().ownText(); + userName = user.first().ownText(); } } + + if(userName != null && !userName.isEmpty()) + return userName; - - Report.e(TAG, "Extracting username failed!"); - return null; + Report.e(TAG, "ParseException", new ParseException("Parsing failed(username extraction)")); + return "User"; //return a default username } @@ -334,15 +336,18 @@ public class SessionManager { return null; } - @Nullable + @NonNull private String extractLogoutLink(@NonNull Document doc) { Elements logoutLink = doc.select("a[href^=https://www.thmmy.gr/smf/index.php?action=logout;sesc=]"); if (!logoutLink.isEmpty()) - return logoutLink.first().attr("href"); - - Report.e(TAG, "Extracting logout link failed!"); - return null; + { + String link = logoutLink.first().attr("href"); + if(link != null && !link.isEmpty()) + return link; + } + Report.e(TAG, "ParseException", new ParseException("Parsing failed(logoutLink extraction)")); + return "https://www.thmmy.gr/smf/index.php?action=logout"; //return a default link } //----------------------------------OTHER FUNCTIONS END----------------------------------------- diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/ParseException.java b/app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/ParseException.java new file mode 100644 index 00000000..b0947f04 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/ParseException.java @@ -0,0 +1,13 @@ +package gr.thmmy.mthmmy.utils.exceptions; + +/** + * ParseException is to be used for errors while parsing. + */ +public class ParseException extends Exception { + public ParseException() {} + + public ParseException(String message) + { + super(message); + } +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/UnknownException.java b/app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/UnknownException.java new file mode 100644 index 00000000..fc0e7f65 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/UnknownException.java @@ -0,0 +1,14 @@ +package gr.thmmy.mthmmy.utils.exceptions; + +/** + * UnknownException is thrown upon an error (see Report.java in release), when no other specific + * exception is set, to report to FireBase. + */ +public class UnknownException extends Exception { + public UnknownException() {} + + public UnknownException(String message) + { + super(message); + } +} diff --git a/app/src/release/java/mthmmy.utils/Report.java b/app/src/release/java/mthmmy.utils/Report.java index ce2ea89d..138afd92 100644 --- a/app/src/release/java/mthmmy.utils/Report.java +++ b/app/src/release/java/mthmmy.utils/Report.java @@ -2,6 +2,8 @@ package mthmmy.utils; import com.google.firebase.crash.FirebaseCrash; +import gr.thmmy.mthmmy.utils.exceptions.UnknownException; + public class Report { @@ -68,6 +70,8 @@ public class Report private static void log(String level, String TAG, String message) { FirebaseCrash.log(level + "/" + TAG + ": " + message); + if(level.equals("E")||level.equals("WTF")) //report only serious exceptions + FirebaseCrash.report(new UnknownException("UnknownException")); } private static void exception(String level, String TAG, String message, Throwable tr) From 97ca4fa9879f49365a7f73144d8fa75469e47c5a Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sun, 22 Jan 2017 18:57:01 +0200 Subject: [PATCH 3/6] Intent filter, user's personal text and links targeting topics fixes. --- app/src/main/AndroidManifest.xml | 3 ++ .../mthmmy/activities/main/MainActivity.java | 1 - .../activities/profile/ProfileActivity.java | 11 ++-- .../activities/topic/TopicActivity.java | 7 ++- .../mthmmy/activities/topic/TopicAdapter.java | 51 ++++++++++--------- .../java/gr/thmmy/mthmmy/model/ThmmyPage.java | 3 +- 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1ad2d90b..f95392f4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,6 +46,9 @@ + + tbody:nth-child(1) > tr:nth-child(2) tr"). first().select("td").last().text(); } - Log.d(TAG, "thumbnailUrl = " + thumbnailUrl); if (thumbnailUrl == null || Objects.equals(thumbnailUrl, "")) { //Maybe there is an avatar - Log.d(TAG, "thumbnailUrl = " + thumbnailUrl); Element profileAvatar = profilePage .select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) img.avatar") .first(); if (profileAvatar != null) thumbnailUrl = profileAvatar.attr("abs:src"); } - Log.d(TAG, "thumbnailUrl = " + thumbnailUrl); - ; - { //Finds personal text Element tmpEl = profilePage.select("td.windowbg:nth-child(2)").first(); if (tmpEl != null) { @@ -294,7 +288,10 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment , R.drawable.ic_default_user_thumbnail, null)) .transform(new CircleTransform()) .into(thumbnailView); - if (personalText != null) personalTextView.setText(personalText); + if (personalText != null) { + personalTextView.setText(personalText); + personalTextView.setVisibility(View.VISIBLE); + } setupViewPager(viewPager, profilePage); TabLayout tabLayout = (TabLayout) findViewById(R.id.profile_tabs); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index 8bf4c7ac..8ca6f707 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -9,6 +9,7 @@ import android.support.design.widget.FloatingActionButton; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; +import android.util.Log; import android.util.SparseArray; import android.view.MotionEvent; import android.view.View; @@ -432,10 +433,9 @@ public class TopicActivity extends BaseActivity { postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf("#"))); } } - //Checks if the page to be loaded is the one already shown if (!Objects.equals(loadedPageUrl, "") && loadedPageUrl.contains(base_url)) { - if (newPageUrl.contains("topicseen#new")) + if (newPageUrl.contains("topicseen#new") || newPageUrl.contains("#new")) if (thisPage == numberOfPages) return SAME_PAGE; if (newPageUrl.contains("msg")) { @@ -448,8 +448,7 @@ public class TopicActivity extends BaseActivity { return SAME_PAGE; } } - } - if (Integer.parseInt(newPageUrl.substring(base_url.length() + 1)) / 15 + 1 == thisPage) + } else if (Integer.parseInt(newPageUrl.substring(base_url.length() + 1)) / 15 + 1 == thisPage) return SAME_PAGE; } else if (!Objects.equals(loadedPageUrl, "")) topicTitle = null; 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 b03b56e5..2ea65fb9 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 @@ -389,30 +389,35 @@ class TopicAdapter extends RecyclerView.Adapter { holder.subject.setMaxLines(1); holder.subject.setEllipsize(TextUtils.TruncateAt.END); } - if (viewProperties.get(position)[isQuoteButtonChecked]) - holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); - else - holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); - //Sets graphics behavior - holder.quoteToggle.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); - if (tmp[isQuoteButtonChecked]) { - if (toQuoteList.contains(currentPost.getPostNumber())) { - toQuoteList.remove(toQuoteList.indexOf(currentPost.getPostNumber())); - } else - Report.i(TAG, "An error occurred while trying to exclude post from" + - "toQuoteList, post wasn't there!"); - holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); - } else { - toQuoteList.add(currentPost.getPostNumber()); - holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); + //noinspection PointlessBooleanExpression,ConstantConditions + if (!BaseActivity.getSessionManager().isLoggedIn() || true) //Hide it until reply is implemented + holder.quoteToggle.setVisibility(View.GONE); + else { + if (viewProperties.get(position)[isQuoteButtonChecked]) + holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); + else + holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); + //Sets graphics behavior + holder.quoteToggle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); + if (tmp[isQuoteButtonChecked]) { + if (toQuoteList.contains(currentPost.getPostNumber())) { + toQuoteList.remove(toQuoteList.indexOf(currentPost.getPostNumber())); + } else + Report.i(TAG, "An error occurred while trying to exclude post from" + + "toQuoteList, post wasn't there!"); + holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); + } else { + toQuoteList.add(currentPost.getPostNumber()); + holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); + } + tmp[isQuoteButtonChecked] = !tmp[isQuoteButtonChecked]; + viewProperties.set(holder.getAdapterPosition(), tmp); } - tmp[isQuoteButtonChecked] = !tmp[isQuoteButtonChecked]; - viewProperties.set(holder.getAdapterPosition(), tmp); - } - }); + }); + } //Card expand/collapse when card is touched holder.cardView.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java b/app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java index c4bc5272..cc9a1781 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java @@ -140,7 +140,8 @@ public class ThmmyPage { final String host = uri.getHost(); final String uriString = uri.toString(); - if (Objects.equals(uriString, "thmmy.gr")) return PageCategory.INDEX; + if (Objects.equals(uriString, "http://thmmy.gr") + || Objects.equals(uriString, "https://thmmy.gr")) return PageCategory.INDEX; if (Objects.equals(host, "www.thmmy.gr")) { if (uriString.contains("topic=")) return PageCategory.TOPIC; else if (uriString.contains("board=")) return PageCategory.BOARD; From 20277c687876831f1c7fd0e6549e7a5d13d529e5 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sun, 22 Jan 2017 20:39:25 +0200 Subject: [PATCH 4/6] Report levels V and D no longer logged in FireBase. Updated CONTRIBUTING.md --- CONTRIBUTING.md | 32 ++++++------------- app/src/release/java/mthmmy.utils/Report.java | 18 +++++++---- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f1102015..8bc96da1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,47 +15,33 @@ There are many ways of contributing to mTHMMY: - Simply using the latest release version - Joining our [Discord server][discord-server] -- Creating issues & joining discussions on our [Issue Tracker][issue-tracker] +- Submiting bugs and ideas on our [Trello board][trello-board] - Getting code access to fork mTHMMY and submit [merge requests](#merge-requests) - Joining our core team - Contacting us by email at `thmmynolife@gmail.com` ## Issue tracker -The [mTHMMY issue tracker on GitLab.com][issue-tracker] is for [bugs](#bugs) concerning the latest mTHMMY release and [improvements](#improvements). - -Before submitting an issue please **[search the issue tracker][issue-tracker]** for similar entries and if you don't find any create your own conforming to the simple issue submission guidelines listed below. - -### Bugs - -Please submit bugs using the ['Bug' issue template](.gitlab/issue_templates/Bug.md) provided on the issue tracker and the [`Bug`](https://gitlab.com/thmmy.gr/mTHMMY/issues?label_name=Bug) label. - -### Improvements - -Please submit improvements/ feature proposals using the ['Improvement' issue template](.gitlab/issue_templates/Improvement.md) provided on the issue tracker and the [`Improvement`](https://gitlab.com/thmmy.gr/mTHMMY/issues?label_name=Improvement) label. - -### Issue weight - -Issue weight represents the amount of work required for an issue, as an abstract measurement of its complexity. You are encouraged to discuss and set the weight of any issue to what makes most sense. -For example, something that has a weight of 1 (or no weight) is really small and simple. -Something that is 9 is a very complex issue requiring to (re)write big parts of code. +The [mTHMMY Board on trello.com][trello-board] is used as an Issue Tracker, for bugs and improvements concerning the available mTHMMY releases. +Before creating a card to submit an issue please **[search the board][trello-board]** for similar entries. ## Merge requests -Merge requests with fixes and improvements to mTHMMY are most welcome. The simple workflow to make a merge request is as follows: +Merge requests with fixes and improvements to mTHMMY are most welcome. Any developer that wants to work independently from the core team can simply +follow the workflow below to make a merge request: +1. Request and get access to the repository 1. Fork the project into your personal space on GitLab.com -1. Create a feature branch, branch away from `master` +1. Create a feature branch, branch away from `develop` 1. Push the commit(s) to your fork -1. Create a merge request (MR) targeting `master` [at mTHMMY](https://gitlab.com/thmmy.gr/mTHMMY/tree/master) +1. Create a merge request (MR) targeting `develop` [at mTHMMY](https://gitlab.com/ThmmyNoLife/mTHMMY/tree/develop) 1. Fill the MR title describing the change you want to make 1. Fill the MR description with a brief motive for your change and the method you used to achieve it. 1. Submit the MR. -*This guide was inspired by [Gitlab CE's Contributing Guide][gitlab-contributing-guide].* -[issue-tracker]: https://gitlab.com/thmmy.gr/mTHMMY/issues +[trello-board]: https://trello.com/invite/b/4MVlkrkg/44a931707bd0b84a5e0bdfc42b9ae4f1/mthmmy [discord-server]: https://discord.gg/CVt3yrn [gitlab-contributing-guide]: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md diff --git a/app/src/release/java/mthmmy.utils/Report.java b/app/src/release/java/mthmmy.utils/Report.java index 138afd92..4a6a46b8 100644 --- a/app/src/release/java/mthmmy.utils/Report.java +++ b/app/src/release/java/mthmmy.utils/Report.java @@ -69,16 +69,22 @@ public class Report private static void log(String level, String TAG, String message) { - FirebaseCrash.log(level + "/" + TAG + ": " + message); - if(level.equals("E")||level.equals("WTF")) //report only serious exceptions - FirebaseCrash.report(new UnknownException("UnknownException")); + if(!level.equals("V")&&!level.equals("D")) //don't log V and D levels + { + FirebaseCrash.log(level + "/" + TAG + ": " + message); + if(level.equals("E")||level.equals("WTF")) //report only serious exceptions + FirebaseCrash.report(new UnknownException("UnknownException")); + } } private static void exception(String level, String TAG, String message, Throwable tr) { - FirebaseCrash.log(level + "/" + TAG + ": " + message + ": " + tr.getMessage()); - if(level.equals("E")||level.equals("WTF")) //report only serious exceptions - FirebaseCrash.report(tr); + if(!level.equals("V")&&!level.equals("D")) //don't log V and D levels + { + FirebaseCrash.log(level + "/" + TAG + ": " + message + ": " + tr.getMessage()); + if(level.equals("E")||level.equals("WTF")) //report only serious exceptions + FirebaseCrash.report(tr); + } } /** From 03cc7ec475ba55d8d0fe05f5e2117eb8f9ce592b Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sun, 22 Jan 2017 23:05:48 +0200 Subject: [PATCH 5/6] User profile dot sign --- .../activities/profile/ProfileActivity.java | 41 +++++++++++++++---- .../profile/summary/SummaryFragment.java | 2 + .../mthmmy/utils/CenterVerticalSpan.java | 20 +++++++++ .../main/res/layout-v21/activity_profile.xml | 1 + app/src/main/res/layout/activity_profile.xml | 1 + app/src/main/res/values/strings.xml | 1 + 6 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java index 19c63ea9..60fea8d3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java @@ -1,6 +1,8 @@ package gr.thmmy.mthmmy.activities.profile; import android.content.Intent; +import android.graphics.Color; +import android.graphics.Typeface; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -12,7 +14,11 @@ import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.content.res.ResourcesCompat; import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; -import android.util.Log; +import android.text.Spannable; +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; @@ -24,6 +30,7 @@ import com.squareup.picasso.Picasso; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import java.util.ArrayList; import java.util.List; @@ -39,6 +46,7 @@ import gr.thmmy.mthmmy.activities.topic.TopicActivity; import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.model.PostSummary; 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 mthmmy.utils.Report; @@ -128,6 +136,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment .transform(new CircleTransform()) .into(thumbnailView); usernameView = (TextView) findViewById(R.id.profile_activity_username); + usernameView.setTypeface(Typeface.createFromAsset(this.getAssets() + , "fonts/fontawesome-webfont.ttf")); if (username != null && !Objects.equals(username, "")) usernameView.setText(username); personalTextView = (TextView) findViewById(R.id.profile_activity_personal_text); @@ -217,6 +227,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment @SuppressWarnings("unused") private static final String TAG = "ProfileTask"; //Separate tag for AsyncTask Document profilePage; + Spannable usernameSpan; protected void onPreExecute() { progressBar.setVisibility(ProgressBar.VISIBLE); @@ -232,16 +243,14 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment try { Response response = client.newCall(request).execute(); profilePage = Jsoup.parse(response.body().string()); + Elements contentsTable = profilePage.select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2)"); + //Finds username if missing if (username == null || Objects.equals(username, "")) { - username = profilePage. - select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tr"). - first().select("td").last().text(); + username = contentsTable.select("tr").first().select("td").last().text(); } if (thumbnailUrl == null || Objects.equals(thumbnailUrl, "")) { //Maybe there is an avatar - Element profileAvatar = profilePage - .select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) img.avatar") - .first(); + Element profileAvatar = contentsTable.select("img.avatar").first(); if (profileAvatar != null) thumbnailUrl = profileAvatar.attr("abs:src"); } { //Finds personal text @@ -255,6 +264,21 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment personalText = null; } } + { //Finds status + usernameSpan = new SpannableString(getResources() + .getString(R.string.fa_circle) + " " + username); + usernameSpan.setSpan(new CenterVerticalSpan(), 0, 2, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + usernameSpan.setSpan(new RelativeSizeSpan(0.45f) + , 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + if (contentsTable.toString().contains("Online") + || contentsTable.toString().contains("Συνδεδεμένος")) { + usernameSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#4CAF50")) + , 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } else + usernameSpan.setSpan(new ForegroundColorSpan(Color.GRAY) + , 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } return true; } catch (SSLHandshakeException e) { Report.w(TAG, "Certificate problem (please switch to unsafe connection)."); @@ -275,7 +299,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(true); progressBar.setVisibility(ProgressBar.INVISIBLE); - if (usernameView.getText() != username) usernameView.setText(username); + if (usernameSpan != null) usernameView.setText(usernameSpan); + else if (usernameView.getText() != username) usernameView.setText(username); if (thumbnailUrl != null && !Objects.equals(thumbnailUrl, "")) //noinspection ConstantConditions Picasso.with(getApplicationContext()) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java index 1236b5a0..a2a0eea9 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java @@ -148,6 +148,8 @@ public class SummaryFragment extends Fragment { if (summaryRow.select("td").size() == 1) //Horizontal rule rows pHtml = ""; + else if (summaryRow.text().contains("Current Status") + || summaryRow.text().contains("Κατάσταση")) continue; else if (rowText.contains("Signature") || rowText.contains("Υπογραφή")) { //This needs special handling since it may have css pHtml = ParseHelpers.youtubeEmbeddedFix(summaryRow); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java new file mode 100644 index 00000000..949a9736 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java @@ -0,0 +1,20 @@ +package gr.thmmy.mthmmy.utils; + +import android.text.TextPaint; +import android.text.style.SuperscriptSpan; +import android.util.Log; + +public class CenterVerticalSpan extends SuperscriptSpan { + public CenterVerticalSpan() { + } + + @Override + public void updateDrawState(TextPaint textPaint) { + textPaint.baselineShift -= 7f; + } + + @Override + public void updateMeasureState(TextPaint tp) { + updateDrawState(tp); + } +} \ No newline at end of file diff --git a/app/src/main/res/layout-v21/activity_profile.xml b/app/src/main/res/layout-v21/activity_profile.xml index 44f5917b..21a187bd 100644 --- a/app/src/main/res/layout-v21/activity_profile.xml +++ b/app/src/main/res/layout-v21/activity_profile.xml @@ -68,6 +68,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" + android:paddingBottom="2dp" android:text="@string/username" android:textColor="@color/accent" android:textSize="25sp"/> diff --git a/app/src/main/res/layout/activity_profile.xml b/app/src/main/res/layout/activity_profile.xml index be02134e..81b3aea7 100644 --- a/app/src/main/res/layout/activity_profile.xml +++ b/app/src/main/res/layout/activity_profile.xml @@ -67,6 +67,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" + android:paddingBottom="2dp" android:text="@string/username" android:textColor="@color/accent" android:textSize="25sp"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1640a038..dffad4fe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -85,4 +85,5 @@ + From af803d78950a9da6f3eacda7929104c7cb655cb3 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sun, 22 Jan 2017 23:18:35 +0200 Subject: [PATCH 6/6] Updated version to 1.1.2 --- CONTRIBUTING.md | 3 ++- VERSION | 2 +- app/build.gradle | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8bc96da1..e28d7593 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,8 @@ vulnerabilities, please report them in private to There are many ways of contributing to mTHMMY: -- Simply using the latest release version +- Simply using the latest release version (anonymous reports are sent automatically) +- Becoming an alpha or beta tester - Joining our [Discord server][discord-server] - Submiting bugs and ideas on our [Trello board][trello-board] - Getting code access to fork mTHMMY and submit [merge requests](#merge-requests) diff --git a/VERSION b/VERSION index 9084fa2f..45a1b3f4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.0 +1.1.2 diff --git a/app/build.gradle b/app/build.gradle index dca03e46..bbf5b90d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "gr.thmmy.mthmmy" minSdkVersion 19 targetSdkVersion 25 - versionCode 4 - versionName "1.1.1" + versionCode 5 + versionName "1.1.2" archivesBaseName = "mTHMMY-v$versionName" }