From ee6bc36d246373a27d1386d5854c8cb7765a0dcb Mon Sep 17 00:00:00 2001 From: Yamen <164387611+Yamenher@users.noreply.github.com> Date: Sat, 28 Dec 2024 15:28:01 +0100 Subject: [PATCH 01/14] Fix : attempt to fix apk sending to telegram (#1537) --- .github/workflows/main-minApi26.yml | 99 +++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 .github/workflows/main-minApi26.yml diff --git a/.github/workflows/main-minApi26.yml b/.github/workflows/main-minApi26.yml new file mode 100644 index 0000000000..e0439c475b --- /dev/null +++ b/.github/workflows/main-minApi26.yml @@ -0,0 +1,99 @@ +name: Android CI + +on: + push: + branches: + - main + paths-ignore: + - '**/*.md' + pull_request: + branches: + - main + paths-ignore: + - '**/*.md' + workflow_dispatch: + +jobs: + init: + name: Init + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: notify telegram + uses: EverythingSuckz/github-telegram-notify@main + continue-on-error: true + with: + bot_token: ${{ secrets.bot_token }} + chat_id: -1001427104411 + topic_id: 257833 + + build_debug_apk: + name: Build App Release APK + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'oracle' + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Validate Gradle wrapper + uses: gradle/actions/wrapper-validation@v4 + + - name: Build with Gradle + id: gradle_build_release + env: + BOT_TOKEN: ${{ secrets.bot_token }} + CHAT_ID: ${{ secrets.chat_id }} + run: ./gradlew assembleMinApi26Release + + - name: Upload release apk + uses: actions/upload-artifact@v4 + with: + name: app-release + path: app/build/outputs/apk/release/app-minApi26-release.apk + + send_debug_apk: + name: Send Release APK + runs-on: ubuntu-latest + needs: build_release_apk + + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + + - name: Download release apk + uses: actions/download-artifact@v4 + with: + name: app-release + + - name: List repo contents + run: ls + + - name: Get the last commit message + id: get_commit_msg + run: | + commit_message=$(git log -1 --pretty=format:'%s') + echo "message=$commit_message" >> $GITHUB_OUTPUT + + - name: Send APK to Release Channel Telegram with Topic ID + if: success() + continue-on-error: true + run: | + curl -X POST "https://api.telegram.org/bot${{ secrets.bot_token }}/sendDocument" \ + -F chat_id="-1001427104411" \ + -F message_thread_id="257833" \ + -F document=@"app-minApi26-release.apk" \ + -F caption="${{ github.event.head_commit.message }} by ${{ github.actor }}" From ecaddc0b56bd6b172ff07b88c27f8a9298e6d1cb Mon Sep 17 00:00:00 2001 From: aikrq <95296093+aikrq@users.noreply.github.com> Date: Sat, 28 Dec 2024 21:56:38 +0700 Subject: [PATCH 02/14] revert: Attempt to fix APK sending to Telegram [skip ci] This reverts commit ee6bc36d246373a27d1386d5854c8cb7765a0dcb. --- .github/workflows/main-minApi26.yml | 99 ----------------------------- 1 file changed, 99 deletions(-) delete mode 100644 .github/workflows/main-minApi26.yml diff --git a/.github/workflows/main-minApi26.yml b/.github/workflows/main-minApi26.yml deleted file mode 100644 index e0439c475b..0000000000 --- a/.github/workflows/main-minApi26.yml +++ /dev/null @@ -1,99 +0,0 @@ -name: Android CI - -on: - push: - branches: - - main - paths-ignore: - - '**/*.md' - pull_request: - branches: - - main - paths-ignore: - - '**/*.md' - workflow_dispatch: - -jobs: - init: - name: Init - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: notify telegram - uses: EverythingSuckz/github-telegram-notify@main - continue-on-error: true - with: - bot_token: ${{ secrets.bot_token }} - chat_id: -1001427104411 - topic_id: 257833 - - build_debug_apk: - name: Build App Release APK - runs-on: ubuntu-latest - - steps: - - name: Check out repository - uses: actions/checkout@v4 - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'oracle' - cache: gradle - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Validate Gradle wrapper - uses: gradle/actions/wrapper-validation@v4 - - - name: Build with Gradle - id: gradle_build_release - env: - BOT_TOKEN: ${{ secrets.bot_token }} - CHAT_ID: ${{ secrets.chat_id }} - run: ./gradlew assembleMinApi26Release - - - name: Upload release apk - uses: actions/upload-artifact@v4 - with: - name: app-release - path: app/build/outputs/apk/release/app-minApi26-release.apk - - send_debug_apk: - name: Send Release APK - runs-on: ubuntu-latest - needs: build_release_apk - - steps: - - name: Check out repository - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.ref }} - - - name: Download release apk - uses: actions/download-artifact@v4 - with: - name: app-release - - - name: List repo contents - run: ls - - - name: Get the last commit message - id: get_commit_msg - run: | - commit_message=$(git log -1 --pretty=format:'%s') - echo "message=$commit_message" >> $GITHUB_OUTPUT - - - name: Send APK to Release Channel Telegram with Topic ID - if: success() - continue-on-error: true - run: | - curl -X POST "https://api.telegram.org/bot${{ secrets.bot_token }}/sendDocument" \ - -F chat_id="-1001427104411" \ - -F message_thread_id="257833" \ - -F document=@"app-minApi26-release.apk" \ - -F caption="${{ github.event.head_commit.message }} by ${{ github.actor }}" From 9584f0b7a261e4de4c531788b16a3a9d98ddfc76 Mon Sep 17 00:00:00 2001 From: Edward-NG-KOC Date: Sat, 28 Dec 2024 19:26:44 +0100 Subject: [PATCH 03/14] fix: reset `ProjectResourceBeans` selection when disabling selectionMode in `projectFontsFragment` --- app/src/main/java/a/a/a/Zt.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/a/a/a/Zt.java b/app/src/main/java/a/a/a/Zt.java index ffa018d1a8..3c8cdcdd0a 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(); } From fcd3bf41ac63f19d6bf2498f79b1d1d053608514 Mon Sep 17 00:00:00 2001 From: Edward-NG-KOC Date: Sat, 28 Dec 2024 19:28:49 +0100 Subject: [PATCH 04/14] fix: allow saving empty `ProjectResourceBeans` list in `projectFontsFragment` --- app/src/main/java/a/a/a/Zt.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/a/a/a/Zt.java b/app/src/main/java/a/a/a/Zt.java index 3c8cdcdd0a..98ed987654 100644 --- a/app/src/main/java/a/a/a/Zt.java +++ b/app/src/main/java/a/a/a/Zt.java @@ -131,7 +131,7 @@ public ArrayList getProjectResourceBeans() { } public void processResources() { - if (projectResourceBeans == null || projectResourceBeans.isEmpty()) { + if (projectResourceBeans == null) { return; } From c46141986aad362d9a3607aedf76d9e7d57d0e75 Mon Sep 17 00:00:00 2001 From: Mustafa salah <87241434+Mustiy0@users.noreply.github.com> Date: Sat, 28 Dec 2024 22:25:57 +0300 Subject: [PATCH 05/14] refactor: Use NavigationRail in CollectioManager * refactor : using nav rail instead of recyclerView in collection manager * refactor : reformat code * fix : inconsistent moreblock and blocks item view in collection manager * fix : wrong string * fix : image collections not selected by def * refactor : reformat code * fix : inconsistent ui --- .../manage/ManageCollectionActivity.java | 260 ++++++------------ .../main/res/drawable/ic_mtrl_moreblock.xml | 11 + app/src/main/res/layout/manage_collection.xml | 10 +- .../manage_collection_block_list_item.xml | 13 +- ...manage_collection_more_block_list_item.xml | 10 +- .../manage_collection_widget_list_item.xml | 10 +- .../res/menu/manage_collection_items_menu.xml | 27 ++ 7 files changed, 145 insertions(+), 196 deletions(-) create mode 100644 app/src/main/res/drawable/ic_mtrl_moreblock.xml create mode 100644 app/src/main/res/menu/manage_collection_items_menu.xml 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/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/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"> + + + + + + + + From 5eec00a74794278d9941fa4cd06dd0ee42a2b9b1 Mon Sep 17 00:00:00 2001 From: Aquiles Trindade Date: Fri, 27 Dec 2024 21:42:40 -0300 Subject: [PATCH 06/14] feat: Better UI on AppSettings --- .../manage/library/LibraryItemView.java | 12 ++-- .../saif/activities/tools/AppSettings.java | 66 ++++++++++++------- 2 files changed, 48 insertions(+), 30 deletions(-) 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..0fa31002bf 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 @@ -16,12 +16,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 MaterialCardView 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/mod/hilal/saif/activities/tools/AppSettings.java b/app/src/main/java/mod/hilal/saif/activities/tools/AppSettings.java index fb649bf5c1..168df79a4d 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; @@ -52,6 +54,7 @@ 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 +67,7 @@ public void onCreate(Bundle savedInstanceState) { topAppBar.setTitle("Settings"); topAppBar.setNavigationOnClickListener(view -> onBackPressed()); - setupViews(); + setupPreferences(); } private void openWorkingDirectory() { @@ -126,18 +129,33 @@ 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); + int backgroundResource; + if (preferences.size() == 1) { + backgroundResource = R.drawable.shape_alone; + } else if (index == 0) { + backgroundResource = R.drawable.shape_top; + } else if (index == preferences.size() - 1) { + backgroundResource = R.drawable.shape_bottom; + } else { + backgroundResource = R.drawable.shape_middle; + } + preference.container.setBackgroundResource(backgroundResource); + content.addView(preference); + }); } private View.OnClickListener openSettingsActivity(String fragmentTag) { @@ -148,21 +166,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() { From 12543be85e6966ebc9f27b57511821c91098b43f Mon Sep 17 00:00:00 2001 From: Aquiles Trindade Date: Fri, 27 Dec 2024 21:57:45 -0300 Subject: [PATCH 07/14] feat: Better UI on ManageLocalLibraries --- .../manage/ManageLocalLibraryActivity.java | 14 +++- .../main/res/layout/view_item_local_lib.xml | 68 ++++++++----------- 2 files changed, 43 insertions(+), 39 deletions(-) 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 feeb2c77ad..6b1395ebf2 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 @@ -31,6 +31,7 @@ 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.utility.FileUtil; @@ -200,7 +201,18 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @Override public void onBindViewHolder(ViewHolder holder, final int position) { var binding = holder.listBinding; - + int backgroundResource; + if (filteredList.size() == 1) { + backgroundResource = R.drawable.shape_alone; + } else if (position == 0) { + backgroundResource = R.drawable.shape_top; + } else if (position == filteredList.size() - 1) { + backgroundResource = R.drawable.shape_bottom; + } else { + backgroundResource = R.drawable.shape_middle; + } + holder.itemView.setBackgroundResource(backgroundResource); + final String libraryName = filteredList.get(position); binding.checkboxContent.setText(libraryName); 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 1ccc799e62..7981316489 100644 --- a/app/src/main/res/layout/view_item_local_lib.xml +++ b/app/src/main/res/layout/view_item_local_lib.xml @@ -1,48 +1,40 @@ - + android:layout_height="wrap_content" + android:layout_marginEnd="16dp" + android:layout_marginStart="16dp" + android:layout_marginTop="8dp"> - + android:orientation="horizontal"> - + android:layout_margin="8dp" + android:layout_weight="1" + android:paddingStart="8dp" + android:textAppearance="?attr/textAppearanceBodyLarge" + tools:text="com.sketchware.pro:1.0.0" /> - + - - - - - - + + \ No newline at end of file From b4d66761f9981d8803b40411c2b64c8f3eaa4c50 Mon Sep 17 00:00:00 2001 From: Aquiles Trindade Date: Fri, 27 Dec 2024 22:22:56 -0300 Subject: [PATCH 08/14] feat: Better UI on LibraryManager --- .../editor/manage/library/LibraryItemView.java | 5 +++-- .../manage/library/ManageLibraryActivity.java | 17 +++++++++-------- app/src/main/res/drawable/shape_alone.xml | 2 +- app/src/main/res/drawable/shape_bottom.xml | 4 ++-- app/src/main/res/drawable/shape_top.xml | 4 ++-- .../res/layout/manage_library_base_item.xml | 6 +++--- app/src/main/res/layout/view_item_local_lib.xml | 2 +- 7 files changed, 21 insertions(+), 19 deletions(-) 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 0fa31002bf..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; @@ -17,7 +18,7 @@ public class LibraryItemView extends FrameLayout { protected final Context context; - public final MaterialCardView container; + public final LinearLayout container; public final ImageView icon; public final TextView title; public final TextView description; 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/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_library_base_item.xml b/app/src/main/res/layout/manage_library_base_item.xml index 2c0d251943..7531cd6435 100644 --- a/app/src/main/res/layout/manage_library_base_item.xml +++ b/app/src/main/res/layout/manage_library_base_item.xml @@ -1,4 +1,4 @@ - - \ 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 7981316489..02e9b8086d 100644 --- a/app/src/main/res/layout/view_item_local_lib.xml +++ b/app/src/main/res/layout/view_item_local_lib.xml @@ -5,7 +5,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="16dp" android:layout_marginStart="16dp" - android:layout_marginTop="8dp"> + android:layout_marginTop="5dp"> Date: Fri, 27 Dec 2024 22:58:17 -0300 Subject: [PATCH 09/14] fix: Dont define layout params of binding root --- .../sayuti/editor/manage/ManageLocalLibraryActivity.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 6b1395ebf2..831c994e39 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 @@ -192,10 +192,7 @@ public LibraryAdapter(List localLibraries) { @NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - var listBinding = ViewItemLocalLibBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); - var layoutParams = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - listBinding.getRoot().setLayoutParams(layoutParams); - return new ViewHolder(listBinding); + return new ViewHolder(ViewItemLocalLibBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override From 62603bbe8fcf75cd3dc94a46057a1f7814c51651 Mon Sep 17 00:00:00 2001 From: Aquiles Trindade Date: Sat, 28 Dec 2024 16:05:25 -0300 Subject: [PATCH 10/14] refactor: use UI#getShapedBackgroundForList(List, Int) instead --- .../manage/ManageLocalLibraryActivity.java | 13 ++----------- .../saif/activities/tools/AppSettings.java | 13 ++----------- .../block/selector/BlockSelectorAdapter.java | 15 ++------------- .../details/BlockSelectorDetailsAdapter.java | 15 ++------------- .../settings/events/EventsManagerFragment.java | 14 ++------------ .../details/EventsManagerDetailsFragment.java | 13 ++----------- .../main/java/pro/sketchware/utility/UI.java | 18 +++++++++++++++++- 7 files changed, 29 insertions(+), 72 deletions(-) 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 831c994e39..7923e3c4c7 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 @@ -36,6 +36,7 @@ import pro.sketchware.databinding.ViewItemLocalLibBinding; import pro.sketchware.utility.FileUtil; import pro.sketchware.utility.SketchwareUtil; +import pro.sketchware.utility.UI; public class ManageLocalLibraryActivity extends AppCompatActivity implements View.OnClickListener { private static String local_libs_path = ""; @@ -198,17 +199,7 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @Override public void onBindViewHolder(ViewHolder holder, final int position) { var binding = holder.listBinding; - int backgroundResource; - if (filteredList.size() == 1) { - backgroundResource = R.drawable.shape_alone; - } else if (position == 0) { - backgroundResource = R.drawable.shape_top; - } else if (position == filteredList.size() - 1) { - backgroundResource = R.drawable.shape_bottom; - } else { - backgroundResource = R.drawable.shape_middle; - } - holder.itemView.setBackgroundResource(backgroundResource); + holder.itemView.setBackgroundResource(UI.getShapedBackgroundForList(filteredList, position)); final String libraryName = filteredList.get(position); binding.checkboxContent.setText(libraryName); 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 168df79a4d..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 @@ -49,6 +49,7 @@ 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 { @@ -143,17 +144,7 @@ private void setupPreferences() { 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); - int backgroundResource; - if (preferences.size() == 1) { - backgroundResource = R.drawable.shape_alone; - } else if (index == 0) { - backgroundResource = R.drawable.shape_top; - } else if (index == preferences.size() - 1) { - backgroundResource = R.drawable.shape_bottom; - } else { - backgroundResource = R.drawable.shape_middle; - } - preference.container.setBackgroundResource(backgroundResource); + preference.container.setBackgroundResource(UI.getShapedBackgroundForList(preferences, index)); content.addView(preference); }); } 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..940b865f3c 100644 --- a/app/src/main/java/pro/sketchware/utility/UI.java +++ b/app/src/main/java/pro/sketchware/utility/UI.java @@ -10,12 +10,15 @@ 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; + public class UI { public static void loadImageFromUrl(ImageView image, String url) { Glide.with(image.getContext()) @@ -72,4 +75,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 From 5f880f0c266a665438fb55b5d07037d6df345332 Mon Sep 17 00:00:00 2001 From: Aquiles Trindade Date: Sat, 28 Dec 2024 16:09:20 -0300 Subject: [PATCH 11/14] fix: Add Missing R package importation --- app/src/main/java/pro/sketchware/utility/UI.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/pro/sketchware/utility/UI.java b/app/src/main/java/pro/sketchware/utility/UI.java index 940b865f3c..4af98183a6 100644 --- a/app/src/main/java/pro/sketchware/utility/UI.java +++ b/app/src/main/java/pro/sketchware/utility/UI.java @@ -19,6 +19,8 @@ import java.util.List; +import pro.sketchware.R; + public class UI { public static void loadImageFromUrl(ImageView image, String url) { Glide.with(image.getContext()) From e30d896ddb9745212a0040df3d0aa62ce2dc37cf Mon Sep 17 00:00:00 2001 From: Aquiles Trindade Date: Sat, 28 Dec 2024 16:56:45 -0300 Subject: [PATCH 12/14] feat: Use 16dp in all filled cards --- app/src/main/res/values/styles_new.xml | 5 ++++- app/src/main/res/values/themes.xml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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 From f80de6d5015a302179184a15097c459ff47c4e5f Mon Sep 17 00:00:00 2001 From: Aquiles Trindade Date: Sat, 28 Dec 2024 17:08:58 -0300 Subject: [PATCH 13/14] fix: use shape_alone by default in LibraryItem --- app/src/main/res/layout/manage_library_base_item.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/res/layout/manage_library_base_item.xml b/app/src/main/res/layout/manage_library_base_item.xml index 7531cd6435..3f5dbd5468 100644 --- a/app/src/main/res/layout/manage_library_base_item.xml +++ b/app/src/main/res/layout/manage_library_base_item.xml @@ -9,8 +9,7 @@ android:layout_marginTop="5dp" android:focusable="true" android:clickable="true" - style="?attr/materialCardViewFilledStyle" - app:cardBackgroundColor="?attr/colorSurfaceContainer"> + android:background="@drawable/shape_alone"> Date: Sat, 28 Dec 2024 17:28:08 -0300 Subject: [PATCH 14/14] feat: Better UI on AndroidManifest Cards --- .../AndroidManifestInjection.java | 117 ++++++++++-------- 1 file changed, 68 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/mod/hilal/saif/activities/android_manifest/AndroidManifestInjection.java b/app/src/main/java/mod/hilal/saif/activities/android_manifest/AndroidManifestInjection.java index 767e2ced68..16658c58fd 100644 --- a/app/src/main/java/mod/hilal/saif/activities/android_manifest/AndroidManifestInjection.java +++ b/app/src/main/java/mod/hilal/saif/activities/android_manifest/AndroidManifestInjection.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Objects; import a.a.a.aB; @@ -41,6 +42,7 @@ import pro.sketchware.utility.SketchwareUtil; import pro.sketchware.utility.FileUtil; +import pro.sketchware.utility.UI; import mod.hey.studios.code.SrcCodeEditor; import mod.hey.studios.code.SrcCodeEditorLegacy; import mod.hey.studios.util.Helper; @@ -109,61 +111,78 @@ private void setupViews() { LinearLayout content = findViewById(R.id.content); LinearLayout cards = findViewById(R.id.cards); - LibraryItemView application_card = new LibraryItemView(this); - makeup(application_card, R.drawable.icons8_app_attrs, "Application", "Default properties for the app"); - cards.addView(application_card); - application_card.setOnClickListener(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); - }); - - { - 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();