Skip to content

Commit

Permalink
feat: Redesign Local Libraries UI
Browse files Browse the repository at this point in the history
  • Loading branch information
aikrq committed Dec 29, 2024
1 parent 371284d commit 65881d0
Show file tree
Hide file tree
Showing 7 changed files with 476 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class LibraryDownloaderDialogFragment extends DialogFragment {
private String local_lib_file = "";
private LibraryDownloaderListener listener;


@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.aldi.sayuti.editor.manage;

import java.io.File;
import java.util.Comparator;

public class LocalLibrariesComparator implements Comparator<File> {
@Override
public int compare(File first, File second) {
return first.getName().compareTo(second.getName());
}
}

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions app/src/main/java/pro/sketchware/utility/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,36 @@

@SuppressWarnings("unused")
public class FileUtil {
public static String formatFileSize(long size) {
return formatFileSize(size, false);
}

public static String formatFileSize(long size, boolean removeZero) {
if (size < 1024) {
return String.format("%d B", size);
} else if (size < 1024 * 1024) {
float value = size / 1024.0f;
if (removeZero && (value - (int) value) * 10 == 0) {
return String.format("%d KB", (int) value);
} else {
return String.format("%.1f KB", value);
}
} else if (size < 1024 * 1024 * 1024) {
float value = size / 1024.0f / 1024.0f;
if (removeZero && (value - (int) value) * 10 == 0) {
return String.format("%d MB", (int) value);
} else {
return String.format("%.1f MB", value);
}
} else {
float value = size / 1024.0f / 1024.0f / 1024.0f;
if (removeZero && (value - (int) value) * 10 == 0) {
return String.format("%d GB", (int) value);
} else {
return String.format("%.1f GB", value);
}
}
}

public static boolean renameFile(String str, String str2) {
return new File(str).renameTo(new File(str2));
Expand Down Expand Up @@ -274,6 +304,17 @@ public static void listDir(String path, ArrayList<String> list) {
}
}

public static void listDirAsFile(String path, ArrayList<File> list) {
File[] listFiles;
File dir = new File(path);
if (dir.exists() && !dir.isFile() && (listFiles = dir.listFiles()) != null && listFiles.length > 0 && list != null) {
list.clear();
for (File file : listFiles) {
list.add(file);
}
}
}

/**
* @return List of files that have the filename extension {@code extension}.
*/
Expand Down
106 changes: 37 additions & 69 deletions app/src/main/res/layout/manage_locallibraries.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,117 +2,84 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/libraries_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="120dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/view_item_local_lib" />

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:elevation="0dp"
app:liftOnScroll="false"
app:elevation="0dp">

<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/collapsingToolbarLayoutLargeSize"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
app:liftOnScrollColor="@android:color/transparent"
app:statusBarForeground="?attr/colorSurface">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/topAppBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:navigationIcon="?attr/homeAsUpIndicator"
app:title="@string/local_library_manager" />
</com.google.android.material.appbar.CollapsingToolbarLayout>

<LinearLayout
<com.google.android.material.search.SearchBar
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/searchInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search for libraries"
android:importantForAutofill="noExcludeDescendants"
app:boxCornerRadiusBottomEnd="50dp"
app:boxCornerRadiusBottomStart="50dp"
app:boxCornerRadiusTopEnd="50dp"
app:boxCornerRadiusTopStart="50dp"
app:startIconDrawable="@drawable/search_icon_grey">
android:hint="Search for libraries"
app:navigationIcon="?attr/homeAsUpIndicator" />

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/searchInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>

</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>

<LinearLayout
android:id="@+id/contentLayout"
<com.google.android.material.search.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
android:hint="Search for libraries"
app:layout_anchor="@id/search_bar">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/librariesList"
android:id="@+id/search_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="8dp"
android:paddingBottom="120dp"
android:paddingBottom="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/view_item_local_lib" />
</LinearLayout>
tools:listitem="@layout/view_item_local_lib_search" />

</com.google.android.material.search.SearchView>

<LinearLayout
android:id="@+id/noContentLayout"
android:id="@+id/no_content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground"
android:fitsSystemWindows="false"
android:background="?attr/colorSurface"
android:gravity="center"
android:orientation="vertical"
android:paddingHorizontal="16dp"
android:paddingHorizontal="24dp"
android:paddingBottom="100dp"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<ImageView
android:layout_width="wrap_content"
android:layout_height="150dp"
android:src="@drawable/img_nocontent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="@string/local_library_manager_no_libraries_title"
android:textColor="?attr/colorOnSurface"
android:textSize="20sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:layout_marginTop="4dp"
android:text="@string/local_library_manager_no_libraries_body"
android:textColor="?attr/colorOnSurfaceVariant"
android:textSize="14sp" />

</LinearLayout>

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
Expand All @@ -123,4 +90,5 @@
android:layout_marginBottom="20dp"
android:text="@string/local_library_manager_download"
app:icon="@drawable/ic_mtrl_download" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
63 changes: 46 additions & 17 deletions app/src/main/res/layout/view_item_local_lib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,73 @@
android:layout_height="wrap_content">

<com.google.android.material.card.MaterialCardView
android:id="@+id/card"
style="?attr/materialCardViewFilledStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
app:cardBackgroundColor="?attr/colorSurfaceContainer">
android:layout_margin="4dp"
android:clickable="true"
android:focusable="true"
app:cardBackgroundColor="@android:color/transparent"
app:cardCornerRadius="24dp">

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:paddingEnd="8dp"
android:paddingStart="20dp"
android:paddingVertical="12dp">

<CheckBox
android:id="@+id/checkbox_content"
<TextView
android:id="@+id/library_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:paddingStart="8dp"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="?attr/textAppearanceBodyLarge"
tools:text="com.sketchware.pro:1.0.0" />
android:textColor="?attr/colorOnSurface"
android:textSize="17sp"
app:layout_constraintEnd_toStartOf="@id/checkbox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/library_size"
tools:text="appcompat-v1.7.0" />

<TextView
android:id="@+id/library_size"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textColor="?attr/colorOnSurfaceVariant"
android:textSize="15sp"
app:layout_constraintEnd_toStartOf="@id/checkbox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/library_name"
tools:text="3.4 KB" />

<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/img_delete"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/img_delete"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="8dp"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:focusable="true"
android:clickable="true"
android:padding="4dp"
android:scaleType="fitCenter"
android:scaleType="centerInside"
android:src="@drawable/ic_more_vert_grey600_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="?attr/colorControlNormal" />

</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.material.card.MaterialCardView>
</FrameLayout>
62 changes: 62 additions & 0 deletions app/src/main/res/layout/view_item_local_lib_search.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:paddingEnd="12dp"
android:paddingStart="20dp"
android:paddingVertical="16dp">

<TextView
android:id="@+id/library_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="?attr/textAppearanceBodyLarge"
android:textColor="?attr/colorOnSurface"
android:textSize="17sp"
app:layout_constraintEnd_toStartOf="@id/checkbox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/library_size"
tools:text="appcompat-v1.7.0" />

<TextView
android:id="@+id/library_size"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textColor="?attr/colorOnSurfaceVariant"
android:textSize="15sp"
app:layout_constraintEnd_toStartOf="@id/checkbox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/library_name"
tools:text="3.4 KB" />

<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/img_delete"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/img_delete"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:focusable="true"
android:clickable="true"
android:scaleType="centerInside"
android:src="@drawable/ic_more_vert_grey600_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="?attr/colorControlNormal" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 65881d0

Please sign in to comment.