Some fixes

This commit is contained in:
Thomas 2020-11-27 18:56:37 +01:00
parent e0907f1dc8
commit e15252a0f8
1 changed files with 32 additions and 48 deletions

View File

@ -21,12 +21,8 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.Spinner;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
@ -42,9 +38,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import app.fedilab.fedilabtube.client.entities.SepiaSearch; import app.fedilab.fedilabtube.client.entities.SepiaSearch;
import app.fedilab.fedilabtube.databinding.ActivitySepiaSearchBinding;
import app.fedilab.fedilabtube.fragment.DisplaySepiaSearchFragment; import app.fedilab.fedilabtube.fragment.DisplaySepiaSearchFragment;
import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.helper.Helper;
import mabbas007.tagsedittext.TagsEditText;
import static app.fedilab.fedilabtube.PeertubeActivity.hideKeyboard; import static app.fedilab.fedilabtube.PeertubeActivity.hideKeyboard;
import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation; import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation;
@ -54,15 +50,17 @@ public class SepiaSearchActivity extends AppCompatActivity {
private SepiaSearch sepiaSearchVideo, sepiaSearchChannel; private SepiaSearch sepiaSearchVideo, sepiaSearchChannel;
private TagsEditText sepia_element_all_of_tags, sepia_element_one_of_tags;
private MaterialSearchBar searchBar; private ActivitySepiaSearchBinding binding;
private ConstraintLayout filter_elements;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sepia_search); binding = ActivitySepiaSearchBinding.inflate(getLayoutInflater());
View rootView = binding.getRoot();
setContentView(rootView);
sepiaSearchVideo = new SepiaSearch(); sepiaSearchVideo = new SepiaSearch();
sepiaSearchChannel = new SepiaSearch(); sepiaSearchChannel = new SepiaSearch();
@ -76,21 +74,18 @@ public class SepiaSearchActivity extends AppCompatActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Button filter = findViewById(R.id.filter); binding.filter.setOnClickListener(view -> {
filter_elements = findViewById(R.id.filter_elements); if (binding.filterElements.getVisibility() == View.VISIBLE) {
filter.setOnClickListener(view -> { binding.filterElements.setVisibility(View.GONE);
if (filter_elements.getVisibility() == View.VISIBLE) {
filter_elements.setVisibility(View.GONE);
} else { } else {
filter_elements.setVisibility(View.VISIBLE); binding.filterElements.setVisibility(View.VISIBLE);
} }
}); });
RadioGroup sepia_element_nsfw = findViewById(R.id.sepia_element_nsfw);
sepia_element_nsfw.setOnCheckedChangeListener((group, checkedId) -> sepiaSearchVideo.setNsfw(checkedId != R.id.sepia_element_nsfw_no));
RadioGroup radio_date = findViewById(R.id.radio_date); binding.sepiaElementNsfw.setOnCheckedChangeListener((group, checkedId) -> sepiaSearchVideo.setNsfw(checkedId != R.id.sepia_element_nsfw_no));
radio_date.setOnCheckedChangeListener((group, checkedId) -> {
binding.radioDate.setOnCheckedChangeListener((group, checkedId) -> {
if (checkedId == R.id.sepia_element_published_date_today) { if (checkedId == R.id.sepia_element_published_date_today) {
Calendar cal = GregorianCalendar.getInstance(); Calendar cal = GregorianCalendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.HOUR_OF_DAY, 0);
@ -122,8 +117,7 @@ public class SepiaSearchActivity extends AppCompatActivity {
}); });
RadioGroup duration = findViewById(R.id.duration); binding.duration.setOnCheckedChangeListener((group, checkedId) -> {
duration.setOnCheckedChangeListener((group, checkedId) -> {
if (checkedId == R.id.sepia_element_duration_short) { if (checkedId == R.id.sepia_element_duration_short) {
sepiaSearchVideo.setDurationMin(0); sepiaSearchVideo.setDurationMin(0);
sepiaSearchVideo.setDurationMax(240); sepiaSearchVideo.setDurationMax(240);
@ -140,11 +134,10 @@ public class SepiaSearchActivity extends AppCompatActivity {
}); });
Spinner sort_by = findViewById(R.id.sort_by);
ArrayAdapter<String> adapterSortBy = new ArrayAdapter<>(SepiaSearchActivity.this, ArrayAdapter<String> adapterSortBy = new ArrayAdapter<>(SepiaSearchActivity.this,
android.R.layout.simple_spinner_dropdown_item, getResources().getStringArray(R.array.sort_by_array)); android.R.layout.simple_spinner_dropdown_item, getResources().getStringArray(R.array.sort_by_array));
sort_by.setAdapter(adapterSortBy); binding.sortBy.setAdapter(adapterSortBy);
sort_by.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { binding.sortBy.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) {
String orderby, channelOrderBy; String orderby, channelOrderBy;
@ -171,12 +164,6 @@ public class SepiaSearchActivity extends AppCompatActivity {
} }
}); });
Spinner sepia_element_category = findViewById(R.id.sepia_element_category);
Spinner sepia_element_license = findViewById(R.id.sepia_element_license);
Spinner sepia_element_language = findViewById(R.id.sepia_element_language);
sepia_element_all_of_tags = findViewById(R.id.sepia_element_all_of_tags);
sepia_element_one_of_tags = findViewById(R.id.sepia_element_one_of_tags);
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories()); LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences()); LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
@ -203,7 +190,7 @@ public class SepiaSearchActivity extends AppCompatActivity {
} }
ArrayAdapter<String> adapterCatgories = new ArrayAdapter<>(SepiaSearchActivity.this, ArrayAdapter<String> adapterCatgories = new ArrayAdapter<>(SepiaSearchActivity.this,
android.R.layout.simple_spinner_dropdown_item, categoriesA); android.R.layout.simple_spinner_dropdown_item, categoriesA);
sepia_element_category.setAdapter(adapterCatgories); binding.sepiaElementCategory.setAdapter(adapterCatgories);
//Populate licenses //Populate licenses
@ -222,7 +209,7 @@ public class SepiaSearchActivity extends AppCompatActivity {
} }
ArrayAdapter<String> adapterLicenses = new ArrayAdapter<>(SepiaSearchActivity.this, ArrayAdapter<String> adapterLicenses = new ArrayAdapter<>(SepiaSearchActivity.this,
android.R.layout.simple_spinner_dropdown_item, licensesA); android.R.layout.simple_spinner_dropdown_item, licensesA);
sepia_element_license.setAdapter(adapterLicenses); binding.sepiaElementLicense.setAdapter(adapterLicenses);
//Populate languages //Populate languages
String[] languagesA = new String[languages.size() + 1]; String[] languagesA = new String[languages.size() + 1];
@ -240,10 +227,10 @@ public class SepiaSearchActivity extends AppCompatActivity {
} }
ArrayAdapter<String> adapterLanguages = new ArrayAdapter<>(SepiaSearchActivity.this, ArrayAdapter<String> adapterLanguages = new ArrayAdapter<>(SepiaSearchActivity.this,
android.R.layout.simple_spinner_dropdown_item, languagesA); android.R.layout.simple_spinner_dropdown_item, languagesA);
sepia_element_language.setAdapter(adapterLanguages); binding.sepiaElementLanguage.setAdapter(adapterLanguages);
sepia_element_license.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { binding.sepiaElementLicense.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) {
updateLicensePosition(position); updateLicensePosition(position);
@ -255,7 +242,7 @@ public class SepiaSearchActivity extends AppCompatActivity {
} }
}); });
//Manage categories //Manage categories
sepia_element_category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { binding.sepiaElementCategory.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) {
updateCategoryPosition(position); updateCategoryPosition(position);
@ -268,7 +255,7 @@ public class SepiaSearchActivity extends AppCompatActivity {
}); });
//Manage languages //Manage languages
sepia_element_language.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { binding.sepiaElementLanguage.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) {
updateLanguagesPosition(position); updateLanguagesPosition(position);
@ -281,9 +268,7 @@ public class SepiaSearchActivity extends AppCompatActivity {
}); });
searchBar = findViewById(R.id.searchBar); binding.searchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
searchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
@Override @Override
public void onSearchStateChanged(boolean enabled) { public void onSearchStateChanged(boolean enabled) {
@ -299,22 +284,21 @@ public class SepiaSearchActivity extends AppCompatActivity {
makeSearch(); makeSearch();
} }
}); });
Button apply_filter = findViewById(R.id.apply_filter); binding.applyFilter.setOnClickListener(v -> makeSearch());
apply_filter.setOnClickListener(v -> makeSearch());
searchBar.openSearch(); binding.searchBar.openSearch();
} }
private void makeSearch() { private void makeSearch() {
hideKeyboard(SepiaSearchActivity.this); hideKeyboard(SepiaSearchActivity.this);
sepiaSearchVideo.setStart("0"); sepiaSearchVideo.setStart("0");
if (sepia_element_one_of_tags.getTags().size() > 0) { if (binding.sepiaElementOneOfTags.getTags().size() > 0) {
sepiaSearchVideo.setTagsOneOf(sepia_element_one_of_tags.getTags()); sepiaSearchVideo.setTagsOneOf(binding.sepiaElementOneOfTags.getTags());
} else { } else {
sepiaSearchVideo.setTagsOneOf(null); sepiaSearchVideo.setTagsOneOf(null);
} }
if (sepia_element_all_of_tags.getTags().size() > 0) { if (binding.sepiaElementAllOfTags.getTags().size() > 0) {
sepiaSearchVideo.setTagsAllOf(sepia_element_all_of_tags.getTags()); sepiaSearchVideo.setTagsAllOf(binding.sepiaElementAllOfTags.getTags());
} else { } else {
sepiaSearchVideo.setTagsAllOf(null); sepiaSearchVideo.setTagsAllOf(null);
} }
@ -322,8 +306,8 @@ public class SepiaSearchActivity extends AppCompatActivity {
Fragment fragment = getSupportFragmentManager().findFragmentByTag("SEPIA_SEARCH"); Fragment fragment = getSupportFragmentManager().findFragmentByTag("SEPIA_SEARCH");
if (fragment != null) if (fragment != null)
getSupportFragmentManager().beginTransaction().remove(fragment).commit(); getSupportFragmentManager().beginTransaction().remove(fragment).commit();
filter_elements.setVisibility(View.GONE); binding.filterElements.setVisibility(View.GONE);
sepiaSearchVideo.setSearch(searchBar.getText()); sepiaSearchVideo.setSearch(binding.searchBar.getText());
DisplaySepiaSearchFragment displaySepiaSearchFragment = new DisplaySepiaSearchFragment(); DisplaySepiaSearchFragment displaySepiaSearchFragment = new DisplaySepiaSearchFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable("sepiaSearchVideo", sepiaSearchVideo); bundle.putParcelable("sepiaSearchVideo", sepiaSearchVideo);