From c4c5737344180e934e78859e82ae0e411e162ad4 Mon Sep 17 00:00:00 2001 From: Ivan Agosto Date: Sun, 26 May 2024 21:47:25 +0000 Subject: [PATCH] Feature/removve kotlin extensions --- app/build.gradle | 24 ++- app/src/main/AndroidManifest.xml | 5 - .../org/libre/agosto/p2play/AboutActivity.kt | 10 +- .../p2play/AppCompatPreferenceActivity.kt | 90 --------- .../libre/agosto/p2play/ChannelActivity.kt | 29 +-- .../org/libre/agosto/p2play/HostActivity.kt | 16 +- .../org/libre/agosto/p2play/LoginActivity.kt | 22 +- .../org/libre/agosto/p2play/MainActivity.kt | 126 ++++++------ .../libre/agosto/p2play/RegisterActivity.kt | 20 +- .../agosto/p2play/ReproductorActivity.kt | 164 +++++++-------- .../libre/agosto/p2play/SettingsActivity.kt | 159 --------------- .../agosto/p2play/dialogs/ThreadDialog.kt | 50 +++-- .../main/res/drawable/ic_fullscreen_24.xml | 2 +- .../res/layout-large/activity_reproductor.xml | 11 +- .../layout-large/custom_player_controls.xml | 189 +++++++++--------- .../main/res/layout-large/dialog_thread.xml | 2 + app/src/main/res/layout/activity_main.xml | 23 ++- app/src/main/res/layout/activity_register.xml | 8 +- .../main/res/layout/activity_reproductor.xml | 9 +- app/src/main/res/layout/app_bar_main.xml | 11 - .../res/layout/custom_player_controls.xml | 186 ++++++++--------- app/src/main/res/layout/dialog_thread.xml | 3 +- app/src/main/res/xml/pref_general.xml | 29 --- app/src/main/res/xml/pref_headers.xml | 23 --- build.gradle | 2 +- 25 files changed, 469 insertions(+), 744 deletions(-) delete mode 100644 app/src/main/java/org/libre/agosto/p2play/AppCompatPreferenceActivity.kt delete mode 100644 app/src/main/java/org/libre/agosto/p2play/SettingsActivity.kt delete mode 100644 app/src/main/res/xml/pref_general.xml delete mode 100644 app/src/main/res/xml/pref_headers.xml diff --git a/app/build.gradle b/app/build.gradle index 66933a5..3c0110a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,13 +2,12 @@ plugins { id "com.android.application" id "kotlin-android" - id "kotlin-android-extensions" } android { - compileSdkVersion 34 defaultConfig { applicationId "org.libre.agosto.p2play" + compileSdk 34 minSdkVersion 26 targetSdkVersion 32 versionCode 10 @@ -22,9 +21,12 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + buildFeatures { + viewBinding = true + } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } namespace 'org.libre.agosto.p2play' lint { @@ -41,14 +43,14 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.google.android.material:material:1.6.0' - implementation 'androidx.preference:preference:1.2.1' + implementation 'com.google.android.material:material:1.12.0' + implementation 'androidx.preference:preference-ktx:1.2.1' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test:runner:1.5.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' - implementation 'androidx.media3:media3-exoplayer:1.1.1' - implementation 'androidx.media3:media3-exoplayer-dash:1.1.1' - implementation 'androidx.media3:media3-ui:1.1.1' - implementation 'androidx.media3:media3-exoplayer-hls:1.1.1' - implementation "androidx.media3:media3-session:1.1.1" + implementation 'androidx.media3:media3-exoplayer:1.3.1' + implementation 'androidx.media3:media3-exoplayer-dash:1.3.1' + implementation 'androidx.media3:media3-ui:1.3.1' + implementation 'androidx.media3:media3-exoplayer-hls:1.3.1' + implementation "androidx.media3:media3-session:1.3.1" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0e34e85..3f6ff3d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -59,11 +59,6 @@ - private lateinit var viewManager: RecyclerView.LayoutManager + private lateinit var binding: ActivityChannelBinding + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_channel) + binding = ActivityChannelBinding.inflate(layoutInflater) + val view = binding.root + setContentView(view) channelId = this.intent.extras?.getString("channel")!! viewManager = getViewManager(this, resources) - subcriptionBtn.setOnClickListener { + binding.subcriptionBtn.setOnClickListener { subscribeAction() } } @@ -48,7 +51,7 @@ class ChannelActivity : AppCompatActivity() { getVideos() if (ManagerSingleton.user.status == 1) { - subcriptionBtn.visibility = View.VISIBLE + binding.subcriptionBtn.visibility = View.VISIBLE getSubscription() } } @@ -57,11 +60,11 @@ class ChannelActivity : AppCompatActivity() { AsyncTask.execute { channel = channelService.getChannelInfo(channelId) runOnUiThread { - usernameProfile.text = channel.name - hostTxt.text = channel.host - subcriptionsTxt.text = channel.followers.toString() + binding.usernameProfile.text = channel.name + binding.hostTxt.text = channel.host + binding.subcriptionsTxt.text = channel.followers.toString() if (channel.channelImg != "") { - Picasso.get().load("https://${ManagerSingleton.url}${channel.channelImg}").into(channelImg) + Picasso.get().load("https://${ManagerSingleton.url}${channel.channelImg}").into(binding.channelImg) } } } @@ -72,7 +75,7 @@ class ChannelActivity : AppCompatActivity() { val res = actionsService.subscribe(ManagerSingleton.token.token, channel.getAccount()) runOnUiThread { if (res == 1) { - subcriptionBtn.text = getString(R.string.unSubscribeBtn) + binding.subcriptionBtn.text = getString(R.string.unSubscribeBtn) ManagerSingleton.toast(getString(R.string.subscribeMsg), this) getSubscription() } else { @@ -87,7 +90,7 @@ class ChannelActivity : AppCompatActivity() { val res = actionsService.unSubscribe(ManagerSingleton.token.token, channel.getAccount()) runOnUiThread { if (res == 1) { - subcriptionBtn.text = getString(R.string.subscribeBtn) + binding.subcriptionBtn.text = getString(R.string.subscribeBtn) ManagerSingleton.toast(getString(R.string.unSubscribeMsg), this) getSubscription() } else { @@ -110,9 +113,9 @@ class ChannelActivity : AppCompatActivity() { isSubcribed = actionsService.getSubscription(ManagerSingleton.token.token, channel.getAccount()) runOnUiThread { if (isSubcribed) { - subcriptionBtn.text = getText(R.string.unSubscribeBtn) + binding.subcriptionBtn.text = getText(R.string.unSubscribeBtn) } else { - subcriptionBtn.text = getText(R.string.subscribeBtn) + binding.subcriptionBtn.text = getText(R.string.subscribeBtn) } } } diff --git a/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt b/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt index 4e8494c..3e3103a 100644 --- a/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/HostActivity.kt @@ -7,8 +7,8 @@ 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 +import org.libre.agosto.p2play.databinding.ActivityHostBinding class HostActivity : AppCompatActivity() { lateinit var settings: SharedPreferences @@ -16,15 +16,19 @@ class HostActivity : AppCompatActivity() { val client: Auth = Auth() private val db = Database(this) + private lateinit var binding: ActivityHostBinding + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_host) + binding = ActivityHostBinding.inflate(layoutInflater) + val view = binding.root + setContentView(view) settings = PreferenceManager.getDefaultSharedPreferences(this) editor = settings.edit() - button.setOnClickListener { - getKeys(hostText.text.toString()) + binding.button.setOnClickListener { + getKeys(binding.hostText.text.toString()) } val host = settings.getString("hostP2play", "") @@ -51,7 +55,7 @@ class HostActivity : AppCompatActivity() { } private fun getKeys(hostText: String) { - button.isEnabled = false + binding.button.isEnabled = false var host = hostText.toString() host = host.replace("http://", "") host = host.replace("https://", "") @@ -71,7 +75,7 @@ class HostActivity : AppCompatActivity() { } else { runOnUiThread { ManagerSingleton.toast(getString(R.string.errorMsg), this) - button.isEnabled = true + binding.button.isEnabled = true } } } diff --git a/app/src/main/java/org/libre/agosto/p2play/LoginActivity.kt b/app/src/main/java/org/libre/agosto/p2play/LoginActivity.kt index 6c2e07b..7b2cfdc 100644 --- a/app/src/main/java/org/libre/agosto/p2play/LoginActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/LoginActivity.kt @@ -9,8 +9,8 @@ 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 +import org.libre.agosto.p2play.databinding.ActivityLoginBinding class LoginActivity : AppCompatActivity() { private val auth = Auth() @@ -20,9 +20,13 @@ class LoginActivity : AppCompatActivity() { private lateinit var db: Database private var optCode: String? = null + private lateinit var binding: ActivityLoginBinding + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_login) + binding = ActivityLoginBinding.inflate(layoutInflater) + val view = binding.root + setContentView(view) setTitle(R.string.action_login) db = Database(this) @@ -30,14 +34,14 @@ class LoginActivity : AppCompatActivity() { clientId = settings.getString("client_id", "")!! clientSecret = settings.getString("client_secret", "")!! - registerActionBtn.setOnClickListener { startActivity(Intent(this, RegisterActivity::class.java)) } - loginBtn.setOnClickListener { tryLogin() } + binding.registerActionBtn.setOnClickListener { startActivity(Intent(this, RegisterActivity::class.java)) } + binding.loginBtn.setOnClickListener { tryLogin() } } fun tryLogin() { - loginBtn.isEnabled = false - val username = userText.text.toString() - val password = passwordText.text.toString() + binding.loginBtn.isEnabled = false + val username = binding.userText.text.toString() + val password = binding.passwordText.text.toString() AsyncTask.execute { if (Looper.myLooper() == null) { @@ -62,7 +66,7 @@ class LoginActivity : AppCompatActivity() { } "-1" -> { runOnUiThread { - loginBtn.isEnabled = true + binding.loginBtn.isEnabled = true ManagerSingleton.toast(getString(R.string.loginFailed_msg), this) } } @@ -84,7 +88,7 @@ class LoginActivity : AppCompatActivity() { } .setNegativeButton("Cancel") { d, _ -> dialog.run { d.cancel() } - loginBtn.isEnabled = true + binding.loginBtn.isEnabled = true } val alertDialog = builder.create() alertDialog.show() diff --git a/app/src/main/java/org/libre/agosto/p2play/MainActivity.kt b/app/src/main/java/org/libre/agosto/p2play/MainActivity.kt index 7efe016..dc1befd 100644 --- a/app/src/main/java/org/libre/agosto/p2play/MainActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/MainActivity.kt @@ -1,34 +1,24 @@ package org.libre.agosto.p2play import android.content.Intent -import android.content.res.Configuration import android.os.AsyncTask import android.os.Bundle import android.os.Handler import android.view.Menu import android.view.MenuItem import android.view.View +import android.widget.ImageView +import android.widget.TextView import androidx.appcompat.app.ActionBarDrawerToggle import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.core.view.GravityCompat -import androidx.recyclerview.widget.GridLayoutManager -import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.android.material.navigation.NavigationView import com.squareup.picasso.Picasso -import kotlinx.android.synthetic.main.activity_main.drawer_layout -import kotlinx.android.synthetic.main.activity_main.nav_view -import kotlinx.android.synthetic.main.app_bar_main.toolbar -import kotlinx.android.synthetic.main.content_main.mini -import kotlinx.android.synthetic.main.content_main.swipeContainer -import kotlinx.android.synthetic.main.mini_player.mini_play_pause -import kotlinx.android.synthetic.main.mini_player.mini_player_author -import kotlinx.android.synthetic.main.mini_player.mini_player_image -import kotlinx.android.synthetic.main.mini_player.mini_player_title -import kotlinx.android.synthetic.main.nav_header_main.* import org.libre.agosto.p2play.adapters.VideosAdapter import org.libre.agosto.p2play.ajax.Videos +import org.libre.agosto.p2play.databinding.ActivityMainBinding import org.libre.agosto.p2play.helpers.getViewManager import org.libre.agosto.p2play.models.VideoModel import org.libre.agosto.p2play.singletons.PlaybackSingleton @@ -44,16 +34,20 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte var section: String = "" var searchVal: String = "" var pagination = 0 + + private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - setSupportActionBar(toolbar) + binding = ActivityMainBinding.inflate(layoutInflater) + val view = binding.root + setContentView(view) + setSupportActionBar(binding.toolbar) - val toggle = ActionBarDrawerToggle(this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) - drawer_layout.addDrawerListener(toggle) + val toggle = ActionBarDrawerToggle(this, binding.drawerLayout, binding.toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) + binding.drawerLayout.addDrawerListener(toggle) toggle.syncState() - nav_view.setNavigationItemSelectedListener(this) + binding.navView.setNavigationItemSelectedListener(this) viewManager = getViewManager(this, resources) @@ -62,19 +56,20 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte this.getTrengindVideos() - swipeContainer.setOnRefreshListener { + binding.content.swipeContainer.setOnRefreshListener { this.refresh() } - mini_player_image.setOnClickListener { this.resumeVideo() } - mini_player_title.setOnClickListener { this.resumeVideo() } - mini_player_author.setOnClickListener { this.resumeVideo() } - mini.setOnClickListener { this.resumeVideo() } - mini_play_pause.setOnClickListener { this.playPausePlayer() } + + binding.content.mini.miniPlayerImage.setOnClickListener { this.resumeVideo() } + binding.content.mini.miniPlayerTitle.setOnClickListener { this.resumeVideo() } + binding.content.mini.miniPlayerAuthor.setOnClickListener { this.resumeVideo() } + // binding.content.mini.setOnClickListener { this.resumeVideo() } + binding.content.mini.miniPlayPause.setOnClickListener { this.playPausePlayer() } Handler().postDelayed({ // Title for nav_bar - side_emailTxt?.text = getString(R.string.nav_header_subtitle) + " " + this.packageManager.getPackageInfo(this.packageName, 0).versionName + binding.navView.getHeaderView(0).findViewById(R.id.side_emailTxt).text = getString(R.string.nav_header_subtitle) + " " + this.packageManager.getPackageInfo(this.packageName, 0).versionName }, 2000) } @@ -99,7 +94,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte super.onScrolled(recyclerView, dx, dy) // super.onScrolled(recyclerView!!, dx, dy) - if (!swipeContainer.isRefreshing) { + if (!binding.content.swipeContainer.isRefreshing) { if (!canScrollVertically(1)) { loadMore() } @@ -107,11 +102,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte } }) } - swipeContainer.isRefreshing = false + binding.content.swipeContainer.isRefreshing = false } private fun addVideos(videos: ArrayList) { - this.swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true try { if (this.pagination == 0) { @@ -125,11 +120,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte ManagerSingleton.toast(getString(R.string.errorMsg), this) } - this.swipeContainer.isRefreshing = false + binding.content.swipeContainer.isRefreshing = false } private fun refresh() { - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true this.pagination = 0 when (section) { "local" -> this.getLocalVideos() @@ -154,7 +149,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte startActivity(Intent(this, LoginActivity::class.java)) return } - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true section = "sub" setTitle(R.string.title_subscriptions) AsyncTask.execute { @@ -167,7 +162,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte // Last videos private fun getLastVideos() { - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true section = "last" setTitle(R.string.title_recent) AsyncTask.execute { @@ -180,7 +175,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte // Popular videos private fun getPopularVideos() { - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true section = "popular" setTitle(R.string.title_popular) AsyncTask.execute { @@ -193,7 +188,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte // Trending videos private fun getTrengindVideos() { - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true section = "trending" setTitle(R.string.title_trending) AsyncTask.execute { @@ -206,7 +201,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte // Local videos private fun getLocalVideos() { - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true section = "local" setTitle(R.string.title_local) AsyncTask.execute { @@ -219,7 +214,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte // Videos of user private fun getMyVideos() { - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true section = "my_videos" setTitle(R.string.title_myVideos) AsyncTask.execute { @@ -232,7 +227,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte // Videos history of user private fun getHistory() { - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true section = "my_videos" setTitle(R.string.nav_history) AsyncTask.execute { @@ -245,7 +240,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte // Most liked private fun getMostLiked() { - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true section = "liked" setTitle(R.string.nav_likes) AsyncTask.execute { @@ -257,8 +252,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte } override fun onBackPressed() { - if (drawer_layout.isDrawerOpen(GravityCompat.START)) { - drawer_layout.closeDrawer(GravityCompat.START) + if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) { + binding.drawerLayout.closeDrawer(GravityCompat.START) } else if (!section.equals("trending")) { // Hot fix pagination = 0 @@ -350,7 +345,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte R.id.nav_likes -> getMostLiked() } - drawer_layout.closeDrawer(GravityCompat.START) + binding.drawerLayout.closeDrawer(GravityCompat.START) return true } @@ -360,13 +355,14 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte if (PlaybackSingleton.player != null && PlaybackSingleton.player!!.isPlaying) { PlaybackSingleton.runMediaSession(this) - mini_player_title.text = PlaybackSingleton.video!!.name - mini_player_author.text = PlaybackSingleton.video!!.username - Picasso.get().load("https://${ManagerSingleton.url}${PlaybackSingleton.video!!.thumbUrl}").into(mini_player_image) - mini_play_pause.setImageResource(R.drawable.ic_pause_24) - mini.visibility = View.VISIBLE + + binding.content.mini.miniPlayerTitle.text = PlaybackSingleton.video!!.name + binding.content.mini.miniPlayerAuthor.text = PlaybackSingleton.video!!.username + Picasso.get().load("https://${ManagerSingleton.url}${PlaybackSingleton.video!!.thumbUrl}").into(binding.content.mini.miniPlayerImage) + binding.content.mini.miniPlayPause.setImageResource(R.drawable.ic_pause_24) + binding.content.mini.miniPlayer.visibility = View.VISIBLE } else { - mini.visibility = View.GONE + binding.content.mini.miniPlayer.visibility = View.GONE } } @@ -379,24 +375,25 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte private fun setSideData() { if (ManagerSingleton.user.status == 1) { - nav_view.menu.findItem(R.id.ml).isVisible = true + binding.navView.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) { - Picasso.get().load("https://" + ManagerSingleton.url + ManagerSingleton.user.avatar).into(side_imageView) + val headerView = binding.navView.getHeaderView(0) + headerView.findViewById(R.id.side_usernameTxt).text = ManagerSingleton.user.username + headerView.findViewById(R.id.side_emailTxt).text = ManagerSingleton.user.email + if (ManagerSingleton.user.avatar != "" && headerView.findViewById(R.id.side_imageView) != null) { + Picasso.get().load("https://" + ManagerSingleton.url + ManagerSingleton.user.avatar).into(headerView.findViewById(R.id.side_imageView)) } - side_imageView?.setOnClickListener { + headerView.findViewById(R.id.side_imageView).setOnClickListener { pagination = 0 getMyVideos() - drawer_layout.closeDrawer(GravityCompat.START) + binding.drawerLayout.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 + binding.navView.menu.findItem(R.id.ml).isVisible = false } } @@ -405,11 +402,12 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte 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 - 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 { } + val headerView = binding.navView.getHeaderView(0) + binding.navView.menu.findItem(R.id.ml).isVisible = false + headerView.findViewById(R.id.side_usernameTxt).text = getString(R.string.nav_header_title) + headerView.findViewById(R.id.side_emailTxt).text = getString(R.string.nav_header_subtitle) + " " + this.packageManager.getPackageInfo(this.packageName, 0).versionName + headerView.findViewById(R.id.side_imageView).setImageResource(R.drawable.default_avatar) + headerView.findViewById(R.id.side_imageView).setOnClickListener { } db.logout() ManagerSingleton.logout() @@ -419,7 +417,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte } private fun loadMore() { - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true this.pagination += ManagerSingleton.videosCount when (section) { @@ -441,7 +439,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte } private fun searchVideos() { - swipeContainer.isRefreshing = true + binding.content.swipeContainer.isRefreshing = true section = "search" this.title = this.searchVal AsyncTask.execute { @@ -462,10 +460,10 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte PlaybackSingleton.player?.let { if (it.isPlaying) { it.pause() - mini_play_pause.setImageResource(R.drawable.ic_play_arrow_24) + binding.content.mini.miniPlayPause.setImageResource(R.drawable.ic_play_arrow_24) } else { it.play() - mini_play_pause.setImageResource(R.drawable.ic_pause_24) + binding.content.mini.miniPlayPause.setImageResource(R.drawable.ic_pause_24) } } } diff --git a/app/src/main/java/org/libre/agosto/p2play/RegisterActivity.kt b/app/src/main/java/org/libre/agosto/p2play/RegisterActivity.kt index 73e2569..f696c03 100644 --- a/app/src/main/java/org/libre/agosto/p2play/RegisterActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/RegisterActivity.kt @@ -7,8 +7,8 @@ import android.os.Looper import android.util.Log import androidx.appcompat.app.AppCompatActivity import androidx.preference.PreferenceManager -import kotlinx.android.synthetic.main.activity_register.* import org.libre.agosto.p2play.ajax.Auth +import org.libre.agosto.p2play.databinding.ActivityRegisterBinding class RegisterActivity : AppCompatActivity() { private val auth = Auth() @@ -16,23 +16,27 @@ class RegisterActivity : AppCompatActivity() { lateinit var clientId: String lateinit var clientSecret: String + private lateinit var binding: ActivityRegisterBinding + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_register) + binding = ActivityRegisterBinding.inflate(layoutInflater) + val view = binding.root + setContentView(view) setTitle(R.string.registerActionBtn) settings = PreferenceManager.getDefaultSharedPreferences(this) clientId = settings.getString("client_id", "")!! clientSecret = settings.getString("client_secret", "")!! - registerBtn.setOnClickListener { registerUser() } + binding.registerBtn.setOnClickListener { registerUser() } } private fun registerUser() { - registerBtn.isEnabled = false - val username = userText2.text.toString() - val password = passwordText2.text.toString() - val email = emailText.text.toString() + binding.registerBtn.isEnabled = false + val username = binding.userText2.text.toString() + val password = binding.passwordText2.text.toString() + val email = binding.emailText.text.toString() AsyncTask.execute { if (Looper.myLooper() == null) { Looper.prepare() @@ -49,7 +53,7 @@ class RegisterActivity : AppCompatActivity() { 0 -> ManagerSingleton.toast(getString(R.string.registerFailed_msg), this) -1 -> ManagerSingleton.toast(getString(R.string.registerError_msg), this) } - registerBtn.isEnabled = true + binding.registerBtn.isEnabled = true } } } diff --git a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt index fe71c0c..cecc487 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt @@ -15,35 +15,28 @@ import android.webkit.WebChromeClient import android.widget.EditText import android.widget.FrameLayout import android.widget.ImageView +import android.widget.LinearLayout import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.media3.common.MediaItem import androidx.media3.common.MediaMetadata import androidx.media3.common.Player -import androidx.media3.exoplayer.DefaultLoadControl import androidx.media3.exoplayer.ExoPlayer -import androidx.media3.exoplayer.upstream.DefaultAllocator import androidx.media3.session.MediaController import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.squareup.picasso.Picasso -import kotlinx.android.synthetic.main.activity_reproductor.* -import kotlinx.android.synthetic.main.comment_component.commentaryBtn -import kotlinx.android.synthetic.main.comment_component.commentaryLayout -import kotlinx.android.synthetic.main.comment_component.commentaryText -import kotlinx.android.synthetic.main.comment_component.userImgCom -import kotlinx.android.synthetic.main.custom_player_controls.view.exo_controls import org.libre.agosto.p2play.adapters.CommentariesAdapter import org.libre.agosto.p2play.ajax.Actions import org.libre.agosto.p2play.ajax.Comments import org.libre.agosto.p2play.ajax.Videos +import org.libre.agosto.p2play.databinding.ActivityReproductorBinding import org.libre.agosto.p2play.helpers.setFullscreen import org.libre.agosto.p2play.models.CommentaryModel import org.libre.agosto.p2play.models.VideoModel import org.libre.agosto.p2play.singletons.PlaybackSingleton -@Suppress("NAME_SHADOWING") class ReproductorActivity : AppCompatActivity() { private val clientVideo: Videos = Videos() lateinit var video: VideoModel @@ -68,14 +61,19 @@ class ReproductorActivity : AppCompatActivity() { // Resume info private var isResume = false + private lateinit var binding: ActivityReproductorBinding + @SuppressLint("SetJavaScriptEnabled", "SetTextI18n") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_reproductor) + binding = ActivityReproductorBinding.inflate(layoutInflater) + val view = binding.root + setContentView(view) - val fullscreenButton: ImageView = exoPlayer.findViewById(R.id.exo_fullscreen_custom) - val fullscreenButton2 = fullscreenPlayer.findViewById(R.id.exo_fullscreen_custom) + val fullscreenButton = binding.exoPlayer.findViewById(R.id.exo_fullscreen_custom) + val fullscreenButton2 = binding.fullscreenPlayer.findViewById(R.id.exo_fullscreen_custom) + val videoView = binding.videoView videoView.webChromeClient = WebClient() videoView.settings.javaScriptEnabled = true videoView.settings.allowContentAccess = true @@ -95,19 +93,19 @@ class ReproductorActivity : AppCompatActivity() { isResume = true } - tittleVideoTxt.text = this.video.name - viewsTxt.text = "${this.video.views} ${getString(R.string.view_text)}" - userTxt.text = this.video.username - descriptionVideoTxt.text = this.video.description + binding.tittleVideoTxt.text = this.video.name + binding.viewsTxt.text = "${this.video.views} ${getString(R.string.view_text)}" + binding.userTxt.text = this.video.username + binding.descriptionVideoTxt.text = this.video.description val haveDescription = this.video.description.endsWith("...") if (haveDescription) { - showMoreBtn.visibility = View.VISIBLE + binding.showMoreBtn.visibility = View.VISIBLE } - hostTxt.text = this.video.userHost + binding.hostTxt.text = this.video.userHost // Check if user had profile image 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(binding.userImg) } // Load the video videoView.loadUrl("https://" + ManagerSingleton.url + this.video.embedUrl) @@ -120,17 +118,17 @@ class ReproductorActivity : AppCompatActivity() { this.getComments() - subscribeBtn.setOnClickListener { subscribe() } - likeLayout.setOnClickListener { rate("like") } - dislikeLayout.setOnClickListener { rate("dislike") } - commentaryBtn.setOnClickListener { makeComment() } - showMoreBtn.setOnClickListener { getDescription() } - shareLayout.setOnClickListener { shareIntent() } - reportLayout.setOnClickListener { reportIntent() } + binding.subscribeBtn.setOnClickListener { subscribe() } + binding.likeLayout.setOnClickListener { rate("like") } + binding.dislikeLayout.setOnClickListener { rate("dislike") } + binding.commentBox.commentaryBtn.setOnClickListener { makeComment() } + binding.showMoreBtn.setOnClickListener { getDescription() } + binding.shareLayout.setOnClickListener { shareIntent() } + binding.reportLayout.setOnClickListener { reportIntent() } fullscreenButton.setOnClickListener { toggleFullscreen() } fullscreenButton2.setOnClickListener { toggleFullscreen() } - userImg.setOnClickListener { + binding.userImg.setOnClickListener { val intent = Intent(this, ChannelActivity::class.java) intent.putExtra("channel", video.getChannel()) startActivity(intent) @@ -139,35 +137,38 @@ class ReproductorActivity : AppCompatActivity() { AsyncTask.execute { videoPlayback = this.clientVideo.getVideo(this.video.uuid) // TODO: Make this configurable - val bufferSize = 1024 * 1024 // 1mb - val allocator = DefaultAllocator(true, bufferSize) - val loadControl = DefaultLoadControl.Builder() - .setAllocator(allocator) - .build() + // val bufferSize = 1024 * 1024 // 1mb + // val allocator = DefaultAllocator(true, bufferSize) + // val loadControl = DefaultLoadControl.Builder() + // .setAllocator(allocator) + // .build() runOnUiThread { try { if (PlaybackSingleton.player == null || !PlaybackSingleton.player!!.playWhenReady) { - PlaybackSingleton.player = ExoPlayer.Builder(this.baseContext) - .setSeekBackIncrementMs(10000) - .setSeekForwardIncrementMs(10000) - .setLoadControl(loadControl).build() + PlaybackSingleton.player = ExoPlayer.Builder(this) + //.setSeekBackIncrementMs(10000) + //.setSeekForwardIncrementMs(10000) + //.setLoadControl(loadControl) + .build() } player = PlaybackSingleton.player!! - exoPlayer.player = player + binding.exoPlayer.player = player + binding.exoPlayer player.addListener( object : Player.Listener { override fun onPlaybackStateChanged(playbackState: Int) { super.onPlaybackStateChanged(playbackState) + val controls = binding.exoPlayer.findViewById(R.id.exo_center_controls) if (playbackState == Player.STATE_BUFFERING || playbackState == Player.STATE_IDLE) { - exoPlayer.exo_controls.visibility = View.INVISIBLE - } else if (playbackState == Player.STATE_READY) { - exoPlayer.exo_controls.visibility = View.VISIBLE - } - } - } + controls.visibility = View.INVISIBLE + } else if (playbackState == Player.STATE_READY) { + controls.visibility = View.VISIBLE + } + } + } ) println("----- video --------") @@ -186,6 +187,7 @@ class ReproductorActivity : AppCompatActivity() { PlaybackSingleton.setData(mediaItem, video) } // Start the playback. + // TODO: Setting for autoplay // player.play() } catch (err: Exception) { err.printStackTrace() @@ -234,11 +236,11 @@ class ReproductorActivity : AppCompatActivity() { runOnUiThread { ManagerSingleton.toast(getString(R.string.rateMsg), this) if (rate == "like") { - textViewLike.setTextColor(ContextCompat.getColor(this, R.color.colorLike)) - textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) + binding.textViewLike.setTextColor(ContextCompat.getColor(this, R.color.colorLike)) + binding.textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) } else if (rate == "dislike") { - textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.colorDislike)) - textViewLike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) + binding.textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.colorDislike)) + binding.textViewLike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) } } } @@ -254,16 +256,16 @@ class ReproductorActivity : AppCompatActivity() { runOnUiThread { when (rate) { "like" -> { - textViewLike.setTextColor(ContextCompat.getColor(this, R.color.colorLike)) - textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) + binding.textViewLike.setTextColor(ContextCompat.getColor(this, R.color.colorLike)) + binding.textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) } "dislike" -> { - textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.colorDislike)) - textViewLike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) + binding.textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.colorDislike)) + binding.textViewLike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) } else -> { - textViewLike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) - textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) + binding.textViewLike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) + binding.textViewDislike.setTextColor(ContextCompat.getColor(this, R.color.primary_dark_material_light)) } } } @@ -285,11 +287,11 @@ class ReproductorActivity : AppCompatActivity() { private fun changeSubscribeBtn(subscribed: Boolean) { if (subscribed) { - subscribeBtn.text = getText(R.string.unSubscribeBtn) - subscribeBtn.setOnClickListener { this.unSubscribe() } + binding.subscribeBtn.text = getText(R.string.unSubscribeBtn) + binding.subscribeBtn.setOnClickListener { this.unSubscribe() } } else { - subscribeBtn.text = getText(R.string.subscribeBtn) - subscribeBtn.setOnClickListener { this.subscribe() } + binding.subscribeBtn.text = getText(R.string.subscribeBtn) + binding.subscribeBtn.setOnClickListener { this.subscribe() } } } @@ -320,17 +322,17 @@ class ReproductorActivity : AppCompatActivity() { } private fun makeComment() { - if (commentaryText.text.toString() == "") { + if (binding.commentBox.commentaryText.text.toString() == "") { ManagerSingleton.toast(getString(R.string.emptyCommentaryMsg), this) return } - val text = commentaryText.text.toString() + val text = binding.commentBox.commentaryText.text.toString() AsyncTask.execute { val res = this.client.makeCommentary(ManagerSingleton.token.token, this.video.id, text) runOnUiThread { if (res) { ManagerSingleton.toast(getString(R.string.makedCommentaryMsg), this) - commentaryText.text?.clear() + binding.commentBox.commentaryText.text?.clear() this.getComments() } else { ManagerSingleton.toast(getString(R.string.errorCommentaryMsg), this) @@ -344,14 +346,14 @@ class ReproductorActivity : AppCompatActivity() { if (ManagerSingleton.user.status == 1) { this.getRate() this.getSubscription() - actionsLayout.visibility = View.VISIBLE - subscribeBtn.visibility = View.VISIBLE - commentaryLayout.visibility = View.VISIBLE + binding.actionsLayout.visibility = View.VISIBLE + binding.subscribeBtn.visibility = View.VISIBLE + binding.commentBox.commentaryLayout.visibility = View.VISIBLE if (ManagerSingleton.user.avatar != "") { - Picasso.get().load("https://" + ManagerSingleton.url + ManagerSingleton.user.avatar).into(userImgCom) + Picasso.get().load("https://" + ManagerSingleton.url + ManagerSingleton.user.avatar).into(binding.commentBox.userImgCom) } } else { - commentaryLayout.visibility = View.GONE + binding.commentBox.commentaryLayout.visibility = View.GONE } } @@ -359,8 +361,8 @@ class ReproductorActivity : AppCompatActivity() { AsyncTask.execute { val fullDescription = this.videos.fullDescription(this.video.id) runOnUiThread { - descriptionVideoTxt.text = fullDescription - showMoreBtn.visibility = View.GONE + binding.descriptionVideoTxt.text = fullDescription + binding.showMoreBtn.visibility = View.GONE } } } @@ -413,10 +415,10 @@ class ReproductorActivity : AppCompatActivity() { private fun toggleFullscreen() { if (isFullscreen) { - nonFullScreen.visibility = View.VISIBLE - fullScreenExo.visibility = View.GONE - exoPlayer.player = player - fullscreenPlayer.player = null + binding.nonFullScreen.visibility = View.VISIBLE + binding.fullScreenExo.visibility = View.GONE + binding.exoPlayer.player = player + binding.fullscreenPlayer.player = null requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED val attrs = window.attributes @@ -429,11 +431,11 @@ class ReproductorActivity : AppCompatActivity() { } else { val matchParent = WindowManager.LayoutParams.MATCH_PARENT - nonFullScreen.visibility = View.GONE - fullScreenExo.visibility = View.VISIBLE + binding.nonFullScreen.visibility = View.GONE + binding.fullScreenExo.visibility = View.VISIBLE - exoPlayer.player = null - fullscreenPlayer.player = player + binding.exoPlayer.player = null + binding.fullscreenPlayer.player = player setFullscreen(window) @@ -469,9 +471,9 @@ class ReproductorActivity : AppCompatActivity() { override fun onHideCustomView() { try { - this@ReproductorActivity.nonFullScreen.visibility = View.VISIBLE - this@ReproductorActivity.fullScreen.visibility = View.GONE - this@ReproductorActivity.fullScreen.removeView(this.mCustomView) + this@ReproductorActivity.binding.nonFullScreen.visibility = View.VISIBLE + this@ReproductorActivity.binding.fullScreen.visibility = View.GONE + this@ReproductorActivity.binding.fullScreen.removeView(this.mCustomView) this.mCustomView = null this.mCustomViewCallback!!.onCustomViewHidden() @@ -502,10 +504,10 @@ class ReproductorActivity : AppCompatActivity() { this.mCustomViewCallback = paramCustomViewCallback val matchParent = WindowManager.LayoutParams.MATCH_PARENT - this@ReproductorActivity.nonFullScreen.visibility = View.GONE - this@ReproductorActivity.fullScreen.visibility = View.VISIBLE + this@ReproductorActivity.binding.nonFullScreen.visibility = View.GONE + this@ReproductorActivity.binding.fullScreen.visibility = View.VISIBLE - this@ReproductorActivity.fullScreen.addView(paramView, FrameLayout.LayoutParams(matchParent, matchParent)) + this@ReproductorActivity.binding.fullScreen.addView(paramView, FrameLayout.LayoutParams(matchParent, matchParent)) setFullscreen(this@ReproductorActivity.window) diff --git a/app/src/main/java/org/libre/agosto/p2play/SettingsActivity.kt b/app/src/main/java/org/libre/agosto/p2play/SettingsActivity.kt deleted file mode 100644 index 246e574..0000000 --- a/app/src/main/java/org/libre/agosto/p2play/SettingsActivity.kt +++ /dev/null @@ -1,159 +0,0 @@ -package org.libre.agosto.p2play - -import android.annotation.TargetApi -import android.content.Context -import android.content.Intent -import android.content.res.Configuration -import android.os.Build -import android.os.Bundle -import android.preference.ListPreference -import android.preference.Preference -import android.preference.PreferenceActivity -import android.preference.PreferenceFragment -import android.preference.PreferenceManager -import android.view.MenuItem - -/** - * A [PreferenceActivity] that presents a set of application settings. On - * handset devices, settings are presented as a single list. On tablets, - * settings are split by category, with category headers shown to the left of - * the list of settings. - * - * See [Android Design: Settings](http://developer.android.com/design/patterns/settings.html) - * for design guidelines and the [Settings API Guide](http://developer.android.com/guide/topics/ui/settings.html) - * for more information on developing a Settings UI. - */ -class SettingsActivity : AppCompatPreferenceActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setupActionBar() - } - - override fun onBackPressed() { - super.onBackPressed() - ManagerSingleton.toast(getString(R.string.pref_message_exit), this) - } - - /** - * Set up the [android.app.ActionBar], if the API is available. - */ - private fun setupActionBar() { - supportActionBar?.setDisplayHomeAsUpEnabled(false) - } - - /** - * {@inheritDoc} - */ - override fun onIsMultiPane(): Boolean { - return isXLargeTablet(this) - } - - /** - * {@inheritDoc} - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - override fun onBuildHeaders(target: List) { - loadHeadersFromResource(R.xml.pref_headers, target) - } - - /** - * This method stops fragment injection in malicious applications. - * 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 - } - - /** - * This fragment shows general preferences only. It is used when the - * activity is showing a two-pane settings UI. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - class GeneralPreferenceFragment : PreferenceFragment() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - addPreferencesFromResource(R.xml.pref_general) - setHasOptionsMenu(true) - - // Bind the summaries of EditText/List/Dialog/Ringtone preferences - // to their values. When their values change, their summaries are - // updated to reflect the new value, per the Android Design - // guidelines. - bindPreferenceSummaryToValue(findPreference("hostP2play")) - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - val id = item.itemId - if (id == android.R.id.home) { - startActivity(Intent(activity, SettingsActivity::class.java)) - return true - } - return super.onOptionsItemSelected(item) - } - } - - companion object { - - /** - * A preference value change listener that updates the preference's summary - * to reflect its new value. - */ - private val sBindPreferenceSummaryToValueListener = Preference.OnPreferenceChangeListener { preference, value -> - val stringValue = value.toString() - - if (preference is ListPreference) { - // For list preferences, look up the correct display value in - // the preference's 'entries' list. - val listPreference = preference - val index = listPreference.findIndexOfValue(stringValue) - - // Set the summary to reflect the new value. - preference.setSummary( - if (index >= 0) { - listPreference.entries[index] - } else { - null - }, - ) - } else { - // For all other preferences, set the summary to the value's - // simple string representation. - preference.summary = stringValue - } - true - } - - /** - * Helper method to determine if the device has an extra-large screen. For - * example, 10" tablets are extra-large. - */ - private fun isXLargeTablet(context: Context): Boolean { - return context.resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK >= Configuration.SCREENLAYOUT_SIZE_XLARGE - } - - /** - * Binds a preference's summary to its value. More specifically, when the - * preference's value is changed, its summary (line of text below the - * preference title) is updated to reflect the value. The summary is also - * immediately updated upon calling this method. The exact display format is - * dependent on the type of preference. - - * @see .sBindPreferenceSummaryToValueListener - */ - private fun bindPreferenceSummaryToValue(preference: Preference) { - // Set the listener to watch for value changes. - preference.onPreferenceChangeListener = sBindPreferenceSummaryToValueListener - - // Trigger the listener immediately with the preference's - // current value. - sBindPreferenceSummaryToValueListener.onPreferenceChange( - preference, - PreferenceManager - .getDefaultSharedPreferences(preference.context) - .getString(preference.key, ""), - ) - } - } -} diff --git a/app/src/main/java/org/libre/agosto/p2play/dialogs/ThreadDialog.kt b/app/src/main/java/org/libre/agosto/p2play/dialogs/ThreadDialog.kt index 04011ce..2643ca8 100644 --- a/app/src/main/java/org/libre/agosto/p2play/dialogs/ThreadDialog.kt +++ b/app/src/main/java/org/libre/agosto/p2play/dialogs/ThreadDialog.kt @@ -12,22 +12,11 @@ import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.squareup.picasso.Picasso -import kotlinx.android.synthetic.main.comment_component.commentaryLayout -import kotlinx.android.synthetic.main.comment_component.commentaryText -import kotlinx.android.synthetic.main.comment_component.userImgCom -import kotlinx.android.synthetic.main.comment_component.view.commentaryBtn -import kotlinx.android.synthetic.main.comment_component.view.commentaryLayout -import kotlinx.android.synthetic.main.comment_component.view.commentaryText -import kotlinx.android.synthetic.main.comment_component.view.userImgCom -import kotlinx.android.synthetic.main.dialog_thread.view.materialToolbar -import kotlinx.android.synthetic.main.view_commentary.view.replyBtn -import kotlinx.android.synthetic.main.view_commentary.view.userCommentImg -import kotlinx.android.synthetic.main.view_commentary.view.userCommentary -import kotlinx.android.synthetic.main.view_commentary.view.userTxt import org.libre.agosto.p2play.ManagerSingleton import org.libre.agosto.p2play.R import org.libre.agosto.p2play.adapters.CommentariesAdapter import org.libre.agosto.p2play.ajax.Comments +import org.libre.agosto.p2play.databinding.DialogThreadBinding import org.libre.agosto.p2play.models.CommentaryModel class ThreadDialog : DialogFragment() { @@ -35,6 +24,12 @@ class ThreadDialog : DialogFragment() { lateinit var fragmentManager2: FragmentManager private val client: Comments = Comments() + private var _binding: DialogThreadBinding? = null + // This property is only valid between onCreateView and +// onDestroyView. + private val binding get() = _binding!! + + // The system calls this to get the DialogFragment's layout, regardless of // whether it's being displayed as a dialog or an embedded fragment. override fun onCreateView( @@ -43,29 +38,30 @@ class ThreadDialog : DialogFragment() { savedInstanceState: Bundle?, ): View { // Inflate the layout to use as a dialog or embedded fragment. - val view = inflater.inflate(R.layout.dialog_thread, container, false) + _binding = DialogThreadBinding.inflate(inflater, container, false) + val view = binding.root comment = arguments?.getSerializable("comment") as CommentaryModel - view.userTxt.text = comment.username - view.userCommentary.text = comment.commentary - Picasso.get().load("https://${ManagerSingleton.url}${comment.userImageUrl}").into(view.userCommentImg) - view.replyBtn.visibility = View.GONE + binding.commentThread?.userTxt?.text = comment.username + binding.commentThread?.userCommentary?.text = comment.commentary + Picasso.get().load("https://${ManagerSingleton.url}${comment.userImageUrl}").into(binding.commentThread?.userCommentImg) + binding.commentThread?.replyBtn?.visibility = View.GONE if (ManagerSingleton.user.status == 1) { - view.commentaryText.setText("${comment.username}@${comment.userHost} ") + binding.commentBox?.commentaryText?.setText("${comment.nameChannel}@${comment.userHost} ") if (ManagerSingleton.user.avatar != "") { - Picasso.get().load("https://${ManagerSingleton.url}${ManagerSingleton.user.avatar}").into(view.userImgCom) + Picasso.get().load("https://${ManagerSingleton.url}${ManagerSingleton.user.avatar}").into(binding.commentBox?.userImgCom) } - view.commentaryText.requestFocus() - view.commentaryBtn.setOnClickListener { this.replyThread() } + binding.commentBox?.commentaryText?.requestFocus() + binding.commentBox?.commentaryBtn?.setOnClickListener { this.replyThread() } } else { - view.commentaryLayout.visibility = View.GONE + binding.commentBox?.commentaryLayout?.visibility = View.GONE } - view.materialToolbar.setTitle("Thread") - view.materialToolbar.setNavigationIcon(R.drawable.baseline_arrow_back_24) - view.materialToolbar.setNavigationOnClickListener { + binding.materialToolbar.setTitle("Thread") + binding.materialToolbar.setNavigationIcon(R.drawable.baseline_arrow_back_24) + binding.materialToolbar.setNavigationOnClickListener { dismiss() this.fragmentManager2.popBackStack() } @@ -109,7 +105,7 @@ class ThreadDialog : DialogFragment() { } private fun replyThread() { - val commentary = view?.commentaryText?.text.toString() + val commentary = binding.commentBox?.commentaryText?.text.toString() if (commentary == "") { ManagerSingleton.toast(getString(R.string.emptyCommentaryMsg), requireActivity()) @@ -121,7 +117,7 @@ class ThreadDialog : DialogFragment() { activity?.runOnUiThread { if (res) { ManagerSingleton.toast(getString(R.string.makedCommentaryMsg), requireActivity()) - commentaryText.text?.clear() + binding.commentBox?.commentaryText?.text?.clear() this.getComments() } else { ManagerSingleton.toast(getString(R.string.errorCommentaryMsg), requireActivity()) diff --git a/app/src/main/res/drawable/ic_fullscreen_24.xml b/app/src/main/res/drawable/ic_fullscreen_24.xml index 42323b2..076c9aa 100644 --- a/app/src/main/res/drawable/ic_fullscreen_24.xml +++ b/app/src/main/res/drawable/ic_fullscreen_24.xml @@ -1,4 +1,4 @@ - + diff --git a/app/src/main/res/layout-large/activity_reproductor.xml b/app/src/main/res/layout-large/activity_reproductor.xml index 18706e2..b3bc599 100644 --- a/app/src/main/res/layout-large/activity_reproductor.xml +++ b/app/src/main/res/layout-large/activity_reproductor.xml @@ -84,12 +84,9 @@ android:id="@+id/exoPlayer" android:layout_width="match_parent" android:layout_height="500dp" - app:auto_show="true" - app:controller_layout_id="@layout/custom_player_controls" - app:repeat_toggle_modes="none" app:show_buffering="always" - app:surface_type="surface_view" - app:use_controller="true" /> + app:use_controller="true" + app:controller_layout_id="@layout/custom_player_controls"/> - + - + + + + + + + - - - - - - - - - - - - + android:layout_height="50dp" + android:layout_gravity="bottom" + android:layout_marginTop="@dimen/exo_styled_bottom_bar_margin_top" + android:background="@color/exo_bottom_bar_background" + android:layoutDirection="ltr"> + android:id="@id/exo_time" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical|start" + android:layoutDirection="ltr" + android:paddingStart="@dimen/exo_styled_bottom_bar_time_padding" + android:paddingLeft="@dimen/exo_styled_bottom_bar_time_padding" + android:paddingEnd="@dimen/exo_styled_bottom_bar_time_padding" + android:paddingRight="@dimen/exo_styled_bottom_bar_time_padding"> + android:id="@id/exo_position" + style="@style/ExoStyledControls.TimeText.Position" /> + style="@style/ExoStyledControls.TimeText.Separator" + android:text="/" /> + android:id="@id/exo_duration" + style="@style/ExoStyledControls.TimeText.Duration" /> - + + + + + + + + + + + + + + + + + + + + + + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout-large/dialog_thread.xml b/app/src/main/res/layout-large/dialog_thread.xml index af93bd5..dc642e1 100644 --- a/app/src/main/res/layout-large/dialog_thread.xml +++ b/app/src/main/res/layout-large/dialog_thread.xml @@ -23,6 +23,7 @@ android:minHeight="?attr/actionBarSize" /> @@ -41,6 +42,7 @@ - + android:layout_height="match_parent" + tools:context=".MainActivity"> + + + + + + + + + + - - @@ -42,7 +42,7 @@ android:textAppearance="@android:style/TextAppearance.Material.Medium.Inverse" android:textColor="@android:color/black" /> - @@ -99,4 +99,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_reproductor.xml b/app/src/main/res/layout/activity_reproductor.xml index 52c161b..e3c5017 100644 --- a/app/src/main/res/layout/activity_reproductor.xml +++ b/app/src/main/res/layout/activity_reproductor.xml @@ -74,12 +74,9 @@ android:id="@+id/exoPlayer" android:layout_width="match_parent" android:layout_height="205dp" - app:auto_show="true" app:show_buffering="always" - app:controller_layout_id="@layout/custom_player_controls" - app:surface_type="surface_view" app:use_controller="true" - app:repeat_toggle_modes="none"/> + app:controller_layout_id="@layout/custom_player_controls" /> - + - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/custom_player_controls.xml b/app/src/main/res/layout/custom_player_controls.xml index 85fd4e1..7afed01 100644 --- a/app/src/main/res/layout/custom_player_controls.xml +++ b/app/src/main/res/layout/custom_player_controls.xml @@ -1,107 +1,113 @@ - + + + + + + + - - - - - - - - - - - - + android:layout_height="50dp" + android:layout_gravity="bottom" + android:layout_marginTop="@dimen/exo_styled_bottom_bar_margin_top" + android:background="@color/exo_bottom_bar_background" + android:layoutDirection="ltr"> + android:id="@id/exo_time" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical|start" + android:layoutDirection="ltr" + android:paddingStart="@dimen/exo_styled_bottom_bar_time_padding" + android:paddingLeft="@dimen/exo_styled_bottom_bar_time_padding" + android:paddingEnd="@dimen/exo_styled_bottom_bar_time_padding" + android:paddingRight="@dimen/exo_styled_bottom_bar_time_padding"> + android:id="@id/exo_position" + style="@style/ExoStyledControls.TimeText.Position" /> + style="@style/ExoStyledControls.TimeText.Separator" + android:text="/" /> + android:id="@id/exo_duration" + style="@style/ExoStyledControls.TimeText.Duration" /> - + + + + + + + + + + + + + + + + + + + + + + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_thread.xml b/app/src/main/res/layout/dialog_thread.xml index bd5c913..95fc828 100644 --- a/app/src/main/res/layout/dialog_thread.xml +++ b/app/src/main/res/layout/dialog_thread.xml @@ -1,7 +1,6 @@ @@ -24,6 +23,7 @@ android:minHeight="?attr/actionBarSize" /> @@ -42,6 +42,7 @@ - - - - - - - - - - diff --git a/app/src/main/res/xml/pref_headers.xml b/app/src/main/res/xml/pref_headers.xml deleted file mode 100644 index 12803d9..0000000 --- a/app/src/main/res/xml/pref_headers.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - -
- - - - diff --git a/build.gradle b/build.gradle index 9967f71..3d6ea4f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.6.21' + ext.kotlin_version = '1.9.20' repositories { google() mavenCentral()