Skip to content

Commit bfb3671

Browse files
Add files via upload
1 parent a53254f commit bfb3671

File tree

2 files changed

+310
-0
lines changed

2 files changed

+310
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Dex-Editor-Android an Advanced Dex Editor for Android
3+
* Copyright 2024-25, developer-krushna
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above
12+
* copyright notice, this list of conditions and the following disclaimer
13+
* in the documentation and/or other materials provided with the
14+
* distribution.
15+
* * Neither the name of developer-krushna nor the names of its
16+
* contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
32+
* Please contact Krushna by email [email protected] if you need
33+
* additional information or have any questions
34+
*/
35+
36+
package modder.hub.dexeditor.updateSoraMenu;
37+
38+
39+
import androidx.annotation.NonNull;
40+
import androidx.recyclerview.widget.ItemTouchHelper;
41+
import androidx.recyclerview.widget.RecyclerView;
42+
43+
/*
44+
Author @developer-krushna
45+
Thanks to GeeksForGeeks.com
46+
*/
47+
48+
public class ItemMoveCallback extends ItemTouchHelper.Callback {
49+
50+
private final ItemTouchHelperContract mAdapter;
51+
52+
public ItemMoveCallback(ItemTouchHelperContract adapter) {
53+
mAdapter = adapter;
54+
}
55+
56+
@Override
57+
public boolean isLongPressDragEnabled() {
58+
return false;
59+
}
60+
61+
@Override
62+
public boolean isItemViewSwipeEnabled() {
63+
return false;
64+
}
65+
66+
@Override
67+
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
68+
69+
}
70+
71+
@Override
72+
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
73+
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
74+
return makeMovementFlags(dragFlags, 0);
75+
}
76+
77+
@Override
78+
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
79+
RecyclerView.ViewHolder target) {
80+
mAdapter.onRowMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition());
81+
return true;
82+
}
83+
84+
@Override
85+
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder,
86+
int actionState) {
87+
88+
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
89+
if (viewHolder instanceof RecyclerViewAdapter.MyViewHolder) {
90+
RecyclerViewAdapter.MyViewHolder myViewHolder =
91+
(RecyclerViewAdapter.MyViewHolder) viewHolder;
92+
mAdapter.onRowSelected(myViewHolder);
93+
}
94+
}
95+
96+
super.onSelectedChanged(viewHolder, actionState);
97+
}
98+
99+
@Override
100+
public void clearView(RecyclerView recyclerView,
101+
RecyclerView.ViewHolder viewHolder) {
102+
super.clearView(recyclerView, viewHolder);
103+
104+
if (viewHolder instanceof RecyclerViewAdapter.MyViewHolder) {
105+
RecyclerViewAdapter.MyViewHolder myViewHolder =
106+
(RecyclerViewAdapter.MyViewHolder) viewHolder;
107+
mAdapter.onRowClear(myViewHolder);
108+
}
109+
}
110+
111+
public interface ItemTouchHelperContract {
112+
113+
void onRowMoved(int fromPosition, int toPosition);
114+
115+
void onRowSelected(RecyclerViewAdapter.MyViewHolder myViewHolder);
116+
117+
void onRowClear(RecyclerViewAdapter.MyViewHolder myViewHolder);
118+
}
119+
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/*
2+
* Dex-Editor-Android an Advanced Dex Editor for Android
3+
* Copyright 2024-25, developer-krushna
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above
12+
* copyright notice, this list of conditions and the following disclaimer
13+
* in the documentation and/or other materials provided with the
14+
* distribution.
15+
* * Neither the name of developer-krushna nor the names of its
16+
* contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
32+
* Please contact Krushna by email [email protected] if you need
33+
* additional information or have any questions
34+
*/
35+
36+
37+
package modder.hub.dexeditor.updateSoraMenu;
38+
39+
import android.content.Context;
40+
import android.content.SharedPreferences;
41+
import android.graphics.Color;
42+
import android.view.LayoutInflater;
43+
import android.view.MotionEvent;
44+
import android.view.View;
45+
import android.view.ViewGroup;
46+
import android.widget.CompoundButton;
47+
import android.widget.ImageView;
48+
import android.widget.RelativeLayout;
49+
import android.widget.Switch;
50+
import android.widget.TextView;
51+
52+
import androidx.recyclerview.widget.RecyclerView;
53+
54+
import com.google.gson.Gson;
55+
56+
import java.util.ArrayList;
57+
import java.util.Collections;
58+
import java.util.HashMap;
59+
import java.util.Map;
60+
61+
import modder.hub.dexeditor.R;
62+
63+
/*
64+
Author @developer-krushna
65+
Thanks to GeeksForGeeks.com
66+
*/
67+
68+
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> implements ItemMoveCallback.ItemTouchHelperContract {
69+
70+
private ArrayList<HashMap<String, Object>> data;
71+
private final StartDragListener mStartDragListener;
72+
private Context context;
73+
private SharedPreferences prefs;
74+
75+
private final Map<String, Integer> buttonIcons = new HashMap<String, Integer>() {{
76+
put("panel_btn_select_all", R.drawable.ic_selectall_mt);
77+
put("panel_btn_copy", R.drawable.ic_copy_mt);
78+
put("panel_btn_paste", R.drawable.ic_paste_mt);
79+
put("goto_btn", R.drawable.ic_goto_mt);
80+
put("translate_btn", R.drawable.ic_translate_mt);
81+
put("panel_btn_cut", R.drawable.ic_cut_mt);
82+
put("comment_btn", R.drawable.ic_hash_mt);
83+
put("openLink_btn", R.drawable.ic_link_mt);
84+
put("share_btn", R.drawable.ic_share_mt);
85+
put("panel_btn_long_select", R.drawable.ic_text_select_start_mt);
86+
put("delete_btn", R.drawable.ic_delete_mt);
87+
put("customize_btn", R.drawable.ic_setting_mt);
88+
}};
89+
90+
public class MyViewHolder extends RecyclerView.ViewHolder {
91+
TextView mTitle;
92+
View rowView;
93+
ImageView imageView;
94+
RelativeLayout relativeLayout;
95+
Switch disableSwitch;
96+
97+
public MyViewHolder(View itemView) {
98+
super(itemView);
99+
rowView = itemView;
100+
mTitle = itemView.findViewById(R.id.txtTitle);
101+
imageView = itemView.findViewById(R.id.imageView);
102+
relativeLayout = itemView.findViewById(R.id.relativeLayout);
103+
disableSwitch = itemView.findViewById(R.id.disableSwitch);
104+
}
105+
}
106+
107+
public RecyclerViewAdapter(ArrayList<HashMap<String, Object>> data, StartDragListener startDragListener, Context context) {
108+
this.data = data;
109+
mStartDragListener = startDragListener;
110+
this.context = context;
111+
prefs = context.getSharedPreferences("editor_prefs", Context.MODE_PRIVATE);
112+
}
113+
114+
@Override
115+
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
116+
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.floating_menu_items, parent, false);
117+
return new MyViewHolder(itemView);
118+
}
119+
120+
@Override
121+
public void onBindViewHolder(final MyViewHolder holder, final int position) {
122+
HashMap<String, Object> item = data.get(position);
123+
String id = (String) item.get("id");
124+
String title = (String) item.get("title");
125+
boolean disabled = item.containsKey("disabled") && (boolean) item.get("disabled");
126+
127+
holder.mTitle.setText(title);
128+
129+
if (buttonIcons.containsKey(id)) {
130+
holder.imageView.setImageResource(buttonIcons.get(id));
131+
}
132+
133+
holder.disableSwitch.setChecked(!disabled);
134+
135+
holder.disableSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
136+
@Override
137+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
138+
item.put("disabled", !isChecked);
139+
updateJson();
140+
}
141+
});
142+
143+
// Drag handling
144+
holder.imageView.setOnTouchListener(new View.OnTouchListener() {
145+
@Override
146+
public boolean onTouch(View v, MotionEvent event) {
147+
if (event.getAction() == MotionEvent.ACTION_DOWN) {
148+
mStartDragListener.requestDrag(holder);
149+
}
150+
return false;
151+
}
152+
});
153+
}
154+
155+
@Override
156+
public int getItemCount() {
157+
return data.size();
158+
}
159+
160+
@Override
161+
public void onRowMoved(int fromPosition, int toPosition) {
162+
if (fromPosition < toPosition) {
163+
for (int i = fromPosition; i < toPosition; i++) {
164+
Collections.swap(data, i, i + 1);
165+
}
166+
} else {
167+
for (int i = fromPosition; i > toPosition; i--) {
168+
Collections.swap(data, i, i - 1);
169+
}
170+
}
171+
notifyItemMoved(fromPosition, toPosition);
172+
updateJson();
173+
}
174+
175+
private void updateJson() {
176+
try {
177+
String jsonContent = new Gson().toJson(data);
178+
prefs.edit().putString("menu_order", jsonContent).apply();
179+
} catch (Exception e) {
180+
e.printStackTrace();
181+
}
182+
}
183+
184+
@Override
185+
public void onRowSelected(MyViewHolder myViewHolder) {
186+
}
187+
188+
@Override
189+
public void onRowClear(MyViewHolder myViewHolder) {
190+
}
191+
}

0 commit comments

Comments
 (0)