[Android] Improve 'About' view loading

Geoffrey Métais git at videolan.org
Tue Jul 25 14:37:37 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul 25 14:37:17 2017 +0200| [501aaad6bb01e0459a8f7136f6edd5e933216ea4] | committer: Geoffrey Métais

Improve 'About' view loading

> https://code.videolan.org/videolan/vlc-android/commit/501aaad6bb01e0459a8f7136f6edd5e933216ea4
---

 .../src/org/videolan/vlc/gui/AboutFragment.java    | 35 +++++++++++++++-------
 .../src/org/videolan/vlc/gui/helpers/UiTools.java  | 14 ++++-----
 2 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
index 128dfaecf..13b8d18bb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
@@ -21,6 +21,7 @@
 package org.videolan.vlc.gui;
 
 import android.os.Bundle;
+import android.support.annotation.Nullable;
 import android.support.design.widget.TabLayout;
 import android.support.v4.app.Fragment;
 import android.support.v4.view.ViewPager;
@@ -50,31 +51,45 @@ public class AboutFragment extends Fragment {
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.about, container, false);
+    }
+
+    @Override
+    public void onViewCreated(final View v, @Nullable Bundle savedInstanceState) {
+        super.onViewCreated(v, savedInstanceState);
         if (getActivity() instanceof AppCompatActivity)
             ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("VLC " + BuildConfig.VERSION_NAME);
-        View v = inflater.inflate(R.layout.about, container, false);
         //Fix android 7 Locale problem with webView
         //https://stackoverflow.com/questions/40398528/android-webview-locale-changes-abruptly-on-android-n
         if (AndroidUtil.isNougatOrLater)
             VLCApplication.setLocale();
 
-        View aboutMain = v.findViewById(R.id.about_main);
-        WebView webView = (WebView)v.findViewById(R.id.webview);
-        String revision = getString(R.string.build_revision);
-        webView.loadData(Util.readAsset("licence.htm", "").replace("!COMMITID!",revision), "text/html", "UTF8");
+        final View aboutMain = v.findViewById(R.id.about_main);
+        final WebView webView = v.findViewById(R.id.webview);
+        final String revision = getString(R.string.build_revision);
 
 
-        UiTools.fillAboutView(v);
 
         View[] lists = new View[]{aboutMain, webView};
         String[] titles = new String[] {getString(R.string.about), getString(R.string.licence)};
-        mViewPager = (ViewPager) v.findViewById(R.id.pager);
+        mViewPager = v.findViewById(R.id.pager);
         mViewPager.setOffscreenPageLimit(MODE_TOTAL-1);
         mViewPager.setAdapter(new AudioPagerAdapter(lists, titles));
 
-        mTabLayout = (TabLayout) v.findViewById(R.id.sliding_tabs);
+        mTabLayout = v.findViewById(R.id.sliding_tabs);
         mTabLayout.setupWithViewPager(mViewPager);
-
-        return v;
+        VLCApplication.runBackground(new Runnable() {
+            @Override
+            public void run() {
+                final String asset = Util.readAsset("licence.htm", "").replace("!COMMITID!",revision);
+                VLCApplication.runOnMainThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        UiTools.fillAboutView(v);
+                        webView.loadData(asset, "text/html", "UTF8");
+                    }
+                });
+            }
+        });
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index 35ec95499..96790e648 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -219,19 +219,19 @@ public class UiTools {
     }
 
     public static void fillAboutView(View v) {
-        TextView link = (TextView) v.findViewById(R.id.main_link);
+        final TextView link = v.findViewById(R.id.main_link);
         link.setText(Html.fromHtml(VLCApplication.getAppResources().getString(R.string.about_link)));
 
-        String revision = VLCApplication.getAppResources().getString(R.string.build_revision)+" VLC: "+VLCApplication.getAppResources().getString(R.string.build_vlc_revision);
-        String builddate = VLCApplication.getAppResources().getString(R.string.build_time);
-        String builder = VLCApplication.getAppResources().getString(R.string.build_host);
+        final String revision = VLCApplication.getAppResources().getString(R.string.build_revision)+" VLC: "+VLCApplication.getAppResources().getString(R.string.build_vlc_revision);
+        final String builddate = VLCApplication.getAppResources().getString(R.string.build_time);
+        final String builder = VLCApplication.getAppResources().getString(R.string.build_host);
 
-        TextView compiled = (TextView) v.findViewById(R.id.main_compiled);
+        final TextView compiled = v.findViewById(R.id.main_compiled);
         compiled.setText(builder + " (" + builddate + ")");
-        TextView textview_rev = (TextView) v.findViewById(R.id.main_revision);
+        final TextView textview_rev = v.findViewById(R.id.main_revision);
         textview_rev.setText(VLCApplication.getAppResources().getString(R.string.revision) + " " + revision + " (" + builddate + ") " + BuildConfig.FLAVOR_abi);
 
-        final ImageView logo = (ImageView) v.findViewById(R.id.logo);
+        final ImageView logo = v.findViewById(R.id.logo);
         logo.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {



More information about the Android mailing list