mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-16 03:20:37 +01:00
code cleanup
This commit is contained in:
parent
27f3c5e736
commit
4b4145d056
@ -236,6 +236,7 @@ public class ProfileLoader extends AsyncTask<Long, Void, Void> {
|
||||
View location_ico = ui.get().findViewById(R.id.loction_ico);
|
||||
View link_ico = ui.get().findViewById(R.id.links_ico);
|
||||
View followback = ui.get().findViewById(R.id.followback);
|
||||
View verified = ui.get().findViewById(R.id.profile_verify);
|
||||
View locked = ui.get().findViewById(R.id.profile_locked);
|
||||
|
||||
if (mode == Mode.LDR_PROFILE) {
|
||||
@ -251,9 +252,43 @@ public class ProfileLoader extends AsyncTask<Long, Void, Void> {
|
||||
following_ico.setVisibility(View.VISIBLE);
|
||||
date_ico.setVisibility(View.VISIBLE);
|
||||
if (user.isVerified())
|
||||
ui.get().findViewById(R.id.profile_verify).setVisibility(View.VISIBLE);
|
||||
verified.setVisibility(View.VISIBLE);
|
||||
if (isFollowed)
|
||||
followback.setVisibility(View.VISIBLE);
|
||||
if (user.isLocked()) {
|
||||
locked.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
if(!txtFollowing.isClickable()) {
|
||||
txtFollowing.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent following = new Intent(ui.get(), UserDetail.class);
|
||||
following.putExtra("userID", user.getId());
|
||||
following.putExtra("mode", 0);
|
||||
ui.get().startActivity(following);
|
||||
}
|
||||
});
|
||||
}
|
||||
if(!txtFollower.isClickable()) {
|
||||
txtFollower.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent follower = new Intent(ui.get(), UserDetail.class);
|
||||
follower.putExtra("userID", user.getId());
|
||||
follower.putExtra("mode", 1);
|
||||
ui.get().startActivity(follower);
|
||||
}
|
||||
});
|
||||
}
|
||||
if(!profile.isClickable()) {
|
||||
profile.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ui.get().imageClick(user.getImageLink());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Spanned bio = Tagger.makeText(user.getBio(), highlight, ui.get());
|
||||
txtBio.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
@ -281,34 +316,7 @@ public class ProfileLoader extends AsyncTask<Long, Void, Void> {
|
||||
String link = user.getImageLink() + "_bigger";
|
||||
Picasso.get().load(link).into(profile);
|
||||
}
|
||||
if (user.isLocked()) {
|
||||
locked.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
txtFollowing.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent following = new Intent(ui.get(), UserDetail.class);
|
||||
following.putExtra("userID", user.getId());
|
||||
following.putExtra("mode", 0);
|
||||
ui.get().startActivity(following);
|
||||
}
|
||||
});
|
||||
txtFollower.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent follower = new Intent(ui.get(), UserDetail.class);
|
||||
follower.putExtra("userID", user.getId());
|
||||
follower.putExtra("mode", 1);
|
||||
ui.get().startActivity(follower);
|
||||
}
|
||||
});
|
||||
}
|
||||
profile.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ui.get().imageClick(user.getImageLink());
|
||||
}
|
||||
});
|
||||
|
||||
ui.get().setTweetCount(user.getTweetCount(), user.getFavorCount());
|
||||
|
||||
if (!tweets.isEmpty()) {
|
||||
|
@ -88,9 +88,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Void> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data [0] TWEET ID
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Long... data) {
|
||||
final long TWEETID = data[0];
|
||||
@ -143,7 +141,6 @@ public class StatusLoader extends AsyncTask<Long, Void, Void> {
|
||||
database.removeFavorite(TWEETID);
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (TwitterException err) {
|
||||
this.err = err;
|
||||
int rCode = err.getErrorCode();
|
||||
@ -164,8 +161,8 @@ public class StatusLoader extends AsyncTask<Long, Void, Void> {
|
||||
|
||||
if(mode == Mode.LOAD) {
|
||||
TextView tweetText = ui.get().findViewById(R.id.tweet_detailed);
|
||||
TextView date = ui.get().findViewById(R.id.timedetail);
|
||||
TextView used_api = ui.get().findViewById(R.id.used_api);
|
||||
TextView tweetDate = ui.get().findViewById(R.id.timedetail);
|
||||
TextView tweet_api = ui.get().findViewById(R.id.used_api);
|
||||
View tweet_verify = ui.get().findViewById(R.id.tweet_verify);
|
||||
View tweet_locked = ui.get().findViewById(R.id.tweet_locked);
|
||||
|
||||
@ -173,11 +170,11 @@ public class StatusLoader extends AsyncTask<Long, Void, Void> {
|
||||
tweetText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
tweetText.setText(sTweet);
|
||||
tweetText.setTextColor(font_color);
|
||||
date.setText(sdf.format(tweet.getTime()));
|
||||
date.setTextColor(font_color);
|
||||
used_api.setText(R.string.sent_from);
|
||||
used_api.append(tweet.getSource());
|
||||
used_api.setTextColor(font_color);
|
||||
tweetDate.setText(sdf.format(tweet.getTime()));
|
||||
tweetDate.setTextColor(font_color);
|
||||
tweet_api.setText(R.string.sent_from);
|
||||
tweet_api.append(tweet.getSource());
|
||||
tweet_api.setTextColor(font_color);
|
||||
|
||||
if (tweet.getUser().isVerified()) {
|
||||
tweet_verify.setVisibility(View.VISIBLE);
|
||||
@ -185,7 +182,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Void> {
|
||||
if (tweet.getUser().isLocked()) {
|
||||
tweet_locked.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (tweet.getMediaLinks() != null && tweet.getMediaLinks().length != 0) {
|
||||
if (tweet.getMediaLinks() != null && tweet.getMediaLinks().length > 0) {
|
||||
View mediaButton = ui.get().findViewById(R.id.image_attach);
|
||||
mediaButton.setVisibility(View.VISIBLE);
|
||||
if(!mediaButton.isClickable()) {
|
||||
|
@ -182,9 +182,9 @@ public class DatabaseAdapter {
|
||||
*/
|
||||
@Nullable
|
||||
public TwitterUser getUser(long userId) {
|
||||
SQLiteDatabase db = dataHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = getDbRead();
|
||||
TwitterUser result = getUser(userId, db);
|
||||
db.close();
|
||||
close(db);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ public class DatabaseAdapter {
|
||||
* @return tweet list
|
||||
*/
|
||||
public List<Tweet> getHomeTimeline() {
|
||||
SQLiteDatabase db = dataHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = getDbRead();
|
||||
List<Tweet> tweetList = new ArrayList<>();
|
||||
String SQL_GET_HOME = "SELECT * FROM tweet " +
|
||||
"INNER JOIN user ON tweet.userID=user.userID " +
|
||||
@ -208,6 +208,7 @@ public class DatabaseAdapter {
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
close(db);
|
||||
return tweetList;
|
||||
}
|
||||
|
||||
@ -217,7 +218,7 @@ public class DatabaseAdapter {
|
||||
* @return tweet list
|
||||
*/
|
||||
public List<Tweet> getMentions() {
|
||||
SQLiteDatabase db = dataHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = getDbRead();
|
||||
List<Tweet> tweetList = new ArrayList<>();
|
||||
String SQL_GET_HOME = "SELECT * FROM tweet " +
|
||||
"INNER JOIN user ON tweet.userID=user.userID " +
|
||||
@ -231,6 +232,7 @@ public class DatabaseAdapter {
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
close(db);
|
||||
return tweetList;
|
||||
}
|
||||
|
||||
@ -241,7 +243,7 @@ public class DatabaseAdapter {
|
||||
* @return Tweet list of user tweets
|
||||
*/
|
||||
public List<Tweet> getUserTweets(long userID) {
|
||||
SQLiteDatabase db = dataHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = getDbRead();
|
||||
List<Tweet> tweetList = new ArrayList<>();
|
||||
String SQL_GET_HOME = "SELECT * FROM tweet " +
|
||||
"INNER JOIN user ON tweet.userID = user.userID " +
|
||||
@ -258,6 +260,7 @@ public class DatabaseAdapter {
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
close(db);
|
||||
return tweetList;
|
||||
}
|
||||
|
||||
@ -268,7 +271,7 @@ public class DatabaseAdapter {
|
||||
* @return favored tweets by user
|
||||
*/
|
||||
public List<Tweet> getUserFavs(long ownerID) {
|
||||
SQLiteDatabase db = dataHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = getDbRead();
|
||||
List<Tweet> tweetList = new ArrayList<>();
|
||||
String SQL_GET_HOME = "SELECT * FROM tweet " +
|
||||
"INNER JOIN favorit on tweet.tweetID = favorit.tweetID " +
|
||||
@ -283,6 +286,7 @@ public class DatabaseAdapter {
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
close(db);
|
||||
return tweetList;
|
||||
}
|
||||
|
||||
@ -294,7 +298,7 @@ public class DatabaseAdapter {
|
||||
*/
|
||||
@Nullable
|
||||
public Tweet getStatus(long tweetId) {
|
||||
SQLiteDatabase db = dataHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = getDbRead();
|
||||
Tweet result = null;
|
||||
String query = "SELECT * FROM tweet " +
|
||||
"INNER JOIN user ON user.userID = tweet.userID " +
|
||||
@ -303,6 +307,7 @@ public class DatabaseAdapter {
|
||||
if (cursor.moveToFirst())
|
||||
result = getStatus(cursor);
|
||||
cursor.close();
|
||||
close(db);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -313,7 +318,7 @@ public class DatabaseAdapter {
|
||||
* @return list of tweet answers
|
||||
*/
|
||||
public List<Tweet> getAnswers(long tweetId) {
|
||||
SQLiteDatabase db = dataHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = getDbRead();
|
||||
List<Tweet> tweetList = new ArrayList<>();
|
||||
String SQL_GET_HOME = "SELECT * FROM tweet " +
|
||||
"INNER JOIN user ON tweet.userID = user.userID " +
|
||||
@ -327,6 +332,7 @@ public class DatabaseAdapter {
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
close(db);
|
||||
return tweetList;
|
||||
}
|
||||
|
||||
@ -430,7 +436,7 @@ public class DatabaseAdapter {
|
||||
* @return list of trends
|
||||
*/
|
||||
public List<Trend> getTrends(int woeId) {
|
||||
SQLiteDatabase db = dataHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = getDbRead();
|
||||
List<Trend> trends = new ArrayList<>();
|
||||
String query = "SELECT * FROM trend WHERE woeID=" + woeId + " ORDER BY trendpos ASC";
|
||||
Cursor cursor = db.rawQuery(query, null);
|
||||
@ -444,7 +450,7 @@ public class DatabaseAdapter {
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
close(db);
|
||||
return trends;
|
||||
}
|
||||
|
||||
@ -455,7 +461,7 @@ public class DatabaseAdapter {
|
||||
*/
|
||||
public List<Message> getMessages() {
|
||||
List<Message> result = new ArrayList<>();
|
||||
SQLiteDatabase db = dataHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = getDbRead();
|
||||
String query = "SELECT * FROM message ORDER BY messageID DESC LIMIT " + LIMIT;
|
||||
Cursor cursor = db.rawQuery(query, null);
|
||||
if (cursor.moveToFirst()) {
|
||||
@ -479,7 +485,7 @@ public class DatabaseAdapter {
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
close(db);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -490,12 +496,12 @@ public class DatabaseAdapter {
|
||||
* @return true if found
|
||||
*/
|
||||
public boolean containStatus(long id) {
|
||||
SQLiteDatabase db = dataHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = getDbRead();
|
||||
String query = "SELECT tweetID FROM tweet WHERE tweetID=" + id + " LIMIT 1;";
|
||||
Cursor c = db.rawQuery(query, null);
|
||||
boolean result = c.moveToFirst();
|
||||
c.close();
|
||||
db.close();
|
||||
close(db);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -702,6 +708,16 @@ public class DatabaseAdapter {
|
||||
}
|
||||
|
||||
|
||||
private synchronized SQLiteDatabase getDbRead() {
|
||||
return dataHelper.getReadableDatabase();
|
||||
}
|
||||
|
||||
|
||||
private synchronized void close(SQLiteDatabase db) {
|
||||
db.close();
|
||||
}
|
||||
|
||||
|
||||
private synchronized SQLiteDatabase getDbWrite() {
|
||||
SQLiteDatabase db = dataHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
|
Loading…
Reference in New Issue
Block a user