retrofit sun

implementation 'com.android.support:cardview-v7:28.0.0'implementation 'com.android.support:recyclerview-v7:28.0.0'

implementation 'com.android.support:design:28.0.0'implementation 'com.android.support:percent:28.0.0'
implementation 'com.squareup.retrofit:retrofit:1.9.0'implementation 'com.squareup.retrofit2:retrofit:2.2.0'implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
implementation 'com.google.code.gson:gson:2.8.2'

package com.sunil.hp.gjstatus.activity;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.support.design.widget.Snackbar;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;
import com.sunil.hp.gjstatus.R;
import com.sunil.hp.gjstatus.adepter.Recyclerview_Category_adepter;
import com.sunil.hp.gjstatus.helper.AppConfig;
import com.sunil.hp.gjstatus.model.model_category;
import com.sunil.hp.gjstatus.preference.LoginPreference;

import java.util.ArrayList;

import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;

@SuppressLint("LongLogTag")
public class CategoryStatusActivity extends AppCompatActivity {

    private static final String TAG = "[CategoryStatusActivity]";
    String BASE_URL = "http://sktechnocast.com/";
    private String category_id;
    private String category_name;

    ArrayList sub_category_id = new ArrayList<>();
    ArrayList sub_category_name = new ArrayList<>();
    private String pos;
    private ProgressDialog loading;

    private boolean isConnected = false;
    private RelativeLayout snek_status_sub_main;
    private LoginPreference session;
    private RecyclerView rv_all_fes_joke;
    private SwipeRefreshLayout swipeRefreshLayout;
    private model_category model_category_dislpay;
    private Recyclerview_Category_adepter mAdapter;
    private String title_name = "Profile Display";

    private BroadcastReceiver myReceiver = new BroadcastReceiver() {
        @Override        public void onReceive(Context context, Intent intent) {
            isNetworkAvailable(context);
        }
    };
    private AdView adView;
    private InterstitialAd mInterstitial;
    private InterstitialAd mInterstitialAd;

    private boolean isNetworkAvailable(Context context) {

        snek_status_sub_main = (RelativeLayout) findViewById(R.id.snek_status_sub_main);

        ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null) {
                for (int i = 0; i < info.length; i++) {
                    if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                        if (!isConnected) {
                            try {
                                sub_category_id.clear();
                                sub_category_name.clear();
                                displayData();

                                isConnected = true;
                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                        }
                        return true;
                    }
                }
            }
        }

        Snackbar snackbar = Snackbar.make(snek_status_sub_main, "No internet connection!", Snackbar.LENGTH_LONG);
        View sbView = snackbar.getView();
        TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setTextColor(Color.YELLOW);
        snackbar.show();

        isConnected = false;
        return false;
    }


    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.category_status_activity);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        Log.i(TAG, "onCreate(), called : ");
        try {

            getSupportActionBar().setTitle(title_name);
            ActionBar mActionbar = getSupportActionBar();
            mActionbar.setBackgroundDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.toolbar_baground, null));
            if (Build.VERSION.SDK_INT >= 21) {
                getWindow().setBackgroundDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.toolbar_baground, null)); //status bar or the time bar at the top            }

            IntentFilter filter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
            getApplicationContext().registerReceiver(myReceiver, filter);

            addbaner();
            init();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public  void  addbaner(){
        try {

            MobileAds.initialize(this,getResources().getString(R.string.addmob_app_id));
            adView = (AdView) findViewById(R.id.adView);
            adView.setAdListener(new AdListener()
            {
                public  void onAdLoaded()
                {
                    adView.setVisibility(View.VISIBLE);
                }
            });
            AdRequest adRequest = new AdRequest.Builder().build();
            adView.loadAd(adRequest);

        }
        catch (Exception e){
            e.printStackTrace();
        }

    }

    public void init() {
        Log.i(TAG, "init(), called : ");
        try {

            Intent i = getIntent();
            category_id = i.getStringExtra("category_id");
            category_name = i.getStringExtra("category_name");

            getSupportActionBar().setTitle(category_name);

            swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);

            rv_all_fes_joke = (RecyclerView) findViewById(R.id.rv_all_fes_joke);

            swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override                public void onRefresh() {
                    // code to refresh
                    sub_category_id.clear();
                    sub_category_name.clear();
                    displayData();

                    swipeRefreshLayout.setRefreshing(false);   //code to stop refresh animation
                }
            });


            GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(), 1);
            rv_all_fes_joke.setLayoutManager(gridLayoutManager);
            rv_all_fes_joke.setItemAnimator(new DefaultItemAnimator());

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override    public boolean onSupportNavigateUp() {
        onBackPressed();
        return true;
    }

    public void onDestroy() {
        super.onDestroy();
        getApplicationContext().unregisterReceiver(myReceiver);
    }


    public void displayData() {
        Log.i(TAG, "init(), called : ");
        try {

            loading = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
            loading.setMessage("Loading");
            loading.show();
            loading.setCancelable(true);
            loading.setCanceledOnTouchOutside(false);

            RestAdapter adapter = new RestAdapter.Builder()
                    .setEndpoint(BASE_URL) //Setting the Root URL                    .build();

            AppConfig.status_sub api = adapter.create(AppConfig.status_sub.class);
            api.status_sub_readal(
                    category_id,

                    new Callback<model_category>() {

                        @Override                        public void success(model_category display_model, Response response) {

                            if (display_model.getSuccess() == 1) {

                                model_category_dislpay = display_model;
                                mAdapter = new Recyclerview_Category_adepter(model_category_dislpay);
                                rv_all_fes_joke.setAdapter(mAdapter);
                                loading.dismiss();
                            } else {
                                loading.dismiss();
                                Toast.makeText(getApplicationContext(), "No Details Found", Toast.LENGTH_SHORT).show();
                            }

                        }

                        @Override                        public void failure(RetrofitError error) {
                            Toast.makeText(CategoryStatusActivity.this, "Check Your Inter Net Connection", Toast.LENGTH_SHORT).show();

                        }
                    }
            );

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

============adepter
package com.sunil.hp.gjstatus.adepter;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.widget.TextView;

import com.sunil.hp.gjstatus.R;
import com.sunil.hp.gjstatus.activity.Selected_SubCategory_Activity;
import com.sunil.hp.gjstatus.model.model_category;


public class Recyclerview_Category_adepter extends RecyclerView.Adapter<Recyclerview_Category_adepter.MyHolderView> {

    private  Context context;
    private final static int FADE_DURATION = 700;
    int lastPosition = -1;
    private View view;
    private model_category Model_Jok_Fes;

    Activity mBureauRateListing;    // it's Activity    Recyclerview_Category_adepter (Activity activity) {
        mBureauRateListing = activity;
    }

    @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_Category_adepter(model_category Model_Jok_Fes) {
        this.Model_Jok_Fes = Model_Jok_Fes;
    }
    @Override    public void onBindViewHolder(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.card_view);

            lastPosition = position;
        }
        if (position < lastPosition) {

            Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_in_up);
            view.startAnimation(animation);
            // second animation            setScaleAnimation(holder.card_view);

            lastPosition = position;
        }

        holder.txt_name.setText(Model_Jok_Fes.getResult().get(position).getSub_category_name());

        //---pass data to new activity
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {

                String sub_category_id= Model_Jok_Fes.getResult().get(position).getSub_category_id();
                String sub_category_name=Model_Jok_Fes.getResult().get(position).getSub_category_name();

                Intent in=new Intent(context,Selected_SubCategory_Activity.class);
                in.putExtra("sub_category_id",sub_category_id);
                in.putExtra("sub_category_name",sub_category_name);

                context.startActivity(in);

            }
        });

    }


    @Override
    public int getItemCount() {
        return Model_Jok_Fes.getResult().size();
    }


    public class MyHolderView extends RecyclerView.ViewHolder {
        private final TextView txt_name;
        private final CardView card_view;

        public MyHolderView(View view) {
            super(view);
            card_view =(CardView) view.findViewById(R.id.card_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);
    }
}


<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">

    <android.support.v7.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>

    </android.support.v7.widget.CardView>

</LinearLayout>


public class AppConfig {

public interface status_sub {
    @FormUrlEncoded    @POST("/android_liveapp/status/status_main_item_sub_category.php")
    void status_sub_readal(
            @Field("category_id") String category_id,
            Callback<model_category> callback);
}
}

Comments

Popular posts from this blog

retrofil gjstatus lanuage

form object

Login Preference in android create class