Small fixes
This commit is contained in:
parent
11209a5334
commit
e503a5ec95
|
@ -44,7 +44,6 @@ import app.fedilab.fedilabtube.client.APIResponse;
|
||||||
import app.fedilab.fedilabtube.client.entities.Instance;
|
import app.fedilab.fedilabtube.client.entities.Instance;
|
||||||
import app.fedilab.fedilabtube.client.entities.InstanceParams;
|
import app.fedilab.fedilabtube.client.entities.InstanceParams;
|
||||||
import app.fedilab.fedilabtube.drawer.InstanceAdapter;
|
import app.fedilab.fedilabtube.drawer.InstanceAdapter;
|
||||||
import app.fedilab.fedilabtube.helper.Helper;
|
|
||||||
import app.fedilab.fedilabtube.helper.RoundedBackgroundSpan;
|
import app.fedilab.fedilabtube.helper.RoundedBackgroundSpan;
|
||||||
import app.fedilab.fedilabtube.viewmodel.InstancesVM;
|
import app.fedilab.fedilabtube.viewmodel.InstancesVM;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
|
@ -56,14 +55,12 @@ import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
||||||
public class InstancePickerActivity extends AppCompatActivity {
|
public class InstancePickerActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
LinearLayoutManager mLayoutManager;
|
|
||||||
private RelativeLayout mainLoader, textviewNoAction;
|
private RelativeLayout mainLoader, textviewNoAction;
|
||||||
private List<Instance> instances;
|
|
||||||
private InstanceAdapter instanceAdapter;
|
|
||||||
boolean[] checkedItems;
|
boolean[] checkedItems;
|
||||||
String[] itemsLabel;
|
String[] itemsLabel;
|
||||||
InstanceParams instanceParams;
|
InstanceParams instanceParams;
|
||||||
private TextView categories_view;
|
private TextView categories_view;
|
||||||
|
private InstancesVM viewModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -74,9 +71,7 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
setContentView(R.layout.activity_instance_picker);
|
setContentView(R.layout.activity_instance_picker);
|
||||||
instances = new ArrayList<>();
|
|
||||||
|
|
||||||
RecyclerView lv_instances = findViewById(R.id.lv_instances);
|
|
||||||
mainLoader = findViewById(R.id.loader);
|
mainLoader = findViewById(R.id.loader);
|
||||||
textviewNoAction = findViewById(R.id.no_action);
|
textviewNoAction = findViewById(R.id.no_action);
|
||||||
mainLoader.setVisibility(View.VISIBLE);
|
mainLoader.setVisibility(View.VISIBLE);
|
||||||
|
@ -91,13 +86,14 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
sensitive.setAdapter(adapterChannel);
|
sensitive.setAdapter(adapterChannel);
|
||||||
|
|
||||||
|
|
||||||
InstancesVM viewModel = new ViewModelProvider(InstancePickerActivity.this).get(InstancesVM.class);
|
viewModel = new ViewModelProvider(InstancePickerActivity.this).get(InstancesVM.class);
|
||||||
|
|
||||||
sensitive.setSelection(1, false);
|
sensitive.setSelection(1, false);
|
||||||
sensitive.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
sensitive.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
instanceParams.setNsfwPolicy(channelSensitive[position]);
|
instanceParams.setNsfwPolicy(channelSensitive[position]);
|
||||||
|
mainLoader.setVisibility(View.VISIBLE);
|
||||||
viewModel.getInstances(instanceParams).observe(InstancePickerActivity.this, apiResponse -> manageVIewInstance(apiResponse));
|
viewModel.getInstances(instanceParams).observe(InstancePickerActivity.this, apiResponse -> manageVIewInstance(apiResponse));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,17 +103,16 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
checkedItems = new boolean[peertubeInformation.getCategories().size()];
|
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
|
||||||
itemsLabel= new String[peertubeInformation.getCategories().size()];
|
checkedItems = new boolean[categories.size()];
|
||||||
|
itemsLabel = new String[categories.size()];
|
||||||
|
|
||||||
pickup_categories.setOnClickListener(v -> {
|
pickup_categories.setOnClickListener(v -> {
|
||||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(InstancePickerActivity.this);
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(InstancePickerActivity.this);
|
||||||
|
|
||||||
|
|
||||||
LinkedHashMap<Integer, String> categories = peertubeInformation.getCategories();
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (categories != null && categories.size() > 0) {
|
if (categories.size() > 0) {
|
||||||
Iterator<Map.Entry<Integer, String>> it = categories.entrySet().iterator();
|
Iterator<Map.Entry<Integer, String>> it = categories.entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<Integer, String> pair = it.next();
|
Map.Entry<Integer, String> pair = it.next();
|
||||||
|
@ -155,6 +150,7 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
instanceParams.setCategoriesOr(cats);
|
instanceParams.setCategoriesOr(cats);
|
||||||
categories_view.setText(stringBuilder, TextView.BufferType.SPANNABLE);
|
categories_view.setText(stringBuilder, TextView.BufferType.SPANNABLE);
|
||||||
|
mainLoader.setVisibility(View.VISIBLE);
|
||||||
viewModel.getInstances(instanceParams).observe(InstancePickerActivity.this, this::manageVIewInstance);
|
viewModel.getInstances(instanceParams).observe(InstancePickerActivity.this, this::manageVIewInstance);
|
||||||
});
|
});
|
||||||
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> dialog.dismiss());
|
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> dialog.dismiss());
|
||||||
|
@ -164,21 +160,10 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mainLoader.setVisibility(View.VISIBLE);
|
mainLoader.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
instanceAdapter = new InstanceAdapter(this.instances);
|
|
||||||
|
|
||||||
lv_instances.setAdapter(instanceAdapter);
|
|
||||||
mLayoutManager = new LinearLayoutManager(InstancePickerActivity.this);
|
|
||||||
lv_instances.setLayoutManager(mLayoutManager);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setTitle(R.string.instances_picker);
|
setTitle(R.string.instances_picker);
|
||||||
|
|
||||||
|
|
||||||
instanceParams = new InstanceParams();
|
instanceParams = new InstanceParams();
|
||||||
instanceParams.setNsfwPolicy(channelSensitive[1]);
|
instanceParams.setNsfwPolicy(channelSensitive[1]);
|
||||||
viewModel.getInstances(instanceParams).observe(InstancePickerActivity.this, this::manageVIewInstance);
|
viewModel.getInstances(instanceParams).observe(InstancePickerActivity.this, this::manageVIewInstance);
|
||||||
|
@ -206,9 +191,12 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||||
List<Instance> instances = apiResponse.getInstances();
|
List<Instance> instances = apiResponse.getInstances();
|
||||||
if ((instances == null || instances.size() == 0)) {
|
if ((instances == null || instances.size() == 0)) {
|
||||||
textviewNoAction.setVisibility(View.VISIBLE);
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
return;
|
} else {
|
||||||
}
|
textviewNoAction.setVisibility(View.GONE);
|
||||||
this.instances.addAll(instances);
|
RecyclerView lv_instances = findViewById(R.id.lv_instances);
|
||||||
instanceAdapter.notifyItemRangeInserted(0, instances.size());
|
InstanceAdapter instanceAdapter = new InstanceAdapter(instances);
|
||||||
|
lv_instances.setAdapter(instanceAdapter);
|
||||||
|
lv_instances.setLayoutManager(new LinearLayoutManager(InstancePickerActivity.this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
navView.inflateMenu(R.menu.bottom_nav_menu);
|
navView.inflateMenu(R.menu.bottom_nav_menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (peertubeInformation == null) {
|
||||||
peertubeInformation = new PeertubeInformation();
|
peertubeInformation = new PeertubeInformation();
|
||||||
peertubeInformation.setCategories(new LinkedHashMap<>());
|
peertubeInformation.setCategories(new LinkedHashMap<>());
|
||||||
peertubeInformation.setLanguages(new LinkedHashMap<>());
|
peertubeInformation.setLanguages(new LinkedHashMap<>());
|
||||||
|
@ -86,6 +87,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
// Passing each menu ID as a set of Ids because each
|
// Passing each menu ID as a set of Ids because each
|
||||||
// menu should be considered as top level destinations.
|
// menu should be considered as top level destinations.
|
||||||
|
|
|
@ -599,8 +599,8 @@ public class PeertubeAPI {
|
||||||
if (instanceParams != null) {
|
if (instanceParams != null) {
|
||||||
if (instanceParams.getCategoriesOr() != null && instanceParams.getCategoriesOr().size() > 0) {
|
if (instanceParams.getCategoriesOr() != null && instanceParams.getCategoriesOr().size() > 0) {
|
||||||
StringBuilder parameters = new StringBuilder();
|
StringBuilder parameters = new StringBuilder();
|
||||||
for (String lang : instanceParams.getLanguagesOr())
|
for (int category : instanceParams.getCategoriesOr())
|
||||||
parameters.append("categoriesOr[]=").append(lang).append("&");
|
parameters.append("categoriesOr[]=").append(category).append("&");
|
||||||
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(15));
|
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(15));
|
||||||
params.put("categoriesOr[]", parameters.toString());
|
params.put("categoriesOr[]", parameters.toString());
|
||||||
}
|
}
|
||||||
|
@ -622,6 +622,7 @@ public class PeertubeAPI {
|
||||||
List<Instance> instances = parseInstances(jsonArray);
|
List<Instance> instances = parseInstances(jsonArray);
|
||||||
apiResponse.setInstances(instances);
|
apiResponse.setInstances(instances);
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
setError(e.getStatusCode(), e);
|
setError(e.getStatusCode(), e);
|
||||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -76,11 +76,11 @@ public class InstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||||
|
|
||||||
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
|
||||||
String between = "";
|
String between = "";
|
||||||
|
LinkedHashMap<Integer, String> info_cat = new LinkedHashMap<>(peertubeInformation.getCategories());
|
||||||
if (instance.getCategories() != null && instance.getCategories().size() > 0 && instance.getSpannableStringBuilder() == null) {
|
if (instance.getCategories() != null && instance.getCategories().size() > 0 && instance.getSpannableStringBuilder() == null) {
|
||||||
Iterator<Map.Entry<Integer, Integer>> it = instance.getCategories().entrySet().iterator();
|
Iterator<Map.Entry<Integer, Integer>> it = instance.getCategories().entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<Integer, Integer> pair = it.next();
|
Map.Entry<Integer, Integer> pair = it.next();
|
||||||
LinkedHashMap<Integer, String> info_cat = peertubeInformation.getCategories();
|
|
||||||
String cat = info_cat.get(pair.getKey());
|
String cat = info_cat.get(pair.getKey());
|
||||||
stringBuilder.append(between);
|
stringBuilder.append(between);
|
||||||
if (cat != null && cat.trim().toLowerCase().compareTo("null") != 0) {
|
if (cat != null && cat.trim().toLowerCase().compareTo("null") != 0) {
|
||||||
|
@ -97,13 +97,12 @@ public class InstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||||
holder.tags.setText(instance.getSpannableStringBuilder());
|
holder.tags.setText(instance.getSpannableStringBuilder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LinkedHashMap<String, String> info_lang = new LinkedHashMap<>(peertubeInformation.getLanguages());
|
||||||
StringBuilder languages = new StringBuilder();
|
StringBuilder languages = new StringBuilder();
|
||||||
if (instance.getLanguages() != null && instance.getLanguages().size() > 0) {
|
if (instance.getLanguages() != null && instance.getLanguages().size() > 0) {
|
||||||
Iterator<Map.Entry<Integer, String>> it = instance.getLanguages().entrySet().iterator();
|
Iterator<Map.Entry<Integer, String>> it = instance.getLanguages().entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry<Integer, String> pair = it.next();
|
Map.Entry<Integer, String> pair = it.next();
|
||||||
LinkedHashMap<String, String> info_lang = peertubeInformation.getLanguages();
|
|
||||||
languages.append(info_lang.get(pair.getValue())).append(" ");
|
languages.append(info_lang.get(pair.getValue())).append(" ");
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_marginTop="10dp"
|
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/categories_view"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
@ -60,13 +60,14 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/sensitive_video"
|
android:text="@string/sensitive_video"
|
||||||
android:labelFor="@+id/sensitive"/>
|
android:labelFor="@+id/sensitive"/>
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
app:layout_constraintTop_toBottomOf="@+id/categories_view"
|
app:layout_constraintTop_toBottomOf="@+id/categories_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="14dp" />
|
android:layout_marginStart="10dp" />
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
Loading…
Reference in New Issue