diff --git a/app/src/main/java/a/a/a/Zt.java b/app/src/main/java/a/a/a/Zt.java index ffa018d1a8..98ed987654 100644 --- a/app/src/main/java/a/a/a/Zt.java +++ b/app/src/main/java/a/a/a/Zt.java @@ -104,6 +104,10 @@ public void setSelectingMode(boolean state) { actBinding.layoutBtnGroup.animate().translationY(isSelecting ? 0F : 400F).setDuration(200L).start(); actBinding.layoutBtnGroup.setVisibility(isSelecting ? View.VISIBLE : View.GONE); + if (!isSelecting) { + projectResourceBeans.forEach(bean -> bean.isSelected = false); + } + adapter.notifyDataSetChanged(); } @@ -127,7 +131,7 @@ public ArrayList getProjectResourceBeans() { } public void processResources() { - if (projectResourceBeans == null || projectResourceBeans.isEmpty()) { + if (projectResourceBeans == null) { return; } diff --git a/app/src/main/java/com/besome/sketch/editor/manage/ManageCollectionActivity.java b/app/src/main/java/com/besome/sketch/editor/manage/ManageCollectionActivity.java index c453d87b80..6e7533ce56 100644 --- a/app/src/main/java/com/besome/sketch/editor/manage/ManageCollectionActivity.java +++ b/app/src/main/java/com/besome/sketch/editor/manage/ManageCollectionActivity.java @@ -1,10 +1,7 @@ package com.besome.sketch.editor.manage; -import android.content.Context; import android.content.Intent; import android.content.res.Configuration; -import android.graphics.ColorMatrix; -import android.graphics.ColorMatrixColorFilter; import android.graphics.Typeface; import android.os.Bundle; import android.view.LayoutInflater; @@ -12,8 +9,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.view.animation.AccelerateInterpolator; -import android.view.animation.DecelerateInterpolator; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; @@ -23,12 +18,9 @@ import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; -import androidx.core.view.ViewCompat; -import androidx.core.view.ViewPropertyAnimatorCompat; import androidx.recyclerview.widget.GridLayoutManager; 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.BlockCollectionBean; @@ -47,12 +39,13 @@ import com.google.android.material.button.MaterialButton; import com.google.android.material.card.MaterialCardView; import com.google.android.material.floatingactionbutton.FloatingActionButton; -import pro.sketchware.R; +import com.google.android.material.navigationrail.NavigationRailView; import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Objects; import a.a.a.Mp; import a.a.a.Np; @@ -67,6 +60,7 @@ import mod.jbk.util.AudioMetadata; import mod.jbk.util.BlockUtil; import mod.jbk.util.SoundPlayingAdapter; +import pro.sketchware.R; public class ManageCollectionActivity extends BaseAppCompatActivity implements View.OnClickListener { private static final int REQUEST_CODE_ADD_IMAGE_DIALOG = 267; @@ -82,41 +76,21 @@ public class ManageCollectionActivity extends BaseAppCompatActivity implements V private LinearLayout actionButtonGroup; private boolean hasDeletedWidget; private boolean selectingToBeDeletedItems; - private CategoryAdapter categoryAdapter; private CollectionAdapter collectionAdapter; private RecyclerView collection; + private NavigationRailView categories; private ArrayList images; private ArrayList sounds; private ArrayList fonts; private ArrayList widgets; private ArrayList blocks; private ArrayList moreBlocks; + private int currentItemId = 1; + private int collectionItemsSize = 6; private TextView noItemsNote; private FloatingActionButton fab; private String sc_id; - private static String getCategoryLabel(Context context, int position) { - return Helper.getResString(switch (position) { - case 0 -> R.string.common_word_image; - case 1 -> R.string.common_word_sound; - case 2 -> R.string.common_word_font; - case 3 -> R.string.common_word_widget; - case 4 -> R.string.common_word_block; - default -> R.string.common_word_moreblock; - }); - } - - private static int getCategoryIcon(int position) { - return switch (position) { - case 0 -> R.drawable.ic_picture_48dp; - case 1 -> R.drawable.ic_sound_wave_48dp; - case 2 -> R.drawable.ic_font_48dp; - case 3 -> R.drawable.collage_96; - case 4 -> R.drawable.block_96_blue; - default -> R.drawable.more_block_96dp; - }; - } - private void showAddImageDialog() { Intent intent = new Intent(getApplicationContext(), AddImageCollectionActivity.class); intent.putParcelableArrayListExtra("images", images); @@ -161,7 +135,7 @@ private void changeDeletingItemsState(boolean deletingItems) { actionButtonGroup.setVisibility(View.VISIBLE); } else { actionButtonGroup.setVisibility(View.GONE); - if (categoryAdapter.currentItemId == 3 || categoryAdapter.currentItemId == 4) { + if (currentItemId == 3 || currentItemId == 4) { fab.setVisibility(View.GONE); } } @@ -172,7 +146,7 @@ private void changeDeletingItemsState(boolean deletingItems) { private void handleFabOnClick(int categoryId) { if (categoryId == 0) { showAddImageDialog(); - } else if (categoryId == 1) { + }else if (categoryId == 1) { showAddSoundDialog(); } else { showAddFontDialog(); @@ -228,8 +202,60 @@ private void openMoreBlockDetails(int position) { startActivityForResult(intent, REQUEST_CODE_SHOW_MORE_BLOCK_DETAILS); } + private int getSelectedIndex(int id) { + if (id == R.id.image) { + return 0; + } else if (id == R.id.audio) { + return 1; + } else if (id == R.id.font) { + return 2; + } else if (id == R.id.widget) { + return 3; + } else if (id == R.id.block) { + return 4; + } else if (id == R.id.moreblock) { + return 5; + } + return -1; + } + + private void setSelectedIndex(int item) { + if (!mB.a()) { + if (item != -1 && item != currentItemId) { + if (currentItemId == 1) { + collectionAdapter.stopPlayback(); + } + currentItemId = item; + collection.removeAllViews(); + collectionAdapter.currentViewType = currentItemId; + collectionAdapter.setData(switch (currentItemId) { + case 0 -> images; + case 1 -> sounds; + case 2 -> fonts; + case 3 -> widgets; + case 4 -> blocks; + default -> moreBlocks; + }); + + if (collectionAdapter.currentViewType == 0) { + collection.setLayoutManager(new GridLayoutManager(getApplicationContext(), getGridLayoutColumnCount())); + fab.show(); + } else { + collection.setLayoutManager(new LinearLayoutManager(getApplicationContext(), RecyclerView.VERTICAL, false)); + if (collectionAdapter.currentViewType != 1 && collectionAdapter.currentViewType != 2) { + fab.hide(); + } else { + fab.show(); + } + } + + collectionAdapter.notifyDataSetChanged(); + } + } + } + private void deleteSelectedToBeDeletedItems() { - for (int i = 0; i < categoryAdapter.getItemCount(); i++) { + for (int i = 0; i < collectionItemsSize; i++) { switch (i) { case 0 -> { for (ProjectResourceBean bean : images) { @@ -304,7 +330,7 @@ private void deleteSelectedToBeDeletedItems() { } private int getCurrentCategoryItemId() { - return categoryAdapter.currentItemId; + return currentItemId; } private int getGridLayoutColumnCount() { @@ -321,7 +347,7 @@ private void initialize() { Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); findViewById(R.id.layout_main_logo).setVisibility(View.GONE); - getSupportActionBar().setTitle(Helper.getResString(R.string.design_actionbar_title_manager_collection)); + Objects.requireNonNull(getSupportActionBar()).setTitle(Helper.getResString(R.string.design_actionbar_title_manager_collection)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(true); toolbar.setNavigationOnClickListener(v -> { @@ -332,11 +358,7 @@ private void initialize() { noItemsNote = findViewById(R.id.tv_no_collections); noItemsNote.setText(Helper.getResString(R.string.event_message_no_events)); - RecyclerView categories = findViewById(R.id.category_list); - categories.setLayoutManager(new LinearLayoutManager(getApplicationContext(), RecyclerView.VERTICAL, false)); - ((SimpleItemAnimator) categories.getItemAnimator()).setSupportsChangeAnimations(false); - categoryAdapter = new CategoryAdapter(); - categories.setAdapter(categoryAdapter); + categories = findViewById(R.id.category_list); collection = findViewById(R.id.collection_list); collectionAdapter = new CollectionAdapter(collection); collection.setAdapter(collectionAdapter); @@ -350,6 +372,12 @@ private void initialize() { cancel.setText(Helper.getResString(R.string.common_word_cancel)); delete.setOnClickListener(this); cancel.setOnClickListener(this); + + + categories.setOnItemSelectedListener(item -> { + setSelectedIndex(getSelectedIndex(item.getItemId())); + return true; + }); } @Override @@ -386,11 +414,11 @@ public void onClick(View v) { if (id == R.id.btn_cancel && selectingToBeDeletedItems) { changeDeletingItemsState(false); - } else if (id == R.id.btn_delete && selectingToBeDeletedItems) { + }else if (id == R.id.btn_delete && selectingToBeDeletedItems) { deleteSelectedToBeDeletedItems(); - } else if (id == R.id.fab) { + }else if (id == R.id.fab) { changeDeletingItemsState(false); - handleFabOnClick(categoryAdapter.currentItemId); + handleFabOnClick(currentItemId); } } @@ -398,7 +426,7 @@ public void onClick(View v) { public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); if (collectionAdapter.currentViewType == 0) { - ((GridLayoutManager) collection.getLayoutManager()).setSpanCount(getGridLayoutColumnCount()); + ((GridLayoutManager) Objects.requireNonNull(collection.getLayoutManager())).setSpanCount(getGridLayoutColumnCount()); collection.requestLayout(); } } @@ -441,6 +469,7 @@ public void onPostCreate(Bundle savedInstanceState) { } loadAllCollectionItems(); + categories.setSelectedItemId(R.id.image); } @Override @@ -469,12 +498,11 @@ private void loadAllCollectionItems() { blocks = Mp.h().f(); moreBlocks = Pp.h().f(); - if (categoryAdapter.currentItemId == -1) { + if (currentItemId == -1) { collectionAdapter.currentViewType = 0; collectionAdapter.setData(images); collection.setLayoutManager(new GridLayoutManager(getApplicationContext(), getGridLayoutColumnCount())); - categoryAdapter.currentItemId = 0; - categoryAdapter.notifyDataSetChanged(); + currentItemId = 0; } if (collectionAdapter != null) { @@ -484,7 +512,7 @@ private void loadAllCollectionItems() { private void loadImages() { images = Op.g().f(); - if (categoryAdapter.currentItemId == 0) { + if (currentItemId == 0) { collectionAdapter.setData(images); collectionAdapter.currentViewType = 0; } @@ -494,7 +522,7 @@ private void loadImages() { private void loadSounds() { sounds = Qp.g().f(); - if (categoryAdapter.currentItemId == 1) { + if (currentItemId == 1) { collectionAdapter.setData(sounds); collectionAdapter.currentViewType = 1; } @@ -504,7 +532,7 @@ private void loadSounds() { private void loadFonts() { fonts = Np.g().f(); - if (categoryAdapter.currentItemId == 2) { + if (currentItemId == 2) { collectionAdapter.setData(fonts); collectionAdapter.currentViewType = 2; } @@ -514,7 +542,7 @@ private void loadFonts() { private void loadWidgets() { widgets = Rp.h().f(); - if (categoryAdapter.currentItemId == 3) { + if (currentItemId == 3) { collectionAdapter.setData(widgets); collectionAdapter.currentViewType = 3; } @@ -524,7 +552,7 @@ private void loadWidgets() { private void loadBlocks() { blocks = Mp.h().f(); - if (categoryAdapter.currentItemId == 4) { + if (currentItemId == 4) { collectionAdapter.setData(blocks); collectionAdapter.currentViewType = 4; } @@ -534,7 +562,7 @@ private void loadBlocks() { private void loadMoreBlocks() { moreBlocks = Pp.h().f(); - if (categoryAdapter.currentItemId == 5) { + if (currentItemId == 5) { collectionAdapter.setData(moreBlocks); collectionAdapter.currentViewType = 5; } @@ -578,124 +606,6 @@ private void unselectToBeDeletedItems() { } } - private class CategoryAdapter extends RecyclerView.Adapter { - private int currentItemId; - - public CategoryAdapter() { - currentItemId = -1; - } - - @Override - public int getItemCount() { - return 6; - } - - @Override - public void onBindViewHolder(@NonNull CategoryAdapter.ViewHolder holder, int position) { - holder.name.setText(ManageCollectionActivity.getCategoryLabel(getApplicationContext(), position)); - holder.icon.setImageResource(ManageCollectionActivity.getCategoryIcon(position)); - ViewPropertyAnimatorCompat var3; - ColorMatrix var4; - ColorMatrixColorFilter var5; - if (currentItemId == position) { - var3 = ViewCompat.animate(holder.icon); - var3.scaleX(1.0F); - var3.scaleY(1.0F); - var3.setDuration(300L); - var3.setInterpolator(new AccelerateInterpolator()); - var3.start(); - var3 = ViewCompat.animate(holder.icon); - var3.scaleX(1.0F); - var3.scaleY(1.0F); - var3.setDuration(300L); - var3.setInterpolator(new AccelerateInterpolator()); - var3.start(); - holder.pointerLeft.setVisibility(View.VISIBLE); - var4 = new ColorMatrix(); - var4.setSaturation(1.0F); - var5 = new ColorMatrixColorFilter(var4); - holder.icon.setColorFilter(var5); - } else { - var3 = ViewCompat.animate(holder.icon); - var3.scaleX(0.8F); - var3.scaleY(0.8F); - var3.setDuration(300L); - var3.setInterpolator(new DecelerateInterpolator()); - var3.start(); - var3 = ViewCompat.animate(holder.icon); - var3.scaleX(0.8F); - var3.scaleY(0.8F); - var3.setDuration(300L); - var3.setInterpolator(new DecelerateInterpolator()); - var3.start(); - holder.pointerLeft.setVisibility(View.GONE); - var4 = new ColorMatrix(); - var4.setSaturation(0.0F); - var5 = new ColorMatrixColorFilter(var4); - holder.icon.setColorFilter(var5); - } - } - - @Override - @NonNull - public CategoryAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.common_category_triangle_item, parent, false)); - } - - 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) { - if (!mB.a()) { - int layoutPosition = getLayoutPosition(); - if (layoutPosition != -1 && layoutPosition != currentItemId) { - if (currentItemId == 1) { - collectionAdapter.stopPlayback(); - } - - notifyItemChanged(currentItemId); - currentItemId = layoutPosition; - notifyItemChanged(currentItemId); - collection.removeAllViews(); - collectionAdapter.currentViewType = currentItemId; - collectionAdapter.setData(switch (currentItemId) { - case 0 -> images; - case 1 -> sounds; - case 2 -> fonts; - case 3 -> widgets; - case 4 -> blocks; - default -> moreBlocks; - }); - - if (collectionAdapter.currentViewType == 0) { - collection.setLayoutManager(new GridLayoutManager(getApplicationContext(), getGridLayoutColumnCount())); - fab.show(); - } else { - collection.setLayoutManager(new LinearLayoutManager(getApplicationContext(), RecyclerView.VERTICAL, false)); - if (collectionAdapter.currentViewType != 1 && collectionAdapter.currentViewType != 2) { - fab.hide(); - } else { - fab.show(); - } - } - - collectionAdapter.notifyDataSetChanged(); - } - } - } - } - } private class CollectionAdapter extends SoundPlayingAdapter { private int lastSelectedItemPosition; @@ -718,7 +628,7 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { return; } fab.hide(); - } else if (dy < -2 && fab.isEnabled()) { + }else if (dy < -2 && fab.isEnabled()) { fab.show(); } } @@ -808,7 +718,7 @@ private void onBindViewHolder(FontCollectionViewHolder holder, int position) { if (bean.isSelected) { holder.delete.setImageResource(R.drawable.ic_checkmark_green_48dp); - } else { + } else { holder.delete.setImageResource(R.drawable.ic_trashcan_white_48dp); } diff --git a/app/src/main/java/com/besome/sketch/editor/manage/library/LibraryItemView.java b/app/src/main/java/com/besome/sketch/editor/manage/library/LibraryItemView.java index ded5554a20..5f7a8d5010 100644 --- a/app/src/main/java/com/besome/sketch/editor/manage/library/LibraryItemView.java +++ b/app/src/main/java/com/besome/sketch/editor/manage/library/LibraryItemView.java @@ -6,9 +6,10 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; +import android.widget.LinearLayout; import com.besome.sketch.beans.ProjectLibraryBean; -import com.google.android.material.card.MaterialCardView; + import pro.sketchware.R; import a.a.a.wB; @@ -16,12 +17,12 @@ public class LibraryItemView extends FrameLayout { protected final Context context; - protected MaterialCardView container; - - public ImageView icon; - public TextView title; - public TextView description; - public TextView enabled; + + public final LinearLayout container; + public final ImageView icon; + public final TextView title; + public final TextView description; + public final TextView enabled; public LibraryItemView(Context context) { super(context); diff --git a/app/src/main/java/com/besome/sketch/editor/manage/library/ManageLibraryActivity.java b/app/src/main/java/com/besome/sketch/editor/manage/library/ManageLibraryActivity.java index b623e615af..70eea1ba8b 100644 --- a/app/src/main/java/com/besome/sketch/editor/manage/library/ManageLibraryActivity.java +++ b/app/src/main/java/com/besome/sketch/editor/manage/library/ManageLibraryActivity.java @@ -62,13 +62,14 @@ public class ManageLibraryActivity extends BaseAppCompatActivity implements View private TextView externalLib; - private void addLibraryItem(@Nullable ProjectLibraryBean libraryBean) { + private void addLibraryItem(@Nullable ProjectLibraryBean libraryBean, int drawable) { LibraryItemView libraryItemView; if (libraryBean != null) { libraryItemView = new LibraryItemView(this); } else { libraryItemView = new ExcludeBuiltInLibrariesLibraryItemView(this, sc_id); } + libraryItemView.container.setBackgroundResource(drawable); libraryItemView.setTag(libraryBean != null ? libraryBean.libType : null); //noinspection ConstantConditions since the variant if it's nullable handles nulls correctly libraryItemView.setData(libraryBean); @@ -327,14 +328,14 @@ public void onPostCreate(Bundle savedInstanceState) { originalGoogleMapUseYn = savedInstanceState.getString("originalGoogleMapUseYn"); } - addLibraryItem(compatLibraryBean); - addLibraryItem(firebaseLibraryBean); - addLibraryItem(admobLibraryBean); - addLibraryItem(googleMapLibraryBean); - addLibraryItem(new ProjectLibraryBean(ProjectLibraryBean.PROJECT_LIB_TYPE_LOCAL_LIB)); - addLibraryItem(new ProjectLibraryBean(ProjectLibraryBean.PROJECT_LIB_TYPE_NATIVE_LIB)); + addLibraryItem(compatLibraryBean, R.drawable.shape_top); + addLibraryItem(firebaseLibraryBean, R.drawable.shape_middle); + addLibraryItem(admobLibraryBean, R.drawable.shape_middle); + addLibraryItem(googleMapLibraryBean, R.drawable.shape_bottom); + addLibraryItem(new ProjectLibraryBean(ProjectLibraryBean.PROJECT_LIB_TYPE_LOCAL_LIB), R.drawable.shape_top); + addLibraryItem(new ProjectLibraryBean(ProjectLibraryBean.PROJECT_LIB_TYPE_NATIVE_LIB), R.drawable.shape_bottom); // Exclude built-in libraries - addLibraryItem(null); + addLibraryItem(null, R.drawable.shape_alone); } @Override diff --git a/app/src/main/java/dev/aldi/sayuti/editor/manage/ManageLocalLibraryActivity.java b/app/src/main/java/dev/aldi/sayuti/editor/manage/ManageLocalLibraryActivity.java index 76522bbfc8..cdbcbbc24f 100644 --- a/app/src/main/java/dev/aldi/sayuti/editor/manage/ManageLocalLibraryActivity.java +++ b/app/src/main/java/dev/aldi/sayuti/editor/manage/ManageLocalLibraryActivity.java @@ -32,11 +32,13 @@ import mod.hey.studios.util.Helper; import mod.jbk.util.AddMarginOnApplyWindowInsetsListener; +import pro.sketchware.R; import pro.sketchware.databinding.ManageLocallibrariesBinding; import pro.sketchware.databinding.ViewItemLocalLibBinding; import pro.sketchware.databinding.ViewItemLocalLibSearchBinding; import pro.sketchware.utility.FileUtil; import pro.sketchware.utility.SketchwareUtil; +import pro.sketchware.utility.UI; import a.a.a.mB; @@ -201,8 +203,7 @@ public class LibraryAdapter extends RecyclerView.Adapter { - Intent intent = new Intent(); - intent.setClass(getApplicationContext(), AndroidManifestInjectionDetails.class); - intent.putExtra("sc_id", sc_id); - intent.putExtra("file_name", activityName); - intent.putExtra("type", "application"); - startActivity(intent); - }); - - { - LibraryItemView permission_card = new LibraryItemView(this); - makeup(permission_card, R.drawable.event_on_signin_complete_48dp, "Permissions", "Add custom Permissions to the app"); - cards.addView(permission_card); - permission_card.setOnClickListener(_view -> { - Intent inta = new Intent(); - inta.setClass(getApplicationContext(), AndroidManifestInjectionDetails.class); - inta.putExtra("sc_id", sc_id); - inta.putExtra("file_name", activityName); - inta.putExtra("type", "permission"); - startActivity(inta); - }); - } - - { - LibraryItemView permission_card = new LibraryItemView(this); - makeup(permission_card, R.drawable.recycling_48, "Launcher Activity", "Change the default Launcher Activity"); - cards.addView(permission_card); - permission_card.setOnClickListener(v -> showLauncherActDialog(AndroidManifestInjector.getLauncherActivity(sc_id))); - } - - LibraryItemView allAct_card = new LibraryItemView(this); - makeup(allAct_card, R.drawable.icons8_all_activities_attrs, "All Activities", "Add attributes for all Activities"); - cards.addView(allAct_card); - allAct_card.setOnClickListener(v -> { - Intent inta = new Intent(); - inta.setClass(getApplicationContext(), AndroidManifestInjectionDetails.class); - inta.putExtra("sc_id", sc_id); - inta.putExtra("file_name", activityName); - inta.putExtra("type", "all"); - startActivity(inta); + List options = new ArrayList<>(); + + options.add(createOption( + "Application", + "Default properties for the app", + R.drawable.icons8_app_attrs, + v -> { + Intent intent = new Intent(); + intent.setClass(getApplicationContext(), AndroidManifestInjectionDetails.class); + intent.putExtra("sc_id", sc_id); + intent.putExtra("file_name", activityName); + intent.putExtra("type", "application"); + startActivity(intent); + } + )); + options.add(createOption( + "Permissions", + "Add custom Permissions to the app", + R.drawable.event_on_signin_complete_48dp, + v -> { + Intent intent = new Intent(); + intent.setClass(getApplicationContext(), AndroidManifestInjectionDetails.class); + intent.putExtra("sc_id", sc_id); + intent.putExtra("file_name", activityName); + intent.putExtra("type", "permission"); + startActivity(intent); + } + )); + options.add(createOption( + "Launcher Activity", + "Change the default Launcher Activity", + R.drawable.recycling_48, + v -> showLauncherActDialog(AndroidManifestInjector.getLauncherActivity(sc_id)) + )); + options.add(createOption( + "All Activities", + "Add attributes for all Activities", + R.drawable.icons8_all_activities_attrs, + v -> { + Intent intent = new Intent(); + intent.setClass(getApplicationContext(), AndroidManifestInjectionDetails.class); + intent.putExtra("sc_id", sc_id); + intent.putExtra("file_name", activityName); + intent.putExtra("type", "all"); + startActivity(intent); + } + )); + options.add(createOption( + "App Components", + "Add extra components", + R.drawable.icons8_app_components, + v -> showAppComponentDialog() + )); + + options.forEach(option -> { + final int index = options.indexOf(option); + option.container.setBackgroundResource(UI.getShapedBackgroundForList(options, index)); + cards.addView(option); }); - - LibraryItemView appCom_card = new LibraryItemView(this); - makeup(appCom_card, R.drawable.icons8_app_components, "App Components", "Add extra components"); - cards.addView(appCom_card); - appCom_card.setOnClickListener(v -> showAppComponentDialog()); - + act_list = new ListView(this); act_list.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); act_list.setDividerHeight(0); content.addView(act_list); } + + private final LibraryItemView createOption(final String title, final String description, final int icon, View.OnClickListener onClick) { + var card = new LibraryItemView(this); + makeup(card, icon, title, description); + card.setOnClickListener(onClick); + return card; + } private void showAppComponentDialog() { Intent intent = new Intent(); diff --git a/app/src/main/java/mod/hilal/saif/activities/tools/AppSettings.java b/app/src/main/java/mod/hilal/saif/activities/tools/AppSettings.java index fb649bf5c1..7baf8b33d4 100644 --- a/app/src/main/java/mod/hilal/saif/activities/tools/AppSettings.java +++ b/app/src/main/java/mod/hilal/saif/activities/tools/AppSettings.java @@ -33,6 +33,8 @@ import dev.aldi.sayuti.editor.manage.ManageLocalLibraryActivity; import java.io.File; +import java.util.ArrayList; +import java.util.List; import kellinwood.security.zipsigner.ZipSigner; @@ -47,11 +49,13 @@ import pro.sketchware.databinding.DialogSelectApkToSignBinding; import pro.sketchware.utility.SketchwareUtil; import pro.sketchware.utility.FileUtil; +import pro.sketchware.utility.UI; public class AppSettings extends BaseAppCompatActivity { private LinearLayout content; private MaterialToolbar topAppBar; + private final List preferences = new ArrayList<>(); @Override public void onCreate(Bundle savedInstanceState) { @@ -64,7 +68,7 @@ public void onCreate(Bundle savedInstanceState) { topAppBar.setTitle("Settings"); topAppBar.setNavigationOnClickListener(view -> onBackPressed()); - setupViews(); + setupPreferences(); } private void openWorkingDirectory() { @@ -126,18 +130,23 @@ private void openWorkingDirectory() { dialog.show(); } - private void setupViews() { - createToolsView(R.drawable.block_96_blue, "Block manager", "Manage your own blocks to use in Logic Editor", content, new ActivityLauncher(new Intent(getApplicationContext(), BlocksManager.class)), false); - createToolsView(R.drawable.pull_down_48, "Block selector menu manager", "Manage your own block selector menus", content, openSettingsActivity(SettingsActivity.BLOCK_SELECTOR_MANAGER_FRAGMENT), false); - createToolsView(R.drawable.collage_48, "Component manager", "Manage your own components", content, new ActivityLauncher(new Intent(getApplicationContext(), ManageCustomComponentActivity.class)), false); - createToolsView(R.drawable.event_on_item_clicked_48dp, "Event manager", "Manage your own events", content, openSettingsActivity(SettingsActivity.EVENTS_MANAGER_FRAGMENT), false); - createToolsView(R.drawable.colored_box_96, "Local library manager", "Manage and download local libraries", content, new ActivityLauncher(new Intent(getApplicationContext(), ManageLocalLibraryActivity.class), new Pair<>("sc_id", "system")), false); - createToolsView(R.drawable.engineering_48, "Mod settings", "Change general mod settings", content, new ActivityLauncher(new Intent(getApplicationContext(), ConfigActivity.class)), false); - createToolsView(R.drawable.ic_mtrl_palette, getString(R.string.settings_appearance), getString(R.string.settings_appearance_description), content, openSettingsActivity(SettingsActivity.SETTINGS_APPEARANCE_FRAGMENT), false); - createToolsView(R.mipmap.ic_type_folder, "Open working directory", "Open Sketchware Pro's directory and edit files in it", content, v -> openWorkingDirectory(), false); - createToolsView(R.drawable.ic_apk_color_96dp, "Sign an APK file with testkey", "Sign an already existing APK file with testkey and signature schemes up to V4", content, v -> signApkFileDialog(), false); - createToolsView(R.drawable.icons8_app_components, getString(R.string.design_drawer_menu_title_logcat_reader), getString(R.string.design_drawer_menu_subtitle_logcat_reader), content, new ActivityLauncher(new Intent(getApplicationContext(), LogReaderActivity.class)), false); - createToolsView(R.drawable.ic_mtrl_settings, getString(R.string.main_drawer_title_system_settings), "Auto-save and vibrations", content, new ActivityLauncher(new Intent(getApplicationContext(), SystemSettingActivity.class)), true); + private void setupPreferences() { + preferences.add(createPreference(R.drawable.block_96_blue, "Block manager", "Manage your own blocks to use in Logic Editor", new ActivityLauncher(new Intent(getApplicationContext(), BlocksManager.class)), false)); + preferences.add(createPreference(R.drawable.pull_down_48, "Block selector menu manager", "Manage your own block selector menus", openSettingsActivity(SettingsActivity.BLOCK_SELECTOR_MANAGER_FRAGMENT), false)); + preferences.add(createPreference(R.drawable.collage_48, "Component manager", "Manage your own components", new ActivityLauncher(new Intent(getApplicationContext(), ManageCustomComponentActivity.class)), false)); + preferences.add(createPreference(R.drawable.event_on_item_clicked_48dp, "Event manager", "Manage your own events", openSettingsActivity(SettingsActivity.EVENTS_MANAGER_FRAGMENT), false)); + preferences.add(createPreference(R.drawable.colored_box_96, "Local library manager", "Manage and download local libraries", new ActivityLauncher(new Intent(getApplicationContext(), ManageLocalLibraryActivity.class), new Pair<>("sc_id", "system")), false)); + preferences.add(createPreference(R.drawable.engineering_48, "Mod settings", "Change general mod settings", new ActivityLauncher(new Intent(getApplicationContext(), ConfigActivity.class)), false)); + preferences.add(createPreference(R.drawable.ic_mtrl_palette, getString(R.string.settings_appearance), getString(R.string.settings_appearance_description), openSettingsActivity(SettingsActivity.SETTINGS_APPEARANCE_FRAGMENT), false)); + preferences.add(createPreference(R.mipmap.ic_type_folder, "Open working directory", "Open Sketchware Pro's directory and edit files in it", v -> openWorkingDirectory(), false)); + preferences.add(createPreference(R.drawable.ic_apk_color_96dp, "Sign an APK file with testkey", "Sign an already existing APK file with testkey and signature schemes up to V4", v -> signApkFileDialog(), false)); + preferences.add(createPreference(R.drawable.icons8_app_components, getString(R.string.design_drawer_menu_title_logcat_reader), getString(R.string.design_drawer_menu_subtitle_logcat_reader), new ActivityLauncher(new Intent(getApplicationContext(), LogReaderActivity.class)), false)); + preferences.add(createPreference(R.drawable.ic_mtrl_settings, getString(R.string.main_drawer_title_system_settings), "Auto-save and vibrations", new ActivityLauncher(new Intent(getApplicationContext(), SystemSettingActivity.class)), true)); + preferences.forEach(preference -> { + final int index = preferences.indexOf(preference); + preference.container.setBackgroundResource(UI.getShapedBackgroundForList(preferences, index)); + content.addView(preference); + }); } private View.OnClickListener openSettingsActivity(String fragmentTag) { @@ -148,21 +157,21 @@ private View.OnClickListener openSettingsActivity(String fragmentTag) { }; } - private void createToolsView(int icon, String title, String desc, LinearLayout toView, View.OnClickListener listener, boolean lastItem) { - LibraryItemView item = new LibraryItemView(this); - item.enabled.setVisibility(View.GONE); - item.icon.setImageResource(icon); - item.title.setText(title); - item.description.setText(desc); - toView.addView(item); - item.setOnClickListener(listener); - LinearLayout.LayoutParams itemParams = new LinearLayout.LayoutParams( + private LibraryItemView createPreference(int icon, String title, String desc, View.OnClickListener listener, boolean lastpreference) { + LibraryItemView preference = new LibraryItemView(this); + preference.enabled.setVisibility(View.GONE); + preference.icon.setImageResource(icon); + preference.title.setText(title); + preference.description.setText(desc); + preference.setOnClickListener(listener); + LinearLayout.LayoutParams preferenceParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.0f ); - itemParams.bottomMargin = lastItem ? dpToPx(25) : dpToPx(0); - item.setLayoutParams(itemParams); + preferenceParams.bottomMargin = lastpreference ? dpToPx(25) : dpToPx(0); + preference.setLayoutParams(preferenceParams); + return preference; } private void signApkFileDialog() { diff --git a/app/src/main/java/pro/sketchware/fragments/settings/block/selector/BlockSelectorAdapter.java b/app/src/main/java/pro/sketchware/fragments/settings/block/selector/BlockSelectorAdapter.java index 209ef4e031..179ee22739 100644 --- a/app/src/main/java/pro/sketchware/fragments/settings/block/selector/BlockSelectorAdapter.java +++ b/app/src/main/java/pro/sketchware/fragments/settings/block/selector/BlockSelectorAdapter.java @@ -11,6 +11,7 @@ import pro.sketchware.R; import pro.sketchware.databinding.LayoutBlockSelectorBinding; +import pro.sketchware.utility.UI; public class BlockSelectorAdapter extends ListAdapter { @@ -43,19 +44,7 @@ public BlockSelectorAdapterViewHolder onCreateViewHolder(@NonNull ViewGroup pare @Override public void onBindViewHolder(@NonNull BlockSelectorAdapterViewHolder holder, int position) { holder.bind(getItem(position), position); - - int backgroundResource; - if (getCurrentList().size() == 1) { - backgroundResource = R.drawable.shape_alone; - } else if (position == 0) { - backgroundResource = R.drawable.shape_top; - } else if (position == getCurrentList().size() - 1) { - backgroundResource = R.drawable.shape_bottom; - } else { - backgroundResource = R.drawable.shape_middle; - } - - holder.itemView.setBackgroundResource(backgroundResource); + holder.itemView.setBackgroundResource(UI.getShapedBackgroundForList(getCurrentList(), position)); } public static class BlockSelectorAdapterViewHolder extends RecyclerView.ViewHolder { diff --git a/app/src/main/java/pro/sketchware/fragments/settings/block/selector/details/BlockSelectorDetailsAdapter.java b/app/src/main/java/pro/sketchware/fragments/settings/block/selector/details/BlockSelectorDetailsAdapter.java index 5ace6e90ec..0b4369f411 100644 --- a/app/src/main/java/pro/sketchware/fragments/settings/block/selector/details/BlockSelectorDetailsAdapter.java +++ b/app/src/main/java/pro/sketchware/fragments/settings/block/selector/details/BlockSelectorDetailsAdapter.java @@ -13,6 +13,7 @@ import pro.sketchware.databinding.LayoutBlockSelectorBinding; import pro.sketchware.fragments.settings.block.selector.BlockSelectorAdapter.OnClickListener; import pro.sketchware.fragments.settings.block.selector.BlockSelectorAdapter.OnLongClickListener; +import pro.sketchware.utility.UI; public class BlockSelectorDetailsAdapter extends ListAdapter { @@ -37,19 +38,7 @@ public BlockSelectorDetailsAdapterViewHolder onCreateViewHolder(@NonNull ViewGro @Override public void onBindViewHolder(@NonNull BlockSelectorDetailsAdapterViewHolder holder, int position) { holder.bind(getItem(position), position); - - int backgroundResource; - if (getCurrentList().size() == 1) { - backgroundResource = R.drawable.shape_alone; - } else if (position == 0) { - backgroundResource = R.drawable.shape_top; - } else if (position == getCurrentList().size() - 1) { - backgroundResource = R.drawable.shape_bottom; - } else { - backgroundResource = R.drawable.shape_middle; - } - - holder.itemView.setBackgroundResource(backgroundResource); + holder.itemView.setBackgroundResource(UI.getShapedBackgroundForList(getCurrentList(), position)); } public static class BlockSelectorDetailsAdapterViewHolder extends RecyclerView.ViewHolder { diff --git a/app/src/main/java/pro/sketchware/fragments/settings/events/EventsManagerFragment.java b/app/src/main/java/pro/sketchware/fragments/settings/events/EventsManagerFragment.java index cbf211f981..9c1ec27ec7 100644 --- a/app/src/main/java/pro/sketchware/fragments/settings/events/EventsManagerFragment.java +++ b/app/src/main/java/pro/sketchware/fragments/settings/events/EventsManagerFragment.java @@ -22,6 +22,7 @@ import pro.sketchware.databinding.LayoutEventItemBinding; import pro.sketchware.utility.SketchwareUtil; import pro.sketchware.utility.FileUtil; +import pro.sketchware.utility.UI; import pro.sketchware.fragments.settings.events.details.EventsManagerDetailsFragment; import java.io.File; @@ -260,18 +261,7 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public void onBindViewHolder(@NonNull ViewHolder holder, int position) { HashMap item = dataArray.get(position); String name = (String) item.get("name"); - - int backgroundResource; - if (dataArray.size() == 1) { - backgroundResource = R.drawable.shape_alone; - } else if (position == 0) { - backgroundResource = R.drawable.shape_top; - } else if (position == dataArray.size() - 1) { - backgroundResource = R.drawable.shape_bottom; - } else { - backgroundResource = R.drawable.shape_middle; - } - holder.itemView.setBackgroundResource(backgroundResource); + holder.itemView.setBackgroundResource(UI.getShapedBackgroundForList(dataArray, position)); holder.binding.eventIcon.setImageResource(R.drawable.event_on_response_48dp); ((LinearLayout) holder.binding.eventIcon.getParent()).setGravity(Gravity.CENTER); diff --git a/app/src/main/java/pro/sketchware/fragments/settings/events/details/EventsManagerDetailsFragment.java b/app/src/main/java/pro/sketchware/fragments/settings/events/details/EventsManagerDetailsFragment.java index a0caa1ff7c..1efe86a338 100644 --- a/app/src/main/java/pro/sketchware/fragments/settings/events/details/EventsManagerDetailsFragment.java +++ b/app/src/main/java/pro/sketchware/fragments/settings/events/details/EventsManagerDetailsFragment.java @@ -15,6 +15,7 @@ import pro.sketchware.databinding.FragmentEventsManagerDetailsBinding; import pro.sketchware.databinding.LayoutEventItemBinding; import pro.sketchware.utility.FileUtil; +import pro.sketchware.utility.UI; import pro.sketchware.fragments.settings.events.EventsManagerConstants; import pro.sketchware.fragments.settings.events.creator.EventsManagerCreatorFragment; @@ -115,17 +116,7 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public void onBindViewHolder(@NonNull ViewHolder holder, int position) { HashMap item = dataArray.get(position); - int backgroundResource; - if (dataArray.size() == 1) { - backgroundResource = R.drawable.shape_alone; - } else if (position == 0) { - backgroundResource = R.drawable.shape_top; - } else if (position == dataArray.size() - 1) { - backgroundResource = R.drawable.shape_bottom; - } else { - backgroundResource = R.drawable.shape_middle; - } - holder.itemView.setBackgroundResource(backgroundResource); + holder.itemView.setBackgroundResource(UI.getShapedBackgroundForList(dataArray, position)); if (listName.isEmpty()) { holder.binding.eventIcon.setImageResource(R.drawable.ic_mtrl_code); diff --git a/app/src/main/java/pro/sketchware/utility/UI.java b/app/src/main/java/pro/sketchware/utility/UI.java index 93445988b2..4af98183a6 100644 --- a/app/src/main/java/pro/sketchware/utility/UI.java +++ b/app/src/main/java/pro/sketchware/utility/UI.java @@ -10,12 +10,17 @@ import android.view.ViewGroup; import android.widget.ImageView; +import androidx.annotation.DrawableRes; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.bumptech.glide.Glide; +import java.util.List; + +import pro.sketchware.R; + public class UI { public static void loadImageFromUrl(ImageView image, String url) { Glide.with(image.getContext()) @@ -72,4 +77,17 @@ public static void addSystemWindowInsetToPadding( return windowInsets; }); } -} + + @DrawableRes + public static int getShapedBackgroundForList(final List list, final int position) { + if (list.size() == 1) { + return R.drawable.shape_alone; + } else if (position == 0) { + return R.drawable.shape_top; + } else if (position == list.size() - 1) { + return R.drawable.shape_bottom; + } else { + return R.drawable.shape_middle; + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_mtrl_moreblock.xml b/app/src/main/res/drawable/ic_mtrl_moreblock.xml new file mode 100644 index 0000000000..abc17947d5 --- /dev/null +++ b/app/src/main/res/drawable/ic_mtrl_moreblock.xml @@ -0,0 +1,11 @@ + + + + diff --git a/app/src/main/res/drawable/shape_alone.xml b/app/src/main/res/drawable/shape_alone.xml index 3527ab743c..9ded949235 100644 --- a/app/src/main/res/drawable/shape_alone.xml +++ b/app/src/main/res/drawable/shape_alone.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_bottom.xml b/app/src/main/res/drawable/shape_bottom.xml index 8f98aaf4e7..a0d3274202 100644 --- a/app/src/main/res/drawable/shape_bottom.xml +++ b/app/src/main/res/drawable/shape_bottom.xml @@ -7,8 +7,8 @@ + android:bottomLeftRadius="16dp" + android:bottomRightRadius="16dp" /> \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_top.xml b/app/src/main/res/drawable/shape_top.xml index 26b1298e57..97cb86bd79 100644 --- a/app/src/main/res/drawable/shape_top.xml +++ b/app/src/main/res/drawable/shape_top.xml @@ -5,8 +5,8 @@ diff --git a/app/src/main/res/layout/manage_collection.xml b/app/src/main/res/layout/manage_collection.xml index 088ce7446b..30bc6919e1 100644 --- a/app/src/main/res/layout/manage_collection.xml +++ b/app/src/main/res/layout/manage_collection.xml @@ -30,11 +30,15 @@ android:layout_height="match_parent" android:orientation="vertical"> - + android:background="@android:color/transparent" + android:fitsSystemWindows="false" + app:itemPaddingBottom="28dp" + app:labelVisibilityMode="labeled" + app:menu="@menu/manage_collection_items_menu" /> diff --git a/app/src/main/res/layout/manage_collection_block_list_item.xml b/app/src/main/res/layout/manage_collection_block_list_item.xml index 221e32e5fa..bf800cc664 100644 --- a/app/src/main/res/layout/manage_collection_block_list_item.xml +++ b/app/src/main/res/layout/manage_collection_block_list_item.xml @@ -1,15 +1,12 @@ + android:layout_margin="4dp" + app:cardBackgroundColor="?attr/colorSurfaceContainer" + app:strokeWidth="0.5dp"> + android:layout_margin="4dp" + app:cardBackgroundColor="?attr/colorSurfaceContainer" + app:strokeWidth="0.5dp"> + android:layout_margin="4dp" + app:cardBackgroundColor="?attr/colorSurfaceContainer" + app:strokeWidth="0.5dp"> + android:background="@drawable/shape_alone"> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/view_item_local_lib.xml b/app/src/main/res/layout/view_item_local_lib.xml index eab21fde2a..8d58e4d08b 100644 --- a/app/src/main/res/layout/view_item_local_lib.xml +++ b/app/src/main/res/layout/view_item_local_lib.xml @@ -1,8 +1,11 @@ - + android:layout_height="wrap_content" + android:layout_marginEnd="16dp" + android:layout_marginStart="16dp" + android:layout_marginTop="5dp"> - + diff --git a/app/src/main/res/menu/manage_collection_items_menu.xml b/app/src/main/res/menu/manage_collection_items_menu.xml new file mode 100644 index 0000000000..2e481ab517 --- /dev/null +++ b/app/src/main/res/menu/manage_collection_items_menu.xml @@ -0,0 +1,27 @@ + + + + + + + + + diff --git a/app/src/main/res/values/styles_new.xml b/app/src/main/res/values/styles_new.xml index cb5828b607..08ed48aee9 100644 --- a/app/src/main/res/values/styles_new.xml +++ b/app/src/main/res/values/styles_new.xml @@ -137,5 +137,8 @@ true true - + + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 87f64d0696..b06e6a912d 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -16,7 +16,7 @@ @style/ThemeOverlay.SketchwarePro.BottomSheetDialog @style/Widget.Material3.PopupMenu @style/Widget.Material3.PopupMenu - + @style/Widget.SketchwarePro.MaterialCardView @style/TextAppearance.SketchwarePro.DisplayLarge @style/TextAppearance.SketchwarePro.DisplayMedium