[Android] TV: Show current time on top right corner

Geoffrey Métais git at videolan.org
Thu Apr 19 16:10:02 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 19 16:09:29 2018 +0200| [53c1c33b08306c87a8d3b269c1a17f75f302a710] | committer: Geoffrey Métais

TV: Show current time on top right corner

> https://code.videolan.org/videolan/vlc-android/commit/53c1c33b08306c87a8d3b269c1a17f75f302a710
---

 vlc-android/res/layout/about_main.xml                 |  1 +
 vlc-android/res/layout/tv_details.xml                 | 15 ++++++++++-----
 vlc-android/res/layout/tv_main.xml                    | 19 ++++++++++++-------
 vlc-android/res/layout/tv_time.xml                    | 12 ++++++++++++
 vlc-android/res/layout/tv_vertical_grid.xml           |  1 +
 .../src/org/videolan/vlc/gui/tv/MainTvActivity.java   |  2 +-
 .../src/org/videolan/vlc/gui/tv/TimeUpdater.kt        |  4 +---
 .../videolan/vlc/gui/tv/browser/BaseTvActivity.java   | 10 ++++++++++
 8 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/vlc-android/res/layout/about_main.xml b/vlc-android/res/layout/about_main.xml
index 28a5dc1ea..efb508153 100644
--- a/vlc-android/res/layout/about_main.xml
+++ b/vlc-android/res/layout/about_main.xml
@@ -108,4 +108,5 @@
 
     </LinearLayout>
 
+    <include layout="@layout/tv_time" />
 </ScrollView>
diff --git a/vlc-android/res/layout/tv_details.xml b/vlc-android/res/layout/tv_details.xml
index f000fbefb..de56b6152 100644
--- a/vlc-android/res/layout/tv_details.xml
+++ b/vlc-android/res/layout/tv_details.xml
@@ -1,6 +1,11 @@
-<fragment xmlns:android="http://schemas.android.com/apk/res/android"
-    android:name="org.videolan.vlc.gui.tv.MediaItemDetailsFragment"
-    android:id="@+id/details_fragment"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-/>
\ No newline at end of file
+    android:layout_height="match_parent" >
+    <fragment
+        android:id="@+id/details_fragment"
+        android:name="org.videolan.vlc.gui.tv.MediaItemDetailsFragment"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        />
+    <include layout="@layout/tv_time" />
+</FrameLayout>
\ No newline at end of file
diff --git a/vlc-android/res/layout/tv_main.xml b/vlc-android/res/layout/tv_main.xml
index 86d85da1e..9960dc3f8 100644
--- a/vlc-android/res/layout/tv_main.xml
+++ b/vlc-android/res/layout/tv_main.xml
@@ -1,9 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:id="@+id/tv_container"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:background="@color/transparent">
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/tv_container"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@color/transparent">
     <fragment
           android:name="org.videolan.vlc.gui.tv.MainTvFragment"
           android:id="@+id/browse_fragment"
@@ -14,8 +15,12 @@
         android:id="@+id/tv_main_progress"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_gravity="top|right"
+        android:layout_gravity="top|end"
         android:layout_marginRight="128dp"
+        android:layout_marginEnd="128dp"
         android:layout_marginTop="32dp"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
         android:visibility="gone" />
-</FrameLayout>
\ No newline at end of file
+    <include layout="@layout/tv_time" />
+</android.support.constraint.ConstraintLayout>
\ No newline at end of file
diff --git a/vlc-android/res/layout/tv_time.xml b/vlc-android/res/layout/tv_time.xml
new file mode 100644
index 000000000..cf4553a34
--- /dev/null
+++ b/vlc-android/res/layout/tv_time.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/tv_time"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    app:layout_constraintTop_toTopOf="parent"
+    app:layout_constraintEnd_toEndOf="parent"
+    android:layout_gravity="end"
+    android:layout_marginRight="16dp"
+    android:layout_marginEnd="16dp"
+    android:layout_marginTop="16dp" />
\ No newline at end of file
diff --git a/vlc-android/res/layout/tv_vertical_grid.xml b/vlc-android/res/layout/tv_vertical_grid.xml
index 76ab6e6e8..c61f1ea52 100644
--- a/vlc-android/res/layout/tv_vertical_grid.xml
+++ b/vlc-android/res/layout/tv_vertical_grid.xml
@@ -19,4 +19,5 @@
         android:layout_gravity="center"
         android:text="@string/directory_empty"
         android:visibility="gone"/>
+    <include layout="@layout/tv_time" />
 </FrameLayout>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index 4418eaa0b..bd88e0885 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * MainTvActivity.java
  *****************************************************************************
- * Copyright © 2014-2016 VLC authors, VideoLAN and VideoLabs
+ * Copyright © 2014-2018 VLC authors, VideoLAN and VideoLabs
  * Author: Geoffrey Métais
  *
  * This program is free software; you can redistribute it and/or modify
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/TimeUpdater.kt b/vlc-android/src/org/videolan/vlc/gui/tv/TimeUpdater.kt
index 0e7116cbb..2070d297c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/TimeUpdater.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/TimeUpdater.kt
@@ -57,6 +57,4 @@ class TimeUpdater(private val activity: Activity, private val tv: TextView) : Li
     }
 }
 
-fun FragmentActivity.registerTimeView(tv: TextView) {
-    lifecycle.addObserver(TimeUpdater(this, tv))
-}
\ No newline at end of file
+fun FragmentActivity.registerTimeView(tv: TextView?) = tv?.let { lifecycle.addObserver(TimeUpdater(this, it)) }
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
index 539077b86..25d641b21 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
@@ -29,18 +29,22 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Handler;
 import android.preference.PreferenceManager;
 import android.support.annotation.Nullable;
 import android.view.KeyEvent;
+import android.widget.TextView;
 
 import org.videolan.medialibrary.Medialibrary;
 import org.videolan.vlc.ExternalMonitor;
 import org.videolan.vlc.MediaParsingService;
+import org.videolan.vlc.R;
 import org.videolan.vlc.ScanProgress;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.PlaybackServiceActivity;
 import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.gui.tv.SearchActivity;
+import org.videolan.vlc.gui.tv.TimeUpdaterKt;
 import org.videolan.vlc.util.Constants;
 import org.videolan.vlc.util.Permissions;
 
@@ -64,6 +68,12 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
         mMediaLibrary = VLCApplication.getMLInstance();
         mSettings = PreferenceManager.getDefaultSharedPreferences(this);
         registerLiveData();
+        new Handler().post(new Runnable() {
+            @Override
+            public void run() {
+                TimeUpdaterKt.registerTimeView(BaseTvActivity.this, (TextView) findViewById(R.id.tv_time));
+            }
+        });
     }
 
     @Override



More information about the Android mailing list