SHARE
TWEET

Untitled

takieddine Oct 18th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MatchesDetails extends AppCompatActivity {
  2.  
  3.     private TextView dates, homescorer, awayscorer, homeyellower, awayyellower, homereder, awayreder, homegoal, awaygoal;
  4.     private Button refresh, goback;
  5.     private ImageView staduims;
  6.     private RequestQueue requestQueue;
  7.     private String eventid;
  8.     private InterstitialAd interstitial;
  9.     private boolean shouldLoadAds;
  10.  
  11.     @Override
  12.     protected void onCreate(@Nullable Bundle savedInstanceState) {
  13.         super.onCreate(savedInstanceState);
  14.         setContentView(R.layout.activity_matchesdetails);
  15.  
  16.         dates = findViewById(R.id.detailsdate);
  17.         staduims = findViewById(R.id.detailsphoto);
  18.         homescorer = findViewById(R.id.homescorer);
  19.         awayscorer = findViewById(R.id.awayscorer);
  20.         homeyellower = findViewById(R.id.homeyellow);
  21.         awayyellower = findViewById(R.id.awayyellow);
  22.         homereder = findViewById(R.id.homered);
  23.         awayreder = findViewById(R.id.awayred);
  24.         homegoal = findViewById(R.id.sporthomescore);
  25.         awaygoal = findViewById(R.id.sportawayscore);
  26.         goback = findViewById(R.id.gobacks);
  27.         refresh = findViewById(R.id.refreshs);
  28.  
  29.  
  30.         /// this is where i receive each eventid based on position
  31.         Intent intent1 = getIntent();
  32.         if (intent1 != null) {
  33.             eventid = intent1.getStringExtra("keys");
  34.         }
  35.  
  36.         if (isConnected()) {
  37.             showdata();
  38.         } else {
  39.             getprefs();
  40.         }
  41.         loadad();
  42.     }
  43.  
  44. /// this is where i retreived data based on eventid
  45.     private void showdata() {
  46.  
  47.         homescorer.setText("");
  48.         awayscorer.setText("");
  49.         homeyellower.setText("");
  50.         awayyellower.setText("");
  51.         homereder.setText("");
  52.         awayreder.setText("");
  53.  
  54.         String api_key = "https://www.thesportsdb.com/api/v1/json/4013070/lookupevent.php?id=" + eventid;
  55.         requestQueue = Volley.newRequestQueue(MatchesDetails.this);
  56.         JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, api_key, null, new
  57.           Response.Listener<JSONObject>() {
  58.             @Override
  59.             public void onResponse(JSONObject response) {
  60.                 try {
  61.                     JSONArray jsonArray = response.getJSONArray("events");
  62.                     for (int i = 0; i < jsonArray.length(); i++) {
  63.                         JSONObject jsonObject = jsonArray.getJSONObject(i);
  64.                         String date = jsonObject.getString("dateEvent");
  65.                         String staduim = jsonObject.getString("strThumb");
  66.                         String homescore = jsonObject.getString("strHomeGoalDetails");
  67.                         String homegoals = jsonObject.getString("intHomeScore");
  68.                         String awaygoals = jsonObject.getString("intAwayScore");
  69.                         String myawayred = jsonObject.getString("strAwayRedCards");
  70.                         String awayscore = jsonObject.getString("strAwayGoalDetails");
  71.                         String myhomey = jsonObject.getString("strHomeYellowCards");
  72.                         String myawayy = jsonObject.getString("strAwayYellowCards");
  73.                         String myhomered = jsonObject.getString("strHomeRedCards");
  74.                         int thiseventid = jsonObject.getInt("idEvent");
  75.  
  76.                         dates.setText(date);
  77.                         homescorer.setText("" + homescore);
  78.                         awayscorer.setText("" + awayscore);
  79.                         awaygoal.setText("" + awaygoals);
  80.                         homereder.setText("" + myhomered);
  81.                         awayreder.setText("" + myawayred);
  82.                         homeyellower.setText("" + myhomey);
  83.                         awayyellower.setText("" + myawayy);
  84.                         homegoal.setText("" + homegoals);
  85.                         Picasso.with(MatchesDetails.this).load(staduim).fit().into(staduims);
  86.  
  87.                        SharedPreferences sharedPreferences =getSharedPreferences("context",MODE_PRIVATE);
  88.                        SharedPreferences.Editor editor = sharedPreferences.edit();
  89.                        editor.putString("date",date);
  90.                        editor.putString("homescore",homescore);
  91.                        editor.putString("awayscore",awayscore);
  92.                        editor.putString("homeyellow",myhomey);
  93.                        editor.putString("awayyellow",myawayy);
  94.                        editor.putString("hred",myhomered);
  95.                        editor.putString("yred",myawayred);
  96.                        editor.putString("photo",staduim);
  97.                        editor.putString("home",homegoals);
  98.                        editor.putString("away",awaygoals);
  99.                        editor.apply();
  100.  
  101.  
  102.                     }
  103.  
  104.  
  105.                 } catch (JSONException e) {
  106.                     e.printStackTrace();
  107.                 }
  108.             }
  109.         }, error -> {
  110.  
  111.         });
  112.         requestQueue.add(jsonObjectRequest);
  113.  
  114.  
  115.     }
  116.  
  117.    
  118.     //// this is where im retreiving the data
  119.     private void getprefs() {
  120.  
  121.         SharedPreferences sharedPreferences = getSharedPreferences("context", MODE_PRIVATE);
  122.         String date1 = sharedPreferences.getString("date", null);
  123.         String homescorer1 = sharedPreferences.getString("homescore", null);
  124.         String awayscorer1 = sharedPreferences.getString("awayscore", null);
  125.         String homeyellow1 = sharedPreferences.getString("homeyellow", null);
  126.         String awayyelow1 = sharedPreferences.getString("awayyelow", null);
  127.         String homered1 = sharedPreferences.getString("hred", null);
  128.         String awayred1 = sharedPreferences.getString("yred", null);
  129.         String photo = sharedPreferences.getString("photo", null);
  130.         String myhome = sharedPreferences.getString("home", null);
  131.         String away = sharedPreferences.getString("away", null);
  132.         Picasso.with(MatchesDetails.this).load(photo).fit().into(staduims);
  133.  
  134.  
  135.        if (date1 != null && homescorer1 != null && awayscorer1 != null && homeyellow1 != null && awayyelow1 != null
  136.                 && homered1 != null && awayred1 != null && photo != null && myhome != null && away != null) {
  137.             dates.setText("" + date1);
  138.             homescorer.setText("" + homescorer1);
  139.             awayscorer.setText("" + awayscorer1);
  140.             homeyellower.setText("" + homeyellow1);
  141.             awayyellower.setText("" + awayyelow1);
  142.             homereder.setText("" + homered1);
  143.             awayreder.setText("" + awayred1);
  144.             homegoal.setText("" + myhome);
  145.             awaygoal.setText("" + away);
  146.  
  147.         } else {
  148.       // do something
  149.         }
  150.  
  151.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top