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 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.*

View File

@ -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

View File

@ -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
@ -60,11 +60,12 @@ 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)
} }
} }
} }
}
private fun subscribe() { private fun subscribe() {
AsyncTask.execute { AsyncTask.execute {
@ -74,8 +75,7 @@ class ChannelActivity : AppCompatActivity() {
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)
} }
} }
@ -90,8 +90,7 @@ class ChannelActivity : AppCompatActivity() {
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,11 +98,12 @@ 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 {
@ -111,8 +111,7 @@ class ChannelActivity : AppCompatActivity() {
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)
} }
} }

View File

@ -72,7 +72,6 @@ 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) {
@ -103,7 +102,6 @@ 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) {
@ -126,5 +124,4 @@ class Database(context:Context): SQLiteOpenHelper(context,"p2play",null,1) {
closeUsers() closeUsers()
closeTokens() closeTokens()
} }
} }

View File

@ -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
@ -58,8 +58,9 @@ class HostActivity : AppCompatActivity() {
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 != "") {
@ -67,8 +68,7 @@ class HostActivity : AppCompatActivity() {
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

View File

@ -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
@ -35,13 +35,14 @@ class LoginActivity : AppCompatActivity() {
} }
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)
@ -90,7 +91,6 @@ class LoginActivity : AppCompatActivity() {
} }
} }
} }
} }
} }
@ -103,8 +103,7 @@ class LoginActivity : AppCompatActivity() {
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)
} }

View File

@ -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)
@ -134,13 +130,14 @@ 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) {
@ -253,13 +250,11 @@ 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()
} }
} }
@ -285,10 +280,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
} }
return true return true
} }
}) })
myMenu = menu myMenu = menu
setSideData() setSideData()
return true return true
@ -374,7 +367,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
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
@ -411,11 +403,12 @@ 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()
} }
} }
@ -431,5 +424,4 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
} }
} }
} }
} }

View File

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

View File

@ -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
@ -34,8 +34,9 @@ class RegisterActivity : AppCompatActivity() {
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())

View File

@ -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
@ -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)
@ -350,8 +353,7 @@ class ReproductorActivity : AppCompatActivity() {
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)
} }
} }
@ -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
@ -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()
} }
} }

View File

@ -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(
preference,
PreferenceManager PreferenceManager
.getDefaultSharedPreferences(preference.context) .getDefaultSharedPreferences(preference.context)
.getString(preference.key, "")) .getString(preference.key, ""),
)
} }
} }
} }

View File

@ -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
@ -51,8 +51,9 @@ class SplashActivity : AppCompatActivity() {
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()

View File

@ -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.*
@ -37,10 +36,11 @@ 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
@ -61,8 +61,9 @@ class CommentariesAdapter(private val myDataset: ArrayList<CommentaryModel>) :
// 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)

View File

@ -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
@ -17,7 +17,6 @@ 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.
@ -60,13 +59,14 @@ 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

View File

@ -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
} }
@ -33,8 +32,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
} }
@ -65,8 +63,7 @@ class Actions: Client() {
} }
data.close() data.close()
} }
} } catch (err: Exception) {
catch (err: Exception){
err.printStackTrace() err.printStackTrace()
isSubscribed = false isSubscribed = false
} }
@ -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
} }
@ -117,8 +113,7 @@ class Actions: Client() {
} }
con.disconnect() con.disconnect()
} }
} } catch (err: Exception) {
catch (err: Exception){
err.printStackTrace() err.printStackTrace()
rating = "none" rating = "none"
} }

View File

@ -4,7 +4,6 @@ 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
@ -24,7 +23,6 @@ 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)
@ -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
} }
@ -74,15 +70,13 @@ 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 {
@ -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
} }
@ -129,7 +120,6 @@ class Auth: Client() {
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)
@ -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
} }
} }

View File

@ -1,9 +1,7 @@
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() {

View File

@ -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
@ -26,8 +25,9 @@ open class Client {
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
@ -64,5 +64,4 @@ open class Client {
con.disconnect() con.disconnect()
return keys return keys
} }
} }

View File

@ -1,7 +1,6 @@
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
@ -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
} }
} }

View File

@ -12,7 +12,7 @@ class ChannelModel (
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,7 +22,6 @@ 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()
@ -31,17 +30,19 @@ 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()
@ -52,10 +53,10 @@ class ChannelModel (
} }
} }
data.endObject() data.endObject()
} } else {
else
data.skipValue() data.skipValue()
} }
}
else -> data.skipValue() else -> data.skipValue()
} }
} }

View File

@ -12,7 +12,7 @@ class CommentaryModel (
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()
@ -40,10 +40,9 @@ class CommentaryModel (
} }
} }
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()
@ -62,5 +61,4 @@ class CommentaryModel (
fun getAccount(): String { fun getAccount(): String {
return "$nameChannel@$userHost" return "$nameChannel@$userHost"
} }
} }

View File

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

View File

@ -8,5 +8,5 @@ class UserModel (
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,
) )

View File

@ -19,7 +19,7 @@ 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"
@ -40,11 +40,12 @@ class VideoModel(
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()
} }
@ -106,10 +107,9 @@ class VideoModel(
} }
} }
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()

View File

@ -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).

View File

@ -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