|
|
@ -6,6 +6,7 @@ import android.view.LayoutInflater; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.widget.EditText; |
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.Nullable; |
|
|
@ -16,6 +17,7 @@ import androidx.recyclerview.widget.RecyclerView; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import awais.instagrabber.R; |
|
|
|
import awais.instagrabber.adapters.KeywordsFilterAdapter; |
|
|
|
import awais.instagrabber.databinding.DialogKeywordsFilterBinding; |
|
|
|
import awais.instagrabber.utils.Constants; |
|
|
@ -23,24 +25,23 @@ import awais.instagrabber.utils.SettingsHelper; |
|
|
|
|
|
|
|
public final class KeywordsFilterDialog extends DialogFragment { |
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Override |
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
|
|
|
DialogKeywordsFilterBinding dialogKeywordsFilterBinding = DialogKeywordsFilterBinding.inflate(inflater, container, false); |
|
|
|
final DialogKeywordsFilterBinding dialogKeywordsFilterBinding = DialogKeywordsFilterBinding.inflate(inflater, container, false); |
|
|
|
|
|
|
|
final Context context = getContext(); |
|
|
|
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context); |
|
|
|
final RecyclerView recyclerView = dialogKeywordsFilterBinding.recycler; |
|
|
|
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context); |
|
|
|
final RecyclerView recyclerView = dialogKeywordsFilterBinding.recyclerKeyword; |
|
|
|
recyclerView.setLayoutManager(linearLayoutManager); |
|
|
|
|
|
|
|
SettingsHelper settingsHelper = new SettingsHelper(context); |
|
|
|
ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS)); |
|
|
|
KeywordsFilterAdapter adapter = new KeywordsFilterAdapter(context, items); |
|
|
|
final SettingsHelper settingsHelper = new SettingsHelper(context); |
|
|
|
final ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS)); |
|
|
|
final KeywordsFilterAdapter adapter = new KeywordsFilterAdapter(context, items); |
|
|
|
recyclerView.setAdapter(adapter); |
|
|
|
|
|
|
|
final EditText editText = dialogKeywordsFilterBinding.editText; |
|
|
|
|
|
|
|
dialogKeywordsFilterBinding.addIcon.setOnClickListener(view ->{ |
|
|
|
dialogKeywordsFilterBinding.btnAdd.setOnClickListener(view ->{ |
|
|
|
final String s = editText.getText().toString(); |
|
|
|
if(s.isEmpty()) return; |
|
|
|
if(items.contains(s)) { |
|
|
@ -49,13 +50,16 @@ public final class KeywordsFilterDialog extends DialogFragment { |
|
|
|
} |
|
|
|
items.add(s); |
|
|
|
settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items)); |
|
|
|
adapter.notifyDataSetChanged(); |
|
|
|
adapter.notifyItemInserted(items.size()); |
|
|
|
final String message = context.getString(R.string.added_keywords).replace("{0}", s); |
|
|
|
Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); |
|
|
|
editText.setText(""); |
|
|
|
}); |
|
|
|
|
|
|
|
dialogKeywordsFilterBinding.btnOK.setOnClickListener(view ->{ |
|
|
|
this.dismiss(); |
|
|
|
}); |
|
|
|
|
|
|
|
return super.onCreateView(inflater, container, savedInstanceState); |
|
|
|
return dialogKeywordsFilterBinding.getRoot(); |
|
|
|
} |
|
|
|
} |