1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-06-24 21:25:23 +00:00

Cleaned up UI to hopefully get it past review.

This commit is contained in:
Koen 2023-08-03 12:03:35 +02:00
parent b32080be01
commit b193d4798b
13 changed files with 289 additions and 93 deletions

View file

@ -78,7 +78,6 @@ android {
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
</manifest>

View file

@ -1,12 +1,14 @@
package com.futo.fcast.receiver
import android.Manifest
import android.animation.ValueAnimator
import android.app.AlertDialog
import android.app.PendingIntent
import android.content.Intent
import android.content.pm.PackageInstaller
import android.content.pm.PackageManager
import android.graphics.drawable.Animatable
import android.graphics.drawable.TransitionDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
@ -14,10 +16,21 @@ import android.provider.Settings
import android.util.Log
import android.view.View
import android.view.WindowManager
import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ui.PlayerView
import com.google.android.exoplayer2.ui.StyledPlayerView
import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.util.Util
import kotlinx.coroutines.*
import okhttp3.OkHttpClient
import java.io.InputStream
@ -31,7 +44,10 @@ class MainActivity : AppCompatActivity() {
private lateinit var _textIPs: TextView
private lateinit var _textProgress: TextView
private lateinit var _updateSpinner: ImageView
private lateinit var _layoutUpdate: LinearLayout;
private lateinit var _imageSpinner: ImageView
private lateinit var _layoutConnectionInfo: ConstraintLayout
private lateinit var _videoBackground: StyledPlayerView
private lateinit var _player: ExoPlayer
private var _updating: Boolean = false
private val _scope: CoroutineScope = CoroutineScope(Dispatchers.Main)
@ -45,10 +61,15 @@ class MainActivity : AppCompatActivity() {
_textIPs = findViewById(R.id.text_ips)
_textProgress = findViewById(R.id.text_progress)
_updateSpinner = findViewById(R.id.update_spinner)
_layoutUpdate = findViewById(R.id.layout_update)
_imageSpinner = findViewById(R.id.image_spinner)
_layoutConnectionInfo = findViewById(R.id.layout_connection_info)
_videoBackground = findViewById(R.id.video_background)
startVideo()
startAnimations()
_text.text = getString(R.string.checking_for_updates)
_buttonUpdate.visibility = View.INVISIBLE
_buttonUpdate.visibility = View.GONE
_buttonUpdate.setOnClickListener {
if (_updating) {
@ -60,11 +81,13 @@ class MainActivity : AppCompatActivity() {
}
if (BuildConfig.IS_PLAYSTORE_VERSION) {
_layoutUpdate.visibility = View.GONE
_text.visibility = View.GONE
_buttonUpdate.visibility = View.GONE
_updateSpinner.visibility = View.GONE
(_updateSpinner.drawable as Animatable?)?.stop()
} else {
_layoutUpdate.visibility = View.VISIBLE
_text.visibility = View.VISIBLE
_buttonUpdate.visibility = View.VISIBLE
_updateSpinner.visibility = View.VISIBLE
(_updateSpinner.drawable as Animatable?)?.start()
@ -86,10 +109,23 @@ class MainActivity : AppCompatActivity() {
requestSystemAlertWindowPermission()
}
override fun onPause() {
super.onPause()
_player.playWhenReady = false
_player.pause()
}
override fun onResume() {
super.onResume()
_player.playWhenReady = true
_player.play()
}
override fun onDestroy() {
super.onDestroy()
InstallReceiver.onReceiveResult = null
_scope.cancel()
_player.release()
TcpListenerService.activityCount--
}
@ -102,6 +138,22 @@ class MainActivity : AppCompatActivity() {
startService(Intent(this, TcpListenerService::class.java))
}
private fun startVideo() {
_player = ExoPlayer.Builder(this).build()
_videoBackground.player = _player
val mediaItem = MediaItem.fromUri(Uri.parse("android.resource://" + packageName + "/" + R.raw.c))
_player.setMediaItem(mediaItem)
_player.prepare()
_player.repeatMode = Player.REPEAT_MODE_ALL
_player.playWhenReady = true
}
private fun startAnimations() {
//Spinner animation
(_imageSpinner.drawable as Animatable?)?.start()
}
private fun checkAndRequestPermissions(): Boolean {
val listPermissionsNeeded = arrayListOf<String>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
@ -202,7 +254,7 @@ class MainActivity : AppCompatActivity() {
withContext(Dispatchers.Main) {
try {
(_updateSpinner.drawable as Animatable?)?.stop()
_updateSpinner.visibility = View.INVISIBLE
_updateSpinner.visibility = View.GONE
_text.text = resources.getText(R.string.there_is_an_update_available_do_you_wish_to_update)
_buttonUpdate.visibility = View.VISIBLE
} catch (e: Throwable) {
@ -212,7 +264,7 @@ class MainActivity : AppCompatActivity() {
}
} else {
withContext(Dispatchers.Main) {
_updateSpinner.visibility = View.INVISIBLE
_updateSpinner.visibility = View.GONE
_text.text = getString(R.string.no_updates_available)
Toast.makeText(this@MainActivity, "Already on latest version", Toast.LENGTH_LONG).show();
}
@ -251,7 +303,7 @@ class MainActivity : AppCompatActivity() {
private fun update() {
_updateSpinner.visibility = View.VISIBLE
_buttonUpdate.visibility = Button.INVISIBLE
_buttonUpdate.visibility = Button.GONE
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
_text.text = resources.getText(R.string.downloading_update)

View file

@ -0,0 +1,8 @@
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:propertyName="rotation"
android:valueFrom="0"
android:valueTo="360"
android:repeatMode="restart"
android:repeatCount="infinite"
android:interpolator="@android:anim/linear_interpolator" />

View file

@ -0,0 +1,8 @@
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2500"
android:propertyName="rotation"
android:valueFrom="0"
android:valueTo="-360"
android:repeatMode="restart"
android:repeatCount="infinite"
android:interpolator="@android:anim/linear_interpolator" />

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#1d1d1d"/>
<corners android:radius="6dp"/>
</shape>

View file

@ -0,0 +1,39 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="125dp"
android:height="125dp"
android:viewportWidth="280"
android:viewportHeight="280">
<group android:translateX="26"
android:translateY="20">
<group
android:name="rotationGroup1"
android:pivotX="113.0"
android:pivotY="121.0"
android:rotation="0.0">
<path
android:pathData="M57.31,63.67C25.81,94.29 24.91,144.64 55.38,176.37C85.84,208.1 136.19,209.24 168.06,179.01L158.36,168.92C132.07,193.79 90.59,192.83 65.47,166.67C40.36,140.52 41.09,99.03 67.01,73.77L57.31,63.67Z"
android:fillColor="#2D63ED"
android:fillType="evenOdd"/>
</group>
<group
android:name="rotationGroup2"
android:pivotX="113.0"
android:pivotY="121.0"
android:rotation="0.0">
<path
android:pathData="M15.01,136.36C23.41,190.35 73.83,227.51 127.96,219.45C182.09,211.38 219.49,161.13 211.77,107.04L197.93,109.1C204.5,155.55 172.37,198.68 125.9,205.6C79.42,212.53 36.11,180.64 28.86,134.29L15.01,136.36Z"
android:fillColor="#0044C8"
android:fillType="evenOdd"/>
</group>
<group
android:name="rotationGroup3"
android:pivotX="113.0"
android:pivotY="121.0"
android:rotation="0.0">
<path
android:pathData="M96.53,239.8C161.63,249.14 222.15,204.18 231.92,139.04C241.69,73.9 197.01,13.17 132.04,3L129.96,16.85C187.29,25.86 226.69,79.47 218.07,136.96C209.45,194.45 156.06,234.15 98.61,225.95L96.53,239.8Z"
android:fillColor="#0022A6"
android:fillType="evenOdd"/>
</group>
</group>
</vector>

View file

@ -0,0 +1,12 @@
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_loader" >
<target
android:name="rotationGroup1"
android:animation="@animator/rotation_1500_clockwise" />
<target
android:name="rotationGroup2"
android:animation="@animator/rotation_2500_counter_clockwise" />
<target
android:name="rotationGroup3"
android:animation="@animator/rotation_2000_clockwise" />
</animated-vector>

View file

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/black"
android:orientation="vertical"
android:gravity="center">
android:background="#000000">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/video_background"
app:use_controller="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:resize_mode="zoom" />
<TextView
android:id="@+id/text_title"
@ -22,20 +22,147 @@
android:textColor="@color/white"
android:gravity="center"
android:fontFamily="@font/inter_bold"
android:textSize="40dp"
android:textSize="40sp"
android:includeFontPadding="false"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
app:layout_constraintBottom_toTopOf="@id/layout_connection_info"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_connection_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/background_manual_connect"
android:paddingStart="55dp"
android:paddingEnd="55dp"
android:paddingTop="25dp"
android:paddingBottom="25dp"
app:layout_constraintTop_toBottomOf="@id/text_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/text_dialog">
<TextView
android:id="@+id/text_waiting_for_connection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:gravity="center"
android:fontFamily="@font/inter_regular"
android:textSize="14sp"
android:text="Waiting for a connection"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/text_manual_connection_information" />
<ImageView
android:id="@+id/image_spinner"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="8dp"
app:srcCompat="@drawable/ic_loader_animated"
app:layout_constraintTop_toTopOf="@id/text_waiting_for_connection"
app:layout_constraintBottom_toBottomOf="@id/text_waiting_for_connection"
app:layout_constraintLeft_toRightOf="@id/text_waiting_for_connection" />
<TextView
android:id="@+id/text_manual_connection_information"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#919191"
android:gravity="center"
android:fontFamily="@font/inter_light"
android:textSize="12sp"
android:text="Manual connection information"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/text_waiting_for_connection"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="parent" />
<TextView
android:id="@+id/text_ips"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:gravity="center"
android:fontFamily="@font/inter_regular"
android:textSize="14sp"
tools:text="IPs\n192.168.1.3\n\nPort\n46899"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/text_manual_connection_information"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/text_automatic_discovery" />
<TextView
android:id="@+id/text_automatic_discovery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#919191"
android:gravity="center"
android:fontFamily="@font/inter_regular"
android:textSize="12sp"
android:text="Automatic discovery is available via mDNS"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/text_ips"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/text_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/there_is_an_update_available_do_you_wish_to_update"
android:textSize="14sp"
android:maxLines="2"
android:ellipsize="end"
android:textColor="@color/white"
android:fontFamily="@font/inter_regular"
android:paddingStart="30dp"
android:gravity="center"
app:layout_constraintTop_toBottomOf="@id/layout_connection_info"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/button_update" />
<LinearLayout
android:id="@+id/button_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background_button_primary"
android:layout_marginEnd="2dp"
android:clickable="true"
app:layout_constraintTop_toBottomOf="@id/text_dialog"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/update"
android:textSize="14sp"
android:textColor="@color/white"
android:fontFamily="@font/inter_regular"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingStart="28dp"
android:paddingEnd="28dp"/>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@id/text_title"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="10dp">
android:layout_marginStart="8dp"
app:layout_constraintStart_toEndOf="@id/text_dialog"
app:layout_constraintTop_toTopOf="@id/text_dialog"
app:layout_constraintBottom_toBottomOf="@id/text_dialog">
<ImageView
android:id="@+id/update_spinner"
@ -54,68 +181,4 @@
android:fontFamily="@font/inter_regular" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/text_ips"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:gravity="center"
android:fontFamily="@font/inter_regular"
android:textSize="12dp"
tools:text="123" />
<LinearLayout
android:id="@+id/layout_update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/text_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/there_is_an_update_available_do_you_wish_to_update"
android:textSize="14sp"
android:minLines="3"
android:textColor="@color/white"
android:fontFamily="@font/inter_regular"
android:layout_marginTop="30dp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_marginTop="28dp"
android:layout_marginBottom="28dp">
<LinearLayout
android:id="@+id/button_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background_button_primary"
android:layout_marginEnd="28dp"
android:clickable="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/update"
android:textSize="14sp"
android:textColor="@color/white"
android:fontFamily="@font/inter_regular"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingStart="28dp"
android:paddingEnd="28dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
</manifest>