Skip to content

Commit

Permalink
add #setLayoutChange
Browse files Browse the repository at this point in the history
  • Loading branch information
appt2 committed Mar 31, 2024
1 parent d83bfdc commit 1c4bdc8
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 44 deletions.
44 changes: 22 additions & 22 deletions .androidide/editor/openedFiles.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
{
"allFiles": [
{
"file": "/storage/emulated/0/AndroidIDEProjects/ListSheet/README.md",
"file": "/storage/emulated/0/AndroidIDEProjects/ListSheet/library/src/main/java/widget/ItemRuner.java",
"selection": {
"end": {
"column": 0,
"index": 0,
"line": 0
"column": 29,
"index": 3779,
"line": 138
},
"start": {
"column": 0,
"index": 0,
"line": 0
"column": 14,
"index": 3764,
"line": 138
}
}
},
{
"file": "/storage/emulated/0/AndroidIDEProjects/ListSheet/library/src/main/java/widget/ItemRuner.java",
"file": "/storage/emulated/0/AndroidIDEProjects/ListSheet/app/src/main/java/com/ninjacoder/listshset/MainActivity.java",
"selection": {
"end": {
"column": 19,
"index": 2389,
"line": 74
"column": 17,
"index": 1404,
"line": 44
},
"start": {
"column": 19,
"index": 2389,
"line": 74
"column": 4,
"index": 624,
"line": 19
}
}
},
{
"file": "/storage/emulated/0/AndroidIDEProjects/ListSheet/library/src/main/java/adapter/ListAdapter.java",
"file": "/storage/emulated/0/AndroidIDEProjects/ListSheet/README.md",
"selection": {
"end": {
"column": 60,
"index": 2187,
"line": 68
"column": 17,
"index": 932,
"line": 34
},
"start": {
"column": 60,
"index": 2187,
"line": 68
"column": 17,
"index": 932,
"line": 34
}
}
}
],
"selectedFile": "/storage/emulated/0/AndroidIDEProjects/ListSheet/library/src/main/java/adapter/ListAdapter.java"
"selectedFile": "/storage/emulated/0/AndroidIDEProjects/ListSheet/library/src/main/java/widget/ItemRuner.java"
}
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@ With the help of this library, you can create different functions in a baton she
```java

ItemRuner runer = new ItemRuner(this);
runer.addItem("Hello",R.drawable.ic_launcher_foreground);
runer.addItem("Hello",R.drawable.ic_launcher_foreground,false);

runer.setCallBack((pos) ->{
runer.setDismiss();
});
runer.addItem("Hello", R.drawable.ic_launcher_foreground);
runer.addItem("Hello", R.drawable.ic_launcher_foreground, false);
runer.addItem("Hello");

runer.setCallBack(
new OnItemClickEvent() {

@Override
public void onClickItem(int pos) {}

@Override
public void onLongItem(int pos) {
runer.removed(pos);
runer.DataRomved(pos);
}
});
runer.setTextColors(Color.CYAN);
runer.setColorFilter(Color.CYAN);
runer.serDivarColor(Color.BLUE);
runer.setTitleColor(Color.CYAN);
runer.setTitle("Hello");
runer.setAnimator(true);
runer.setSheetBackground(Color.BLACK);
runer.setLayoutChange(true);
runer.show();

```
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/com/ninjacoder/listshset/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

ItemRuner runer = new ItemRuner(this);
runer.addItem("Hello", R.drawable.ic_launcher_foreground, true);
runer.addItem("Hello", R.drawable.ic_launcher_foreground, false);
runer.addItem("Hello", R.drawable.ic_launcher_foreground, false);
runer.addItem("Hello", R.drawable.ic_launcher_foreground, false);
runer.addItem("Hello", R.drawable.ic_launcher_foreground, false);
runer.addItem("Hello", R.drawable.ic_launcher_foreground);
runer.addItem("Hello", R.drawable.ic_launcher_foreground, false);
runer.addItem("Hello");

runer.setCallBack(
new OnItemClickEvent() {
Expand All @@ -44,6 +41,7 @@ public void onLongItem(int pos) {
runer.setTitle("Hello");
runer.setAnimator(true);
runer.setSheetBackground(Color.BLACK);
runer.setLayoutChange(true);
runer.show();
}
}
9 changes: 5 additions & 4 deletions library/src/main/java/adapter/ListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.VH> {
private int colorFilter = Color.WHITE;
protected OnItemClickEvent ev;
protected boolean isAnim = false;
protected boolean isLayout2 = false;


public ListAdapter(List<SheetModel> model, OnItemClickEvent ev) {
Expand All @@ -35,10 +36,7 @@ public ListAdapter(List<SheetModel> model, OnItemClickEvent ev) {

@Override
public VH onCreateViewHolder(ViewGroup parent, int viewType) {

View view =
LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_adapter, parent, false);

var view = LayoutInflater.from(parent.getContext()).inflate(isLayout2 ? R.layout.layout_adapter2 : R.layout.layout_adapter, parent, false);
return new VH(view);
}

Expand Down Expand Up @@ -91,6 +89,9 @@ public void setColorFilter(int colorFilter) {
public void setAnimatorItem(boolean is){
this.isAnim = is;
}
public void setLayoutChange(boolean isLayout2){
this.isLayout2 = isLayout2;
}

static class VH extends RecyclerView.ViewHolder {
private LinearLayout root;
Expand Down
26 changes: 20 additions & 6 deletions library/src/main/java/widget/ItemRuner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.IdRes;
import androidx.appcompat.widget.PopupMenu;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.bottomsheet.BottomSheetDialog;
Expand All @@ -26,19 +28,22 @@ public class ItemRuner {
protected BottomSheetDialog dialog;
protected SheetModel model;
protected ListAdapter ad;
protected View view;
protected TextView title;
private boolean isLayout2 = false;
protected static String TAG = ItemRuner.class.getSimpleName();
protected MaterialDivider divar;

public ItemRuner(Context context) {
this.context = context;
var view = LayoutInflater.from(context).inflate(R.layout.layout_sheet_main, null);
view = LayoutInflater.from(context).inflate(R.layout.layout_sheet_main, null);
title = view.findViewById(R.id.title);
listview = view.findViewById(R.id.listdata);
divar = view.findViewById(R.id.diver);
listview.setItemAnimator(new CustomItemAnimator(context));
dialog = new BottomSheetDialog(context);
dialog.setContentView(view);

}

public void setCancelable(boolean boll) {
Expand Down Expand Up @@ -69,13 +74,14 @@ public void addItem(String name) {

public void removed(int pos) {
if (pos >= 0 && pos < list.size()) {
list.remove(pos);
Log.e("Item : " , String.valueOf(pos));
list.remove(pos);
Log.e("Item : ", String.valueOf(pos));
} else {
Log.e(TAG, "Invalid position: " + pos);
throw new IndexOutOfBoundsException("Invalid position: " + pos);
Log.e(TAG, "Invalid position: " + pos);
throw new IndexOutOfBoundsException("Invalid position: " + pos);
}
}
}

public void show() {
dialog.show();
}
Expand Down Expand Up @@ -129,4 +135,12 @@ public void DataRefresh(int pos) {
listview.setAdapter(ad);
listview.getAdapter().notifyItemChanged(pos);
}

public void setLayoutChange(boolean is) {
if (ad != null) {
ad.setLayoutChange(is);
listview.setAdapter(ad);
listview.getAdapter().notifyDataSetChanged();
}
}
}
28 changes: 28 additions & 0 deletions library/src/main/res/layout/layout_adapter2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal"
android:id="@+id/root">

<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="16sp"
android:layout_marginRight="4dp"
android:textColor="#ffffffff"
android:layout_weight="1"
android:id="@+id/name"
android:text="TextView" />

<ImageView
android:layout_height="60dp"
android:layout_width="60dp"
android:scaleType="centerInside"
android:id="@+id/icon" />

</LinearLayout>
2 changes: 1 addition & 1 deletion library/src/main/res/layout/layout_sheet_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal|center_horizontal"
android:padding="8dp"
android:textSize="18sp"
android:textColor="#ffffff"
Expand All @@ -50,7 +51,6 @@
android:id="@+id/listdata"
/>


</LinearLayout>

</LinearLayout>

0 comments on commit 1c4bdc8

Please sign in to comment.