Commit b1b4b238 authored by Mathieu Féry (Mathius)'s avatar Mathieu Féry (Mathius)
Browse files

Merge manually jonctFrontApi in api

parents c2443b62 ba8f56f1
Pipeline #23342 failed with stages
in 2 minutes and 32 seconds
package fr.iutnantes.miar.dndgenerator;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
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;
......@@ -35,17 +37,21 @@ 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;
private List<GIFObject> m_listGif;
private ListGifAdapter m_adapter;
private AsyncTaskGetGifList m_asyncTaskGetGifList;
private TextView lbl_displayGif_name, lbl_displayGif_tag;
private EditText txt_displayGif_nbResult, txt_displayGif_recherche;
private ImageView img_displayGif_gif;
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) {
......@@ -60,13 +66,18 @@ 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();
m_sheet = (DnDSheet) v_bundle.getSerializable(DisplayResultActivity.SHEET);
setDataList(savedInstanceState, checkNbResult());
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));
......@@ -82,13 +93,13 @@ public class DisplayGIFActivity extends AppCompatActivity {
if (v_tags.isEmpty()){
lbl_displayGif_tag.setText("No tags attached on this GIF");
}
String v_urlGif = Objects.requireNonNull(m_sheet.getGIF().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) {
......@@ -102,17 +113,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;
}
doSearch();
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
......@@ -122,7 +136,12 @@ public class DisplayGIFActivity extends AppCompatActivity {
@Override
public void afterTextChanged(Editable editable) {
doSearch();
if(m_enableResearchListener) {
launchAsyncSearch();
if (txt_displayGif_recherche.getText().toString().isEmpty()) {
rdbtn_displayGif_withSheet.setChecked(true);
}
}
}
});
......@@ -134,23 +153,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;
doSearch();
m_searchPostChange = true;
launchAsyncSearch();
}
});
swtch_displayGif_isNSFW.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
doSearch();
}
swtch_displayGif_isNSFW.setOnCheckedChangeListener((compoundButton, b) -> {
launchAsyncSearch();
});
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 {
......@@ -176,9 +214,13 @@ public class DisplayGIFActivity extends AppCompatActivity {
}
private void doSearch() {
int v_nbResult = checkNbResult();
String v_recherche = m_sheet.getGIF().searchQuery;
int v_nbResult = m_nbResult;
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.getGIF().searchQuery;
}
if(!txt_displayGif_recherche.getText().toString().isEmpty()) {
v_recherche = txt_displayGif_recherche.getText().toString();
}
......@@ -190,7 +232,6 @@ public class DisplayGIFActivity extends AppCompatActivity {
v_recherche, v_tenorArgs.fork(v_nbResult, m_sheet.getGIF()));
m_listGif.clear();
m_listGif.addAll(v_newGifs);
m_adapter.notifyDataSetChanged();
}
}
......@@ -199,4 +240,24 @@ public class DisplayGIFActivity extends AppCompatActivity {
outState.putSerializable(GIF_LIST, (Serializable) m_listGif);
super.onSaveInstanceState(outState);
}
private class AsyncTaskGetGifList extends AsyncTask<Nullable, String, Nullable> {
@Override
protected void onPreExecute() {
super.onPreExecute();
m_nbResult = checkNbResult();
}
@Override
protected Nullable doInBackground(Nullable... nullables) {
doSearch();
return null;
}
@Override
protected void onPostExecute(Nullable nullable) {
super.onPostExecute(nullable);
m_adapter.notifyDataSetChanged();
}
}
}
\ No newline at end of file
......@@ -2,22 +2,28 @@ package fr.iutnantes.miar.dndgenerator;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Toast;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import fr.iutnantes.miar.dndgenerator.adapter.ListResultsAdapter;
......@@ -36,7 +42,8 @@ public class HomeActivity extends AppCompatActivity {
Spinner spnr_home_system, spnr_home_class;
EditText txt_home_nbResult;
SeekBar skbr_home_nbResult;
Button btn_home_generate;
Button btn_home_generate, btn_home_delFav;
RadioButton rdbtn_home_bySystem, rdbtn_home_byClass;
RecyclerView rclr_home_favourites;
private ListResultsAdapter m_adapter;
......@@ -53,6 +60,9 @@ public class HomeActivity extends AppCompatActivity {
txt_home_nbResult = findViewById(R.id.txt_home_nbResult);
skbr_home_nbResult = findViewById(R.id.skbr_home_nbResult);
btn_home_generate = findViewById(R.id.btn_home_generate);
btn_home_delFav = findViewById(R.id.btn_home_delFav);
rdbtn_home_bySystem = findViewById(R.id.rdbtn_home_bySystem);
rdbtn_home_byClass = findViewById(R.id.rdbtn_home_byClass);
rclr_home_favourites = findViewById(R.id.rclr_home_favourites);
List<String> v_lstSystemName = new ArrayList<>();
......@@ -119,6 +129,15 @@ public class HomeActivity extends AppCompatActivity {
startActivity(v_intent);
});
btn_home_delFav.setOnClickListener(onClickDelFav());
View.OnClickListener v_rdbtnListener = view -> {
sortFavourites();
m_adapter.notifyDataSetChanged();
};
rdbtn_home_bySystem.setOnClickListener(v_rdbtnListener);
rdbtn_home_byClass.setOnClickListener(v_rdbtnListener);
m_favourites = DnDSheet.getFavs(this);
......@@ -130,8 +149,60 @@ public class HomeActivity extends AppCompatActivity {
@Override
protected void onResume() {
super.onResume();
AsyncTaskGetFavourites v_asyncTaskGetFavourites = new AsyncTaskGetFavourites();
v_asyncTaskGetFavourites.execute((Nullable) null);
}
private void getFav() {
m_favourites.clear();
m_favourites.addAll(DnDSheet.getFavs(this));
m_adapter.notifyDataSetChanged();
sortFavourites();
}
private void sortFavourites() {
if(rdbtn_home_bySystem.isChecked()) {
Collections.sort(m_favourites, DnDSheet.COMPARATOR_BY_SYSTEM);
}
else {
Collections.sort(m_favourites, DnDSheet.COMPARATOR_BY_CLASS);
}
}
private View.OnClickListener onClickDelFav() {
View.OnClickListener v_onClickListener = view -> {
AlertDialog.Builder v_builder = new AlertDialog.Builder(HomeActivity.this);
v_builder.setMessage("Do you realy what to delete all favourites ?");
v_builder.setPositiveButton("OK", (dialogInterface, i) -> {
DnDSheet.removeAllFavs(HomeActivity.this);
m_favourites.clear();
m_adapter.notifyDataSetChanged();
});
v_builder.setNegativeButton("CANCEL", (dialogInterface, i) -> {});
v_builder.create().show();
};
return v_onClickListener;
}
private class AsyncTaskGetFavourites extends AsyncTask<Nullable, String, Nullable> {
@Override
protected void onPreExecute() {
super.onPreExecute();
m_adapter.notifyDataSetChanged();
rclr_home_favourites.setEnabled(false);
}
@Override
protected Nullable doInBackground(Nullable... nullables) {
getFav();
return null;
}
@Override
protected void onPostExecute(Nullable nullable) {
super.onPostExecute(nullable);
m_adapter.notifyDataSetChanged();
rclr_home_favourites.setEnabled(true);
}
}
}
\ No newline at end of file
......@@ -11,152 +11,211 @@
android:layout_height="match_parent"
android:orientation="horizontal">
<androidx.constraintlayout.widget.ConstraintLayout
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:id="@+id/linearLayout3"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
android:layout_margin="8dp">
<ImageView
android:id="@+id/img_displayGif_gif"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/abc_vector_test" />
<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="@+id/lbl_displayGif_name"
android:layout_width="0dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/img_displayGif_gif"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/abc_vector_test" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
android:textAppearance="@style/AppTextTitle"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/lbl_displayGif_titleTag"
android:layout_width="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/lbl_displayGif_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
android:textAppearance="@style/AppTextTitle"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/lbl_displayGif_titleTag"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Tags :"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lbl_displayGif_name" />
<TextView
android:id="@+id/lbl_displayGif_tag"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/lbl_displayGif_titleTag"
app:layout_constraintTop_toBottomOf="@+id/lbl_displayGif_titleTag" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<TextView
android:id="@+id/lbl_displayGif_nbResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Nb Results"
app:layout_constraintStart_toStartOf="@+id/linearLayout3"
app:layout_constraintTop_toBottomOf="@+id/linearLayout3" />
<EditText
android:id="@+id/txt_displayGif_nbResult"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ems="10"
android:inputType="numberDecimal"
android:text="8"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/lbl_displayGif_nbResult"
app:layout_constraintEnd_toEndOf="@+id/linearLayout3"
app:layout_constraintStart_toEndOf="@+id/lbl_displayGif_nbResult"
app:layout_constraintTop_toTopOf="@+id/lbl_displayGif_nbResult" />
<SeekBar
android:id="@+id/skbr_displayGif_nbResult"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:max="49"
android:progress="7"
app:layout_constraintEnd_toEndOf="@+id/txt_displayGif_nbResult"
app:layout_constraintStart_toStartOf="@+id/lbl_displayGif_nbResult"
app:layout_constraintTop_toBottomOf="@+id/txt_displayGif_nbResult" />
<TextView
android:id="@+id/lbl_displayGif_recherche"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Rechercher un gif"
app:layout_constraintStart_toStartOf="@+id/lbl_displayGif_nbResult"
app:layout_constraintTop_toBottomOf="@+id/skbr_displayGif_nbResult" />
<TextView
android:id="@+id/lbl_displayGif_searchTenor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search Tenor"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="@+id/lbl_displayGif_recherche"
app:layout_constraintStart_toStartOf="@+id/lbl_displayGif_recherche"
app:layout_constraintTop_toBottomOf="@+id/lbl_displayGif_recherche" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:checkedButton="@id/rdbtn_displayGif_withSheet"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/lbl_displayGif_searchTenor"
app:layout_constraintStart_toEndOf="@+id/lbl_displayGif_recherche"
app:layout_constraintTop_toTopOf="@+id/lbl_displayGif_recherche">
<RadioButton
android:id="@+id/rdbtn_displayGif_withSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Tags :"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lbl_displayGif_name" />
<TextView
android:id="@+id/lbl_displayGif_tag"
android:layout_width="0dp"
android:text="With Sheet"
android:textColor="@color/white" />
<RadioButton
android:id="@+id/rdbtn_displayGif_withGif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/lbl_displayGif_titleTag"
app:layout_constraintTop_toBottomOf="@+id/lbl_displayGif_titleTag" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
android:text="With GIF"
android:textColor="@color/white" />
</RadioGroup>
<TextView
android:id="@+id/lbl_displayGif_titleRelatedGif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Related GIFs"
app:layout_constraintStart_toStartOf="@+id/linearLayout3"
app:layout_constraintTop_toBottomOf="@+id/linearLayout3" />
<TextView
android:id="@+id/lbl_displayGif_orWith"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintEnd_toStartOf="@+id/txt_displayGif_recherche"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lbl_displayGif_searchTenor" />
<EditText
android:id="@+id/txt_displayGif_recherche"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ems="10"
android:inputType="textPersonName"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/lbl_displayGif_orWith"
app:layout_constraintStart_toEndOf="@+id/lbl_displayGif_recherche"
app:layout_constraintTop_toTopOf="@+id/lbl_displayGif_orWith" />
<Switch
android:id="@+id/swtch_displayGif_isNSFW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="NSFW"
android:textColor="@color/white"
app:layout_constraintStart_toStartOf="@+id/lbl_displayGif_recherche"
app:layout_constraintTop_toBottomOf="@+id/txt_displayGif_recherche" />
<TextView
android:id="@+id/lbl_displayGif_nbResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Nb Results"
app:layout_constraintStart_toEndOf="@+id/lbl_displayGif_titleRelatedGif"
app:layout_constraintTop_toTopOf="@+id/lbl_displayGif_titleRelatedGif" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<EditText
android:id="@+id/txt_displayGif_nbResult"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ems="10"
android:inputType="numberDecimal"