diff --git a/app/src/main/java/org/libre/agosto/p2play/Database.kt b/app/src/main/java/org/libre/agosto/p2play/Database.kt index 200a865..af0dabe 100644 --- a/app/src/main/java/org/libre/agosto/p2play/Database.kt +++ b/app/src/main/java/org/libre/agosto/p2play/Database.kt @@ -61,12 +61,14 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) { try { var cursor= db.rawQuery("SELECT * FROM tokens WHERE status=1 ORDER BY id DESC LIMIT 1",null) - cursor.moveToFirst() - token.token = cursor.getString(cursor.getColumnIndex("token")).toString() - token.refresh_token = cursor.getString(cursor.getColumnIndex("refresh_token")).toString() - token.status = cursor.getString(cursor.getColumnIndex("status")).toInt() + if(cursor.count != 0){ + cursor.moveToFirst() + token.token = cursor.getString(cursor.getColumnIndex("token")).toString() + token.refresh_token = cursor.getString(cursor.getColumnIndex("refresh_token")).toString() + token.status = cursor.getString(cursor.getColumnIndex("status")).toInt() + } cursor.close() return token @@ -85,15 +87,18 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) { try { var cursor= db.rawQuery("SELECT * FROM users WHERE status=1 ORDER BY id DESC LIMIT 1",null) - cursor.moveToFirst() - user.uuid = cursor.getString(cursor.getColumnIndex("uuid")).toInt() - user.username = cursor.getString(cursor.getColumnIndex("username")).toString() - user.email = cursor.getString(cursor.getColumnIndex("email")).toString() - user.nsfw = cursor.getString(cursor.getColumnIndex("nsfw")).toBoolean() - user.followers = cursor.getString(cursor.getColumnIndex("followers")).toInt() - user.avatar = cursor.getString(cursor.getColumnIndex("avatar")).toString() - user.status = cursor.getString(cursor.getColumnIndex("status")).toInt() + if(cursor.count != 0){ + cursor.moveToFirst() + + user.uuid = cursor.getString(cursor.getColumnIndex("uuid")).toInt() + user.username = cursor.getString(cursor.getColumnIndex("username")).toString() + user.email = cursor.getString(cursor.getColumnIndex("email")).toString() + user.nsfw = cursor.getString(cursor.getColumnIndex("nsfw")).toBoolean() + user.followers = cursor.getString(cursor.getColumnIndex("followers")).toInt() + user.avatar = cursor.getString(cursor.getColumnIndex("avatar")).toString() + user.status = cursor.getString(cursor.getColumnIndex("status")).toInt() + } cursor.close() 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 8c7ea2f..432a6e6 100644 --- a/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt @@ -34,6 +34,7 @@ class HostActivity : AppCompatActivity() { if(host!=""){ if(lastHost!=host){ _db.logout() + ManagerSingleton.logout() getKeys(host) }else{ ManagerSingleton.url=host diff --git a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt index 6828307..de22ac4 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt @@ -1,5 +1,8 @@ package org.libre.agosto.p2play +import android.app.Activity +import android.graphics.Bitmap +import android.graphics.BitmapFactory import android.os.AsyncTask import android.support.v7.app.AppCompatActivity import android.os.Bundle @@ -9,6 +12,8 @@ import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.util.Log import android.view.View +import android.webkit.WebChromeClient +import android.widget.FrameLayout import com.squareup.picasso.Picasso import kotlinx.android.synthetic.main.activity_reproductor.* import org.libre.agosto.p2play.adapters.CommentariesAdapter @@ -32,6 +37,7 @@ class ReproductorActivity : AppCompatActivity() { setContentView(R.layout.activity_reproductor) ManagerSingleton.context = this + videoView.webChromeClient = WebClient() videoView.settings.javaScriptEnabled = true videoView.settings.allowContentAccess = true videoView.settings.javaScriptCanOpenWindowsAutomatically = true @@ -45,7 +51,7 @@ class ReproductorActivity : AppCompatActivity() { tittleVideoTxt.text = this.video.name viewsTxt.text = this.video.views.toString() + ' ' + getString(R.string.view_text) userTxt.text = this.video.username - descriptionVideoTxt.text = this.video.description + descriptionVideoTxt.text = this.video.description.toString() if(this.video.userImageUrl!="") Picasso.get().load("https://"+ManagerSingleton.url+this.video.userImageUrl).into(userImg) @@ -227,4 +233,54 @@ class ReproductorActivity : AppCompatActivity() { } } } + + internal inner class WebClient(): WebChromeClient() { + private var mCustomView: View? = null + private var mCustomViewCallback: WebChromeClient.CustomViewCallback? = null + private var mFullscreenContainer: FrameLayout? = null + private var mOriginalOrientation: Int = 0 + private var mOriginalSystemUiVisibility: Int = 0 + + fun WebClient() {} + + override fun getDefaultVideoPoster(): Bitmap? { + return if (mCustomView == null) { + null + } else BitmapFactory.decodeResource(this@ReproductorActivity.resources, 2130837573) + } + + override fun onHideCustomView() { + try { + (this@ReproductorActivity.window.decorView as FrameLayout).removeView(this.mCustomView) + this.mCustomView = null + this@ReproductorActivity.window.decorView.systemUiVisibility = this.mOriginalSystemUiVisibility + this@ReproductorActivity.requestedOrientation = this.mOriginalOrientation + this.mCustomViewCallback?.onCustomViewHidden() + this.mCustomViewCallback = null + } + catch (err: Exception){ + err.printStackTrace() + } + } + + override fun onShowCustomView(paramView: View, paramCustomViewCallback: WebChromeClient.CustomViewCallback) { + if (this.mCustomView != null) { + this.onHideCustomView() + return + } + try { + + this.mCustomView = paramView + this.mOriginalSystemUiVisibility = this@ReproductorActivity.window.decorView.systemUiVisibility + this.mOriginalOrientation = this@ReproductorActivity.requestedOrientation + this.mCustomViewCallback = paramCustomViewCallback + (this@ReproductorActivity.window.decorView as FrameLayout).addView(this.mCustomView, FrameLayout.LayoutParams(-1, -1)) + this@ReproductorActivity.window.decorView.systemUiVisibility = 3846 + } + catch (err: Exception){ + err.printStackTrace() + } + } + + } } diff --git a/app/src/main/java/org/libre/agosto/p2play/SplashActivity.kt b/app/src/main/java/org/libre/agosto/p2play/SplashActivity.kt index 15ab068..fc5845c 100644 --- a/app/src/main/java/org/libre/agosto/p2play/SplashActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/SplashActivity.kt @@ -8,7 +8,9 @@ import android.os.Bundle import android.os.Handler import android.os.Looper import android.preference.PreferenceManager +import android.util.Log import org.libre.agosto.p2play.ajax.Auth +import java.lang.Exception class SplashActivity : AppCompatActivity() { lateinit var settings: SharedPreferences @@ -27,53 +29,64 @@ class SplashActivity : AppCompatActivity() { val host = settings.getString("hostP2play","") val lastHost = settings.getString("last_host","") - if(host!=""){ - if(lastHost!=host){ + if(host != ""){ + if(lastHost != host){ _db.logout() Handler().postDelayed({ startHostActivity() }, 2000) }else{ - ManagerSingleton.url=host + ManagerSingleton.url = host checkUser() } } - - Handler().postDelayed({ - startHostActivity() - }, 2000) + else{ + Handler().postDelayed({ + startHostActivity() + }, 2000) + } } private fun checkUser(){ - val token = _db.getToken() - val user = _db.getUser() - AsyncTask.execute { - if (Looper.myLooper() == null) - Looper.prepare() + Log.d("was", "Chequed") + try { + 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", "") + 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) + val newToken = client.refreshToken(token, client_id, client_secret) - when (token.status.toString()) { - "1" -> { - _db.newToken(newToken) - ManagerSingleton.token = newToken - ManagerSingleton.user = user + when (token.status.toString()) { + "1" -> { + _db.newToken(newToken) + ManagerSingleton.token = newToken + ManagerSingleton.user = user + } + else -> _db.logout() } - else -> _db.logout() + } else { + _db.logout() } - } else { - _db.logout() - } + + startApp() + Log.d("Aqui", "81") + + } + } + catch (err: Exception){ + err.printStackTrace() + Log.d("Aqui", "89") Handler().postDelayed({ startApp() }, 2000) - } } diff --git a/app/src/main/res/layout/activity_reproductor.xml b/app/src/main/res/layout/activity_reproductor.xml index e2dbbff..84974b6 100644 --- a/app/src/main/res/layout/activity_reproductor.xml +++ b/app/src/main/res/layout/activity_reproductor.xml @@ -8,10 +8,11 @@ + app:layout_constraintTop_toTopOf="parent"> + android:layout_height="270dp" + android:layout_weight="1"> @@ -48,7 +50,7 @@ @@ -58,21 +60,25 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" - android:orientation="vertical"> + android:orientation="vertical" + android:visibility="visible"> @@ -83,21 +89,24 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" - android:orientation="vertical"> + android:orientation="vertical" + android:visibility="visible"> @@ -105,7 +114,7 @@