From abec98d172ff9ec9cebd78177edfa6a0d061911d Mon Sep 17 00:00:00 2001 From: ivan agosto Date: Mon, 28 Jan 2019 14:54:08 -0600 Subject: [PATCH] Splash screen + commentaries changes --- app/src/main/AndroidManifest.xml | 11 ++- .../org/libre/agosto/p2play/HostActivity.kt | 37 +------- .../org/libre/agosto/p2play/SplashActivity.kt | 95 +++++++++++++++++++ .../main/res/layout/activity_reproductor.xml | 22 +++-- app/src/main/res/layout/activity_splash.xml | 58 +++++++++++ app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 182 insertions(+), 43 deletions(-) create mode 100644 app/src/main/java/org/libre/agosto/p2play/SplashActivity.kt create mode 100644 app/src/main/res/layout/activity_splash.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0fd316f..359a8dc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,19 +7,22 @@ - + android:theme="@style/P2playTheme"> + + @@ -29,7 +32,7 @@ + android:label="@string/title_activity_settings" /> \ No newline at end of file diff --git a/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt b/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt index ade6200..8c7ea2f 100644 --- a/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt @@ -29,48 +29,20 @@ class HostActivity : AppCompatActivity() { getKeys(hostText.text.toString()) } - val host = settings.getString("hostP2play","") - val lastHost = settings.getString("last_host","") + val host = settings.getString("hostP2play", "") + val lastHost = settings.getString("last_host", "") if(host!=""){ if(lastHost!=host){ _db.logout() getKeys(host) }else{ ManagerSingleton.url=host - checkUser() + startApp() } } } - fun checkUser(){ - val token = _db.getToken() - val user = _db.getUser() - AsyncTask.execute { - if (Looper.myLooper() == null) - Looper.prepare() - startApp() - if (token.status == 1 && user.status == 1) { - val client_id = settings.getString("client_id", "") - val client_secret = settings.getString("client_secret", "") - - val newToken = client.refreshToken(token, client_id, client_secret) - - when (token.status.toString()) { - "1" -> { - _db.newToken(newToken) - ManagerSingleton.token = newToken - ManagerSingleton.user = user - } - else -> _db.logout() - } - } else { - _db.logout() - } - - this.finish() - } - } fun saveHost(host: String){ editor.putString("last_host",host) @@ -78,7 +50,7 @@ class HostActivity : AppCompatActivity() { editor.apply() ManagerSingleton.Toast(getString(R.string.finallyMsg)) ManagerSingleton.url=host - checkUser() + startApp() } private fun getKeys(hostText: String){ @@ -112,6 +84,7 @@ class HostActivity : AppCompatActivity() { runOnUiThread { val intent = Intent(ManagerSingleton.context,MainActivity::class.java) startActivity(intent) + this.finish() } } } diff --git a/app/src/main/java/org/libre/agosto/p2play/SplashActivity.kt b/app/src/main/java/org/libre/agosto/p2play/SplashActivity.kt new file mode 100644 index 0000000..15ab068 --- /dev/null +++ b/app/src/main/java/org/libre/agosto/p2play/SplashActivity.kt @@ -0,0 +1,95 @@ +package org.libre.agosto.p2play + +import android.content.Intent +import android.content.SharedPreferences +import android.os.AsyncTask +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.preference.PreferenceManager +import org.libre.agosto.p2play.ajax.Auth + +class SplashActivity : AppCompatActivity() { + lateinit var settings: SharedPreferences + lateinit var editor: SharedPreferences.Editor + val client: Auth = Auth() + val _db = Database(this) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_splash) + + settings = PreferenceManager.getDefaultSharedPreferences(this) + + editor = settings.edit() + ManagerSingleton.context = this + + val host = settings.getString("hostP2play","") + val lastHost = settings.getString("last_host","") + if(host!=""){ + if(lastHost!=host){ + _db.logout() + Handler().postDelayed({ + startHostActivity() + }, 2000) + }else{ + ManagerSingleton.url=host + checkUser() + } + } + + Handler().postDelayed({ + startHostActivity() + }, 2000) + } + + private fun checkUser(){ + val token = _db.getToken() + val user = _db.getUser() + AsyncTask.execute { + if (Looper.myLooper() == null) + Looper.prepare() + + + if (token.status == 1 && user.status == 1) { + val client_id = settings.getString("client_id", "") + val client_secret = settings.getString("client_secret", "") + + val newToken = client.refreshToken(token, client_id, client_secret) + + when (token.status.toString()) { + "1" -> { + _db.newToken(newToken) + ManagerSingleton.token = newToken + ManagerSingleton.user = user + } + else -> _db.logout() + } + } else { + _db.logout() + } + + Handler().postDelayed({ + startApp() + }, 2000) + + } + } + + private fun startApp() { + runOnUiThread { + val intent = Intent(ManagerSingleton.context, MainActivity::class.java) + startActivity(intent) + this.finish() + } + } + + private fun startHostActivity() { + runOnUiThread { + val intent = Intent(ManagerSingleton.context, HostActivity::class.java) + startActivity(intent) + this.finish() + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_reproductor.xml b/app/src/main/res/layout/activity_reproductor.xml index 18af040..e2dbbff 100644 --- a/app/src/main/res/layout/activity_reproductor.xml +++ b/app/src/main/res/layout/activity_reproductor.xml @@ -160,22 +160,22 @@ android:id="@+id/descriptionTxt" android:layout_width="match_parent" android:layout_height="wrap_content" + android:maxLength="1000" + android:maxLines="100" android:paddingLeft="5dp" android:text="@string/descriptionTxt" /> + android:layout_height="80dp" + android:scrollbarStyle="insideInset"> + android:maxLines="100" /> + + + + + android:visibility="gone"> + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index a0089c9..976888b 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -2,6 +2,7 @@ Proximamente + Cargando... diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 146758e..99c09a3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,6 +6,7 @@ Close navigation drawer Navigation header Coming soon! + Loading...