Splash screen + commentaries changes

This commit is contained in:
ivan agosto 2019-01-28 14:54:08 -06:00
parent e74e39fe28
commit abec98d172
7 changed files with 182 additions and 43 deletions

View File

@ -7,19 +7,22 @@
<application <application
android:allowBackup="true" android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_p2play" android:icon="@mipmap/ic_p2play"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_p2play" android:roundIcon="@mipmap/ic_p2play"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/P2playTheme" android:theme="@style/P2playTheme">
android:hardwareAccelerated="true"> <activity
<activity android:name=".HostActivity"> android:name=".SplashActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".HostActivity" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:theme="@style/P2playTheme.NoActionBar" /> android:theme="@style/P2playTheme.NoActionBar" />
@ -29,7 +32,7 @@
<activity android:name=".AboutActivity" /> <activity android:name=".AboutActivity" />
<activity <activity
android:name=".SettingsActivity" android:name=".SettingsActivity"
android:label="@string/title_activity_settings"></activity> android:label="@string/title_activity_settings" />
</application> </application>
</manifest> </manifest>

View File

@ -29,48 +29,20 @@ class HostActivity : AppCompatActivity() {
getKeys(hostText.text.toString()) getKeys(hostText.text.toString())
} }
val host = settings.getString("hostP2play","") val host = settings.getString("hostP2play", "")
val lastHost = settings.getString("last_host","") val lastHost = settings.getString("last_host", "")
if(host!=""){ if(host!=""){
if(lastHost!=host){ if(lastHost!=host){
_db.logout() _db.logout()
getKeys(host) getKeys(host)
}else{ }else{
ManagerSingleton.url=host 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){ fun saveHost(host: String){
editor.putString("last_host",host) editor.putString("last_host",host)
@ -78,7 +50,7 @@ class HostActivity : AppCompatActivity() {
editor.apply() editor.apply()
ManagerSingleton.Toast(getString(R.string.finallyMsg)) ManagerSingleton.Toast(getString(R.string.finallyMsg))
ManagerSingleton.url=host ManagerSingleton.url=host
checkUser() startApp()
} }
private fun getKeys(hostText: String){ private fun getKeys(hostText: String){
@ -112,6 +84,7 @@ class HostActivity : AppCompatActivity() {
runOnUiThread { runOnUiThread {
val intent = Intent(ManagerSingleton.context,MainActivity::class.java) val intent = Intent(ManagerSingleton.context,MainActivity::class.java)
startActivity(intent) startActivity(intent)
this.finish()
} }
} }
} }

View File

@ -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()
}
}
}

View File

@ -160,22 +160,22 @@
android:id="@+id/descriptionTxt" android:id="@+id/descriptionTxt"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLength="1000"
android:maxLines="100"
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:text="@string/descriptionTxt" /> android:text="@string/descriptionTxt" />
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="80dp"> android:layout_height="80dp"
android:scrollbarStyle="insideInset">
<TextView <TextView
android:id="@+id/descriptionVideoTxt" android:id="@+id/descriptionVideoTxt"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="none|textLongMessage"
android:maxLength="1000" android:maxLength="1000"
android:maxLines="10" android:maxLines="100" />
android:text="-"
android:textStyle="italic" />
</ScrollView> </ScrollView>
<View <View
@ -184,6 +184,10 @@
android:layout_height="1dp" android:layout_height="1dp"
android:background="?android:attr/listDivider" /> android:background="?android:attr/listDivider" />
<Space
android:layout_width="match_parent"
android:layout_height="30dp" />
<TextView <TextView
android:id="@+id/commentariesTxt" android:id="@+id/commentariesTxt"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -191,12 +195,16 @@
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:text="@string/commentariesTxt" /> android:text="@string/commentariesTxt" />
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<LinearLayout <LinearLayout
android:id="@+id/commentaryLayout" android:id="@+id/commentaryLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:visibility="visible"> android:visibility="gone">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context=".SplashActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
app:srcCompat="@drawable/icon" />
<Space
android:layout_width="match_parent"
android:layout_height="30dp" />
<TextView
android:id="@+id/hostInfoText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/charging"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.Material.Medium.Inverse"
android:textColor="@android:color/black" />
<Space
android:layout_width="match_parent"
android:layout_height="30dp" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="?attr/colorAccent"
android:indeterminate="true" />
</LinearLayout>
</FrameLayout>
</android.support.constraint.ConstraintLayout>

View File

@ -2,6 +2,7 @@
<resources> <resources>
<!-- Start Global strings --> <!-- Start Global strings -->
<string name="comming">Proximamente</string> <string name="comming">Proximamente</string>
<string name="charging">Cargando...</string>
<!-- End Global strings --> <!-- End Global strings -->
<!-- Start About strings --> <!-- Start About strings -->

View File

@ -6,6 +6,7 @@
<string name="navigation_drawer_close" translatable="false">Close navigation drawer</string> <string name="navigation_drawer_close" translatable="false">Close navigation drawer</string>
<string name="nav_header_desc" translatable="false">Navigation header</string> <string name="nav_header_desc" translatable="false">Navigation header</string>
<string name="comming">Coming soon!</string> <string name="comming">Coming soon!</string>
<string name="charging">Loading...</string>
<!-- End Global string --> <!-- End Global string -->