From 015a2f32899b53237d03b708520b992f78e2acbe Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 18 Sep 2020 12:03:35 +0200 Subject: [PATCH] Some fixes --- app/src/acad/res/values/strings.xml | 1 + app/src/full/res/values/strings.xml | 1 + .../fedilabtube/InstancePickerActivity.java | 104 +++++++++++++++--- .../helper/RoundedBackgroundSpan.java | 6 +- .../res/drawable/ic_baseline_category_24.xml | 16 +++ .../res/layout/activity_instance_picker.xml | 37 ++++++- app/src/main/res/values/colors.xml | 3 +- 7 files changed, 140 insertions(+), 28 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_category_24.xml diff --git a/app/src/acad/res/values/strings.xml b/app/src/acad/res/values/strings.xml index 6eaca23..3f0287b 100644 --- a/app/src/acad/res/values/strings.xml +++ b/app/src/acad/res/values/strings.xml @@ -234,4 +234,5 @@ Blur Display No opinion + Pickup languages diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml index 5b6d916..ea7c315 100644 --- a/app/src/full/res/values/strings.xml +++ b/app/src/full/res/values/strings.xml @@ -250,4 +250,5 @@ Help Pickup categories + Pickup languages \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/InstancePickerActivity.java b/app/src/main/java/app/fedilab/fedilabtube/InstancePickerActivity.java index c050997..e2a07a2 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/InstancePickerActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/InstancePickerActivity.java @@ -56,10 +56,14 @@ public class InstancePickerActivity extends AppCompatActivity { private RelativeLayout mainLoader, textviewNoAction; - boolean[] checkedItems; - String[] itemsLabel; + boolean[] checkedItemsCategory; + int[] itemsKeyCategory; + String[] itemsLabelCategory; + boolean[] checkedItemsLanguage; + String[] itemsKeyLanguage; + String[] itemsLabelLanguage; InstanceParams instanceParams; - private TextView categories_view; + private TextView categories_view, languages_view; private InstancesVM viewModel; @Override @@ -76,7 +80,9 @@ public class InstancePickerActivity extends AppCompatActivity { textviewNoAction = findViewById(R.id.no_action); mainLoader.setVisibility(View.VISIBLE); Button pickup_categories = findViewById(R.id.pickup_categories); + Button pickup_languages = findViewById(R.id.pickup_languages); categories_view = findViewById(R.id.categories_view); + languages_view = findViewById(R.id.languages_view); Spinner sensitive = findViewById(R.id.sensitive); String[] channelSensitive = new String[]{"do_not_list", "blur", "display", "no_opinion"}; @@ -103,29 +109,91 @@ public class InstancePickerActivity extends AppCompatActivity { } }); - LinkedHashMap categories = new LinkedHashMap<>(peertubeInformation.getCategories()); - checkedItems = new boolean[categories.size()]; - itemsLabel = new String[categories.size()]; - pickup_categories.setOnClickListener(v -> { + LinkedHashMap 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); int i = 0; - if (categories.size() > 0) { - Iterator> it = categories.entrySet().iterator(); + if (languages.size() > 0) { + Iterator> it = languages.entrySet().iterator(); while (it.hasNext()) { - Map.Entry pair = it.next(); - itemsLabel[i] = pair.getValue(); - checkedItems[i] = false; + Map.Entry pair = it.next(); + itemsLabelLanguage[i] = pair.getValue(); + checkedItemsLanguage[i] = false; + itemsKeyLanguage[i] = pair.getKey(); it.remove(); i++; } } - dialogBuilder.setMultiChoiceItems(itemsLabel, checkedItems, (dialog, which, isChecked) -> { + dialogBuilder.setMultiChoiceItems(itemsLabelLanguage, checkedItemsLanguage, (dialog, which, isChecked) -> { // 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 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 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> it = categories.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry 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 -> { @@ -134,10 +202,10 @@ public class InstancePickerActivity extends AppCompatActivity { String between = ""; stringBuilder.append(between); List cats = new ArrayList<>(); - for(boolean itemcheked: checkedItems){ + for(boolean itemcheked: checkedItemsCategory){ if( itemcheked) { - cats.add(j); - String cat = itemsLabel[j]; + cats.add(itemsKeyCategory[j]); + String cat = itemsLabelCategory[j]; if (cat != null && cat.trim().toLowerCase().compareTo("null") != 0) { if (between.length() == 0) between = " "; String tag = " " + cat + " "; @@ -156,7 +224,7 @@ public class InstancePickerActivity extends AppCompatActivity { dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> dialog.dismiss()); AlertDialog alertDialog = dialogBuilder.create(); - alertDialog.setTitle(getString(R.string.action_playlist_create)); + alertDialog.setTitle(getString(R.string.pickup_categories)); alertDialog.show(); }); diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/RoundedBackgroundSpan.java b/app/src/main/java/app/fedilab/fedilabtube/helper/RoundedBackgroundSpan.java index 86ac758..bffd214 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/helper/RoundedBackgroundSpan.java +++ b/app/src/main/java/app/fedilab/fedilabtube/helper/RoundedBackgroundSpan.java @@ -17,13 +17,13 @@ public class RoundedBackgroundSpan extends ReplacementSpan { public RoundedBackgroundSpan(Context context) { super(); - backgroundColor = context.getResources().getColor(R.color.colorAccent_full); - textColor = context.getResources().getColor(R.color.browser_actions_bg_grey); + backgroundColor = context.getResources().getColor(R.color.tag_color); + textColor = context.getResources().getColor(R.color.tag_color_text); } @Override 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); canvas.drawRoundRect(rect, 8, 8, paint); paint.setColor(textColor); diff --git a/app/src/main/res/drawable/ic_baseline_category_24.xml b/app/src/main/res/drawable/ic_baseline_category_24.xml new file mode 100644 index 0000000..b45741e --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_category_24.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/layout/activity_instance_picker.xml b/app/src/main/res/layout/activity_instance_picker.xml index 2c0bd6e..d0d1046 100644 --- a/app/src/main/res/layout/activity_instance_picker.xml +++ b/app/src/main/res/layout/activity_instance_picker.xml @@ -30,6 +30,11 @@ android:layout_width="match_parent" android:layout_height="match_parent" > +