Browse Source

Links inside topics behavior fix, recent topics scroll to bottom

pull/24/head
Apostolos Fanakis 7 years ago
parent
commit
c8cf10979e
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  2. 36
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  3. 20
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

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

@ -35,6 +35,7 @@ import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWN
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_FOCUS_TO_LAST_POST;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL;
@ -116,6 +117,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
Intent i = new Intent(MainActivity.this, TopicActivity.class);
i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl());
i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject());
i.putExtra(BUNDLE_FOCUS_TO_LAST_POST, true);
startActivity(i);
}

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

@ -81,6 +81,10 @@ public class TopicActivity extends BaseActivity {
* The key to use when putting topic's title String to {@link TopicActivity}'s Bundle.
*/
public static final String BUNDLE_TOPIC_TITLE = "TOPIC_TITLE";
/**
* The key to use when activity should scroll to bottom, for example when coming from recent.
*/
public static final String BUNDLE_FOCUS_TO_LAST_POST = "BUNDLE_FOCUS_TO_LAST_POST";
private static TopicTask topicTask;
private MaterialProgressBar progressBar;
private TextView toolbarTitle;
@ -103,6 +107,7 @@ public class TopicActivity extends BaseActivity {
* bundle one and gets rendered in the toolbar.
*/
private String parsedTitle;
private Boolean focusToLastPost;
private RecyclerView recyclerView;
/**
* Holds the url of this page
@ -203,6 +208,7 @@ public class TopicActivity extends BaseActivity {
Toast.makeText(this, "An error has occurred\n Aborting.", Toast.LENGTH_SHORT).show();
finish();
}
focusToLastPost = extras.getBoolean(BUNDLE_FOCUS_TO_LAST_POST);
thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl));
@ -246,7 +252,7 @@ public class TopicActivity extends BaseActivity {
CustomLinearLayoutManager layoutManager = new CustomLinearLayoutManager(
getApplicationContext(), loadedPageUrl);
recyclerView.setLayoutManager(layoutManager);
topicAdapter = new TopicAdapter(this, postsList, topicTask);
topicAdapter = new TopicAdapter(this, postsList, base_url, topicTask);
recyclerView.setAdapter(topicAdapter);
replyFAB = findViewById(R.id.topic_fab);
@ -594,6 +600,14 @@ public class TopicActivity extends BaseActivity {
Response response = client.newCall(request).execute();
document = Jsoup.parse(response.body().string());
localPostsList = parse(document);
//Finds the position of the focused message if present
for (int i = 0; i < localPostsList.size(); ++i) {
if (localPostsList.get(i).getPostIndex() == postFocus) {
postFocusPosition = i;
break;
}
}
return SUCCESS;
} catch (IOException e) {
Timber.i(e, "IO Exception");
@ -605,14 +619,6 @@ public class TopicActivity extends BaseActivity {
}
protected void onPostExecute(Integer parseResult) {
//Finds the position of the focused message if present
for (int i = 0; i < postsList.size(); ++i) {
if (postsList.get(i).getPostIndex() == postFocus) {
postFocusPosition = i;
break;
}
}
switch (parseResult) {
case SUCCESS:
if (topicTitle == null || Objects.equals(topicTitle, "")
@ -634,8 +640,8 @@ public class TopicActivity extends BaseActivity {
if (replyPageUrl == null) {
replyFAB.hide();
topicAdapter.resetTopic(new TopicTask(), false);
} else topicAdapter.resetTopic(new TopicTask(), true);
topicAdapter.resetTopic(base_url, new TopicTask(), false);
} else topicAdapter.resetTopic(base_url, new TopicTask(), true);
if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true);
@ -643,6 +649,10 @@ public class TopicActivity extends BaseActivity {
pageIndicator.setText(String.valueOf(thisPage) + "/" + String.valueOf(numberOfPages));
pageRequestValue = thisPage;
if (focusToLastPost) {
recyclerView.scrollToPosition(postsList.size() - 1);
}
paginationEnabled(true);
break;
case NETWORK_ERROR:
@ -652,8 +662,8 @@ public class TopicActivity extends BaseActivity {
progressBar.setVisibility(ProgressBar.INVISIBLE);
if (replyPageUrl == null) {
replyFAB.hide();
topicAdapter.resetTopic(new TopicTask(), false);
} else topicAdapter.resetTopic(new TopicTask(), true);
topicAdapter.resetTopic(base_url, new TopicTask(), false);
} else topicAdapter.resetTopic(base_url, new TopicTask(), true);
if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true);
paginationEnabled(true);
Toast.makeText(TopicActivity.this, "That's the same page.", Toast.LENGTH_SHORT).show();

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

@ -52,6 +52,7 @@ import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL;
import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_WHITE;
import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_YELLOW;
import static gr.thmmy.mthmmy.base.BaseActivity.getSessionManager;
@ -66,6 +67,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static int THUMBNAIL_SIZE;
private final Context context;
private String topicTitle;
private String baseUrl;
private final ArrayList<Integer> toQuoteList = new ArrayList<>();
private final List<Post> postsList;
/**
@ -97,9 +99,11 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
* @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) {
TopicAdapter(Context context, List<Post> postsList, String baseUrl,
TopicActivity.TopicTask topicTask) {
this.context = context;
this.postsList = postsList;
this.baseUrl = baseUrl;
THUMBNAIL_SIZE = (int) context.getResources().getDimension(R.dimen.thumbnail_size);
for (int i = 0; i < postsList.size(); ++i) {
@ -473,7 +477,8 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
}
void resetTopic(TopicActivity.TopicTask topicTask, boolean canReply) {
void resetTopic(String baseUrl, TopicActivity.TopicTask topicTask, boolean canReply) {
this.baseUrl = baseUrl;
this.topicTask = topicTask;
this.canReply = canReply;
viewProperties.clear();
@ -582,7 +587,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
if (target.is(ThmmyPage.PageCategory.TOPIC)) {
//This url points to a topic
//Checks if this is the current topic
/*if (Objects.equals(uriString.substring(0, uriString.lastIndexOf(".")), base_url)) {
if (Objects.equals(uriString.substring(0, uriString.lastIndexOf(".")), baseUrl)) {
//Gets uri's targeted message's index number
String msgIndexReq = uriString.substring(uriString.indexOf("msg") + 3);
if (msgIndexReq.contains("#"))
@ -597,9 +602,16 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
return true;
}
}
}*/
topicTask.execute(uri.toString());
}
Intent intent = new Intent(context, TopicActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_TOPIC_URL, uriString);
intent.putExtras(extras);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
return true;
} else if (target.is(ThmmyPage.PageCategory.BOARD)) {
Intent intent = new Intent(context, BoardActivity.class);

Loading…
Cancel
Save