Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE-271 Typographic hierarchy should be visible #5047

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions catroid/src/main/java/org/catrobat/catroid/ui/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Build;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -164,4 +165,34 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
}
};
}

public static ArrayAdapter getAlertDialogAdapterForTextWithIcons(Activity activity, Context context, Pair<String, Integer>[] items) {
return new ArrayAdapter<Pair<String, Integer>>(context, android.R.layout.simple_list_item_1, items) {
TextView item;

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

if (convertView == null) {
convertView = inflater.inflate(R.layout.dialog_item_with_icon, parent, false);
item = (TextView) convertView.findViewById(R.id.item_text);
convertView.setTag(item);
} else {
item = (TextView) convertView.getTag();
}

item.setText(items[position].first);

if (activity.getWindow().getDecorView().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR) {
item.setCompoundDrawablesWithIntrinsicBounds(items[position].second, 0, 0, 0);
} else {
item.setCompoundDrawablesWithIntrinsicBounds(0, 0, items[position].second, 0);
}

return convertView;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
import android.content.DialogInterface;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Pair;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;

import org.catrobat.catroid.R;
import org.catrobat.catroid.ui.UiUtils;
Expand All @@ -49,6 +52,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import androidx.annotation.IntDef;
import androidx.annotation.PluralsRes;
Expand All @@ -57,6 +61,8 @@
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

import static org.catrobat.catroid.ui.UiUtils.getAlertDialogAdapterForTextWithIcons;

public abstract class BackpackRecyclerViewFragment<T> extends Fragment implements
ActionMode.Callback,
RVAdapter.SelectionListener,
Expand Down Expand Up @@ -292,28 +298,40 @@ public void onItemClick(final T item, MultiSelectionManager selectionManager) {
return;
}

List<Integer> options = new ArrayList<>();
options.add(R.string.unpack);
options.add(R.string.delete);
List<String> names = new ArrayList<>();
for (Integer option: options) {
names.add(getString(option));
}
ListAdapter arrayAdapter = UiUtils.getAlertDialogAdapterForMenuIcons(options,
names, requireContext(), requireActivity());

new AlertDialog.Builder(requireContext())
.setTitle(getItemName(item))
.setAdapter(arrayAdapter, (dialog, which) -> {
switch (which) {
case 0:
unpackItems(new ArrayList<>(Collections.singletonList(item)));
break;
case 1:
showDeleteAlert(new ArrayList<>(Collections.singletonList(item)));
}
})
.show();
Pair[] items = new Pair[] {
new Pair<String, Integer>(getString(R.string.unpack), R.drawable.ic_logout),
new Pair<String, Integer>(getString(R.string.delete), R.drawable.ic_delete)};
Comment on lines +301 to +303
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to get rid of the warning Raw use of parameterized class 'Pair' by using Lists as bellow:

Suggested change
Pair[] items = new Pair[] {
new Pair<String, Integer>(getString(R.string.unpack), R.drawable.ic_logout),
new Pair<String, Integer>(getString(R.string.delete), R.drawable.ic_delete)};
List<Pair<String, Integer>> items = Arrays.asList(
new Pair<>(getString(R.string.unpack), R.drawable.ic_logout),
new Pair<>(getString(R.string.delete), R.drawable.ic_delete)
);


LayoutInflater inflater = LayoutInflater.from(requireContext());
View customDialogView = inflater.inflate(R.layout.dialog_backpack_custom_alert, null);
ListAdapter listAdapter = getAlertDialogAdapterForTextWithIcons(requireActivity(),
requireContext(), items);

AlertDialog dialog = new AlertDialog.Builder(requireContext())
.setView(customDialogView)
.create();
Objects.requireNonNull(dialog.getWindow())
.setBackgroundDrawableResource(R.drawable.backpack_background_round);

TextView textView = customDialogView.findViewById(R.id.backpack_dialog_title);
textView.setText(getItemName(item));

ListView listView = customDialogView.findViewById(R.id.backpack_item_list);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener((parent, view, position, id) -> {
switch (position) {
case 0:
unpackItems(new ArrayList<>(Collections.singletonList(item)));
break;
case 1:
showDeleteAlert(new ArrayList<>(Collections.singletonList(item)));
break;
}

dialog.dismiss();
});

dialog.show();
}

public void setShowProgressBar(boolean show) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.util.Pair;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import org.catrobat.catroid.R;
Expand All @@ -55,6 +58,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.Objects;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
Expand All @@ -66,6 +70,7 @@
import androidx.recyclerview.widget.RecyclerView;

import static org.catrobat.catroid.common.SharedPreferenceKeys.SORT_PROJECTS_PREFERENCE_KEY;
import static org.catrobat.catroid.ui.UiUtils.getAlertDialogAdapterForTextWithIcons;

public abstract class RecyclerViewFragment<T extends Nameable> extends Fragment implements
ActionMode.Callback,
Expand Down Expand Up @@ -477,19 +482,37 @@ public void notifyDataSetChanged() {
}

protected void showBackpackModeChooser() {
CharSequence[] items = new CharSequence[] {getString(R.string.pack), getString(R.string.unpack)};
new AlertDialog.Builder(requireContext())
.setTitle(R.string.backpack_title)
.setItems(items, (dialog, which) -> {
switch (which) {
case 0:
startActionMode(BACKPACK);
break;
case 1:
switchToBackpack();
}
})
.show();
Pair[] items = new Pair[] {
new Pair<String, Integer>(getString(R.string.pack), R.drawable.ic_login),
new Pair<String, Integer>(getString(R.string.unpack), R.drawable.ic_logout)};
Comment on lines +485 to +487
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the same as in BackpackRecyclerViewFragment.java.


LayoutInflater inflater = LayoutInflater.from(requireContext());
View customDialogView = inflater.inflate(R.layout.dialog_backpack_custom_alert, null);
ListAdapter listAdapter = getAlertDialogAdapterForTextWithIcons(requireActivity(),
requireContext(), items);

AlertDialog dialog = new AlertDialog.Builder(requireContext())
.setView(customDialogView)
.create();
Objects.requireNonNull(dialog.getWindow())
.setBackgroundDrawableResource(R.drawable.backpack_background_round);

ListView listView = customDialogView.findViewById(R.id.backpack_item_list);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener((parent, view, position, id) -> {
switch (position) {
case 0:
startActionMode(BACKPACK);
break;
case 1:
switchToBackpack();
break;
}

dialog.dismiss();
});

dialog.show();
}

protected abstract void packItems(List<T> selectedItems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.util.Pair;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -37,7 +38,10 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import org.catrobat.catroid.BuildConfig;
import org.catrobat.catroid.ProjectManager;
Expand Down Expand Up @@ -93,6 +97,7 @@
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import androidx.annotation.IntDef;
Expand All @@ -107,6 +112,7 @@

import static org.catrobat.catroid.common.Constants.CODE_XML_FILE_NAME;
import static org.catrobat.catroid.common.Constants.UNDO_CODE_XML_FILE_NAME;
import static org.catrobat.catroid.ui.UiUtils.getAlertDialogAdapterForTextWithIcons;

public class ScriptFragment extends ListFragment implements
ActionMode.Callback,
Expand Down Expand Up @@ -847,19 +853,37 @@ public boolean onBrickLongClick(Brick brick, int position) {
}

private void showBackpackModeChooser() {
CharSequence[] items = new CharSequence[] {getString(R.string.pack), getString(R.string.unpack)};
new AlertDialog.Builder(getContext())
.setTitle(R.string.backpack_title)
.setItems(items, (dialog, which) -> {
switch (which) {
case 0:
startActionMode(BACKPACK);
break;
case 1:
switchToBackpack();
}
})
.show();
Pair[] items = new Pair[] {
new Pair<String, Integer>(getString(R.string.pack), R.drawable.ic_login),
new Pair<String, Integer>(getString(R.string.unpack), R.drawable.ic_logout)};
Comment on lines +856 to +858
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the same as in the other files.


LayoutInflater inflater = LayoutInflater.from(requireContext());
View customDialogView = inflater.inflate(R.layout.dialog_backpack_custom_alert, null);
ListAdapter listAdapter = getAlertDialogAdapterForTextWithIcons(requireActivity(),
requireContext(), items);

AlertDialog dialog = new AlertDialog.Builder(requireContext())
.setView(customDialogView)
.create();
Objects.requireNonNull(dialog.getWindow())
.setBackgroundDrawableResource(R.drawable.backpack_background_round);

ListView listView = customDialogView.findViewById(R.id.backpack_item_list);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener((parent, view, position, id) -> {
switch (position) {
case 0:
startActionMode(BACKPACK);
break;
case 1:
switchToBackpack();
break;
}

dialog.dismiss();
});

dialog.show();
}

public void showNewScriptGroupAlert(List<Brick> selectedBricks) {
Expand Down
27 changes: 27 additions & 0 deletions catroid/src/main/res/drawable/backpack_background_round.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Catroid: An on-device visual programming system for Android devices
~ Copyright (C) 2010-2024 The Catrobat Team
~ (<http://developer.catrobat.org/credits>)
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as
~ published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ An additional term exception under section 7 of the GNU Affero
~ General Public License, version 3, is available at
~ http://developer.catrobat.org/license_additional_term
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="30dp" />
<solid android:color="@color/backpack_background" />
</shape>
52 changes: 52 additions & 0 deletions catroid/src/main/res/layout/dialog_backpack_custom_alert.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Catroid: An on-device visual programming system for Android devices
~ Copyright (C) 2010-2024 The Catrobat Team
~ (<http://developer.catrobat.org/credits>)
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as
~ published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ An additional term exception under section 7 of the GNU Affero
~ General Public License, version 3, is available at
~ http://developer.catrobat.org/license_additional_term
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="5dp"
android:paddingEnd="5dp">

<TextView
android:id="@+id/backpack_dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/backpack_title"
android:textAppearance="?android:textAppearanceLarge"
android:textSize="20sp"
android:padding="16dp"/>

<View
android:id="@+id/backpack_title_divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/accent"/>

<ListView
android:id="@+id/backpack_item_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:padding="16dp"/>
</LinearLayout>
Loading