Some fixes

This commit is contained in:
Thomas 2020-09-18 12:03:35 +02:00
parent 647c827ee4
commit 015a2f3289
7 changed files with 140 additions and 28 deletions

View File

@ -234,4 +234,5 @@
<string name="blur">Blur</string> <string name="blur">Blur</string>
<string name="display">Display</string> <string name="display">Display</string>
<string name="no_opinion">No opinion</string> <string name="no_opinion">No opinion</string>
<string name="pickup_languages">Pickup languages</string>
</resources> </resources>

View File

@ -250,4 +250,5 @@
<string name="help">Help</string> <string name="help">Help</string>
<string name="pickup_categories">Pickup categories</string> <string name="pickup_categories">Pickup categories</string>
<string name="pickup_languages">Pickup languages</string>
</resources> </resources>

View File

@ -56,10 +56,14 @@ public class InstancePickerActivity extends AppCompatActivity {
private RelativeLayout mainLoader, textviewNoAction; private RelativeLayout mainLoader, textviewNoAction;
boolean[] checkedItems; boolean[] checkedItemsCategory;
String[] itemsLabel; int[] itemsKeyCategory;
String[] itemsLabelCategory;
boolean[] checkedItemsLanguage;
String[] itemsKeyLanguage;
String[] itemsLabelLanguage;
InstanceParams instanceParams; InstanceParams instanceParams;
private TextView categories_view; private TextView categories_view, languages_view;
private InstancesVM viewModel; private InstancesVM viewModel;
@Override @Override
@ -76,7 +80,9 @@ public class InstancePickerActivity extends AppCompatActivity {
textviewNoAction = findViewById(R.id.no_action); textviewNoAction = findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE); mainLoader.setVisibility(View.VISIBLE);
Button pickup_categories = findViewById(R.id.pickup_categories); Button pickup_categories = findViewById(R.id.pickup_categories);
Button pickup_languages = findViewById(R.id.pickup_languages);
categories_view = findViewById(R.id.categories_view); categories_view = findViewById(R.id.categories_view);
languages_view = findViewById(R.id.languages_view);
Spinner sensitive = findViewById(R.id.sensitive); Spinner sensitive = findViewById(R.id.sensitive);
String[] channelSensitive = new String[]{"do_not_list", "blur", "display", "no_opinion"}; String[] channelSensitive = new String[]{"do_not_list", "blur", "display", "no_opinion"};
@ -103,29 +109,91 @@ public class InstancePickerActivity extends AppCompatActivity {
} }
}); });
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
checkedItems = new boolean[categories.size()];
itemsLabel = new String[categories.size()];
pickup_categories.setOnClickListener(v -> { LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
checkedItemsLanguage = new boolean[languages.size()];
itemsLabelLanguage = new String[languages.size()];
itemsKeyLanguage = new String[languages.size()];
pickup_languages.setOnClickListener(v -> {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(InstancePickerActivity.this); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(InstancePickerActivity.this);
int i = 0; int i = 0;
if (categories.size() > 0) { if (languages.size() > 0) {
Iterator<Map.Entry<Integer, String>> it = categories.entrySet().iterator(); Iterator<Map.Entry<String, String>> it = languages.entrySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry<Integer, String> pair = it.next(); Map.Entry<String, String> pair = it.next();
itemsLabel[i] = pair.getValue(); itemsLabelLanguage[i] = pair.getValue();
checkedItems[i] = false; checkedItemsLanguage[i] = false;
itemsKeyLanguage[i] = pair.getKey();
it.remove(); it.remove();
i++; i++;
} }
} }
dialogBuilder.setMultiChoiceItems(itemsLabel, checkedItems, (dialog, which, isChecked) -> { dialogBuilder.setMultiChoiceItems(itemsLabelLanguage, checkedItemsLanguage, (dialog, which, isChecked) -> {
// The user checked or unchecked a box // The user checked or unchecked a box
checkedItems[which] = isChecked; checkedItemsLanguage[which] = isChecked;
});
dialogBuilder.setOnDismissListener(dialogInterface -> {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
String between = "";
stringBuilder.append(between);
List<String> langs = new ArrayList<>();
int j = 0;
for(boolean itemcheked: checkedItemsLanguage){
if( itemcheked) {
langs.add(itemsKeyLanguage[j]);
String lang = itemsLabelLanguage[j];
if (lang != null && lang.trim().toLowerCase().compareTo("null") != 0) {
if (between.length() == 0) between = " ";
String tag = " " + lang + " ";
stringBuilder.append(tag);
stringBuilder.setSpan(new RoundedBackgroundSpan(InstancePickerActivity.this), stringBuilder.length() - tag.length(), stringBuilder.length() - tag.length() + tag.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
stringBuilder.append(" ");
}
}
j++;
}
instanceParams.setLanguagesOr(langs);
languages_view.setText(stringBuilder, TextView.BufferType.SPANNABLE);
mainLoader.setVisibility(View.VISIBLE);
viewModel.getInstances(instanceParams).observe(InstancePickerActivity.this, this::manageVIewInstance);
});
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.pickup_languages));
alertDialog.show();
});
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
checkedItemsCategory = new boolean[categories.size()];
itemsLabelCategory = new String[categories.size()];
itemsKeyCategory = new int[categories.size()];
pickup_categories.setOnClickListener(v -> {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(InstancePickerActivity.this);
int i = 0;
if (categories.size() > 0) {
Iterator<Map.Entry<Integer, String>> it = categories.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Integer, String> pair = it.next();
itemsLabelCategory[i] = pair.getValue();
itemsKeyCategory[i] = pair.getKey();
checkedItemsCategory[i] = false;
it.remove();
i++;
}
}
dialogBuilder.setMultiChoiceItems(itemsLabelCategory, checkedItemsCategory, (dialog, which, isChecked) -> {
// The user checked or unchecked a box
checkedItemsCategory[which] = isChecked;
}); });
dialogBuilder.setOnDismissListener(dialogInterface -> { dialogBuilder.setOnDismissListener(dialogInterface -> {
@ -134,10 +202,10 @@ public class InstancePickerActivity extends AppCompatActivity {
String between = ""; String between = "";
stringBuilder.append(between); stringBuilder.append(between);
List<Integer> cats = new ArrayList<>(); List<Integer> cats = new ArrayList<>();
for(boolean itemcheked: checkedItems){ for(boolean itemcheked: checkedItemsCategory){
if( itemcheked) { if( itemcheked) {
cats.add(j); cats.add(itemsKeyCategory[j]);
String cat = itemsLabel[j]; String cat = itemsLabelCategory[j];
if (cat != null && cat.trim().toLowerCase().compareTo("null") != 0) { if (cat != null && cat.trim().toLowerCase().compareTo("null") != 0) {
if (between.length() == 0) between = " "; if (between.length() == 0) between = " ";
String tag = " " + cat + " "; String tag = " " + cat + " ";
@ -156,7 +224,7 @@ public class InstancePickerActivity extends AppCompatActivity {
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> dialog.dismiss()); dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> dialog.dismiss());
AlertDialog alertDialog = dialogBuilder.create(); AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.action_playlist_create)); alertDialog.setTitle(getString(R.string.pickup_categories));
alertDialog.show(); alertDialog.show();
}); });

View File

@ -17,13 +17,13 @@ public class RoundedBackgroundSpan extends ReplacementSpan {
public RoundedBackgroundSpan(Context context) { public RoundedBackgroundSpan(Context context) {
super(); super();
backgroundColor = context.getResources().getColor(R.color.colorAccent_full); backgroundColor = context.getResources().getColor(R.color.tag_color);
textColor = context.getResources().getColor(R.color.browser_actions_bg_grey); textColor = context.getResources().getColor(R.color.tag_color_text);
} }
@Override @Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, @NotNull Paint paint) { public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, @NotNull Paint paint) {
RectF rect = new RectF(x, top, x + measureText(paint, text, start, end), bottom); RectF rect = new RectF(x, top+2, x + measureText(paint, text, start, end), bottom-1);
paint.setColor(backgroundColor); paint.setColor(backgroundColor);
canvas.drawRoundRect(rect, 8, 8, paint); canvas.drawRoundRect(rect, 8, 8, paint);
paint.setColor(textColor); paint.setColor(textColor);

View File

@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2l-5.5,9h11z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M17.5,17.5m-4.5,0a4.5,4.5 0,1 1,9 0a4.5,4.5 0,1 1,-9 0"/>
<path
android:fillColor="@android:color/white"
android:pathData="M3,13.5h8v8H3z"/>
</vector>

View File

@ -30,6 +30,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
> >
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/filters_container"
>
<Button <Button
android:id="@+id/pickup_categories" android:id="@+id/pickup_categories"
style="@style/Base.Widget.AppCompat.Button.Colored" style="@style/Base.Widget.AppCompat.Button.Colored"
@ -40,21 +45,41 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
/> />
<Button
android:id="@+id/pickup_languages"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/pickup_languages"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/pickup_categories"
/>
<TextView <TextView
android:layout_marginTop="5dp"
app:layout_constraintTop_toBottomOf="@+id/pickup_categories" app:layout_constraintTop_toBottomOf="@+id/pickup_categories"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
android:id="@+id/categories_view" android:id="@+id/categories_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:minHeight="50dp" android:layout_height="wrap_content"
android:layout_height="wrap_content" /> app:drawableStartCompat="@drawable/ic_baseline_category_24" />
<TextView
android:layout_marginTop="5dp"
app:layout_constraintTop_toBottomOf="@+id/categories_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:id="@+id/languages_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:drawableStartCompat="@drawable/ic_baseline_forum_24"/>
<TextView <TextView
android:layout_marginTop="14dp" android:layout_marginTop="14dp"
android:id="@+id/text_spinner" android:id="@+id/text_spinner"
app:layout_constraintTop_toBottomOf="@+id/categories_view" app:layout_constraintTop_toBottomOf="@+id/languages_view"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -62,16 +87,16 @@
android:labelFor="@+id/sensitive"/> android:labelFor="@+id/sensitive"/>
<Spinner <Spinner
app:layout_constraintTop_toBottomOf="@+id/categories_view" app:layout_constraintTop_toBottomOf="@+id/languages_view"
app:layout_constraintStart_toEndOf="@+id/text_spinner" app:layout_constraintStart_toEndOf="@+id/text_spinner"
android:id="@+id/sensitive" android:id="@+id/sensitive"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" /> android:layout_marginStart="10dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout <LinearLayout
app:layout_constraintTop_toBottomOf="@+id/text_spinner" app:layout_constraintTop_toBottomOf="@+id/filters_container"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"

View File

@ -8,7 +8,8 @@
<color name="colorPrimary_full">#212529</color> <color name="colorPrimary_full">#212529</color>
<color name="colorPrimaryDark_full">#000000</color> <color name="colorPrimaryDark_full">#000000</color>
<color name="colorAccent_full">#F2690D</color> <color name="colorAccent_full">#F2690D</color>
<color name="tag_color">#bbF2690D</color>
<color name="tag_color_text">#FAFAFA</color>
<color name="positive_thumbs">#2b90d9</color> <color name="positive_thumbs">#2b90d9</color>
<color name="negative_thumbs">#F44336</color> <color name="negative_thumbs">#F44336</color>