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);
}
@Override
protected void onPreExecute() {
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);
}
/**
* @param args [0] Twitter User ID
*/
@ -65,7 +63,6 @@ public class ProfileInformation extends AsyncTask<Long,Void,Void>
return null;
}
@Override
protected void onPostExecute(Void v) {
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>
{
private TwitterStore mTwitter;
private Button loginButton, verifierButton;
private Context context;
@ -29,7 +28,7 @@ public class RegisterAccount extends AsyncTask<String, Void, Boolean>
@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();

View File

@ -22,10 +22,10 @@ public class TwitterEngine extends AsyncTask<Long, Void, Void>
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<Long, Void, Void>
@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<Long, Void, Void>
}
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<Long, Void, Void>
*/
@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);
}
}

View File

@ -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);
}
}