Advertisement
MarMar_IV

Twít

Oct 22nd, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1.     class Tweet{
  2.         private String message;
  3.  
  4.         public Tweet(String message){
  5.             this.message = message;
  6.         }
  7.  
  8.         public String getMessage() {
  9.             return message;
  10.         }
  11.     }
  12.  
  13.     class GetTweetsTask extends AsyncTask<String, Integer, Boolean>{
  14.         private Context context;
  15.         private ProgressDialog dialog;
  16.         private ArrayList<Tweet> mojeTweety;
  17.  
  18.         public GetTweetsTask(Context p_Context){
  19.             this.context = p_Context;
  20.  
  21.             this.mojeTweety = new ArrayList<Tweet>();
  22.  
  23.             this.dialog = new ProgressDialog(p_Context);
  24.             this.dialog.setMessage("NaÄŤĂ­tám tweety");
  25.         }
  26.  
  27.         @Override
  28.         protected void onPreExecute() {
  29.             this.dialog.show();
  30.         }
  31.  
  32.         @Override
  33.         protected Boolean doInBackground(String... params) {
  34.             Boolean res = false;
  35.  
  36.             try {
  37.                 ResponseList<twitter4j.Status> statusy = twitter.getUserTimeline();
  38.                 for(twitter4j.Status status : statusy){
  39.                     Tweet tweet = new Tweet(status.getText());
  40.  
  41.                     this.mojeTweety.add(tweet);
  42.                 }
  43.  
  44.                 res = true;
  45.             } catch (Exception e) {
  46.                 e.printStackTrace();
  47.             }
  48.  
  49.             return res;
  50.         }
  51.  
  52.         @Override
  53.         protected void onPostExecute(Boolean result) {
  54.             this.dialog.cancel();
  55.  
  56.             if(result){
  57.                 MainActivity.this.states.clear();
  58.                 MainActivity.this.states.addAll(this.mojeTweety);
  59.                 MainActivity.this.adapter.notifyDataSetChanged();
  60.             }else{
  61.                 Toast.makeText(context, "Nastala chyba pĹ™i stahovánĂ­ dat", Toast.LENGTH_SHORT).show();
  62.             }
  63.         }
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement