From 1173b083e0e211772e576a4030776d96a648b3de Mon Sep 17 00:00:00 2001 From: daigorian Date: Thu, 8 Jul 2021 22:45:35 +0900 Subject: [PATCH] =?UTF-8?q?=E9=8C=B2=E7=94=BB=E3=83=AB=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E3=82=92=E6=96=B0=E3=81=97=E3=81=84=E9=A0=86/=E5=8F=A4?= =?UTF-8?q?=E3=81=84=E9=A0=86=E3=81=AB=E4=B8=A6=E3=81=B9=E6=9B=BF=E3=81=88?= =?UTF-8?q?=20=E6=A9=9F=E8=83=BD=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/daigorian/epcltvapp/MainFragment.kt | 91 +++++++++++++------ .../epcltvapp/epgstationcaller/EpgStation.kt | 2 +- 2 files changed, 62 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/daigorian/epcltvapp/MainFragment.kt b/app/src/main/java/com/daigorian/epcltvapp/MainFragment.kt index eb7f775..1211d8e 100644 --- a/app/src/main/java/com/daigorian/epcltvapp/MainFragment.kt +++ b/app/src/main/java/com/daigorian/epcltvapp/MainFragment.kt @@ -1,4 +1,5 @@ package com.daigorian.epcltvapp +import android.annotation.SuppressLint import com.daigorian.epcltvapp.epgstationcaller.* import com.daigorian.epcltvapp.epgstationv2caller.* @@ -218,48 +219,56 @@ class MainFragment : BrowseSupportFragment() { mMainMenuAdapter.addToCategory(Category.SEARCH_HISTORY,historyRow) } + //ルールの並び順を表すフラグ。デフォルトfalse。 + val isNewestFirst = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(getString(R.string.pref_key_rules_order_is_newest_first),false) //次の横の列。録画ルール。録画ルールの数だけ行が増える。 - EpgStation.api?.getRulesList()?.enqueue(object : Callback> { - override fun onResponse(call: Call>, response: Response>) { - response.body()?.forEach { rule -> - - //録画ルールにキーワードが設定されていない場合、キーワードの代わりにルールIDをセット - val keyword:String = if ( rule.keyword.isNullOrEmpty() ){ - getString(R.string.rule_id_is_x, rule.id.toString()) - }else{ - rule.keyword - } - val recordedByRule = contentsListRowBuilder( - GetRecordedParam(rule= rule.id), - GetRecordedParamV2(ruleId= rule.id), - keyword - ) - mMainMenuAdapter.addToCategory(Category.RECORDED_BY_RULES,recordedByRule) + EpgStation.api?.getRulesList()?.enqueue(object : Callback> { + override fun onResponse(call: Call>, response: Response>) { + response.body()?.let{ it -> + val rules = if(isNewestFirst){it.reversed()}else{it} + rules.forEach { rule -> + + //録画ルールにキーワードが設定されていない場合、キーワードの代わりにルールIDをセット + val keyword:String = if ( rule.keyword.isNullOrEmpty() ){ + getString(R.string.rule_id_is_x, rule.id.toString()) + }else{ + rule.keyword + } + val recordedByRule = contentsListRowBuilder( + GetRecordedParam(rule= rule.id), + GetRecordedParamV2(ruleId= rule.id), + keyword + ) + mMainMenuAdapter.addToCategory(Category.RECORDED_BY_RULES,recordedByRule) + } } } - override fun onFailure(call: Call>, t: Throwable) { + override fun onFailure(call: Call>, t: Throwable) { Log.d(TAG,"loadRows() getRulesList API Failure") Toast.makeText(context!!, R.string.connect_epgstation_failed, Toast.LENGTH_LONG).show() } }) EpgStationV2.api?.getRules(limit=Int.MAX_VALUE)?.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { - response.body()?.rules?.forEach { rule -> - - //録画ルールにキーワードが設定されていない場合、キーワードの代わりにルールIDをセット - val keyword:String = if ( rule.searchOption?.keyword.isNullOrEmpty() ){ - getString(R.string.rule_id_is_x, rule.id.toString()) - }else{ - rule.searchOption?.keyword!! + response.body()?.rules?.let{ it -> + val rules = if(isNewestFirst){it.reversed()}else{it} + rules.forEach { rule -> + + //録画ルールにキーワードが設定されていない場合、キーワードの代わりにルールIDをセット + val keyword:String = if ( rule.searchOption?.keyword.isNullOrEmpty() ){ + getString(R.string.rule_id_is_x, rule.id.toString()) + }else{ + rule.searchOption?.keyword!! + } + val recordedByRule = contentsListRowBuilder( + GetRecordedParam(rule= rule.id), + GetRecordedParamV2(ruleId= rule.id), + keyword + ) + mMainMenuAdapter.addToCategory(Category.RECORDED_BY_RULES,recordedByRule) } - val recordedByRule = contentsListRowBuilder( - GetRecordedParam(rule= rule.id), - GetRecordedParamV2(ruleId= rule.id), - keyword - ) - mMainMenuAdapter.addToCategory(Category.RECORDED_BY_RULES,recordedByRule) } } override fun onFailure(call: Call, t: Throwable) { @@ -274,6 +283,13 @@ class MainFragment : BrowseSupportFragment() { val gridRowAdapter = ArrayObjectAdapter(gridPresenter) gridRowAdapter.add(resources.getString(R.string.settings)) gridRowAdapter.add(resources.getString(R.string.reload)) + if (isNewestFirst){ + gridRowAdapter.add(resources.getString(R.string.set_oldest_rule_first)) + }else{ + gridRowAdapter.add(resources.getString(R.string.set_newest_rule_first)) + } + + mMainMenuAdapter.addToCategory(Category.SETTINGS,ListRow(gridHeader, gridRowAdapter)) } @@ -291,6 +307,7 @@ class MainFragment : BrowseSupportFragment() { } private inner class ItemViewClickedListener : OnItemViewClickedListener { + @SuppressLint("ApplySharedPref") override fun onItemClicked( itemViewHolder: Presenter.ViewHolder, item: Any, @@ -338,6 +355,20 @@ class MainFragment : BrowseSupportFragment() { item.contains(getString(R.string.reload)) -> { loadRows() } + item.contains(getString(R.string.set_newest_rule_first)) -> { + PreferenceManager.getDefaultSharedPreferences(context) + .edit() + .putBoolean(getString(R.string.pref_key_rules_order_is_newest_first),true) + .commit() + loadRows() + } + item.contains(getString(R.string.set_oldest_rule_first)) -> { + PreferenceManager.getDefaultSharedPreferences(context) + .edit() + .putBoolean(getString(R.string.pref_key_rules_order_is_newest_first),false) + .commit() + loadRows() + } else -> { Toast.makeText(context!!, item, Toast.LENGTH_LONG).show() } diff --git a/app/src/main/java/com/daigorian/epcltvapp/epgstationcaller/EpgStation.kt b/app/src/main/java/com/daigorian/epcltvapp/epgstationcaller/EpgStation.kt index dc26d8c..1a7f0fa 100644 --- a/app/src/main/java/com/daigorian/epcltvapp/epgstationcaller/EpgStation.kt +++ b/app/src/main/java/com/daigorian/epcltvapp/epgstationcaller/EpgStation.kt @@ -23,7 +23,7 @@ object EpgStation { ): Call @GET("rules/list") - fun getRulesList(): Call> + fun getRulesList(): Call> } private var ip:String = "192.168.0.0"