This commit is contained in:
kehaoyuan@ghzhushou.com
2020-03-12 14:19:45 +08:00
parent 81dc17530f
commit c87bf1e613
9 changed files with 88 additions and 60 deletions

View File

@ -12,6 +12,9 @@ import android.view.ViewGroup;
import com.gh.base.OnListClickListener;
import com.gh.base.OnRequestCallBackListener;
import com.gh.common.constant.Constants;
import com.gh.common.syncpage.ISyncAdapterHandler;
import com.gh.common.syncpage.SyncDataEntity;
import com.gh.common.syncpage.SyncPageRepository;
import com.gh.gamecenter.BuildConfig;
import com.gh.gamecenter.eventbus.EBMiPush;
import com.lightgame.OnTitleClickListener;
@ -31,10 +34,12 @@ import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.ButterKnife;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import kotlin.Pair;
import static com.gh.common.util.EntranceUtils.KEY_ENTRANCE;
@ -141,6 +146,29 @@ public abstract class BaseFragment<T> extends Fragment implements OnRequestCallB
ButterKnife.bind(this, mCachedView);
initView(mCachedView);
RecyclerView syncRecyclerView = provideSyncPageRecyclerView();
if (syncRecyclerView != null) {
initSyncPageObserver(syncRecyclerView);
}
}
private void initSyncPageObserver(RecyclerView syncRecyclerView) {
SyncPageRepository.INSTANCE.getSyncPageLiveData().observe(this, syncDataEntities -> {
if (syncDataEntities == null || syncDataEntities.isEmpty()) return;
RecyclerView.Adapter adapter = syncRecyclerView.getAdapter();
if (!(adapter instanceof ISyncAdapterHandler)) return;
for (int i = 0; i < adapter.getItemCount(); i++) {
Pair<String, Object> syncKey = ((ISyncAdapterHandler) adapter).getSyncData(i);
if (syncKey == null) return;
for (SyncDataEntity syncDataEntity : syncDataEntities) {
if (syncDataEntity.getSyncId().equals(syncKey.getFirst())) {
boolean isSuccess = SyncPageRepository.INSTANCE.handleSyncData(syncKey.getSecond(), syncDataEntity);
if (isSuccess) adapter.notifyItemChanged(i);
}
}
}
});
}
// 必须的有subscribe才能register
@ -255,4 +283,7 @@ public abstract class BaseFragment<T> extends Fragment implements OnRequestCallB
return this;
}
protected RecyclerView provideSyncPageRecyclerView() {
return null;
}
}