Browse Source

Bug fixes

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
d5b520690a
  1. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  2. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java
  3. 25
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  4. 14
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  5. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  6. 14
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  7. 7
      app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java
  8. 3
      app/src/main/java/gr/thmmy/mthmmy/model/Category.java
  9. 1
      app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java
  10. 37
      app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java
  11. 22
      app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java
  12. 2
      app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java
  13. 2
      app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java
  14. 6
      app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/UnknownException.java
  15. 4
      app/src/main/res/layout/activity_topic_quick_reply_row.xml

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

@ -9,7 +9,6 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.Toast;
import gr.thmmy.mthmmy.R;

6
app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumAdapter.java

@ -36,7 +36,7 @@ class ForumAdapter extends ExpandableRecyclerAdapter<Category, Board, ForumAdapt
super(categories);
this.context = context;
this.categories = categories;
mListener = (ForumFragment.ForumFragmentInteractionListener)listener;
mListener = (ForumFragment.ForumFragmentInteractionListener) listener;
layoutInflater = LayoutInflater.from(context);
}
@ -68,7 +68,7 @@ class ForumAdapter extends ExpandableRecyclerAdapter<Category, Board, ForumAdapt
class CategoryViewHolder extends ParentViewHolder {
private TextView categoryTextview;
private final TextView categoryTextview;
CategoryViewHolder(View itemView) {
super(itemView);
@ -83,7 +83,7 @@ class ForumAdapter extends ExpandableRecyclerAdapter<Category, Board, ForumAdapt
class BoardViewHolder extends ChildViewHolder {
private TextView boardTextView;
private final TextView boardTextView;
public Board board;
BoardViewHolder(View itemView) {

25
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -18,7 +18,6 @@ import android.text.method.LinkMovementMethod;
import android.text.method.ScrollingMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.Menu;
@ -104,22 +103,23 @@ public class TopicActivity extends BaseActivity {
private static final int LARGE_STEP = 10;
private Integer pageRequestValue;
//Bottom navigation graphics
LinearLayout bottomNavBar;
private LinearLayout bottomNavBar;
private ImageButton firstPage;
private ImageButton previousPage;
private TextView pageIndicator;
private ImageButton nextPage;
private ImageButton lastPage;
//Topic's info
SpannableStringBuilder topicTreeAndMods = new SpannableStringBuilder("Loading..."),
private SpannableStringBuilder topicTreeAndMods = new SpannableStringBuilder("Loading..."),
topicViewers = new SpannableStringBuilder("Loading...");
//Other variables
private MaterialProgressBar progressBar;
TextView toolbarTitle;
private static String base_url = "";
private String topicTitle;
private String parsedTitle;
private RecyclerView recyclerView;
private String loadedPageUrl = "";
String loadedPageUrl = "";
private boolean reloadingPage = false;
@ -143,7 +143,7 @@ public class TopicActivity extends BaseActivity {
//Initializes graphics
toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
toolbarTitle.setText(topicTitle);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
@ -165,7 +165,7 @@ public class TopicActivity extends BaseActivity {
recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
topicAdapter = new TopicAdapter(this, postsList, topicTask, topicTitle);
topicAdapter = new TopicAdapter(this, postsList, topicTask, topicTitle, loadedPageUrl);
recyclerView.setAdapter(topicAdapter);
replyFAB = (FloatingActionButton) findViewById(R.id.topic_fab);
@ -271,7 +271,7 @@ public class TopicActivity extends BaseActivity {
* This class is used to implement the repetitive incrementPageRequestValue/decrementPageRequestValue
* of page value when long pressing one of the page navigation buttons.
*/
class RepetitiveUpdater implements Runnable {
private class RepetitiveUpdater implements Runnable {
private final int step;
/**
@ -490,14 +490,10 @@ public class TopicActivity extends BaseActivity {
return SAME_PAGE;
if (newPageUrl.contains("msg")) {
String tmpUrlSbstr = newPageUrl.substring(newPageUrl.indexOf("msg") + 3);
Log.d("TAG", tmpUrlSbstr);
if (tmpUrlSbstr.contains("msg"))
tmpUrlSbstr = tmpUrlSbstr.substring(0, tmpUrlSbstr.indexOf("msg") - 1);
Log.d("TAG", tmpUrlSbstr);
int testAgainst = Integer.parseInt(tmpUrlSbstr);
Log.d("TAG", "testAgainst = " + testAgainst);
for (Post post : postsList) {
Log.d("TAG", "post index = " + post.getPostIndex());
if (post.getPostIndex() == testAgainst) {
return SAME_PAGE;
}
@ -543,11 +539,11 @@ public class TopicActivity extends BaseActivity {
if (topicTitle == null || Objects.equals(topicTitle, "")) {
thisPageBookmark = new Bookmark(parsedTitle, ThmmyPage.getTopicId(loadedPageUrl));
invalidateOptionsMenu();
//setTopicBookmark(menu.getItem(0));
}
progressBar.setVisibility(ProgressBar.INVISIBLE);
topicAdapter.customNotifyDataSetChanged(new TopicTask());
topicAdapter.setTopicInfo(parsedTitle, loadedPageUrl);
if (replyPageUrl == null) replyFAB.hide();
if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true);
@ -557,8 +553,10 @@ public class TopicActivity extends BaseActivity {
paginationEnabled(true);
if (topicTitle != null)
if (parsedTitle != null)
if (topicTitle == null || Objects.equals(topicTitle, ""))
toolbar.setTitle(parsedTitle);
toolbarTitle.setText(parsedTitle);
break;
case NETWORK_ERROR:
Toast.makeText(getBaseContext(), "Network Error", Toast.LENGTH_SHORT).show();
@ -773,7 +771,6 @@ public class TopicActivity extends BaseActivity {
reloadingPage = true;
topicTask.execute(loadedPageUrl);
}
Log.d("TAG", "sent");
}
}
}

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

@ -105,13 +105,14 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private String[] replyDataHolder = new String[2];
private int replySubject = 0, replyText = 1;
private String loadedPageUrl = "";
/**
* @param context the context of the {@link RecyclerView}
* @param postsList List of {@link Post} objects to use
*/
TopicAdapter(Context context, List<Post> postsList, TopicActivity.TopicTask topicTask
, String topicTitle) {
, String topicTitle, String loadedPageUrl) {
this.context = context;
this.postsList = postsList;
@ -122,12 +123,18 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
this.topicTask = topicTask;
this.topicTitle = topicTitle;
this.loadedPageUrl = loadedPageUrl;
}
void prepareForReply(TopicActivity.ReplyTask replyTask) {
this.replyTask = replyTask;
}
void setTopicInfo(String topicTitle, String loadedPageUrl) {
this.topicTitle = topicTitle;
this.loadedPageUrl = loadedPageUrl;
}
@Override
public int getItemViewType(int position) {
return postsList.get(position) == null ? VIEW_TYPE_QUICK_REPLY : VIEW_TYPE_POST;
@ -712,7 +719,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
private class CustomEditTextListener implements TextWatcher {
private int positionInDataHolder;
private final int positionInDataHolder;
CustomEditTextListener(int positionInDataHolder) {
this.positionInDataHolder = positionInDataHolder;
@ -777,7 +784,8 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
if (postsList.get(quotePosition).getPostIndex() != 0) {
if (postDate != null) {
return "[quote author=" + postsList.get(quotePosition).getAuthor()
+ " link=topic=68525.msg" + postsList.get(quotePosition).getPostIndex()
+ " link=topic=" + ThmmyPage.getTopicId(loadedPageUrl) + ".msg"
+ postsList.get(quotePosition).getPostIndex()
+ "#msg" + postsList.get(quotePosition).getPostIndex()
+ " date=" + postDate.getTime() / 1000 + "]"
+ "\n" + postsList.get(quotePosition).getContent()

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

@ -200,8 +200,6 @@ class TopicParser {
p_postIndex = Integer.parseInt(tmp.substring(tmp.indexOf("msg") + 3));
} else{
postIndex = thisRow.select("div[id^=subject]").first();
Log.d("TAG", "got");
Log.d("TAG", postIndex.toString());
if (postIndex == null)
p_postIndex = NO_INDEX;
else{

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

@ -64,8 +64,8 @@ public abstract class BaseActivity extends AppCompatActivity {
private static final String BOOKMARKED_TOPICS_KEY = "bookmarkedTopicsKey";
private static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey";
protected Bookmark thisPageBookmark;
protected MenuItem thisPageBookmarkMenuButton;
protected ImageButton thisPageBookmarkImageButton;
private MenuItem thisPageBookmarkMenuButton;
private ImageButton thisPageBookmarkImageButton;
private SharedPreferences bookmarksFile;
private ArrayList<Bookmark> topicsBookmarked;
private ArrayList<Bookmark> boardsBookmarked;
@ -347,7 +347,7 @@ public abstract class BaseActivity extends AppCompatActivity {
});
}
protected void updateDrawer() {
private void updateDrawer() {
if (drawer != null) {
if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
{
@ -376,7 +376,7 @@ public abstract class BaseActivity extends AppCompatActivity {
* Result toast will always display a success, because when user chooses logout all data are
* cleared regardless of the actual outcome
*/
protected class LogoutTask extends AsyncTask<Void, Void, Integer> { //Attempt logout
private class LogoutTask extends AsyncTask<Void, Void, Integer> { //Attempt logout
ProgressDialog progressDialog;
protected Integer doInBackground(Void... voids) {
@ -419,7 +419,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}
}
protected void topicMenuBookmarkClick(){
protected void topicMenuBookmarkClick() {
if (thisPageBookmark.matchExists(topicsBookmarked)) {
thisPageBookmarkMenuButton.setIcon(notBookmarked);
toggleTopicToBookmarks(thisPageBookmark);
@ -524,7 +524,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}
//Display popup gor user to grant permission
public void requestPerms() { //Runtime permissions request for devices with API >= 23
private void requestPerms() { //Runtime permissions request for devices with API >= 23
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
@ -559,7 +559,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}
//Uses temp file - called after permission grant
public void launchDownloadService() {
private void launchDownloadService() {
if (checkPerms())
DownloadService.startActionDownload(this, tempThmmyFile.getFileUrl().toString());

7
app/src/main/java/gr/thmmy/mthmmy/base/BaseFragment.java

@ -15,7 +15,7 @@ public abstract class BaseFragment extends Fragment {
protected FragmentInteractionListener fragmentInteractionListener;
private String TAG;
protected int sectionNumber;
private int sectionNumber;
protected static OkHttpClient client;
@Override
@ -23,7 +23,7 @@ public abstract class BaseFragment extends Fragment {
super.onCreate(savedInstanceState);
TAG = getArguments().getString(ARG_TAG);
sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER);
if(client==null)
if (client == null)
client = BaseApplication.getInstance().getClient(); //must check every time - e.g.
// becomes null when app restarts after crash
Timber.d("onCreate");
@ -76,5 +76,6 @@ public abstract class BaseFragment extends Fragment {
* the activity that contains it, to allow communication upon interaction,
* between the fragment and the activity/ other fragments
*/
public interface FragmentInteractionListener {}
public interface FragmentInteractionListener {
}
}

3
app/src/main/java/gr/thmmy/mthmmy/model/Category.java

@ -7,8 +7,7 @@ import java.util.List;
import static android.R.attr.id;
public class Category implements Parent<Board>
{
public class Category implements Parent<Board> {
private final String title;
private final String categoryURL;
private boolean expanded = false;

1
app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java

@ -1,7 +1,6 @@
package gr.thmmy.mthmmy.model;
import android.net.Uri;
import android.util.Log;
import java.util.Objects;

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

@ -27,7 +27,7 @@ import timber.log.Timber;
*/
public class DownloadService extends IntentService {
private static final String TAG = "DownloadService";
private static int sDownloadId =0;
private static int sDownloadId = 0;
private Receiver receiver;
@ -48,7 +48,6 @@ public class DownloadService extends IntentService {
public static final String FAILED = "Failed";
public DownloadService() {
super("DownloadService");
}
@ -109,14 +108,12 @@ public class DownloadService extends IntentService {
Response response = client.newCall(request).execute();
String contentType = response.headers("Content-Type").toString(); //check if link provides a binary file
if(contentType.equals("[application/octet-stream]"))
{
if (contentType.equals("[application/octet-stream]")) {
fileName = response.headers("Content-Disposition").toString().split("\"")[1];
File dirPath = new File(SAVE_DIR);
if(!dirPath.isDirectory())
{
if(dirPath.mkdirs())
if (!dirPath.isDirectory()) {
if (dirPath.mkdirs())
Timber.i("mTHMMY's directory created successfully!");
else
Timber.e("Couldn't create mTHMMY's directory...");
@ -126,20 +123,16 @@ public class DownloadService extends IntentService {
String nameFormat;
String[] tokens = fileName.split("\\.(?=[^\\.]+$)");
if(tokens.length!=2)
{
if (tokens.length != 2) {
Timber.w("Couldn't get file extension...");
nameFormat = fileName + "(%d)";
}
else
} else
nameFormat = tokens[0] + "(%d)." + tokens[1];
File file = new File(dirPath, fileName);
for (int i = 1;;i++) {
for (int i = 1; ; i++) {
if (!file.exists()) {
break;
}
@ -157,21 +150,18 @@ public class DownloadService extends IntentService {
sink.flush();
Timber.i("Download OK!");
sendNotification(downloadId, COMPLETED, fileName);
}
else
} else
Timber.e("Response not a binary file!");
}
catch (FileNotFoundException e){
} catch (FileNotFoundException e) {
Timber.i("Download failed...");
Timber.e("FileNotFound", e);
sendNotification(downloadId, FAILED, fileName);
}
catch (IOException e){
} catch (IOException e) {
Timber.i("Download failed...");
Timber.e("IOException", e);
sendNotification(downloadId, FAILED, fileName);
} finally {
if (sink!= null) {
if (sink != null) {
try {
sink.close();
} catch (IOException e) {
@ -181,8 +171,7 @@ public class DownloadService extends IntentService {
}
}
private void sendNotification(int downloadId, String type, @NonNull String fileName)
{
private void sendNotification(int downloadId, String type, @NonNull String fileName) {
Intent intent = new Intent(ACTION_DOWNLOAD);
switch (type) {
case STARTED: {
@ -203,7 +192,7 @@ public class DownloadService extends IntentService {
intent.putExtra(EXTRA_NOTIFICATION_TICKER, "Download Failed");
break;
}
default:{
default: {
Timber.e("Invalid notification case!");
return;
}

22
app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java

@ -48,12 +48,12 @@ public class SessionManager {
public static final int EXCEPTION = 6;
// Client & Cookies
private OkHttpClient client;
private PersistentCookieJar cookieJar;
private SharedPrefsCookiePersistor cookiePersistor; //Used to explicitly edit cookies in cookieJar
private final OkHttpClient client;
private final PersistentCookieJar cookieJar;
private final SharedPrefsCookiePersistor cookiePersistor; //Used to explicitly edit cookies in cookieJar
//Shared Preferences & its keys
private SharedPreferences sharedPrefs;
private final SharedPreferences sharedPrefs;
private static final String USERNAME = "Username";
private static final String AVATAR_LINK = "AvatarLink";
private static final String HAS_AVATAR = "HasAvatar";
@ -109,7 +109,7 @@ public class SessionManager {
Elements unreadRepliesLinks = document.select("a[href=https://www.thmmy.gr/smf/index.php?action=unreadreplies]");
if (unreadRepliesLinks.size()>=2) //Normally it's just == 2, but who knows what can be posted by users
if (unreadRepliesLinks.size() >= 2) //Normally it's just == 2, but who knows what can be posted by users
{
Timber.i("Login successful!");
setPersistentCookieSession(); //Store cookies
@ -289,7 +289,7 @@ public class SessionManager {
}
@NonNull
private String extractUserName(@NonNull Document doc){
private String extractUserName(@NonNull Document doc) {
//Scribbles2 Theme
Elements user = doc.select("div[id=myuser] > h3");
String userName = null;
@ -301,8 +301,7 @@ public class SessionManager {
Matcher matcher = pattern.matcher(txt);
if (matcher.find())
userName = matcher.group(1);
}
else {
} else {
//Helios_Multi and SMF_oneBlue
user = doc.select("td.smalltext[width=100%] b");
if (user.size() == 1)
@ -315,7 +314,7 @@ public class SessionManager {
}
}
if(userName != null && !userName.isEmpty())
if (userName != null && !userName.isEmpty())
return userName;
Timber.e("ParseException", new ParseException("Parsing failed(username extraction)"));
@ -337,10 +336,9 @@ public class SessionManager {
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())
{
if (!logoutLink.isEmpty()) {
String link = logoutLink.first().attr("href");
if(link != null && !link.isEmpty())
if (link != null && !link.isEmpty())
return link;
}
Timber.e("ParseException", new ParseException("Parsing failed(logoutLink extraction)"));

2
app/src/main/java/gr/thmmy/mthmmy/utils/CenterVerticalSpan.java

@ -14,7 +14,7 @@ public class CenterVerticalSpan extends ReplacementSpan {
}
@Override
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom,@NonNull Paint paint) {
text = text.subSequence(start, end);
Rect charSize = new Rect();
paint.getTextBounds(text.toString(), 0, 1, charSize);

2
app/src/main/java/gr/thmmy/mthmmy/utils/ParseHelpers.java

@ -1,7 +1,5 @@
package gr.thmmy.mthmmy.utils;
import android.util.Log;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

6
app/src/main/java/gr/thmmy/mthmmy/utils/exceptions/UnknownException.java

@ -5,10 +5,10 @@ package gr.thmmy.mthmmy.utils.exceptions;
* exception is set, to report to FireBase.
*/
public class UnknownException extends Exception {
public UnknownException() {}
public UnknownException() {
}
public UnknownException(String message)
{
public UnknownException(String message) {
super(message);
}
}

4
app/src/main/res/layout/activity_topic_quick_reply_row.xml

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
@ -76,7 +77,8 @@
android:hint="@string/quick_reply_subject"
android:inputType="textMultiLine"
android:maxLength="80"
android:textSize="10sp"/>
android:textSize="10sp"
tools:ignore="SmallSp"/>
</RelativeLayout>
<LinearLayout

Loading…
Cancel
Save