Browse Source

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

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
8b8130c1e4
  1. 51
      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

51
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.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.util.Pair;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView;
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.LOGIN_STATUS;
@SuppressWarnings("unchecked")
public class TopicActivity extends BaseActivity {
//-----------------------------------------CLASS VARIABLES------------------------------------------
@ -315,11 +318,16 @@ public class TopicActivity extends BaseActivity {
private void changePage(int pageRequested) {
if (pageRequested != thisPage - 1) {
//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.putExtra("TOPIC_URL", pagesUrls.get(pageRequested));
intent.putExtra("TOPIC_TITLE", topicTitle);
startActivity(intent, options.toBundle());
finish();
startActivity(intent);
}
}
//------------------------------------BOTTOM NAV BAR METHODS END------------------------------------
@ -466,18 +474,10 @@ public class TopicActivity extends BaseActivity {
//Post's WebView parameters set
post.setClickable(true);
//post.setWebViewClient(new LinkLauncher());
post.setWebViewClient(new LinkLauncher());
post.getSettings().setJavaScriptEnabled(true);
//TODO
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.
* Otherwise user is prompt to open the link in a browser.
*/
@SuppressWarnings("unchecked")
private class LinkLauncher extends WebViewClient { //Used to handle link clicks
//Older versions
@SuppressWarnings("deprecation")
@ -665,26 +666,46 @@ public class TopicActivity extends BaseActivity {
Log.i(TAG, "Uri = " + uri);
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
//host's application activity or load it in a browser.
if (Objects.equals(host, "www.thmmy.gr")) {
//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?
if (Objects.equals(
uri.toString().substring(0, uri.toString().lastIndexOf(".")), base_url)) {
uriString.substring(0, uriString.lastIndexOf(".")), base_url)) {
//Get uri's targeted message's index number
String msgIndexReq = uriString.substring(uriString.indexOf("msg") + 3);
if (msgIndexReq.contains("#"))
msgIndexReq = msgIndexReq.substring(0, msgIndexReq.indexOf("#"));
else
msgIndexReq = msgIndexReq.substring(0, msgIndexReq.indexOf(";"));
//Is this post already shown now? (is it in current page?)
for (Post post : postsList) {
if (post.getPostIndex() == Integer.parseInt(msgIndexReq)) {
//Don't restart Activity
//Just change post focus
//TODO
} else {
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();
startActivity(intent);
}
}
return true;
}

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

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

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

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

Loading…
Cancel
Save