Update setting view
This commit is contained in:
parent
ac191c04d3
commit
6a8d3baccb
|
@ -42,6 +42,7 @@ dependencies {
|
|||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'com.android.support:appcompat-v7:23.2.0'
|
||||
implementation 'com.google.android.material:material:1.6.0'
|
||||
implementation 'androidx.preference:preference:1.2.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test:runner:1.5.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
|
||||
|
|
|
@ -11,13 +11,23 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.P2play">
|
||||
<activity android:name=".ChannelActivity"
|
||||
android:theme="@style/Theme.P2play.NoActionBar"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".SettingsActivity2"
|
||||
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
|
||||
android:name=".SplashActivity"
|
||||
android:theme="@style/Theme.P2play.NoActionBar"
|
||||
android:exported="true">
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.P2play.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
@ -26,26 +36,32 @@
|
|||
</activity>
|
||||
<activity
|
||||
android:name=".HostActivity"
|
||||
android:theme="@style/Theme.P2play.NoActionBar"
|
||||
android:exported="false" />
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.P2play.NoActionBar" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:theme="@style/Theme.P2play.NoActionBar"
|
||||
android:exported="false" />
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.P2play.NoActionBar" />
|
||||
<activity
|
||||
android:name=".ReproductorActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:exported="false"
|
||||
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" />
|
||||
<activity android:name=".LoginActivity" android:exported="false" />
|
||||
<activity android:name=".RegisterActivity" android:exported="false" />
|
||||
<activity android:name=".AboutActivity" android:exported="false" />
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_settings"
|
||||
android:theme="@style/Theme.P2play"
|
||||
android:exported="false"/>
|
||||
android:theme="@style/Theme.P2play" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -6,7 +6,7 @@ import android.os.AsyncTask
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.os.Looper
|
||||
import android.preference.PreferenceManager
|
||||
import androidx.preference.PreferenceManager
|
||||
import kotlinx.android.synthetic.main.activity_host.*
|
||||
import org.libre.agosto.p2play.ajax.Auth
|
||||
|
||||
|
@ -35,14 +35,12 @@ class HostActivity : AppCompatActivity() {
|
|||
ManagerSingleton.logout()
|
||||
getKeys(host!!)
|
||||
}else{
|
||||
ManagerSingleton.url=host
|
||||
ManagerSingleton.url = host
|
||||
startApp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun saveHost(host: String){
|
||||
editor.putString("last_host",host)
|
||||
editor.putString("hostP2play",host)
|
||||
|
|
|
@ -304,7 +304,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
when (item.itemId) {
|
||||
R.id.action_settings -> {
|
||||
val intent = Intent(this, SettingsActivity::class.java)
|
||||
val intent = Intent(this, SettingsActivity2::class.java)
|
||||
startActivity(intent)
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
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
|
||||
|
||||
|
@ -10,13 +13,29 @@ object ManagerSingleton {
|
|||
var token: TokenModel = TokenModel()
|
||||
var nfsw: Boolean = false
|
||||
var videos_count: Int = 0
|
||||
|
||||
lateinit var settings: SharedPreferences
|
||||
lateinit var db: Database
|
||||
fun Toast(text: String?, context: Context) {
|
||||
android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
fun logout(){
|
||||
db.logout()
|
||||
user = UserModel()
|
||||
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()
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,14 +7,13 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.preference.PreferenceManager
|
||||
import androidx.preference.PreferenceManager
|
||||
import android.util.Log
|
||||
import org.libre.agosto.p2play.ajax.Auth
|
||||
import java.lang.Exception
|
||||
|
||||
class SplashActivity : AppCompatActivity() {
|
||||
lateinit var settings: SharedPreferences
|
||||
lateinit var editor: SharedPreferences.Editor
|
||||
val client: Auth = Auth()
|
||||
val _db = Database(this)
|
||||
|
||||
|
@ -23,16 +22,15 @@ class SplashActivity : AppCompatActivity() {
|
|||
setContentView(R.layout.activity_splash)
|
||||
|
||||
settings = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
ManagerSingleton.settings = settings
|
||||
ManagerSingleton.db = _db
|
||||
|
||||
ManagerSingleton.nfsw = settings.getBoolean("show_nfsw", false)
|
||||
ManagerSingleton.videos_count = settings.getString("videos_count", "15")!!.toInt()
|
||||
|
||||
ManagerSingleton.reloadSettings()
|
||||
|
||||
val host = settings.getString("hostP2play","")
|
||||
val lastHost = settings.getString("last_host","")
|
||||
if(host != ""){
|
||||
if(lastHost != host){
|
||||
_db.logout()
|
||||
Handler().postDelayed({
|
||||
startHostActivity()
|
||||
}, 2000)
|
||||
|
@ -40,8 +38,7 @@ class SplashActivity : AppCompatActivity() {
|
|||
ManagerSingleton.url = host
|
||||
checkUser()
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
Handler().postDelayed({
|
||||
startHostActivity()
|
||||
}, 2000)
|
||||
|
@ -49,7 +46,7 @@ class SplashActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun checkUser(){
|
||||
Log.d("was", "Chequed")
|
||||
Log.d("was", "Checked")
|
||||
try {
|
||||
val token = _db.getToken()
|
||||
val user = _db.getUser()
|
||||
|
@ -57,12 +54,11 @@ class SplashActivity : AppCompatActivity() {
|
|||
if (Looper.myLooper() == null)
|
||||
Looper.prepare()
|
||||
|
||||
|
||||
if (token.status == 1 && user.status == 1) {
|
||||
val client_id = settings.getString("client_id", "")!!
|
||||
val client_secret = settings.getString("client_secret", "")!!
|
||||
val clientId = settings.getString("client_id", "")!!
|
||||
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()) {
|
||||
"1" -> {
|
||||
|
@ -70,21 +66,18 @@ class SplashActivity : AppCompatActivity() {
|
|||
ManagerSingleton.token = newToken
|
||||
ManagerSingleton.user = user
|
||||
}
|
||||
else -> _db.logout()
|
||||
else -> ManagerSingleton.logout()
|
||||
}
|
||||
} else {
|
||||
_db.logout()
|
||||
ManagerSingleton.logout()
|
||||
}
|
||||
|
||||
|
||||
startApp()
|
||||
Log.d("Aqui", "81")
|
||||
|
||||
}
|
||||
}
|
||||
catch (err: Exception){
|
||||
err.printStackTrace()
|
||||
Log.d("Aqui", "89")
|
||||
Handler().postDelayed({
|
||||
startApp()
|
||||
}, 2000)
|
||||
|
|
|
@ -65,14 +65,14 @@
|
|||
<WebView
|
||||
android:id="@+id/videoView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="222dp"
|
||||
android:layout_height="205dp"
|
||||
android:layout_weight="1"
|
||||
android:visibility="gone" />
|
||||
|
||||
<androidx.media3.ui.PlayerView
|
||||
android:id="@+id/exoPlayer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="222dp"
|
||||
android:layout_height="205dp"
|
||||
app:use_controller="true"
|
||||
app:controller_layout_id="@layout/custom_player_controls"
|
||||
app:player_layout_id="@layout/exo_player_view"/>
|
||||
|
|
|
@ -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>
|
|
@ -12,7 +12,7 @@
|
|||
<item name="colorSurface">@color/md_theme_light_surface</item>
|
||||
<item name="colorOnSurface">@color/md_theme_light_onSurface</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>
|
||||
</style>
|
||||
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue