Cleanup, bugfix

This commit is contained in:
Sufian 2018-05-19 11:36:31 +02:00
parent fff724d2f4
commit 069fd694c3
10 changed files with 62 additions and 51 deletions

View File

@ -1,5 +1,6 @@
package org.nuclearfog.twidda.backend; package org.nuclearfog.twidda.backend;
import android.annotation.SuppressLint;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -18,24 +19,22 @@ import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.ErrorLog; import org.nuclearfog.twidda.database.ErrorLog;
import java.io.InputStream; import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.net.URL; import java.net.URL;
public class ImagePopup extends AsyncTask<String, Void, Boolean> { public class ImagePopup extends AsyncTask<String, Void, Boolean> {
private ImageView mImg; private WeakReference<Context> ui;
private Dialog popup; private Dialog popup;
private Bitmap imgArray[]; private Bitmap imgArray[];
private ProgressBar mCircle;
private Context c;
private LayoutInflater inf; private LayoutInflater inf;
private int index = 0; private int index = 0;
private int position = 0; private int position = 0;
public ImagePopup(Context c) { public ImagePopup(Context c) {
popup = new Dialog(c); popup = new Dialog(c);
mCircle = new ProgressBar(c); ui = new WeakReference<>(c);
inf = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inf = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.c = c;
} }
@Override @Override
@ -43,6 +42,7 @@ public class ImagePopup extends AsyncTask<String, Void, Boolean> {
popup.requestWindowFeature(Window.FEATURE_NO_TITLE); popup.requestWindowFeature(Window.FEATURE_NO_TITLE);
if(popup.getWindow() != null) if(popup.getWindow() != null)
popup.getWindow().setBackgroundDrawableResource(android.R.color.transparent); popup.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
ProgressBar mCircle = new ProgressBar(ui.get());
popup.setContentView(mCircle); popup.setContentView(mCircle);
popup.setOnCancelListener(new DialogInterface.OnCancelListener() { popup.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override @Override
@ -76,18 +76,19 @@ public class ImagePopup extends AsyncTask<String, Void, Boolean> {
} catch (Exception err) { } catch (Exception err) {
Log.e("shitter:","Image download failed!"); Log.e("shitter:","Image download failed!");
err.printStackTrace(); err.printStackTrace();
ErrorLog errorLog = new ErrorLog(c); ErrorLog errorLog = new ErrorLog(ui.get());
errorLog.add(err.getMessage()); errorLog.add(err.getMessage());
return false; return false;
} }
} }
@Override @Override
@SuppressLint("InflateParams")
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
if(result) { if(result) {
View content = inf.inflate(R.layout.imagepreview,null); View content = inf.inflate(R.layout.imagepreview,null,false);
mImg = content.findViewById(R.id.fullSizeImage); ImageView mImg = content.findViewById(R.id.fullSizeImage);
setImage(imgArray[position]); setImage(imgArray[position], mImg);
popup.setContentView(content); popup.setContentView(content);
if(index > 0) { if(index > 0) {
final Button left = content.findViewById(R.id.image_left); final Button left = content.findViewById(R.id.image_left);
@ -121,7 +122,7 @@ public class ImagePopup extends AsyncTask<String, Void, Boolean> {
} }
} }
private void setImage(Bitmap btm) { private void setImage(Bitmap btm, ImageView mImg) {
int height = (int)(btm.getHeight() / (btm.getWidth() / 640.0)); int height = (int)(btm.getHeight() / (btm.getWidth() / 640.0));
btm = Bitmap.createScaledBitmap( btm,640,height, false); btm = Bitmap.createScaledBitmap( btm,640,height, false);
mImg.setImageBitmap(btm); mImg.setImageBitmap(btm);

View File

@ -32,7 +32,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
private WeakReference<MainActivity> ui; private WeakReference<MainActivity> ui;
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private RecyclerView timelineList, trendList, mentionList;
private TimelineRecycler timelineAdapter, mentionAdapter; private TimelineRecycler timelineAdapter, mentionAdapter;
private TrendRecycler trendsAdapter; private TrendRecycler trendsAdapter;
private int woeid; private int woeid;
@ -49,17 +49,19 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
mTwitter = TwitterEngine.getInstance(context); mTwitter = TwitterEngine.getInstance(context);
SharedPreferences settings = context.getSharedPreferences("settings", 0); SharedPreferences settings = context.getSharedPreferences("settings", 0);
woeid = settings.getInt("woeid",23424829); // Germany WOEID woeid = settings.getInt("woeid",23424829); // Germany WOEID
timelineList = ui.get().findViewById(R.id.tl_list);
trendList = ui.get().findViewById(R.id.tr_list);
mentionList = ui.get().findViewById(R.id.m_list);
highlight = settings.getInt("highlight_color", 0xffff00ff); highlight = settings.getInt("highlight_color", 0xffff00ff);
font = settings.getInt("font_color", 0xffffffff); font = settings.getInt("font_color", 0xffffffff);
image = settings.getBoolean("image_load", true); image = settings.getBoolean("image_load", true);
RecyclerView timelineList = ui.get().findViewById(R.id.tl_list);
RecyclerView mentionList = ui.get().findViewById(R.id.m_list);
timelineAdapter = (TimelineRecycler) timelineList.getAdapter();
mentionAdapter = (TimelineRecycler) mentionList.getAdapter();
} }
/** /**
* @param args [0] Execution Mode: (0)HomeTL, (1)Trend, (2)Mention * @param args [0] Execution Mode: (0)HomeTL, (1)Trend, (2)Mention
* @return success * @return Mode
*/ */
@Override @Override
protected Integer doInBackground(Integer... args) { protected Integer doInBackground(Integer... args) {
@ -72,7 +74,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
TrendDatabase trendDb = new TrendDatabase(ui.get()); TrendDatabase trendDb = new TrendDatabase(ui.get());
switch (MODE) { switch (MODE) {
case HOME: case HOME:
timelineAdapter = (TimelineRecycler) timelineList.getAdapter();
if(timelineAdapter != null && timelineAdapter.getItemCount() > 0) { if(timelineAdapter != null && timelineAdapter.getItemCount() > 0) {
id = timelineAdapter.getItemId(0); id = timelineAdapter.getItemId(0);
tweets = mTwitter.getHome(page,id); tweets = mTwitter.getHome(page,id);
@ -98,7 +100,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
case TRND: case TRND:
List<Trend> trends = mTwitter.getTrends(woeid); List<Trend> trends = mTwitter.getTrends(woeid);
trendDb.store(trends); trendDb.store(trends);
trendsAdapter = (TrendRecycler) trendList.getAdapter();
trendsAdapter = new TrendRecycler(trends, ui.get()); trendsAdapter = new TrendRecycler(trends, ui.get());
trendsAdapter.setColor(font); trendsAdapter.setColor(font);
break; break;
@ -110,7 +112,6 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
case MENT: case MENT:
List<Tweet> mention; List<Tweet> mention;
mentionAdapter = (TimelineRecycler) mentionList.getAdapter();
if(mentionAdapter != null && mentionAdapter.getItemCount() != 0) { if(mentionAdapter != null && mentionAdapter.getItemCount() != 0) {
id = mentionAdapter.getItemId(0); id = mentionAdapter.getItemId(0);
mention = mTwitter.getMention(page,id); mention = mTwitter.getMention(page,id);
@ -150,6 +151,9 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
SwipeRefreshLayout timelineRefresh = connect.findViewById(R.id.timeline); SwipeRefreshLayout timelineRefresh = connect.findViewById(R.id.timeline);
SwipeRefreshLayout trendRefresh = connect.findViewById(R.id.trends); SwipeRefreshLayout trendRefresh = connect.findViewById(R.id.trends);
SwipeRefreshLayout mentionRefresh = connect.findViewById(R.id.mention); SwipeRefreshLayout mentionRefresh = connect.findViewById(R.id.mention);
RecyclerView timelineList = ui.get().findViewById(R.id.tl_list);
RecyclerView mentionList = ui.get().findViewById(R.id.m_list);
RecyclerView trendList = ui.get().findViewById(R.id.tr_list);
switch(MODE) { switch(MODE) {
case HOME: case HOME:
@ -171,11 +175,11 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
break; break;
case FAIL: case FAIL:
Toast.makeText(connect, "Fehler: "+errMsg, Toast.LENGTH_LONG).show();
default: default:
timelineRefresh.setRefreshing(false); timelineRefresh.setRefreshing(false);
trendRefresh.setRefreshing(false); trendRefresh.setRefreshing(false);
mentionRefresh.setRefreshing(false); mentionRefresh.setRefreshing(false);
Toast.makeText(connect, "Fehler: "+errMsg, Toast.LENGTH_LONG).show();
} }
} }
} }

View File

@ -41,15 +41,14 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
private static final long IGNORE = 0x9; private static final long IGNORE = 0x9;
private String screenName, username, description, location, follower, following; private String screenName, username, description, location, follower, following;
private RecyclerView profileTweets, profileFavorits;
private String /* bannerLink,*/ profileImage, link, dateString; private String /* bannerLink,*/ profileImage, link, dateString;
private TimelineRecycler homeTl, homeFav; private TimelineRecycler homeTl, homeFav;
private WeakReference<UserProfile> ui; private WeakReference<UserProfile> ui;
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private String errMsg = ""; private String errMsg = "";
private int font, highlight; private int font, highlight;
private boolean imgEnabled;
private boolean isHome = false; private boolean isHome = false;
private boolean imgEnabled = false;
private boolean isFollowing = false; private boolean isFollowing = false;
private boolean isFollowed = false; private boolean isFollowed = false;
private boolean isVerified = false; private boolean isVerified = false;
@ -62,13 +61,16 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
*/ */
public ProfileLoader(Context context) { public ProfileLoader(Context context) {
ui = new WeakReference<>((UserProfile)context); ui = new WeakReference<>((UserProfile)context);
profileTweets = ui.get().findViewById(R.id.ht_list);
profileFavorits = ui.get().findViewById(R.id.hf_list);
mTwitter = TwitterEngine.getInstance(context); mTwitter = TwitterEngine.getInstance(context);
SharedPreferences settings = context.getSharedPreferences("settings", 0); SharedPreferences settings = context.getSharedPreferences("settings", 0);
font = settings.getInt("font_color", 0xffffffff); font = settings.getInt("font_color", 0xffffffff);
highlight = settings.getInt("highlight_color", 0xffff00ff); highlight = settings.getInt("highlight_color", 0xffff00ff);
imgEnabled = settings.getBoolean("image_load",true); imgEnabled = settings.getBoolean("image_load",true);
RecyclerView profileTweets = ui.get().findViewById(R.id.ht_list);
RecyclerView profileFavorits = ui.get().findViewById(R.id.hf_list);
homeTl = (TimelineRecycler) profileTweets.getAdapter();
homeFav = (TimelineRecycler) profileFavorits.getAdapter();
} }
@ -116,7 +118,7 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
{ {
DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get()); DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get());
List<Tweet> tweets; List<Tweet> tweets;
homeTl = (TimelineRecycler) profileTweets.getAdapter();
if(homeTl != null && homeTl.getItemCount() > 0) { if(homeTl != null && homeTl.getItemCount() > 0) {
id = homeTl.getItemId(0); id = homeTl.getItemId(0);
tweets = mTwitter.getUserTweets(userId,args[2],id); tweets = mTwitter.getUserTweets(userId,args[2],id);
@ -137,7 +139,6 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
{ {
DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get()); DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get());
List<Tweet> favorits; List<Tweet> favorits;
homeFav = (TimelineRecycler) profileFavorits.getAdapter();
if(homeFav != null && homeFav.getItemCount() > 0) { if(homeFav != null && homeFav.getItemCount() > 0) {
id = homeFav.getItemId(0); id = homeFav.getItemId(0);
favorits = mTwitter.getUserFavs(userId,args[2],id); favorits = mTwitter.getUserFavs(userId,args[2],id);
@ -244,12 +245,14 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
} }
else if(mode == GET_TWEETS) else if(mode == GET_TWEETS)
{ {
RecyclerView profileTweets = ui.get().findViewById(R.id.ht_list);
profileTweets.setAdapter(homeTl); profileTweets.setAdapter(homeTl);
SwipeRefreshLayout tweetsReload = connect.findViewById(R.id.hometweets); SwipeRefreshLayout tweetsReload = connect.findViewById(R.id.hometweets);
tweetsReload.setRefreshing(false); tweetsReload.setRefreshing(false);
} }
else if(mode == GET_FAVS) else if(mode == GET_FAVS)
{ {
RecyclerView profileFavorits = ui.get().findViewById(R.id.hf_list);
profileFavorits.setAdapter(homeFav); profileFavorits.setAdapter(homeFav);
SwipeRefreshLayout favoritsReload = connect.findViewById(R.id.homefavorits); SwipeRefreshLayout favoritsReload = connect.findViewById(R.id.homefavorits);
favoritsReload.setRefreshing(false); favoritsReload.setRefreshing(false);

View File

@ -33,7 +33,7 @@ public class Registration extends AsyncTask<String, Void, Boolean> {
String pin = twitterPin[0]; String pin = twitterPin[0];
try { try {
if( pin.trim().isEmpty() ) { if( pin.trim().isEmpty() ) {
mTwitter.request(); mTwitter.request(ui.get());
} else { } else {
mTwitter.initialize(pin); mTwitter.initialize(pin);
return true; return true;

View File

@ -51,7 +51,6 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private TimelineRecycler tlAdp; private TimelineRecycler tlAdp;
private RecyclerView replyList;
private String usernameStr, scrNameStr, tweetStr, dateString; private String usernameStr, scrNameStr, tweetStr, dateString;
private String repliedUsername, apiName, retweeter; private String repliedUsername, apiName, retweeter;
private String medialinks[], profile_pb; private String medialinks[], profile_pb;
@ -71,7 +70,8 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
highlight = settings.getInt("highlight_color", 0xffff00ff); highlight = settings.getInt("highlight_color", 0xffff00ff);
toggleImg = settings.getBoolean("image_load",true); toggleImg = settings.getBoolean("image_load",true);
ui = new WeakReference<>((TweetDetail)c); ui = new WeakReference<>((TweetDetail)c);
replyList = ui.get().findViewById(R.id.answer_list); RecyclerView replyList = ui.get().findViewById(R.id.answer_list);
tlAdp = (TimelineRecycler) replyList.getAdapter();
} }
@ -90,7 +90,6 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
if(tweet == null) if(tweet == null)
return IGNORE; return IGNORE;
tlAdp = (TimelineRecycler) replyList.getAdapter();
List<Tweet> answers = dbAdp.load(DatabaseAdapter.ANS, tweetID); List<Tweet> answers = dbAdp.load(DatabaseAdapter.ANS, tweetID);
tlAdp = new TimelineRecycler(answers,ui.get()); tlAdp = new TimelineRecycler(answers,ui.get());
tlAdp.setColor(highlight, font); tlAdp.setColor(highlight, font);
@ -154,7 +153,6 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
List<Tweet> answers; List<Tweet> answers;
DatabaseAdapter twdb = new DatabaseAdapter(ui.get()); DatabaseAdapter twdb = new DatabaseAdapter(ui.get());
String replyname = tweet.user.screenname; String replyname = tweet.user.screenname;
tlAdp = (TimelineRecycler) replyList.getAdapter();
if(tlAdp != null && tlAdp.getItemCount() > 0) { if(tlAdp != null && tlAdp.getItemCount() > 0) {
long sinceId = tlAdp.getItemId(0); long sinceId = tlAdp.getItemId(0);
answers = mTwitter.getAnswers(replyname, tweetID, sinceId); answers = mTwitter.getAnswers(replyname, tweetID, sinceId);
@ -217,7 +215,6 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
txtRet.setText(rtStr); txtRet.setText(rtStr);
if(tlAdp != null) { if(tlAdp != null) {
replyList.setAdapter(tlAdp);
String ansStr = Integer.toString(tlAdp.getItemCount()); String ansStr = Integer.toString(tlAdp.getItemCount());
TextView txtAns = connect.findViewById(R.id.no_ans_detail); TextView txtAns = connect.findViewById(R.id.no_ans_detail);
txtAns.setText(ansStr); txtAns.setText(ansStr);
@ -273,7 +270,6 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
setIcons(favoriteButton, retweetButton); setIcons(favoriteButton, retweetButton);
} }
else if(mode == LOAD_REPLY) { else if(mode == LOAD_REPLY) {
replyList.setAdapter(tlAdp);
SwipeRefreshLayout ansReload = connect.findViewById(R.id.answer_reload); SwipeRefreshLayout ansReload = connect.findViewById(R.id.answer_reload);
ansReload.setRefreshing(false); ansReload.setRefreshing(false);
String ansStr = Integer.toString(tlAdp.getItemCount()); String ansStr = Integer.toString(tlAdp.getItemCount());

View File

@ -18,8 +18,6 @@ public class StatusUpload extends AsyncTask<Object, Void, Boolean> implements Al
private WeakReference<TweetPopup> ui; private WeakReference<TweetPopup> ui;
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private View load;
private EditText tweet;
private String[] path; private String[] path;
/** /**
@ -29,13 +27,14 @@ public class StatusUpload extends AsyncTask<Object, Void, Boolean> implements Al
public StatusUpload(Context context, String[] path) { public StatusUpload(Context context, String[] path) {
ui = new WeakReference<>((TweetPopup)context); ui = new WeakReference<>((TweetPopup)context);
mTwitter = TwitterEngine.getInstance(context); mTwitter = TwitterEngine.getInstance(context);
load = ui.get().findViewById(R.id.tweet_sending);
tweet = (EditText) ui.get().findViewById(R.id.tweet_input);
this.path = path; this.path = path;
} }
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
EditText tweet = ui.get().findViewById(R.id.tweet_input);
View load = ui.get().findViewById(R.id.tweet_sending);
load.setVisibility(View.VISIBLE); load.setVisibility(View.VISIBLE);
tweet.setFocusable(false); tweet.setFocusable(false);
} }
@ -80,6 +79,7 @@ public class StatusUpload extends AsyncTask<Object, Void, Boolean> implements Al
builder.setTitle("Fehler").setMessage("Tweet wurde nicht gesendet!") builder.setTitle("Fehler").setMessage("Tweet wurde nicht gesendet!")
.setPositiveButton(R.string.retry, this) .setPositiveButton(R.string.retry, this)
.setNegativeButton(R.string.cancel, this).show(); .setNegativeButton(R.string.cancel, this).show();
View load = ui.get().findViewById(R.id.tweet_sending);
load.setVisibility(View.INVISIBLE); load.setVisibility(View.INVISIBLE);
} }
} }

View File

@ -38,12 +38,11 @@ import twitter4j.conf.ConfigurationBuilder;
public class TwitterEngine { public class TwitterEngine {
private final String TWITTER_CONSUMER_KEY = "0EKRHWYcakpCkl8Lr4OcBFMZb"; private final String TWITTER_CONSUMER_KEY = "0EKRHWYcakpCkl8Lr4OcBFMZb";
private final String TWITTER_CONSUMER_SECRET = "RQrf0uQus5v7IMuYgdlVeBuLw1ApRJhxcAMM8MyUVRh1nKSxnE"; private final String TWITTER_CONSUMER_SECRET = "insert your own key";
private static TwitterEngine mTwitter; private static TwitterEngine mTwitter;
private static long twitterID = -1L; private static long twitterID = -1L;
private Twitter twitter; private Twitter twitter;
private Context context;
private SharedPreferences settings; private SharedPreferences settings;
private RequestToken reqToken; private RequestToken reqToken;
private boolean login; private boolean login;
@ -64,7 +63,6 @@ public class TwitterEngine {
Configuration configuration = builder.build(); Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration); TwitterFactory factory = new TwitterFactory(configuration);
twitter = factory.getInstance(); twitter = factory.getInstance();
this.context = context;
} }
@ -72,7 +70,7 @@ public class TwitterEngine {
* get RequestToken and Open Twitter Registration Website * get RequestToken and Open Twitter Registration Website
* @throws TwitterException if Connection is unavailable * @throws TwitterException if Connection is unavailable
*/ */
public void request() throws TwitterException { public void request(Context context) throws TwitterException {
if(reqToken == null) if(reqToken == null)
reqToken = twitter.getOAuthRequestToken(); reqToken = twitter.getOAuthRequestToken();
String redirectURL = reqToken.getAuthenticationURL(); String redirectURL = reqToken.getAuthenticationURL();
@ -147,6 +145,13 @@ public class TwitterEngine {
twitterID = settings.getLong("userID", -1L); twitterID = settings.getLong("userID", -1L);
} }
/**
* set amount of tweets to be loaded
*/
private void setLoad() {
load = settings.getInt("preload", 10);
}
/** /**
* @return if Twitter4J is registered * @return if Twitter4J is registered
*/ */
@ -588,7 +593,7 @@ public class TwitterEngine {
mTwitter = new TwitterEngine(context); mTwitter = new TwitterEngine(context);
mTwitter.init(); mTwitter.init();
} }
mTwitter.load = mTwitter.settings.getInt("preload", 10); mTwitter.setLoad();
return mTwitter; return mTwitter;
} }
} }

View File

@ -23,7 +23,6 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
private TimelineRecycler tlRc; private TimelineRecycler tlRc;
private UserRecycler uAdp; private UserRecycler uAdp;
private RecyclerView tweetSearch, userSearch;
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private WeakReference<SearchPage> ui; private WeakReference<SearchPage> ui;
private int highlight, font_color; private int highlight, font_color;
@ -32,14 +31,17 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
public TwitterSearch(Context context) { public TwitterSearch(Context context) {
ui = new WeakReference<>((SearchPage)context); ui = new WeakReference<>((SearchPage)context);
tweetSearch = ui.get().findViewById(R.id.tweet_result);
userSearch = ui.get().findViewById(R.id.user_result);
mTwitter = TwitterEngine.getInstance(context); mTwitter = TwitterEngine.getInstance(context);
SharedPreferences settings = context.getSharedPreferences("settings", 0); SharedPreferences settings = context.getSharedPreferences("settings", 0);
font_color = settings.getInt("font_color", 0xffffffff); font_color = settings.getInt("font_color", 0xffffffff);
highlight = settings.getInt("highlight_color", 0xffff00ff); highlight = settings.getInt("highlight_color", 0xffff00ff);
imageload = settings.getBoolean("image_load",true); imageload = settings.getBoolean("image_load",true);
RecyclerView tweetSearch = ui.get().findViewById(R.id.tweet_result);
RecyclerView userSearch = ui.get().findViewById(R.id.user_result);
tlRc = (TimelineRecycler) tweetSearch.getAdapter();
uAdp = (UserRecycler) userSearch.getAdapter();
} }
@ -48,9 +50,6 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
String strSearch = search[0]; String strSearch = search[0];
long id = 1L; long id = 1L;
try { try {
tlRc = (TimelineRecycler) tweetSearch.getAdapter();
uAdp = (UserRecycler) userSearch.getAdapter();
if(tlRc != null && tlRc.getItemCount() > 0) { if(tlRc != null && tlRc.getItemCount() > 0) {
id = tlRc.getItemId(0); id = tlRc.getItemId(0);
List<Tweet> tweets = mTwitter.searchTweets(strSearch,id); List<Tweet> tweets = mTwitter.searchTweets(strSearch,id);
@ -89,6 +88,8 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
SwipeRefreshLayout tweetReload = connect.findViewById(R.id.searchtweets); SwipeRefreshLayout tweetReload = connect.findViewById(R.id.searchtweets);
View circleLoad = connect.findViewById(R.id.search_progress); View circleLoad = connect.findViewById(R.id.search_progress);
circleLoad.setVisibility(View.INVISIBLE); circleLoad.setVisibility(View.INVISIBLE);
RecyclerView tweetSearch = ui.get().findViewById(R.id.tweet_result);
RecyclerView userSearch = ui.get().findViewById(R.id.user_result);
tweetSearch.setAdapter(tlRc); tweetSearch.setAdapter(tlRc);
userSearch.setAdapter(uAdp); userSearch.setAdapter(uAdp);
tweetReload.setRefreshing(false); tweetReload.setRefreshing(false);

View File

@ -27,7 +27,6 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
private WeakReference<UserDetail> ui; private WeakReference<UserDetail> ui;
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private UserRecycler usrAdp; private UserRecycler usrAdp;
private RecyclerView userList;
private String errmsg; private String errmsg;
private boolean imageload; private boolean imageload;
@ -38,7 +37,8 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
public UserLists(Context context) { public UserLists(Context context) {
ui = new WeakReference<>((UserDetail)context); ui = new WeakReference<>((UserDetail)context);
mTwitter = TwitterEngine.getInstance(context); mTwitter = TwitterEngine.getInstance(context);
userList = ui.get().findViewById(R.id.userlist); RecyclerView userList = ui.get().findViewById(R.id.userlist);
usrAdp = (UserRecycler) userList.getAdapter();
SharedPreferences settings = context.getSharedPreferences("settings", 0); SharedPreferences settings = context.getSharedPreferences("settings", 0);
imageload = settings.getBoolean("image_load",true); imageload = settings.getBoolean("image_load",true);
@ -51,7 +51,7 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
long mode = data[1]; long mode = data[1];
long cursor = data[2]; long cursor = data[2];
try { try {
usrAdp = (UserRecycler) userList.getAdapter();
if(mode == FOLLOWING) { if(mode == FOLLOWING) {
List<TwitterUser> user = mTwitter.getFollowing(id,cursor); List<TwitterUser> user = mTwitter.getFollowing(id,cursor);
usrAdp = new UserRecycler(user,ui.get()); usrAdp = new UserRecycler(user,ui.get());
@ -84,6 +84,7 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
mProgress.setVisibility(View.INVISIBLE); mProgress.setVisibility(View.INVISIBLE);
if(errmsg == null) { if(errmsg == null) {
RecyclerView userList = ui.get().findViewById(R.id.userlist);
userList.setAdapter(usrAdp); userList.setAdapter(usrAdp);
} }
else { else {

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/preview_root"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center">