-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prefs: add dialog for editing mpv.conf
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package `is`.xyz.mpv | ||
|
||
import android.content.Context | ||
import android.preference.DialogPreference | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import android.widget.Button | ||
import android.widget.EditText | ||
import java.io.File | ||
|
||
class MpvConfEditDialog @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = android.R.attr.dialogPreferenceStyle, | ||
defStyleRes: Int = 0 | ||
): DialogPreference(context, attrs, defStyleAttr, defStyleRes) { | ||
private val configFile: File = File("${context.filesDir.path}/mpv.conf") | ||
|
||
init { | ||
isPersistent = false | ||
dialogLayoutResource = R.layout.conf_editor | ||
} | ||
|
||
override fun onBindDialogView(view: View) { | ||
super.onBindDialogView(view) | ||
|
||
view.findViewById<Button>(R.id.button_cancel).setOnClickListener { | ||
this.dialog.cancel() | ||
} | ||
view.findViewById<Button>(R.id.button_ok).setOnClickListener { | ||
val content = view.findViewById<EditText>(R.id.editText).text.toString() | ||
configFile.writeText(content) | ||
this.dialog.dismiss() | ||
} | ||
|
||
val editText = view.findViewById<EditText>(R.id.editText) | ||
if (configFile.exists()) | ||
editText.setText(configFile.readText()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@android:id/message" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingEnd="0dp" | ||
android:paddingStart="6dp" /> | ||
|
||
<Button | ||
android:id="@+id/button_cancel" | ||
style="@style/Widget.AppCompat.Button.Borderless.Colored" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentStart="true" | ||
android:text="@string/dialog_cancel" /> | ||
|
||
<Button | ||
android:id="@+id/button_ok" | ||
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentEnd="true" | ||
android:text="@string/dialog_ok" /> | ||
|
||
<EditText | ||
android:id="@+id/editText" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_above="@+id/button_cancel" | ||
android:layout_alignParentEnd="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_below="@android:id/message" | ||
android:fontFamily="monospace" | ||
android:gravity="top" | ||
android:inputType="textMultiLine|textNoSuggestions" | ||
android:scrollbars="vertical" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<is.xyz.mpv.MpvConfEditDialog | ||
android:key="" | ||
android:title="@string/pref_advanced_mpvconf" | ||
android:dialogMessage="@string/pref_advanced_mpvconf_message" | ||
android:positiveButtonText="@null" | ||
android:negativeButtonText="@null" /> | ||
|
||
<is.xyz.mpv.VersionInfoDialog | ||
android:key="" | ||
android:title="@string/pref_advanced_version" | ||
android:negativeButtonText="@null" /> | ||
|
||
</PreferenceScreen> |