mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-05 07:41:23 +00:00
Minor UI tweak, allow for settings reload, async settings load (with loader)
This commit is contained in:
parent
201fe6f0df
commit
10a661ad4c
5 changed files with 56 additions and 7 deletions
|
@ -10,7 +10,10 @@ import androidx.activity.result.ActivityResult
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.futo.platformplayer.*
|
import com.futo.platformplayer.*
|
||||||
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import com.futo.platformplayer.views.Loader
|
||||||
import com.futo.platformplayer.views.fields.FieldForm
|
import com.futo.platformplayer.views.fields.FieldForm
|
||||||
import com.futo.platformplayer.views.fields.ReadOnlyTextField
|
import com.futo.platformplayer.views.fields.ReadOnlyTextField
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
|
@ -18,6 +21,7 @@ import com.google.android.material.button.MaterialButton
|
||||||
class SettingsActivity : AppCompatActivity(), IWithResultLauncher {
|
class SettingsActivity : AppCompatActivity(), IWithResultLauncher {
|
||||||
private lateinit var _form: FieldForm;
|
private lateinit var _form: FieldForm;
|
||||||
private lateinit var _buttonBack: ImageButton;
|
private lateinit var _buttonBack: ImageButton;
|
||||||
|
private lateinit var _loader: Loader;
|
||||||
|
|
||||||
private lateinit var _devSets: LinearLayout;
|
private lateinit var _devSets: LinearLayout;
|
||||||
private lateinit var _buttonDev: MaterialButton;
|
private lateinit var _buttonDev: MaterialButton;
|
||||||
|
@ -33,9 +37,10 @@ class SettingsActivity : AppCompatActivity(), IWithResultLauncher {
|
||||||
_buttonBack = findViewById(R.id.button_back);
|
_buttonBack = findViewById(R.id.button_back);
|
||||||
_buttonDev = findViewById(R.id.button_dev);
|
_buttonDev = findViewById(R.id.button_dev);
|
||||||
_devSets = findViewById(R.id.dev_settings);
|
_devSets = findViewById(R.id.dev_settings);
|
||||||
|
_loader = findViewById(R.id.loader);
|
||||||
|
|
||||||
_form.fromObject(Settings.instance);
|
|
||||||
_form.onChanged.subscribe { field, value ->
|
_form.onChanged.subscribe { field, value ->
|
||||||
|
Logger.i("SettingsActivity", "Setting [${field.field?.name}] changed, saving");
|
||||||
_form.setObjectValues();
|
_form.setObjectValues();
|
||||||
Settings.instance.save();
|
Settings.instance.save();
|
||||||
};
|
};
|
||||||
|
@ -59,6 +64,15 @@ class SettingsActivity : AppCompatActivity(), IWithResultLauncher {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_lastActivity = this;
|
_lastActivity = this;
|
||||||
|
|
||||||
|
reloadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
fun reloadSettings() {
|
||||||
|
_loader.start();
|
||||||
|
_form.fromObject(lifecycleScope, Settings.instance) {
|
||||||
|
_loader.stop();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
|
|
@ -8,6 +8,10 @@ import com.futo.platformplayer.R
|
||||||
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
||||||
import com.futo.platformplayer.constructs.Event2
|
import com.futo.platformplayer.constructs.Event2
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
|
@ -33,6 +37,28 @@ class FieldForm : LinearLayout {
|
||||||
_root = findViewById(R.id.field_form_root);
|
_root = findViewById(R.id.field_form_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun fromObject(scope: CoroutineScope, obj : Any, onLoaded: (()->Unit)? = null) {
|
||||||
|
_root.removeAllViews();
|
||||||
|
|
||||||
|
scope.launch(Dispatchers.Default) {
|
||||||
|
val newFields = getFieldsFromObject(context, obj);
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
for (field in newFields) {
|
||||||
|
if (field !is View)
|
||||||
|
throw java.lang.IllegalStateException("Only views can be IFields");
|
||||||
|
|
||||||
|
_root.addView(field as View);
|
||||||
|
field.onChanged.subscribe { a1, a2 ->
|
||||||
|
onChanged.emit(a1, a2);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
_fields = newFields;
|
||||||
|
|
||||||
|
onLoaded?.invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
fun fromObject(obj : Any) {
|
fun fromObject(obj : Any) {
|
||||||
_root.removeAllViews();
|
_root.removeAllViews();
|
||||||
val newFields = getFieldsFromObject(context, obj);
|
val newFields = getFieldsFromObject(context, obj);
|
||||||
|
|
|
@ -52,6 +52,13 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
<com.futo.platformplayer.views.Loader
|
||||||
|
android:id="@+id/loader"
|
||||||
|
android:layout_marginBottom="15dp"
|
||||||
|
android:layout_marginTop="15dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="60dp" />
|
||||||
|
|
||||||
<com.futo.platformplayer.views.fields.FieldForm
|
<com.futo.platformplayer.views.fields.FieldForm
|
||||||
android:id="@+id/settings_form"
|
android:id="@+id/settings_form"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
<LinearLayout android:layout_width="wrap_content"
|
<LinearLayout android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="18dp"
|
android:paddingStart="15dp"
|
||||||
android:paddingEnd="18dp"
|
android:paddingEnd="15dp"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingBottom="8dp">
|
android:paddingBottom="8dp">
|
||||||
|
|
||||||
|
|
|
@ -303,6 +303,7 @@
|
||||||
android:id="@+id/videodetail_channel_button"
|
android:id="@+id/videodetail_channel_button"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="7dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
@ -311,21 +312,22 @@
|
||||||
|
|
||||||
<com.futo.platformplayer.views.others.CreatorThumbnail
|
<com.futo.platformplayer.views.others.CreatorThumbnail
|
||||||
android:id="@+id/creator_thumbnail"
|
android:id="@+id/creator_thumbnail"
|
||||||
android:layout_width="27dp"
|
android:layout_width="35dp"
|
||||||
android:layout_height="27dp" />
|
android:layout_height="35dp" />
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_marginStart="6dp"
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/videodetail_channel_name"
|
android:id="@+id/videodetail_channel_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingEnd="10dp"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_marginTop="-4dp"
|
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
tools:text="Channel Name" />
|
tools:text="Channel Name" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue