mirror of https://github.com/FongMi/TV.git
parent
85e24d6fa4
commit
3d31ab66ec
@ -0,0 +1,93 @@ |
||||
package com.fongmi.android.tv.ui.custom.dialog; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.annotation.Nullable; |
||||
import androidx.viewbinding.ViewBinding; |
||||
|
||||
import com.fongmi.android.tv.api.ApiConfig; |
||||
import com.fongmi.android.tv.bean.Config; |
||||
import com.fongmi.android.tv.bean.History; |
||||
import com.fongmi.android.tv.databinding.DialogReceiveBinding; |
||||
import com.fongmi.android.tv.event.CastEvent; |
||||
import com.fongmi.android.tv.event.RefreshEvent; |
||||
import com.fongmi.android.tv.net.Callback; |
||||
import com.fongmi.android.tv.ui.activity.DetailActivity; |
||||
import com.fongmi.android.tv.utils.ImgUtil; |
||||
import com.fongmi.android.tv.utils.Notify; |
||||
|
||||
public class ReceiveDialog extends BaseDialog { |
||||
|
||||
private DialogReceiveBinding binding; |
||||
private CastEvent event; |
||||
|
||||
public static ReceiveDialog create() { |
||||
return new ReceiveDialog(); |
||||
} |
||||
|
||||
public ReceiveDialog event(CastEvent event) { |
||||
this.event = event; |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
protected ViewBinding getBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) { |
||||
return binding = DialogReceiveBinding.inflate(inflater, container, false); |
||||
} |
||||
|
||||
@Override |
||||
protected void initView() { |
||||
History item = event.getHistory(); |
||||
binding.name.setText(item.getVodName()); |
||||
binding.from.setText(event.getDevice().getName()); |
||||
ImgUtil.loadHistory(item.getVodPic(), binding.image); |
||||
} |
||||
|
||||
@Override |
||||
protected void initEvent() { |
||||
binding.frame.setOnClickListener(v -> onReceiveCast()); |
||||
} |
||||
|
||||
private void showProgress() { |
||||
binding.frame.setEnabled(false); |
||||
binding.play.setVisibility(View.GONE); |
||||
binding.progress.getRoot().setVisibility(View.VISIBLE); |
||||
} |
||||
|
||||
private void hideProgress() { |
||||
binding.frame.setEnabled(true); |
||||
binding.play.setVisibility(View.VISIBLE); |
||||
binding.progress.getRoot().setVisibility(View.GONE); |
||||
} |
||||
|
||||
private void onReceiveCast() { |
||||
if (ApiConfig.getUrl().equals(event.getConfig())) { |
||||
DetailActivity.cast(getActivity(), event.getHistory().update(ApiConfig.getCid())); |
||||
dismiss(); |
||||
} else { |
||||
showProgress(); |
||||
ApiConfig.get().clear().config(Config.find(event.getConfig(), 0)).load(getCallback()); |
||||
} |
||||
} |
||||
|
||||
private Callback getCallback() { |
||||
return new Callback() { |
||||
@Override |
||||
public void success() { |
||||
RefreshEvent.config(); |
||||
RefreshEvent.video(); |
||||
onReceiveCast(); |
||||
hideProgress(); |
||||
} |
||||
|
||||
@Override |
||||
public void error(int resId) { |
||||
Notify.show(resId); |
||||
hideProgress(); |
||||
} |
||||
}; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue