Ver código fonte

Merge pull request #827 from nextcloud/welcome-webview

Implement webview welcome pages
Mario Đanić 8 anos atrás
pai
commit
e9c9884357

+ 69 - 4
src/main/java/com/owncloud/android/ui/activity/WhatsNewActivity.java

@@ -37,6 +37,8 @@ import android.support.v4.view.ViewPager;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
 import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.ImageView;
@@ -74,11 +76,20 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
         mProgress = (ProgressIndicator) findViewById(R.id.progressIndicator);
         mPager = (ViewPager)findViewById(R.id.contentPanel);
         final boolean isBeta = getResources().getBoolean(R.bool.is_beta);
-        FeaturesViewAdapter adapter = new FeaturesViewAdapter(getSupportFragmentManager(),
-                FeatureList.getFiltered(getLastSeenVersionCode(), isFirstRun(), isBeta));
+        String[] urls = getResources().getStringArray(R.array.whatsnew_urls);
+
+        if (urls.length > 0) {
+            FeaturesWebViewAdapter featuresWebViewAdapter = new FeaturesWebViewAdapter(getSupportFragmentManager(),
+                    urls);
+            mProgress.setNumberOfSteps(featuresWebViewAdapter.getCount());
+            mPager.setAdapter(featuresWebViewAdapter);
+        } else {
+            FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(),
+                    FeatureList.getFiltered(getLastSeenVersionCode(), isFirstRun(), isBeta));
+            mProgress.setNumberOfSteps(featuresViewAdapter.getCount());
+            mPager.setAdapter(featuresViewAdapter);
+        }
 
-        mProgress.setNumberOfSteps(adapter.getCount());
-        mPager.setAdapter(adapter);
         mPager.addOnPageChangeListener(this);
 
 
@@ -191,6 +202,60 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
         // unused but to be implemented due to abstract parent
     }
 
+    private final class FeaturesWebViewAdapter extends FragmentPagerAdapter {
+        private String[] mWebUrls;
+
+        public FeaturesWebViewAdapter(FragmentManager fm, String[] webUrls) {
+            super(fm);
+            mWebUrls = webUrls;
+        }
+
+        @Override
+        public Fragment getItem(int position) {
+            return FeatureWebFragment.newInstance(mWebUrls[position]);
+        }
+
+        @Override
+        public int getCount() {
+            return mWebUrls.length;
+        }
+    }
+
+    public static class FeatureWebFragment extends Fragment {
+        private String mWebUrl;
+
+        static public FeatureWebFragment newInstance(String webUrl) {
+            FeatureWebFragment f = new FeatureWebFragment();
+            Bundle args = new Bundle();
+            args.putString("url", webUrl);
+            f.setArguments(args);
+            return f;
+        }
+
+        @Override
+        public void onCreate(@Nullable Bundle savedInstanceState) {
+            super.onCreate(savedInstanceState);
+            mWebUrl = getArguments() != null ? (String)getArguments().getString("url") : null;
+        }
+
+        @Nullable
+        @Override
+        public View onCreateView(LayoutInflater inflater,
+                                 @Nullable ViewGroup container,
+                                 @Nullable Bundle savedInstanceState) {
+            View v = inflater.inflate(R.layout.whats_new_webview_element, container, false);
+
+            WebView webView = (WebView) v.findViewById(R.id.whatsNewWebView);
+            webView.getSettings().setJavaScriptEnabled(true);
+            webView.getSettings().setAllowFileAccess(false);
+            webView.setWebViewClient(new WebViewClient());
+            webView.loadUrl(mWebUrl);
+
+            return v;
+        }
+
+
+    }
     private final class FeaturesViewAdapter extends FragmentPagerAdapter {
 
         private FeatureItem[] mFeatures;

+ 8 - 8
src/main/res/layout/whats_new_activity.xml

@@ -30,7 +30,7 @@
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:layout_margin="5dp"
-        android:layout_weight="10"
+        android:layout_weight="6"
         android:gravity="center"
         android:text="@string/placeholder_sentence"
         android:textAppearance="?android:attr/textAppearanceLarge"
@@ -40,16 +40,15 @@
         android:id="@+id/contentPanel"
         android:layout_width="match_parent"
         android:layout_height="0dp"
-        android:layout_weight="80">
+        android:layout_weight="86">
     </android.support.v4.view.ViewPager>
 
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="0dp"
-        android:layout_marginBottom="@dimen/standard_margin"
         android:layout_marginLeft="@dimen/standard_margin"
         android:layout_marginRight="@dimen/standard_margin"
-        android:layout_weight="10"
+        android:layout_weight="8"
         android:orientation="horizontal"
         android:weightSum="3">
 
@@ -57,11 +56,12 @@
             android:id="@+id/skip"
             style="@style/Button.Borderless.Login"
             android:layout_width="0dp"
-            android:layout_height="wrap_content"
+            android:layout_height="match_parent"
             android:layout_gravity="center_vertical|center_horizontal"
             android:layout_weight="1"
-            android:paddingRight="0dp"
+            android:gravity="center"
             android:paddingLeft="0dp"
+            android:paddingRight="0dp"
             android:text="@string/whats_new_skip"/>
 
         <com.owncloud.android.ui.whatsnew.ProgressIndicator
@@ -74,9 +74,10 @@
 
         <LinearLayout
             android:layout_width="0dp"
-            android:layout_height="wrap_content"
+            android:layout_height="match_parent"
             android:layout_gravity="center"
             android:layout_weight="1"
+            android:gravity="center"
             android:orientation="vertical">
 
             <ImageButton
@@ -84,7 +85,6 @@
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_gravity="center"
-                android:padding="@dimen/standard_padding"
                 android:src="@drawable/arrow_right"/>
         </LinearLayout>
     </LinearLayout>

+ 13 - 0
src/main/res/layout/whats_new_webview_element.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent">
+
+    <WebView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:id="@+id/whatsNewWebView">
+    </WebView>
+
+</LinearLayout>

+ 2 - 0
src/main/res/values/setup.xml

@@ -37,6 +37,8 @@
     <bool name = "share_via_link_feature">true</bool>
     <bool name = "share_with_users_feature">true</bool>
     <bool name="show_whats_new">true</bool>
+    <!-- To fill if you want to show webviews instead of regular welcome views -->
+    <array name="whatsnew_urls"></array>
     
     <!-- Colors -->
     <color name="login_text_color">@color/white</color>

+ 4 - 1
src/modified/res/values/setup.xml

@@ -33,7 +33,10 @@
     <string name = "send_files_to_other_apps">on</string>
     <bool name = "share_via_link_feature">true</bool>
     <bool name = "share_with_users_feature">true</bool>
-
+    <bool name="show_whats_new">true</bool>
+    <!-- To fill if you want to show webviews instead of regular welcome views -->
+    <array name="whatsnew_urls"></array>
+    
     <!-- Colors -->
     <color name="login_text_color">@color/white</color>
     <color name="login_text_hint_color">#7fC0E3</color>