From 427bb98d0a634c364243c2659e15a94522cf9fd3 Mon Sep 17 00:00:00 2001 From: NudeDude Date: Sun, 24 Dec 2017 22:54:22 +0100 Subject: [PATCH] Major Enhancements --- .../twidda/Engine/ProfileInformation.java | 3 -- .../twidda/Engine/ProfileTweets.java | 51 ++++++++++++++++++ .../twidda/Engine/RegisterAccount.java | 3 +- .../twidda/Engine/TwitterEngine.java | 53 ++++++------------- .../org/nuclearfog/twidda/Window/Profile.java | 5 +- 5 files changed, 70 insertions(+), 45 deletions(-) create mode 100644 app/src/main/java/org/nuclearfog/twidda/Engine/ProfileTweets.java diff --git a/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileInformation.java b/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileInformation.java index 41ae8105..2f4fff6a 100644 --- a/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileInformation.java +++ b/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileInformation.java @@ -30,7 +30,6 @@ public class ProfileInformation extends AsyncTask imgEnabled = settings.getBoolean("image_load",false); } - @Override protected void onPreExecute() { txtUser = (TextView) ((Profile)context).findViewById(R.id.profile_username); @@ -43,7 +42,6 @@ public class ProfileInformation extends AsyncTask banner = (ImageView)((Profile)context).findViewById(R.id.banner); } - /** * @param args [0] Twitter User ID */ @@ -65,7 +63,6 @@ public class ProfileInformation extends AsyncTask return null; } - @Override protected void onPostExecute(Void v) { ImageDownloader profileImg, bannerImg; diff --git a/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileTweets.java b/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileTweets.java new file mode 100644 index 00000000..98a22902 --- /dev/null +++ b/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileTweets.java @@ -0,0 +1,51 @@ +package org.nuclearfog.twidda.Engine; + +import android.content.Context; +import android.os.AsyncTask; +import android.support.v4.widget.SwipeRefreshLayout; +import android.widget.ListView; + +import org.nuclearfog.twidda.DataBase.TweetDatabase; +import org.nuclearfog.twidda.R; +import org.nuclearfog.twidda.ViewAdapter.TimelineAdapter; +import org.nuclearfog.twidda.Window.Profile; + +import twitter4j.Twitter; + +public class ProfileTweets extends AsyncTask { + + private Context context; + private SwipeRefreshLayout refreshHome; + private ListView profileList; + private TwitterStore twitterStore; + private TimelineAdapter homeTl; + + public ProfileTweets(Context context){ + this.context=context; + twitterStore = TwitterStore.getInstance(context); + twitterStore.init(); + } + + @Override + protected void onPreExecute(){ + refreshHome = (SwipeRefreshLayout)((Profile)context).findViewById(R.id.refreshHome); + profileList = (ListView)((Profile)context).findViewById(R.id.home_tl); + } + + @Override + protected Void doInBackground(Long... id) { + try { + Twitter twitter = twitterStore.getTwitter(); + long userId = id[0]; + TweetDatabase hTweets = new TweetDatabase(twitter.getUserTimeline(userId), context,TweetDatabase.USER_TL); + homeTl = new TimelineAdapter(context,R.layout.tweet,hTweets); + } catch(Exception err){err.printStackTrace();} + return null; + } + + @Override + protected void onPostExecute(Void v){ + profileList.setAdapter(homeTl); + refreshHome.setRefreshing(false); + } +} diff --git a/app/src/main/java/org/nuclearfog/twidda/Engine/RegisterAccount.java b/app/src/main/java/org/nuclearfog/twidda/Engine/RegisterAccount.java index 5879adf3..8cd262d1 100644 --- a/app/src/main/java/org/nuclearfog/twidda/Engine/RegisterAccount.java +++ b/app/src/main/java/org/nuclearfog/twidda/Engine/RegisterAccount.java @@ -12,7 +12,6 @@ import twitter4j.TwitterException; public class RegisterAccount extends AsyncTask { - private TwitterStore mTwitter; private Button loginButton, verifierButton; private Context context; @@ -29,7 +28,7 @@ public class RegisterAccount extends AsyncTask @Override protected Boolean doInBackground( String... twitterPin ) { String pin = twitterPin[0]; - mTwitter = TwitterStore.getInstance(context); + TwitterStore mTwitter = TwitterStore.getInstance(context); try { if( pin.trim().isEmpty() ) { mTwitter.request(); diff --git a/app/src/main/java/org/nuclearfog/twidda/Engine/TwitterEngine.java b/app/src/main/java/org/nuclearfog/twidda/Engine/TwitterEngine.java index 39c45c44..b1f5176e 100644 --- a/app/src/main/java/org/nuclearfog/twidda/Engine/TwitterEngine.java +++ b/app/src/main/java/org/nuclearfog/twidda/Engine/TwitterEngine.java @@ -22,10 +22,10 @@ public class TwitterEngine extends AsyncTask private final String ERR_MSG = "Fehler bei der Verbindung"; private TwitterStore twitterStore; private Context context; - private ListView list, profileList; - private TimelineAdapter timelineAdapter, homeTl; + private ListView list; + private TimelineAdapter timelineAdapter; private TrendsAdapter trendsAdapter; - private SwipeRefreshLayout refresh, refreshHome; + private SwipeRefreshLayout refresh; public TwitterEngine(Context context) { this.context=context; @@ -35,21 +35,13 @@ public class TwitterEngine extends AsyncTask @Override protected void onPreExecute() { - - if(context.getClass() == MainActivity.class) - { - refresh = (SwipeRefreshLayout)((MainActivity)context).findViewById(R.id.refresh); - list = (ListView)((MainActivity)context).findViewById(R.id.list); - }else { - refreshHome = (SwipeRefreshLayout)((Profile)context).findViewById(R.id.refreshHome); - profileList = (ListView)((Profile)context).findViewById(R.id.home_tl); - } + refresh = (SwipeRefreshLayout)((MainActivity)context).findViewById(R.id.refresh); + list = (ListView)((MainActivity)context).findViewById(R.id.list); } - /** - * @param args [0] Executing Mode: (0)HomeTL, (1)Trend, (2)Mention, (3)UserTL - * [1] User ID + * @param args [0] Executing Mode: (0)HomeTL, (1)Trend, (2)Mention + * */ @Override protected Void doInBackground(Long... args) { @@ -65,11 +57,6 @@ public class TwitterEngine extends AsyncTask } else if(args[0]==2) { //TODO } - else if(args[0]==3) { - long userId = args[1]; - TweetDatabase hTweets = new TweetDatabase(twitter.getUserTimeline(userId), context,TweetDatabase.USER_TL); - homeTl = new TimelineAdapter(context,R.layout.tweet,hTweets); - } } catch (TwitterException e) { Toast.makeText(context, ERR_MSG, Toast.LENGTH_SHORT).show(); } catch (Exception e){ e.printStackTrace(); } @@ -81,23 +68,13 @@ public class TwitterEngine extends AsyncTask */ @Override protected void onPostExecute(Void v) { - new Thread() { - @Override - public void run(){ - if(timelineAdapter != null) { - list.setAdapter(timelineAdapter); - } - else if(trendsAdapter != null) { - list.setAdapter(trendsAdapter); - } - else if(homeTl != null) { - profileList.setAdapter(homeTl); - } - if(refresh != null) - refresh.setRefreshing(false); - if(refreshHome!= null) - refreshHome.setRefreshing(false); - } - }.run(); + if(timelineAdapter != null) { + list.setAdapter(timelineAdapter); + } + else if(trendsAdapter != null) { + list.setAdapter(trendsAdapter); + } + if(refresh != null) + refresh.setRefreshing(false); } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/twidda/Window/Profile.java b/app/src/main/java/org/nuclearfog/twidda/Window/Profile.java index 392406ff..a4bac662 100644 --- a/app/src/main/java/org/nuclearfog/twidda/Window/Profile.java +++ b/app/src/main/java/org/nuclearfog/twidda/Window/Profile.java @@ -15,6 +15,7 @@ import android.widget.TabHost; import android.widget.TextView; import org.nuclearfog.twidda.Engine.ProfileInformation; +import org.nuclearfog.twidda.Engine.ProfileTweets; import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.Engine.TwitterEngine; @@ -109,7 +110,7 @@ public class Profile extends AppCompatActivity { } private void getTweets(){ - TwitterEngine twitterEngine = new TwitterEngine(this); - twitterEngine.execute(3L,userId); + ProfileTweets mProfile = new ProfileTweets(this); + mProfile.execute(userId); } }