Могут ли все ссылки на изображения, доступные в Интернете, использоваться в json-документе?

Amit Chaudhary спросил: 30 августа 2018 в 05:27 в: java

Я создаю приложение для Android с помощью Android-студии. Я использую api, загружая свой json-файл на dropbox.https://www.dropbox.com/s/45xopes03s1iyse/Movie.json? dl = 0 Я хочу знать изображения, которые я взял, могут использоваться в моем проекте, потому что они не загружаются, когда я использую GLIDE для извлечения изображений и сбоев приложений.

Также данные автоматически не обновляются автоматически. Мне нужно обновить снова и снова для отображаемых данных

КОД:

Моя основная активность:

package com.example.amitc.pvrathome;import android.app.usage.UsageEvents;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.*;
import android.support.v7.widget.Toolbar;
import android.view.View;import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;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.StringRequest;
import com.android.volley.toolbox.Volley;import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.net.URL;
import java.util.ArrayList;public class movies_tab extends AppCompatActivity {    //private static final String url = "https://www.dropbox.com/s/45xopes03s1iyse/Movie.json?dl=1";
    private static final String url = "https://www.dropbox.com/s/45xopes03s1iyse/Movie.json?dl=1";
    private ArrayList<String> m_name = new ArrayList<>();
    private ArrayList<String> m_release_year = new ArrayList<>();
    private ArrayList<String> m_genre = new ArrayList<>();
    private ArrayList<String> m_desc = new ArrayList<>();
    private ArrayList<String> m_director = new ArrayList<>();
    private ArrayList<String> m_rating = new ArrayList<>();
    private ArrayList<String> m_actor = new ArrayList<>();
    private ArrayList<String> m_imgsrc = new ArrayList<>();    private ArrayList<String> m_name1 = new ArrayList<>();
    private ArrayList<String> m_release_year1 = new ArrayList<>();
    private ArrayList<String> m_genre1 = new ArrayList<>();
    private ArrayList<String> m_director1 = new ArrayList<>();
    private ArrayList<String> m_rating1 = new ArrayList<>();
    private ArrayList<String> m_actor1 = new ArrayList<>();
    private ArrayList<String> m_desc1 = new ArrayList<>();
    private ArrayList<String> m_imgsrc1 = new ArrayList<>();    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_movies_tab);        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);        // add back arrow to toolbar
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
        }        StringRequest stringRequest = new StringRequest(Request.Method.GET,
                url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            JSONArray array = jsonObject.getJSONArray("movies");                            for (int i = 0; i < array.length(); i++) {
                                JSONObject o = array.getJSONObject(i);
                                String name = o.getString("name");
                                String year = o.getString("year");
                                String genre = o.getString("genre");
                                String rating = o.getString("rating");
                                String director = o.getString("directors_name");
                                String actor = o.getString("cast");
                                String img_src = o.getString("poster_src");
                                String desc = o.getString("description");                                m_name.add(name);
                                m_release_year.add(year);
                                m_genre.add(genre);
                                m_rating.add(rating);
                                m_director.add(director);
                                m_actor.add(actor);
                                m_imgsrc.add(img_src);
                                m_desc.add(desc);                                m_name1.add(name);
                                m_release_year1.add(year);
                                m_genre1.add(genre);
                                m_rating1.add(rating);
                                m_director1.add(director);
                                m_actor1.add(actor);
                                m_imgsrc1.add(img_src);
                                m_desc1.add(desc);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {                    }
                });        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);        initRecyclerView1();
        initRecyclerView1();
    }    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // handle arrow click here
        if (item.getItemId() == android.R.id.home) {
            finish(); // close this activity and return to preview activity (if there is any)
        }        return super.onOptionsItemSelected(item);
    }    public void initRecyclerView() {
        //Log.d(TAG, "initRecyclerView: init recyclerview.");
        RecyclerView recyclerView = findViewById(R.id.newest);
        RecyclerViewAdapter adapter = new RecyclerViewAdapter(m_name, m_release_year, m_genre, m_desc, m_director, m_rating, m_actor, m_imgsrc, this);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    }    public void initRecyclerView1() {
        //Log.d(TAG, "initRecyclerView: init recyclerview.");
        RecyclerView recyclerView = findViewById(R.id.hottest);
        RecyclerViewAdapter adapter = new RecyclerViewAdapter(m_name1, m_release_year1, m_genre1, m_desc1, m_director1, m_rating1, m_actor1, m_imgsrc1, this);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    }    public void gotoHome(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.home_button);
        startActivity(new Intent(movies_tab.this, MainActivity.class));
    }    public void gotoMovies(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.movie_button);
        startActivity(new Intent(movies_tab.this, movies_tab.class));
    }    public void gotoSeries(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.series_button);
        startActivity(new Intent(movies_tab.this, series_tab.class));
    }    public void gotoSpecials(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.specials_button);
        startActivity(new Intent(movies_tab.this, specials_tab.class));
    }    public void gotoActors(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.actors_button);
        startActivity(new Intent(movies_tab.this, actors_tab.class));
    }    public void gotoFavourites(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.favorites_button);
        startActivity(new Intent(movies_tab.this, favorite_tab.class));
    }    public void gotoDownloads(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.downloads_button);
        startActivity(new Intent(movies_tab.this, downloaded_tab.class));
    }
}

ADAPTER:

package com.example.amitc.pvrathome;import android.content.Context;
import android.content.Intent;
import android.media.Image;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;import com.bumptech.glide.Glide;import java.util.ArrayList;public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>{    private ArrayList<String> m_name = new ArrayList<>();
    private ArrayList<String> m_year = new ArrayList<>();
    private ArrayList<String> m_genre = new ArrayList<>();
    private ArrayList<String> m_images = new ArrayList<>();
    private ArrayList<String> m_desc = new ArrayList<>();
    private ArrayList<String> m_director = new ArrayList<>();
    private ArrayList<String> m_rating = new ArrayList<>();
    private ArrayList<String> m_stars = new ArrayList<>();    private Context mContext;    public RecyclerViewAdapter(ArrayList<String> m_name, ArrayList<String> m_year, ArrayList<String> m_genre, ArrayList<String> m_desc, ArrayList<String> m_director, ArrayList<String> m_rating, ArrayList<String> m_stars, ArrayList<String> images,  Context mContext) {
        this.m_name = m_name;
        this.m_year = m_year;
        this.m_genre = m_genre;
        this.m_desc = m_desc;
        this.m_director = m_director;
        this.m_rating = m_rating;
        this.m_stars = m_stars;
        this.mContext = mContext;
        this.m_images = images;
    }    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row, viewGroup, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {//        Glide.with(mContext)
//                .asBitmap()
//                .load(m_images.get(i))
//                .into(viewHolder.img);        viewHolder.parentLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                Intent intent = new Intent(mContext, msms.class);
                intent.putExtra("names", m_name.get(i));
                intent.putExtra("genres", m_genre.get(i));
                intent.putExtra("years", m_year.get(i));
                intent.putExtra("stars", m_stars.get(i));
                intent.putExtra("decs", m_desc.get(i));
                intent.putExtra("direcs", m_director.get(i));
                intent.putExtra("ratings", m_rating.get(i));
                intent.putExtra("img1", m_images.get(i));                mContext.startActivity(intent);
                }
        });        viewHolder.names.setText(m_name.get(i));
        viewHolder.years.setText(m_year.get(i));
        viewHolder.genres.setText(m_genre.get(i));//        Glide.with(mContext)
//                .asBitmap()
//                .load(m_images.get(i))
//                .into(viewHolder.img1);
    }    @Override
    public int getItemCount() {
        return m_name.size();
    }    public class ViewHolder extends RecyclerView.ViewHolder
    {
        LinearLayout parentLayout;
        TextView names;
        TextView years;
        TextView genres;
        TextView actors;
        ImageView img;
        ImageView img1;        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            parentLayout = itemView.findViewById(R.id.dabba);
            names = itemView.findViewById(R.id.m_name);
            years = itemView.findViewById(R.id.m_year);
            genres = itemView.findViewById(R.id.m_genre);
            //img = itemView.findViewById(R.id.dabba);
            img1 = itemView.findViewById(R.id.msms_image);
        }
    }
}

Другой адаптер внутри адаптера:

package com.example.amitc.pvrathome;import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;public class msms extends AppCompatActivity{
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.msms);        getIncomingIntent();
    }    private void getIncomingIntent()
    {
        String name = getIntent().getStringExtra("names");
        String name1 = getIntent().getStringExtra("names");
        String year = getIntent().getStringExtra("years");
        String genre = getIntent().getStringExtra("genres");
        String rating = getIntent().getStringExtra("ratings");
        String desc = getIntent().getStringExtra("decss");
        String director = getIntent().getStringExtra("direcs");
        String actor = getIntent().getStringExtra("stars");
        String img_src = getIntent().getStringExtra("img_src");        TextView m_name = (TextView) findViewById(R.id.msms_name);
        m_name.setText(name);        TextView m_name1 = (TextView) findViewById(R.id.msms_name1);
        m_name1.setText(name);
//        TextView m_year = (TextView) findViewById(R.id.msms_year);
//        m_year.setText(year);        TextView m_genre = (TextView) findViewById(R.id.msms_genre);
        m_genre.setText(genre);        TextView m_rating = (TextView) findViewById(R.id.msms_rating);
        m_rating.setText(rating);        TextView m_desc = (TextView) findViewById(R.id.msms_desc);
        m_desc.setText(desc);        TextView m_direc = (TextView) findViewById(R.id.msms_direc);
        m_direc.setText(director);        TextView m_actor = (TextView) findViewById(R.id.msms_actor);
        m_actor.setText(actor);        final ImageView imageView = (ImageView) findViewById(R.id.msms_image);
        Glide.with(this)
                .asBitmap()
                .load(img_src)
                .into(imageView);

}

Обновлено основное действие:

package com.example.amitc.pvrathome;import android.app.usage.UsageEvents;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.*;
import android.support.v7.widget.Toolbar;
import android.view.View;import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;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.StringRequest;
import com.android.volley.toolbox.Volley;import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.net.URL;
import java.util.ArrayList;public class movies_tab extends AppCompatActivity {    //private static final String url = "https://www.dropbox.com/s/45xopes03s1iyse/Movie.json?dl=1";
    private static final String url = "https://www.dropbox.com/s/45xopes03s1iyse/Movie.json?dl=1";
    private ArrayList<String> m_name = new ArrayList<>();
    private ArrayList<String> m_release_year = new ArrayList<>();
    private ArrayList<String> m_genre = new ArrayList<>();
    private ArrayList<String> m_desc = new ArrayList<>();
    private ArrayList<String> m_director = new ArrayList<>();
    private ArrayList<String> m_rating = new ArrayList<>();
    private ArrayList<String> m_actor = new ArrayList<>();
    private ArrayList<String> m_imgsrc = new ArrayList<>();
    StringRequest stringRequest;
    private ArrayList<String> m_name1 = new ArrayList<>();
    private ArrayList<String> m_release_year1 = new ArrayList<>();
    private ArrayList<String> m_genre1 = new ArrayList<>();
    private ArrayList<String> m_director1 = new ArrayList<>();
    private ArrayList<String> m_rating1 = new ArrayList<>();
    private ArrayList<String> m_actor1 = new ArrayList<>();
    private ArrayList<String> m_desc1 = new ArrayList<>();
    private ArrayList<String> m_imgsrc1 = new ArrayList<>();    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_movies_tab);        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);        // add back arrow to toolbar
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
        }        new fetchdata().execute();
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);        initRecyclerView();        initRecyclerView1();
    }    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // handle arrow click here
        if (item.getItemId() == android.R.id.home) {
            finish(); // close this activity and return to preview activity (if there is any)
        }        return super.onOptionsItemSelected(item);
    }    public void initRecyclerView() {
        //Log.d(TAG, "initRecyclerView: init recyclerview.");
        RecyclerView recyclerView = findViewById(R.id.newest);
        RecyclerViewAdapter adapter = new RecyclerViewAdapter(m_name, m_release_year, m_genre, m_desc, m_director, m_rating, m_actor, m_imgsrc, this);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    }    public void initRecyclerView1() {
        //Log.d(TAG, "initRecyclerView: init recyclerview.");
        RecyclerView recyclerView = findViewById(R.id.hottest);
        RecyclerViewAdapter adapter = new RecyclerViewAdapter(m_name1, m_release_year1, m_genre1, m_desc1, m_director1, m_rating1, m_actor1, m_imgsrc1, this);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    }    public void gotoHome(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.home_button);
        startActivity(new Intent(movies_tab.this, MainActivity.class));
    }    public void gotoMovies(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.movie_button);
        startActivity(new Intent(movies_tab.this, movies_tab.class));
    }    public void gotoSeries(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.series_button);
        startActivity(new Intent(movies_tab.this, series_tab.class));
    }    public void gotoSpecials(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.specials_button);
        startActivity(new Intent(movies_tab.this, specials_tab.class));
    }    public void gotoActors(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.actors_button);
        startActivity(new Intent(movies_tab.this, actors_tab.class));
    }    public void gotoFavourites(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.favorites_button);
        startActivity(new Intent(movies_tab.this, favorite_tab.class));
    }    public void gotoDownloads(View v) {
        //ImageView btn = (ImageView)findViewById(R.id.downloads_button);
        startActivity(new Intent(movies_tab.this, downloaded_tab.class));
    }    public class fetchdata extends AsyncTask<Void, Void, Void> {        @Override
        protected Void doInBackground(Void... voids) {
            stringRequest = new StringRequest(Request.Method.GET,
                url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            JSONArray array = jsonObject.getJSONArray("movies");                            for (int i = 0; i < array.length(); i++) {
                                JSONObject o = array.getJSONObject(i);
                                String name = o.getString("name");
                                String year = o.getString("year");
                                String genre = o.getString("genre");
                                String rating = o.getString("rating");
                                String director = o.getString("directors_name");
                                String actor = o.getString("cast");
                                String img_src = o.getString("poster_src");
                                String desc = o.getString("description");                                m_name.add(name);
                                m_release_year.add(year);
                                m_genre.add(genre);
                                m_rating.add(rating);
                                m_director.add(director);
                                m_actor.add(actor);
                                m_imgsrc.add(img_src);
                                m_desc.add(desc);                                m_name1.add(name);
                                m_release_year1.add(year);
                                m_genre1.add(genre);
                                m_rating1.add(rating);
                                m_director1.add(director);
                                m_actor1.add(actor);
                                m_imgsrc1.add(img_src);
                                m_desc1.add(desc);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {                    }
                });            return null;
        }
    }
}

0 ответов