Skip to content

Commit

Permalink
各画面で削除したときに、画面を更新するようにした。
Browse files Browse the repository at this point in the history
CardPresenterSelectorは使っていないので削除
  • Loading branch information
daigorian committed Sep 25, 2021
1 parent 83e60f0 commit 4e23f86
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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
}

}

}
8 changes: 5 additions & 3 deletions app/src/main/java/com/daigorian/epcltvapp/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -747,6 +747,7 @@ class MainFragment : BrowseSupportFragment() {
}//synchronized
}


fun sortRulesByRecordedDate(){
synchronized(this){
//bubble sort で新しいのを下からあげていく
Expand All @@ -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
//下のアイテムが上のアイテムより録画時間が新しい
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/daigorian/epcltvapp/SearchFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ 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

class SearchFragment : SearchSupportFragment() , SearchSupportFragment.SearchResultProvider {
private val mListRowPresenter = ListRowPresenter()
private val mRowsAdapter = CustomArrayObjectAdapter(mListRowPresenter)
private val mCardPresenter = OriginalCardPresenter()

override fun getResultsAdapter(): ObjectAdapter {
return mRowsAdapter
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mCardPresenter.objAdapter = mRowsAdapter
setSearchResultProvider(this)
setOnItemViewClickedListener(ItemViewClickedListener())
setOnItemViewSelectedListener(ItemViewSelectedListener())
Expand Down Expand Up @@ -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)とすることでフォーカスを移さないようにした工夫。
Expand Down Expand Up @@ -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)

Expand Down
18 changes: 10 additions & 8 deletions app/src/main/java/com/daigorian/epcltvapp/VideoDetailsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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<GetRecordedResponse> {
override fun onResponse(call: Call<GetRecordedResponse>, response: Response<GetRecordedResponse>) {
Expand All @@ -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<GetRecordedResponse> {
override fun onResponse(call: Call<GetRecordedResponse>, response: Response<GetRecordedResponse>) {
response.body()?.recorded?.forEach {
Expand Down Expand Up @@ -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<Records> {
Expand All @@ -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<Records> {
override fun onResponse(call: Call<Records>, response: Response<Records>) {
Expand Down

This file was deleted.

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 @@ -40,7 +40,7 @@
<string name="use_custom_base_url">API Base URLを編集する</string>
<string name="customize_base_url">API Base URL</string>
<string name="do_you_want_to_delete">%1$s を削除しますか</string>
<string name="successfully_deleted">削除しました。リストを再読み込みしてください。</string>
<string name="successfully_deleted">削除しました。</string>
<string name="delete_failed">削除に失敗しました</string>
<string name="delete">削除</string>
<string name="cancel">キャンセル</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 @@ -103,7 +103,7 @@
<string name="customize_base_url">Customized Base URL</string>
<string name="pref_val_custom_base_url_default" translatable="false">http://192.168.0.0:8888/api/</string>
<string name="do_you_want_to_delete">Do you want to delete %1$s</string>
<string name="successfully_deleted">Successfully deleted. Please reload items.</string>
<string name="successfully_deleted">Deleted.</string>
<string name="delete_failed">Delete failed</string>
<string name="delete">Delete</string>
<string name="cancel">Cancel</string>
Expand Down

0 comments on commit 4e23f86

Please sign in to comment.