|
|
|
|
@ -1,14 +1,10 @@ |
|
|
|
|
package com.fongmi.android.tv.ui.custom.dialog; |
|
|
|
|
|
|
|
|
|
import android.app.Activity; |
|
|
|
|
import android.view.LayoutInflater; |
|
|
|
|
import android.view.ViewGroup; |
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
import androidx.annotation.Nullable; |
|
|
|
|
import androidx.appcompat.app.AlertDialog; |
|
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
|
import androidx.fragment.app.FragmentActivity; |
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager; |
|
|
|
|
import androidx.viewbinding.ViewBinding; |
|
|
|
|
|
|
|
|
|
import com.fongmi.android.tv.api.LiveConfig; |
|
|
|
|
import com.fongmi.android.tv.bean.Live; |
|
|
|
|
@ -16,55 +12,60 @@ import com.fongmi.android.tv.databinding.DialogLiveBinding; |
|
|
|
|
import com.fongmi.android.tv.impl.LiveCallback; |
|
|
|
|
import com.fongmi.android.tv.ui.adapter.LiveAdapter; |
|
|
|
|
import com.fongmi.android.tv.ui.custom.SpaceItemDecoration; |
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; |
|
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
|
|
|
|
|
|
|
|
|
public class LiveDialog extends BaseDialog implements LiveAdapter.OnClickListener { |
|
|
|
|
public class LiveDialog implements LiveAdapter.OnClickListener { |
|
|
|
|
|
|
|
|
|
private final LiveAdapter adapter; |
|
|
|
|
private final LiveCallback callback; |
|
|
|
|
private DialogLiveBinding binding; |
|
|
|
|
private LiveCallback callback; |
|
|
|
|
private LiveAdapter adapter; |
|
|
|
|
private AlertDialog dialog; |
|
|
|
|
|
|
|
|
|
public static LiveDialog create() { |
|
|
|
|
return new LiveDialog(); |
|
|
|
|
public static LiveDialog create(Activity activity) { |
|
|
|
|
return new LiveDialog(activity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public LiveDialog() { |
|
|
|
|
this.adapter = new LiveAdapter(this); |
|
|
|
|
public static LiveDialog create(Fragment fragment) { |
|
|
|
|
return new LiveDialog(fragment); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void show(FragmentActivity activity) { |
|
|
|
|
for (Fragment f : activity.getSupportFragmentManager().getFragments()) if (f instanceof BottomSheetDialogFragment) return; |
|
|
|
|
show(activity.getSupportFragmentManager(), null); |
|
|
|
|
public LiveDialog(Activity activity) { |
|
|
|
|
this.callback = (LiveCallback) activity; |
|
|
|
|
init(activity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void show(Fragment fragment) { |
|
|
|
|
for (Fragment f : fragment.getChildFragmentManager().getFragments()) if (f instanceof BottomSheetDialogFragment) return; |
|
|
|
|
show(fragment.getChildFragmentManager(), null); |
|
|
|
|
public LiveDialog(Fragment fragment) { |
|
|
|
|
this.callback = (LiveCallback) fragment; |
|
|
|
|
init(fragment.getActivity()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private int getCount() { |
|
|
|
|
return adapter.getItemCount() < 2 ? 1 : 2; |
|
|
|
|
private void init(Activity activity) { |
|
|
|
|
this.binding = DialogLiveBinding.inflate(LayoutInflater.from(activity)); |
|
|
|
|
this.dialog = new MaterialAlertDialogBuilder(activity).setView(binding.getRoot()).create(); |
|
|
|
|
this.adapter = new LiveAdapter(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected ViewBinding getBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) { |
|
|
|
|
return binding = DialogLiveBinding.inflate(inflater, container, false); |
|
|
|
|
public void show() { |
|
|
|
|
setRecyclerView(); |
|
|
|
|
setDialog(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void initView() { |
|
|
|
|
private void setRecyclerView() { |
|
|
|
|
binding.recycler.setAdapter(adapter); |
|
|
|
|
binding.recycler.setHasFixedSize(true); |
|
|
|
|
binding.recycler.addItemDecoration(new SpaceItemDecoration(getCount(), 16)); |
|
|
|
|
binding.recycler.setLayoutManager(new GridLayoutManager(getContext(), getCount())); |
|
|
|
|
binding.recycler.addItemDecoration(new SpaceItemDecoration(1, 16)); |
|
|
|
|
binding.recycler.scrollToPosition(LiveConfig.getHomeIndex()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setDialog() { |
|
|
|
|
if (adapter.getItemCount() == 0) return; |
|
|
|
|
dialog.getWindow().setDimAmount(0); |
|
|
|
|
dialog.show(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onItemClick(Live item) { |
|
|
|
|
callback.setLive(item); |
|
|
|
|
dismiss(); |
|
|
|
|
dialog.dismiss(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|