retrofil gjstatus lanuage
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
public class ApiClient {
public static String BASE_URL = "https://sktechnocastt.000webhostapp.com/";
private static Retrofit retrofit = null;
public static Retrofit getClient(Context context) {
if (retrofit == null) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient httpClient = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addInterceptor(interceptor)
.build();
Gson gson = new GsonBuilder()
.setLenient()
.create();
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(httpClient)
.build();
}
return retrofit;
}
}
public interface ApiInterface {
@POST("/android_liveapp/status/status_main_item_category.php")
Call<model_language> readData();
}
public void initView() {
Log.i(TAG, "initView(), called : ");
try {
progressDialog = new ProgressDialog(getActivity());
rv_language = (RecyclerView) view.findViewById(R.id.rv_language);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 1);
rv_language.setLayoutManager(gridLayoutManager);
rv_language.setItemAnimator(new DefaultItemAnimator());
} catch (Exception e) {
e.printStackTrace();
}
}
private void getJsonDataFromServerLanguage() {
Log.i(TAG, "getJsonDataFromServerLanguage() called : ");
try {
progressDialog.setTitle(getResources().getString(R.string.please_wait));
progressDialog.setMessage(getResources().getString(R.string.loading));
progressDialog.show();
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(false);
ApiInterface apiService = ApiClient.getClient(getActivity()).create(ApiInterface.class);
Call<model_language> call = apiService.readData();
call.enqueue(new Callback<model_language>() {
@Override
public void onResponse(Call<model_language> call, Response<model_language> response) {
progressDialog.dismiss();
try {
Log.i(TAG, "getJsonDataFromServerLanguage response== : " + response.body().getResult().toString());
if (response.body().getSuccess().equals(1)) {
if (response.body().getResult().size() > 0 && response.body().getResult() != null) {
ArrayList<model_language.Result> model_languageList = new ArrayList<>();
model_languageList = response.body().getResult();
rv_language.setAdapter(new Recyclerview_language_adepter(model_languageList));
}
} else {
Toast.makeText(getActivity(), ("No Details Found").toString(), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<model_language> call, Throwable t) {
// Log error here since request failed
progressDialog.dismiss();
Toast.makeText(getActivity(), "Check Your Internet Connection", Toast.LENGTH_LONG).show();
Log.i(TAG, t.toString());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public class Recyclerview_language_adepter extends RecyclerView.Adapter<Recyclerview_language_adepter.MyHolderView> {
private View view;
private Context context;
private ArrayList<model_language.Result> Main_lag;
private final static int FADE_DURATION = 700;
int lastPosition = -1;
@Override
public MyHolderView onCreateViewHolder(ViewGroup parent, int viewType) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.language_fragment_recycler_adepter_layout, parent, false);
context = view.getContext();
return new MyHolderView(view);
}
public Recyclerview_language_adepter(ArrayList<model_language.Result> Main_lag) {
this.Main_lag = Main_lag;
}
@Override
public void onBindViewHolder(Recyclerview_language_adepter.MyHolderView holder, final int position) {
if(position >lastPosition) {
Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_in_up);
view.startAnimation(animation);
// second animation
setScaleAnimation(holder.txt_name);
lastPosition = position;
}
if(position < lastPosition) {
Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_in_up);
view.startAnimation(animation);
// second animation
setScaleAnimation(holder.txt_name);
lastPosition = position;
}
holder.txt_name.setText(Main_lag.get(position).getCategoryName());
//---pass data to new activity
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String category_id= Main_lag.get(position).getCategoryId();
String category_name=Main_lag.get(position).getCategoryName();
Intent in=new Intent(context, CategoryTypeActivity.class);
in.putExtra("category_id",category_id);
in.putExtra("category_name",category_name);
context.startActivity(in);
}
});
}
@Override
public int getItemCount() {
return Main_lag.size();
}
public class MyHolderView extends RecyclerView.ViewHolder {
private final TextView txt_name;
public MyHolderView(View view) {
super(view);
txt_name=(TextView)view.findViewById(R.id.txt_name);
}
}
private void setScaleAnimation(View view) {
ScaleAnimation anim = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(FADE_DURATION);
view.startAnimation(anim);
}
}
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
public class ApiClient {
public static String BASE_URL = "https://sktechnocastt.000webhostapp.com/";
private static Retrofit retrofit = null;
public static Retrofit getClient(Context context) {
if (retrofit == null) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient httpClient = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addInterceptor(interceptor)
.build();
Gson gson = new GsonBuilder()
.setLenient()
.create();
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(httpClient)
.build();
}
return retrofit;
}
}
public interface ApiInterface {
@POST("/android_liveapp/status/status_main_item_category.php")
Call<model_language> readData();
}
public void initView() {
Log.i(TAG, "initView(), called : ");
try {
progressDialog = new ProgressDialog(getActivity());
rv_language = (RecyclerView) view.findViewById(R.id.rv_language);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 1);
rv_language.setLayoutManager(gridLayoutManager);
rv_language.setItemAnimator(new DefaultItemAnimator());
} catch (Exception e) {
e.printStackTrace();
}
}
private void getJsonDataFromServerLanguage() {
Log.i(TAG, "getJsonDataFromServerLanguage() called : ");
try {
progressDialog.setTitle(getResources().getString(R.string.please_wait));
progressDialog.setMessage(getResources().getString(R.string.loading));
progressDialog.show();
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(false);
ApiInterface apiService = ApiClient.getClient(getActivity()).create(ApiInterface.class);
Call<model_language> call = apiService.readData();
call.enqueue(new Callback<model_language>() {
@Override
public void onResponse(Call<model_language> call, Response<model_language> response) {
progressDialog.dismiss();
try {
Log.i(TAG, "getJsonDataFromServerLanguage response== : " + response.body().getResult().toString());
if (response.body().getSuccess().equals(1)) {
if (response.body().getResult().size() > 0 && response.body().getResult() != null) {
ArrayList<model_language.Result> model_languageList = new ArrayList<>();
model_languageList = response.body().getResult();
rv_language.setAdapter(new Recyclerview_language_adepter(model_languageList));
}
} else {
Toast.makeText(getActivity(), ("No Details Found").toString(), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<model_language> call, Throwable t) {
// Log error here since request failed
progressDialog.dismiss();
Toast.makeText(getActivity(), "Check Your Internet Connection", Toast.LENGTH_LONG).show();
Log.i(TAG, t.toString());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public class Recyclerview_language_adepter extends RecyclerView.Adapter<Recyclerview_language_adepter.MyHolderView> {
private View view;
private Context context;
private ArrayList<model_language.Result> Main_lag;
private final static int FADE_DURATION = 700;
int lastPosition = -1;
@Override
public MyHolderView onCreateViewHolder(ViewGroup parent, int viewType) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.language_fragment_recycler_adepter_layout, parent, false);
context = view.getContext();
return new MyHolderView(view);
}
public Recyclerview_language_adepter(ArrayList<model_language.Result> Main_lag) {
this.Main_lag = Main_lag;
}
@Override
public void onBindViewHolder(Recyclerview_language_adepter.MyHolderView holder, final int position) {
if(position >lastPosition) {
Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_in_up);
view.startAnimation(animation);
// second animation
setScaleAnimation(holder.txt_name);
lastPosition = position;
}
if(position < lastPosition) {
Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_in_up);
view.startAnimation(animation);
// second animation
setScaleAnimation(holder.txt_name);
lastPosition = position;
}
holder.txt_name.setText(Main_lag.get(position).getCategoryName());
//---pass data to new activity
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String category_id= Main_lag.get(position).getCategoryId();
String category_name=Main_lag.get(position).getCategoryName();
Intent in=new Intent(context, CategoryTypeActivity.class);
in.putExtra("category_id",category_id);
in.putExtra("category_name",category_name);
context.startActivity(in);
}
});
}
@Override
public int getItemCount() {
return Main_lag.size();
}
public class MyHolderView extends RecyclerView.ViewHolder {
private final TextView txt_name;
public MyHolderView(View view) {
super(view);
txt_name=(TextView)view.findViewById(R.id.txt_name);
}
}
private void setScaleAnimation(View view) {
ScaleAnimation anim = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(FADE_DURATION);
view.startAnimation(anim);
}
}
public class model_language {
/* @SerializedName("success")
@Expose
private Integer success;
@SerializedName("result")
@Expose
private ArrayList<Language> result = new ArrayList<>();
public Integer getSuccess() {
return success;
}
public void setSuccess(Integer success) {
this.success = success;
}
public ArrayList<Language> getResult() {
return result;
}
public void setResult(ArrayList<Language> result) {
this.result = result;
}
public static class Language{
@SerializedName("category_id")
@Expose
private String category_id;
@SerializedName("category_name")
@Expose
private String category_name;
public String getCategory_id() {
return category_id;
}
public void setCategory_id(String category_id) {
this.category_id = category_id;
}
public String getCategory_name() {
return category_name;
}
public void setCategory_name(String category_name) {
this.category_name = category_name;
}
}*/
@SerializedName("result")
@Expose
private ArrayList<Result> result = null;
@SerializedName("success")
@Expose
private Integer success;
public ArrayList<Result> getResult() {
return result;
}
public void setResult(ArrayList<Result> result) {
this.result = result;
}
public Integer getSuccess() {
return success;
}
public void setSuccess(Integer success) {
this.success = success;
}
public class Result {
@SerializedName("category_id")
@Expose
private String categoryId;
@SerializedName("category_name")
@Expose
private String categoryName;
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
}
}
*********************xml adepter
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="@+id/card_view"
style="@style/CardView.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="3dp"
card_view:cardBackgroundColor="@android:color/transparent"
card_view:cardElevation="0dp"
card_view:cardUseCompatPadding="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="@drawable/shadow"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/white"
android:padding="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_purple"
android:layout_gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/txt_name"
android:text="good dfgd dfg"
android:textStyle="bold|italic"
android:textSize="14dp"
android:textColor="@color/colorPrimaryDark"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
***********************
rv xml
<?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"
android:background="@drawable/app_baground"
android:paddingTop="10dp"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/snek_status_all">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
tools:listitem="@layout/language_fragment_recycler_adepter_layout"
android:id="@+id/rv_language">
</androidx.recyclerview.widget.RecyclerView>
<!--<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView_language"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
ads:adUnitId="@string/baner_id">
</com.google.android.gms.ads.AdView>-->
</RelativeLayout>
Comments
Post a Comment