fix all lint errors

This commit is contained in:
Ivan Agosto
2024-04-06 18:03:23 -06:00
parent b6e1a979ca
commit 48738f100a
20 changed files with 112 additions and 111 deletions

View File

@@ -14,14 +14,13 @@ import org.libre.agosto.p2play.ajax.Channels
import org.libre.agosto.p2play.ajax.Videos import org.libre.agosto.p2play.ajax.Videos
import org.libre.agosto.p2play.models.ChannelModel import org.libre.agosto.p2play.models.ChannelModel
import org.libre.agosto.p2play.models.VideoModel import org.libre.agosto.p2play.models.VideoModel
class ChannelActivity : AppCompatActivity() { class ChannelActivity : AppCompatActivity() {
private lateinit var channelId: String private lateinit var channelId: String
private lateinit var channel: ChannelModel private lateinit var channel: ChannelModel
private var isSubcribed: Boolean = false private var isSubcribed: Boolean = false
private val _channel = Channels() private val channelService = Channels()
private val _videos = Videos() private val videosService = Videos()
private val _actions = Actions() private val actionsService = Actions()
private lateinit var recyclerView: RecyclerView private lateinit var recyclerView: RecyclerView
private lateinit var viewAdapter: RecyclerView.Adapter<VideosAdapter.ViewHolder> private lateinit var viewAdapter: RecyclerView.Adapter<VideosAdapter.ViewHolder>
@@ -55,7 +54,7 @@ class ChannelActivity : AppCompatActivity() {
private fun getChannel() { private fun getChannel() {
AsyncTask.execute { AsyncTask.execute {
channel = _channel.getChannelInfo(channelId) channel = channelService.getChannelInfo(channelId)
runOnUiThread { runOnUiThread {
usernameProfile.text = channel.name usernameProfile.text = channel.name
hostTxt.text = channel.host hostTxt.text = channel.host
@@ -69,14 +68,14 @@ class ChannelActivity : AppCompatActivity() {
private fun subscribe() { private fun subscribe() {
AsyncTask.execute { AsyncTask.execute {
val res = _actions.subscribe(ManagerSingleton.token.token, channel.getAccount()) val res = actionsService.subscribe(ManagerSingleton.token.token, channel.getAccount())
runOnUiThread { runOnUiThread {
if (res == 1) { if (res == 1) {
subcriptionBtn.text = getString(R.string.unSubscribeBtn) subcriptionBtn.text = getString(R.string.unSubscribeBtn)
ManagerSingleton.Toast(getString(R.string.subscribeMsg), this) ManagerSingleton.toast(getString(R.string.subscribeMsg), this)
getSubscription() getSubscription()
} else { } else {
ManagerSingleton.Toast(getString(R.string.errorMsg), this) ManagerSingleton.toast(getString(R.string.errorMsg), this)
} }
} }
} }
@@ -84,14 +83,14 @@ class ChannelActivity : AppCompatActivity() {
private fun unSubscribe() { private fun unSubscribe() {
AsyncTask.execute { AsyncTask.execute {
val res = _actions.unSubscribe(ManagerSingleton.token.token, channel.getAccount()) val res = actionsService.unSubscribe(ManagerSingleton.token.token, channel.getAccount())
runOnUiThread { runOnUiThread {
if (res == 1) { if (res == 1) {
subcriptionBtn.text = getString(R.string.subscribeBtn) subcriptionBtn.text = getString(R.string.subscribeBtn)
ManagerSingleton.Toast(getString(R.string.unSubscribeMsg), this) ManagerSingleton.toast(getString(R.string.unSubscribeMsg), this)
getSubscription() getSubscription()
} else { } else {
ManagerSingleton.Toast(getString(R.string.errorMsg), this) ManagerSingleton.toast(getString(R.string.errorMsg), this)
} }
} }
} }
@@ -107,7 +106,7 @@ class ChannelActivity : AppCompatActivity() {
private fun getSubscription() { private fun getSubscription() {
AsyncTask.execute { AsyncTask.execute {
isSubcribed = _actions.getSubscription(ManagerSingleton.token.token, channel.getAccount()) isSubcribed = actionsService.getSubscription(ManagerSingleton.token.token, channel.getAccount())
runOnUiThread { runOnUiThread {
if (isSubcribed) { if (isSubcribed) {
subcriptionBtn.text = getText(R.string.unSubscribeBtn) subcriptionBtn.text = getText(R.string.unSubscribeBtn)
@@ -120,7 +119,7 @@ class ChannelActivity : AppCompatActivity() {
private fun getVideos() { private fun getVideos() {
AsyncTask.execute { AsyncTask.execute {
val videos = _videos.channelVideos(channel.getAccount(), 0) val videos = videosService.channelVideos(channel.getAccount(), 0)
runOnUiThread { runOnUiThread {
initRecycler(videos) initRecycler(videos)
} }

View File

@@ -14,7 +14,7 @@ class HostActivity : AppCompatActivity() {
lateinit var settings: SharedPreferences lateinit var settings: SharedPreferences
lateinit var editor: SharedPreferences.Editor lateinit var editor: SharedPreferences.Editor
val client: Auth = Auth() val client: Auth = Auth()
val _db = Database(this) private val db = Database(this)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -31,7 +31,7 @@ class HostActivity : AppCompatActivity() {
val lastHost = settings.getString("last_host", "") val lastHost = settings.getString("last_host", "")
if (host != "") { if (host != "") {
if (lastHost != host) { if (lastHost != host) {
_db.logout() db.logout()
ManagerSingleton.logout() ManagerSingleton.logout()
getKeys(host!!) getKeys(host!!)
} else { } else {
@@ -45,7 +45,7 @@ class HostActivity : AppCompatActivity() {
editor.putString("last_host", host) editor.putString("last_host", host)
editor.putString("hostP2play", host) editor.putString("hostP2play", host)
editor.apply() editor.apply()
ManagerSingleton.Toast(getString(R.string.finallyMsg), this) ManagerSingleton.toast(getString(R.string.finallyMsg), this)
ManagerSingleton.url = host ManagerSingleton.url = host
startApp() startApp()
} }
@@ -70,7 +70,7 @@ class HostActivity : AppCompatActivity() {
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

@@ -13,22 +13,22 @@ import kotlinx.android.synthetic.main.activity_login.*
import org.libre.agosto.p2play.ajax.Auth import org.libre.agosto.p2play.ajax.Auth
class LoginActivity : AppCompatActivity() { class LoginActivity : AppCompatActivity() {
private val _auth = Auth() private val auth = Auth()
lateinit var settings: SharedPreferences lateinit var settings: SharedPreferences
lateinit var client_id: String lateinit var clientId: String
lateinit var client_secret: String lateinit var clientSecret: String
private lateinit var _db: Database private lateinit var db: Database
private var optCode: String? = null private var optCode: String? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login) setContentView(R.layout.activity_login)
setTitle(R.string.action_login) setTitle(R.string.action_login)
_db = Database(this) db = Database(this)
settings = PreferenceManager.getDefaultSharedPreferences(this) settings = PreferenceManager.getDefaultSharedPreferences(this)
client_id = settings.getString("client_id", "")!! clientId = settings.getString("client_id", "")!!
client_secret = settings.getString("client_secret", "")!! clientSecret = settings.getString("client_secret", "")!!
registerActionBtn.setOnClickListener { startActivity(Intent(this, RegisterActivity::class.java)) } registerActionBtn.setOnClickListener { startActivity(Intent(this, RegisterActivity::class.java)) }
loginBtn.setOnClickListener { tryLogin() } loginBtn.setOnClickListener { tryLogin() }
@@ -44,26 +44,26 @@ class LoginActivity : AppCompatActivity() {
Looper.prepare() Looper.prepare()
} }
val token = _auth.login(username, password, client_id, client_secret, optCode) val token = auth.login(username, password, clientId, clientSecret, optCode)
// Log.d("token", token.token ) // Log.d("token", token.token )
// Log.d("status", token.status.toString() ) // Log.d("status", token.status.toString() )
when (token.status.toString()) { when (token.status.toString()) {
"1" -> { "1" -> {
_db.newToken(token) db.newToken(token)
ManagerSingleton.token = token ManagerSingleton.token = token
getUser() getUser()
} }
"0" -> { "0" -> {
runOnUiThread { runOnUiThread {
ManagerSingleton.Toast(getString(R.string.loginError_msg), this) ManagerSingleton.toast(getString(R.string.loginError_msg), this)
} }
} }
"-1" -> { "-1" -> {
runOnUiThread { runOnUiThread {
loginBtn.isEnabled = true loginBtn.isEnabled = true
ManagerSingleton.Toast(getString(R.string.loginFailed_msg), this) ManagerSingleton.toast(getString(R.string.loginFailed_msg), this)
} }
} }
"-2" -> { "-2" -> {
@@ -95,17 +95,17 @@ class LoginActivity : AppCompatActivity() {
} }
fun getUser() { fun getUser() {
val user = _auth.me(ManagerSingleton.token.token) val user = auth.me(ManagerSingleton.token.token)
if (user.status == 1) { if (user.status == 1) {
_db.newUser(user) db.newUser(user)
ManagerSingleton.user = user ManagerSingleton.user = user
runOnUiThread { runOnUiThread {
ManagerSingleton.Toast(getString(R.string.loginSuccess_msg), this) ManagerSingleton.toast(getString(R.string.loginSuccess_msg), this)
finish() finish()
} }
} else { } else {
runOnUiThread { runOnUiThread {
ManagerSingleton.Toast(getString(R.string.loginError_msg), this) ManagerSingleton.toast(getString(R.string.loginError_msg), this)
} }
} }
} }

View File

@@ -29,9 +29,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
private lateinit var viewManager: RecyclerView.LayoutManager private lateinit var viewManager: RecyclerView.LayoutManager
private val client: Videos = Videos() private val client: Videos = Videos()
private lateinit var lastItem: MenuItem private lateinit var lastItem: MenuItem
private lateinit var subItem: MenuItem
lateinit var myMenu: Menu lateinit var myMenu: Menu
private val _db = Database(this) private val db = Database(this)
var section: String = "" var section: String = ""
var searchVal: String = "" var searchVal: String = ""
var pagination = 0 var pagination = 0
@@ -113,7 +112,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
(viewAdapter as VideosAdapter).addData(videos) (viewAdapter as VideosAdapter).addData(videos)
} catch (err: Exception) { } catch (err: Exception) {
err.printStackTrace() err.printStackTrace()
ManagerSingleton.Toast(getString(R.string.errorMsg), this) ManagerSingleton.toast(getString(R.string.errorMsg), this)
} }
this.swipeContainer.isRefreshing = false this.swipeContainer.isRefreshing = false
@@ -141,7 +140,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
private fun getSubscriptionVideos() { private fun getSubscriptionVideos() {
if (ManagerSingleton.user.status != 1) { if (ManagerSingleton.user.status != 1) {
ManagerSingleton.Toast("Inicia session primero", this) ManagerSingleton.toast("Inicia session primero", this)
startActivity(Intent(this, LoginActivity::class.java)) startActivity(Intent(this, LoginActivity::class.java))
return return
} }
@@ -383,17 +382,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
side_emailTxt?.text = getString(R.string.nav_header_subtitle) + " " + this.packageManager.getPackageInfo(this.packageName, 0).versionName side_emailTxt?.text = getString(R.string.nav_header_subtitle) + " " + this.packageManager.getPackageInfo(this.packageName, 0).versionName
side_imageView?.setImageResource(R.drawable.default_avatar) side_imageView?.setImageResource(R.drawable.default_avatar)
side_imageView?.setOnClickListener { } side_imageView?.setOnClickListener { }
_db.logout() db.logout()
ManagerSingleton.logout() ManagerSingleton.logout()
this.refresh() this.refresh()
ManagerSingleton.Toast(getString(R.string.logout_msg), this) ManagerSingleton.toast(getString(R.string.logout_msg), this)
setSideData() setSideData()
} }
private fun loadMore() { private fun loadMore() {
swipeContainer.isRefreshing = true swipeContainer.isRefreshing = true
this.pagination += ManagerSingleton.videos_count this.pagination += ManagerSingleton.videosCount
when (section) { when (section) {
"local" -> this.getLocalVideos() "local" -> this.getLocalVideos()

View File

@@ -10,10 +10,10 @@ object ManagerSingleton {
var user: UserModel = UserModel() var user: UserModel = UserModel()
var token: TokenModel = TokenModel() var token: TokenModel = TokenModel()
var nfsw: Boolean = false var nfsw: Boolean = false
var videos_count: Int = 0 var videosCount: Int = 0
lateinit var settings: SharedPreferences lateinit var settings: SharedPreferences
lateinit var db: Database lateinit var db: Database
fun Toast(text: String?, context: Context) { fun toast(text: String?, context: Context) {
android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show() android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show()
} }
@@ -34,6 +34,6 @@ object ManagerSingleton {
} }
nfsw = settings.getBoolean("show_nsfw", false) nfsw = settings.getBoolean("show_nsfw", false)
videos_count = settings.getString("videos_count", "15")!!.toInt() videosCount = settings.getString("videos_count", "15")!!.toInt()
} }
} }

View File

@@ -4,17 +4,17 @@ import android.content.SharedPreferences
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 android.preference.PreferenceManager
import android.util.Log import android.util.Log
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
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
class RegisterActivity : AppCompatActivity() { class RegisterActivity : AppCompatActivity() {
private val _auth = Auth() private val auth = Auth()
lateinit var settings: SharedPreferences lateinit var settings: SharedPreferences
lateinit var client_id: String lateinit var clientId: String
lateinit var client_secret: String lateinit var clientSecret: String
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -22,13 +22,13 @@ class RegisterActivity : AppCompatActivity() {
setTitle(R.string.registerActionBtn) setTitle(R.string.registerActionBtn)
settings = PreferenceManager.getDefaultSharedPreferences(this) settings = PreferenceManager.getDefaultSharedPreferences(this)
client_id = settings.getString("client_id", "")!! clientId = settings.getString("client_id", "")!!
client_secret = settings.getString("client_secret", "")!! clientSecret = settings.getString("client_secret", "")!!
registerBtn.setOnClickListener { registerUser() } registerBtn.setOnClickListener { registerUser() }
} }
fun registerUser() { private fun registerUser() {
registerBtn.isEnabled = false registerBtn.isEnabled = false
val username = userText2.text.toString() val username = userText2.text.toString()
val password = passwordText2.text.toString() val password = passwordText2.text.toString()
@@ -38,16 +38,16 @@ class RegisterActivity : AppCompatActivity() {
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())
runOnUiThread { runOnUiThread {
when (res) { when (res) {
1 -> { 1 -> {
ManagerSingleton.Toast(getString(R.string.registerSuccess_msg), this) ManagerSingleton.toast(getString(R.string.registerSuccess_msg), this)
finish() finish()
} }
0 -> ManagerSingleton.Toast(getString(R.string.registerFailed_msg), this) 0 -> ManagerSingleton.toast(getString(R.string.registerFailed_msg), this)
-1 -> ManagerSingleton.Toast(getString(R.string.registerError_msg), this) -1 -> ManagerSingleton.toast(getString(R.string.registerError_msg), this)
} }
registerBtn.isEnabled = true registerBtn.isEnabled = true
} }

View File

@@ -37,7 +37,7 @@ import org.libre.agosto.p2play.models.VideoModel
class ReproductorActivity : AppCompatActivity() { class ReproductorActivity : AppCompatActivity() {
private val clientVideo: Videos = Videos() private val clientVideo: Videos = Videos()
lateinit var video: VideoModel lateinit var video: VideoModel
private val _actions: Actions = Actions() private val actions: Actions = Actions()
private val client: Comments = Comments() private val client: Comments = Comments()
private val videos: Videos = Videos() private val videos: Videos = Videos()
@@ -150,10 +150,10 @@ class ReproductorActivity : AppCompatActivity() {
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 {
ManagerSingleton.Toast(getString(R.string.subscribeMsg), this) ManagerSingleton.toast(getString(R.string.subscribeMsg), this)
this.changeSubscribeBtn(true) this.changeSubscribeBtn(true)
} }
} }
@@ -165,10 +165,10 @@ class ReproductorActivity : AppCompatActivity() {
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 {
ManagerSingleton.Toast(getString(R.string.unSubscribeMsg), this) ManagerSingleton.toast(getString(R.string.unSubscribeMsg), this)
this.changeSubscribeBtn(false) this.changeSubscribeBtn(false)
} }
} }
@@ -180,10 +180,10 @@ class ReproductorActivity : AppCompatActivity() {
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 {
ManagerSingleton.Toast(getString(R.string.rateMsg), this) ManagerSingleton.toast(getString(R.string.rateMsg), this)
if (rate == "like") { if (rate == "like") {
textViewLike.setTextColor(ContextCompat.getColor(this, R.color.colorLike)) textViewLike.setTextColor(ContextCompat.getColor(this, R.color.colorLike))
textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light))
@@ -201,7 +201,7 @@ class ReproductorActivity : AppCompatActivity() {
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) {
"like" -> { "like" -> {
@@ -227,7 +227,7 @@ class ReproductorActivity : AppCompatActivity() {
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)
} }
@@ -272,7 +272,7 @@ class ReproductorActivity : AppCompatActivity() {
private fun makeComment() { private fun makeComment() {
if (commentaryText.text.toString() == "") { if (commentaryText.text.toString() == "") {
ManagerSingleton.Toast(getString(R.string.emptyCommentaryMsg), this) ManagerSingleton.toast(getString(R.string.emptyCommentaryMsg), this)
return return
} }
val text = commentaryText.text.toString() val text = commentaryText.text.toString()
@@ -280,11 +280,11 @@ class ReproductorActivity : AppCompatActivity() {
val res = this.client.makeCommentary(ManagerSingleton.token.token, this.video.id, text) val res = this.client.makeCommentary(ManagerSingleton.token.token, this.video.id, text)
runOnUiThread { runOnUiThread {
if (res) { if (res) {
ManagerSingleton.Toast(getString(R.string.makedCommentaryMsg), this) ManagerSingleton.toast(getString(R.string.makedCommentaryMsg), this)
commentaryText.text?.clear() commentaryText.text?.clear()
this.getComments() this.getComments()
} else { } else {
ManagerSingleton.Toast(getString(R.string.errorCommentaryMsg), this) ManagerSingleton.toast(getString(R.string.errorCommentaryMsg), this)
} }
} }
} }
@@ -348,13 +348,13 @@ class ReproductorActivity : AppCompatActivity() {
private fun reportVideo(reason: String) { private fun reportVideo(reason: String) {
AsyncTask.execute { AsyncTask.execute {
val res = _actions.reportVideo(video.id, reason, ManagerSingleton.token.token) val res = actions.reportVideo(video.id, reason, ManagerSingleton.token.token)
runOnUiThread { runOnUiThread {
if (res) { if (res) {
ManagerSingleton.Toast(getText(R.string.reportDialogMsg).toString(), this) ManagerSingleton.toast(getText(R.string.reportDialogMsg).toString(), this)
} else { } else {
ManagerSingleton.Toast(getText(R.string.errorMsg).toString(), this) ManagerSingleton.toast(getText(R.string.errorMsg).toString(), this)
} }
} }
} }
@@ -404,7 +404,7 @@ class ReproductorActivity : AppCompatActivity() {
override fun getDefaultVideoPoster(): Bitmap? { override fun getDefaultVideoPoster(): Bitmap? {
AsyncTask.execute { AsyncTask.execute {
this@ReproductorActivity._actions.watchVideo(this@ReproductorActivity.video.id, ManagerSingleton.token.token) this@ReproductorActivity.actions.watchVideo(this@ReproductorActivity.video.id, ManagerSingleton.token.token)
} }
return if (mCustomView == null) { return if (mCustomView == null) {
@@ -447,12 +447,12 @@ class ReproductorActivity : AppCompatActivity() {
this.mOriginalSystemUiVisibility = this@ReproductorActivity.window.decorView.systemUiVisibility this.mOriginalSystemUiVisibility = this@ReproductorActivity.window.decorView.systemUiVisibility
this.mOriginalOrientation = this@ReproductorActivity.requestedOrientation this.mOriginalOrientation = this@ReproductorActivity.requestedOrientation
this.mCustomViewCallback = paramCustomViewCallback this.mCustomViewCallback = paramCustomViewCallback
val match_parent = WindowManager.LayoutParams.MATCH_PARENT val matchParent = WindowManager.LayoutParams.MATCH_PARENT
this@ReproductorActivity.nonFullScreen.visibility = View.GONE this@ReproductorActivity.nonFullScreen.visibility = View.GONE
this@ReproductorActivity.fullScreen.visibility = View.VISIBLE this@ReproductorActivity.fullScreen.visibility = View.VISIBLE
this@ReproductorActivity.fullScreen.addView(paramView, FrameLayout.LayoutParams(match_parent, match_parent)) this@ReproductorActivity.fullScreen.addView(paramView, FrameLayout.LayoutParams(matchParent, matchParent))
setFullscreen(this@ReproductorActivity.window) setFullscreen(this@ReproductorActivity.window)

View File

@@ -32,7 +32,7 @@ class SettingsActivity : AppCompatPreferenceActivity() {
override fun onBackPressed() { override fun onBackPressed() {
super.onBackPressed() super.onBackPressed()
ManagerSingleton.Toast(getString(R.string.pref_message_exit), this) ManagerSingleton.toast(getString(R.string.pref_message_exit), this)
} }
/** /**

View File

@@ -15,7 +15,7 @@ import java.lang.Exception
class SplashActivity : AppCompatActivity() { class SplashActivity : AppCompatActivity() {
lateinit var settings: SharedPreferences lateinit var settings: SharedPreferences
val client: Auth = Auth() val client: Auth = Auth()
val _db = Database(this) val db = Database(this)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -23,7 +23,7 @@ class SplashActivity : AppCompatActivity() {
settings = PreferenceManager.getDefaultSharedPreferences(this) settings = PreferenceManager.getDefaultSharedPreferences(this)
ManagerSingleton.settings = settings ManagerSingleton.settings = settings
ManagerSingleton.db = _db ManagerSingleton.db = db
ManagerSingleton.reloadSettings() ManagerSingleton.reloadSettings()
@@ -48,8 +48,8 @@ class SplashActivity : AppCompatActivity() {
private fun checkUser() { private fun checkUser() {
Log.d("was", "Checked") Log.d("was", "Checked")
try { try {
val token = _db.getToken() val token = db.getToken()
val user = _db.getUser() val user = db.getUser()
AsyncTask.execute { AsyncTask.execute {
if (Looper.myLooper() == null) { if (Looper.myLooper() == null) {
Looper.prepare() Looper.prepare()
@@ -63,7 +63,7 @@ class SplashActivity : AppCompatActivity() {
when (token.status.toString()) { when (token.status.toString()) {
"1" -> { "1" -> {
_db.newToken(newToken) db.newToken(newToken)
ManagerSingleton.token = newToken ManagerSingleton.token = newToken
ManagerSingleton.user = user ManagerSingleton.user = user
} }

View File

@@ -9,8 +9,8 @@ import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView 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 org.libre.agosto.p2play.ManagerSingleton
import org.libre.agosto.p2play.* import org.libre.agosto.p2play.R
import org.libre.agosto.p2play.models.CommentaryModel import org.libre.agosto.p2play.models.CommentaryModel
@Suppress("DEPRECATION") @Suppress("DEPRECATION")

View File

@@ -9,7 +9,10 @@ import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView 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.ChannelActivity
import org.libre.agosto.p2play.ManagerSingleton
import org.libre.agosto.p2play.R
import org.libre.agosto.p2play.ReproductorActivity
import org.libre.agosto.p2play.helpers.mapSeconds import org.libre.agosto.p2play.helpers.mapSeconds
import org.libre.agosto.p2play.models.VideoModel import org.libre.agosto.p2play.models.VideoModel
import java.io.Serializable import java.io.Serializable

View File

@@ -6,7 +6,7 @@ import java.io.InputStreamReader
class Actions : Client() { class Actions : Client() {
fun subscribe(token: String, account: String): Int { fun subscribe(token: String, account: String): Int {
val con = this._newCon("users/me/subscriptions", "POST", token) val con = this.newCon("users/me/subscriptions", "POST", token)
val params: String = "uri=$account" val params: String = "uri=$account"
con.outputStream.write(params.toByteArray()) con.outputStream.write(params.toByteArray())
var response = 0 var response = 0
@@ -25,7 +25,7 @@ class Actions : Client() {
} }
fun unSubscribe(token: String, account: String): Int { fun unSubscribe(token: String, account: String): Int {
val con = this._newCon("users/me/subscriptions/$account", "DELETE", token) val con = this.newCon("users/me/subscriptions/$account", "DELETE", token)
var response = 0 var response = 0
try { try {
@@ -42,7 +42,7 @@ class Actions : Client() {
} }
fun getSubscription(token: String, account: String): Boolean { fun getSubscription(token: String, account: String): Boolean {
val con = this._newCon("users/me/subscriptions/exist?uris=$account", "GET", token) val con = this.newCon("users/me/subscriptions/exist?uris=$account", "GET", token)
var isSubscribed = false var isSubscribed = false
try { try {
@@ -73,7 +73,7 @@ class Actions : Client() {
} }
fun rate(token: String, id_video: Int, rate: String): Int { fun rate(token: String, id_video: Int, rate: String): Int {
val con = this._newCon("videos/$id_video/rate", "PUT", token) val con = this.newCon("videos/$id_video/rate", "PUT", token)
val params = "rating=$rate" val params = "rating=$rate"
con.outputStream.write(params.toByteArray()) con.outputStream.write(params.toByteArray())
var response = 0 var response = 0
@@ -92,7 +92,7 @@ class Actions : Client() {
} }
fun getRate(token: String, id_video: Int): String { fun getRate(token: String, id_video: Int): String {
val con = this._newCon("users/me/videos/$id_video/rating", "GET", token) val con = this.newCon("users/me/videos/$id_video/rating", "GET", token)
var rating = "none" var rating = "none"
try { try {
@@ -123,7 +123,7 @@ class Actions : Client() {
} }
fun reportVideo(videoId: Int, reason: String, token: String): Boolean { fun reportVideo(videoId: Int, reason: String, token: String): Boolean {
val con = this._newCon("videos/$videoId/abuse", "POST", token) val con = this.newCon("videos/$videoId/abuse", "POST", token)
val params = "reason=$reason" val params = "reason=$reason"
con.outputStream.write(params.toByteArray()) con.outputStream.write(params.toByteArray())
@@ -141,7 +141,7 @@ class Actions : Client() {
} }
fun watchVideo(videoId: Int, token: String): Boolean { fun watchVideo(videoId: Int, token: String): Boolean {
val con = this._newCon("videos/$videoId/watching", "PUT", token) val con = this.newCon("videos/$videoId/watching", "PUT", token)
val params = "currentTime=1" val params = "currentTime=1"
con.outputStream.write(params.toByteArray()) con.outputStream.write(params.toByteArray())

View File

@@ -12,7 +12,7 @@ class Auth : Client() {
private val stockParams = "grant_type=password" private val stockParams = "grant_type=password"
fun login(username: String, password: String, client_id: String, client_secret: String, twoFactorCode: String? = null): TokenModel { fun login(username: String, password: String, client_id: String, client_secret: String, twoFactorCode: String? = null): TokenModel {
val con = this._newCon("users/token", "POST") val con = this.newCon("users/token", "POST")
val params = "$stockParams&username=$username&password=$password&client_id=$client_id&client_secret=$client_secret" val params = "$stockParams&username=$username&password=$password&client_id=$client_id&client_secret=$client_secret"
if (twoFactorCode !== null) { if (twoFactorCode !== null) {
@@ -60,7 +60,7 @@ class Auth : Client() {
} }
fun register(username: String, password: String, email: String): Int { fun register(username: String, password: String, email: String): Int {
val con = this._newCon("users/register", "POST") val con = this.newCon("users/register", "POST")
val params = "username=$username&password=$password&email=$email" val params = "username=$username&password=$password&email=$email"
con.outputStream.write(params.toByteArray()) con.outputStream.write(params.toByteArray())
@@ -80,7 +80,7 @@ class Auth : Client() {
} }
fun refreshToken(token: TokenModel, client_id: String, client_secret: String): TokenModel { fun refreshToken(token: TokenModel, client_id: String, client_secret: String): TokenModel {
val con = this._newCon("users/token", "POST", token.token) val con = this.newCon("users/token", "POST", token.token)
val params = "refresh_token=${token.refresh_token}&response_type=code&grant_type=refresh_token&client_id=$client_id&client_secret=$client_secret" val params = "refresh_token=${token.refresh_token}&response_type=code&grant_type=refresh_token&client_id=$client_id&client_secret=$client_secret"
con.outputStream.write(params.toByteArray()) con.outputStream.write(params.toByteArray())
// val token = TokenModel() // val token = TokenModel()
@@ -116,7 +116,7 @@ class Auth : Client() {
} }
fun me(token: String): UserModel { fun me(token: String): UserModel {
val con = this._newCon("users/me", "GET", token) val con = this.newCon("users/me", "GET", token)
val user = UserModel() val user = UserModel()
try { try {

View File

@@ -15,7 +15,7 @@ class Channels : Client() {
} }
fun getChannelInfo(account: String): ChannelModel { fun getChannelInfo(account: String): ChannelModel {
val con = this._newCon("video-channels/$account", "GET") val con = this.newCon("video-channels/$account", "GET")
var channel = ChannelModel() var channel = ChannelModel()
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {

View File

@@ -9,7 +9,7 @@ import java.net.HttpURLConnection
import java.net.URL import java.net.URL
open class Client { open class Client {
protected fun _newCon(uri: String, method: String, token: String = ""): HttpURLConnection { protected fun newCon(uri: String, method: String, token: String = ""): HttpURLConnection {
val url = URL("https://${ManagerSingleton.url}/api/v1/$uri") val url = URL("https://${ManagerSingleton.url}/api/v1/$uri")
val con = url.openConnection() as HttpURLConnection val con = url.openConnection() as HttpURLConnection
@@ -34,7 +34,7 @@ open class Client {
} }
fun getKeys(): HostModel { fun getKeys(): HostModel {
val con = this._newCon("oauth-clients/local", "GET") val con = this.newCon("oauth-clients/local", "GET")
val keys = HostModel("", "") val keys = HostModel("", "")
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {

View File

@@ -31,7 +31,7 @@ class Comments : Client() {
fun getCommentaries(videoId: Int): ArrayList<CommentaryModel> { fun getCommentaries(videoId: Int): ArrayList<CommentaryModel> {
var commentaries = arrayListOf<CommentaryModel>() var commentaries = arrayListOf<CommentaryModel>()
val con = this._newCon("videos/$videoId/comment-threads", "GET") val con = this.newCon("videos/$videoId/comment-threads", "GET")
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {
@@ -48,7 +48,7 @@ class Comments : Client() {
} }
fun makeCommentary(token: String, videoId: Int, text: String): Boolean { fun makeCommentary(token: String, videoId: Int, text: String): Boolean {
val con = this._newCon("videos/$videoId/comment-threads", "POST", token) val con = this.newCon("videos/$videoId/comment-threads", "POST", token)
val params = "text=$text" val params = "text=$text"
con.outputStream.write(params.toByteArray()) con.outputStream.write(params.toByteArray())

View File

@@ -31,10 +31,10 @@ class Videos : Client() {
private fun getVideos(start: Int, sort: String = "-publishedAt", isLocal: Boolean = false): ArrayList<VideoModel> { private fun getVideos(start: Int, sort: String = "-publishedAt", isLocal: Boolean = false): ArrayList<VideoModel> {
val nsfw = ManagerSingleton.nfsw val nsfw = ManagerSingleton.nfsw
val count = ManagerSingleton.videos_count val count = ManagerSingleton.videosCount
var params = "start=$start&count=$count&sort=$sort&nsfw=$nsfw&isLocal=$isLocal" var params = "start=$start&count=$count&sort=$sort&nsfw=$nsfw&isLocal=$isLocal"
val con = this._newCon("videos?$params", "GET") val con = this.newCon("videos?$params", "GET")
var videos = arrayListOf<VideoModel>() var videos = arrayListOf<VideoModel>()
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {
@@ -67,9 +67,9 @@ class Videos : Client() {
} }
fun myVideos(token: String, start: Int = 0): ArrayList<VideoModel> { fun myVideos(token: String, start: Int = 0): ArrayList<VideoModel> {
val count = ManagerSingleton.videos_count val count = ManagerSingleton.videosCount
val params = "start=$start&count=$count" val params = "start=$start&count=$count"
val con = this._newCon("users/me/videos?$params", "GET", token) val con = this.newCon("users/me/videos?$params", "GET", token)
var videos = arrayListOf<VideoModel>() var videos = arrayListOf<VideoModel>()
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {
@@ -87,9 +87,9 @@ class Videos : Client() {
} }
fun videoSubscriptions(token: String, start: Int = 0): ArrayList<VideoModel> { fun videoSubscriptions(token: String, start: Int = 0): ArrayList<VideoModel> {
val count = ManagerSingleton.videos_count val count = ManagerSingleton.videosCount
val params = "start=$start&count=$count" val params = "start=$start&count=$count"
val con = this._newCon("users/me/subscriptions/videos?$params", "GET", token) val con = this.newCon("users/me/subscriptions/videos?$params", "GET", token)
var videos = arrayListOf<VideoModel>() var videos = arrayListOf<VideoModel>()
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {
@@ -111,9 +111,9 @@ class Videos : Client() {
} }
fun videoHistory(token: String, start: Int = 0): ArrayList<VideoModel> { fun videoHistory(token: String, start: Int = 0): ArrayList<VideoModel> {
val count = ManagerSingleton.videos_count val count = ManagerSingleton.videosCount
val params = "start=$start&count=$count" val params = "start=$start&count=$count"
val con = this._newCon("users/me/history/videos?$params", "GET", token) val con = this.newCon("users/me/history/videos?$params", "GET", token)
var videos = arrayListOf<VideoModel>() var videos = arrayListOf<VideoModel>()
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {
@@ -131,10 +131,10 @@ class Videos : Client() {
} }
fun search(text: String, start: Int = 0): ArrayList<VideoModel> { fun search(text: String, start: Int = 0): ArrayList<VideoModel> {
val count = ManagerSingleton.videos_count val count = ManagerSingleton.videosCount
val nsfw = ManagerSingleton.nfsw val nsfw = ManagerSingleton.nfsw
val params = "search=$text&start=$start&count=$count&nsfw=$nsfw" val params = "search=$text&start=$start&count=$count&nsfw=$nsfw"
val con = this._newCon("search/videos?$params", "GET") val con = this.newCon("search/videos?$params", "GET")
var videos = arrayListOf<VideoModel>() var videos = arrayListOf<VideoModel>()
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {
@@ -151,7 +151,7 @@ class Videos : Client() {
} }
fun fullDescription(videoId: Int): String { fun fullDescription(videoId: Int): String {
val con = this._newCon("videos/$videoId/description", "GET") val con = this.newCon("videos/$videoId/description", "GET")
var description = "" var description = ""
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {
@@ -178,9 +178,9 @@ class Videos : Client() {
} }
fun channelVideos(account: String, start: Int): ArrayList<VideoModel> { fun channelVideos(account: String, start: Int): ArrayList<VideoModel> {
val count = ManagerSingleton.videos_count val count = ManagerSingleton.videosCount
val params = "start=$start&count=$count" val params = "start=$start&count=$count"
val con = this._newCon("video-channels/$account/videos?$params", "GET") val con = this.newCon("video-channels/$account/videos?$params", "GET")
var videos = arrayListOf<VideoModel>() var videos = arrayListOf<VideoModel>()
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {
@@ -202,7 +202,7 @@ class Videos : Client() {
} }
fun getVideo(uuid: String): VideoModel { fun getVideo(uuid: String): VideoModel {
val con = this._newCon("videos/$uuid", "GET") val con = this.newCon("videos/$uuid", "GET")
val video = VideoModel() val video = VideoModel()
try { try {
if (con.responseCode == 200) { if (con.responseCode == 200) {

View File

@@ -1,6 +1,6 @@
package org.libre.agosto.p2play package org.libre.agosto.p2play
import org.junit.Assert.* import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test
/** /**