Major Enhancements

This commit is contained in:
NudeDude 2017-12-24 22:54:22 +01:00
parent b9346b4978
commit 427bb98d0a
5 changed files with 70 additions and 45 deletions

View File

@ -30,7 +30,6 @@ public class ProfileInformation extends AsyncTask<Long,Void,Void>
imgEnabled = settings.getBoolean("image_load",false); imgEnabled = settings.getBoolean("image_load",false);
} }
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
txtUser = (TextView) ((Profile)context).findViewById(R.id.profile_username); txtUser = (TextView) ((Profile)context).findViewById(R.id.profile_username);
@ -43,7 +42,6 @@ public class ProfileInformation extends AsyncTask<Long,Void,Void>
banner = (ImageView)((Profile)context).findViewById(R.id.banner); banner = (ImageView)((Profile)context).findViewById(R.id.banner);
} }
/** /**
* @param args [0] Twitter User ID * @param args [0] Twitter User ID
*/ */
@ -65,7 +63,6 @@ public class ProfileInformation extends AsyncTask<Long,Void,Void>
return null; return null;
} }
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
ImageDownloader profileImg, bannerImg; ImageDownloader profileImg, bannerImg;

View File

@ -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<Long, Void, Void> {
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);
}
}

View File

@ -12,7 +12,6 @@ import twitter4j.TwitterException;
public class RegisterAccount extends AsyncTask<String, Void, Boolean> public class RegisterAccount extends AsyncTask<String, Void, Boolean>
{ {
private TwitterStore mTwitter;
private Button loginButton, verifierButton; private Button loginButton, verifierButton;
private Context context; private Context context;
@ -29,7 +28,7 @@ public class RegisterAccount extends AsyncTask<String, Void, Boolean>
@Override @Override
protected Boolean doInBackground( String... twitterPin ) { protected Boolean doInBackground( String... twitterPin ) {
String pin = twitterPin[0]; String pin = twitterPin[0];
mTwitter = TwitterStore.getInstance(context); TwitterStore mTwitter = TwitterStore.getInstance(context);
try { try {
if( pin.trim().isEmpty() ) { if( pin.trim().isEmpty() ) {
mTwitter.request(); mTwitter.request();

View File

@ -22,10 +22,10 @@ public class TwitterEngine extends AsyncTask<Long, Void, Void>
private final String ERR_MSG = "Fehler bei der Verbindung"; private final String ERR_MSG = "Fehler bei der Verbindung";
private TwitterStore twitterStore; private TwitterStore twitterStore;
private Context context; private Context context;
private ListView list, profileList; private ListView list;
private TimelineAdapter timelineAdapter, homeTl; private TimelineAdapter timelineAdapter;
private TrendsAdapter trendsAdapter; private TrendsAdapter trendsAdapter;
private SwipeRefreshLayout refresh, refreshHome; private SwipeRefreshLayout refresh;
public TwitterEngine(Context context) { public TwitterEngine(Context context) {
this.context=context; this.context=context;
@ -35,21 +35,13 @@ public class TwitterEngine extends AsyncTask<Long, Void, Void>
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
refresh = (SwipeRefreshLayout)((MainActivity)context).findViewById(R.id.refresh);
if(context.getClass() == MainActivity.class) list = (ListView)((MainActivity)context).findViewById(R.id.list);
{
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);
}
} }
/** /**
* @param args [0] Executing Mode: (0)HomeTL, (1)Trend, (2)Mention, (3)UserTL * @param args [0] Executing Mode: (0)HomeTL, (1)Trend, (2)Mention
* [1] User ID *
*/ */
@Override @Override
protected Void doInBackground(Long... args) { protected Void doInBackground(Long... args) {
@ -65,11 +57,6 @@ public class TwitterEngine extends AsyncTask<Long, Void, Void>
} }
else if(args[0]==2) { //TODO 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) { } catch (TwitterException e) {
Toast.makeText(context, ERR_MSG, Toast.LENGTH_SHORT).show(); Toast.makeText(context, ERR_MSG, Toast.LENGTH_SHORT).show();
} catch (Exception e){ e.printStackTrace(); } } catch (Exception e){ e.printStackTrace(); }
@ -81,23 +68,13 @@ public class TwitterEngine extends AsyncTask<Long, Void, Void>
*/ */
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
new Thread() { if(timelineAdapter != null) {
@Override list.setAdapter(timelineAdapter);
public void run(){ }
if(timelineAdapter != null) { else if(trendsAdapter != null) {
list.setAdapter(timelineAdapter); list.setAdapter(trendsAdapter);
} }
else if(trendsAdapter != null) { if(refresh != null)
list.setAdapter(trendsAdapter); refresh.setRefreshing(false);
}
else if(homeTl != null) {
profileList.setAdapter(homeTl);
}
if(refresh != null)
refresh.setRefreshing(false);
if(refreshHome!= null)
refreshHome.setRefreshing(false);
}
}.run();
} }
} }

View File

@ -15,6 +15,7 @@ import android.widget.TabHost;
import android.widget.TextView; import android.widget.TextView;
import org.nuclearfog.twidda.Engine.ProfileInformation; import org.nuclearfog.twidda.Engine.ProfileInformation;
import org.nuclearfog.twidda.Engine.ProfileTweets;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.Engine.TwitterEngine; import org.nuclearfog.twidda.Engine.TwitterEngine;
@ -109,7 +110,7 @@ public class Profile extends AppCompatActivity {
} }
private void getTweets(){ private void getTweets(){
TwitterEngine twitterEngine = new TwitterEngine(this); ProfileTweets mProfile = new ProfileTweets(this);
twitterEngine.execute(3L,userId); mProfile.execute(userId);
} }
} }