Browse Source

Shared elements activity transitions. WebView's link handling fixes.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
8b8130c1e4
  1. 67
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 5
      app/src/main/res/layout/activity_topic.xml
  3. 3
      app/src/main/res/values-v21/styles.xml

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

@ -11,7 +11,9 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.util.Pair;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -55,6 +57,7 @@ import okhttp3.Response;
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_IN; import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_IN;
import static gr.thmmy.mthmmy.session.SessionManager.LOGIN_STATUS; import static gr.thmmy.mthmmy.session.SessionManager.LOGIN_STATUS;
@SuppressWarnings("unchecked")
public class TopicActivity extends BaseActivity { public class TopicActivity extends BaseActivity {
//-----------------------------------------CLASS VARIABLES------------------------------------------ //-----------------------------------------CLASS VARIABLES------------------------------------------
@ -315,11 +318,16 @@ public class TopicActivity extends BaseActivity {
private void changePage(int pageRequested) { private void changePage(int pageRequested) {
if (pageRequested != thisPage - 1) { if (pageRequested != thisPage - 1) {
//Restart activity with new page //Restart activity with new page
Pair<View, String> p1 = Pair.create((View)replyFAB, "fab");
Pair<View, String> p2 = Pair.create((View)toolbar, "toolbar");
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(this, p1, p2);
Intent intent = getIntent(); Intent intent = getIntent();
intent.putExtra("TOPIC_URL", pagesUrls.get(pageRequested)); intent.putExtra("TOPIC_URL", pagesUrls.get(pageRequested));
intent.putExtra("TOPIC_TITLE", topicTitle); intent.putExtra("TOPIC_TITLE", topicTitle);
startActivity(intent, options.toBundle());
finish(); finish();
startActivity(intent);
} }
} }
//------------------------------------BOTTOM NAV BAR METHODS END------------------------------------ //------------------------------------BOTTOM NAV BAR METHODS END------------------------------------
@ -466,18 +474,10 @@ public class TopicActivity extends BaseActivity {
//Post's WebView parameters set //Post's WebView parameters set
post.setClickable(true); post.setClickable(true);
//post.setWebViewClient(new LinkLauncher()); post.setWebViewClient(new LinkLauncher());
post.getSettings().setJavaScriptEnabled(true); post.getSettings().setJavaScriptEnabled(true);
//TODO //TODO
post.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND); post.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
post.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
@ -642,6 +642,7 @@ public class TopicActivity extends BaseActivity {
* When link url is one that the app can handle internally, it does. * When link url is one that the app can handle internally, it does.
* Otherwise user is prompt to open the link in a browser. * Otherwise user is prompt to open the link in a browser.
*/ */
@SuppressWarnings("unchecked")
private class LinkLauncher extends WebViewClient { //Used to handle link clicks private class LinkLauncher extends WebViewClient { //Used to handle link clicks
//Older versions //Older versions
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -663,28 +664,48 @@ public class TopicActivity extends BaseActivity {
private boolean handleUri(final Uri uri) { private boolean handleUri(final Uri uri) {
//Method always returns true as we don't want any url to be loaded in WebViews //Method always returns true as we don't want any url to be loaded in WebViews
Log.i(TAG, "Uri =" + uri); Log.i(TAG, "Uri = " + uri);
final String host = uri.getHost(); //Get requested url's host final String host = uri.getHost(); //Get requested url's host
final String uriString = uri.toString();
//Determine if you are going to pass the url to a //Determine if you are going to pass the url to a
//host's application activity or load it in a browser. //host's application activity or load it in a browser.
if (Objects.equals(host, "www.thmmy.gr")) { if (Objects.equals(host, "www.thmmy.gr")) {
//This is my web site, so figure out what Activity should launch //This is my web site, so figure out what Activity should launch
if (uri.toString().contains("topic=")) { //This url points to a topic if (uriString.contains("topic=")) { //This url points to a topic
//Is the link pointing to current topic? //Is the link pointing to current topic?
if (Objects.equals( if (Objects.equals(
uri.toString().substring(0, uri.toString().lastIndexOf(".")), base_url)) { uriString.substring(0, uriString.lastIndexOf(".")), base_url)) {
//Don't restart Activity
//Just change post focus //Get uri's targeted message's index number
//TODO String msgIndexReq = uriString.substring(uriString.indexOf("msg") + 3);
} else { if (msgIndexReq.contains("#"))
//Restart activity with new data msgIndexReq = msgIndexReq.substring(0, msgIndexReq.indexOf("#"));
Intent intent = getIntent(); else
intent.putExtra("TOPIC_URL", uri.toString()); msgIndexReq = msgIndexReq.substring(0, msgIndexReq.indexOf(";"));
intent.putExtra("TOPIC_TITLE", "");
finish(); //Is this post already shown now? (is it in current page?)
startActivity(intent); for (Post post : postsList) {
if (post.getPostIndex() == Integer.parseInt(msgIndexReq)) {
//Don't restart Activity
//Just change post focus
//TODO
return true;
}
}
} }
//Restart activity with new data
Pair<View, String> p1 = Pair.create((View) replyFAB, "fab");
Pair<View, String> p2 = Pair.create((View) toolbar, "toolbar");
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(TopicActivity.this, p1, p2);
Intent intent = getIntent();
intent.putExtra("TOPIC_URL", uri.toString());
intent.putExtra("TOPIC_TITLE", "");
startActivity(intent, options.toBundle());
finish();
} }
return true; return true;
} }

5
app/src/main/res/layout/activity_topic.xml

@ -21,6 +21,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
android:transitionName="toolbar"
app:popupTheme="@style/ToolbarTheme"> app:popupTheme="@style/ToolbarTheme">
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
@ -30,8 +31,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="top|start" android:layout_gravity="top|start"
android:layout_marginTop="64dp"
android:layout_marginBottom="50dp" android:layout_marginBottom="50dp"
android:layout_marginTop="64dp"
android:background="@color/background" android:background="@color/background"
android:scrollbars="none" android:scrollbars="none"
tools:context="gr.thmmy.mthmmy.activities.topic.TopicActivity"> tools:context="gr.thmmy.mthmmy.activities.topic.TopicActivity">
@ -54,6 +55,7 @@
android:layout_height="50dp" android:layout_height="50dp"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_marginTop="-2dp" android:layout_marginTop="-2dp"
android:transitionName="bottom_navigation_bar"
app:elevation="8dp"> app:elevation="8dp">
<ImageButton <ImageButton
@ -116,6 +118,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_marginBottom="42dp" android:layout_marginBottom="42dp"
android:transitionName="fab"
app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareFABBehavior" app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareFABBehavior"
app:srcCompat="@drawable/ic_add_fab"/> app:srcCompat="@drawable/ic_add_fab"/>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>

3
app/src/main/res/values-v21/styles.xml

@ -1,4 +1,7 @@
<resources> <resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowContentTransitions">true</item>
</style>
<style name="AppTheme.NoActionBar"> <style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>

Loading…
Cancel
Save