public class casaactivity extends AppCompatActivity {

    String localcasa;
    String precocasa;
    String imgurlcasa;
    String infocasa;
    String idcasa;
    Toolbar toolbarinfocasa;
    ImageView imageViewinfocasa;
    TextView textViewinfocasa;
    ViewGroup mRoot;
    AppBarLayout appBarLayout;
    CollapsingToolbarLayout imgtoolbar;
    LikeButton favoriteButton;
    SharedPreferences sharedPreferences;
    SharedPreferences isappopen;
    SharedPreferences.Editor editor;
    String PREFSNAME = "FAVS";
    final String ISOPENAPP="appstate";
    int favflag;
    int nightModeFlags;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ){
            Transition tr=new ChangeBounds();
            getWindow().setSharedElementEnterTransition(tr);
        }

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_casaactivity);

        nightModeFlags =
                casaactivity.this.getResources().getConfiguration().uiMode &
                        Configuration.UI_MODE_NIGHT_MASK;

        isappopen=getSharedPreferences(ISOPENAPP, 0);
        editor=isappopen.edit();
        editor.putInt("open", 1);
        editor.apply();

        localcasa=getIntent().getStringExtra("localcasa");
        precocasa=getIntent().getStringExtra("precocasa");
        imgurlcasa=getIntent().getStringExtra("imgurl");
        infocasa=getIntent().getStringExtra("infocs");
        idcasa=getIntent().getStringExtra("csid");

        appBarLayout= findViewById(R.id.infocasaappbar);
        toolbarinfocasa= findViewById(R.id.barinfocasaactivity);
        toolbarinfocasa.setTitle(localcasa);
        if (isNetworkAvailable(casaactivity.this)){
            toolbarinfocasa.setNavigationIcon(R.mipmap.ic_arrow_back_white_24dp);
        }else {
            toolbarinfocasa.setNavigationIcon(R.mipmap.ic_arrow_back_black_24dp);
        }

        imageViewinfocasa= findViewById(R.id.imginfocasaactivity);
        toolbarinfocasa.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        imgtoolbar= findViewById(R.id.tbinfocasaactivity);


        textViewinfocasa= findViewById(R.id.txtinfocasaactivity);

        VolleySingleton volleySingleton = VolleySingleton.getInstancia(casaactivity.this);
        RequestQueue requestQueue = volleySingleton.getRequestQueue();
        ImageLoader imageLoader = volleySingleton.getImageLoader();

        if (isNetworkAvailable(casaactivity.this)) {

            imageLoader.get(imgurlcasa, new ImageLoader.ImageListener() {
                @Override
                public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
                    imageViewinfocasa.setImageBitmap(response.getBitmap());
                }
                @Override
                public void onErrorResponse(VolleyError error) {

                }

            });

        }else {
            imageViewinfocasa.setImageResource(R.drawable.logo);
            switch (nightModeFlags) {
                case Configuration.UI_MODE_NIGHT_YES:
                    imgtoolbar.setExpandedTitleColor(ContextCompat.getColor(casaactivity.this,android.R.color.black));
                    imgtoolbar.setCollapsedTitleTextColor(ContextCompat.getColor(casaactivity.this,android.R.color.white));
                    break;
                case Configuration.UI_MODE_NIGHT_NO:
                    imgtoolbar.setExpandedTitleColor(ContextCompat.getColor(casaactivity.this,android.R.color.black));
                    imgtoolbar.setCollapsedTitleTextColor(ContextCompat.getColor(casaactivity.this,android.R.color.black));
                    break;
            }
        }


        favoriteButton= findViewById(R.id.favbuttoncasa);
        favoriteButton.setIcon(IconType.Heart);
        favoriteButton.setIconSizeDp(25);
        favoriteButton.setCircleEndColorRes(R.color.colorAccent);
        favoriteButton.setExplodingDotColorsRes(R.color.colorPrimary,R.color.colorAccent);
        favoriteButton.setLikeDrawableRes(R.drawable.heartliked);
        favoriteButton.setUnlikeDrawableRes(R.drawable.heartunliked);

        sharedPreferences=getSharedPreferences(PREFSNAME, 0);
        favflag=sharedPreferences.getInt(idcasa, 0);

        firebaseutils.checklike(casaactivity.this,idcasa,favoriteButton);


        favoriteButton.setOnLikeListener(new OnLikeListener() {
            @Override
            public void liked(LikeButton likeButton) {
                favflag = sharedPreferences.getInt(idcasa, 0);

                sharedPreferences = getSharedPreferences(PREFSNAME, 0);
                editor = sharedPreferences.edit();
                editor.putInt(idcasa, 1);
                editor.apply();
                favflag = sharedPreferences.getInt(idcasa, 0);

                firebaseutils.setlike(idcasa);

                favoriteButton.setLiked(true);
            }

            @Override
            public void unLiked(LikeButton likeButton) {

                favflag = sharedPreferences.getInt(idcasa, 0);

                sharedPreferences = getSharedPreferences(PREFSNAME, 0);
                editor = sharedPreferences.edit();
                editor.putInt(String.valueOf(idcasa), 0);
                editor.apply();
                favflag = sharedPreferences.getInt(String.valueOf(idcasa), 0);

                firebaseutils.removelike(idcasa);

                favoriteButton.setLiked(false);
            }
        });


        textViewinfocasa.setText("Preço: " + precocasa+"\n\n"+infocasa);

        mRoot= findViewById(R.id.card_viewinfo);

    }

    @Override
    public void onBackPressed() {
        if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ){
            TransitionManager.beginDelayedTransition(mRoot,new Slide());
            mRoot.setVisibility(View.INVISIBLE);
        }
        if (isTaskRoot()) {
            finish();
            startActivity(new Intent(this, MainActivity.class));
        } else {
            super.onBackPressed();
        }
    }

    public boolean isNetworkAvailable(final Context context) {
        final ConnectivityManager connectivityManager = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
        return (connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null) != null && connectivityManager.getActiveNetworkInfo().isConnected();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
} public class adaptadorrvtodas extends RecyclerView.Adapter<adaptadorrvtodas.vhtodas> {

    private ArrayList<todascasas> casas=new ArrayList<>();
    private LayoutInflater layoutInflater;
    private ImageLoader imageLoader;
    public static Context ctx;

    public  adaptadorrvtodas(Context context){
        layoutInflater= LayoutInflater.from(context);
        VolleySingleton volleySingleton=VolleySingleton.getInstancia(context);
        imageLoader=volleySingleton.getImageLoader();
        ctx=context;

    }

    public void setCasas(ArrayList<todascasas> cs){
        this.casas=cs;
        notifyDataSetChanged();
    }

    @Override
    public vhtodas onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=layoutInflater.inflate(R.layout.itencasas, parent, false);
        return new vhtodas(view);
    }

    @Override
    public void onBindViewHolder(final vhtodas holder, final int position) {

        YoYo.with(Techniques.Tada)
                .duration(700)
                .playOn(holder.itemView);

        final todascasas casaexata=casas.get(position);
        holder.txtLocalcasa.setText(casaexata.getLOCAL());
        holder.txtPrecocasa.setText(casaexata.getPRECO());
        String url=casaexata.getIMGURL();
        if(url!=null){
            imageLoader.get(url, new ImageLoader.ImageListener() {
                @Override
                public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
                    holder.imgcasa.setImageBitmap(response.getBitmap());
                }

                @Override
                public void onErrorResponse(VolleyError error) {
                    holder.imgcasa.setImageResource(R.drawable.logo);
                }
            });
        }
        holder.favoriteButton.setIcon(IconType.Heart);
        holder.favoriteButton.setIconSizeDp(25);
        holder.favoriteButton.setCircleEndColorRes(R.color.colorAccent);
        holder.favoriteButton.setExplodingDotColorsRes(R.color.colorPrimary,R.color.colorAccent);
        holder.favoriteButton.setLikeDrawableRes(R.drawable.heartliked);
        holder.favoriteButton.setUnlikeDrawableRes(R.drawable.heartunliked);

        holder.favoriteButton.setOnLikeListener(new OnLikeListener() {
            @Override
            public void liked(LikeButton likeButton) {
                firebaseutils.setlike(casaexata.getID());
                holder.favoriteButton.setLiked(true);
            }

            @Override
            public void unLiked(LikeButton likeButton) {
                firebaseutils.removelike(casaexata.getID());
                holder.favoriteButton.setLiked(false);
            }
        });
        firebaseutils.checklike(ctx,casaexata.getID(),holder.favoriteButton);
    }

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

    static class vhtodas extends RecyclerView.ViewHolder implements View.OnClickListener{

        private ImageView imgcasa;
        private TextView txtLocalcasa;
        private TextView txtPrecocasa;
        private LikeButton favoriteButton;

        vhtodas(final View itemView) {
            super(itemView);

            imgcasa = itemView.findViewById(R.id.imgcasa);
            txtLocalcasa = itemView.findViewById(R.id.txtlocalcasa);
            txtPrecocasa = itemView.findViewById(R.id.txtprecocasa);
            favoriteButton = itemView.findViewById(R.id.favbutton);


        }

        @Override
        public void onClick(View v) {

        }
    }
} public class adaptadorrvtodasoffline extends RecyclerView.Adapter<adaptadorrvtodasoffline.vhoffline> {

    private LayoutInflater inflater;
    private List<listasql> dados= Collections.emptyList();
    private static Context ctx;

    public adaptadorrvtodasoffline(Context c,List<listasql> dados){
        inflater=LayoutInflater.from(c);
        this.dados=dados;
        ctx=c;
    }


    @Override
    public vhoffline onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=inflater.inflate(R.layout.itencasas, parent, false);
        return new vhoffline(view);
    }

    @Override
    public void onBindViewHolder(final vhoffline holder, int position) {

        YoYo.with(Techniques.Tada)
                .duration(700)
                .playOn(holder.itemView);

        final listasql offlinedata=dados.get(position);
        holder.txtLocalcasa.setText(offlinedata.Loc);
        holder.imgcasa.setImageResource(R.drawable.logo);
        holder.txtPrecocasa.setText(offlinedata.Prec);

        holder.favoriteButton.setIcon(IconType.Heart);
        holder.favoriteButton.setIconSizeDp(25);
        holder.favoriteButton.setCircleEndColorRes(R.color.colorAccent);
        holder.favoriteButton.setExplodingDotColorsRes(R.color.colorPrimary,R.color.colorAccent);
        holder.favoriteButton.setLikeDrawableRes(R.drawable.heartliked);
        holder.favoriteButton.setUnlikeDrawableRes(R.drawable.heartunliked);


        holder.favoriteButton.setOnLikeListener(new OnLikeListener() {
            @Override
            public void liked(LikeButton likeButton) {
                firebaseutils.setlike(offlinedata.Id);
                holder.favoriteButton.setLiked(true);
            }

            @Override
            public void unLiked(LikeButton likeButton) {
                firebaseutils.removelike(offlinedata.Id);
                holder.favoriteButton.setLiked(false);
            }
        });

        firebaseutils.checklike(ctx,offlinedata.Id,holder.favoriteButton);
    }

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

    class vhoffline extends RecyclerView.ViewHolder{
        private ImageView imgcasa;
        private TextView txtLocalcasa;
        private TextView txtPrecocasa;
        private LikeButton favoriteButton;

        vhoffline(View itemView) {
            super(itemView);

            imgcasa= itemView.findViewById(R.id.imgcasa);
            txtLocalcasa= itemView.findViewById(R.id.txtlocalcasa);
            txtPrecocasa= itemView.findViewById(R.id.txtprecocasa);
            favoriteButton= itemView.findViewById(R.id.favbutton);
        }
    }
} public class VolleySingleton {

    private static VolleySingleton mInstancia;
    private RequestQueue mrequestQueue;
    private ImageLoader mimageLoader;
    private static Context mContext;

    private VolleySingleton(Context context){
        mContext=context;
        mrequestQueue=getRequestQueue();

        mimageLoader=new ImageLoader(mrequestQueue, new ImageLoader.ImageCache() {
            private final LruCache<String, Bitmap>
                    cache = new LruCache<>(20);

            @Override
            public Bitmap getBitmap(String url) {
                return cache.get(url);
            }

            @Override
            public void putBitmap(String url, Bitmap bitmap) {
                cache.put(url, bitmap);
            }
        });
    }

    public static synchronized VolleySingleton getInstancia(Context context){
        if(mInstancia==null){
            mInstancia=new VolleySingleton(context);
        }

        return mInstancia;
    }

    public RequestQueue getRequestQueue() {
        if (mrequestQueue == null) {

            mrequestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
        }
        return mrequestQueue;
    }

    public <T> void addToRequestQueue(Request<T> req) {
        getRequestQueue().add(req);
    }

    public ImageLoader getImageLoader() {
        return mimageLoader;
    }


} public class BDAdapter {

    private BDCore core;
    static Context ctx;
   private String loc;
   private String prec;
   private String inf;

    public BDAdapter(Context context){
        core=new BDCore(context);
        ctx=context;
    }

    public Long inserirdados(String local, String preco, String info){

        SQLiteDatabase sqLiteDatabase=core.getWritableDatabase();
        ContentValues contentValues=new ContentValues();
        contentValues.put(BDCore.TABLE_LOCAL,local);
        contentValues.put(BDCore.TABLE_PRECO,preco);
        contentValues.put(BDCore.TABLE_INFO, info);
        contentValues.put(BDCore.TABLE_FAV, 0);

        return sqLiteDatabase.insert(BDCore.TABLE_NAME, null, contentValues);
    }

    public String verlocais(String ID){
        SQLiteDatabase sqLiteDatabase=core.getWritableDatabase();
        String[] colunas={BDCore.TABLE_LOCAL,BDCore.TABLE_PRECO,BDCore.TABLE_INFO};
        Cursor cursor=sqLiteDatabase.query(BDCore.TABLE_NAME, colunas, BDCore.TABLE_ID + "='" + ID + "'", null, null, null, null);
        while (cursor.moveToNext()){
            loc=cursor.getString(0);
            prec=cursor.getString(1);
            inf=cursor.getString(2);



            //Toast.makeText(ctx,loc+" "+prec+" "+inf+" ",Toast.LENGTH_LONG).show();

        }
        cursor.close();
        return loc;
    }

    public String verprecos(String ID){
        SQLiteDatabase sqLiteDatabase=core.getWritableDatabase();
        String[] colunas={BDCore.TABLE_LOCAL,BDCore.TABLE_PRECO,BDCore.TABLE_INFO};
        Cursor cursor=sqLiteDatabase.query(BDCore.TABLE_NAME, colunas, BDCore.TABLE_ID+"='"+ID+"'", null, null, null, null);
        while (cursor.moveToNext()){

            loc=cursor.getString(0);
            prec=cursor.getString(1);
            inf=cursor.getString(2);



            //Toast.makeText(ctx,loc+" "+prec+" "+inf+" ",Toast.LENGTH_LONG).show();

        }
        cursor.close();
        return prec;
    }

    public String verinfos(String ID){
        SQLiteDatabase sqLiteDatabase=core.getWritableDatabase();
        String[] colunas={BDCore.TABLE_LOCAL,BDCore.TABLE_PRECO,BDCore.TABLE_INFO};
        Cursor cursor=sqLiteDatabase.query(BDCore.TABLE_NAME, colunas, BDCore.TABLE_ID+"='"+ID+"'", null, null, null, null);
        while (cursor.moveToNext()){
            loc=cursor.getString(0);
            prec=cursor.getString(1);
            inf=cursor.getString(2);



            //Toast.makeText(ctx,loc+" "+prec+" "+inf+" ",Toast.LENGTH_LONG).show();

        }
        cursor.close();
        return inf;
    }

    public  int numerodecolunas(){
        int cnt=0;
        try {
            SQLiteDatabase sqLiteDatabase=core.getWritableDatabase();
            Cursor cursor=sqLiteDatabase.query(BDCore.TABLE_NAME, null,null, null, null, null, null);
            while (cursor.moveToNext()){
                cnt++;


            }
            cursor.close();
        }catch (Exception ex){
            Toast.makeText(ctx,ex.toString(),Toast.LENGTH_LONG).show();
        }
        return cnt;
    }

    private static class BDCore extends SQLiteOpenHelper {
        private static final String BD_NAME="dbcasas";
        private static final int BD_VERSION=4;
        private static final String TABLE_NAME="casa";
        private static final String TABLE_LOCAL="local";
        private static final String TABLE_PRECO="preco";
        private static final String TABLE_INFO="infocasa";
        private static final String TABLE_ID="_id";
        private static final String TABLE_FAV="fav";
        Context context;

        BDCore(Context context) {
            super(context, BD_NAME, null, BD_VERSION);
            this.context=context;
        }

        @Override
        public void onCreate(SQLiteDatabase db) {

            try {
                db.execSQL("create table "+TABLE_NAME+"("+TABLE_ID+" integer primary key autoincrement,"+TABLE_LOCAL+" text not null,"+TABLE_PRECO+" text not null,infocasa text not null,"+TABLE_FAV+" integer);");

            }catch (Exception e){
                Toast.makeText(ctx,e.toString(),Toast.LENGTH_LONG).show();
            }

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            try {
                db.execSQL("drop table casa;");
                Toast.makeText(ctx,"base de dados atualizada",Toast.LENGTH_LONG).show();
                onCreate(db);
            }catch (Exception e){
                Toast.makeText(ctx,e.toString(),Toast.LENGTH_LONG).show();
            }

        }
    }

} public class NetworkCheck {
    public static boolean isNetworkAvailable(final Context context) {
        final ConnectivityManager connectivityManager = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
        return (connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null) != null && connectivityManager.getActiveNetworkInfo().isConnected();
    }
} public interface RecyclerViewOnClickListenerHack {
    void onClickListener(View view, int position);
    void onLongPressClickListener(View view, int position);
} public interface keys {

    interface allkeys{
        String KEY_ID="id";
        String KEY_LOCAL="local";
        String KEY_PRECO="preco";
        String KEY_IMGURL="imgURL";
        String KEY_INFO="infocasa";
    }
} public class listacasas {

    public String Local;
    public String Preço;
    public String IMGurl;
    public String info;
    public String idcs;
} public class listasql {
    public String Loc;
    public String Inf;
    public String Prec;
    public String Id;
} public class todascasas {

    private String ID;
    private String LOCAL;
    private String PRECO;
    private String IMGURL;


    public todascasas(){

    }

    public todascasas(String local,
                      String preco,
                      String imgurl,
                      String id){
        this.LOCAL=local;
        this.PRECO=preco;
        this.IMGURL=imgurl;
        this.ID=id;
    }

    public void setLOCAL(String local){
        this.LOCAL=local;
    }

    public void setPRECO(String preco){
        this.PRECO=preco;
    }
    public void setIMGURL(String imgurl){
        this.IMGURL=imgurl;
    }

    public void setID(String id){
        this.ID=id;
    }

    public String getLOCAL(){
        return LOCAL;
    }

    public String getPRECO(){
        return PRECO;
    }
    public String getIMGURL(){
        return IMGURL;
    }

    public String getID(){
        return ID;
    }

    public String toString(){
        return
                "ID: "+ID
                +"\nLOCAL: "+ LOCAL
                +"\nPRECO: "+PRECO
                +"\nIMGURL: "+IMGURL;
    }
}
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.util.Pair;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.CardView;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.telephony.TelephonyManager;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.example.massa.luxvilla.Actividades.casaactivity;
import com.example.massa.luxvilla.R;
import com.example.massa.luxvilla.adaptadores.adaptadorrvtodas;
import com.example.massa.luxvilla.adaptadores.adaptadorrvtodasoffline;
import com.example.massa.luxvilla.network.VolleySingleton;
import com.example.massa.luxvilla.sqlite.BDAdapter;
import com.example.massa.luxvilla.utils.NetworkCheck;
import com.example.massa.luxvilla.utils.RecyclerViewOnClickListenerHack;
import com.example.massa.luxvilla.utils.keys;
import com.example.massa.luxvilla.utils.listacasas;
import com.example.massa.luxvilla.utils.listasql;
import com.example.massa.luxvilla.utils.todascasas;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;

                    favflag=sharedPreferences.getInt(id, 0);
                    if (favflag==1){
                        todascasas casasadd=new todascasas();
                        casasadd.setLOCAL(local);
                        casasadd.setPRECO(preco);
                        casasadd.setIMGURL(imgurl);
                        casasadd.setID(id);
                        listacasas cs=new listacasas();
                        cs.Local=local;
                        cs.Preço=preco;
                        cs.IMGurl=imgurl;
                        cs.info=info;
                        cs.idcs=id;

                        casas.add(0,casasadd);
                        ids.add(0,cs);
                    }

                } catch (JSONException e) {
                    progressBar.setVisibility(View.GONE);
                    swipeRefreshLayout.setVisibility(View.VISIBLE);
                    Toast.makeText(getActivity(), "Falha ao ligar ao servidor", Toast.LENGTH_LONG).show();
                }
            }

        }
        return casas;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view= inflater.inflate(R.layout.fragment_separadorlikes, container, false);

        recyclerViewtodas= view.findViewById(R.id.rvcasas);
        progressBar= view.findViewById(R.id.progress_bar);
        swipeRefreshLayout= view.findViewById(R.id.swipe);

        TelephonyManager manager = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
        if(manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE){
            //tablet
            final int rotation = ((WindowManager) ctxtodas.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
            switch (rotation) {
                case Surface.ROTATION_0:
                    recyclerViewtodas.setLayoutManager(new GridLayoutManager(getActivity(), 2, GridLayoutManager.VERTICAL, false));
                    break;
                case Surface.ROTATION_90:
                    recyclerViewtodas.setLayoutManager(new GridLayoutManager(getActivity(), 4, GridLayoutManager.VERTICAL, false));
                    break;
                case Surface.ROTATION_180:
                    recyclerViewtodas.setLayoutManager(new GridLayoutManager(getActivity(), 2, GridLayoutManager.VERTICAL, false));
                    break;
                default:
                    recyclerViewtodas.setLayoutManager(new GridLayoutManager(getActivity(), 4, GridLayoutManager.VERTICAL, false));
                    break;
                case Surface.ROTATION_270:
                    break;
            }
        }else{
            //phone
            final int rotation = ((WindowManager) ctxtodas.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
            switch (rotation) {
                case Surface.ROTATION_0:
                    recyclerViewtodas.setLayoutManager(new LinearLayoutManager(getActivity()));
                    break;
                case Surface.ROTATION_90:
                    recyclerViewtodas.setLayoutManager(new GridLayoutManager(getActivity(), 2, GridLayoutManager.VERTICAL, false));
                    break;
                case Surface.ROTATION_180:
                    recyclerViewtodas.setLayoutManager(new LinearLayoutManager(getActivity()));
                    break;
                default:
                    recyclerViewtodas.setLayoutManager(new GridLayoutManager(getActivity(), 2, GridLayoutManager.VERTICAL, false));
                    break;
                case Surface.ROTATION_270:
                    break;
            }
        }

        if (NetworkCheck.isNetworkAvailable(getActivity())) {

            adaptador=new adaptadorrvtodas(getActivity());
            recyclerViewtodas.setAdapter(adaptador);

            sendjsonRequest();
        } else {
            progressBar.setVisibility(View.GONE);
            swipeRefreshLayout.setVisibility(View.VISIBLE);
            adaptadoroffline=new adaptadorrvtodasoffline(getActivity(),getdados());
            recyclerViewtodas.setAdapter(adaptadoroffline);
        }


        //SWIPE
        swipeRefreshLayout.setColorSchemeColors(ContextCompat.getColor(getActivity(),R.color.colorPrimaryDark),ContextCompat.getColor(getActivity(),R.color.colorPrimaryDark),ContextCompat.getColor(getActivity(),R.color.colorPrimaryDark));
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if (NetworkCheck.isNetworkAvailable(getActivity())) {

                    adaptador=new adaptadorrvtodas(getActivity());
                    recyclerViewtodas.setAdapter(adaptador);

                    sendjsonRequest();
                } else {
                    adaptadoroffline=new adaptadorrvtodasoffline(getActivity(),getdados());
                    recyclerViewtodas.setAdapter(adaptadoroffline);
                }

                swipeRefreshLayout.setRefreshing(false);
            }
        });

        recyclerViewtodas.addOnItemTouchListener(new RecyclerViewTouchListener(getActivity(), recyclerViewtodas, this));

        return view;
    }

    public static List<listasql> getdados(){