Skip to content
Snippets Groups Projects
Commit 30f741ee authored by Valentin Bout's avatar Valentin Bout
Browse files

Feat: need to work on second screen detail

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 641 additions and 0 deletions
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
# Default ignored files
/shelf/
/workspace.xml
TP Retrofit
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="/usr/local/Cellar/gradle/7.5.1_1/libexec" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="app/src/main/res/layout/activity_main.xml" value="0.2597362326987717" />
<entry key="app/src/main/res/layout/product_card.xml" value="0.375" />
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
/build
\ No newline at end of file
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.tpretrofit"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.squareup.picasso:picasso:2.8'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
package com.example.tpretrofit;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.example.tpretrofit", appContext.getPackageName());
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tpretrofit">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.TPRetrofit">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package API;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class APIClient {
public static String BASE_URL ="https://biomatyx.fr/api/";
public static String BASE_IMAGE_URL = "https://biomatyx.fr/";
private static Retrofit retrofit;
public static Retrofit getClient(){
if(retrofit == null){
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
package Model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class BiomatixProduct {
@SerializedName("referenceNumber")
@Expose
private String referenceNumber;
@SerializedName("name")
@Expose
private String name;
@SerializedName("categoryRefNumber")
@Expose
private String categoryRefNumber;
@SerializedName("manufacturerRefNumber")
@Expose
private String manufacturerRefNumber;
@SerializedName("manufacturerName")
@Expose
private String manufacturerName;
@SerializedName("state")
@Expose
private String state;
@SerializedName("status")
@Expose
private String status;
@SerializedName("newProduct")
@Expose
private boolean newProduct;
@SerializedName("picture")
@Expose
private BiomatrixProductPicture picture;
public String getReferenceNumber() {
return referenceNumber;
}
public void setReferenceNumber(String referenceNumber) {
this.referenceNumber = referenceNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCategoryRefNumber() {
return categoryRefNumber;
}
public void setCategoryRefNumber(String categoryRefNumber) {
this.categoryRefNumber = categoryRefNumber;
}
public String getManufacturerRefNumber() {
return manufacturerRefNumber;
}
public void setManufacturerRefNumber(String manufacturerRefNumber) {
this.manufacturerRefNumber = manufacturerRefNumber;
}
public String getManufacturerName() {
return manufacturerName;
}
public void setManufacturerName(String manufacturerName) {
this.manufacturerName = manufacturerName;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public boolean isNewProduct() {
return newProduct;
}
public void setNewProduct(boolean newProduct) {
this.newProduct = newProduct;
}
public BiomatrixProductPicture getPicture() {
return picture;
}
public void setPicture(BiomatrixProductPicture picture) {
this.picture = picture;
}
}
package Model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
public class BiomatrixCatalog {
@SerializedName("currentPage")
@Expose
private int currentPage;
@SerializedName("pageSize")
@Expose
private int pageSize;
@SerializedName("totalRecords")
@Expose
private int totalRecords;
@SerializedName("productList")
@Expose
private List<BiomatixProduct> productList;
public BiomatrixCatalog() {
this.currentPage = 1;
this.pageSize = 500;
this.totalRecords = -1;
this.productList = new ArrayList<>();
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalRecords() {
return totalRecords;
}
public void setTotalRecords(int totalRecords) {
this.totalRecords = totalRecords;
}
public List<BiomatixProduct> getProductList() {
return productList;
}
public void setProductList(List<BiomatixProduct> productList) {
this.productList = productList;
}
}
package Model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class BiomatrixProductPicture {
@SerializedName("url")
@Expose
private String url;
@SerializedName("tag")
@Expose
private String tag;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
}
package calls;
import android.util.Log;
import android.widget.Toast;
import API.APIClient;
import Model.BiomatrixCatalog;
import interfaces.BiomatrixService;
import interfaces.OnFailure;
import interfaces.OnResponse;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class BiomatrixCalls {
// Get a Retrofit instance and the related endpoints
BiomatrixService biomatrixService = APIClient.getClient().create(BiomatrixService.class);
public void getBiomatrixCatalog(int num_page, int page_size, OnResponse response_do, OnFailure failure_do) {
Call<BiomatrixCatalog> call = biomatrixService.getCatalog(num_page, page_size);
call.enqueue(new Callback<BiomatrixCatalog>() {
@Override
public void onResponse(Call<BiomatrixCatalog> call, Response<BiomatrixCatalog> response) {
Log.d("AHHA", "on response");
response_do.doSomething(call, response);
}
@Override
public void onFailure(Call<BiomatrixCatalog> call, Throwable t) {
Log.d("AHA", "on failure");
failure_do.doSomething(call, t);
}
});
}
}
package com.example.tpretrofit;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import com.squareup.picasso.Picasso;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import API.APIClient;
import Model.BiomatixProduct;
import Model.BiomatrixCatalog;
public class CardRecyclerViewAdapter extends RecyclerView.Adapter<CardViewHolder> {
public BiomatrixCatalog localData;
//public void removeAt(int position) {
// localDataSet.remove(position);
// notifyItemRemoved(position);
// notifyItemRangeChanged(position, localDataSet.size());
//}
public CardRecyclerViewAdapter(BiomatrixCatalog data) {
localData = data;
}
public CardViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.product_card, viewGroup, false);
return new CardViewHolder(view, this);
}
@Override
public void onBindViewHolder(CardViewHolder viewHolder, final int position) {
BiomatixProduct bp= localData.getProductList().get(position);
viewHolder.getTextViewRef().setText(bp.getReferenceNumber());
viewHolder.getTextViewName().setText(bp.getName());
try {
Picasso.get().load(APIClient.BASE_IMAGE_URL + "images/product/thumbnail/" + bp.getPicture().getUrl()).resize(130, 130).into(viewHolder.getImage());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public int getItemCount() {
return localData.getProductList().size();
}
public void setData(BiomatrixCatalog catalog) {
this.localData = catalog;
notifyDataSetChanged();
}
}
package com.example.tpretrofit;
import android.media.Image;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
public class CardViewHolder extends RecyclerView.ViewHolder {
private CardRecyclerViewAdapter holder;
private TextView textViewName;
private TextView textViewRef;
private ImageView image;
public CardViewHolder(View view, CardRecyclerViewAdapter holder) {
super(view);
this.holder = holder;
textViewName = (TextView) view.findViewById(R.id.product_name);
textViewRef = (TextView) view.findViewById(R.id.product_ref);
image = (ImageView) view.findViewById(R.id.product_image);
}
public ImageView getImage() {
return image;
}
public TextView getTextViewName() {
return textViewName;
}
public TextView getTextViewRef() {
return textViewRef;
}
}
package com.example.tpretrofit;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import Model.BiomatrixCatalog;
import calls.BiomatrixCalls;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BiomatrixCatalog biomatrixCatalog = new BiomatrixCatalog();
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
CardRecyclerViewAdapter adapter = new CardRecyclerViewAdapter(biomatrixCatalog);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
BiomatrixCalls calls = new BiomatrixCalls();
calls.getBiomatrixCatalog(1, 20, (call, resp) -> {
adapter.setData(resp.body());
}, (a, b) -> {
Toast.makeText(getApplicationContext(), "An error occur for this", Toast.LENGTH_SHORT).show();
});
Button prev = (Button) findViewById(R.id.prev);
Button next = (Button) findViewById(R.id.next);
prev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (adapter.localData.getCurrentPage() >= 2) {
calls.getBiomatrixCatalog(adapter.localData.getCurrentPage() -1, 20, (call, resp) -> {
adapter.setData(resp.body());
}, (a, b) -> {
Toast.makeText(getApplicationContext(), "An error occur for this", Toast.LENGTH_SHORT).show();
});
}
}
});
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
calls.getBiomatrixCatalog(adapter.localData.getCurrentPage() +1, 20, (call, resp) -> {
adapter.setData(resp.body());
}, (a, b) -> {
Toast.makeText(getApplicationContext(), "An error occur for this", Toast.LENGTH_SHORT).show();
});
}
});
}
}
\ No newline at end of file
package interfaces;
import Model.BiomatrixCatalog;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface BiomatrixService {
@GET("catalog")
Call<BiomatrixCatalog> getCatalog(@Query("page") int num_page, @Query("pagesize") int page_size);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment