From 399f6d418b921d24ff718056a96bcd62b4e8ccba Mon Sep 17 00:00:00 2001 From: Apostolof Date: Tue, 13 Dec 2016 19:59:54 +0200 Subject: [PATCH] Adapter swap on topic's page change (instead of activity restart). --- .../activities/topic/TopicActivity.java | 33 +++++++------------ .../mthmmy/activities/topic/TopicAdapter.java | 4 +-- 2 files changed, 14 insertions(+), 23 deletions(-) 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 9f1633d3..092d6629 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 @@ -7,8 +7,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.support.design.widget.FloatingActionButton; -import android.support.v4.app.ActivityOptionsCompat; -import android.support.v4.util.Pair; import android.support.v7.app.AlertDialog; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -79,6 +77,8 @@ public class TopicActivity extends BaseActivity { private String topicTitle; private FloatingActionButton replyFAB; private String parsedTitle; + private RecyclerView recyclerView; + private RecyclerView.LayoutManager layoutManager; @Override protected void onCreate(Bundle savedInstanceState) { @@ -101,7 +101,6 @@ public class TopicActivity extends BaseActivity { postsList = new ArrayList<>(); - firstPage = (ImageButton) findViewById(R.id.page_first_button); previousPage = (ImageButton) findViewById(R.id.page_previous_button); pageIndicator = (TextView) findViewById(R.id.page_indicator); @@ -166,6 +165,12 @@ public class TopicActivity extends BaseActivity { } }); + recyclerView = (RecyclerView)findViewById(R.id.topic_recycler_view); + recyclerView.setHasFixedSize(true); + layoutManager = new LinearLayoutManager(getApplicationContext()); + recyclerView.setLayoutManager(layoutManager); + recyclerView.setAdapter(new TopicAdapter(getApplicationContext(), postsList)); + new TopicTask().execute(extras.getString("TOPIC_URL")); //Attempt data parsing } @@ -292,17 +297,7 @@ public class TopicActivity extends BaseActivity { private void changePage(int pageRequested) { if (pageRequested != thisPage - 1) { - //Restart activity with new page - Pair p1 = Pair.create((View) replyFAB, "fab"); - Pair p2 = Pair.create((View) toolbar, "toolbar"); - ActivityOptionsCompat options = ActivityOptionsCompat. - makeSceneTransitionAnimation(this, p1, p2); - - Intent intent = getIntent(); - intent.putExtra("TOPIC_URL", pagesUrls.get(pageRequested)); - intent.putExtra("TOPIC_TITLE", topicTitle); - startActivity(intent, options.toBundle()); - finish(); + new TopicTask().execute(pagesUrls.get(pageRequested)); //Attempt data parsing } } //------------------------------------BOTTOM NAV BAR METHODS END------------------------------------ @@ -315,6 +310,7 @@ public class TopicActivity extends BaseActivity { //Show a progress bar until done protected void onPreExecute() { progressBar.setVisibility(ProgressBar.VISIBLE); + replyFAB.setEnabled(false); } protected Boolean doInBackground(String... strings) { @@ -324,6 +320,7 @@ public class TopicActivity extends BaseActivity { //Find message focus if present { + postFocus = NO_POST_FOCUS; if (pageUrl.contains("msg")) { String tmp = pageUrl.substring(pageUrl.indexOf("msg") + 3); if (tmp.contains(";")) @@ -414,13 +411,7 @@ public class TopicActivity extends BaseActivity { * adds a card for each post to the ScrollView. */ private void populateLayout() { - RecyclerView recyclerView = (RecyclerView)findViewById(R.id.topic_recycler_view); - recyclerView.setHasFixedSize(true); - RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext()); - recyclerView.setLayoutManager(layoutManager); - - TopicAdapter adapter = new TopicAdapter(getApplicationContext(), postsList); - recyclerView.setAdapter(adapter); + recyclerView.swapAdapter(new TopicAdapter(getApplicationContext(), postsList), false); //Set post focus if (postFocus != NO_POST_FOCUS) { 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 b76b13bd..59e5791b 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 @@ -305,7 +305,7 @@ class TopicAdapter extends RecyclerView.Adapter { holder.username.setMaxLines(Integer.MAX_VALUE); holder.username.setEllipsize(null); - holder.subject.setTextColor(Color.parseColor("#000000")); + holder.subject.setTextColor(Color.parseColor("#FFFFFF")); holder.subject.setMaxLines(Integer.MAX_VALUE); holder.subject.setEllipsize(null); } else { //Collapsed @@ -332,7 +332,7 @@ class TopicAdapter extends RecyclerView.Adapter { TopicAnimations.animatePostExtraInfoVisibility(holder.postDateAndNumberExp , holder.username, holder.subject - , Color.parseColor("#000000") + , Color.parseColor("#FFFFFF") , Color.parseColor("#757575")); } });