-
-
Save anandrex5/1c34df7e67ef2885b060394eab2a47bd to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:id="@+id/constraints" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<androidx.cardview.widget.CardView | |
android:id="@+id/cardView" | |
android:layout_width="match_parent" | |
android:layout_height="70dp" | |
android:backgroundTint="#716d6d" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
> | |
<TextView | |
android:id="@+id/giftcard" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginStart="19dp" | |
android:layout_marginTop="20dp" | |
android:text="@string/giftcardstore" | |
android:textColor="@color/white" | |
android:textSize="20dp" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginStart="19dp" | |
android:layout_marginTop="45dp" | |
android:text="@string/giftingmadeeasy" | |
android:textColor="@color/white" | |
android:textSize="13sp" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:background="@drawable/rectangle_14129" | |
android:layout_marginStart="210dp" | |
android:layout_marginTop="30dp" | |
android:text="@string/mygiftcards" | |
android:textColor="#f7e98e" | |
android:gravity="center" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintTop_toTopOf="parent"/> | |
</androidx.cardview.widget.CardView> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycle" | |
android:layout_width="match_parent" | |
android:layout_height="0dp" | |
app:layout_constraintTop_toBottomOf="@+id/cardView" | |
app:layout_constraintBottom_toBottomOf="parent"/> | |
</androidx.constraintlayout.widget.ConstraintLayout> | |
<!--<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"--> | |
<!-- xmlns:app="http://schemas.android.com/apk/res-auto"--> | |
<!-- xmlns:tools="http://schemas.android.com/tools"--> | |
<!-- android:layout_width="match_parent"--> | |
<!-- android:layout_height="match_parent"--> | |
<!-- tools:context=".MainActivity">--> | |
<!-- <TextView--> | |
<!-- android:id="@+id/textView"--> | |
<!-- android:layout_width="wrap_content"--> | |
<!-- android:layout_height="wrap_content"--> | |
<!-- android:background="@drawable/rectangle_17433"--> | |
<!-- android:textSize="21sp"--> | |
<!-- app:layout_constraintEnd_toEndOf="parent"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintTop_toTopOf="parent" />--> | |
<!-- <TextView--> | |
<!-- android:id="@+id/giftcard"--> | |
<!-- android:layout_width="wrap_content"--> | |
<!-- android:layout_height="wrap_content"--> | |
<!-- android:layout_marginStart="19dp"--> | |
<!-- android:layout_marginTop="40.0dp"--> | |
<!-- android:text="@string/giftcardstore"--> | |
<!-- android:textSize="21sp"--> | |
<!-- android:textColor="@color/white"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintTop_toTopOf="parent" />--> | |
<!--<!– <TextView–>--> | |
<!-- android:layout_width="wrap_content"--> | |
<!-- android:layout_height="wrap_content"--> | |
<!-- android:layout_marginStart="19dp"--> | |
<!-- android:text="@string/giftingmadeeasy"--> | |
<!-- android:textColor="@color/white"--> | |
<!-- android:textSize="13sp"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintTop_toBottomOf="@+id/giftcard" />--> | |
<!-- <TextView--> | |
<!-- android:layout_width="wrap_content"--> | |
<!-- android:layout_height="wrap_content"--> | |
<!-- android:background="@drawable/rectangle_14129"--> | |
<!-- android:layout_marginStart="210dp"--> | |
<!-- android:layout_marginTop="55.0dp"--> | |
<!-- android:text="@string/mygiftcards"--> | |
<!-- android:textColor="#f7e98e"--> | |
<!-- android:gravity="center"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintEnd_toEndOf="parent"--> | |
<!-- app:layout_constraintTop_toTopOf="parent"/>--> | |
<!-- <TextView--> | |
<!-- android:layout_width="wrap_content"--> | |
<!-- android:layout_height="wrap_content"--> | |
<!-- android:layout_marginStart="19dp"--> | |
<!-- android:text="@string/birthdaygiftmsg"--> | |
<!-- android:textSize="17dp"--> | |
<!-- android:textColor="#1a2421"--> | |
<!-- app:layout_constraintBottom_toTopOf="@+id/imageView"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintTop_toBottomOf="@+id/textView" />--> | |
<!-- <ImageView--> | |
<!-- android:id="@+id/imageView"--> | |
<!-- android:layout_width="380dp"--> | |
<!-- android:layout_height="180dp"--> | |
<!-- android:layout_marginStart="19dp"--> | |
<!-- android:layout_marginTop="149.0dp"--> | |
<!-- android:layout_marginEnd="19dp"--> | |
<!-- android:background="@drawable/birthday"--> | |
<!-- app:layout_constraintEnd_toEndOf="parent"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintTop_toTopOf="parent" />--> | |
<!-- <TextView--> | |
<!-- android:id="@+id/textView2"--> | |
<!-- android:layout_width="380dp"--> | |
<!-- android:layout_height="80dp"--> | |
<!-- android:layout_marginStart="19dp"--> | |
<!-- android:layout_marginTop="328dp"--> | |
<!-- android:layout_marginEnd="19dp"--> | |
<!-- android:background="@drawable/rectangle_13190"--> | |
<!-- app:layout_constraintEnd_toEndOf="parent"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintTop_toTopOf="parent" />--> | |
<!-- <TextView--> | |
<!-- android:id="@+id/text10"--> | |
<!-- android:layout_width="wrap_content"--> | |
<!-- android:layout_height="25dp"--> | |
<!-- android:text="@string/birthdaygiftcard"--> | |
<!-- android:layout_marginBottom="20dp"--> | |
<!-- android:textColor="@color/black"--> | |
<!-- android:textSize="15sp"--> | |
<!-- android:textStyle="bold"--> | |
<!-- app:layout_constraintBottom_toBottomOf="@+id/textView2"--> | |
<!-- app:layout_constraintEnd_toEndOf="@+id/textView2"--> | |
<!-- app:layout_constraintStart_toStartOf="@+id/textView2"--> | |
<!-- app:layout_constraintTop_toBottomOf="@+id/imageView"--> | |
<!-- />--> | |
<!-- <TextView--> | |
<!-- android:id="@+id/textView3"--> | |
<!-- android:layout_width="wrap_content"--> | |
<!-- android:layout_height="25dp"--> | |
<!-- android:text="@string/loadyourgift"--> | |
<!-- android:textColor="#555555"--> | |
<!-- android:textSize="13sp"--> | |
<!-- app:layout_constraintBottom_toBottomOf="@+id/textView2"--> | |
<!-- app:layout_constraintEnd_toEndOf="@+id/textView2"--> | |
<!-- app:layout_constraintStart_toStartOf="@+id/textView2"--> | |
<!-- app:layout_constraintTop_toBottomOf="@+id/text10" />--> | |
<!-- <ImageView--> | |
<!-- android:id="@+id/imageView11"--> | |
<!-- android:layout_width="380dp"--> | |
<!-- android:layout_height="180dp"--> | |
<!-- android:background="@drawable/birthday"--> | |
<!-- android:layout_marginTop="50dp"--> | |
<!-- android:layout_marginStart="19dp"--> | |
<!-- app:layout_constraintTop_toBottomOf="@+id/textView2"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintEnd_toEndOf="parent"--> | |
<!-- android:layout_marginEnd="19dp"--> | |
<!-- />--> | |
<!-- <TextView--> | |
<!-- android:id="@+id/textView4"--> | |
<!-- android:layout_width="380dp"--> | |
<!-- android:layout_height="80dp"--> | |
<!-- android:layout_marginStart="19dp"--> | |
<!-- android:layout_marginEnd="19dp"--> | |
<!-- android:background="@drawable/rectangle_13190"--> | |
<!-- app:layout_constraintEnd_toEndOf="parent"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintTop_toBottomOf="@+id/imageView11" />--> | |
<!-- <TextView--> | |
<!-- android:id="@+id/text12"--> | |
<!-- android:layout_width="wrap_content"--> | |
<!-- android:layout_height="25dp"--> | |
<!-- android:text="@string/giftcardfor"--> | |
<!-- android:textColor="@color/black"--> | |
<!-- android:textSize="15sp"--> | |
<!-- android:textStyle="bold"--> | |
<!-- android:layout_marginTop="15sp"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintEnd_toEndOf="parent"--> | |
<!-- app:layout_constraintTop_toBottomOf="@+id/imageView11"--> | |
<!-- />--> | |
<!-- <TextView--> | |
<!-- android:id="@+id/textView13"--> | |
<!-- android:layout_width="wrap_content"--> | |
<!-- android:layout_height="25dp"--> | |
<!-- android:text="@string/loadyourgift"--> | |
<!-- android:textColor="#555555"--> | |
<!-- android:textSize="13sp"--> | |
<!-- android:layout_marginStart="19dp"--> | |
<!-- android:layout_marginEnd="19dp"--> | |
<!-- app:layout_constraintStart_toStartOf="parent"--> | |
<!-- app:layout_constraintEnd_toEndOf="parent"--> | |
<!-- app:layout_constraintBottom_toBottomOf="@+id/textView4" />--> | |
<!--</androidx.constraintlayout.widget.ConstraintLayout>--> | |
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
package="com.example.exam2"> | |
<uses-permission android:name="android.permission.INTERNET"/> | |
<application | |
android:allowBackup="true" | |
android:usesCleartextTraffic="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/Theme.Exam2" | |
tools:targetApi="31"> | |
<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> |
package com.example.exam2; | |
import retrofit2.Call; | |
import retrofit2.http.GET; | |
public interface ApiInterface { | |
@GET("/cans/tt/rest/api/sec/v1/giftCard/giftCardDetails.json") //parameter of URL | |
Call<GiftCardModel>getData(); | |
} |
plugins { | |
id 'com.android.application' | |
} | |
android { | |
compileSdk 32 | |
defaultConfig { | |
applicationId "com.example.exam2" | |
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 'androidx.appcompat:appcompat:1.4.2' | |
implementation 'com.google.android.material:material:1.6.1' | |
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | |
testImplementation 'junit:junit:4.13.2' | |
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | |
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | |
implementation 'androidx.fragment:fragment:1.3.5' | |
testImplementation 'junit:junit:4.13.2' | |
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | |
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | |
implementation 'de.hdodenhof:circleimageview:3.1.0' | |
implementation "androidx.cardview:cardview:1.0.0" | |
implementation "androidx.recyclerview:recyclerview:1.2.1" | |
implementation 'com.google.code.gson:gson:2.8.7' | |
implementation 'com.squareup.retrofit2:retrofit:2.4.0' | |
implementation 'com.google.code.gson:gson:2.6.2' | |
implementation 'com.squareup.retrofit2:converter-gson:2.1.0' | |
implementation 'com.squareup.retrofit2:converter-gson:2.4.0' | |
implementation 'com.squareup.picasso:picasso:2.5.2' | |
implementation("com.squareup.okhttp3:logging-interceptor:4.9.3") | |
implementation "androidx.recyclerview:recyclerview:1.2.1" | |
// For control over item selection of both touch and mouse driven selection | |
implementation "androidx.recyclerview:recyclerview-selection:1.1.0" | |
implementation 'com.github.bumptech.glide:glide:4.12.0' | |
// Glide v4 uses this new annotation processor -- see https://bumptech.github.io/glide/doc/generatedapi.html | |
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' | |
} |
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginStart="19dp" | |
android:layout_marginTop="10dp" | |
android:text="@string/birthdaygiftmsg" | |
android:textColor="#1a2421" | |
android:textSize="17dp" | |
/> | |
<ImageView | |
android:id="@+id/imageView" | |
android:layout_width="380dp" | |
android:layout_height="180dp" | |
android:layout_marginStart="19dp" | |
android:layout_marginTop="45dp" | |
android:layout_marginEnd="19dp" | |
android:background="@drawable/birthday" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<TextView | |
android:id="@+id/textView2" | |
android:layout_width="380dp" | |
android:layout_height="80dp" | |
android:layout_marginStart="19dp" | |
android:layout_marginTop="225dp" | |
android:layout_marginEnd="19dp" | |
android:background="@drawable/rectangle_13190" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<TextView | |
android:id="@+id/text10" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerHorizontal="true" | |
android:layout_marginTop="230dp" | |
android:text="@string/giftcardfor" | |
android:textColor="@color/black" | |
android:textSize="15sp" | |
android:textStyle="bold" | |
/> | |
<TextView | |
android:id="@+id/textView11" | |
android:layout_width="wrap_content" | |
android:layout_height="25dp" | |
android:layout_marginHorizontal="80dp" | |
android:layout_marginTop="250dp" | |
android:text="@string/loadyourgift" | |
android:textColor="#555555" | |
android:layout_centerHorizontal="true" | |
android:textSize="13sp" /> | |
</RelativeLayout> | |
package com.example.exam2; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import androidx.annotation.NonNull; | |
import androidx.recyclerview.widget.RecyclerView; | |
import com.bumptech.glide.Glide; | |
import java.util.List; | |
class GiftAdapter extends RecyclerView.Adapter<GiftAdapter.MyViewHolder> { | |
List<GiftCardResponse> list; | |
public GiftAdapter(List<GiftCardResponse> list) { | |
this.list = list; | |
} | |
@NonNull | |
@Override | |
public GiftAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | |
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardlayout, null); | |
MyViewHolder viewHolder = new MyViewHolder(view); | |
return viewHolder; | |
} | |
@Override | |
public void onBindViewHolder(@NonNull GiftAdapter.MyViewHolder holder, int position) { | |
GiftCardResponse giftCardResponse = list.get(position); | |
holder.textView1.setText(giftCardResponse.getGiftCardName()); | |
holder.textView2.setText(giftCardResponse.getGiftCardCode()); | |
Glide.with(holder.itemView.getContext()) | |
.load(giftCardResponse.getGiftCardImageUrl()) | |
.into(holder.imageView); | |
} | |
@Override | |
public int getItemCount() { | |
return list.size(); | |
} | |
class MyViewHolder extends RecyclerView.ViewHolder { | |
TextView textView1; | |
TextView textView2; | |
ImageView imageView; | |
public MyViewHolder(@NonNull View itemView) { | |
super(itemView); | |
imageView = itemView.findViewById(R.id.imageView); | |
textView1 = itemView.findViewById(R.id.text10); | |
textView2 = itemView.findViewById(R.id.textView11); | |
} | |
} | |
} | |
package com.example.exam2; | |
import com.google.gson.annotations.Expose; | |
import com.google.gson.annotations.SerializedName; | |
import java.util.List; | |
public class GiftCardModel { | |
@SerializedName("giftCardResponseList") | |
@Expose | |
private List<GiftCardResponse> giftCardResponseList = null; | |
@SerializedName("status") | |
@Expose | |
private String status; | |
public List<GiftCardResponse> getGiftCardResponseList() { | |
return giftCardResponseList; | |
} | |
public void setGiftCardResponseList(List<GiftCardResponse> giftCardResponseList) { | |
this.giftCardResponseList = giftCardResponseList; | |
} | |
public String getStatus() { | |
return status; | |
} | |
public void setStatus(String status) { | |
this.status = status; | |
} | |
} | |
package com.example.exam2; | |
import com.google.gson.annotations.Expose; | |
import com.google.gson.annotations.SerializedName; | |
public class GiftCardResponse { | |
@SerializedName("productType") | |
@Expose | |
private String productType; | |
@SerializedName("giftCardCode") | |
@Expose | |
private String giftCardCode; | |
@SerializedName("currencyCode") | |
@Expose | |
private String currencyCode; | |
@SerializedName("faceValue") | |
@Expose | |
private Double faceValue; | |
@SerializedName("activationMaxAmt") | |
@Expose | |
private Double activationMaxAmt; | |
@SerializedName("activationMinAmt") | |
@Expose | |
private Double activationMinAmt; | |
@SerializedName("allowedActivate") | |
@Expose | |
private Integer allowedActivate; | |
@SerializedName("allowedReload") | |
@Expose | |
private Integer allowedReload; | |
@SerializedName("allowedRedeem") | |
@Expose | |
private Integer allowedRedeem; | |
@SerializedName("isFixValue") | |
@Expose | |
private Integer isFixValue; | |
@SerializedName("giftCardName") | |
@Expose | |
private String giftCardName; | |
@SerializedName("termAndCondition") | |
@Expose | |
private String termAndCondition; | |
@SerializedName("giftCardImageUrl") | |
@Expose | |
private String giftCardImageUrl; | |
@SerializedName("description") | |
@Expose | |
private String description; | |
@SerializedName("marketingContent01") | |
@Expose | |
private String marketingContent01; | |
@SerializedName("marketingContent02") | |
@Expose | |
private String marketingContent02; | |
@SerializedName("giftCardStatus") | |
@Expose | |
private Object giftCardStatus; | |
@SerializedName("barcodeNumber") | |
@Expose | |
private Object barcodeNumber; | |
@SerializedName("giftCardPurchaseType") | |
@Expose | |
private Object giftCardPurchaseType; | |
@SerializedName("purchaseContent") | |
@Expose | |
private Object purchaseContent; | |
@SerializedName("denominationAmount01") | |
@Expose | |
private Double denominationAmount01; | |
@SerializedName("denominationAmount02") | |
@Expose | |
private Double denominationAmount02; | |
@SerializedName("mobileNumber") | |
@Expose | |
private Object mobileNumber; | |
@SerializedName("activationAmount") | |
@Expose | |
private Double activationAmount; | |
@SerializedName("referenceNumber") | |
@Expose | |
private Object referenceNumber; | |
@SerializedName("expiryDate") | |
@Expose | |
private Object expiryDate; | |
@SerializedName("purchaseDate") | |
@Expose | |
private Object purchaseDate; | |
@SerializedName("latestBalance") | |
@Expose | |
private Object latestBalance; | |
@SerializedName("sharedWith") | |
@Expose | |
private Object sharedWith; | |
@SerializedName("giftedBy") | |
@Expose | |
private Object giftedBy; | |
@SerializedName("status") | |
@Expose | |
private Object status; | |
@SerializedName("activationBarcodeNumber") | |
@Expose | |
private Object activationBarcodeNumber; | |
@SerializedName("balanceBarcodeNumber") | |
@Expose | |
private Object balanceBarcodeNumber; | |
/** | |
* No args constructor for use in serialization | |
* | |
*/ | |
public GiftCardResponse() { | |
} | |
/** | |
* | |
* @param barcodeNumber | |
* @param purchaseDate | |
* @param giftCardStatus | |
* @param mobileNumber | |
* @param description | |
* @param giftCardImageUrl | |
* @param giftCardCode | |
* @param allowedReload | |
* @param allowedRedeem | |
* @param purchaseContent | |
* @param expiryDate | |
* @param balanceBarcodeNumber | |
* @param marketingContent01 | |
* @param marketingContent02 | |
* @param referenceNumber | |
* @param allowedActivate | |
* @param productType | |
* @param activationAmount | |
* @param giftCardPurchaseType | |
* @param giftedBy | |
* @param activationMinAmt | |
* @param isFixValue | |
* @param sharedWith | |
* @param latestBalance | |
* @param giftCardName | |
* @param termAndCondition | |
* @param faceValue | |
* @param activationMaxAmt | |
* @param activationBarcodeNumber | |
* @param currencyCode | |
* @param denominationAmount01 | |
* @param denominationAmount02 | |
* @param status | |
*/ | |
public GiftCardResponse(String productType, String giftCardCode, String currencyCode, Double faceValue, Double activationMaxAmt, Double activationMinAmt, Integer allowedActivate, Integer allowedReload, Integer allowedRedeem, Integer isFixValue, String giftCardName, String termAndCondition, String giftCardImageUrl, String description, String marketingContent01, String marketingContent02, Object giftCardStatus, Object barcodeNumber, Object giftCardPurchaseType, Object purchaseContent, Double denominationAmount01, Double denominationAmount02, Object mobileNumber, Double activationAmount, Object referenceNumber, Object expiryDate, Object purchaseDate, Object latestBalance, Object sharedWith, Object giftedBy, Object status, Object activationBarcodeNumber, Object balanceBarcodeNumber) { | |
super(); | |
this.productType = productType; | |
this.giftCardCode = giftCardCode; | |
this.currencyCode = currencyCode; | |
this.faceValue = faceValue; | |
this.activationMaxAmt = activationMaxAmt; | |
this.activationMinAmt = activationMinAmt; | |
this.allowedActivate = allowedActivate; | |
this.allowedReload = allowedReload; | |
this.allowedRedeem = allowedRedeem; | |
this.isFixValue = isFixValue; | |
this.giftCardName = giftCardName; | |
this.termAndCondition = termAndCondition; | |
this.giftCardImageUrl = giftCardImageUrl; | |
this.description = description; | |
this.marketingContent01 = marketingContent01; | |
this.marketingContent02 = marketingContent02; | |
this.giftCardStatus = giftCardStatus; | |
this.barcodeNumber = barcodeNumber; | |
this.giftCardPurchaseType = giftCardPurchaseType; | |
this.purchaseContent = purchaseContent; | |
this.denominationAmount01 = denominationAmount01; | |
this.denominationAmount02 = denominationAmount02; | |
this.mobileNumber = mobileNumber; | |
this.activationAmount = activationAmount; | |
this.referenceNumber = referenceNumber; | |
this.expiryDate = expiryDate; | |
this.purchaseDate = purchaseDate; | |
this.latestBalance = latestBalance; | |
this.sharedWith = sharedWith; | |
this.giftedBy = giftedBy; | |
this.status = status; | |
this.activationBarcodeNumber = activationBarcodeNumber; | |
this.balanceBarcodeNumber = balanceBarcodeNumber; | |
} | |
public String getProductType() { | |
return productType; | |
} | |
public void setProductType(String productType) { | |
this.productType = productType; | |
} | |
public String getGiftCardCode() { | |
return giftCardCode; | |
} | |
public void setGiftCardCode(String giftCardCode) { | |
this.giftCardCode = giftCardCode; | |
} | |
public String getCurrencyCode() { | |
return currencyCode; | |
} | |
public void setCurrencyCode(String currencyCode) { | |
this.currencyCode = currencyCode; | |
} | |
public Double getFaceValue() { | |
return faceValue; | |
} | |
public void setFaceValue(Double faceValue) { | |
this.faceValue = faceValue; | |
} | |
public Double getActivationMaxAmt() { | |
return activationMaxAmt; | |
} | |
public void setActivationMaxAmt(Double activationMaxAmt) { | |
this.activationMaxAmt = activationMaxAmt; | |
} | |
public Double getActivationMinAmt() { | |
return activationMinAmt; | |
} | |
public void setActivationMinAmt(Double activationMinAmt) { | |
this.activationMinAmt = activationMinAmt; | |
} | |
public Integer getAllowedActivate() { | |
return allowedActivate; | |
} | |
public void setAllowedActivate(Integer allowedActivate) { | |
this.allowedActivate = allowedActivate; | |
} | |
public Integer getAllowedReload() { | |
return allowedReload; | |
} | |
public void setAllowedReload(Integer allowedReload) { | |
this.allowedReload = allowedReload; | |
} | |
public Integer getAllowedRedeem() { | |
return allowedRedeem; | |
} | |
public void setAllowedRedeem(Integer allowedRedeem) { | |
this.allowedRedeem = allowedRedeem; | |
} | |
public Integer getIsFixValue() { | |
return isFixValue; | |
} | |
public void setIsFixValue(Integer isFixValue) { | |
this.isFixValue = isFixValue; | |
} | |
public String getGiftCardName() { | |
return giftCardName; | |
} | |
public void setGiftCardName(String giftCardName) { | |
this.giftCardName = giftCardName; | |
} | |
public String getTermAndCondition() { | |
return termAndCondition; | |
} | |
public void setTermAndCondition(String termAndCondition) { | |
this.termAndCondition = termAndCondition; | |
} | |
public String getGiftCardImageUrl() { | |
return giftCardImageUrl; | |
} | |
public void setGiftCardImageUrl(String giftCardImageUrl) { | |
this.giftCardImageUrl = giftCardImageUrl; | |
} | |
public String getDescription() { | |
return description; | |
} | |
public void setDescription(String description) { | |
this.description = description; | |
} | |
public String getMarketingContent01() { | |
return marketingContent01; | |
} | |
public void setMarketingContent01(String marketingContent01) { | |
this.marketingContent01 = marketingContent01; | |
} | |
public String getMarketingContent02() { | |
return marketingContent02; | |
} | |
public void setMarketingContent02(String marketingContent02) { | |
this.marketingContent02 = marketingContent02; | |
} | |
public Object getGiftCardStatus() { | |
return giftCardStatus; | |
} | |
public void setGiftCardStatus(Object giftCardStatus) { | |
this.giftCardStatus = giftCardStatus; | |
} | |
public Object getBarcodeNumber() { | |
return barcodeNumber; | |
} | |
public void setBarcodeNumber(Object barcodeNumber) { | |
this.barcodeNumber = barcodeNumber; | |
} | |
public Object getGiftCardPurchaseType() { | |
return giftCardPurchaseType; | |
} | |
public void setGiftCardPurchaseType(Object giftCardPurchaseType) { | |
this.giftCardPurchaseType = giftCardPurchaseType; | |
} | |
public Object getPurchaseContent() { | |
return purchaseContent; | |
} | |
public void setPurchaseContent(Object purchaseContent) { | |
this.purchaseContent = purchaseContent; | |
} | |
public Double getDenominationAmount01() { | |
return denominationAmount01; | |
} | |
public void setDenominationAmount01(Double denominationAmount01) { | |
this.denominationAmount01 = denominationAmount01; | |
} | |
public Double getDenominationAmount02() { | |
return denominationAmount02; | |
} | |
public void setDenominationAmount02(Double denominationAmount02) { | |
this.denominationAmount02 = denominationAmount02; | |
} | |
public Object getMobileNumber() { | |
return mobileNumber; | |
} | |
public void setMobileNumber(Object mobileNumber) { | |
this.mobileNumber = mobileNumber; | |
} | |
public Double getActivationAmount() { | |
return activationAmount; | |
} | |
public void setActivationAmount(Double activationAmount) { | |
this.activationAmount = activationAmount; | |
} | |
public Object getReferenceNumber() { | |
return referenceNumber; | |
} | |
public void setReferenceNumber(Object referenceNumber) { | |
this.referenceNumber = referenceNumber; | |
} | |
public Object getExpiryDate() { | |
return expiryDate; | |
} | |
public void setExpiryDate(Object expiryDate) { | |
this.expiryDate = expiryDate; | |
} | |
public Object getPurchaseDate() { | |
return purchaseDate; | |
} | |
public void setPurchaseDate(Object purchaseDate) { | |
this.purchaseDate = purchaseDate; | |
} | |
public Object getLatestBalance() { | |
return latestBalance; | |
} | |
public void setLatestBalance(Object latestBalance) { | |
this.latestBalance = latestBalance; | |
} | |
public Object getSharedWith() { | |
return sharedWith; | |
} | |
public void setSharedWith(Object sharedWith) { | |
this.sharedWith = sharedWith; | |
} | |
public Object getGiftedBy() { | |
return giftedBy; | |
} | |
public void setGiftedBy(Object giftedBy) { | |
this.giftedBy = giftedBy; | |
} | |
public Object getStatus() { | |
return status; | |
} | |
public void setStatus(Object status) { | |
this.status = status; | |
} | |
public Object getActivationBarcodeNumber() { | |
return activationBarcodeNumber; | |
} | |
public void setActivationBarcodeNumber(Object activationBarcodeNumber) { | |
this.activationBarcodeNumber = activationBarcodeNumber; | |
} | |
public Object getBalanceBarcodeNumber() { | |
return balanceBarcodeNumber; | |
} | |
public void setBalanceBarcodeNumber(Object balanceBarcodeNumber) { | |
this.balanceBarcodeNumber = balanceBarcodeNumber; | |
} | |
} |
package com.example.exam2; | |
import androidx.appcompat.app.AppCompatActivity; | |
import androidx.constraintlayout.widget.ConstraintLayout; | |
import androidx.recyclerview.widget.LinearLayoutManager; | |
import androidx.recyclerview.widget.RecyclerView; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Toast; | |
import com.google.android.material.snackbar.Snackbar; | |
import java.util.List; | |
import retrofit2.Call; | |
import retrofit2.Callback; | |
import retrofit2.Response; | |
public class MainActivity extends AppCompatActivity { | |
RecyclerView recycle; | |
List<GiftCardResponse> list; | |
GiftAdapter giftAdapter; | |
ConstraintLayout constraintLayout; | |
Snackbar snackbar; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
recycle = findViewById(R.id.recycle); | |
constraintLayout = findViewById(R.id.constraints); | |
listingdata(); | |
} | |
private void listingdata() { | |
ApiInterface apiInterface = Retrofit.getRetrofit().create(ApiInterface.class); | |
Call<GiftCardModel> listingdata = apiInterface.getData(); | |
listingdata.enqueue(new Callback<GiftCardModel>() { | |
@Override | |
public void onResponse(Call<GiftCardModel> call, Response<GiftCardModel> response) { | |
final int statusCode = response.code(); | |
switch (statusCode) { | |
case 200: | |
GiftCardModel model = (GiftCardModel) response.body(); | |
list = model.getGiftCardResponseList(); | |
giftAdapter = new GiftAdapter(list); | |
recycle.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false)); | |
recycle.setAdapter(giftAdapter); | |
break; | |
case 400: | |
snackbar = Snackbar.make(constraintLayout, "Bad Request", Snackbar.LENGTH_SHORT) | |
.setAction("ok", new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
snackbar.dismiss(); | |
} | |
}); | |
snackbar.show(); | |
break; | |
case 500: | |
snackbar = Snackbar.make(constraintLayout, "Internal Server Error", Snackbar.LENGTH_SHORT) | |
.setAction("ok", new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
snackbar.dismiss(); | |
} | |
}); | |
snackbar.show(); | |
break; | |
case 401: | |
snackbar = Snackbar.make(constraintLayout, "Authentication Token verification failed", Snackbar.LENGTH_SHORT) | |
.setAction("ok", new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
snackbar.dismiss(); | |
} | |
}); | |
snackbar.show(); | |
break; | |
default: | |
break; | |
} | |
} | |
@Override | |
public void onFailure(Call<GiftCardModel> call, Throwable t) { | |
// Toast.makeText(getApplicationContext(), "Failure", Toast.LENGTH_SHORT); | |
snackbar = Snackbar.make(constraintLayout, "Failure", Snackbar.LENGTH_SHORT) | |
.setAction("ok", new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
snackbar.dismiss(); | |
} | |
}); | |
snackbar.show(); | |
} | |
}); | |
} | |
} | |
package com.example.exam2; | |
import com.google.gson.Gson; | |
import com.google.gson.GsonBuilder; | |
import okhttp3.OkHttpClient; | |
import okhttp3.Request; | |
import okhttp3.logging.HttpLoggingInterceptor; | |
import retrofit2.converter.gson.GsonConverterFactory; | |
public class Retrofit { | |
private static String baseurl="http://13.232.198.40:7080/"; | |
private static retrofit2.Retrofit retrofit; | |
public static retrofit2.Retrofit getRetrofit() | |
{ | |
if(retrofit== null) { | |
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); | |
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); | |
OkHttpClient client = new OkHttpClient.Builder() | |
.addInterceptor(chain -> { | |
Request request = chain.request() | |
.newBuilder() | |
.addHeader("COUNTRY", "India") | |
.addHeader("Language", "EN") | |
.addHeader("CITY", "Noida") | |
.addHeader("DEVICE_ID", "eep3U-uaTgGaekgnJVd5aQ") | |
.addHeader("deviceId", "eep3U-uaTgGaekgnJVd5aQ") | |
.addHeader("APP_VERSION", "0.1.72") | |
.addHeader("Content-Type", "application/json") | |
.addHeader("AUTH_TOKEN", "dfV8ntU+f0cikVRBDBg0CA==") | |
.addHeader("Authorization", "dfV8ntU+f0cikVRBDBg0CA==") | |
.build(); | |
return chain.proceed(request); | |
}) | |
.addInterceptor(httpLoggingInterceptor) | |
.build(); | |
retrofit = new retrofit2.Retrofit.Builder() | |
.baseUrl(baseurl).client(client) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build(); | |
} | |
return retrofit; | |
} | |
} |
Now the same question - Use string file instead of text and use ViewBinding instead of find view by ID ?
Step 1 - //Add these lines inside the android{} body of the gradle file(inside the app-level build gradle file)
buildFeatures {
viewBinding = true
dataBinding = true
}
Step 2 - Put all main_activity.xml code inside
<layout
.............
.............
main code
Step 3 - Declare it inside the Main Activity -
ActivityMainBinding binding;
then - write the View Binding code inside the onCreate -
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
then -
Replace the lines where you find the view/layout -
//for Snackbar
snackbar = Snackbar.make(binding.constraints, R.string.message400, Snackbar.LENGTH_SHORT)
- View Binding main_activity.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/constraints"
>
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="70dp"
android:backgroundTint="#716d6d"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<TextView
android:id="@+id/giftcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="19dp"
android:layout_marginTop="20dp"
android:text="@string/giftcardstore"
android:textColor="@color/white"
android:textSize="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="19dp"
android:layout_marginTop="45dp"
android:text="@string/giftingmadeeasy"
android:textColor="@color/white"
android:textSize="13sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rectangle_14129"
android:layout_marginStart="210dp"
android:layout_marginTop="30dp"
android:text="@string/mygiftcards"
android:textColor="#f7e98e"
android:gravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.cardview.widget.CardView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycle"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/cardView"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
2) Data Binding Main Activity
package com.example.exam2;
public class MainActivity extends AppCompatActivity {
RecyclerView recycle;
List<GiftCardResponse> list;
GiftAdapter giftAdapter;
ConstraintLayout constraintLayout;
Snackbar snackbar;
**ActivityMainBinding binding;**
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// recycle = findViewById(R.id.recycle);
// constraintLayout = findViewById(R.id.constraints);
//View Binding
**binding = DataBindingUtil.setContentView(this, R.layout.activity_main);**
// activityMainBinding = ActivityMainBinding.inflate(getLayoutInflater());
// View view = activityMainBinding.getRoot();
// setContentView(view);
listingdata();
}
private void listingdata() {
ApiInterface apiInterface = Retrofit.getRetrofit().create(ApiInterface.class);
Call<GiftCardModel> listingdata = apiInterface.getData();
listingdata.enqueue(new Callback<GiftCardModel>() {
@Override
public void onResponse(Call<GiftCardModel> call, Response<GiftCardModel> response) {
final int statusCode = response.code();
switch (statusCode) {
case 200:
GiftCardModel model = (GiftCardModel) response.body();
list = model.getGiftCardResponseList();
giftAdapter = new GiftAdapter(list);
binding.recycle.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false));
binding.recycle.setAdapter(giftAdapter);
break;
case 400:
snackbar = Snackbar.make(**binding.constraints**, R.string.message400, Snackbar.LENGTH_SHORT)
.setAction(R.string.message_ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.show();
break;
case 500:
snackbar = Snackbar.make(**binding.constraints**, R.string.message500, Snackbar.LENGTH_SHORT)
.setAction(R.string.message_ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.show();
break;
case 401:
snackbar = Snackbar.make(**binding.constraints**, R.string.message401, Snackbar.LENGTH_SHORT)
.setAction(R.string.message_ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.show();
break;
default:
break;
}
}
@Override
public void onFailure(Call<GiftCardModel> call, Throwable t) {
// Toast.makeText(getApplicationContext(), "Failure", Toast.LENGTH_SHORT);
snackbar = Snackbar.make(binding.constraints,R.string.message_failure, Snackbar.LENGTH_SHORT)
.setAction(R.string.message_ok, new View.OnClickListener() {
@OverRide
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.show();
}
});
}
}
//View Binding (Main Activity )
public class MainActivity extends AppCompatActivity {
// RecyclerView recycle;
List list;
GiftAdapter giftAdapter;
// ConstraintLayout constraintLayout;
Snackbar snackbar;
//data binding
// ActivityMainBinding binding;
//View Binding
ActivityMainBinding activityMainBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// recycle = findViewById(R.id.recycle);
// constraintLayout = findViewById(R.id.constraints);
//Data Binding Implementation
activityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
//View Binding Implementation
activityMainBinding = ActivityMainBinding.inflate(getLayoutInflater());
View view = activityMainBinding.getRoot();
setContentView(view);
listingdata();
}
private void listingdata() {
ApiInterface apiInterface = Retrofit.getRetrofit().create(ApiInterface.class);
Call<GiftCardModel> listingdata = apiInterface.getData();
listingdata.enqueue(new Callback<GiftCardModel>() {
@Override
public void onResponse(Call<GiftCardModel> call, Response<GiftCardModel> response) {
final int statusCode = response.code();
switch (statusCode) {
case 200:
GiftCardModel model = (GiftCardModel) response.body();
list = model.getGiftCardResponseList();
giftAdapter = new GiftAdapter(list);
activityMainBinding.recycle.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false));
activityMainBinding.recycle.setAdapter(giftAdapter);
break;
case 400:
snackbar = Snackbar.make(activityMainBinding.constraints, R.string.message400, Snackbar.LENGTH_SHORT)
.setAction(R.string.message_ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.show();
break;
case 500:
snackbar = Snackbar.make(activityMainBinding.constraints, R.string.message500, Snackbar.LENGTH_SHORT)
.setAction(R.string.message_ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.show();
break;
case 401:
snackbar = Snackbar.make(activityMainBinding.constraints, R.string.message401, Snackbar.LENGTH_SHORT)
.setAction(R.string.message_ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.show();
break;
default:
break;
}
}
@Override
public void onFailure(Call<GiftCardModel> call, Throwable t) {
// Toast.makeText(getApplicationContext(), "Failure", Toast.LENGTH_SHORT);
snackbar = Snackbar.make(activityMainBinding.constraints,R.string.message_failure, Snackbar.LENGTH_SHORT)
.setAction(R.string.message_ok, new View.OnClickListener() {
@OverRide
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.show();
}
});
}
}
Current Token -
--> GET http://13.232.198.40:7080//cans/tt/rest/api/sec/v1/giftCard/giftCardDetails.json
Authorization: dfV8ntU+f0cikVRBDBg0CA==
AUTH_TOKEN: dfV8ntU+f0cikVRBDBg0CA==
Language: EN
COUNTRY: India
CITY: Noida
DEVICE_ID: eep3U-uaTgGaekgnJVd5aQ
deviceId: eep3U-uaTgGaekgnJVd5aQ
APP_VERSION: 0.1.72
Content-Type: application/json