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>) :