Commit ba8f56f1 authored by Mathilde BALLOUHEY's avatar Mathilde BALLOUHEY
Browse files

Ajout option de recherche par fiche ou par gif

parent c004c383
Pipeline #23340 failed with stages
in 2 minutes and 31 seconds
......@@ -14,9 +14,9 @@ import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
......@@ -37,7 +37,8 @@ import fr.iutnantes.miar.dndgenerator.api.tenor.TenorArgs;
public class DisplayGIFActivity extends AppCompatActivity {
private static String TAG = "DisplayGIFActivity :: ";
private static final String GIF_LIST = "gifList";
private boolean m_searchOnChange = true;
private boolean m_searchPostChange = true;
private boolean m_enableResearchListener = false;
private int m_nbResult;
private Context m_context = this;
private DnDSheet m_sheet;
......@@ -50,6 +51,7 @@ public class DisplayGIFActivity extends AppCompatActivity {
private RecyclerView rclr_displayGif_relatedGif;
private SeekBar skbr_displayGif_nbResult;
private Switch swtch_displayGif_isNSFW;
private RadioButton rdbtn_displayGif_withSheet, rdbtn_displayGif_withGif;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -64,6 +66,8 @@ public class DisplayGIFActivity extends AppCompatActivity {
txt_displayGif_recherche = findViewById(R.id.txt_displayGif_recherche);
skbr_displayGif_nbResult = findViewById(R.id.skbr_displayGif_nbResult);
swtch_displayGif_isNSFW = findViewById(R.id.swtch_displayGif_isNSFW);
rdbtn_displayGif_withSheet = findViewById(R.id.rdbtn_displayGif_withSheet);
rdbtn_displayGif_withGif = findViewById(R.id.rdbtn_displayGif_withGif);
Intent v_intent = getIntent();
Bundle v_bundle = v_intent.getExtras();
......@@ -73,10 +77,11 @@ public class DisplayGIFActivity extends AppCompatActivity {
if(savedInstanceState != null) {
savedInstanceState.clear();
}
//Recycler View
m_adapter = new ListGifAdapter(m_listGif, this);
rclr_displayGif_relatedGif.setAdapter(m_adapter);
rclr_displayGif_relatedGif.setLayoutManager(new GridLayoutManager(this, 2));
// Labels
lbl_displayGif_name.setText(m_sheet.gif.toString());
String v_tags = "";
if(m_sheet.gif.tags.size() > 0) {
......@@ -89,13 +94,14 @@ public class DisplayGIFActivity extends AppCompatActivity {
if (v_tags.isEmpty()){
lbl_displayGif_tag.setText("No tags attached on this GIF");
}
// GIF
String v_urlGif = Objects.requireNonNull(m_sheet.gif.media.get(GIFFormat.GIF)).url;
Glide.with(this)
.load(v_urlGif)
.into(img_displayGif_gif);
// Listeners
txt_displayGif_nbResult.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
......@@ -109,21 +115,20 @@ public class DisplayGIFActivity extends AppCompatActivity {
@Override
public void afterTextChanged(Editable editable) {
if(m_listGif == null || !m_searchOnChange) {
if(m_listGif == null || !m_searchPostChange) {
return;
}
if(m_asyncTaskGetGifList != null) {
m_asyncTaskGetGifList.cancel(true);
}
m_asyncTaskGetGifList = new AsyncTaskGetGifList();
m_asyncTaskGetGifList.execute((Nullable) null);
launchAsyncSearch();
}
});
txt_displayGif_recherche.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if(m_enableResearchListener) {
rdbtn_displayGif_withGif.setChecked(false);
rdbtn_displayGif_withSheet.setChecked(false);
}
}
@Override
......@@ -133,11 +138,12 @@ public class DisplayGIFActivity extends AppCompatActivity {
@Override
public void afterTextChanged(Editable editable) {
if(m_asyncTaskGetGifList != null) {
m_asyncTaskGetGifList.cancel(true);
if(m_enableResearchListener) {
launchAsyncSearch();
if (txt_displayGif_recherche.getText().toString().isEmpty()) {
rdbtn_displayGif_withSheet.setChecked(true);
}
}
m_asyncTaskGetGifList = new AsyncTaskGetGifList();
m_asyncTaskGetGifList.execute((Nullable) null);
}
});
......@@ -149,38 +155,42 @@ public class DisplayGIFActivity extends AppCompatActivity {
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
m_searchOnChange = false;
m_searchPostChange = false;
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
m_searchOnChange = true;
if(m_asyncTaskGetGifList != null) {
m_asyncTaskGetGifList.cancel(true);
}
m_asyncTaskGetGifList = new AsyncTaskGetGifList();
m_asyncTaskGetGifList.execute((Nullable) null);
m_searchPostChange = true;
launchAsyncSearch();
}
});
swtch_displayGif_isNSFW.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(m_asyncTaskGetGifList != null) {
m_asyncTaskGetGifList.cancel(true);
}
m_asyncTaskGetGifList = new AsyncTaskGetGifList();
m_asyncTaskGetGifList.execute((Nullable) null);
}
swtch_displayGif_isNSFW.setOnCheckedChangeListener((compoundButton, b) -> {
launchAsyncSearch();
});
if(txt_displayGif_recherche.getText().toString().isEmpty()){
if(m_asyncTaskGetGifList != null) {
m_asyncTaskGetGifList.cancel(true);
}
m_asyncTaskGetGifList = new AsyncTaskGetGifList();
m_asyncTaskGetGifList.execute((Nullable) null);
View.OnClickListener v_onClickRadioButtonListener = view -> {
m_enableResearchListener = false;
txt_displayGif_recherche.setText("");
launchAsyncSearch();
m_enableResearchListener = true;
};
rdbtn_displayGif_withSheet.setOnClickListener(v_onClickRadioButtonListener);
rdbtn_displayGif_withGif.setOnClickListener(v_onClickRadioButtonListener);
if(rdbtn_displayGif_withSheet.isChecked() || rdbtn_displayGif_withGif.isChecked()){
launchAsyncSearch();
}
}
private void launchAsyncSearch() {
if (m_asyncTaskGetGifList != null) {
m_asyncTaskGetGifList.cancel(true);
}
m_asyncTaskGetGifList = new AsyncTaskGetGifList();
m_asyncTaskGetGifList.execute((Nullable) null);
}
private int checkNbResult() {
int v_nbResult = 0;
try {
......@@ -209,6 +219,9 @@ public class DisplayGIFActivity extends AppCompatActivity {
String v_recherche = m_sheet.searchGIF;
Log.d(TAG, v_recherche);
TenorArgs v_tenorArgs = TenorArgs.GIF_SAFE;
if(rdbtn_displayGif_withGif.isChecked()) {
v_recherche = m_sheet.gif.searchQuery;
}
if(!txt_displayGif_recherche.getText().toString().isEmpty()) {
v_recherche = txt_displayGif_recherche.getText().toString();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment