Fix lint errors automated
This commit is contained in:
parent
96d8ae19c6
commit
b6e1a979ca
|
@ -0,0 +1,2 @@
|
||||||
|
[*.{kt,kts}]
|
||||||
|
ktlint_code_style = intellij_idea
|
|
@ -1,6 +1,5 @@
|
||||||
package org.libre.agosto.p2play
|
package org.libre.agosto.p2play
|
||||||
|
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import kotlinx.android.synthetic.main.activity_about.*
|
import kotlinx.android.synthetic.main.activity_about.*
|
||||||
|
@ -11,7 +10,7 @@ class AboutActivity : AppCompatActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_about)
|
setContentView(R.layout.activity_about)
|
||||||
|
|
||||||
aboutUrl.text = "https://"+ManagerSingleton.url+"/about/instance"
|
aboutUrl.text = "https://" + ManagerSingleton.url + "/about/instance"
|
||||||
|
|
||||||
aboutLabel.text = aboutLabel.text.toString() + " " + this.packageManager.getPackageInfo(this.packageName, 0).versionName
|
aboutLabel.text = aboutLabel.text.toString() + " " + this.packageManager.getPackageInfo(this.packageName, 0).versionName
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.libre.agosto.p2play
|
package org.libre.agosto.p2play
|
||||||
|
|
||||||
import androidx.appcompat.app.ActionBar
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.preference.PreferenceActivity
|
import android.preference.PreferenceActivity
|
||||||
|
@ -8,6 +7,7 @@ import android.view.MenuInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
|
import androidx.appcompat.app.ActionBar
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package org.libre.agosto.p2play
|
package org.libre.agosto.p2play
|
||||||
|
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import android.view.View
|
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import kotlinx.android.synthetic.main.activity_channel.*
|
import kotlinx.android.synthetic.main.activity_channel.*
|
||||||
import org.libre.agosto.p2play.adapters.VideosAdapter
|
import org.libre.agosto.p2play.adapters.VideosAdapter
|
||||||
|
@ -47,7 +47,7 @@ class ChannelActivity : AppCompatActivity() {
|
||||||
getSubscription()
|
getSubscription()
|
||||||
getVideos()
|
getVideos()
|
||||||
|
|
||||||
if(ManagerSingleton.user.status == 1) {
|
if (ManagerSingleton.user.status == 1) {
|
||||||
subcriptionBtn.visibility = View.VISIBLE
|
subcriptionBtn.visibility = View.VISIBLE
|
||||||
getSubscription()
|
getSubscription()
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,9 @@ class ChannelActivity : AppCompatActivity() {
|
||||||
usernameProfile.text = channel.name
|
usernameProfile.text = channel.name
|
||||||
hostTxt.text = channel.host
|
hostTxt.text = channel.host
|
||||||
subcriptionsTxt.text = channel.followers.toString()
|
subcriptionsTxt.text = channel.followers.toString()
|
||||||
if(channel.channelImg != "")
|
if (channel.channelImg != "") {
|
||||||
Picasso.get().load("https://${ManagerSingleton.url}${channel.channelImg}").into(channelImg)
|
Picasso.get().load("https://${ManagerSingleton.url}${channel.channelImg}").into(channelImg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,12 +71,11 @@ class ChannelActivity : AppCompatActivity() {
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
val res = _actions.subscribe(ManagerSingleton.token.token, channel.getAccount())
|
val res = _actions.subscribe(ManagerSingleton.token.token, channel.getAccount())
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
if(res == 1){
|
if (res == 1) {
|
||||||
subcriptionBtn.text = getString(R.string.unSubscribeBtn)
|
subcriptionBtn.text = getString(R.string.unSubscribeBtn)
|
||||||
ManagerSingleton.Toast(getString(R.string.subscribeMsg), this)
|
ManagerSingleton.Toast(getString(R.string.subscribeMsg), this)
|
||||||
getSubscription()
|
getSubscription()
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
|
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,12 +86,11 @@ class ChannelActivity : AppCompatActivity() {
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
val res = _actions.unSubscribe(ManagerSingleton.token.token, channel.getAccount())
|
val res = _actions.unSubscribe(ManagerSingleton.token.token, channel.getAccount())
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
if(res == 1){
|
if (res == 1) {
|
||||||
subcriptionBtn.text = getString(R.string.subscribeBtn)
|
subcriptionBtn.text = getString(R.string.subscribeBtn)
|
||||||
ManagerSingleton.Toast(getString(R.string.unSubscribeMsg), this)
|
ManagerSingleton.Toast(getString(R.string.unSubscribeMsg), this)
|
||||||
getSubscription()
|
getSubscription()
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
|
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,20 +98,20 @@ class ChannelActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun subscribeAction() {
|
private fun subscribeAction() {
|
||||||
if(isSubcribed)
|
if (isSubcribed) {
|
||||||
unSubscribe()
|
unSubscribe()
|
||||||
else
|
} else {
|
||||||
subscribe()
|
subscribe()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSubscription() {
|
private fun getSubscription() {
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
isSubcribed = _actions.getSubscription(ManagerSingleton.token.token, channel.getAccount())
|
isSubcribed = _actions.getSubscription(ManagerSingleton.token.token, channel.getAccount())
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
if(isSubcribed){
|
if (isSubcribed) {
|
||||||
subcriptionBtn.text = getText(R.string.unSubscribeBtn)
|
subcriptionBtn.text = getText(R.string.unSubscribeBtn)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
subcriptionBtn.text = getText(R.string.subscribeBtn)
|
subcriptionBtn.text = getText(R.string.subscribeBtn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +128,7 @@ class ChannelActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic function for set data to RecyclerView
|
// Generic function for set data to RecyclerView
|
||||||
private fun initRecycler(data: ArrayList<VideoModel>){
|
private fun initRecycler(data: ArrayList<VideoModel>) {
|
||||||
// val data = arrayListOf<VideoModel>()
|
// val data = arrayListOf<VideoModel>()
|
||||||
viewAdapter = VideosAdapter(data)
|
viewAdapter = VideosAdapter(data)
|
||||||
|
|
||||||
|
@ -146,4 +145,4 @@ class ChannelActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
// swipeContainer.isRefreshing = false
|
// swipeContainer.isRefreshing = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,11 @@ import android.database.sqlite.SQLiteOpenHelper
|
||||||
import org.libre.agosto.p2play.models.TokenModel
|
import org.libre.agosto.p2play.models.TokenModel
|
||||||
import org.libre.agosto.p2play.models.UserModel
|
import org.libre.agosto.p2play.models.UserModel
|
||||||
|
|
||||||
class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
|
class Database(context: Context) : SQLiteOpenHelper(context, "p2play", null, 1) {
|
||||||
val dbName = "p2play"
|
val dbName = "p2play"
|
||||||
|
|
||||||
private val dbUsers = "CREATE TABLE users(id INTEGER PRIMARY KEY AUTOINCREMENT, uuid INTEGER, username varchar(30), " +
|
private val dbUsers = "CREATE TABLE users(id INTEGER PRIMARY KEY AUTOINCREMENT, uuid INTEGER, username varchar(30), " +
|
||||||
"nsfw INTEGER, email string, followers INTEGER, avatar string, status integer)"
|
"nsfw INTEGER, email string, followers INTEGER, avatar string, status integer)"
|
||||||
private val dbTokens = "CREATE TABLE tokens(id INTEGER PRIMARY KEY AUTOINCREMENT, token STRING, refresh_token STRING, status INTEGER)"
|
private val dbTokens = "CREATE TABLE tokens(id INTEGER PRIMARY KEY AUTOINCREMENT, token STRING, refresh_token STRING, status INTEGER)"
|
||||||
override fun onCreate(db: SQLiteDatabase?) {
|
override fun onCreate(db: SQLiteDatabase?) {
|
||||||
db?.execSQL(dbUsers)
|
db?.execSQL(dbUsers)
|
||||||
|
@ -28,12 +28,12 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
|
||||||
fun newToken(token: TokenModel): Boolean {
|
fun newToken(token: TokenModel): Boolean {
|
||||||
val db = writableDatabase
|
val db = writableDatabase
|
||||||
this.closeTokens()
|
this.closeTokens()
|
||||||
val newToken=ContentValues()
|
val newToken = ContentValues()
|
||||||
newToken.put("token", token.token)
|
newToken.put("token", token.token)
|
||||||
newToken.put("refresh_token", token.refresh_token)
|
newToken.put("refresh_token", token.refresh_token)
|
||||||
newToken.put("status", token.status)
|
newToken.put("status", token.status)
|
||||||
|
|
||||||
db.insert("tokens",null,newToken)
|
db.insert("tokens", null, newToken)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
|
||||||
fun newUser(user: UserModel): Boolean {
|
fun newUser(user: UserModel): Boolean {
|
||||||
val db = writableDatabase
|
val db = writableDatabase
|
||||||
this.closeUsers()
|
this.closeUsers()
|
||||||
val newUser=ContentValues()
|
val newUser = ContentValues()
|
||||||
newUser.put("uuid", user.uuid)
|
newUser.put("uuid", user.uuid)
|
||||||
newUser.put("username", user.username)
|
newUser.put("username", user.username)
|
||||||
newUser.put("email", user.email)
|
newUser.put("email", user.email)
|
||||||
|
@ -50,19 +50,19 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
|
||||||
newUser.put("avatar", user.avatar)
|
newUser.put("avatar", user.avatar)
|
||||||
newUser.put("status", user.status)
|
newUser.put("status", user.status)
|
||||||
|
|
||||||
db.insert("users",null, newUser)
|
db.insert("users", null, newUser)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getToken(): TokenModel{
|
fun getToken(): TokenModel {
|
||||||
val db = writableDatabase
|
val db = writableDatabase
|
||||||
var token = TokenModel()
|
var token = TokenModel()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var cursor= db.rawQuery("SELECT * FROM tokens WHERE status=1 ORDER BY id DESC LIMIT 1",null)
|
var cursor = db.rawQuery("SELECT * FROM tokens WHERE status=1 ORDER BY id DESC LIMIT 1", null)
|
||||||
|
|
||||||
if(cursor.count != 0){
|
if (cursor.count != 0) {
|
||||||
cursor.moveToFirst()
|
cursor.moveToFirst()
|
||||||
|
|
||||||
token.token = cursor.getString(cursor.getColumnIndex("token")).toString()
|
token.token = cursor.getString(cursor.getColumnIndex("token")).toString()
|
||||||
|
@ -72,23 +72,22 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
return token
|
return token
|
||||||
|
} catch (e: SQLiteException) {
|
||||||
}catch (e:SQLiteException){
|
|
||||||
db?.execSQL(dbTokens)
|
db?.execSQL(dbTokens)
|
||||||
}catch (e:Exception){
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUser(): UserModel{
|
fun getUser(): UserModel {
|
||||||
val db = writableDatabase
|
val db = writableDatabase
|
||||||
var user = UserModel()
|
var user = UserModel()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var cursor= db.rawQuery("SELECT * FROM users WHERE status=1 ORDER BY id DESC LIMIT 1",null)
|
var cursor = db.rawQuery("SELECT * FROM users WHERE status=1 ORDER BY id DESC LIMIT 1", null)
|
||||||
|
|
||||||
if(cursor.count != 0){
|
if (cursor.count != 0) {
|
||||||
cursor.moveToFirst()
|
cursor.moveToFirst()
|
||||||
|
|
||||||
user.uuid = cursor.getString(cursor.getColumnIndex("uuid")).toInt()
|
user.uuid = cursor.getString(cursor.getColumnIndex("uuid")).toInt()
|
||||||
|
@ -103,28 +102,26 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
} catch (e: SQLiteException) {
|
||||||
}catch (e:SQLiteException){
|
|
||||||
db?.execSQL(dbTokens)
|
db?.execSQL(dbTokens)
|
||||||
}catch (e:Exception){
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun closeTokens(){
|
private fun closeTokens() {
|
||||||
val db = writableDatabase
|
val db = writableDatabase
|
||||||
db.execSQL("UPDATE tokens SET status=-1 WHERE 1")
|
db.execSQL("UPDATE tokens SET status=-1 WHERE 1")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun closeUsers(){
|
private fun closeUsers() {
|
||||||
val db = writableDatabase
|
val db = writableDatabase
|
||||||
db.execSQL("UPDATE users SET status=-1 WHERE 1")
|
db.execSQL("UPDATE users SET status=-1 WHERE 1")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logout(){
|
fun logout() {
|
||||||
closeUsers()
|
closeUsers()
|
||||||
closeTokens()
|
closeTokens()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ package org.libre.agosto.p2play
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import kotlinx.android.synthetic.main.activity_host.*
|
import kotlinx.android.synthetic.main.activity_host.*
|
||||||
import org.libre.agosto.p2play.ajax.Auth
|
import org.libre.agosto.p2play.ajax.Auth
|
||||||
|
@ -13,7 +13,7 @@ import org.libre.agosto.p2play.ajax.Auth
|
||||||
class HostActivity : AppCompatActivity() {
|
class HostActivity : AppCompatActivity() {
|
||||||
lateinit var settings: SharedPreferences
|
lateinit var settings: SharedPreferences
|
||||||
lateinit var editor: SharedPreferences.Editor
|
lateinit var editor: SharedPreferences.Editor
|
||||||
val client:Auth = Auth()
|
val client: Auth = Auth()
|
||||||
val _db = Database(this)
|
val _db = Database(this)
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -29,46 +29,46 @@ class HostActivity : AppCompatActivity() {
|
||||||
|
|
||||||
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()
|
||||||
ManagerSingleton.logout()
|
ManagerSingleton.logout()
|
||||||
getKeys(host!!)
|
getKeys(host!!)
|
||||||
}else{
|
} else {
|
||||||
ManagerSingleton.url = host
|
ManagerSingleton.url = host
|
||||||
startApp()
|
startApp()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveHost(host: String){
|
fun saveHost(host: String) {
|
||||||
editor.putString("last_host",host)
|
editor.putString("last_host", host)
|
||||||
editor.putString("hostP2play",host)
|
editor.putString("hostP2play", host)
|
||||||
editor.apply()
|
editor.apply()
|
||||||
ManagerSingleton.Toast(getString(R.string.finallyMsg), this)
|
ManagerSingleton.Toast(getString(R.string.finallyMsg), this)
|
||||||
ManagerSingleton.url=host
|
ManagerSingleton.url = host
|
||||||
startApp()
|
startApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getKeys(hostText: String){
|
private fun getKeys(hostText: String) {
|
||||||
button.isEnabled = false
|
button.isEnabled = false
|
||||||
var host = hostText.toString()
|
var host = hostText.toString()
|
||||||
host = host.replace("http://","")
|
host = host.replace("http://", "")
|
||||||
host = host.replace("https://","")
|
host = host.replace("https://", "")
|
||||||
host = host.replace("/","")
|
host = host.replace("/", "")
|
||||||
ManagerSingleton.url = host
|
ManagerSingleton.url = host
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
if (Looper.myLooper()==null)
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare()
|
Looper.prepare()
|
||||||
|
}
|
||||||
|
|
||||||
val keys = client.getKeys()
|
val keys = client.getKeys()
|
||||||
if(keys.client_id!=""){
|
if (keys.client_id != "") {
|
||||||
editor.putString("client_id",keys.client_id)
|
editor.putString("client_id", keys.client_id)
|
||||||
editor.putString("client_secret",keys.client_secret)
|
editor.putString("client_secret", keys.client_secret)
|
||||||
editor.apply()
|
editor.apply()
|
||||||
saveHost(host)
|
saveHost(host)
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
|
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
|
||||||
button.isEnabled = true
|
button.isEnabled = true
|
||||||
|
@ -77,9 +77,9 @@ class HostActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startApp(){
|
private fun startApp() {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
val intent = Intent(this,MainActivity::class.java)
|
val intent = Intent(this, MainActivity::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
this.finish()
|
this.finish()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@ package org.libre.agosto.p2play
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import kotlinx.android.synthetic.main.activity_login.*
|
import kotlinx.android.synthetic.main.activity_login.*
|
||||||
import org.libre.agosto.p2play.ajax.Auth
|
import org.libre.agosto.p2play.ajax.Auth
|
||||||
|
@ -34,21 +34,22 @@ class LoginActivity : AppCompatActivity() {
|
||||||
loginBtn.setOnClickListener { tryLogin() }
|
loginBtn.setOnClickListener { tryLogin() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun tryLogin(){
|
fun tryLogin() {
|
||||||
loginBtn.isEnabled = false;
|
loginBtn.isEnabled = false
|
||||||
val username = userText.text.toString()
|
val username = userText.text.toString()
|
||||||
val password = passwordText.text.toString()
|
val password = passwordText.text.toString()
|
||||||
|
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
if (Looper.myLooper()==null)
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare()
|
Looper.prepare()
|
||||||
|
}
|
||||||
|
|
||||||
val token = _auth.login(username, password, client_id, client_secret, optCode)
|
val token = _auth.login(username, password, client_id, client_secret, optCode)
|
||||||
|
|
||||||
// Log.d("token", token.token )
|
// Log.d("token", token.token )
|
||||||
// Log.d("status", token.status.toString() )
|
// Log.d("status", token.status.toString() )
|
||||||
|
|
||||||
when(token.status.toString()){
|
when (token.status.toString()) {
|
||||||
"1" -> {
|
"1" -> {
|
||||||
_db.newToken(token)
|
_db.newToken(token)
|
||||||
ManagerSingleton.token = token
|
ManagerSingleton.token = token
|
||||||
|
@ -90,21 +91,19 @@ class LoginActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUser(){
|
fun getUser() {
|
||||||
val user = _auth.me(ManagerSingleton.token.token)
|
val user = _auth.me(ManagerSingleton.token.token)
|
||||||
if(user.status == 1){
|
if (user.status == 1) {
|
||||||
_db.newUser(user)
|
_db.newUser(user)
|
||||||
ManagerSingleton.user = user
|
ManagerSingleton.user = user
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
ManagerSingleton.Toast(getString(R.string.loginSuccess_msg), this)
|
ManagerSingleton.Toast(getString(R.string.loginSuccess_msg), this)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
ManagerSingleton.Toast(getString(R.string.loginError_msg), this)
|
ManagerSingleton.Toast(getString(R.string.loginError_msg), this)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,10 @@ package org.libre.agosto.p2play
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.WindowManager
|
|
||||||
|
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
|
@ -39,7 +36,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
var searchVal: String = ""
|
var searchVal: String = ""
|
||||||
var pagination = 0
|
var pagination = 0
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
@ -74,7 +70,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic function for set data to RecyclerView
|
// Generic function for set data to RecyclerView
|
||||||
private fun initRecycler(){
|
private fun initRecycler() {
|
||||||
val data = arrayListOf<VideoModel>()
|
val data = arrayListOf<VideoModel>()
|
||||||
viewAdapter = VideosAdapter(data)
|
viewAdapter = VideosAdapter(data)
|
||||||
|
|
||||||
|
@ -94,8 +90,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
super.onScrolled(recyclerView, dx, dy)
|
super.onScrolled(recyclerView, dx, dy)
|
||||||
// super.onScrolled(recyclerView!!, dx, dy)
|
// super.onScrolled(recyclerView!!, dx, dy)
|
||||||
|
|
||||||
if(!swipeContainer.isRefreshing){
|
if (!swipeContainer.isRefreshing) {
|
||||||
if(!canScrollVertically(1)){
|
if (!canScrollVertically(1)) {
|
||||||
loadMore()
|
loadMore()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,17 +101,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
swipeContainer.isRefreshing = false
|
swipeContainer.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addVideos(videos: ArrayList<VideoModel>){
|
private fun addVideos(videos: ArrayList<VideoModel>) {
|
||||||
this.swipeContainer.isRefreshing = true
|
this.swipeContainer.isRefreshing = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(this.pagination == 0){
|
if (this.pagination == 0) {
|
||||||
(viewAdapter as VideosAdapter).clearData()
|
(viewAdapter as VideosAdapter).clearData()
|
||||||
recyclerView.scrollToPosition(0)
|
recyclerView.scrollToPosition(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
(viewAdapter as VideosAdapter).addData(videos)
|
(viewAdapter as VideosAdapter).addData(videos)
|
||||||
}catch (err: Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
|
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
|
||||||
}
|
}
|
||||||
|
@ -123,10 +119,10 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
this.swipeContainer.isRefreshing = false
|
this.swipeContainer.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refresh(){
|
private fun refresh() {
|
||||||
swipeContainer.isRefreshing = true
|
swipeContainer.isRefreshing = true
|
||||||
this.pagination = 0
|
this.pagination = 0
|
||||||
when(section){
|
when (section) {
|
||||||
"local" -> this.getLocalVideos()
|
"local" -> this.getLocalVideos()
|
||||||
"popular" -> this.getPopularVideos()
|
"popular" -> this.getPopularVideos()
|
||||||
"trending" -> this.getTrengindVideos()
|
"trending" -> this.getTrengindVideos()
|
||||||
|
@ -134,16 +130,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
"sub" -> this.getSubscriptionVideos()
|
"sub" -> this.getSubscriptionVideos()
|
||||||
"search" -> this.searchVideos()
|
"search" -> this.searchVideos()
|
||||||
"my_videos" -> {
|
"my_videos" -> {
|
||||||
if(ManagerSingleton.token.token != "")
|
if (ManagerSingleton.token.token != "") {
|
||||||
this.getMyVideos()
|
this.getMyVideos()
|
||||||
else
|
} else {
|
||||||
this.getLastVideos()
|
this.getLastVideos()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSubscriptionVideos(){
|
private fun getSubscriptionVideos() {
|
||||||
if(ManagerSingleton.user.status != 1){
|
if (ManagerSingleton.user.status != 1) {
|
||||||
ManagerSingleton.Toast("Inicia session primero", this)
|
ManagerSingleton.Toast("Inicia session primero", this)
|
||||||
startActivity(Intent(this, LoginActivity::class.java))
|
startActivity(Intent(this, LoginActivity::class.java))
|
||||||
return
|
return
|
||||||
|
@ -160,7 +157,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last videos
|
// Last videos
|
||||||
private fun getLastVideos(){
|
private fun getLastVideos() {
|
||||||
swipeContainer.isRefreshing = true
|
swipeContainer.isRefreshing = true
|
||||||
section = "last"
|
section = "last"
|
||||||
setTitle(R.string.title_recent)
|
setTitle(R.string.title_recent)
|
||||||
|
@ -173,7 +170,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Popular videos
|
// Popular videos
|
||||||
private fun getPopularVideos(){
|
private fun getPopularVideos() {
|
||||||
swipeContainer.isRefreshing = true
|
swipeContainer.isRefreshing = true
|
||||||
section = "popular"
|
section = "popular"
|
||||||
setTitle(R.string.title_popular)
|
setTitle(R.string.title_popular)
|
||||||
|
@ -186,7 +183,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trending videos
|
// Trending videos
|
||||||
private fun getTrengindVideos(){
|
private fun getTrengindVideos() {
|
||||||
swipeContainer.isRefreshing = true
|
swipeContainer.isRefreshing = true
|
||||||
section = "trending"
|
section = "trending"
|
||||||
setTitle(R.string.title_trending)
|
setTitle(R.string.title_trending)
|
||||||
|
@ -199,7 +196,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local videos
|
// Local videos
|
||||||
private fun getLocalVideos(){
|
private fun getLocalVideos() {
|
||||||
swipeContainer.isRefreshing = true
|
swipeContainer.isRefreshing = true
|
||||||
section = "local"
|
section = "local"
|
||||||
setTitle(R.string.title_local)
|
setTitle(R.string.title_local)
|
||||||
|
@ -212,7 +209,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Videos of user
|
// Videos of user
|
||||||
private fun getMyVideos(){
|
private fun getMyVideos() {
|
||||||
swipeContainer.isRefreshing = true
|
swipeContainer.isRefreshing = true
|
||||||
section = "my_videos"
|
section = "my_videos"
|
||||||
setTitle(R.string.title_myVideos)
|
setTitle(R.string.title_myVideos)
|
||||||
|
@ -225,7 +222,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Videos history of user
|
// Videos history of user
|
||||||
private fun getHistory(){
|
private fun getHistory() {
|
||||||
swipeContainer.isRefreshing = true
|
swipeContainer.isRefreshing = true
|
||||||
section = "my_videos"
|
section = "my_videos"
|
||||||
setTitle(R.string.nav_history)
|
setTitle(R.string.nav_history)
|
||||||
|
@ -238,7 +235,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Most liked
|
// Most liked
|
||||||
private fun getMostLiked(){
|
private fun getMostLiked() {
|
||||||
swipeContainer.isRefreshing = true
|
swipeContainer.isRefreshing = true
|
||||||
section = "liked"
|
section = "liked"
|
||||||
setTitle(R.string.nav_likes)
|
setTitle(R.string.nav_likes)
|
||||||
|
@ -252,14 +249,12 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
|
if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
|
||||||
drawer_layout.closeDrawer(GravityCompat.START)
|
drawer_layout.closeDrawer(GravityCompat.START)
|
||||||
}
|
} else if (!section.equals("trending")) {
|
||||||
else if(!section.equals("trending")) {
|
|
||||||
// Hot fix
|
// Hot fix
|
||||||
pagination = 0
|
pagination = 0
|
||||||
this.getTrengindVideos()
|
this.getTrengindVideos()
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
super.onBackPressed()
|
super.onBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,13 +266,13 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
val searchItem = menu.findItem(R.id.app_bar_search)
|
val searchItem = menu.findItem(R.id.app_bar_search)
|
||||||
val searchView = searchItem.actionView as SearchView
|
val searchView = searchItem.actionView as SearchView
|
||||||
|
|
||||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener{
|
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||||
override fun onQueryTextChange(p0: String?): Boolean {
|
override fun onQueryTextChange(p0: String?): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onQueryTextSubmit(p0: String?): Boolean {
|
override fun onQueryTextSubmit(p0: String?): Boolean {
|
||||||
if(!p0.isNullOrBlank()){
|
if (!p0.isNullOrBlank()) {
|
||||||
searchVal = p0
|
searchVal = p0
|
||||||
pagination = 0
|
pagination = 0
|
||||||
searchView.onActionViewCollapsed()
|
searchView.onActionViewCollapsed()
|
||||||
|
@ -285,10 +280,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
myMenu = menu
|
myMenu = menu
|
||||||
setSideData()
|
setSideData()
|
||||||
return true
|
return true
|
||||||
|
@ -327,7 +320,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
// Handle navigation view item clicks here.
|
// Handle navigation view item clicks here.
|
||||||
|
|
||||||
// if(::lastItem.isInitialized){
|
// if(::lastItem.isInitialized){
|
||||||
// lastItem.isChecked = false
|
// lastItem.isChecked = false
|
||||||
// }
|
// }
|
||||||
lastItem = item
|
lastItem = item
|
||||||
pagination = 0
|
pagination = 0
|
||||||
|
@ -357,40 +350,39 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
setSideData()
|
setSideData()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setSideData(){
|
private fun setSideData() {
|
||||||
if(ManagerSingleton.user.status == 1){
|
if (ManagerSingleton.user.status == 1) {
|
||||||
nav_view.menu.findItem(R.id.ml).isVisible = true
|
nav_view.menu.findItem(R.id.ml).isVisible = true
|
||||||
|
|
||||||
side_usernameTxt?.text = ManagerSingleton.user.username
|
side_usernameTxt?.text = ManagerSingleton.user.username
|
||||||
side_emailTxt?.text = ManagerSingleton.user.email
|
side_emailTxt?.text = ManagerSingleton.user.email
|
||||||
if(ManagerSingleton.user.avatar!="" && side_imageView != null) {
|
if (ManagerSingleton.user.avatar != "" && side_imageView != null) {
|
||||||
Picasso.get().load("https://" + ManagerSingleton.url + ManagerSingleton.user.avatar).into(side_imageView)
|
Picasso.get().load("https://" + ManagerSingleton.url + ManagerSingleton.user.avatar).into(side_imageView)
|
||||||
}
|
}
|
||||||
side_imageView?.setOnClickListener {
|
side_imageView?.setOnClickListener {
|
||||||
pagination = 0
|
pagination = 0
|
||||||
getMyVideos()
|
getMyVideos()
|
||||||
drawer_layout.closeDrawer(GravityCompat.START)
|
drawer_layout.closeDrawer(GravityCompat.START)
|
||||||
}
|
}
|
||||||
if(::myMenu.isInitialized){
|
if (::myMenu.isInitialized) {
|
||||||
myMenu.findItem(R.id.action_login).isVisible = false
|
myMenu.findItem(R.id.action_login).isVisible = false
|
||||||
myMenu.findItem(R.id.action_logout).isVisible = true
|
myMenu.findItem(R.id.action_logout).isVisible = true
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nav_view.menu.findItem(R.id.ml).isVisible = false
|
nav_view.menu.findItem(R.id.ml).isVisible = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun logout(){
|
private fun logout() {
|
||||||
if(::myMenu.isInitialized){
|
if (::myMenu.isInitialized) {
|
||||||
myMenu.findItem(R.id.action_login).isVisible = true
|
myMenu.findItem(R.id.action_login).isVisible = true
|
||||||
myMenu.findItem(R.id.action_logout).isVisible = false
|
myMenu.findItem(R.id.action_logout).isVisible = false
|
||||||
}
|
}
|
||||||
//nav_view.menu.findItem(R.id.ml).isVisible = false
|
// nav_view.menu.findItem(R.id.ml).isVisible = false
|
||||||
side_usernameTxt?.text = getString(R.string.nav_header_title)
|
side_usernameTxt?.text = getString(R.string.nav_header_title)
|
||||||
side_emailTxt?.text = getString(R.string.nav_header_subtitle) + " " + this.packageManager.getPackageInfo(this.packageName, 0).versionName
|
side_emailTxt?.text = getString(R.string.nav_header_subtitle) + " " + this.packageManager.getPackageInfo(this.packageName, 0).versionName
|
||||||
side_imageView?.setImageResource(R.drawable.default_avatar)
|
side_imageView?.setImageResource(R.drawable.default_avatar)
|
||||||
side_imageView?.setOnClickListener { }
|
side_imageView?.setOnClickListener { }
|
||||||
_db.logout()
|
_db.logout()
|
||||||
ManagerSingleton.logout()
|
ManagerSingleton.logout()
|
||||||
|
|
||||||
|
@ -399,11 +391,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
setSideData()
|
setSideData()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadMore(){
|
private fun loadMore() {
|
||||||
swipeContainer.isRefreshing = true
|
swipeContainer.isRefreshing = true
|
||||||
this.pagination += ManagerSingleton.videos_count
|
this.pagination += ManagerSingleton.videos_count
|
||||||
|
|
||||||
when(section){
|
when (section) {
|
||||||
"local" -> this.getLocalVideos()
|
"local" -> this.getLocalVideos()
|
||||||
"popular" -> this.getPopularVideos()
|
"popular" -> this.getPopularVideos()
|
||||||
"trending" -> this.getTrengindVideos()
|
"trending" -> this.getTrengindVideos()
|
||||||
|
@ -411,16 +403,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
"sub" -> this.getSubscriptionVideos()
|
"sub" -> this.getSubscriptionVideos()
|
||||||
"search" -> this.searchVideos()
|
"search" -> this.searchVideos()
|
||||||
"my_videos" -> {
|
"my_videos" -> {
|
||||||
if(ManagerSingleton.token.token != "")
|
if (ManagerSingleton.token.token != "") {
|
||||||
this.getMyVideos()
|
this.getMyVideos()
|
||||||
else
|
} else {
|
||||||
this.getLastVideos()
|
this.getLastVideos()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"liked" -> this.getMostLiked()
|
"liked" -> this.getMostLiked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun searchVideos(){
|
private fun searchVideos() {
|
||||||
swipeContainer.isRefreshing = true
|
swipeContainer.isRefreshing = true
|
||||||
section = "search"
|
section = "search"
|
||||||
this.title = this.searchVal
|
this.title = this.searchVal
|
||||||
|
@ -431,5 +424,4 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package org.libre.agosto.p2play
|
package org.libre.agosto.p2play
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Handler
|
|
||||||
import org.libre.agosto.p2play.models.TokenModel
|
import org.libre.agosto.p2play.models.TokenModel
|
||||||
import org.libre.agosto.p2play.models.UserModel
|
import org.libre.agosto.p2play.models.UserModel
|
||||||
|
|
||||||
object ManagerSingleton {
|
object ManagerSingleton {
|
||||||
var url: String?= null
|
var url: String? = null
|
||||||
var user: UserModel = UserModel()
|
var user: UserModel = UserModel()
|
||||||
var token: TokenModel = TokenModel()
|
var token: TokenModel = TokenModel()
|
||||||
var nfsw: Boolean = false
|
var nfsw: Boolean = false
|
||||||
|
@ -19,17 +17,17 @@ object ManagerSingleton {
|
||||||
android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show()
|
android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logout(){
|
fun logout() {
|
||||||
db.logout()
|
db.logout()
|
||||||
user = UserModel()
|
user = UserModel()
|
||||||
token = TokenModel()
|
token = TokenModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reloadSettings () {
|
fun reloadSettings() {
|
||||||
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) {
|
||||||
logout()
|
logout()
|
||||||
}
|
}
|
||||||
url = host
|
url = host
|
||||||
|
@ -38,4 +36,4 @@ object ManagerSingleton {
|
||||||
nfsw = settings.getBoolean("show_nsfw", false)
|
nfsw = settings.getBoolean("show_nsfw", false)
|
||||||
videos_count = settings.getString("videos_count", "15")!!.toInt()
|
videos_count = settings.getString("videos_count", "15")!!.toInt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ package org.libre.agosto.p2play
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import kotlinx.android.synthetic.main.activity_register.*
|
import kotlinx.android.synthetic.main.activity_register.*
|
||||||
import org.libre.agosto.p2play.ajax.Auth
|
import org.libre.agosto.p2play.ajax.Auth
|
||||||
|
|
||||||
|
@ -28,14 +28,15 @@ class RegisterActivity : AppCompatActivity() {
|
||||||
registerBtn.setOnClickListener { registerUser() }
|
registerBtn.setOnClickListener { registerUser() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun registerUser(){
|
fun registerUser() {
|
||||||
registerBtn.isEnabled = false
|
registerBtn.isEnabled = false
|
||||||
val username = userText2.text.toString()
|
val username = userText2.text.toString()
|
||||||
val password = passwordText2.text.toString()
|
val password = passwordText2.text.toString()
|
||||||
val email = emailText.text.toString()
|
val email = emailText.text.toString()
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
if (Looper.myLooper()==null)
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare()
|
Looper.prepare()
|
||||||
|
}
|
||||||
|
|
||||||
val res = _auth.register(username, password, email)
|
val res = _auth.register(username, password, email)
|
||||||
Log.d("Res register", res.toString())
|
Log.d("Res register", res.toString())
|
||||||
|
|
|
@ -5,17 +5,16 @@ import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.media.Image
|
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.webkit.WebChromeClient
|
import android.webkit.WebChromeClient
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.media3.common.MediaItem
|
import androidx.media3.common.MediaItem
|
||||||
|
@ -83,11 +82,11 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
hostTxt.text = this.video.userHost
|
hostTxt.text = this.video.userHost
|
||||||
|
|
||||||
// Check if user had profile image
|
// Check if user had profile image
|
||||||
if (this.video.userImageUrl != "")
|
if (this.video.userImageUrl != "") {
|
||||||
Picasso.get().load("https://" + ManagerSingleton.url + this.video.userImageUrl).into(userImg)
|
Picasso.get().load("https://" + ManagerSingleton.url + this.video.userImageUrl).into(userImg)
|
||||||
|
}
|
||||||
// Load the video
|
// Load the video
|
||||||
videoView.loadUrl("https://" + ManagerSingleton.url + this.video.embedUrl)
|
videoView.loadUrl("https://" + ManagerSingleton.url + this.video.embedUrl)
|
||||||
|
|
||||||
} catch (err: Exception) {
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
|
@ -113,7 +112,6 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
val video = this.clientVideo.getVideo(this.video.uuid)
|
val video = this.clientVideo.getVideo(this.video.uuid)
|
||||||
// TODO: Make this configurable
|
// TODO: Make this configurable
|
||||||
|
@ -140,7 +138,7 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
player.prepare()
|
player.prepare()
|
||||||
// Start the playback.
|
// Start the playback.
|
||||||
// player.play()
|
// player.play()
|
||||||
} catch(err: Exception) {
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,8 +147,9 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private fun subscribe() {
|
private fun subscribe() {
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
if (Looper.myLooper() == null)
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare()
|
Looper.prepare()
|
||||||
|
}
|
||||||
val res = this._actions.subscribe(ManagerSingleton.token.token, video.getChannel())
|
val res = this._actions.subscribe(ManagerSingleton.token.token, video.getChannel())
|
||||||
if (res == 1) {
|
if (res == 1) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
@ -163,8 +162,9 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private fun unSubscribe() {
|
private fun unSubscribe() {
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
if (Looper.myLooper() == null)
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare()
|
Looper.prepare()
|
||||||
|
}
|
||||||
val res = this._actions.unSubscribe(ManagerSingleton.token.token, video.getChannel())
|
val res = this._actions.unSubscribe(ManagerSingleton.token.token, video.getChannel())
|
||||||
if (res == 1) {
|
if (res == 1) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
@ -177,8 +177,9 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private fun rate(rate: String) {
|
private fun rate(rate: String) {
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
if (Looper.myLooper() == null)
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare()
|
Looper.prepare()
|
||||||
|
}
|
||||||
val res = this._actions.rate(ManagerSingleton.token.token, this.video.id, rate)
|
val res = this._actions.rate(ManagerSingleton.token.token, this.video.id, rate)
|
||||||
if (res == 1) {
|
if (res == 1) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
@ -197,8 +198,9 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private fun getRate() {
|
private fun getRate() {
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
if (Looper.myLooper() == null)
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare()
|
Looper.prepare()
|
||||||
|
}
|
||||||
val rate = this._actions.getRate(ManagerSingleton.token.token, this.video.id)
|
val rate = this._actions.getRate(ManagerSingleton.token.token, this.video.id)
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
when (rate) {
|
when (rate) {
|
||||||
|
@ -222,8 +224,9 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
private fun getSubscription() {
|
private fun getSubscription() {
|
||||||
val account = this.video.nameChannel + "@" + this.video.userHost
|
val account = this.video.nameChannel + "@" + this.video.userHost
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
if (Looper.myLooper() == null)
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare()
|
Looper.prepare()
|
||||||
|
}
|
||||||
val isSubscribed = this._actions.getSubscription(ManagerSingleton.token.token, account)
|
val isSubscribed = this._actions.getSubscription(ManagerSingleton.token.token, account)
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
this.changeSubscribeBtn(isSubscribed)
|
this.changeSubscribeBtn(isSubscribed)
|
||||||
|
@ -343,22 +346,21 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
alertDialog.show()
|
alertDialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reportVideo(reason: String){
|
private fun reportVideo(reason: String) {
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
val res = _actions.reportVideo(video.id, reason, ManagerSingleton.token.token)
|
val res = _actions.reportVideo(video.id, reason, ManagerSingleton.token.token)
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
if(res) {
|
if (res) {
|
||||||
ManagerSingleton.Toast(getText(R.string.reportDialogMsg).toString(), this)
|
ManagerSingleton.Toast(getText(R.string.reportDialogMsg).toString(), this)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ManagerSingleton.Toast(getText(R.string.errorMsg).toString(), this)
|
ManagerSingleton.Toast(getText(R.string.errorMsg).toString(), this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFullscreen () {
|
private fun toggleFullscreen() {
|
||||||
if (isFullscreen) {
|
if (isFullscreen) {
|
||||||
nonFullScreen.visibility = View.VISIBLE
|
nonFullScreen.visibility = View.VISIBLE
|
||||||
fullScreenExo.visibility = View.GONE
|
fullScreenExo.visibility = View.GONE
|
||||||
|
@ -373,8 +375,7 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
||||||
|
|
||||||
isFullscreen = false
|
isFullscreen = false
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
val matchParent = WindowManager.LayoutParams.MATCH_PARENT
|
val matchParent = WindowManager.LayoutParams.MATCH_PARENT
|
||||||
|
|
||||||
nonFullScreen.visibility = View.GONE
|
nonFullScreen.visibility = View.GONE
|
||||||
|
@ -395,7 +396,7 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal inner class WebClient: WebChromeClient() {
|
internal inner class WebClient : WebChromeClient() {
|
||||||
private var mCustomView: View? = null
|
private var mCustomView: View? = null
|
||||||
private var mCustomViewCallback: WebChromeClient.CustomViewCallback? = null
|
private var mCustomViewCallback: WebChromeClient.CustomViewCallback? = null
|
||||||
private var mOriginalOrientation: Int = 0
|
private var mOriginalOrientation: Int = 0
|
||||||
|
@ -408,7 +409,9 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
|
|
||||||
return if (mCustomView == null) {
|
return if (mCustomView == null) {
|
||||||
null
|
null
|
||||||
} else BitmapFactory.decodeResource(this@ReproductorActivity.resources, 2130837573)
|
} else {
|
||||||
|
BitmapFactory.decodeResource(this@ReproductorActivity.resources, 2130837573)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onHideCustomView() {
|
override fun onHideCustomView() {
|
||||||
|
@ -429,8 +432,7 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
attrs.flags = attrs.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON.inv()
|
attrs.flags = attrs.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON.inv()
|
||||||
window.attributes = attrs
|
window.attributes = attrs
|
||||||
this@ReproductorActivity.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
this@ReproductorActivity.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -455,8 +457,7 @@ class ReproductorActivity : AppCompatActivity() {
|
||||||
setFullscreen(this@ReproductorActivity.window)
|
setFullscreen(this@ReproductorActivity.window)
|
||||||
|
|
||||||
this@ReproductorActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
this@ReproductorActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,6 @@ import android.annotation.TargetApi
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.media.RingtoneManager
|
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.preference.ListPreference
|
import android.preference.ListPreference
|
||||||
|
@ -13,9 +11,6 @@ import android.preference.Preference
|
||||||
import android.preference.PreferenceActivity
|
import android.preference.PreferenceActivity
|
||||||
import android.preference.PreferenceFragment
|
import android.preference.PreferenceFragment
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
import android.preference.RingtonePreference
|
|
||||||
import android.text.TextUtils
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,8 +62,8 @@ class SettingsActivity : AppCompatPreferenceActivity() {
|
||||||
* Make sure to deny any unknown fragments here.
|
* Make sure to deny any unknown fragments here.
|
||||||
*/
|
*/
|
||||||
override fun isValidFragment(fragmentName: String): Boolean {
|
override fun isValidFragment(fragmentName: String): Boolean {
|
||||||
return PreferenceFragment::class.java.name == fragmentName
|
return PreferenceFragment::class.java.name == fragmentName ||
|
||||||
|| GeneralPreferenceFragment::class.java.name == fragmentName
|
GeneralPreferenceFragment::class.java.name == fragmentName
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,11 +111,12 @@ class SettingsActivity : AppCompatPreferenceActivity() {
|
||||||
|
|
||||||
// Set the summary to reflect the new value.
|
// Set the summary to reflect the new value.
|
||||||
preference.setSummary(
|
preference.setSummary(
|
||||||
if (index >= 0)
|
if (index >= 0) {
|
||||||
listPreference.entries[index]
|
listPreference.entries[index]
|
||||||
else
|
} else {
|
||||||
null)
|
null
|
||||||
|
},
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
// For all other preferences, set the summary to the value's
|
// For all other preferences, set the summary to the value's
|
||||||
// simple string representation.
|
// simple string representation.
|
||||||
|
@ -152,10 +148,12 @@ class SettingsActivity : AppCompatPreferenceActivity() {
|
||||||
|
|
||||||
// Trigger the listener immediately with the preference's
|
// Trigger the listener immediately with the preference's
|
||||||
// current value.
|
// current value.
|
||||||
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
|
sBindPreferenceSummaryToValueListener.onPreferenceChange(
|
||||||
PreferenceManager
|
preference,
|
||||||
.getDefaultSharedPreferences(preference.context)
|
PreferenceManager
|
||||||
.getString(preference.key, ""))
|
.getDefaultSharedPreferences(preference.context)
|
||||||
|
.getString(preference.key, ""),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,4 +28,4 @@ class SettingsActivity2 : AppCompatActivity() {
|
||||||
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@ package org.libre.agosto.p2play
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import org.libre.agosto.p2play.ajax.Auth
|
import org.libre.agosto.p2play.ajax.Auth
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
|
|
||||||
|
@ -27,14 +27,14 @@ class SplashActivity : AppCompatActivity() {
|
||||||
|
|
||||||
ManagerSingleton.reloadSettings()
|
ManagerSingleton.reloadSettings()
|
||||||
|
|
||||||
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) {
|
||||||
Handler().postDelayed({
|
Handler().postDelayed({
|
||||||
startHostActivity()
|
startHostActivity()
|
||||||
}, 2000)
|
}, 2000)
|
||||||
}else{
|
} else {
|
||||||
ManagerSingleton.url = host
|
ManagerSingleton.url = host
|
||||||
checkUser()
|
checkUser()
|
||||||
}
|
}
|
||||||
|
@ -45,14 +45,15 @@ class SplashActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkUser(){
|
private fun checkUser() {
|
||||||
Log.d("was", "Checked")
|
Log.d("was", "Checked")
|
||||||
try {
|
try {
|
||||||
val token = _db.getToken()
|
val token = _db.getToken()
|
||||||
val user = _db.getUser()
|
val user = _db.getUser()
|
||||||
AsyncTask.execute {
|
AsyncTask.execute {
|
||||||
if (Looper.myLooper() == null)
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare()
|
Looper.prepare()
|
||||||
|
}
|
||||||
|
|
||||||
if (token.status == 1 && user.status == 1) {
|
if (token.status == 1 && user.status == 1) {
|
||||||
val clientId = settings.getString("client_id", "")!!
|
val clientId = settings.getString("client_id", "")!!
|
||||||
|
@ -72,11 +73,9 @@ class SplashActivity : AppCompatActivity() {
|
||||||
ManagerSingleton.logout()
|
ManagerSingleton.logout()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
startApp()
|
startApp()
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
Handler().postDelayed({
|
Handler().postDelayed({
|
||||||
startApp()
|
startApp()
|
||||||
|
@ -99,4 +98,4 @@ class SplashActivity : AppCompatActivity() {
|
||||||
this.finish()
|
this.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package org.libre.agosto.p2play.adapters
|
package org.libre.agosto.p2play.adapters
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import kotlinx.android.synthetic.main.view_video.view.userImg
|
import kotlinx.android.synthetic.main.view_video.view.userImg
|
||||||
import org.libre.agosto.p2play.*
|
import org.libre.agosto.p2play.*
|
||||||
|
@ -16,13 +15,13 @@ import org.libre.agosto.p2play.models.CommentaryModel
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
|
class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
|
||||||
RecyclerView.Adapter<CommentariesAdapter.ViewHolder>() {
|
RecyclerView.Adapter<CommentariesAdapter.ViewHolder>() {
|
||||||
|
|
||||||
// Provide a reference to the views for each data item
|
// Provide a reference to the views for each data item
|
||||||
// Complex data items may need more than one view per item, and
|
// Complex data items may need more than one view per item, and
|
||||||
// you provide access to all the views for a data item in a view holder.
|
// you provide access to all the views for a data item in a view holder.
|
||||||
// Each data item is just a string in this case that is shown in a TextView.
|
// Each data item is just a string in this case that is shown in a TextView.
|
||||||
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view){
|
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||||
val userImg: ImageView
|
val userImg: ImageView
|
||||||
val username: TextView
|
val username: TextView
|
||||||
val commentary: TextView
|
val commentary: TextView
|
||||||
|
@ -37,13 +36,14 @@ class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create new views (invoked by the layout manager)
|
// Create new views (invoked by the layout manager)
|
||||||
override fun onCreateViewHolder(parent: ViewGroup,
|
override fun onCreateViewHolder(
|
||||||
viewType: Int): CommentariesAdapter.ViewHolder {
|
parent: ViewGroup,
|
||||||
|
viewType: Int,
|
||||||
|
): CommentariesAdapter.ViewHolder {
|
||||||
// create a new view
|
// create a new view
|
||||||
val view = LayoutInflater.from(parent.context)
|
val view = LayoutInflater.from(parent.context)
|
||||||
.inflate(R.layout.view_commentary, parent, false) as View
|
.inflate(R.layout.view_commentary, parent, false) as View
|
||||||
|
|
||||||
// set the view's size, margins, paddings and layout parameters
|
// set the view's size, margins, paddings and layout parameters
|
||||||
return ViewHolder(view)
|
return ViewHolder(view)
|
||||||
|
@ -56,13 +56,14 @@ class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
|
||||||
holder.username.text = myDataset[position].username
|
holder.username.text = myDataset[position].username
|
||||||
|
|
||||||
// holder.userImg.setOnClickListener {
|
// holder.userImg.setOnClickListener {
|
||||||
// val intent = Intent(holder.context, ChannelActivity::class.java)
|
// val intent = Intent(holder.context, ChannelActivity::class.java)
|
||||||
// intent.putExtra("channel", myDataset[position])
|
// intent.putExtra("channel", myDataset[position])
|
||||||
// holder.context.startActivity(intent)
|
// holder.context.startActivity(intent)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if(myDataset[position].userImageUrl!="")
|
if (myDataset[position].userImageUrl != "") {
|
||||||
Picasso.get().load("https://"+ManagerSingleton.url+myDataset[position].userImageUrl).into(holder.userImg);
|
Picasso.get().load("https://" + ManagerSingleton.url + myDataset[position].userImageUrl).into(holder.userImg)
|
||||||
|
}
|
||||||
|
|
||||||
holder.commentary.text = Html.fromHtml(myDataset[position].commentary)
|
holder.commentary.text = Html.fromHtml(myDataset[position].commentary)
|
||||||
|
|
||||||
|
@ -76,4 +77,4 @@ class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
|
||||||
|
|
||||||
// Return the size of your dataset (invoked by the layout manager)
|
// Return the size of your dataset (invoked by the layout manager)
|
||||||
override fun getItemCount() = myDataset.size
|
override fun getItemCount() = myDataset.size
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,12 @@ package org.libre.agosto.p2play.adapters
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import org.libre.agosto.p2play.*
|
import org.libre.agosto.p2play.*
|
||||||
import org.libre.agosto.p2play.helpers.mapSeconds
|
import org.libre.agosto.p2play.helpers.mapSeconds
|
||||||
|
@ -15,14 +15,13 @@ import org.libre.agosto.p2play.models.VideoModel
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
|
class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
|
||||||
RecyclerView.Adapter<VideosAdapter.ViewHolder>() {
|
RecyclerView.Adapter<VideosAdapter.ViewHolder>() {
|
||||||
|
|
||||||
|
|
||||||
// Provide a reference to the views for each data item
|
// Provide a reference to the views for each data item
|
||||||
// Complex data items may need more than one view per item, and
|
// Complex data items may need more than one view per item, and
|
||||||
// you provide access to all the views for a data item in a view holder.
|
// you provide access to all the views for a data item in a view holder.
|
||||||
// Each data item is just a string in this case that is shown in a TextView.
|
// Each data item is just a string in this case that is shown in a TextView.
|
||||||
class ViewHolder(private val view: View) : RecyclerView.ViewHolder(view){
|
class ViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
|
||||||
val thumb: ImageView = view.findViewById(R.id.thumb)
|
val thumb: ImageView = view.findViewById(R.id.thumb)
|
||||||
val userImg: ImageView = view.findViewById(R.id.userImg)
|
val userImg: ImageView = view.findViewById(R.id.userImg)
|
||||||
val title: TextView = view.findViewById(R.id.tittleTxt)
|
val title: TextView = view.findViewById(R.id.tittleTxt)
|
||||||
|
@ -36,7 +35,7 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
// create a new view
|
// create a new view
|
||||||
val view = LayoutInflater.from(parent.context)
|
val view = LayoutInflater.from(parent.context)
|
||||||
.inflate(R.layout.view_video, parent, false) as View
|
.inflate(R.layout.view_video, parent, false) as View
|
||||||
// set the view's size, margins, paddings and layout parameters
|
// set the view's size, margins, paddings and layout parameters
|
||||||
return ViewHolder(view)
|
return ViewHolder(view)
|
||||||
}
|
}
|
||||||
|
@ -49,7 +48,7 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
|
||||||
holder.title.setOnClickListener {
|
holder.title.setOnClickListener {
|
||||||
this.launchChannelActivity(myDataset[position] as Serializable, holder.context)
|
this.launchChannelActivity(myDataset[position] as Serializable, holder.context)
|
||||||
}
|
}
|
||||||
Picasso.get().load("https://"+ManagerSingleton.url+myDataset[position].thumbUrl).into(holder.thumb)
|
Picasso.get().load("https://" + ManagerSingleton.url + myDataset[position].thumbUrl).into(holder.thumb)
|
||||||
holder.thumb.setOnClickListener {
|
holder.thumb.setOnClickListener {
|
||||||
this.launchChannelActivity(myDataset[position] as Serializable, holder.context)
|
this.launchChannelActivity(myDataset[position] as Serializable, holder.context)
|
||||||
}
|
}
|
||||||
|
@ -60,18 +59,19 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
|
||||||
holder.context.startActivity(intent)
|
holder.context.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(myDataset[position].userImageUrl!="")
|
if (myDataset[position].userImageUrl != "") {
|
||||||
Picasso.get().load("https://"+ManagerSingleton.url+myDataset[position].userImageUrl).into(holder.userImg)
|
Picasso.get().load("https://" + ManagerSingleton.url + myDataset[position].userImageUrl).into(holder.userImg)
|
||||||
else
|
} else {
|
||||||
Picasso.get().load(R.drawable.default_avatar).into(holder.userImg)
|
Picasso.get().load(R.drawable.default_avatar).into(holder.userImg)
|
||||||
|
}
|
||||||
|
|
||||||
val viewsText = holder.context.getString(R.string.view_text)
|
val viewsText = holder.context.getString(R.string.view_text)
|
||||||
val seconds = myDataset[position].duration.toInt();
|
val seconds = myDataset[position].duration.toInt()
|
||||||
val timeString = mapSeconds(seconds)
|
val timeString = mapSeconds(seconds)
|
||||||
|
|
||||||
holder.duration.text = timeString
|
holder.duration.text = timeString
|
||||||
|
|
||||||
holder.description.text = myDataset[position].username+" - "+myDataset[position].views+" "+viewsText
|
holder.description.text = myDataset[position].username + " - " + myDataset[position].views + " " + viewsText
|
||||||
|
|
||||||
if (myDataset[position].isLive) {
|
if (myDataset[position].isLive) {
|
||||||
holder.isLive.visibility = View.VISIBLE
|
holder.isLive.visibility = View.VISIBLE
|
||||||
|
@ -81,20 +81,20 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
|
||||||
// Return the size of your dataset (invoked by the layout manager)
|
// Return the size of your dataset (invoked by the layout manager)
|
||||||
override fun getItemCount() = myDataset.size
|
override fun getItemCount() = myDataset.size
|
||||||
|
|
||||||
fun clearData(){
|
fun clearData() {
|
||||||
myDataset.clear()
|
myDataset.clear()
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addData(newItems: ArrayList<VideoModel>){
|
fun addData(newItems: ArrayList<VideoModel>) {
|
||||||
val lastPos = myDataset.size
|
val lastPos = myDataset.size
|
||||||
myDataset.addAll(newItems)
|
myDataset.addAll(newItems)
|
||||||
notifyItemRangeInserted(lastPos, newItems.size)
|
notifyItemRangeInserted(lastPos, newItems.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchChannelActivity (data: Serializable, context: Context) {
|
private fun launchChannelActivity(data: Serializable, context: Context) {
|
||||||
val intent = Intent(context, ReproductorActivity::class.java)
|
val intent = Intent(context, ReproductorActivity::class.java)
|
||||||
intent.putExtra("video", data)
|
intent.putExtra("video", data)
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@ package org.libre.agosto.p2play.ajax
|
||||||
import android.util.JsonReader
|
import android.util.JsonReader
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
class Actions: Client() {
|
class Actions : Client() {
|
||||||
|
|
||||||
fun subscribe(token: String, account: String):Int{
|
fun subscribe(token: String, account: String): Int {
|
||||||
val con = this._newCon("users/me/subscriptions","POST", token)
|
val con = this._newCon("users/me/subscriptions", "POST", token)
|
||||||
val params:String= "uri=$account"
|
val params: String = "uri=$account"
|
||||||
con.outputStream.write(params.toByteArray())
|
con.outputStream.write(params.toByteArray())
|
||||||
var response = 0
|
var response = 0
|
||||||
|
|
||||||
|
@ -15,8 +15,7 @@ class Actions: Client() {
|
||||||
if (con.responseCode == 204) {
|
if (con.responseCode == 204) {
|
||||||
response = 1
|
response = 1
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
response = -1
|
response = -1
|
||||||
}
|
}
|
||||||
|
@ -25,16 +24,15 @@ class Actions: Client() {
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unSubscribe(token: String, account: String):Int{
|
fun unSubscribe(token: String, account: String): Int {
|
||||||
val con = this._newCon("users/me/subscriptions/$account","DELETE", token)
|
val con = this._newCon("users/me/subscriptions/$account", "DELETE", token)
|
||||||
var response = 0
|
var response = 0
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 204) {
|
if (con.responseCode == 204) {
|
||||||
response = 1
|
response = 1
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
response = -1
|
response = -1
|
||||||
}
|
}
|
||||||
|
@ -43,8 +41,8 @@ class Actions: Client() {
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSubscription(token: String, account: String): Boolean{
|
fun getSubscription(token: String, account: String): Boolean {
|
||||||
val con = this._newCon("users/me/subscriptions/exist?uris=$account","GET", token)
|
val con = this._newCon("users/me/subscriptions/exist?uris=$account", "GET", token)
|
||||||
var isSubscribed = false
|
var isSubscribed = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -52,21 +50,20 @@ class Actions: Client() {
|
||||||
val response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
val data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val key = data.nextName()
|
val key = data.nextName()
|
||||||
when (key.toString()) {
|
when (key.toString()) {
|
||||||
account->{
|
account -> {
|
||||||
isSubscribed = data.nextBoolean()
|
isSubscribed = data.nextBoolean()
|
||||||
}
|
}
|
||||||
else->{
|
else -> {
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
isSubscribed = false
|
isSubscribed = false
|
||||||
}
|
}
|
||||||
|
@ -75,8 +72,8 @@ class Actions: Client() {
|
||||||
return isSubscribed
|
return isSubscribed
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rate(token: String, id_video: Int, rate: String):Int{
|
fun rate(token: String, id_video: Int, rate: String): Int {
|
||||||
val con = this._newCon("videos/$id_video/rate","PUT", token)
|
val con = this._newCon("videos/$id_video/rate", "PUT", token)
|
||||||
val params = "rating=$rate"
|
val params = "rating=$rate"
|
||||||
con.outputStream.write(params.toByteArray())
|
con.outputStream.write(params.toByteArray())
|
||||||
var response = 0
|
var response = 0
|
||||||
|
@ -85,8 +82,7 @@ class Actions: Client() {
|
||||||
if (con.responseCode == 204) {
|
if (con.responseCode == 204) {
|
||||||
response = 1
|
response = 1
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
response = -1
|
response = -1
|
||||||
}
|
}
|
||||||
|
@ -95,8 +91,8 @@ class Actions: Client() {
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRate(token: String, id_video: Int):String{
|
fun getRate(token: String, id_video: Int): String {
|
||||||
val con = this._newCon("users/me/videos/$id_video/rating","GET", token)
|
val con = this._newCon("users/me/videos/$id_video/rating", "GET", token)
|
||||||
var rating = "none"
|
var rating = "none"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -104,21 +100,20 @@ class Actions: Client() {
|
||||||
val response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
val data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val key = data.nextName()
|
val key = data.nextName()
|
||||||
when (key.toString()) {
|
when (key.toString()) {
|
||||||
"rating"->{
|
"rating" -> {
|
||||||
rating = data.nextString()
|
rating = data.nextString()
|
||||||
}
|
}
|
||||||
else->{
|
else -> {
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
rating = "none"
|
rating = "none"
|
||||||
}
|
}
|
||||||
|
@ -134,7 +129,7 @@ class Actions: Client() {
|
||||||
|
|
||||||
var response = false
|
var response = false
|
||||||
try {
|
try {
|
||||||
if(con.responseCode == 200){
|
if (con.responseCode == 200) {
|
||||||
response = true
|
response = true
|
||||||
}
|
}
|
||||||
} catch (err: Exception) {
|
} catch (err: Exception) {
|
||||||
|
@ -152,7 +147,7 @@ class Actions: Client() {
|
||||||
|
|
||||||
var response = false
|
var response = false
|
||||||
try {
|
try {
|
||||||
if(con.responseCode == 204){
|
if (con.responseCode == 204) {
|
||||||
response = true
|
response = true
|
||||||
}
|
}
|
||||||
} catch (err: Exception) {
|
} catch (err: Exception) {
|
||||||
|
@ -162,4 +157,4 @@ class Actions: Client() {
|
||||||
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,16 +4,15 @@ package org.libre.agosto.p2play.ajax
|
||||||
import android.util.JsonReader
|
import android.util.JsonReader
|
||||||
import android.util.JsonToken
|
import android.util.JsonToken
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import org.libre.agosto.p2play.ManagerSingleton
|
|
||||||
import org.libre.agosto.p2play.models.TokenModel
|
import org.libre.agosto.p2play.models.TokenModel
|
||||||
import org.libre.agosto.p2play.models.UserModel
|
import org.libre.agosto.p2play.models.UserModel
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
class Auth: Client() {
|
class Auth : Client() {
|
||||||
private val stockParams = "grant_type=password"
|
private val stockParams = "grant_type=password"
|
||||||
|
|
||||||
fun login(username: String, password: String, client_id: String, client_secret: String, twoFactorCode: String? = null): TokenModel{
|
fun login(username: String, password: String, client_id: String, client_secret: String, twoFactorCode: String? = null): TokenModel {
|
||||||
val con = this._newCon("users/token","POST")
|
val con = this._newCon("users/token", "POST")
|
||||||
val params = "$stockParams&username=$username&password=$password&client_id=$client_id&client_secret=$client_secret"
|
val params = "$stockParams&username=$username&password=$password&client_id=$client_id&client_secret=$client_secret"
|
||||||
|
|
||||||
if (twoFactorCode !== null) {
|
if (twoFactorCode !== null) {
|
||||||
|
@ -24,16 +23,15 @@ class Auth: Client() {
|
||||||
val token = TokenModel()
|
val token = TokenModel()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
when (con.responseCode) {
|
when (con.responseCode) {
|
||||||
200 -> {
|
200 -> {
|
||||||
val response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
val data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
|
|
||||||
while(data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val k = data.nextName()
|
val k = data.nextName()
|
||||||
when(k.toString()){
|
when (k.toString()) {
|
||||||
"access_token" -> token.token = data.nextString()
|
"access_token" -> token.token = data.nextString()
|
||||||
"refresh_token" -> token.refresh_token = data.nextString()
|
"refresh_token" -> token.refresh_token = data.nextString()
|
||||||
else -> data.skipValue()
|
else -> data.skipValue()
|
||||||
|
@ -43,7 +41,6 @@ class Auth: Client() {
|
||||||
data.endObject()
|
data.endObject()
|
||||||
data.close()
|
data.close()
|
||||||
token.status = 1
|
token.status = 1
|
||||||
|
|
||||||
}
|
}
|
||||||
401 -> {
|
401 -> {
|
||||||
// User require 2FA code
|
// User require 2FA code
|
||||||
|
@ -53,8 +50,7 @@ class Auth: Client() {
|
||||||
Log.d("Status", con.responseMessage)
|
Log.d("Status", con.responseMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
token.status = 0
|
token.status = 0
|
||||||
}
|
}
|
||||||
|
@ -63,8 +59,8 @@ class Auth: Client() {
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
fun register(username: String, password: String, email: String): Int{
|
fun register(username: String, password: String, email: String): Int {
|
||||||
val con = this._newCon("users/register","POST")
|
val con = this._newCon("users/register", "POST")
|
||||||
val params = "username=$username&password=$password&email=$email"
|
val params = "username=$username&password=$password&email=$email"
|
||||||
con.outputStream.write(params.toByteArray())
|
con.outputStream.write(params.toByteArray())
|
||||||
|
|
||||||
|
@ -74,32 +70,30 @@ class Auth: Client() {
|
||||||
if (con.responseCode == 204) {
|
if (con.responseCode == 204) {
|
||||||
response = 1
|
response = 1
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
response = -1
|
response = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshToken(token: TokenModel, client_id: String, client_secret: String): TokenModel{
|
fun refreshToken(token: TokenModel, client_id: String, client_secret: String): TokenModel {
|
||||||
val con = this._newCon("users/token", "POST", token.token)
|
val con = this._newCon("users/token", "POST", token.token)
|
||||||
val params = "refresh_token=${token.refresh_token}&response_type=code&grant_type=refresh_token&client_id=$client_id&client_secret=$client_secret"
|
val params = "refresh_token=${token.refresh_token}&response_type=code&grant_type=refresh_token&client_id=$client_id&client_secret=$client_secret"
|
||||||
con.outputStream.write(params.toByteArray())
|
con.outputStream.write(params.toByteArray())
|
||||||
// val token = TokenModel()
|
// val token = TokenModel()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(con.responseCode==200){
|
if (con.responseCode == 200) {
|
||||||
val response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
val data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
|
|
||||||
while(data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val k = data.nextName()
|
val k = data.nextName()
|
||||||
when(k.toString()){
|
when (k.toString()) {
|
||||||
"access_token" -> token.token = data.nextString()
|
"access_token" -> token.token = data.nextString()
|
||||||
"refresh_token" -> token.refresh_token = data.nextString()
|
"refresh_token" -> token.refresh_token = data.nextString()
|
||||||
else -> data.skipValue()
|
else -> data.skipValue()
|
||||||
|
@ -109,13 +103,10 @@ class Auth: Client() {
|
||||||
data.endObject()
|
data.endObject()
|
||||||
data.close()
|
data.close()
|
||||||
token.status = 1
|
token.status = 1
|
||||||
|
} else {
|
||||||
}
|
|
||||||
else{
|
|
||||||
Log.d("Status", con.responseMessage)
|
Log.d("Status", con.responseMessage)
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
token.status = 0
|
token.status = 0
|
||||||
}
|
}
|
||||||
|
@ -124,32 +115,31 @@ class Auth: Client() {
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
fun me(token: String): UserModel{
|
fun me(token: String): UserModel {
|
||||||
val con = this._newCon("users/me","GET", token)
|
val con = this._newCon("users/me", "GET", token)
|
||||||
val user = UserModel()
|
val user = UserModel()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (con.responseCode == 200) {
|
||||||
if(con.responseCode==200){
|
|
||||||
val response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
val data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
|
|
||||||
while(data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val k = data.nextName()
|
val k = data.nextName()
|
||||||
when(k.toString()){
|
when (k.toString()) {
|
||||||
"id" -> user.uuid = data.nextInt()
|
"id" -> user.uuid = data.nextInt()
|
||||||
"username" -> user.username = data.nextString()
|
"username" -> user.username = data.nextString()
|
||||||
"email" -> user.email = data.nextString()
|
"email" -> user.email = data.nextString()
|
||||||
"displayNSFW" -> user.nsfw = data.nextBoolean()
|
"displayNSFW" -> user.nsfw = data.nextBoolean()
|
||||||
"account" -> {
|
"account" -> {
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val l = data.nextName()
|
val l = data.nextName()
|
||||||
when(l.toString()){
|
when (l.toString()) {
|
||||||
"followersCount" -> user.followers = data.nextInt()
|
"followersCount" -> user.followers = data.nextInt()
|
||||||
"avatar" -> {
|
"avatar" -> {
|
||||||
if(data.peek() == JsonToken.BEGIN_OBJECT) {
|
if (data.peek() == JsonToken.BEGIN_OBJECT) {
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()) {
|
while (data.hasNext()) {
|
||||||
val m = data.nextName()
|
val m = data.nextName()
|
||||||
|
@ -159,8 +149,7 @@ class Auth: Client() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.endObject()
|
data.endObject()
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,13 +165,10 @@ class Auth: Client() {
|
||||||
data.endObject()
|
data.endObject()
|
||||||
data.close()
|
data.close()
|
||||||
user.status = 1
|
user.status = 1
|
||||||
|
} else {
|
||||||
}
|
|
||||||
else{
|
|
||||||
Log.d("Status", con.responseMessage)
|
Log.d("Status", con.responseMessage)
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
user.status = 0
|
user.status = 0
|
||||||
}
|
}
|
||||||
|
@ -190,5 +176,4 @@ class Auth: Client() {
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package org.libre.agosto.p2play.ajax
|
package org.libre.agosto.p2play.ajax
|
||||||
|
|
||||||
import android.util.JsonReader
|
import android.util.JsonReader
|
||||||
import android.util.JsonToken
|
|
||||||
import org.libre.agosto.p2play.models.ChannelModel
|
import org.libre.agosto.p2play.models.ChannelModel
|
||||||
import org.libre.agosto.p2play.models.CommentaryModel
|
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
class Channels: Client() {
|
class Channels : Client() {
|
||||||
|
|
||||||
private fun parseChannel(data: JsonReader): ChannelModel{
|
private fun parseChannel(data: JsonReader): ChannelModel {
|
||||||
val channel = ChannelModel()
|
val channel = ChannelModel()
|
||||||
|
|
||||||
data.close()
|
data.close()
|
||||||
|
@ -20,16 +18,16 @@ class Channels: Client() {
|
||||||
val con = this._newCon("video-channels/$account", "GET")
|
val con = this._newCon("video-channels/$account", "GET")
|
||||||
var channel = ChannelModel()
|
var channel = ChannelModel()
|
||||||
try {
|
try {
|
||||||
if(con.responseCode == 200){
|
if (con.responseCode == 200) {
|
||||||
val response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
val data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
channel.parseChannel(data)
|
channel.parseChannel(data)
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
}catch (err: Exception) {
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.util.Log
|
||||||
import org.libre.agosto.p2play.ManagerSingleton
|
import org.libre.agosto.p2play.ManagerSingleton
|
||||||
import org.libre.agosto.p2play.models.HostModel
|
import org.libre.agosto.p2play.models.HostModel
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.io.Reader
|
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
|
@ -18,24 +17,25 @@ open class Client {
|
||||||
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
|
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
|
||||||
con.setRequestProperty("Accept", "*/*")
|
con.setRequestProperty("Accept", "*/*")
|
||||||
|
|
||||||
if(token != ""){
|
if (token != "") {
|
||||||
con.setRequestProperty("Authorization", "Bearer $token")
|
con.setRequestProperty("Authorization", "Bearer $token")
|
||||||
}
|
}
|
||||||
|
|
||||||
con.requestMethod=method
|
con.requestMethod = method
|
||||||
con.connectTimeout=60000
|
con.connectTimeout = 60000
|
||||||
con.readTimeout=60000
|
con.readTimeout = 60000
|
||||||
|
|
||||||
if(method == "POST")
|
if (method == "POST") {
|
||||||
con.doOutput=true
|
con.doOutput = true
|
||||||
|
}
|
||||||
|
|
||||||
Log.d("Petition", url.toString())
|
Log.d("Petition", url.toString())
|
||||||
return con
|
return con
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getKeys():HostModel{
|
fun getKeys(): HostModel {
|
||||||
val con = this._newCon("oauth-clients/local","GET")
|
val con = this._newCon("oauth-clients/local", "GET")
|
||||||
val keys = HostModel("","")
|
val keys = HostModel("", "")
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
val response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
|
@ -44,25 +44,24 @@ open class Client {
|
||||||
while (data.hasNext()) {
|
while (data.hasNext()) {
|
||||||
val key = data.nextName()
|
val key = data.nextName()
|
||||||
when (key.toString()) {
|
when (key.toString()) {
|
||||||
"client_id"->{
|
"client_id" -> {
|
||||||
keys.client_id = data.nextString()
|
keys.client_id = data.nextString()
|
||||||
}
|
}
|
||||||
"client_secret"->{
|
"client_secret" -> {
|
||||||
keys.client_secret = data.nextString()
|
keys.client_secret = data.nextString()
|
||||||
}
|
}
|
||||||
else->{
|
else -> {
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
package org.libre.agosto.p2play.ajax
|
package org.libre.agosto.p2play.ajax
|
||||||
|
|
||||||
import android.util.JsonReader
|
import android.util.JsonReader
|
||||||
import android.util.JsonToken
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import org.libre.agosto.p2play.models.CommentaryModel
|
import org.libre.agosto.p2play.models.CommentaryModel
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
class Comments: Client() {
|
class Comments : Client() {
|
||||||
|
|
||||||
private fun parseCommentaries(data: JsonReader): ArrayList<CommentaryModel> {
|
private fun parseCommentaries(data: JsonReader): ArrayList<CommentaryModel> {
|
||||||
val commentaries = arrayListOf<CommentaryModel>()
|
val commentaries = arrayListOf<CommentaryModel>()
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
when(data.nextName()) {
|
when (data.nextName()) {
|
||||||
"data" -> {
|
"data" -> {
|
||||||
data.beginArray()
|
data.beginArray()
|
||||||
while (data.hasNext()) {
|
while (data.hasNext()) {
|
||||||
|
@ -41,7 +40,7 @@ class Comments: Client() {
|
||||||
commentaries = parseCommentaries(data)
|
commentaries = parseCommentaries(data)
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
|
@ -59,13 +58,11 @@ class Comments: Client() {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
response = true
|
response = true
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
Log.d("Status", con.responseMessage)
|
Log.d("Status", con.responseMessage)
|
||||||
response = false
|
response = false
|
||||||
}
|
}
|
||||||
}
|
} catch (err: Exception) {
|
||||||
catch (err: Exception){
|
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
response = false
|
response = false
|
||||||
}
|
}
|
||||||
|
@ -73,5 +70,4 @@ class Comments: Client() {
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -5,14 +5,14 @@ import org.libre.agosto.p2play.ManagerSingleton
|
||||||
import org.libre.agosto.p2play.models.VideoModel
|
import org.libre.agosto.p2play.models.VideoModel
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
class Videos: Client() {
|
class Videos : Client() {
|
||||||
|
|
||||||
private fun parseVideos(data: JsonReader): ArrayList<VideoModel>{
|
private fun parseVideos(data: JsonReader): ArrayList<VideoModel> {
|
||||||
val videos = arrayListOf<VideoModel>()
|
val videos = arrayListOf<VideoModel>()
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
when(data.nextName()){
|
when (data.nextName()) {
|
||||||
"data"->{
|
"data" -> {
|
||||||
data.beginArray()
|
data.beginArray()
|
||||||
while (data.hasNext()) {
|
while (data.hasNext()) {
|
||||||
val video = VideoModel()
|
val video = VideoModel()
|
||||||
|
@ -21,7 +21,7 @@ class Videos: Client() {
|
||||||
}
|
}
|
||||||
data.endArray()
|
data.endArray()
|
||||||
}
|
}
|
||||||
else-> data.skipValue()
|
else -> data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.endObject()
|
data.endObject()
|
||||||
|
@ -29,12 +29,12 @@ class Videos: Client() {
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getVideos(start:Int, sort:String = "-publishedAt", isLocal:Boolean = false):ArrayList<VideoModel>{
|
private fun getVideos(start: Int, sort: String = "-publishedAt", isLocal: Boolean = false): ArrayList<VideoModel> {
|
||||||
val nsfw = ManagerSingleton.nfsw
|
val nsfw = ManagerSingleton.nfsw
|
||||||
val count = ManagerSingleton.videos_count
|
val count = ManagerSingleton.videos_count
|
||||||
var params = "start=$start&count=$count&sort=$sort&nsfw=$nsfw&isLocal=$isLocal"
|
var params = "start=$start&count=$count&sort=$sort&nsfw=$nsfw&isLocal=$isLocal"
|
||||||
|
|
||||||
val con = this._newCon("videos?$params","GET")
|
val con = this._newCon("videos?$params", "GET")
|
||||||
var videos = arrayListOf<VideoModel>()
|
var videos = arrayListOf<VideoModel>()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
|
@ -43,33 +43,33 @@ class Videos: Client() {
|
||||||
videos = parseVideos(data)
|
videos = parseVideos(data)
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLastVideos(start:Int = 0): ArrayList<VideoModel>{
|
fun getLastVideos(start: Int = 0): ArrayList<VideoModel> {
|
||||||
return this.getVideos(start)
|
return this.getVideos(start)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPopularVideos(start:Int = 0): ArrayList<VideoModel>{
|
fun getPopularVideos(start: Int = 0): ArrayList<VideoModel> {
|
||||||
return this.getVideos(start,"-views")
|
return this.getVideos(start, "-views")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTrendingVideos(start:Int = 0): ArrayList<VideoModel>{
|
fun getTrendingVideos(start: Int = 0): ArrayList<VideoModel> {
|
||||||
return this.getVideos(start,"-trending")
|
return this.getVideos(start, "-trending")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLocalVideos(start:Int = 0): ArrayList<VideoModel>{
|
fun getLocalVideos(start: Int = 0): ArrayList<VideoModel> {
|
||||||
return this.getVideos(start,"-publishedAt", true)
|
return this.getVideos(start, "-publishedAt", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun myVideos(token: String, start: Int = 0): ArrayList<VideoModel>{
|
fun myVideos(token: String, start: Int = 0): ArrayList<VideoModel> {
|
||||||
val count = ManagerSingleton.videos_count
|
val count = ManagerSingleton.videos_count
|
||||||
val params = "start=$start&count=$count"
|
val params = "start=$start&count=$count"
|
||||||
val con = this._newCon("users/me/videos?$params","GET", token)
|
val con = this._newCon("users/me/videos?$params", "GET", token)
|
||||||
var videos = arrayListOf<VideoModel>()
|
var videos = arrayListOf<VideoModel>()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
|
@ -78,7 +78,7 @@ class Videos: Client() {
|
||||||
videos = parseVideos(data)
|
videos = parseVideos(data)
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,10 +86,10 @@ class Videos: Client() {
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
|
||||||
fun videoSubscriptions(token: String, start: Int = 0): ArrayList<VideoModel>{
|
fun videoSubscriptions(token: String, start: Int = 0): ArrayList<VideoModel> {
|
||||||
val count = ManagerSingleton.videos_count
|
val count = ManagerSingleton.videos_count
|
||||||
val params = "start=$start&count=$count"
|
val params = "start=$start&count=$count"
|
||||||
val con = this._newCon("users/me/subscriptions/videos?$params","GET", token)
|
val con = this._newCon("users/me/subscriptions/videos?$params", "GET", token)
|
||||||
var videos = arrayListOf<VideoModel>()
|
var videos = arrayListOf<VideoModel>()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
|
@ -102,7 +102,7 @@ class Videos: Client() {
|
||||||
val data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
print(data)
|
print(data)
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,10 +110,10 @@ class Videos: Client() {
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
|
||||||
fun videoHistory(token: String, start: Int = 0): ArrayList<VideoModel>{
|
fun videoHistory(token: String, start: Int = 0): ArrayList<VideoModel> {
|
||||||
val count = ManagerSingleton.videos_count
|
val count = ManagerSingleton.videos_count
|
||||||
val params = "start=$start&count=$count"
|
val params = "start=$start&count=$count"
|
||||||
val con = this._newCon("users/me/history/videos?$params","GET", token)
|
val con = this._newCon("users/me/history/videos?$params", "GET", token)
|
||||||
var videos = arrayListOf<VideoModel>()
|
var videos = arrayListOf<VideoModel>()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
|
@ -122,7 +122,7 @@ class Videos: Client() {
|
||||||
videos = parseVideos(data)
|
videos = parseVideos(data)
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,11 +130,11 @@ class Videos: Client() {
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
|
||||||
fun search(text: String, start: Int = 0): ArrayList<VideoModel>{
|
fun search(text: String, start: Int = 0): ArrayList<VideoModel> {
|
||||||
val count = ManagerSingleton.videos_count
|
val count = ManagerSingleton.videos_count
|
||||||
val nsfw = ManagerSingleton.nfsw
|
val nsfw = ManagerSingleton.nfsw
|
||||||
val params = "search=$text&start=$start&count=$count&nsfw=$nsfw"
|
val params = "search=$text&start=$start&count=$count&nsfw=$nsfw"
|
||||||
val con = this._newCon("search/videos?$params","GET")
|
val con = this._newCon("search/videos?$params", "GET")
|
||||||
var videos = arrayListOf<VideoModel>()
|
var videos = arrayListOf<VideoModel>()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
|
@ -143,15 +143,15 @@ class Videos: Client() {
|
||||||
videos = parseVideos(data)
|
videos = parseVideos(data)
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fullDescription(videoId: Int): String{
|
fun fullDescription(videoId: Int): String {
|
||||||
val con = this._newCon("videos/$videoId/description","GET")
|
val con = this._newCon("videos/$videoId/description", "GET")
|
||||||
var description = ""
|
var description = ""
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
|
@ -159,9 +159,9 @@ class Videos: Client() {
|
||||||
val data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
|
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val name = data.nextName()
|
val name = data.nextName()
|
||||||
when(name){
|
when (name) {
|
||||||
"description" -> description = data.nextString()
|
"description" -> description = data.nextString()
|
||||||
else -> data.skipValue()
|
else -> data.skipValue()
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ class Videos: Client() {
|
||||||
data.endObject()
|
data.endObject()
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
description = "Error!"
|
description = "Error!"
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ class Videos: Client() {
|
||||||
fun channelVideos(account: String, start: Int): ArrayList<VideoModel> {
|
fun channelVideos(account: String, start: Int): ArrayList<VideoModel> {
|
||||||
val count = ManagerSingleton.videos_count
|
val count = ManagerSingleton.videos_count
|
||||||
val params = "start=$start&count=$count"
|
val params = "start=$start&count=$count"
|
||||||
val con = this._newCon("video-channels/$account/videos?$params","GET")
|
val con = this._newCon("video-channels/$account/videos?$params", "GET")
|
||||||
var videos = arrayListOf<VideoModel>()
|
var videos = arrayListOf<VideoModel>()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
|
@ -189,7 +189,7 @@ class Videos: Client() {
|
||||||
videos = parseVideos(data)
|
videos = parseVideos(data)
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,12 +197,12 @@ class Videos: Client() {
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMostLikedVideos(start:Int = 0): ArrayList<VideoModel>{
|
fun getMostLikedVideos(start: Int = 0): ArrayList<VideoModel> {
|
||||||
return this.getVideos(start,"-likes")
|
return this.getVideos(start, "-likes")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVideo(uuid: String): VideoModel {
|
fun getVideo(uuid: String): VideoModel {
|
||||||
val con = this._newCon("videos/$uuid","GET")
|
val con = this._newCon("videos/$uuid", "GET")
|
||||||
val video = VideoModel()
|
val video = VideoModel()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
|
@ -211,11 +211,11 @@ class Videos: Client() {
|
||||||
video.parseVideo(data)
|
video.parseVideo(data)
|
||||||
data.close()
|
data.close()
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch (err: Exception) {
|
||||||
err.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
con.disconnect()
|
con.disconnect()
|
||||||
return video
|
return video
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.libre.agosto.p2play.helpers
|
package org.libre.agosto.p2play.helpers
|
||||||
|
|
||||||
fun mapSeconds (inputSeconds: Int): String {
|
fun mapSeconds(inputSeconds: Int): String {
|
||||||
val seconds = (inputSeconds % 60)
|
val seconds = (inputSeconds % 60)
|
||||||
var minutes = inputSeconds / 60
|
var minutes = inputSeconds / 60
|
||||||
var hours = 0
|
var hours = 0
|
||||||
|
@ -17,4 +17,4 @@ fun mapSeconds (inputSeconds: Int): String {
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,10 @@ import android.view.View
|
||||||
import android.view.Window
|
import android.view.Window
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
|
||||||
fun setFullscreen (window: Window) {
|
fun setFullscreen(window: Window) {
|
||||||
val attrs = window.attributes
|
val attrs = window.attributes
|
||||||
attrs.flags = attrs.flags or WindowManager.LayoutParams.FLAG_FULLSCREEN
|
attrs.flags = attrs.flags or WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||||
attrs.flags = attrs.flags or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
attrs.flags = attrs.flags or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||||
window.attributes = attrs
|
window.attributes = attrs
|
||||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,16 @@ package org.libre.agosto.p2play.models
|
||||||
import android.util.JsonReader
|
import android.util.JsonReader
|
||||||
import android.util.JsonToken
|
import android.util.JsonToken
|
||||||
|
|
||||||
class ChannelModel (
|
class ChannelModel(
|
||||||
var id: Int = 0,
|
var id: Int = 0,
|
||||||
var url: String = "",
|
var url: String = "",
|
||||||
var nameChannel: String = "",
|
var nameChannel: String = "",
|
||||||
var followers: Int = 0,
|
var followers: Int = 0,
|
||||||
var host: String = "",
|
var host: String = "",
|
||||||
var name: String = "",
|
var name: String = "",
|
||||||
var description: String = "",
|
var description: String = "",
|
||||||
var support: String = "",
|
var support: String = "",
|
||||||
var channelImg: String = ""
|
var channelImg: String = "",
|
||||||
) {
|
) {
|
||||||
fun getAccount(): String {
|
fun getAccount(): String {
|
||||||
return "$nameChannel@$host"
|
return "$nameChannel@$host"
|
||||||
|
@ -22,8 +22,7 @@ class ChannelModel (
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
|
|
||||||
while (data.hasNext()) {
|
while (data.hasNext()) {
|
||||||
|
when (data.nextName()) {
|
||||||
when(data.nextName()){
|
|
||||||
"id" -> this.id = data.nextInt()
|
"id" -> this.id = data.nextInt()
|
||||||
"url" -> this.url = data.nextString()
|
"url" -> this.url = data.nextString()
|
||||||
"name" -> this.nameChannel = data.nextString()
|
"name" -> this.nameChannel = data.nextString()
|
||||||
|
@ -31,34 +30,36 @@ class ChannelModel (
|
||||||
"followersCount" -> this.followers = data.nextInt()
|
"followersCount" -> this.followers = data.nextInt()
|
||||||
"displayName" -> this.name = data.nextString()
|
"displayName" -> this.name = data.nextString()
|
||||||
"description" -> {
|
"description" -> {
|
||||||
if(data.peek() == JsonToken.STRING)
|
if (data.peek() == JsonToken.STRING) {
|
||||||
this.description = data.nextString()
|
this.description = data.nextString()
|
||||||
else
|
} else {
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"support" -> {
|
"support" -> {
|
||||||
if(data.peek() == JsonToken.STRING)
|
if (data.peek() == JsonToken.STRING) {
|
||||||
this.support = data.nextString()
|
this.support = data.nextString()
|
||||||
else
|
} else {
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"avatar" -> {
|
"avatar" -> {
|
||||||
if(data.peek() == JsonToken.BEGIN_OBJECT){
|
if (data.peek() == JsonToken.BEGIN_OBJECT) {
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
when(data.nextName()){
|
when (data.nextName()) {
|
||||||
"path" -> this.channelImg = data.nextString()
|
"path" -> this.channelImg = data.nextString()
|
||||||
else -> data.skipValue()
|
else -> data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.endObject()
|
data.endObject()
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> data.skipValue()
|
else -> data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.endObject()
|
data.endObject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,16 @@ package org.libre.agosto.p2play.models
|
||||||
import android.util.JsonReader
|
import android.util.JsonReader
|
||||||
import android.util.JsonToken
|
import android.util.JsonToken
|
||||||
|
|
||||||
class CommentaryModel (
|
class CommentaryModel(
|
||||||
var id: Int = 0,
|
var id: Int = 0,
|
||||||
var threadId: Int = 0,
|
var threadId: Int = 0,
|
||||||
var userUuid: String = "",
|
var userUuid: String = "",
|
||||||
var username: String = "",
|
var username: String = "",
|
||||||
var userImageUrl: String = "",
|
var userImageUrl: String = "",
|
||||||
var commentary: String = "",
|
var commentary: String = "",
|
||||||
var userHost: String = "",
|
var userHost: String = "",
|
||||||
var replies: Int = 0,
|
var replies: Int = 0,
|
||||||
var nameChannel: String = ""
|
var nameChannel: String = "",
|
||||||
) {
|
) {
|
||||||
fun parseCommentary(data: JsonReader) {
|
fun parseCommentary(data: JsonReader) {
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
|
@ -25,25 +25,24 @@ class CommentaryModel (
|
||||||
"totalReplies" -> this.replies = data.nextInt()
|
"totalReplies" -> this.replies = data.nextInt()
|
||||||
"account" -> {
|
"account" -> {
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val acKey = data.nextName()
|
val acKey = data.nextName()
|
||||||
when(acKey.toString()){
|
when (acKey.toString()) {
|
||||||
"displayName"-> this.username=data.nextString()
|
"displayName" -> this.username = data.nextString()
|
||||||
"avatar"-> {
|
"avatar" -> {
|
||||||
if(data.peek() == JsonToken.BEGIN_OBJECT){
|
if (data.peek() == JsonToken.BEGIN_OBJECT) {
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val avKey = data.nextName()
|
val avKey = data.nextName()
|
||||||
when(avKey){
|
when (avKey) {
|
||||||
"path"-> this.userImageUrl = data.nextString()
|
"path" -> this.userImageUrl = data.nextString()
|
||||||
else-> data.skipValue()
|
else -> data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.endObject()
|
data.endObject()
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"uuid" -> this.userUuid = data.nextString()
|
"uuid" -> this.userUuid = data.nextString()
|
||||||
"host" -> this.userHost = data.nextString()
|
"host" -> this.userHost = data.nextString()
|
||||||
|
@ -60,7 +59,6 @@ class CommentaryModel (
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAccount(): String {
|
fun getAccount(): String {
|
||||||
return "$nameChannel@$userHost"
|
return "$nameChannel@$userHost"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package org.libre.agosto.p2play.models
|
package org.libre.agosto.p2play.models
|
||||||
|
|
||||||
class HostModel (var client_id:String, var client_secret:String)
|
class HostModel(var client_id: String, var client_secret: String)
|
||||||
|
|
|
@ -12,10 +12,10 @@ class StreamingModel(
|
||||||
while (data.hasNext()) {
|
while (data.hasNext()) {
|
||||||
val key = data.nextName()
|
val key = data.nextName()
|
||||||
when (key.toString()) {
|
when (key.toString()) {
|
||||||
"playlistUrl"->{
|
"playlistUrl" -> {
|
||||||
this.playlistUrl = data.nextString()
|
this.playlistUrl = data.nextString()
|
||||||
}
|
}
|
||||||
"segmentsSha256Url"->{
|
"segmentsSha256Url" -> {
|
||||||
this.segmentsSha256Url = data.nextString()
|
this.segmentsSha256Url = data.nextString()
|
||||||
}
|
}
|
||||||
else -> data.skipValue()
|
else -> data.skipValue()
|
||||||
|
@ -23,4 +23,4 @@ class StreamingModel(
|
||||||
}
|
}
|
||||||
data.endObject()
|
data.endObject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.libre.agosto.p2play.models
|
package org.libre.agosto.p2play.models
|
||||||
|
|
||||||
class TokenModel (
|
class TokenModel(
|
||||||
var token: String = "",
|
var token: String = "",
|
||||||
var refresh_token: String = "",
|
var refresh_token: String = "",
|
||||||
var status: Int = -1
|
var status: Int = -1,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package org.libre.agosto.p2play.models
|
package org.libre.agosto.p2play.models
|
||||||
|
|
||||||
class UserModel (
|
class UserModel(
|
||||||
var id: Int = 0,
|
var id: Int = 0,
|
||||||
var uuid: Int = 0,
|
var uuid: Int = 0,
|
||||||
var username: String = "",
|
var username: String = "",
|
||||||
var email: String = "",
|
var email: String = "",
|
||||||
var nsfw: Boolean = true,
|
var nsfw: Boolean = true,
|
||||||
var followers: Int = 0,
|
var followers: Int = 0,
|
||||||
var avatar: String = "",
|
var avatar: String = "",
|
||||||
var status: Int = -1
|
var status: Int = -1,
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,8 +19,8 @@ class VideoModel(
|
||||||
var userHost: String = "",
|
var userHost: String = "",
|
||||||
var nameChannel: String = "",
|
var nameChannel: String = "",
|
||||||
var isLive: Boolean = false,
|
var isLive: Boolean = false,
|
||||||
var streamingData: StreamingModel? = null
|
var streamingData: StreamingModel? = null,
|
||||||
):Serializable {
|
) : Serializable {
|
||||||
fun getChannel(): String {
|
fun getChannel(): String {
|
||||||
return "$nameChannel@$userHost"
|
return "$nameChannel@$userHost"
|
||||||
}
|
}
|
||||||
|
@ -29,38 +29,39 @@ class VideoModel(
|
||||||
return "https://$userHost/videos/watch/$uuid"
|
return "https://$userHost/videos/watch/$uuid"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parseVideo(data: JsonReader){
|
fun parseVideo(data: JsonReader) {
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val key = data.nextName()
|
val key = data.nextName()
|
||||||
when (key.toString()) {
|
when (key.toString()) {
|
||||||
"id"-> this.id = data.nextInt()
|
"id" -> this.id = data.nextInt()
|
||||||
"uuid" -> this.uuid = data.nextString()
|
"uuid" -> this.uuid = data.nextString()
|
||||||
"name"->{
|
"name" -> {
|
||||||
this.name= data.nextString()
|
this.name = data.nextString()
|
||||||
}
|
}
|
||||||
"description"->{
|
"description" -> {
|
||||||
if(data.peek() == JsonToken.STRING)
|
if (data.peek() == JsonToken.STRING) {
|
||||||
this.description = data.nextString()
|
this.description = data.nextString()
|
||||||
else
|
} else {
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"duration"->{
|
"duration" -> {
|
||||||
this.duration = data.nextInt()
|
this.duration = data.nextInt()
|
||||||
}
|
}
|
||||||
"thumbnailPath"->{
|
"thumbnailPath" -> {
|
||||||
this.thumbUrl = data.nextString()
|
this.thumbUrl = data.nextString()
|
||||||
}
|
}
|
||||||
"embedPath"->{
|
"embedPath" -> {
|
||||||
this.embedUrl = data.nextString()
|
this.embedUrl = data.nextString()
|
||||||
}
|
}
|
||||||
"views"->{
|
"views" -> {
|
||||||
this.views = data.nextInt()
|
this.views = data.nextInt()
|
||||||
}
|
}
|
||||||
"isLive"-> {
|
"isLive" -> {
|
||||||
this.isLive = data.nextBoolean()
|
this.isLive = data.nextBoolean()
|
||||||
}
|
}
|
||||||
"streamingPlaylists"-> {
|
"streamingPlaylists" -> {
|
||||||
data.beginArray()
|
data.beginArray()
|
||||||
if (data.hasNext()) {
|
if (data.hasNext()) {
|
||||||
val streamingData = StreamingModel()
|
val streamingData = StreamingModel()
|
||||||
|
@ -77,7 +78,7 @@ class VideoModel(
|
||||||
while (data.hasNext()) {
|
while (data.hasNext()) {
|
||||||
val key2 = data.nextName()
|
val key2 = data.nextName()
|
||||||
when (key2.toString()) {
|
when (key2.toString()) {
|
||||||
"fileDownloadUrl"->{
|
"fileDownloadUrl" -> {
|
||||||
streamingData = StreamingModel()
|
streamingData = StreamingModel()
|
||||||
streamingData!!.playlistUrl = data.nextString()
|
streamingData!!.playlistUrl = data.nextString()
|
||||||
}
|
}
|
||||||
|
@ -89,41 +90,40 @@ class VideoModel(
|
||||||
data.endArray()
|
data.endArray()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"channel"->{
|
"channel" -> {
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val acKey = data.nextName()
|
val acKey = data.nextName()
|
||||||
when(acKey.toString()){
|
when (acKey.toString()) {
|
||||||
"displayName"-> this.username=data.nextString()
|
"displayName" -> this.username = data.nextString()
|
||||||
"avatar"-> {
|
"avatar" -> {
|
||||||
if(data.peek() == JsonToken.BEGIN_OBJECT){
|
if (data.peek() == JsonToken.BEGIN_OBJECT) {
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()) {
|
||||||
val avKey = data.nextName()
|
val avKey = data.nextName()
|
||||||
when(avKey){
|
when (avKey) {
|
||||||
"path"-> this.userImageUrl = data.nextString()
|
"path" -> this.userImageUrl = data.nextString()
|
||||||
else-> data.skipValue()
|
else -> data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.endObject()
|
data.endObject()
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"uuid" -> this.userUuid = data.nextString()
|
"uuid" -> this.userUuid = data.nextString()
|
||||||
"host" -> this.userHost = data.nextString()
|
"host" -> this.userHost = data.nextString()
|
||||||
"name" -> this.nameChannel = data.nextString()
|
"name" -> this.nameChannel = data.nextString()
|
||||||
else-> data.skipValue()
|
else -> data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.endObject()
|
data.endObject()
|
||||||
}
|
}
|
||||||
else->{
|
else -> {
|
||||||
data.skipValue()
|
data.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.endObject()
|
data.endObject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package org.libre.agosto.p2play
|
package org.libre.agosto.p2play
|
||||||
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example local unit test, which will execute on the development machine (host).
|
* Example local unit test, which will execute on the development machine (host).
|
||||||
|
|
|
@ -12,6 +12,7 @@ android.useAndroidX=true
|
||||||
android.defaults.buildfeatures.buildconfig=true
|
android.defaults.buildfeatures.buildconfig=true
|
||||||
android.nonTransitiveRClass=false
|
android.nonTransitiveRClass=false
|
||||||
android.nonFinalResIds=false
|
android.nonFinalResIds=false
|
||||||
|
org.gradle.configuration-cache=true
|
||||||
|
|
||||||
# When configured, Gradle will run in incubating parallel mode.
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
# This option should only be used with decoupled projects. More details, visit
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
|
|
Loading…
Reference in New Issue