Skip to content

Commit

Permalink
設定画面を右側に寄せて透過させる"LeanbackSettingsFragment"に差し替え。
Browse files Browse the repository at this point in the history
  • Loading branch information
daigorian committed Jun 23, 2021
1 parent a05b1af commit ca80cef
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ https://play.google.com/store/apps/details?id=com.daigorian.epcltvapp
## 今後やりたいこと
- ~~動画リストの一番右に「さらに読み込む」ボタンの追加~~ DONE!
- ~~検索履歴を残して再検索を楽にする~~ DONE !
- 設定画面をLeanbackSettingsFragmentに変えてかっこよくする
- ~~設定画面をLeanbackSettingsFragmentに変えてかっこよくする~~ DONE !
- 検索画面をメイン画面とシームレスに接続する
- 割と入手性の良い端末であるAmazon FireTVシリーズへの対応、Amazonのストアでの公開
- 初回起動時のOnboarding画面の追加
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.daigorian.epcltvapp"
minSdkVersion 22
targetSdkVersion 30
versionCode 13
versionName "1.13"
versionCode 14
versionName "1.14"

}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
<activity android:name=".PlaybackActivity"
android:screenOrientation="landscape"/>
<activity android:name=".SearchActivity"
android:theme="@style/CustomizedSearchActivity"
android:screenOrientation="landscape"/>
<activity android:name=".SettingsActivity"
android:theme="@style/LeanbackPreferences"
android:screenOrientation="landscape"/>
</application>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/daigorian/epcltvapp/SettingsActivity.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.daigorian.epcltvapp


import android.app.Activity
import android.os.Bundle
import androidx.fragment.app.FragmentActivity

class SettingsActivity : FragmentActivity() {
class SettingsActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
Expand Down
121 changes: 94 additions & 27 deletions app/src/main/java/com/daigorian/epcltvapp/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,108 @@ import android.content.Context
import android.os.Bundle
import android.widget.Toast
import androidx.leanback.preference.LeanbackPreferenceFragment
import androidx.leanback.preference.LeanbackSettingsFragment
import androidx.preference.*
import androidx.preference.DialogPreference.TargetFragment


class SettingsFragment : LeanbackPreferenceFragment() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey)
class SettingsFragment : LeanbackSettingsFragment(), TargetFragment {
private var mPreferenceFragment: PreferenceFragment? = null
override fun onPreferenceStartInitialScreen() {
mPreferenceFragment = buildPreferenceFragment(R.xml.preferences, null)
startPreferenceFragment(mPreferenceFragment!!)
}

override fun onPreferenceStartFragment(
preferenceFragment: PreferenceFragment,
preference: Preference
): Boolean {
return false
}

override fun onPreferenceStartScreen(
preferenceFragment: PreferenceFragment,
preferenceScreen: PreferenceScreen
): Boolean {
val frag = buildPreferenceFragment(
R.xml.preferences,
preferenceScreen.key
)
startPreferenceFragment(frag)
return true
}


//IPアドレスの入力時バリデーション
val ipAddressPref = preferenceScreen.findPreference(getText(R.string.pref_key_ip_addr)) as EditTextPreference?
ipAddressPref?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
val regex = Regex(pattern =IP_REGEX_PATTERN)
if (value.toString().matches(regex)){
true
}else{
Toast.makeText(activity, getString(R.string.not_a_valid_ipv4_addr,value.toString()), Toast.LENGTH_LONG).show()
false
private fun buildPreferenceFragment(preferenceResId: Int, root: String?): PreferenceFragment {
val fragment: PreferenceFragment =
PrefFragment()
val args = Bundle()
args.putInt(
PREFERENCE_RESOURCE_ID,
preferenceResId
)
args.putString(
PREFERENCE_ROOT,
root
)
fragment.arguments = args
return fragment
}

override fun <T : Preference?> findPreference(key: CharSequence): T? {
return mPreferenceFragment!!.findPreference(key)
}

class PrefFragment : LeanbackPreferenceFragment() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
val root = arguments.getString(PREFERENCE_ROOT, null)
val prefResId = arguments.getInt(PREFERENCE_RESOURCE_ID)
if (root == null) {
addPreferencesFromResource(prefResId)
} else {
setPreferencesFromResource(prefResId, root)
}

}

//PORT番号の入力時バリデーション
val portNumPref = preferenceScreen.findPreference(getText(R.string.pref_key_port_num)) as EditTextPreference?
portNumPref?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
val regex = Regex(pattern =PORT_REGEX_PATTERN)
if (value.toString().matches(regex)){
true
}else{
Toast.makeText(activity, getString(R.string.not_a_valid_port_num,value.toString()), Toast.LENGTH_LONG).show()
false
//IPアドレスの入力時バリデーション
val ipAddressPref = preferenceScreen.findPreference(getText(R.string.pref_key_ip_addr)) as EditTextPreference?
ipAddressPref?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
val regex = Regex(pattern =IP_REGEX_PATTERN)
if (value.toString().matches(regex)){
true
}else{
Toast.makeText(activity, getString(R.string.not_a_valid_ipv4_addr,value.toString()), Toast.LENGTH_LONG).show()
false
}

}

//PORT番号の入力時バリデーション
val portNumPref = preferenceScreen.findPreference(getText(R.string.pref_key_port_num)) as EditTextPreference?
portNumPref?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
val regex = Regex(pattern =PORT_REGEX_PATTERN)
if (value.toString().matches(regex)){
true
}else{
Toast.makeText(activity, getString(R.string.not_a_valid_port_num,value.toString()), Toast.LENGTH_LONG).show()
false
}

}

}


companion object{
}

}


companion object{
companion object {
private const val PREFERENCE_RESOURCE_ID = "preferenceResource"
private const val PREFERENCE_ROOT = "root"

private const val IP_REGEX_PATTERN = """^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$"""
private const val PORT_REGEX_PATTERN = """^([1-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"""

Expand All @@ -60,11 +125,13 @@ class SettingsFragment : LeanbackPreferenceFragment() {
}
//ほかのパラメータの存在チェック
return (
pref.contains(context.getString(R.string.pref_key_fetch_limit)) &&
pref.contains(context.getString(R.string.pref_key_player)) &&
pref.contains(context.getString(R.string.pref_key_num_of_history))
)
pref.contains(context.getString(R.string.pref_key_fetch_limit)) &&
pref.contains(context.getString(R.string.pref_key_player)) &&
pref.contains(context.getString(R.string.pref_key_num_of_history))
)
}

}


}
6 changes: 1 addition & 5 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
android:name="com.daigorian.epcltvapp.SettingsFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>




</RelativeLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<string name="pref_options_movie_player_label_MX">MX Player (デフォルト)</string>
<string name="pref_options_movie_player_label_VLC">VLC</string>
<string name="pref_options_movie_player_label_INTERNAL">内蔵 (非推奨)</string>
<string name="settings_title">\"EPGStationの録画を見る\" の設定</string>
<string name="settings_title">設定</string>
<string name="not_a_valid_ipv4_addr">%1$s は有効なIPv4アドレスではありません</string>
<string name="not_a_valid_port_num">%1$s は有効なポート番号ではありません</string>
<string name="version_of_epgstation">EPGStationのバージョン</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- UI -->
<string name="browse_title">EPGStation</string>
<string name="settings">Settings</string>
<string name="settings_title">Settings of EPGStation Player</string>
<string name="settings_title">Settings</string>
<string name="now_on_recording">Now On Recording</string>
<string name="recent_videos">Recent videos</string>
<string name="rule_id_is_x">Rule ID %1$s</string>
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<resources>

<style name="Theme.Epcltvapp" parent="@style/Theme.Leanback" >
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Leanback</item>
<item name="android:colorPrimary">@color/background_epgstation</item>
</style>

<style name="LeanbackPreferences" parent="Theme.Leanback">
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Leanback</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:colorPrimary">@color/background_epgstation</item>
</style>

<style name="CustomizedSearchActivity" parent="Theme.Leanback">
</style>

</resources>

0 comments on commit ca80cef

Please sign in to comment.