Fixed warnings

This commit is contained in:
zerrium 2021-03-19 18:47:50 +07:00
parent 10f5d91a42
commit 21950a4277
4 changed files with 16 additions and 13 deletions

View File

@ -30,7 +30,7 @@ public class KeywordsFilterAdapter extends RecyclerView.Adapter<KeywordsFilterDi
@NonNull
@Override
public KeywordsFilterDialogViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_keyword, parent, false);
final View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_keyword, parent, false);
return new KeywordsFilterDialogViewHolder(v);
}

View File

@ -42,13 +42,12 @@ public class FeedPostFetchService implements PostFetcher.PostFetchService {
nextCursor = result.getNextCursor();
hasNextPage = result.hasNextPage();
//Check caption if it doesn't contain any specified keywords in filter_keywords.xml
final List<Media> mediaResults = result.getFeedModels();
if(!settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)){
feedModels.addAll(mediaResults);
}else{
ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS));
if(settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)){
final ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS));
feedModels.addAll(new KeywordsFilterUtils(items).filter(mediaResults));
}else{
feedModels.addAll(mediaResults);
}
if (fetchListener != null) {

View File

@ -29,7 +29,14 @@ public final class KeywordsFilterDialog extends DialogFragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final DialogKeywordsFilterBinding dialogKeywordsFilterBinding = DialogKeywordsFilterBinding.inflate(inflater, container, false);
final Context context = getContext();
init(dialogKeywordsFilterBinding, getContext());
dialogKeywordsFilterBinding.btnOK.setOnClickListener(view -> this.dismiss());
return dialogKeywordsFilterBinding.getRoot();
}
private void init(DialogKeywordsFilterBinding dialogKeywordsFilterBinding, Context context){
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
final RecyclerView recyclerView = dialogKeywordsFilterBinding.recyclerKeyword;
recyclerView.setLayoutManager(linearLayoutManager);
@ -55,11 +62,5 @@ public final class KeywordsFilterDialog extends DialogFragment {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
editText.setText("");
});
dialogKeywordsFilterBinding.btnOK.setOnClickListener(view ->{
this.dismiss();
});
return dialogKeywordsFilterBinding.getRoot();
}
}

View File

@ -17,6 +17,7 @@ public final class KeywordsFilterUtils {
public boolean filter(final String caption){
if(caption == null) return false;
if(keywords.isEmpty()) return false;
final String temp = caption.toLowerCase(Locale.getDefault());
for(final String s:keywords){
if(temp.contains(s)) return true;
@ -28,6 +29,7 @@ public final class KeywordsFilterUtils {
if(media == null) return false;
final Caption c = media.getCaption();
if(c == null) return false;
if(keywords.isEmpty()) return false;
final String temp = c.getText().toLowerCase(LocaleUtils.getCurrentLocale());
for(final String s:keywords){
if(temp.contains(s)) return true;
@ -36,6 +38,7 @@ public final class KeywordsFilterUtils {
}
public List<Media> filter(final List<Media> media){
if(keywords.isEmpty()) return media;
if(media == null) return new ArrayList<>();
final List<Media> result= new ArrayList<>();