Fix lint errors automated

This commit is contained in:
Ivan Agosto 2024-04-06 14:38:04 -06:00
parent 96d8ae19c6
commit b6e1a979ca
33 changed files with 430 additions and 472 deletions

2
.editorconfig Normal file
View File

@ -0,0 +1,2 @@
[*.{kt,kts}]
ktlint_code_style = intellij_idea

View File

@ -1,6 +1,5 @@
package org.libre.agosto.p2play
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_about.*
@ -11,7 +10,7 @@ class AboutActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
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
}

View File

@ -1,6 +1,5 @@
package org.libre.agosto.p2play
import androidx.appcompat.app.ActionBar
import android.content.res.Configuration
import android.os.Bundle
import android.preference.PreferenceActivity
@ -8,6 +7,7 @@ import android.view.MenuInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.widget.Toolbar

View File

@ -1,11 +1,11 @@
package org.libre.agosto.p2play
import android.os.AsyncTask
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.activity_channel.*
import org.libre.agosto.p2play.adapters.VideosAdapter
@ -47,7 +47,7 @@ class ChannelActivity : AppCompatActivity() {
getSubscription()
getVideos()
if(ManagerSingleton.user.status == 1) {
if (ManagerSingleton.user.status == 1) {
subcriptionBtn.visibility = View.VISIBLE
getSubscription()
}
@ -60,8 +60,9 @@ class ChannelActivity : AppCompatActivity() {
usernameProfile.text = channel.name
hostTxt.text = channel.host
subcriptionsTxt.text = channel.followers.toString()
if(channel.channelImg != "")
if (channel.channelImg != "") {
Picasso.get().load("https://${ManagerSingleton.url}${channel.channelImg}").into(channelImg)
}
}
}
}
@ -70,12 +71,11 @@ class ChannelActivity : AppCompatActivity() {
AsyncTask.execute {
val res = _actions.subscribe(ManagerSingleton.token.token, channel.getAccount())
runOnUiThread {
if(res == 1){
if (res == 1) {
subcriptionBtn.text = getString(R.string.unSubscribeBtn)
ManagerSingleton.Toast(getString(R.string.subscribeMsg), this)
getSubscription()
}
else {
} else {
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
}
}
@ -86,12 +86,11 @@ class ChannelActivity : AppCompatActivity() {
AsyncTask.execute {
val res = _actions.unSubscribe(ManagerSingleton.token.token, channel.getAccount())
runOnUiThread {
if(res == 1){
if (res == 1) {
subcriptionBtn.text = getString(R.string.subscribeBtn)
ManagerSingleton.Toast(getString(R.string.unSubscribeMsg), this)
getSubscription()
}
else {
} else {
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
}
}
@ -99,20 +98,20 @@ class ChannelActivity : AppCompatActivity() {
}
private fun subscribeAction() {
if(isSubcribed)
if (isSubcribed) {
unSubscribe()
else
} else {
subscribe()
}
}
private fun getSubscription() {
AsyncTask.execute {
isSubcribed = _actions.getSubscription(ManagerSingleton.token.token, channel.getAccount())
runOnUiThread {
if(isSubcribed){
if (isSubcribed) {
subcriptionBtn.text = getText(R.string.unSubscribeBtn)
}
else {
} else {
subcriptionBtn.text = getText(R.string.subscribeBtn)
}
}
@ -129,7 +128,7 @@ class ChannelActivity : AppCompatActivity() {
}
// Generic function for set data to RecyclerView
private fun initRecycler(data: ArrayList<VideoModel>){
private fun initRecycler(data: ArrayList<VideoModel>) {
// val data = arrayListOf<VideoModel>()
viewAdapter = VideosAdapter(data)
@ -146,4 +145,4 @@ class ChannelActivity : AppCompatActivity() {
}
// swipeContainer.isRefreshing = false
}
}
}

View File

@ -8,11 +8,11 @@ import android.database.sqlite.SQLiteOpenHelper
import org.libre.agosto.p2play.models.TokenModel
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"
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)"
override fun onCreate(db: SQLiteDatabase?) {
db?.execSQL(dbUsers)
@ -28,12 +28,12 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
fun newToken(token: TokenModel): Boolean {
val db = writableDatabase
this.closeTokens()
val newToken=ContentValues()
val newToken = ContentValues()
newToken.put("token", token.token)
newToken.put("refresh_token", token.refresh_token)
newToken.put("status", token.status)
db.insert("tokens",null,newToken)
db.insert("tokens", null, newToken)
return true
}
@ -41,7 +41,7 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
fun newUser(user: UserModel): Boolean {
val db = writableDatabase
this.closeUsers()
val newUser=ContentValues()
val newUser = ContentValues()
newUser.put("uuid", user.uuid)
newUser.put("username", user.username)
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("status", user.status)
db.insert("users",null, newUser)
db.insert("users", null, newUser)
return true
}
fun getToken(): TokenModel{
fun getToken(): TokenModel {
val db = writableDatabase
var token = TokenModel()
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()
token.token = cursor.getString(cursor.getColumnIndex("token")).toString()
@ -72,23 +72,22 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
cursor.close()
return token
}catch (e:SQLiteException){
} catch (e: SQLiteException) {
db?.execSQL(dbTokens)
}catch (e:Exception){
} catch (e: Exception) {
e.printStackTrace()
}
return token
}
fun getUser(): UserModel{
fun getUser(): UserModel {
val db = writableDatabase
var user = UserModel()
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()
user.uuid = cursor.getString(cursor.getColumnIndex("uuid")).toInt()
@ -103,28 +102,26 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
cursor.close()
return user
}catch (e:SQLiteException){
} catch (e: SQLiteException) {
db?.execSQL(dbTokens)
}catch (e:Exception){
} catch (e: Exception) {
e.printStackTrace()
}
return user
}
private fun closeTokens(){
private fun closeTokens() {
val db = writableDatabase
db.execSQL("UPDATE tokens SET status=-1 WHERE 1")
}
private fun closeUsers(){
private fun closeUsers() {
val db = writableDatabase
db.execSQL("UPDATE users SET status=-1 WHERE 1")
}
fun logout(){
fun logout() {
closeUsers()
closeTokens()
}
}
}

View File

@ -3,9 +3,9 @@ package org.libre.agosto.p2play
import android.content.Intent
import android.content.SharedPreferences
import android.os.AsyncTask
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import kotlinx.android.synthetic.main.activity_host.*
import org.libre.agosto.p2play.ajax.Auth
@ -13,7 +13,7 @@ import org.libre.agosto.p2play.ajax.Auth
class HostActivity : AppCompatActivity() {
lateinit var settings: SharedPreferences
lateinit var editor: SharedPreferences.Editor
val client:Auth = Auth()
val client: Auth = Auth()
val _db = Database(this)
override fun onCreate(savedInstanceState: Bundle?) {
@ -29,46 +29,46 @@ class HostActivity : AppCompatActivity() {
val host = settings.getString("hostP2play", "")
val lastHost = settings.getString("last_host", "")
if(host!=""){
if(lastHost!=host){
if (host != "") {
if (lastHost != host) {
_db.logout()
ManagerSingleton.logout()
getKeys(host!!)
}else{
} else {
ManagerSingleton.url = host
startApp()
}
}
}
fun saveHost(host: String){
editor.putString("last_host",host)
editor.putString("hostP2play",host)
fun saveHost(host: String) {
editor.putString("last_host", host)
editor.putString("hostP2play", host)
editor.apply()
ManagerSingleton.Toast(getString(R.string.finallyMsg), this)
ManagerSingleton.url=host
ManagerSingleton.url = host
startApp()
}
private fun getKeys(hostText: String){
private fun getKeys(hostText: String) {
button.isEnabled = false
var host = hostText.toString()
host = host.replace("http://","")
host = host.replace("https://","")
host = host.replace("/","")
host = host.replace("http://", "")
host = host.replace("https://", "")
host = host.replace("/", "")
ManagerSingleton.url = host
AsyncTask.execute {
if (Looper.myLooper()==null)
if (Looper.myLooper() == null) {
Looper.prepare()
}
val keys = client.getKeys()
if(keys.client_id!=""){
editor.putString("client_id",keys.client_id)
editor.putString("client_secret",keys.client_secret)
if (keys.client_id != "") {
editor.putString("client_id", keys.client_id)
editor.putString("client_secret", keys.client_secret)
editor.apply()
saveHost(host)
}
else{
} else {
runOnUiThread {
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
button.isEnabled = true
@ -77,9 +77,9 @@ class HostActivity : AppCompatActivity() {
}
}
private fun startApp(){
private fun startApp() {
runOnUiThread {
val intent = Intent(this,MainActivity::class.java)
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
this.finish()
}

View File

@ -3,11 +3,11 @@ package org.libre.agosto.p2play
import android.content.Intent
import android.content.SharedPreferences
import android.os.AsyncTask
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Looper
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import kotlinx.android.synthetic.main.activity_login.*
import org.libre.agosto.p2play.ajax.Auth
@ -34,21 +34,22 @@ class LoginActivity : AppCompatActivity() {
loginBtn.setOnClickListener { tryLogin() }
}
fun tryLogin(){
loginBtn.isEnabled = false;
fun tryLogin() {
loginBtn.isEnabled = false
val username = userText.text.toString()
val password = passwordText.text.toString()
AsyncTask.execute {
if (Looper.myLooper()==null)
if (Looper.myLooper() == null) {
Looper.prepare()
}
val token = _auth.login(username, password, client_id, client_secret, optCode)
// Log.d("token", token.token )
// Log.d("status", token.status.toString() )
when(token.status.toString()){
when (token.status.toString()) {
"1" -> {
_db.newToken(token)
ManagerSingleton.token = token
@ -90,21 +91,19 @@ class LoginActivity : AppCompatActivity() {
}
}
}
}
}
fun getUser(){
fun getUser() {
val user = _auth.me(ManagerSingleton.token.token)
if(user.status == 1){
if (user.status == 1) {
_db.newUser(user)
ManagerSingleton.user = user
runOnUiThread {
ManagerSingleton.Toast(getString(R.string.loginSuccess_msg), this)
finish()
}
}
else{
} else {
runOnUiThread {
ManagerSingleton.Toast(getString(R.string.loginError_msg), this)
}

View File

@ -2,13 +2,10 @@ package org.libre.agosto.p2play
import android.content.Intent
import android.os.AsyncTask
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
@ -39,7 +36,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
var searchVal: String = ""
var pagination = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@ -74,7 +70,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
// Generic function for set data to RecyclerView
private fun initRecycler(){
private fun initRecycler() {
val data = arrayListOf<VideoModel>()
viewAdapter = VideosAdapter(data)
@ -94,8 +90,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
super.onScrolled(recyclerView, dx, dy)
// super.onScrolled(recyclerView!!, dx, dy)
if(!swipeContainer.isRefreshing){
if(!canScrollVertically(1)){
if (!swipeContainer.isRefreshing) {
if (!canScrollVertically(1)) {
loadMore()
}
}
@ -105,17 +101,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
swipeContainer.isRefreshing = false
}
private fun addVideos(videos: ArrayList<VideoModel>){
private fun addVideos(videos: ArrayList<VideoModel>) {
this.swipeContainer.isRefreshing = true
try {
if(this.pagination == 0){
if (this.pagination == 0) {
(viewAdapter as VideosAdapter).clearData()
recyclerView.scrollToPosition(0)
}
(viewAdapter as VideosAdapter).addData(videos)
}catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
ManagerSingleton.Toast(getString(R.string.errorMsg), this)
}
@ -123,10 +119,10 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
this.swipeContainer.isRefreshing = false
}
private fun refresh(){
private fun refresh() {
swipeContainer.isRefreshing = true
this.pagination = 0
when(section){
when (section) {
"local" -> this.getLocalVideos()
"popular" -> this.getPopularVideos()
"trending" -> this.getTrengindVideos()
@ -134,16 +130,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
"sub" -> this.getSubscriptionVideos()
"search" -> this.searchVideos()
"my_videos" -> {
if(ManagerSingleton.token.token != "")
if (ManagerSingleton.token.token != "") {
this.getMyVideos()
else
} else {
this.getLastVideos()
}
}
}
}
private fun getSubscriptionVideos(){
if(ManagerSingleton.user.status != 1){
private fun getSubscriptionVideos() {
if (ManagerSingleton.user.status != 1) {
ManagerSingleton.Toast("Inicia session primero", this)
startActivity(Intent(this, LoginActivity::class.java))
return
@ -160,7 +157,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
// Last videos
private fun getLastVideos(){
private fun getLastVideos() {
swipeContainer.isRefreshing = true
section = "last"
setTitle(R.string.title_recent)
@ -173,7 +170,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
// Popular videos
private fun getPopularVideos(){
private fun getPopularVideos() {
swipeContainer.isRefreshing = true
section = "popular"
setTitle(R.string.title_popular)
@ -186,7 +183,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
// Trending videos
private fun getTrengindVideos(){
private fun getTrengindVideos() {
swipeContainer.isRefreshing = true
section = "trending"
setTitle(R.string.title_trending)
@ -199,7 +196,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
// Local videos
private fun getLocalVideos(){
private fun getLocalVideos() {
swipeContainer.isRefreshing = true
section = "local"
setTitle(R.string.title_local)
@ -212,7 +209,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
// Videos of user
private fun getMyVideos(){
private fun getMyVideos() {
swipeContainer.isRefreshing = true
section = "my_videos"
setTitle(R.string.title_myVideos)
@ -225,7 +222,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
// Videos history of user
private fun getHistory(){
private fun getHistory() {
swipeContainer.isRefreshing = true
section = "my_videos"
setTitle(R.string.nav_history)
@ -238,7 +235,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
// Most liked
private fun getMostLiked(){
private fun getMostLiked() {
swipeContainer.isRefreshing = true
section = "liked"
setTitle(R.string.nav_likes)
@ -252,14 +249,12 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
override fun onBackPressed() {
if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
drawer_layout.closeDrawer(GravityCompat.START)
}
else if(!section.equals("trending")) {
drawer_layout.closeDrawer(GravityCompat.START)
} else if (!section.equals("trending")) {
// Hot fix
pagination = 0
this.getTrengindVideos()
}
else {
} else {
super.onBackPressed()
}
}
@ -271,13 +266,13 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
val searchItem = menu.findItem(R.id.app_bar_search)
val searchView = searchItem.actionView as SearchView
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener{
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextChange(p0: String?): Boolean {
return true
}
override fun onQueryTextSubmit(p0: String?): Boolean {
if(!p0.isNullOrBlank()){
if (!p0.isNullOrBlank()) {
searchVal = p0
pagination = 0
searchView.onActionViewCollapsed()
@ -285,10 +280,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
return true
}
})
myMenu = menu
setSideData()
return true
@ -327,7 +320,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
// Handle navigation view item clicks here.
// if(::lastItem.isInitialized){
// lastItem.isChecked = false
// lastItem.isChecked = false
// }
lastItem = item
pagination = 0
@ -357,40 +350,39 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
setSideData()
}
private fun setSideData(){
if(ManagerSingleton.user.status == 1){
private fun setSideData() {
if (ManagerSingleton.user.status == 1) {
nav_view.menu.findItem(R.id.ml).isVisible = true
side_usernameTxt?.text = ManagerSingleton.user.username
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)
}
side_imageView?.setOnClickListener {
pagination = 0
side_imageView?.setOnClickListener {
pagination = 0
getMyVideos()
drawer_layout.closeDrawer(GravityCompat.START)
}
if(::myMenu.isInitialized){
drawer_layout.closeDrawer(GravityCompat.START)
}
if (::myMenu.isInitialized) {
myMenu.findItem(R.id.action_login).isVisible = false
myMenu.findItem(R.id.action_logout).isVisible = true
}
} else {
nav_view.menu.findItem(R.id.ml).isVisible = false
}
}
private fun logout(){
if(::myMenu.isInitialized){
private fun logout() {
if (::myMenu.isInitialized) {
myMenu.findItem(R.id.action_login).isVisible = true
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_emailTxt?.text = getString(R.string.nav_header_subtitle) + " " + this.packageManager.getPackageInfo(this.packageName, 0).versionName
side_imageView?.setImageResource(R.drawable.default_avatar)
side_imageView?.setOnClickListener { }
side_imageView?.setOnClickListener { }
_db.logout()
ManagerSingleton.logout()
@ -399,11 +391,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
setSideData()
}
private fun loadMore(){
private fun loadMore() {
swipeContainer.isRefreshing = true
this.pagination += ManagerSingleton.videos_count
when(section){
when (section) {
"local" -> this.getLocalVideos()
"popular" -> this.getPopularVideos()
"trending" -> this.getTrengindVideos()
@ -411,16 +403,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
"sub" -> this.getSubscriptionVideos()
"search" -> this.searchVideos()
"my_videos" -> {
if(ManagerSingleton.token.token != "")
if (ManagerSingleton.token.token != "") {
this.getMyVideos()
else
} else {
this.getLastVideos()
}
}
"liked" -> this.getMostLiked()
}
}
private fun searchVideos(){
private fun searchVideos() {
swipeContainer.isRefreshing = true
section = "search"
this.title = this.searchVal
@ -431,5 +424,4 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
}
}
}

View File

@ -1,14 +1,12 @@
package org.libre.agosto.p2play
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Handler
import org.libre.agosto.p2play.models.TokenModel
import org.libre.agosto.p2play.models.UserModel
object ManagerSingleton {
var url: String?= null
var url: String? = null
var user: UserModel = UserModel()
var token: TokenModel = TokenModel()
var nfsw: Boolean = false
@ -19,17 +17,17 @@ object ManagerSingleton {
android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show()
}
fun logout(){
fun logout() {
db.logout()
user = UserModel()
token = TokenModel()
}
fun reloadSettings () {
fun reloadSettings() {
val host = settings.getString("hostP2play", "")
val lastHost = settings.getString("last_host", "")
if(host != ""){
if(lastHost != host){
if (host != "") {
if (lastHost != host) {
logout()
}
url = host
@ -38,4 +36,4 @@ object ManagerSingleton {
nfsw = settings.getBoolean("show_nsfw", false)
videos_count = settings.getString("videos_count", "15")!!.toInt()
}
}
}

View File

@ -2,11 +2,11 @@ package org.libre.agosto.p2play
import android.content.SharedPreferences
import android.os.AsyncTask
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Looper
import android.preference.PreferenceManager
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_register.*
import org.libre.agosto.p2play.ajax.Auth
@ -28,14 +28,15 @@ class RegisterActivity : AppCompatActivity() {
registerBtn.setOnClickListener { registerUser() }
}
fun registerUser(){
fun registerUser() {
registerBtn.isEnabled = false
val username = userText2.text.toString()
val password = passwordText2.text.toString()
val email = emailText.text.toString()
AsyncTask.execute {
if (Looper.myLooper()==null)
if (Looper.myLooper() == null) {
Looper.prepare()
}
val res = _auth.register(username, password, email)
Log.d("Res register", res.toString())

View File

@ -5,17 +5,16 @@ import android.content.Intent
import android.content.pm.ActivityInfo
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.media.Image
import android.os.AsyncTask
import android.os.Bundle
import android.os.Looper
import androidx.appcompat.app.AlertDialog
import android.view.View
import android.view.WindowManager
import android.webkit.WebChromeClient
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.media3.common.MediaItem
@ -83,11 +82,11 @@ class ReproductorActivity : AppCompatActivity() {
hostTxt.text = this.video.userHost
// 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)
}
// Load the video
videoView.loadUrl("https://" + ManagerSingleton.url + this.video.embedUrl)
} catch (err: Exception) {
err.printStackTrace()
}
@ -113,7 +112,6 @@ class ReproductorActivity : AppCompatActivity() {
startActivity(intent)
}
AsyncTask.execute {
val video = this.clientVideo.getVideo(this.video.uuid)
// TODO: Make this configurable
@ -140,7 +138,7 @@ class ReproductorActivity : AppCompatActivity() {
player.prepare()
// Start the playback.
// player.play()
} catch(err: Exception) {
} catch (err: Exception) {
err.printStackTrace()
}
}
@ -149,8 +147,9 @@ class ReproductorActivity : AppCompatActivity() {
private fun subscribe() {
AsyncTask.execute {
if (Looper.myLooper() == null)
if (Looper.myLooper() == null) {
Looper.prepare()
}
val res = this._actions.subscribe(ManagerSingleton.token.token, video.getChannel())
if (res == 1) {
runOnUiThread {
@ -163,8 +162,9 @@ class ReproductorActivity : AppCompatActivity() {
private fun unSubscribe() {
AsyncTask.execute {
if (Looper.myLooper() == null)
if (Looper.myLooper() == null) {
Looper.prepare()
}
val res = this._actions.unSubscribe(ManagerSingleton.token.token, video.getChannel())
if (res == 1) {
runOnUiThread {
@ -177,8 +177,9 @@ class ReproductorActivity : AppCompatActivity() {
private fun rate(rate: String) {
AsyncTask.execute {
if (Looper.myLooper() == null)
if (Looper.myLooper() == null) {
Looper.prepare()
}
val res = this._actions.rate(ManagerSingleton.token.token, this.video.id, rate)
if (res == 1) {
runOnUiThread {
@ -197,8 +198,9 @@ class ReproductorActivity : AppCompatActivity() {
private fun getRate() {
AsyncTask.execute {
if (Looper.myLooper() == null)
if (Looper.myLooper() == null) {
Looper.prepare()
}
val rate = this._actions.getRate(ManagerSingleton.token.token, this.video.id)
runOnUiThread {
when (rate) {
@ -222,8 +224,9 @@ class ReproductorActivity : AppCompatActivity() {
private fun getSubscription() {
val account = this.video.nameChannel + "@" + this.video.userHost
AsyncTask.execute {
if (Looper.myLooper() == null)
if (Looper.myLooper() == null) {
Looper.prepare()
}
val isSubscribed = this._actions.getSubscription(ManagerSingleton.token.token, account)
runOnUiThread {
this.changeSubscribeBtn(isSubscribed)
@ -343,22 +346,21 @@ class ReproductorActivity : AppCompatActivity() {
alertDialog.show()
}
private fun reportVideo(reason: String){
private fun reportVideo(reason: String) {
AsyncTask.execute {
val res = _actions.reportVideo(video.id, reason, ManagerSingleton.token.token)
runOnUiThread {
if(res) {
if (res) {
ManagerSingleton.Toast(getText(R.string.reportDialogMsg).toString(), this)
}
else {
} else {
ManagerSingleton.Toast(getText(R.string.errorMsg).toString(), this)
}
}
}
}
private fun toggleFullscreen () {
private fun toggleFullscreen() {
if (isFullscreen) {
nonFullScreen.visibility = View.VISIBLE
fullScreenExo.visibility = View.GONE
@ -373,8 +375,7 @@ class ReproductorActivity : AppCompatActivity() {
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
isFullscreen = false
}
else {
} else {
val matchParent = WindowManager.LayoutParams.MATCH_PARENT
nonFullScreen.visibility = View.GONE
@ -395,7 +396,7 @@ class ReproductorActivity : AppCompatActivity() {
super.onDestroy()
}
internal inner class WebClient: WebChromeClient() {
internal inner class WebClient : WebChromeClient() {
private var mCustomView: View? = null
private var mCustomViewCallback: WebChromeClient.CustomViewCallback? = null
private var mOriginalOrientation: Int = 0
@ -408,7 +409,9 @@ class ReproductorActivity : AppCompatActivity() {
return if (mCustomView == null) {
null
} else BitmapFactory.decodeResource(this@ReproductorActivity.resources, 2130837573)
} else {
BitmapFactory.decodeResource(this@ReproductorActivity.resources, 2130837573)
}
}
override fun onHideCustomView() {
@ -429,8 +432,7 @@ class ReproductorActivity : AppCompatActivity() {
attrs.flags = attrs.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON.inv()
window.attributes = attrs
this@ReproductorActivity.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
}
}
@ -455,8 +457,7 @@ class ReproductorActivity : AppCompatActivity() {
setFullscreen(this@ReproductorActivity.window)
this@ReproductorActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
}
}

View File

@ -4,8 +4,6 @@ import android.annotation.TargetApi
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.media.RingtoneManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.preference.ListPreference
@ -13,9 +11,6 @@ import android.preference.Preference
import android.preference.PreferenceActivity
import android.preference.PreferenceFragment
import android.preference.PreferenceManager
import android.preference.RingtonePreference
import android.text.TextUtils
import android.util.Log
import android.view.MenuItem
/**
@ -67,8 +62,8 @@ class SettingsActivity : AppCompatPreferenceActivity() {
* Make sure to deny any unknown fragments here.
*/
override fun isValidFragment(fragmentName: String): Boolean {
return PreferenceFragment::class.java.name == fragmentName
|| GeneralPreferenceFragment::class.java.name == fragmentName
return PreferenceFragment::class.java.name == fragmentName ||
GeneralPreferenceFragment::class.java.name == fragmentName
}
/**
@ -116,11 +111,12 @@ class SettingsActivity : AppCompatPreferenceActivity() {
// Set the summary to reflect the new value.
preference.setSummary(
if (index >= 0)
listPreference.entries[index]
else
null)
if (index >= 0) {
listPreference.entries[index]
} else {
null
},
)
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
@ -152,10 +148,12 @@ class SettingsActivity : AppCompatPreferenceActivity() {
// Trigger the listener immediately with the preference's
// current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.context)
.getString(preference.key, ""))
sBindPreferenceSummaryToValueListener.onPreferenceChange(
preference,
PreferenceManager
.getDefaultSharedPreferences(preference.context)
.getString(preference.key, ""),
)
}
}
}

View File

@ -28,4 +28,4 @@ class SettingsActivity2 : AppCompatActivity() {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
}
}
}
}

View File

@ -3,12 +3,12 @@ package org.libre.agosto.p2play
import android.content.Intent
import android.content.SharedPreferences
import android.os.AsyncTask
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.preference.PreferenceManager
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import org.libre.agosto.p2play.ajax.Auth
import java.lang.Exception
@ -27,14 +27,14 @@ class SplashActivity : AppCompatActivity() {
ManagerSingleton.reloadSettings()
val host = settings.getString("hostP2play","")
val lastHost = settings.getString("last_host","")
if(host != ""){
if(lastHost != host){
val host = settings.getString("hostP2play", "")
val lastHost = settings.getString("last_host", "")
if (host != "") {
if (lastHost != host) {
Handler().postDelayed({
startHostActivity()
}, 2000)
}else{
} else {
ManagerSingleton.url = host
checkUser()
}
@ -45,14 +45,15 @@ class SplashActivity : AppCompatActivity() {
}
}
private fun checkUser(){
private fun checkUser() {
Log.d("was", "Checked")
try {
val token = _db.getToken()
val user = _db.getUser()
AsyncTask.execute {
if (Looper.myLooper() == null)
if (Looper.myLooper() == null) {
Looper.prepare()
}
if (token.status == 1 && user.status == 1) {
val clientId = settings.getString("client_id", "")!!
@ -72,11 +73,9 @@ class SplashActivity : AppCompatActivity() {
ManagerSingleton.logout()
}
startApp()
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
Handler().postDelayed({
startApp()
@ -99,4 +98,4 @@ class SplashActivity : AppCompatActivity() {
this.finish()
}
}
}
}

View File

@ -1,14 +1,13 @@
package org.libre.agosto.p2play.adapters
import android.content.Context
import android.content.Intent
import androidx.recyclerview.widget.RecyclerView
import android.text.Html
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.view_video.view.userImg
import org.libre.agosto.p2play.*
@ -16,13 +15,13 @@ import org.libre.agosto.p2play.models.CommentaryModel
@Suppress("DEPRECATION")
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
// 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.
// 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 username: TextView
val commentary: TextView
@ -37,13 +36,14 @@ class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
}
}
// Create new views (invoked by the layout manager)
override fun onCreateViewHolder(parent: ViewGroup,
viewType: Int): CommentariesAdapter.ViewHolder {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int,
): CommentariesAdapter.ViewHolder {
// create a new view
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
return ViewHolder(view)
@ -56,13 +56,14 @@ class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
holder.username.text = myDataset[position].username
// holder.userImg.setOnClickListener {
// val intent = Intent(holder.context, ChannelActivity::class.java)
// intent.putExtra("channel", myDataset[position])
// holder.context.startActivity(intent)
// val intent = Intent(holder.context, ChannelActivity::class.java)
// intent.putExtra("channel", myDataset[position])
// holder.context.startActivity(intent)
// }
if(myDataset[position].userImageUrl!="")
Picasso.get().load("https://"+ManagerSingleton.url+myDataset[position].userImageUrl).into(holder.userImg);
if (myDataset[position].userImageUrl != "") {
Picasso.get().load("https://" + ManagerSingleton.url + myDataset[position].userImageUrl).into(holder.userImg)
}
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)
override fun getItemCount() = myDataset.size
}
}

View File

@ -2,12 +2,12 @@ package org.libre.agosto.p2play.adapters
import android.content.Context
import android.content.Intent
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.squareup.picasso.Picasso
import org.libre.agosto.p2play.*
import org.libre.agosto.p2play.helpers.mapSeconds
@ -15,14 +15,13 @@ import org.libre.agosto.p2play.models.VideoModel
import java.io.Serializable
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
// 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.
// 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 userImg: ImageView = view.findViewById(R.id.userImg)
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 {
// create a new view
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
return ViewHolder(view)
}
@ -49,7 +48,7 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
holder.title.setOnClickListener {
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 {
this.launchChannelActivity(myDataset[position] as Serializable, holder.context)
}
@ -60,18 +59,19 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
holder.context.startActivity(intent)
}
if(myDataset[position].userImageUrl!="")
Picasso.get().load("https://"+ManagerSingleton.url+myDataset[position].userImageUrl).into(holder.userImg)
else
if (myDataset[position].userImageUrl != "") {
Picasso.get().load("https://" + ManagerSingleton.url + myDataset[position].userImageUrl).into(holder.userImg)
} else {
Picasso.get().load(R.drawable.default_avatar).into(holder.userImg)
}
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)
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) {
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)
override fun getItemCount() = myDataset.size
fun clearData(){
fun clearData() {
myDataset.clear()
notifyDataSetChanged()
}
fun addData(newItems: ArrayList<VideoModel>){
fun addData(newItems: ArrayList<VideoModel>) {
val lastPos = myDataset.size
myDataset.addAll(newItems)
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)
intent.putExtra("video", data)
context.startActivity(intent)
}
}
}

View File

@ -3,11 +3,11 @@ package org.libre.agosto.p2play.ajax
import android.util.JsonReader
import java.io.InputStreamReader
class Actions: Client() {
class Actions : Client() {
fun subscribe(token: String, account: String):Int{
val con = this._newCon("users/me/subscriptions","POST", token)
val params:String= "uri=$account"
fun subscribe(token: String, account: String): Int {
val con = this._newCon("users/me/subscriptions", "POST", token)
val params: String = "uri=$account"
con.outputStream.write(params.toByteArray())
var response = 0
@ -15,8 +15,7 @@ class Actions: Client() {
if (con.responseCode == 204) {
response = 1
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
response = -1
}
@ -25,16 +24,15 @@ class Actions: Client() {
return response
}
fun unSubscribe(token: String, account: String):Int{
val con = this._newCon("users/me/subscriptions/$account","DELETE", token)
fun unSubscribe(token: String, account: String): Int {
val con = this._newCon("users/me/subscriptions/$account", "DELETE", token)
var response = 0
try {
if (con.responseCode == 204) {
response = 1
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
response = -1
}
@ -43,8 +41,8 @@ class Actions: Client() {
return response
}
fun getSubscription(token: String, account: String): Boolean{
val con = this._newCon("users/me/subscriptions/exist?uris=$account","GET", token)
fun getSubscription(token: String, account: String): Boolean {
val con = this._newCon("users/me/subscriptions/exist?uris=$account", "GET", token)
var isSubscribed = false
try {
@ -52,21 +50,20 @@ class Actions: Client() {
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while (data.hasNext()){
while (data.hasNext()) {
val key = data.nextName()
when (key.toString()) {
account->{
account -> {
isSubscribed = data.nextBoolean()
}
else->{
else -> {
data.skipValue()
}
}
}
data.close()
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
isSubscribed = false
}
@ -75,8 +72,8 @@ class Actions: Client() {
return isSubscribed
}
fun rate(token: String, id_video: Int, rate: String):Int{
val con = this._newCon("videos/$id_video/rate","PUT", token)
fun rate(token: String, id_video: Int, rate: String): Int {
val con = this._newCon("videos/$id_video/rate", "PUT", token)
val params = "rating=$rate"
con.outputStream.write(params.toByteArray())
var response = 0
@ -85,8 +82,7 @@ class Actions: Client() {
if (con.responseCode == 204) {
response = 1
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
response = -1
}
@ -95,8 +91,8 @@ class Actions: Client() {
return response
}
fun getRate(token: String, id_video: Int):String{
val con = this._newCon("users/me/videos/$id_video/rating","GET", token)
fun getRate(token: String, id_video: Int): String {
val con = this._newCon("users/me/videos/$id_video/rating", "GET", token)
var rating = "none"
try {
@ -104,21 +100,20 @@ class Actions: Client() {
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while (data.hasNext()){
while (data.hasNext()) {
val key = data.nextName()
when (key.toString()) {
"rating"->{
"rating" -> {
rating = data.nextString()
}
else->{
else -> {
data.skipValue()
}
}
}
con.disconnect()
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
rating = "none"
}
@ -134,7 +129,7 @@ class Actions: Client() {
var response = false
try {
if(con.responseCode == 200){
if (con.responseCode == 200) {
response = true
}
} catch (err: Exception) {
@ -152,7 +147,7 @@ class Actions: Client() {
var response = false
try {
if(con.responseCode == 204){
if (con.responseCode == 204) {
response = true
}
} catch (err: Exception) {
@ -162,4 +157,4 @@ class Actions: Client() {
return response
}
}
}

View File

@ -4,16 +4,15 @@ package org.libre.agosto.p2play.ajax
import android.util.JsonReader
import android.util.JsonToken
import android.util.Log
import org.libre.agosto.p2play.ManagerSingleton
import org.libre.agosto.p2play.models.TokenModel
import org.libre.agosto.p2play.models.UserModel
import java.io.InputStreamReader
class Auth: Client() {
class Auth : Client() {
private val stockParams = "grant_type=password"
fun login(username: String, password: String, client_id: String, client_secret: String, twoFactorCode: String? = null): TokenModel{
val con = this._newCon("users/token","POST")
fun login(username: String, password: String, client_id: String, client_secret: String, twoFactorCode: String? = null): TokenModel {
val con = this._newCon("users/token", "POST")
val params = "$stockParams&username=$username&password=$password&client_id=$client_id&client_secret=$client_secret"
if (twoFactorCode !== null) {
@ -24,16 +23,15 @@ class Auth: Client() {
val token = TokenModel()
try {
when (con.responseCode) {
200 -> {
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while(data.hasNext()){
while (data.hasNext()) {
val k = data.nextName()
when(k.toString()){
when (k.toString()) {
"access_token" -> token.token = data.nextString()
"refresh_token" -> token.refresh_token = data.nextString()
else -> data.skipValue()
@ -43,7 +41,6 @@ class Auth: Client() {
data.endObject()
data.close()
token.status = 1
}
401 -> {
// User require 2FA code
@ -53,8 +50,7 @@ class Auth: Client() {
Log.d("Status", con.responseMessage)
}
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
token.status = 0
}
@ -63,8 +59,8 @@ class Auth: Client() {
return token
}
fun register(username: String, password: String, email: String): Int{
val con = this._newCon("users/register","POST")
fun register(username: String, password: String, email: String): Int {
val con = this._newCon("users/register", "POST")
val params = "username=$username&password=$password&email=$email"
con.outputStream.write(params.toByteArray())
@ -74,32 +70,30 @@ class Auth: Client() {
if (con.responseCode == 204) {
response = 1
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
response = -1
}
con.disconnect()
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 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())
// val token = TokenModel()
try {
if(con.responseCode==200){
if (con.responseCode == 200) {
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while(data.hasNext()){
while (data.hasNext()) {
val k = data.nextName()
when(k.toString()){
when (k.toString()) {
"access_token" -> token.token = data.nextString()
"refresh_token" -> token.refresh_token = data.nextString()
else -> data.skipValue()
@ -109,13 +103,10 @@ class Auth: Client() {
data.endObject()
data.close()
token.status = 1
}
else{
} else {
Log.d("Status", con.responseMessage)
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
token.status = 0
}
@ -124,32 +115,31 @@ class Auth: Client() {
return token
}
fun me(token: String): UserModel{
val con = this._newCon("users/me","GET", token)
fun me(token: String): UserModel {
val con = this._newCon("users/me", "GET", token)
val user = UserModel()
try {
if(con.responseCode==200){
if (con.responseCode == 200) {
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while(data.hasNext()){
while (data.hasNext()) {
val k = data.nextName()
when(k.toString()){
when (k.toString()) {
"id" -> user.uuid = data.nextInt()
"username" -> user.username = data.nextString()
"email" -> user.email = data.nextString()
"displayNSFW" -> user.nsfw = data.nextBoolean()
"account" -> {
data.beginObject()
while (data.hasNext()){
while (data.hasNext()) {
val l = data.nextName()
when(l.toString()){
when (l.toString()) {
"followersCount" -> user.followers = data.nextInt()
"avatar" -> {
if(data.peek() == JsonToken.BEGIN_OBJECT) {
if (data.peek() == JsonToken.BEGIN_OBJECT) {
data.beginObject()
while (data.hasNext()) {
val m = data.nextName()
@ -159,8 +149,7 @@ class Auth: Client() {
}
}
data.endObject()
}
else{
} else {
data.skipValue()
}
}
@ -176,13 +165,10 @@ class Auth: Client() {
data.endObject()
data.close()
user.status = 1
}
else{
} else {
Log.d("Status", con.responseMessage)
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
user.status = 0
}
@ -190,5 +176,4 @@ class Auth: Client() {
con.disconnect()
return user
}
}
}

View File

@ -1,14 +1,12 @@
package org.libre.agosto.p2play.ajax
import android.util.JsonReader
import android.util.JsonToken
import org.libre.agosto.p2play.models.ChannelModel
import org.libre.agosto.p2play.models.CommentaryModel
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()
data.close()
@ -20,16 +18,16 @@ class Channels: Client() {
val con = this._newCon("video-channels/$account", "GET")
var channel = ChannelModel()
try {
if(con.responseCode == 200){
if (con.responseCode == 200) {
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
channel.parseChannel(data)
data.close()
}
}catch (err: Exception) {
} catch (err: Exception) {
err.printStackTrace()
}
return channel
}
}
}

View File

@ -5,7 +5,6 @@ import android.util.Log
import org.libre.agosto.p2play.ManagerSingleton
import org.libre.agosto.p2play.models.HostModel
import java.io.InputStreamReader
import java.io.Reader
import java.net.HttpURLConnection
import java.net.URL
@ -18,24 +17,25 @@ open class Client {
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
con.setRequestProperty("Accept", "*/*")
if(token != ""){
if (token != "") {
con.setRequestProperty("Authorization", "Bearer $token")
}
con.requestMethod=method
con.connectTimeout=60000
con.readTimeout=60000
con.requestMethod = method
con.connectTimeout = 60000
con.readTimeout = 60000
if(method == "POST")
con.doOutput=true
if (method == "POST") {
con.doOutput = true
}
Log.d("Petition", url.toString())
return con
}
fun getKeys():HostModel{
val con = this._newCon("oauth-clients/local","GET")
val keys = HostModel("","")
fun getKeys(): HostModel {
val con = this._newCon("oauth-clients/local", "GET")
val keys = HostModel("", "")
try {
if (con.responseCode == 200) {
val response = InputStreamReader(con.inputStream)
@ -44,25 +44,24 @@ open class Client {
while (data.hasNext()) {
val key = data.nextName()
when (key.toString()) {
"client_id"->{
"client_id" -> {
keys.client_id = data.nextString()
}
"client_secret"->{
"client_secret" -> {
keys.client_secret = data.nextString()
}
else->{
else -> {
data.skipValue()
}
}
}
data.close()
}
} catch(err:Exception){
} catch (err: Exception) {
err.printStackTrace()
}
con.disconnect()
return keys
}
}
}

View File

@ -1,18 +1,17 @@
package org.libre.agosto.p2play.ajax
import android.util.JsonReader
import android.util.JsonToken
import android.util.Log
import org.libre.agosto.p2play.models.CommentaryModel
import java.io.InputStreamReader
class Comments: Client() {
class Comments : Client() {
private fun parseCommentaries(data: JsonReader): ArrayList<CommentaryModel> {
val commentaries = arrayListOf<CommentaryModel>()
data.beginObject()
while (data.hasNext()){
when(data.nextName()) {
while (data.hasNext()) {
when (data.nextName()) {
"data" -> {
data.beginArray()
while (data.hasNext()) {
@ -41,7 +40,7 @@ class Comments: Client() {
commentaries = parseCommentaries(data)
data.close()
}
} catch(err:Exception){
} catch (err: Exception) {
err.printStackTrace()
}
con.disconnect()
@ -59,13 +58,11 @@ class Comments: Client() {
if (con.responseCode == 200) {
con.disconnect()
response = true
}
else{
} else {
Log.d("Status", con.responseMessage)
response = false
}
}
catch (err: Exception){
} catch (err: Exception) {
err.printStackTrace()
response = false
}
@ -73,5 +70,4 @@ class Comments: Client() {
con.disconnect()
return response
}
}
}

View File

@ -5,14 +5,14 @@ import org.libre.agosto.p2play.ManagerSingleton
import org.libre.agosto.p2play.models.VideoModel
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>()
data.beginObject()
while (data.hasNext()){
when(data.nextName()){
"data"->{
while (data.hasNext()) {
when (data.nextName()) {
"data" -> {
data.beginArray()
while (data.hasNext()) {
val video = VideoModel()
@ -21,7 +21,7 @@ class Videos: Client() {
}
data.endArray()
}
else-> data.skipValue()
else -> data.skipValue()
}
}
data.endObject()
@ -29,12 +29,12 @@ class Videos: Client() {
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 count = ManagerSingleton.videos_count
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>()
try {
if (con.responseCode == 200) {
@ -43,33 +43,33 @@ class Videos: Client() {
videos = parseVideos(data)
data.close()
}
} catch(err:Exception){
} catch (err: Exception) {
err.printStackTrace()
}
con.disconnect()
return videos
}
fun getLastVideos(start:Int = 0): ArrayList<VideoModel>{
fun getLastVideos(start: Int = 0): ArrayList<VideoModel> {
return this.getVideos(start)
}
fun getPopularVideos(start:Int = 0): ArrayList<VideoModel>{
return this.getVideos(start,"-views")
fun getPopularVideos(start: Int = 0): ArrayList<VideoModel> {
return this.getVideos(start, "-views")
}
fun getTrendingVideos(start:Int = 0): ArrayList<VideoModel>{
return this.getVideos(start,"-trending")
fun getTrendingVideos(start: Int = 0): ArrayList<VideoModel> {
return this.getVideos(start, "-trending")
}
fun getLocalVideos(start:Int = 0): ArrayList<VideoModel>{
return this.getVideos(start,"-publishedAt", true)
fun getLocalVideos(start: Int = 0): ArrayList<VideoModel> {
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 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>()
try {
if (con.responseCode == 200) {
@ -78,7 +78,7 @@ class Videos: Client() {
videos = parseVideos(data)
data.close()
}
} catch(err:Exception){
} catch (err: Exception) {
err.printStackTrace()
}
@ -86,10 +86,10 @@ class Videos: Client() {
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 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>()
try {
if (con.responseCode == 200) {
@ -102,7 +102,7 @@ class Videos: Client() {
val data = JsonReader(response)
print(data)
}
} catch(err:Exception){
} catch (err: Exception) {
err.printStackTrace()
}
@ -110,10 +110,10 @@ class Videos: Client() {
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 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>()
try {
if (con.responseCode == 200) {
@ -122,7 +122,7 @@ class Videos: Client() {
videos = parseVideos(data)
data.close()
}
} catch(err:Exception){
} catch (err: Exception) {
err.printStackTrace()
}
@ -130,11 +130,11 @@ class Videos: Client() {
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 nsfw = ManagerSingleton.nfsw
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>()
try {
if (con.responseCode == 200) {
@ -143,15 +143,15 @@ class Videos: Client() {
videos = parseVideos(data)
data.close()
}
} catch(err:Exception){
} catch (err: Exception) {
err.printStackTrace()
}
con.disconnect()
return videos
}
fun fullDescription(videoId: Int): String{
val con = this._newCon("videos/$videoId/description","GET")
fun fullDescription(videoId: Int): String {
val con = this._newCon("videos/$videoId/description", "GET")
var description = ""
try {
if (con.responseCode == 200) {
@ -159,9 +159,9 @@ class Videos: Client() {
val data = JsonReader(response)
data.beginObject()
while (data.hasNext()){
while (data.hasNext()) {
val name = data.nextName()
when(name){
when (name) {
"description" -> description = data.nextString()
else -> data.skipValue()
}
@ -169,7 +169,7 @@ class Videos: Client() {
data.endObject()
data.close()
}
} catch(err:Exception){
} catch (err: Exception) {
err.printStackTrace()
description = "Error!"
}
@ -180,7 +180,7 @@ class Videos: Client() {
fun channelVideos(account: String, start: Int): ArrayList<VideoModel> {
val count = ManagerSingleton.videos_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>()
try {
if (con.responseCode == 200) {
@ -189,7 +189,7 @@ class Videos: Client() {
videos = parseVideos(data)
data.close()
}
} catch(err:Exception){
} catch (err: Exception) {
err.printStackTrace()
}
@ -197,12 +197,12 @@ class Videos: Client() {
return videos
}
fun getMostLikedVideos(start:Int = 0): ArrayList<VideoModel>{
return this.getVideos(start,"-likes")
fun getMostLikedVideos(start: Int = 0): ArrayList<VideoModel> {
return this.getVideos(start, "-likes")
}
fun getVideo(uuid: String): VideoModel {
val con = this._newCon("videos/$uuid","GET")
val con = this._newCon("videos/$uuid", "GET")
val video = VideoModel()
try {
if (con.responseCode == 200) {
@ -211,11 +211,11 @@ class Videos: Client() {
video.parseVideo(data)
data.close()
}
} catch(err:Exception){
} catch (err: Exception) {
err.printStackTrace()
}
con.disconnect()
return video
}
}
}

View File

@ -1,6 +1,6 @@
package org.libre.agosto.p2play.helpers
fun mapSeconds (inputSeconds: Int): String {
fun mapSeconds(inputSeconds: Int): String {
val seconds = (inputSeconds % 60)
var minutes = inputSeconds / 60
var hours = 0
@ -17,4 +17,4 @@ fun mapSeconds (inputSeconds: Int): String {
}
return result
}
}

View File

@ -4,10 +4,10 @@ import android.view.View
import android.view.Window
import android.view.WindowManager
fun setFullscreen (window: Window) {
fun setFullscreen(window: Window) {
val attrs = window.attributes
attrs.flags = attrs.flags or WindowManager.LayoutParams.FLAG_FULLSCREEN
attrs.flags = attrs.flags or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
window.attributes = attrs
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
}
}

View File

@ -3,16 +3,16 @@ package org.libre.agosto.p2play.models
import android.util.JsonReader
import android.util.JsonToken
class ChannelModel (
var id: Int = 0,
var url: String = "",
var nameChannel: String = "",
var followers: Int = 0,
var host: String = "",
var name: String = "",
var description: String = "",
var support: String = "",
var channelImg: String = ""
class ChannelModel(
var id: Int = 0,
var url: String = "",
var nameChannel: String = "",
var followers: Int = 0,
var host: String = "",
var name: String = "",
var description: String = "",
var support: String = "",
var channelImg: String = "",
) {
fun getAccount(): String {
return "$nameChannel@$host"
@ -22,8 +22,7 @@ class ChannelModel (
data.beginObject()
while (data.hasNext()) {
when(data.nextName()){
when (data.nextName()) {
"id" -> this.id = data.nextInt()
"url" -> this.url = data.nextString()
"name" -> this.nameChannel = data.nextString()
@ -31,34 +30,36 @@ class ChannelModel (
"followersCount" -> this.followers = data.nextInt()
"displayName" -> this.name = data.nextString()
"description" -> {
if(data.peek() == JsonToken.STRING)
if (data.peek() == JsonToken.STRING) {
this.description = data.nextString()
else
} else {
data.skipValue()
}
}
"support" -> {
if(data.peek() == JsonToken.STRING)
if (data.peek() == JsonToken.STRING) {
this.support = data.nextString()
else
} else {
data.skipValue()
}
}
"avatar" -> {
if(data.peek() == JsonToken.BEGIN_OBJECT){
if (data.peek() == JsonToken.BEGIN_OBJECT) {
data.beginObject()
while (data.hasNext()){
when(data.nextName()){
while (data.hasNext()) {
when (data.nextName()) {
"path" -> this.channelImg = data.nextString()
else -> data.skipValue()
}
}
data.endObject()
}
else
} else {
data.skipValue()
}
}
else -> data.skipValue()
}
}
data.endObject()
}
}
}

View File

@ -3,16 +3,16 @@ package org.libre.agosto.p2play.models
import android.util.JsonReader
import android.util.JsonToken
class CommentaryModel (
var id: Int = 0,
var threadId: Int = 0,
var userUuid: String = "",
var username: String = "",
var userImageUrl: String = "",
var commentary: String = "",
var userHost: String = "",
var replies: Int = 0,
var nameChannel: String = ""
class CommentaryModel(
var id: Int = 0,
var threadId: Int = 0,
var userUuid: String = "",
var username: String = "",
var userImageUrl: String = "",
var commentary: String = "",
var userHost: String = "",
var replies: Int = 0,
var nameChannel: String = "",
) {
fun parseCommentary(data: JsonReader) {
data.beginObject()
@ -25,25 +25,24 @@ class CommentaryModel (
"totalReplies" -> this.replies = data.nextInt()
"account" -> {
data.beginObject()
while (data.hasNext()){
while (data.hasNext()) {
val acKey = data.nextName()
when(acKey.toString()){
"displayName"-> this.username=data.nextString()
"avatar"-> {
if(data.peek() == JsonToken.BEGIN_OBJECT){
when (acKey.toString()) {
"displayName" -> this.username = data.nextString()
"avatar" -> {
if (data.peek() == JsonToken.BEGIN_OBJECT) {
data.beginObject()
while (data.hasNext()){
while (data.hasNext()) {
val avKey = data.nextName()
when(avKey){
"path"-> this.userImageUrl = data.nextString()
else-> data.skipValue()
when (avKey) {
"path" -> this.userImageUrl = data.nextString()
else -> data.skipValue()
}
}
data.endObject()
}
else
} else {
data.skipValue()
}
}
"uuid" -> this.userUuid = data.nextString()
"host" -> this.userHost = data.nextString()
@ -60,7 +59,6 @@ class CommentaryModel (
}
fun getAccount(): String {
return "$nameChannel@$userHost"
return "$nameChannel@$userHost"
}
}
}

View File

@ -1,3 +1,3 @@
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)

View File

@ -12,10 +12,10 @@ class StreamingModel(
while (data.hasNext()) {
val key = data.nextName()
when (key.toString()) {
"playlistUrl"->{
"playlistUrl" -> {
this.playlistUrl = data.nextString()
}
"segmentsSha256Url"->{
"segmentsSha256Url" -> {
this.segmentsSha256Url = data.nextString()
}
else -> data.skipValue()
@ -23,4 +23,4 @@ class StreamingModel(
}
data.endObject()
}
}
}

View File

@ -1,7 +1,7 @@
package org.libre.agosto.p2play.models
class TokenModel (
var token: String = "",
var refresh_token: String = "",
var status: Int = -1
)
class TokenModel(
var token: String = "",
var refresh_token: String = "",
var status: Int = -1,
)

View File

@ -1,12 +1,12 @@
package org.libre.agosto.p2play.models
class UserModel (
var id: Int = 0,
var uuid: Int = 0,
var username: String = "",
var email: String = "",
var nsfw: Boolean = true,
var followers: Int = 0,
var avatar: String = "",
var status: Int = -1
)
class UserModel(
var id: Int = 0,
var uuid: Int = 0,
var username: String = "",
var email: String = "",
var nsfw: Boolean = true,
var followers: Int = 0,
var avatar: String = "",
var status: Int = -1,
)

View File

@ -19,8 +19,8 @@ class VideoModel(
var userHost: String = "",
var nameChannel: String = "",
var isLive: Boolean = false,
var streamingData: StreamingModel? = null
):Serializable {
var streamingData: StreamingModel? = null,
) : Serializable {
fun getChannel(): String {
return "$nameChannel@$userHost"
}
@ -29,38 +29,39 @@ class VideoModel(
return "https://$userHost/videos/watch/$uuid"
}
fun parseVideo(data: JsonReader){
fun parseVideo(data: JsonReader) {
data.beginObject()
while (data.hasNext()){
while (data.hasNext()) {
val key = data.nextName()
when (key.toString()) {
"id"-> this.id = data.nextInt()
"id" -> this.id = data.nextInt()
"uuid" -> this.uuid = data.nextString()
"name"->{
this.name= data.nextString()
"name" -> {
this.name = data.nextString()
}
"description"->{
if(data.peek() == JsonToken.STRING)
"description" -> {
if (data.peek() == JsonToken.STRING) {
this.description = data.nextString()
else
} else {
data.skipValue()
}
}
"duration"->{
"duration" -> {
this.duration = data.nextInt()
}
"thumbnailPath"->{
"thumbnailPath" -> {
this.thumbUrl = data.nextString()
}
"embedPath"->{
"embedPath" -> {
this.embedUrl = data.nextString()
}
"views"->{
"views" -> {
this.views = data.nextInt()
}
"isLive"-> {
"isLive" -> {
this.isLive = data.nextBoolean()
}
"streamingPlaylists"-> {
"streamingPlaylists" -> {
data.beginArray()
if (data.hasNext()) {
val streamingData = StreamingModel()
@ -77,7 +78,7 @@ class VideoModel(
while (data.hasNext()) {
val key2 = data.nextName()
when (key2.toString()) {
"fileDownloadUrl"->{
"fileDownloadUrl" -> {
streamingData = StreamingModel()
streamingData!!.playlistUrl = data.nextString()
}
@ -89,41 +90,40 @@ class VideoModel(
data.endArray()
}
}
"channel"->{
"channel" -> {
data.beginObject()
while (data.hasNext()){
while (data.hasNext()) {
val acKey = data.nextName()
when(acKey.toString()){
"displayName"-> this.username=data.nextString()
"avatar"-> {
if(data.peek() == JsonToken.BEGIN_OBJECT){
when (acKey.toString()) {
"displayName" -> this.username = data.nextString()
"avatar" -> {
if (data.peek() == JsonToken.BEGIN_OBJECT) {
data.beginObject()
while (data.hasNext()){
while (data.hasNext()) {
val avKey = data.nextName()
when(avKey){
"path"-> this.userImageUrl = data.nextString()
else-> data.skipValue()
when (avKey) {
"path" -> this.userImageUrl = data.nextString()
else -> data.skipValue()
}
}
data.endObject()
}
else
} else {
data.skipValue()
}
}
"uuid" -> this.userUuid = data.nextString()
"host" -> this.userHost = data.nextString()
"name" -> this.nameChannel = data.nextString()
else-> data.skipValue()
else -> data.skipValue()
}
}
data.endObject()
}
else->{
else -> {
data.skipValue()
}
}
}
data.endObject()
}
}
}

View File

@ -1,8 +1,7 @@
package org.libre.agosto.p2play
import org.junit.Test
import org.junit.Assert.*
import org.junit.Test
/**
* Example local unit test, which will execute on the development machine (host).

View File

@ -12,6 +12,7 @@ android.useAndroidX=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
org.gradle.configuration-cache=true
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit