Initial commit
This commit is contained in:
149
sources/com/ubt/jimu/controller/view/DragRecycleView.java
Normal file
149
sources/com/ubt/jimu/controller/view/DragRecycleView.java
Normal file
@@ -0,0 +1,149 @@
|
||||
package com.ubt.jimu.controller.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.DragEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.ubt.jimu.R;
|
||||
import com.ubt.jimu.base.data.Servo;
|
||||
import com.ubt.jimu.controller.adapter.DragAdapter;
|
||||
import com.ubt.jimu.course.view.GridItemDecoration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class DragRecycleView extends FrameLayout implements View.OnDragListener {
|
||||
private View a;
|
||||
private ImageView b;
|
||||
private TextView c;
|
||||
private RecyclerView d;
|
||||
private TextView e;
|
||||
private List<Servo> f;
|
||||
private DragAdapter g;
|
||||
private OnDragListener h;
|
||||
|
||||
public interface OnDragListener {
|
||||
void a(View view, int i);
|
||||
|
||||
void a(Servo servo);
|
||||
|
||||
void b(Servo servo);
|
||||
}
|
||||
|
||||
public DragRecycleView(Context context) {
|
||||
super(context);
|
||||
this.f = new ArrayList();
|
||||
a();
|
||||
}
|
||||
|
||||
private void a() {
|
||||
View inflate = LayoutInflater.from(getContext()).inflate(R.layout.layout_drag_recycleview, (ViewGroup) this, true);
|
||||
this.e = (TextView) inflate.findViewById(R.id.tv_title);
|
||||
this.d = (RecyclerView) inflate.findViewById(R.id.rv_drag);
|
||||
this.d.setLayoutManager(new GridLayoutManager(getContext(), 4));
|
||||
int dimensionPixelSize = getContext().getResources().getDimensionPixelSize(R.dimen.servo_mode_item_spacing);
|
||||
this.d.a(new GridItemDecoration(dimensionPixelSize, dimensionPixelSize, 0));
|
||||
setOnDragListener(this);
|
||||
this.a = inflate.findViewById(R.id.rl_servo_null);
|
||||
this.b = (ImageView) inflate.findViewById(R.id.iv_servo_null);
|
||||
this.c = (TextView) inflate.findViewById(R.id.tv_servo_null_tips);
|
||||
}
|
||||
|
||||
public void b(int i) {
|
||||
List<Servo> list = this.f;
|
||||
if (list != null && list.size() <= 0) {
|
||||
a(true);
|
||||
}
|
||||
this.g.notifyItemRemoved(i);
|
||||
}
|
||||
|
||||
public DragAdapter getAdapter() {
|
||||
return this.g;
|
||||
}
|
||||
|
||||
public RecyclerView getRecycleView() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
@Override // android.view.View.OnDragListener
|
||||
public boolean onDrag(View view, DragEvent dragEvent) {
|
||||
if (!(dragEvent.getLocalState() instanceof Servo)) {
|
||||
return false;
|
||||
}
|
||||
int action = dragEvent.getAction();
|
||||
if (action == 3) {
|
||||
if (this.h == null) {
|
||||
return true;
|
||||
}
|
||||
this.h.a((Servo) dragEvent.getLocalState());
|
||||
return true;
|
||||
}
|
||||
if (action != 4 || this.h == null) {
|
||||
return true;
|
||||
}
|
||||
this.h.b((Servo) dragEvent.getLocalState());
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setTitle(int i) {
|
||||
this.e.setText(i);
|
||||
}
|
||||
|
||||
public DragRecycleView(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
this.f = new ArrayList();
|
||||
a();
|
||||
}
|
||||
|
||||
public void a(int i, int i2) {
|
||||
this.c.setText(i2);
|
||||
this.b.setImageResource(i);
|
||||
}
|
||||
|
||||
public void a(List<Servo> list, final OnDragListener onDragListener) {
|
||||
this.f = list;
|
||||
this.h = onDragListener;
|
||||
List<Servo> list2 = this.f;
|
||||
if (list2 != null && list2.size() > 0) {
|
||||
this.d.setVisibility(0);
|
||||
this.a.setVisibility(8);
|
||||
}
|
||||
if (this.g == null) {
|
||||
this.g = new DragAdapter(getContext(), this.f, new DragAdapter.OnDragListener(this) { // from class: com.ubt.jimu.controller.view.DragRecycleView.1
|
||||
@Override // com.ubt.jimu.controller.adapter.DragAdapter.OnDragListener
|
||||
public void a(View view, int i) {
|
||||
OnDragListener onDragListener2 = onDragListener;
|
||||
if (onDragListener2 != null) {
|
||||
onDragListener2.a(view, i);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
this.d.setAdapter(this.g);
|
||||
}
|
||||
|
||||
private void a(boolean z) {
|
||||
if (z) {
|
||||
this.d.setVisibility(8);
|
||||
this.a.setVisibility(0);
|
||||
} else {
|
||||
this.d.setVisibility(0);
|
||||
this.a.setVisibility(8);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(int i) {
|
||||
List<Servo> list = this.f;
|
||||
if (list != null && list.size() > 0) {
|
||||
a(false);
|
||||
}
|
||||
this.g.notifyItemInserted(i);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user