Update setting view

This commit is contained in:
Ivan Agosto 2024-03-31 16:59:57 -06:00
parent ac191c04d3
commit 6a8d3baccb
11 changed files with 140 additions and 42 deletions

View File

@ -42,6 +42,7 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.support:appcompat-v7:23.2.0' implementation 'com.android.support:appcompat-v7:23.2.0'
implementation 'com.google.android.material:material:1.6.0' implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.preference:preference:1.2.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.5.2' androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'

View File

@ -11,13 +11,23 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.P2play"> android:theme="@style/Theme.P2play">
<activity android:name=".ChannelActivity" <activity
android:theme="@style/Theme.P2play.NoActionBar" android:name=".SettingsActivity2"
android:exported="false" /> android:exported="false"
android:label="@string/title_activity_settings"
android:theme="@style/Theme.P2play">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".ChannelActivity"
android:exported="false"
android:theme="@style/Theme.P2play.NoActionBar" />
<activity <activity
android:name=".SplashActivity" android:name=".SplashActivity"
android:theme="@style/Theme.P2play.NoActionBar" android:exported="true"
android:exported="true"> android:theme="@style/Theme.P2play.NoActionBar">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -26,26 +36,32 @@
</activity> </activity>
<activity <activity
android:name=".HostActivity" android:name=".HostActivity"
android:theme="@style/Theme.P2play.NoActionBar" android:exported="false"
android:exported="false" /> android:theme="@style/Theme.P2play.NoActionBar" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:theme="@style/Theme.P2play.NoActionBar" android:exported="false"
android:exported="false" /> android:theme="@style/Theme.P2play.NoActionBar" />
<activity <activity
android:name=".ReproductorActivity" android:name=".ReproductorActivity"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:exported="false"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
android:theme="@style/Theme.P2play.NoActionBar" android:theme="@style/Theme.P2play.NoActionBar" />
<activity
android:name=".LoginActivity"
android:exported="false" />
<activity
android:name=".RegisterActivity"
android:exported="false" />
<activity
android:name=".AboutActivity"
android:exported="false" /> android:exported="false" />
<activity android:name=".LoginActivity" android:exported="false" />
<activity android:name=".RegisterActivity" android:exported="false" />
<activity android:name=".AboutActivity" android:exported="false" />
<activity <activity
android:name=".SettingsActivity" android:name=".SettingsActivity"
android:exported="false"
android:label="@string/title_activity_settings" android:label="@string/title_activity_settings"
android:theme="@style/Theme.P2play" android:theme="@style/Theme.P2play" />
android:exported="false"/>
</application> </application>
</manifest> </manifest>

View File

@ -6,7 +6,7 @@ import android.os.AsyncTask
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.os.Looper import android.os.Looper
import android.preference.PreferenceManager import androidx.preference.PreferenceManager
import kotlinx.android.synthetic.main.activity_host.* import kotlinx.android.synthetic.main.activity_host.*
import org.libre.agosto.p2play.ajax.Auth import org.libre.agosto.p2play.ajax.Auth
@ -41,8 +41,6 @@ class HostActivity : AppCompatActivity() {
} }
} }
fun saveHost(host: String){ fun saveHost(host: String){
editor.putString("last_host",host) editor.putString("last_host",host)
editor.putString("hostP2play",host) editor.putString("hostP2play",host)

View File

@ -304,7 +304,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
// as you specify a parent activity in AndroidManifest.xml. // as you specify a parent activity in AndroidManifest.xml.
when (item.itemId) { when (item.itemId) {
R.id.action_settings -> { R.id.action_settings -> {
val intent = Intent(this, SettingsActivity::class.java) val intent = Intent(this, SettingsActivity2::class.java)
startActivity(intent) startActivity(intent)
return true return true
} }

View File

@ -1,6 +1,9 @@
package org.libre.agosto.p2play package org.libre.agosto.p2play
import android.content.Context import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Handler
import org.libre.agosto.p2play.models.TokenModel import org.libre.agosto.p2play.models.TokenModel
import org.libre.agosto.p2play.models.UserModel import org.libre.agosto.p2play.models.UserModel
@ -10,13 +13,29 @@ object ManagerSingleton {
var token: TokenModel = TokenModel() var token: TokenModel = TokenModel()
var nfsw: Boolean = false var nfsw: Boolean = false
var videos_count: Int = 0 var videos_count: Int = 0
lateinit var settings: SharedPreferences
lateinit var db: Database
fun Toast(text: String?, context: Context) { fun Toast(text: String?, context: Context) {
android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show() android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show()
} }
fun logout(){ fun logout(){
db.logout()
user = UserModel() user = UserModel()
token = TokenModel() token = TokenModel()
} }
fun reloadSettings () {
val host = settings.getString("hostP2play", "")
val lastHost = settings.getString("last_host", "")
if(host != ""){
if(lastHost != host){
logout()
}
url = host
}
nfsw = settings.getBoolean("show_nsfw", false)
videos_count = settings.getString("videos_count", "15")!!.toInt()
}
} }

View File

@ -0,0 +1,31 @@
package org.libre.agosto.p2play
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceFragmentCompat
class SettingsActivity2 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.settings_activity)
if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
.replace(R.id.settings, SettingsFragment())
.commit()
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
override fun onDestroy() {
super.onDestroy()
ManagerSingleton.reloadSettings()
}
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
}
}
}

View File

@ -7,14 +7,13 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.preference.PreferenceManager import androidx.preference.PreferenceManager
import android.util.Log import android.util.Log
import org.libre.agosto.p2play.ajax.Auth import org.libre.agosto.p2play.ajax.Auth
import java.lang.Exception import java.lang.Exception
class SplashActivity : AppCompatActivity() { class SplashActivity : AppCompatActivity() {
lateinit var settings: SharedPreferences lateinit var settings: SharedPreferences
lateinit var editor: SharedPreferences.Editor
val client: Auth = Auth() val client: Auth = Auth()
val _db = Database(this) val _db = Database(this)
@ -23,16 +22,15 @@ class SplashActivity : AppCompatActivity() {
setContentView(R.layout.activity_splash) setContentView(R.layout.activity_splash)
settings = PreferenceManager.getDefaultSharedPreferences(this) settings = PreferenceManager.getDefaultSharedPreferences(this)
ManagerSingleton.settings = settings
ManagerSingleton.db = _db
ManagerSingleton.nfsw = settings.getBoolean("show_nfsw", false) ManagerSingleton.reloadSettings()
ManagerSingleton.videos_count = settings.getString("videos_count", "15")!!.toInt()
val host = settings.getString("hostP2play","") val host = settings.getString("hostP2play","")
val lastHost = settings.getString("last_host","") val lastHost = settings.getString("last_host","")
if(host != ""){ if(host != ""){
if(lastHost != host){ if(lastHost != host){
_db.logout()
Handler().postDelayed({ Handler().postDelayed({
startHostActivity() startHostActivity()
}, 2000) }, 2000)
@ -40,8 +38,7 @@ class SplashActivity : AppCompatActivity() {
ManagerSingleton.url = host ManagerSingleton.url = host
checkUser() checkUser()
} }
} } else {
else{
Handler().postDelayed({ Handler().postDelayed({
startHostActivity() startHostActivity()
}, 2000) }, 2000)
@ -49,7 +46,7 @@ class SplashActivity : AppCompatActivity() {
} }
private fun checkUser(){ private fun checkUser(){
Log.d("was", "Chequed") Log.d("was", "Checked")
try { try {
val token = _db.getToken() val token = _db.getToken()
val user = _db.getUser() val user = _db.getUser()
@ -57,12 +54,11 @@ class SplashActivity : AppCompatActivity() {
if (Looper.myLooper() == null) if (Looper.myLooper() == null)
Looper.prepare() Looper.prepare()
if (token.status == 1 && user.status == 1) { if (token.status == 1 && user.status == 1) {
val client_id = settings.getString("client_id", "")!! val clientId = settings.getString("client_id", "")!!
val client_secret = settings.getString("client_secret", "")!! val clientSecret = settings.getString("client_secret", "")!!
val newToken = client.refreshToken(token, client_id, client_secret) val newToken = client.refreshToken(token, clientId, clientSecret)
when (token.status.toString()) { when (token.status.toString()) {
"1" -> { "1" -> {
@ -70,21 +66,18 @@ class SplashActivity : AppCompatActivity() {
ManagerSingleton.token = newToken ManagerSingleton.token = newToken
ManagerSingleton.user = user ManagerSingleton.user = user
} }
else -> _db.logout() else -> ManagerSingleton.logout()
} }
} else { } else {
_db.logout() ManagerSingleton.logout()
} }
startApp() startApp()
Log.d("Aqui", "81")
} }
} }
catch (err: Exception){ catch (err: Exception){
err.printStackTrace() err.printStackTrace()
Log.d("Aqui", "89")
Handler().postDelayed({ Handler().postDelayed({
startApp() startApp()
}, 2000) }, 2000)

View File

@ -65,14 +65,14 @@
<WebView <WebView
android:id="@+id/videoView" android:id="@+id/videoView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="222dp" android:layout_height="205dp"
android:layout_weight="1" android:layout_weight="1"
android:visibility="gone" /> android:visibility="gone" />
<androidx.media3.ui.PlayerView <androidx.media3.ui.PlayerView
android:id="@+id/exoPlayer" android:id="@+id/exoPlayer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="222dp" android:layout_height="205dp"
app:use_controller="true" app:use_controller="true"
app:controller_layout_id="@layout/custom_player_controls" app:controller_layout_id="@layout/custom_player_controls"
app:player_layout_id="@layout/exo_player_view"/> app:player_layout_id="@layout/exo_player_view"/>

View File

@ -0,0 +1,9 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

View File

@ -12,7 +12,7 @@
<item name="colorSurface">@color/md_theme_light_surface</item> <item name="colorSurface">@color/md_theme_light_surface</item>
<item name="colorOnSurface">@color/md_theme_light_onSurface</item> <item name="colorOnSurface">@color/md_theme_light_onSurface</item>
<item name="colorPrimaryDark">@color/md_theme_light_primary</item> <item name="colorPrimaryDark">@color/md_theme_light_primary</item>
<item name="colorAccent">@color/md_theme_light_onPrimary</item> <item name="colorAccent">@color/md_theme_light_secondary</item>
<item name="android:textColorLink">@color/md_theme_light_secondary</item> <item name="android:textColorLink">@color/md_theme_light_secondary</item>
</style> </style>

View File

@ -0,0 +1,31 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory app:title="@string/pref_header_general">
<EditTextPreference
app:defaultValue="@string/pref_hostname_error"
android:inputType="text"
app:key="hostP2play"
android:maxLines="1"
android:selectAllOnFocus="true"
android:singleLine="true"
app:useSimpleSummaryProvider="true"
app:title="@string/pref_hostname_title" />
<SwitchPreference
app:defaultValue="false"
app:key="show_nsfw"
app:summary="@string/pref_nfsw_description"
app:title="@string/pref_nfsw_title" />
<EditTextPreference
app:defaultValue="15"
android:inputType="number"
app:key="videos_count"
android:selectAllOnFocus="true"
app:singleLine="true"
app:useSimpleSummaryProvider="true"
app:title="@string/pref_videos_count_title" />
</PreferenceCategory>
</PreferenceScreen>