From 4e23f86e3b5866cfadc0623c8df6458f904ba8ca Mon Sep 17 00:00:00 2001 From: daigorian Date: Sat, 25 Sep 2021 21:34:03 +0900 Subject: [PATCH] =?UTF-8?q?=E5=90=84=E7=94=BB=E9=9D=A2=E3=81=A7=E5=89=8A?= =?UTF-8?q?=E9=99=A4=E3=81=97=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AB=E3=80=81?= =?UTF-8?q?=E7=94=BB=E9=9D=A2=E3=82=92=E6=9B=B4=E6=96=B0=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F=E3=80=82=20CardPr?= =?UTF-8?q?esenterSelector=E3=81=AF=E4=BD=BF=E3=81=A3=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=81=AE=E3=81=A7=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeleteEnabledArrayObjectAdapter.kt | 35 +++++++++++++++++++ .../com/daigorian/epcltvapp/MainFragment.kt | 8 +++-- .../{presenter => }/OriginalCardPresenter.kt | 10 +++--- .../com/daigorian/epcltvapp/SearchFragment.kt | 7 ++-- .../epcltvapp/VideoDetailsFragment.kt | 18 +++++----- .../presenter/CardPresenterSelector.kt | 13 ------- app/src/main/res/values-ja-rJP/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 8 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 app/src/main/java/com/daigorian/epcltvapp/DeleteEnabledArrayObjectAdapter.kt rename app/src/main/java/com/daigorian/epcltvapp/{presenter => }/OriginalCardPresenter.kt (96%) delete mode 100644 app/src/main/java/com/daigorian/epcltvapp/presenter/CardPresenterSelector.kt diff --git a/app/src/main/java/com/daigorian/epcltvapp/DeleteEnabledArrayObjectAdapter.kt b/app/src/main/java/com/daigorian/epcltvapp/DeleteEnabledArrayObjectAdapter.kt new file mode 100644 index 0000000..175ed7a --- /dev/null +++ b/app/src/main/java/com/daigorian/epcltvapp/DeleteEnabledArrayObjectAdapter.kt @@ -0,0 +1,35 @@ +package com.daigorian.epcltvapp + +import androidx.leanback.widget.ArrayObjectAdapter +import androidx.leanback.widget.ListRow +import androidx.leanback.widget.Presenter +import androidx.leanback.widget.PresenterSelector +import kotlin.reflect.typeOf + +open class DeleteEnabledArrayObjectAdapter : ArrayObjectAdapter { + constructor(presenterSelector: PresenterSelector?) : super(presenterSelector) + constructor(presenter: Presenter?) : super(presenter) + + fun removeItemFromAllListRows(item:Any){ + var verticalIndex = 0 + while(verticalIndex < size()){ + val row = get(verticalIndex) + if(row is ListRow){ + val horizontalArrayObjectAdapter = row.adapter as? ArrayObjectAdapter + horizontalArrayObjectAdapter?.let{ + var horizontalIndex = 0 + while(horizontalIndex < it.size()) { + if(it.get(horizontalIndex).equals(item) ){ + it.removeItems(horizontalIndex,1) + } + horizontalIndex += 1 + } + } + + } + verticalIndex += 1 + } + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/daigorian/epcltvapp/MainFragment.kt b/app/src/main/java/com/daigorian/epcltvapp/MainFragment.kt index 23bdaec..1775665 100644 --- a/app/src/main/java/com/daigorian/epcltvapp/MainFragment.kt +++ b/app/src/main/java/com/daigorian/epcltvapp/MainFragment.kt @@ -25,7 +25,6 @@ import com.bumptech.glide.Glide import com.bumptech.glide.load.model.GlideUrl import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition -import com.daigorian.epcltvapp.presenter.CardPresenterSelector import java.util.* //Retrofit 2 @@ -47,7 +46,7 @@ class MainFragment : BrowseSupportFragment() { private var mNeedsReloadAllOnResume = false private var mNeedsReloadHistoryOnResume = false - private val mCardPresenter = CardPresenterSelector() + private val mCardPresenter = OriginalCardPresenter() private val mMainMenuListRowPresenter = ListRowPresenter() private val mMainMenuAdapter = MainMenuAdapter(mMainMenuListRowPresenter) @@ -56,6 +55,7 @@ class MainFragment : BrowseSupportFragment() { super.onCreate(savedInstanceState) adapter = mMainMenuAdapter + mCardPresenter.objAdapter = mMainMenuAdapter if(!SettingsFragment.isPreferenceAllExists(requireContext())){ Log.i(TAG, "not all Preference exists") @@ -688,7 +688,7 @@ class MainFragment : BrowseSupportFragment() { SETTINGS } - private inner class MainMenuAdapter(presenter: Presenter?) : ArrayObjectAdapter(presenter) { + private inner class MainMenuAdapter(presenter: Presenter?) : DeleteEnabledArrayObjectAdapter(presenter) { private val numOfRowInCategory = IntArray(Category.values().size) @@ -747,6 +747,7 @@ class MainFragment : BrowseSupportFragment() { }//synchronized } + fun sortRulesByRecordedDate(){ synchronized(this){ //bubble sort で新しいのを下からあげていく @@ -764,6 +765,7 @@ class MainFragment : BrowseSupportFragment() { if (itemJMinus1 != null && itemJMinus1.size() >0) { //上のアイテムに録画済の要素がある + //TODO : EPGStation V2(RecordedItem) への対応 val startTimeOfJ = (itemJ.get(0) as? RecordedProgram)?.startAt val startTimeOfJMinus1 = (itemJMinus1.get(0) as? RecordedProgram)?.startAt //下のアイテムが上のアイテムより録画時間が新しい diff --git a/app/src/main/java/com/daigorian/epcltvapp/presenter/OriginalCardPresenter.kt b/app/src/main/java/com/daigorian/epcltvapp/OriginalCardPresenter.kt similarity index 96% rename from app/src/main/java/com/daigorian/epcltvapp/presenter/OriginalCardPresenter.kt rename to app/src/main/java/com/daigorian/epcltvapp/OriginalCardPresenter.kt index 1303c40..7374926 100644 --- a/app/src/main/java/com/daigorian/epcltvapp/presenter/OriginalCardPresenter.kt +++ b/app/src/main/java/com/daigorian/epcltvapp/OriginalCardPresenter.kt @@ -1,6 +1,5 @@ -package com.daigorian.epcltvapp.presenter +package com.daigorian.epcltvapp -import android.content.DialogInterface import android.graphics.drawable.Drawable import android.util.Log import android.view.ViewGroup @@ -11,7 +10,6 @@ import androidx.leanback.widget.ImageCardView import androidx.leanback.widget.Presenter import com.bumptech.glide.Glide import com.bumptech.glide.load.model.GlideUrl -import com.daigorian.epcltvapp.R import com.daigorian.epcltvapp.epgstationcaller.* import com.daigorian.epcltvapp.epgstationv2caller.* import retrofit2.Call @@ -23,13 +21,15 @@ import kotlin.properties.Delegates * A OriginalCardPresenter is used to generate Views and bind Objects to them on demand. * It contains an ImageCardView. */ -class OriginalCardPresenter : Presenter() { +class OriginalCardPresenter() : Presenter() { private var mDefaultCardImage: Drawable? = null private var mOnRecordingCardImage: Drawable? = null private var sSelectedBackgroundColor: Int by Delegates.notNull() private var sDefaultBackgroundColor: Int by Delegates.notNull() + var objAdapter :DeleteEnabledArrayObjectAdapter? =null + override fun onCreateViewHolder(parent: ViewGroup): ViewHolder { Log.d(TAG, "onCreateViewHolder") @@ -77,6 +77,7 @@ class OriginalCardPresenter : Presenter() { ) { Toast.makeText(it.context, it.context.getString(R.string.successfully_deleted), Toast.LENGTH_LONG) .show() + objAdapter?.removeItemFromAllListRows(item) } else { Toast.makeText(it.context, it.context.getString(R.string.delete_failed), Toast.LENGTH_LONG) .show() @@ -107,6 +108,7 @@ class OriginalCardPresenter : Presenter() { ) { Toast.makeText(it.context, it.context.getString(R.string.successfully_deleted), Toast.LENGTH_LONG) .show() + objAdapter?.removeItemFromAllListRows(item) } else { Toast.makeText(it.context, it.context.getString(R.string.delete_failed), Toast.LENGTH_LONG) .show() diff --git a/app/src/main/java/com/daigorian/epcltvapp/SearchFragment.kt b/app/src/main/java/com/daigorian/epcltvapp/SearchFragment.kt index daa276a..fe8b240 100644 --- a/app/src/main/java/com/daigorian/epcltvapp/SearchFragment.kt +++ b/app/src/main/java/com/daigorian/epcltvapp/SearchFragment.kt @@ -19,7 +19,6 @@ import com.daigorian.epcltvapp.epgstationv2caller.EpgStationV2 import com.daigorian.epcltvapp.epgstationv2caller.GetRecordedParamV2 import com.daigorian.epcltvapp.epgstationv2caller.RecordedItem import com.daigorian.epcltvapp.epgstationv2caller.Records -import com.daigorian.epcltvapp.presenter.CardPresenterSelector import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -27,6 +26,7 @@ import retrofit2.Response class SearchFragment : SearchSupportFragment() , SearchSupportFragment.SearchResultProvider { private val mListRowPresenter = ListRowPresenter() private val mRowsAdapter = CustomArrayObjectAdapter(mListRowPresenter) + private val mCardPresenter = OriginalCardPresenter() override fun getResultsAdapter(): ObjectAdapter { return mRowsAdapter @@ -34,6 +34,7 @@ class SearchFragment : SearchSupportFragment() , SearchSupportFragment.SearchRes override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + mCardPresenter.objAdapter = mRowsAdapter setSearchResultProvider(this) setOnItemViewClickedListener(ItemViewClickedListener()) setOnItemViewSelectedListener(ItemViewSelectedListener()) @@ -72,7 +73,7 @@ class SearchFragment : SearchSupportFragment() , SearchSupportFragment.SearchRes } private inner class CustomArrayObjectAdapter(presenter: Presenter?) : - ArrayObjectAdapter(presenter) { + DeleteEnabledArrayObjectAdapter(presenter) { //単純に ArrayObjectAdapter.add(0,item) とするとフォーカスがArrayObjectAdapter[1]に残り続けるので //ArrayObjectAdapter.replace(0,item)とすることでフォーカスを移さないようにした工夫。 @@ -141,7 +142,7 @@ class SearchFragment : SearchSupportFragment() , SearchSupportFragment.SearchRes //まずは結果行を加える。(API呼出し後の処理の中の非同期処理で加えると連続処理したときに場所が不確定になってしまうため) val newResultRowHeader = HeaderItem(query) - val newResultRowContents = ArrayObjectAdapter(CardPresenterSelector()) + val newResultRowContents = ArrayObjectAdapter(mCardPresenter) val newResultRow = ListRow(newResultRowHeader, newResultRowContents) mRowsAdapter.addToTop(newResultRow) diff --git a/app/src/main/java/com/daigorian/epcltvapp/VideoDetailsFragment.kt b/app/src/main/java/com/daigorian/epcltvapp/VideoDetailsFragment.kt index eb87c67..32ad118 100644 --- a/app/src/main/java/com/daigorian/epcltvapp/VideoDetailsFragment.kt +++ b/app/src/main/java/com/daigorian/epcltvapp/VideoDetailsFragment.kt @@ -25,7 +25,6 @@ import com.daigorian.epcltvapp.epgstationcaller.RecordedProgram import com.daigorian.epcltvapp.epgstationv2caller.EpgStationV2 import com.daigorian.epcltvapp.epgstationv2caller.RecordedItem import com.daigorian.epcltvapp.epgstationv2caller.Records -import com.daigorian.epcltvapp.presenter.CardPresenterSelector import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -42,7 +41,8 @@ class VideoDetailsFragment : DetailsSupportFragment() { private lateinit var mDetailsBackground: DetailsSupportFragmentBackgroundController private lateinit var mPresenterSelector: ClassPresenterSelector - private lateinit var mAdapter: ArrayObjectAdapter + private lateinit var mAdapter: DeleteEnabledArrayObjectAdapter + private val mCardPresenter = OriginalCardPresenter() override fun onCreate(savedInstanceState: Bundle?) { Log.d(TAG, "onCreate DetailsFragment") @@ -60,7 +60,8 @@ class VideoDetailsFragment : DetailsSupportFragment() { mSelectedRecordedProgram != null -> { // EPGStation Version 1.x.x mPresenterSelector = ClassPresenterSelector() - mAdapter = ArrayObjectAdapter(mPresenterSelector) + mAdapter = DeleteEnabledArrayObjectAdapter(mPresenterSelector) + mCardPresenter.objAdapter = mAdapter setupDetailsOverviewRow() setupDetailsOverviewRowPresenter() setupRelatedMovieListRow() @@ -71,7 +72,8 @@ class VideoDetailsFragment : DetailsSupportFragment() { mSelectedRecordedItem != null -> { // EPGStation Version 2.x.x mPresenterSelector = ClassPresenterSelector() - mAdapter = ArrayObjectAdapter(mPresenterSelector) + mAdapter = DeleteEnabledArrayObjectAdapter(mPresenterSelector) + mCardPresenter.objAdapter = mAdapter setupDetailsOverviewRow() setupDetailsOverviewRowPresenter() setupRelatedMovieListRow() @@ -337,7 +339,7 @@ class VideoDetailsFragment : DetailsSupportFragment() { val programName = programNameStriped.split(regexDelimiter) if (programName.size > 1 ) { - val listRowAdapter = ArrayObjectAdapter(CardPresenterSelector()) + val listRowAdapter = ArrayObjectAdapter(mCardPresenter) val searchKeyword = programName[0] EpgStation.api?.getRecorded(keyword = searchKeyword)?.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { @@ -359,7 +361,7 @@ class VideoDetailsFragment : DetailsSupportFragment() { // ルールIDがある場合は、同じルールIDの動画のリストを作成する recorded_program.ruleId?.let{ rule_id -> - val listRowAdapter = ArrayObjectAdapter(CardPresenterSelector()) + val listRowAdapter = ArrayObjectAdapter(mCardPresenter) EpgStation.api?.getRecorded(rule = rule_id)?.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { response.body()?.recorded?.forEach { @@ -387,7 +389,7 @@ class VideoDetailsFragment : DetailsSupportFragment() { val programName = programNameStriped.split(regexDelimiter) if (programName.size > 1 ) { - val listRowAdapter = ArrayObjectAdapter(CardPresenterSelector()) + val listRowAdapter = ArrayObjectAdapter(mCardPresenter) val searchKeyword = programName[0] EpgStationV2.api?.getRecorded(keyword = searchKeyword)?.enqueue(object : Callback { @@ -409,7 +411,7 @@ class VideoDetailsFragment : DetailsSupportFragment() { // ルールIDがある場合は、同じルールIDの動画のリストを作成する recorded_item.ruleId?.let { rule_id -> - val listRowAdapter = ArrayObjectAdapter(CardPresenterSelector()) + val listRowAdapter = ArrayObjectAdapter(mCardPresenter) EpgStationV2.api?.getRecorded(ruleId = rule_id) ?.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { diff --git a/app/src/main/java/com/daigorian/epcltvapp/presenter/CardPresenterSelector.kt b/app/src/main/java/com/daigorian/epcltvapp/presenter/CardPresenterSelector.kt deleted file mode 100644 index 5632d7c..0000000 --- a/app/src/main/java/com/daigorian/epcltvapp/presenter/CardPresenterSelector.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.daigorian.epcltvapp.presenter - -import androidx.leanback.widget.Presenter -import androidx.leanback.widget.PresenterSelector - -class CardPresenterSelector() : PresenterSelector() { - private val originalCardPresenter = OriginalCardPresenter() - - override fun getPresenter(item: Any): Presenter { - - return originalCardPresenter - } -} diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 604ba1b..0f992eb 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -40,7 +40,7 @@ API Base URLを編集する API Base URL %1$s を削除しますか - 削除しました。リストを再読み込みしてください。 + 削除しました。 削除に失敗しました 削除 キャンセル diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 654e358..48616b6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -103,7 +103,7 @@ Customized Base URL http://192.168.0.0:8888/api/ Do you want to delete %1$s - Successfully deleted. Please reload items. + Deleted. Delete failed Delete Cancel