Skip to content

Commit

Permalink
Merge pull request Sketchware-Pro#1293 from elfilibusterismo/logic-pa…
Browse files Browse the repository at this point in the history
…lette
  • Loading branch information
ilyassesalama authored Oct 16, 2024
2 parents ab94480 + a6efc3f commit 7d0d4b8
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 183 deletions.
158 changes: 43 additions & 115 deletions app/src/main/java/a/a/a/rs.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.content.Context;
import android.content.Intent;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.os.Bundle;
import android.text.InputType;
import android.util.Pair;
Expand All @@ -12,8 +10,6 @@
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
Expand All @@ -23,11 +19,8 @@
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.core.view.ViewCompat;
import androidx.core.view.ViewPropertyAnimatorCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import com.besome.sketch.beans.BlockBean;
import com.besome.sketch.beans.ComponentBean;
Expand All @@ -43,6 +36,7 @@
import com.google.android.material.button.MaterialButton;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigationrail.NavigationRailView;
import com.sketchware.remod.R;

import java.util.ArrayList;
Expand All @@ -57,7 +51,7 @@
public class rs extends qA implements View.OnClickListener, MoreblockImporterDialog.CallBack {

private ProjectFileBean currentActivity;
private CategoryAdapter categoryAdapter;
private NavigationRailView paletteView;
private EventAdapter eventAdapter;
private FloatingActionButton fab;
private HashMap<Integer, ArrayList<EventBean>> events;
Expand Down Expand Up @@ -97,14 +91,29 @@ public static String a(Context context, int i) {
default -> "";
};
}

private int getPaletteIndex(int id) {
return switch (id) {
case R.id.activity -> 0;
case R.id.view -> 1;
case R.id.component -> 2;
case R.id.drawer -> 3;
case R.id.moreblock -> 4;
default -> -1;
};
}

private int getPaletteIndex() {
return getPaletteIndex(paletteView.getSelectedItemId());
}

@Override
public void onClick(View v) {
if (!mB.a() && v.getId() == R.id.fab) {
Intent intent = new Intent(requireActivity().getApplicationContext(), AddEventActivity.class);
intent.putExtra("sc_id", sc_id);
intent.putExtra("project_file", currentActivity);
intent.putExtra("category_index", categoryAdapter.index);
intent.putExtra("category_index", getPaletteIndex());
addEventLauncher.launch(intent);
}
}
Expand Down Expand Up @@ -169,21 +178,17 @@ public void refreshEvents() {
drawerViewEvents.add(eventBean);
}
}
if (categoryAdapter.index == -1) {
if (getPaletteIndex() == -1) {
eventAdapter.a(events.get(0));
categoryAdapter.index = 0;
categoryAdapter.notifyDataSetChanged();
paletteView.setSelectedItemId(R.id.activity);
}
if (categoryAdapter.index == 4) {
if (getPaletteIndex() == 4) {
importMoreBlockFromCollection.setVisibility(View.VISIBLE);
} else {
importMoreBlockFromCollection.setVisibility(View.GONE);
}
if (eventAdapter != null) {
if (categoryAdapter != null) {
categoryAdapter.notifyDataSetChanged();
}
eventAdapter.a(events.get(categoryAdapter.index));
eventAdapter.a(events.get(getPaletteIndex()));
eventAdapter.notifyDataSetChanged();
}
}
Expand All @@ -195,7 +200,7 @@ private void deleteMoreBlock(EventBean moreBlock, int position) {
} else {
jC.a(sc_id).n(currentActivity.getJavaName(), moreBlock.targetId);
bB.a(requireContext(), xB.b().a(requireContext(), R.string.common_message_complete_delete), 0).show();
events.get(categoryAdapter.index).remove(position);
events.get(getPaletteIndex()).remove(position);
eventAdapter.notifyItemRemoved(position);
eventAdapter.notifyItemRangeChanged(position, eventAdapter.getItemCount());
}
Expand All @@ -215,15 +220,23 @@ public void c() {
private void initialize(ViewGroup parent) {
noEvents = parent.findViewById(R.id.tv_no_events);
RecyclerView eventList = parent.findViewById(R.id.event_list);
RecyclerView categoryList = parent.findViewById(R.id.category_list);
fab = parent.findViewById(R.id.fab);
paletteView = parent.findViewById(R.id.palette);
paletteView.setOnItemSelectedListener(
item -> {
initializeEvents(events.get(getPaletteIndex(item.getItemId())));
if (getPaletteIndex(item.getItemId()) == 4) {
importMoreBlockFromCollection.setVisibility(View.VISIBLE);
} else {
importMoreBlockFromCollection.setVisibility(View.GONE);
}
eventAdapter.a(events.get(getPaletteIndex(item.getItemId())));
eventAdapter.notifyDataSetChanged();
return true;
});
fab = paletteView.getHeaderView().findViewById(R.id.fab);
noEvents.setVisibility(View.GONE);
noEvents.setText(xB.b().a(requireContext(), R.string.event_message_no_events));
eventList.setLayoutManager(new LinearLayoutManager(null, RecyclerView.VERTICAL, false));
categoryList.setLayoutManager(new LinearLayoutManager(null, RecyclerView.VERTICAL, false));
((SimpleItemAnimator) categoryList.getItemAnimator()).setSupportsChangeAnimations(false);
categoryAdapter = new CategoryAdapter();
categoryList.setAdapter(categoryAdapter);
eventAdapter = new EventAdapter();
eventList.setAdapter(eventAdapter);
fab.setOnClickListener(this);
Expand Down Expand Up @@ -290,7 +303,7 @@ private void showImportMoreBlockFromCollectionsDialog() {
private void deleteEvent(EventBean event, int position) {
EventBean.deleteEvent(sc_id, event, currentActivity);
bB.a(requireContext(), xB.b().a(requireContext(), R.string.common_message_complete_delete), 0).show();
events.get(categoryAdapter.index).remove(position);
events.get(getPaletteIndex()).remove(position);
eventAdapter.notifyItemRemoved(position);
eventAdapter.notifyItemRangeChanged(position, eventAdapter.getItemCount());
}
Expand Down Expand Up @@ -362,91 +375,6 @@ private void saveMoreBlockToCollection(String moreBlockName, EventBean moreBlock
}
}

private class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.ViewHolder> {
private int index = -1;

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.name.setText(rs.a(requireContext(), position));
holder.icon.setImageResource(rs.a(position));
if (index == position) {
ViewPropertyAnimatorCompat animator1 = ViewCompat.animate(holder.icon);
animator1.scaleX(1);
animator1.scaleY(1);
animator1.setDuration(300);
animator1.setInterpolator(new AccelerateInterpolator());
animator1.start();
ViewPropertyAnimatorCompat animator2 = ViewCompat.animate(holder.icon);
animator2.scaleX(1);
animator2.scaleY(1);
animator2.setDuration(300);
animator2.setInterpolator(new AccelerateInterpolator());
animator2.start();
holder.pointerLeft.setVisibility(View.VISIBLE);
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(1);
holder.icon.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
} else {
ViewPropertyAnimatorCompat animator1 = ViewCompat.animate(holder.icon);
animator1.scaleX(0.8f);
animator1.scaleY(0.8f);
animator1.setDuration(300);
animator1.setInterpolator(new DecelerateInterpolator());
animator1.start();
ViewPropertyAnimatorCompat animator2 = ViewCompat.animate(holder.icon);
animator2.scaleX(0.8f);
animator2.scaleY(0.8f);
animator2.setDuration(300);
animator2.setInterpolator(new DecelerateInterpolator());
animator2.start();
holder.pointerLeft.setVisibility(View.GONE);
ColorMatrix colorMatrix2 = new ColorMatrix();
colorMatrix2.setSaturation(0);
holder.icon.setColorFilter(new ColorMatrixColorFilter(colorMatrix2));
}
}

@Override
@NonNull
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.common_category_triangle_item, parent, false));
}

@Override
public int getItemCount() {
return events.size();
}

private class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public final ImageView icon;
public final TextView name;
public final View pointerLeft;

public ViewHolder(View itemView) {
super(itemView);
icon = itemView.findViewById(R.id.img_icon);
name = itemView.findViewById(R.id.tv_name);
pointerLeft = itemView.findViewById(R.id.pointer_left);
itemView.setOnClickListener(this);
}

@Override
public void onClick(View v) {
notifyItemChanged(index);
index = getLayoutPosition();
notifyItemChanged(index);
initializeEvents(events.get(index));
if (index == 4) {
importMoreBlockFromCollection.setVisibility(View.VISIBLE);
} else {
importMoreBlockFromCollection.setVisibility(View.GONE);
}
eventAdapter.a(events.get(index));
eventAdapter.notifyDataSetChanged();
}
}
}

private class EventAdapter extends RecyclerView.Adapter<EventAdapter.ViewHolder> {
private ArrayList<EventBean> currentCategoryEvents = new ArrayList<>();

Expand Down Expand Up @@ -574,7 +502,7 @@ public ViewHolder(View itemView) {
optionsLayout = itemView.findViewById(R.id.event_option);
optionsLayout.setButtonOnClickListener(v -> {
if (!mB.a()) {
EventBean eventBean = (events.get(categoryAdapter.index)).get(getLayoutPosition());
EventBean eventBean = (events.get(getPaletteIndex())).get(getLayoutPosition());
if (v instanceof CollapsibleButton button) {
setAnimateNextTransformation(true);
int id = button.getButtonId();
Expand Down Expand Up @@ -603,7 +531,7 @@ public ViewHolder(View itemView) {
notifyItemChanged(getLayoutPosition());
} else if (eventBean.buttonPressed == 1) {
eventBean.isConfirmation = false;
if (categoryAdapter.index != 4) {
if (getPaletteIndex() != 4) {
deleteEvent(eventBean, getLayoutPosition());
} else {
deleteMoreBlock(eventBean, getLayoutPosition());
Expand All @@ -617,20 +545,20 @@ public ViewHolder(View itemView) {
onDoneInitializingViews();
root.setOnClickListener(v -> {
if (!mB.a()) {
EventBean eventBean = events.get(categoryAdapter.index).get(getLayoutPosition());
EventBean eventBean = events.get(getPaletteIndex()).get(getLayoutPosition());
openEvent(eventBean.targetId, eventBean.eventName, description.getText().toString());
}
});
}

@Override
protected boolean isCollapsed() {
return events.get(categoryAdapter.index).get(getLayoutPosition()).isCollapsed;
return events.get(getPaletteIndex()).get(getLayoutPosition()).isCollapsed;
}

@Override
protected void setIsCollapsed(boolean isCollapsed) {
events.get(categoryAdapter.index).get(getLayoutPosition()).isCollapsed = isCollapsed;
events.get(getPaletteIndex()).get(getLayoutPosition()).isCollapsed = isCollapsed;
}

@NonNull
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_component.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M200,880Q167,880 143.5,856.5Q120,833 120,800L120,349Q102,338 91,320.5Q80,303 80,280L80,160Q80,127 103.5,103.5Q127,80 160,80L800,80Q833,80 856.5,103.5Q880,127 880,160L880,280Q880,303 869,320.5Q858,338 840,349L840,800Q840,833 816.5,856.5Q793,880 760,880L200,880ZM200,360L200,800Q200,800 200,800Q200,800 200,800L760,800Q760,800 760,800Q760,800 760,800L760,360L200,360ZM160,280L800,280Q800,280 800,280Q800,280 800,280L800,160Q800,160 800,160Q800,160 800,160L160,160Q160,160 160,160Q160,160 160,160L160,280Q160,280 160,280Q160,280 160,280ZM360,560L600,560L600,480L360,480L360,560ZM480,580L480,580L480,580Q480,580 480,580Q480,580 480,580L480,580Q480,580 480,580Q480,580 480,580Z"/>
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_drawer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840ZM480,760L760,760Q760,760 760,760Q760,760 760,760L760,200Q760,200 760,200Q760,200 760,200L480,200L480,760Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_lifecycle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M368,368L457,221L398,123Q386,103 363.5,103Q341,103 329,123L231,286L368,368ZM755,640L666,492L805,412L869,519Q880,536 881,557Q882,578 872,596Q862,616 842.5,628Q823,640 800,640L755,640ZM640,920L480,760L640,600L640,680L830,680L772,796Q761,816 742,828Q723,840 700,840L640,840L640,920ZM253,840Q233,840 216.5,829.5Q200,819 192,802Q184,786 184.5,768.5Q185,751 194,736L228,680L400,680L400,840L253,840ZM154,726L89,596Q80,578 80.5,557.5Q81,537 92,519L108,492L40,451L259,396L314,616L245,574L154,726ZM694,384L475,329L544,288L419,80L560,80Q581,80 599.5,90.5Q618,101 629,119L681,206L749,164L694,384Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M80,600L80,360Q80,327 103.5,303.5Q127,280 160,280Q193,280 216.5,303.5Q240,327 240,360L240,600Q240,633 216.5,656.5Q193,680 160,680Q127,680 103.5,656.5Q80,633 80,600ZM360,760Q327,760 303.5,736.5Q280,713 280,680L280,280Q280,247 303.5,223.5Q327,200 360,200L600,200Q633,200 656.5,223.5Q680,247 680,280L680,680Q680,713 656.5,736.5Q633,760 600,760L360,760ZM720,600L720,360Q720,327 743.5,303.5Q767,280 800,280Q833,280 856.5,303.5Q880,327 880,360L880,600Q880,633 856.5,656.5Q833,680 800,680Q767,680 743.5,656.5Q720,633 720,600ZM360,680L600,680Q600,680 600,680Q600,680 600,680L600,280Q600,280 600,280Q600,280 600,280L360,280Q360,280 360,280Q360,280 360,280L360,680Q360,680 360,680Q360,680 360,680ZM480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/layout/fab.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.floatingactionbutton.FloatingActionButton
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:id="@+id/fab"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:srcCompat="@drawable/ic_add_white_36dp"
tools:ignore="ContentDescription" />
Loading

0 comments on commit 7d0d4b8

Please sign in to comment.