mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-25 13:58:36 +01:00
changed method names, added comments, added tweet media warning
This commit is contained in:
parent
d1fc26ec0b
commit
d95ef4ab38
4
.idea/assetWizardSettings.xml
generated
4
.idea/assetWizardSettings.xml
generated
@ -20,8 +20,8 @@
|
||||
<map>
|
||||
<entry key="assetSourceType" value="FILE" />
|
||||
<entry key="autoMirrored" value="true" />
|
||||
<entry key="outputName" value="no_banner" />
|
||||
<entry key="sourceFile" value="$USER_HOME$/Dokumente/Unbenannt 2.svg" />
|
||||
<entry key="outputName" value="sensitive_content" />
|
||||
<entry key="sourceFile" value="$USER_HOME$/Dokumente/Rest/Entypo SVG/eye-with-line.svg" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
|
@ -35,7 +35,7 @@ android {
|
||||
dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
|
||||
implementation 'com.google.android.material:material:1.2.0'
|
||||
implementation 'com.google.android.material:material:1.2.1'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
|
@ -38,7 +38,7 @@ import org.nuclearfog.twidda.backend.engine.EngineException;
|
||||
import org.nuclearfog.twidda.backend.helper.ErrorHandler;
|
||||
import org.nuclearfog.twidda.backend.helper.FontTool;
|
||||
import org.nuclearfog.twidda.backend.items.TwitterUser;
|
||||
import org.nuclearfog.twidda.backend.items.UserConnection;
|
||||
import org.nuclearfog.twidda.backend.items.UserRelation;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
@ -89,7 +89,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
private TabLayout tabLayout;
|
||||
|
||||
private ProfileLoader profileAsync;
|
||||
private UserConnection properties;
|
||||
private UserRelation relation;
|
||||
private TwitterUser user;
|
||||
|
||||
@Override
|
||||
@ -233,27 +233,27 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
listItem.setVisible(false);
|
||||
}
|
||||
}
|
||||
if (properties != null) {
|
||||
if (properties.isFriend()) {
|
||||
if (relation != null) {
|
||||
if (relation.isFriend()) {
|
||||
MenuItem followIcon = m.findItem(R.id.profile_follow);
|
||||
MenuItem listItem = m.findItem(R.id.profile_lists);
|
||||
followIcon.setIcon(R.drawable.follow_enabled);
|
||||
followIcon.setTitle(R.string.user_unfollow);
|
||||
listItem.setVisible(true);
|
||||
}
|
||||
if (properties.isBlocked()) {
|
||||
if (relation.isBlocked()) {
|
||||
MenuItem blockIcon = m.findItem(R.id.profile_block);
|
||||
blockIcon.setTitle(R.string.user_unblock);
|
||||
}
|
||||
if (properties.isMuted()) {
|
||||
if (relation.isMuted()) {
|
||||
MenuItem muteIcon = m.findItem(R.id.profile_mute);
|
||||
muteIcon.setTitle(R.string.user_unmute);
|
||||
}
|
||||
if (properties.canDm()) {
|
||||
if (relation.canDm()) {
|
||||
MenuItem dmIcon = m.findItem(R.id.profile_message);
|
||||
dmIcon.setVisible(true);
|
||||
}
|
||||
if (properties.isFollower()) {
|
||||
if (relation.isFollower()) {
|
||||
follow_back.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
@ -265,7 +265,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (profileAsync != null && user != null && profileAsync.getStatus() != RUNNING) {
|
||||
if (user != null && properties != null) {
|
||||
if (user != null && relation != null) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.profile_tweet:
|
||||
String tweetPrefix = user.getScreenname() + " ";
|
||||
@ -282,7 +282,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
|
||||
case R.id.profile_follow:
|
||||
profileAsync = new ProfileLoader(this, ProfileLoader.Action.ACTION_FOLLOW);
|
||||
if (!properties.isFriend()) {
|
||||
if (!relation.isFriend()) {
|
||||
profileAsync.execute(user.getId());
|
||||
} else {
|
||||
new Builder(this).setMessage(R.string.confirm_unfollow)
|
||||
@ -298,7 +298,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
|
||||
case R.id.profile_mute:
|
||||
profileAsync = new ProfileLoader(this, ProfileLoader.Action.ACTION_MUTE);
|
||||
if (properties.isMuted()) {
|
||||
if (relation.isMuted()) {
|
||||
profileAsync.execute(user.getId());
|
||||
} else {
|
||||
new Builder(this).setMessage(R.string.confirm_mute)
|
||||
@ -314,7 +314,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
|
||||
case R.id.profile_block:
|
||||
profileAsync = new ProfileLoader(this, ProfileLoader.Action.ACTION_BLOCK);
|
||||
if (properties.isBlocked()) {
|
||||
if (relation.isBlocked()) {
|
||||
profileAsync.execute(user.getId());
|
||||
} else {
|
||||
new Builder(this).setMessage(R.string.confirm_block)
|
||||
@ -330,11 +330,11 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
|
||||
case R.id.profile_message:
|
||||
Intent dmPage;
|
||||
if (properties.isHome()) {
|
||||
if (relation.isHome()) {
|
||||
dmPage = new Intent(this, DirectMessage.class);
|
||||
} else {
|
||||
dmPage = new Intent(this, MessagePopup.class);
|
||||
dmPage.putExtra(KEY_DM_PREFIX, properties.getTargetScreenname());
|
||||
dmPage.putExtra(KEY_DM_PREFIX, relation.getTargetScreenname());
|
||||
}
|
||||
startActivity(dmPage);
|
||||
break;
|
||||
@ -397,10 +397,10 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (user != null && properties != null) {
|
||||
if (user != null && relation != null) {
|
||||
switch (v.getId()) {
|
||||
case R.id.following:
|
||||
if (!user.isLocked() || properties.isFriend() || user.getId() == settings.getUserId()) {
|
||||
if (!(user.isLocked() || relation.isBlocked()) || relation.isFriend() || user.getId() == settings.getUserId()) {
|
||||
Intent following = new Intent(this, UserDetail.class);
|
||||
following.putExtra(KEY_USERDETAIL_ID, user.getId());
|
||||
following.putExtra(KEY_USERDETAIL_MODE, USERLIST_FRIENDS);
|
||||
@ -409,7 +409,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
break;
|
||||
|
||||
case R.id.follower:
|
||||
if (!user.isLocked() || properties.isFriend() || user.getId() == settings.getUserId()) {
|
||||
if (!(user.isLocked() || relation.isBlocked()) || relation.isFriend() || user.getId() == settings.getUserId()) {
|
||||
Intent follower = new Intent(this, UserDetail.class);
|
||||
follower.putExtra(KEY_USERDETAIL_ID, user.getId());
|
||||
follower.putExtra(KEY_USERDETAIL_MODE, USERLIST_FOLLOWER);
|
||||
@ -534,8 +534,8 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
*
|
||||
* @param properties relationship to the current user
|
||||
*/
|
||||
public void setConnection(UserConnection properties) {
|
||||
this.properties = properties;
|
||||
public void setConnection(UserRelation properties) {
|
||||
this.relation = properties;
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@ -545,7 +545,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||
* @param properties connection to an user
|
||||
* @param action Action on the user profile
|
||||
*/
|
||||
public void onAction(UserConnection properties, ProfileLoader.Action action) {
|
||||
public void onAction(UserRelation properties, ProfileLoader.Action action) {
|
||||
switch (action) {
|
||||
case ACTION_FOLLOW:
|
||||
if (properties.isFriend())
|
||||
|
@ -8,7 +8,7 @@ import org.nuclearfog.twidda.activity.UserProfile;
|
||||
import org.nuclearfog.twidda.backend.engine.EngineException;
|
||||
import org.nuclearfog.twidda.backend.engine.TwitterEngine;
|
||||
import org.nuclearfog.twidda.backend.items.TwitterUser;
|
||||
import org.nuclearfog.twidda.backend.items.UserConnection;
|
||||
import org.nuclearfog.twidda.backend.items.UserRelation;
|
||||
import org.nuclearfog.twidda.database.AppDatabase;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
@ -18,7 +18,7 @@ import java.lang.ref.WeakReference;
|
||||
*
|
||||
* @see UserProfile
|
||||
*/
|
||||
public class ProfileLoader extends AsyncTask<Object, TwitterUser, UserConnection> {
|
||||
public class ProfileLoader extends AsyncTask<Object, TwitterUser, UserRelation> {
|
||||
|
||||
public enum Action {
|
||||
LDR_PROFILE,
|
||||
@ -44,8 +44,8 @@ public class ProfileLoader extends AsyncTask<Object, TwitterUser, UserConnection
|
||||
|
||||
|
||||
@Override
|
||||
protected UserConnection doInBackground(Object[] args) {
|
||||
UserConnection connection;
|
||||
protected UserRelation doInBackground(Object[] args) {
|
||||
UserRelation connection;
|
||||
TwitterUser user;
|
||||
long userId = 0;
|
||||
String username = "";
|
||||
@ -136,7 +136,7 @@ public class ProfileLoader extends AsyncTask<Object, TwitterUser, UserConnection
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(UserConnection properties) {
|
||||
protected void onPostExecute(UserRelation properties) {
|
||||
if (callback.get() != null) {
|
||||
if (properties != null) {
|
||||
callback.get().setConnection(properties);
|
||||
|
@ -17,7 +17,7 @@ import org.nuclearfog.twidda.backend.items.Tweet;
|
||||
import org.nuclearfog.twidda.backend.items.TwitterList;
|
||||
import org.nuclearfog.twidda.backend.items.TwitterTrend;
|
||||
import org.nuclearfog.twidda.backend.items.TwitterUser;
|
||||
import org.nuclearfog.twidda.backend.items.UserConnection;
|
||||
import org.nuclearfog.twidda.backend.items.UserRelation;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
|
||||
import java.io.File;
|
||||
@ -459,9 +459,9 @@ public class TwitterEngine {
|
||||
* @return User Properties
|
||||
* @throws EngineException if Connection is unavailable
|
||||
*/
|
||||
public UserConnection getConnection(long userId) throws EngineException {
|
||||
public UserRelation getConnection(long userId) throws EngineException {
|
||||
try {
|
||||
return new UserConnection(twitter.showFriendship(twitterID, userId));
|
||||
return new UserRelation(twitter.showFriendship(twitterID, userId));
|
||||
} catch (TwitterException err) {
|
||||
throw new EngineException(err);
|
||||
}
|
||||
@ -475,9 +475,9 @@ public class TwitterEngine {
|
||||
* @return User Properties
|
||||
* @throws EngineException if Connection is unavailable
|
||||
*/
|
||||
public UserConnection getConnection(String username) throws EngineException {
|
||||
public UserRelation getConnection(String username) throws EngineException {
|
||||
try {
|
||||
return new UserConnection(twitter.showFriendship(twitter.getScreenName(), username));
|
||||
return new UserRelation(twitter.showFriendship(twitter.getScreenName(), username));
|
||||
} catch (TwitterException err) {
|
||||
throw new EngineException(err);
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ public class Tweet {
|
||||
private final long myRetweetId;
|
||||
private final boolean retweeted;
|
||||
private final boolean favored;
|
||||
private final boolean sensitiveMedia;
|
||||
|
||||
private final String locationName;
|
||||
private final String locationCoordinates;
|
||||
@ -77,6 +78,7 @@ public class Tweet {
|
||||
replyID = status.getInReplyToStatusId();
|
||||
myRetweetId = status.getCurrentUserRetweetId();
|
||||
replyUserId = status.getInReplyToUserId();
|
||||
sensitiveMedia = status.isPossiblySensitive();
|
||||
|
||||
// remove HTML tag
|
||||
String api = "" + status.getSource();
|
||||
@ -154,12 +156,13 @@ public class Tweet {
|
||||
* @param myRetweetId ID of the current users retweeted tweet
|
||||
* @param retweeted tweet is retweeted by current user
|
||||
* @param favored tweet is favored by current user
|
||||
* @param sensitiveMedia tweet contains sensitie media content
|
||||
* @param geo location gps coordinates
|
||||
* @param place location full place name
|
||||
*/
|
||||
public Tweet(long tweetID, int retweetCount, int favoriteCount, TwitterUser user, String tweet, long time,
|
||||
String replyName, long replyUserId, String[] medias, MediaType mediaType, String source, long replyID,
|
||||
Tweet embedded, long myRetweetId, boolean retweeted, boolean favored, String place, String geo) {
|
||||
Tweet embedded, long myRetweetId, boolean retweeted, boolean favored, boolean sensitiveMedia, String place, String geo) {
|
||||
|
||||
this.tweetID = tweetID;
|
||||
this.user = user;
|
||||
@ -172,6 +175,7 @@ public class Tweet {
|
||||
this.mediaType = mediaType;
|
||||
this.retweeted = retweeted;
|
||||
this.favored = favored;
|
||||
this.sensitiveMedia = sensitiveMedia;
|
||||
this.myRetweetId = myRetweetId;
|
||||
this.replyUserId = replyUserId;
|
||||
this.tweet = tweet != null ? tweet : "";
|
||||
@ -308,6 +312,15 @@ public class Tweet {
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if tweet contains sensitive media
|
||||
*
|
||||
* @return true if media has sensitive conent
|
||||
*/
|
||||
public boolean containsSensitiveMedia() {
|
||||
return sensitiveMedia;
|
||||
}
|
||||
|
||||
/**
|
||||
* is tweet retweeted by me
|
||||
*
|
||||
|
@ -7,7 +7,7 @@ import twitter4j.Relationship;
|
||||
/**
|
||||
* Holder for relationship information between the current user and another user
|
||||
*/
|
||||
public class UserConnection {
|
||||
public class UserRelation {
|
||||
|
||||
private final String targetScreenname;
|
||||
private final boolean isHome;
|
||||
@ -22,7 +22,7 @@ public class UserConnection {
|
||||
*
|
||||
* @param connect twitter4j relationship information
|
||||
*/
|
||||
public UserConnection(Relationship connect) {
|
||||
public UserRelation(Relationship connect) {
|
||||
targetScreenname = '@' + connect.getTargetUserScreenName();
|
||||
isHome = connect.getSourceUserId() == connect.getTargetUserId();
|
||||
isFriend = connect.isSourceFollowingTarget();
|
@ -28,8 +28,9 @@ public class AppDatabase {
|
||||
private static final int RPL_MASK = 1 << 5; // tweet is from a reply timeline
|
||||
|
||||
private static final int MEDIA_IMAGE_MASK = 1 << 6; // tweet contains images
|
||||
private static final int MEDIA_VIDEO_MASK = 1 << 7; // tweet contains a video
|
||||
private static final int MEDIA_ANGIF_MASK = 1 << 8; // tweet contains an animation
|
||||
private static final int MEDIA_VIDEO_MASK = 2 << 6; // tweet contains a video
|
||||
private static final int MEDIA_ANGIF_MASK = 3 << 6; // tweet contains an animation
|
||||
private static final int MEDIA_SENS_MASK = 1 << 8; // tweet contains sensitive media
|
||||
|
||||
private static final int VER_MASK = 1; // user is verified
|
||||
private static final int LCK_MASK = 1 << 1; // user is private
|
||||
@ -107,7 +108,7 @@ public class AppDatabase {
|
||||
removeOldFavorites(db, ownerId);
|
||||
for (Tweet tweet : fav) {
|
||||
storeStatus(tweet, 0, db);
|
||||
storeFavorite(tweet, ownerId, db);
|
||||
storeFavorite(tweet.getId(), ownerId, db);
|
||||
}
|
||||
commit(db);
|
||||
}
|
||||
@ -153,7 +154,7 @@ public class AppDatabase {
|
||||
public void storeFavorite(Tweet tweet) {
|
||||
SQLiteDatabase db = getDbWrite();
|
||||
storeStatus(tweet, 0, db);
|
||||
storeFavorite(tweet, homeId, db);
|
||||
storeFavorite(tweet.getId(), homeId, db);
|
||||
commit(db);
|
||||
}
|
||||
|
||||
@ -339,21 +340,21 @@ public class AppDatabase {
|
||||
SQLiteDatabase db = getDbWrite();
|
||||
ContentValues statColumn = new ContentValues();
|
||||
ContentValues userColumn = new ContentValues();
|
||||
int register = getTweetStatus(db, tweet.getId());
|
||||
int flags = getTweetFlags(db, tweet.getId());
|
||||
if (tweet.retweeted())
|
||||
register |= RTW_MASK;
|
||||
flags |= RTW_MASK;
|
||||
else
|
||||
register &= ~RTW_MASK;
|
||||
flags &= ~RTW_MASK;
|
||||
if (tweet.favored())
|
||||
register |= FAV_MASK;
|
||||
flags |= FAV_MASK;
|
||||
else
|
||||
register &= ~FAV_MASK;
|
||||
flags &= ~FAV_MASK;
|
||||
statColumn.put("tweet", tweet.getTweet());
|
||||
statColumn.put("retweet", tweet.getRetweetCount());
|
||||
statColumn.put("favorite", tweet.getFavorCount());
|
||||
statColumn.put("retweeterID", tweet.getMyRetweetId());
|
||||
statColumn.put("replyname", tweet.getReplyName());
|
||||
statColumn.put("statusregister", register);
|
||||
statColumn.put("statusregister", flags);
|
||||
statColumn.put("media", getMediaLinks(tweet));
|
||||
|
||||
TwitterUser user = tweet.getUser();
|
||||
@ -411,10 +412,10 @@ public class AppDatabase {
|
||||
final String[] updateArgs = {Long.toString(tweetId)};
|
||||
|
||||
SQLiteDatabase db = getDbWrite();
|
||||
int register = getTweetStatus(db, tweetId);
|
||||
register &= ~FAV_MASK;
|
||||
int flags = getTweetFlags(db, tweetId);
|
||||
flags &= ~FAV_MASK;
|
||||
ContentValues status = new ContentValues();
|
||||
status.put("statusregister", register);
|
||||
status.put("statusregister", flags);
|
||||
db.delete("favorit", "tweetID=? AND ownerID=?", delArgs);
|
||||
db.update("tweet", status, "tweet.tweetID=?", updateArgs);
|
||||
commit(db);
|
||||
@ -518,19 +519,24 @@ public class AppDatabase {
|
||||
final String[] ARGS = new String[]{Long.toString(id)};
|
||||
|
||||
SQLiteDatabase db = getDbWrite();
|
||||
int userRegister = getUserStatus(db, id);
|
||||
int flags = getUserFlags(db, id);
|
||||
if (mute)
|
||||
userRegister |= EXCL_USR;
|
||||
flags |= EXCL_USR;
|
||||
else
|
||||
userRegister &= ~EXCL_USR;
|
||||
flags &= ~EXCL_USR;
|
||||
|
||||
ContentValues userColumn = new ContentValues();
|
||||
userColumn.put("userregister", userRegister);
|
||||
userColumn.put("userregister", flags);
|
||||
db.update("user", userColumn, "user.userID=?", ARGS);
|
||||
commit(db);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get tweet information from database
|
||||
*
|
||||
* @param cursor cursor containing tweet informations
|
||||
* @return tweet instance
|
||||
*/
|
||||
private Tweet getStatus(Cursor cursor) {
|
||||
long time = cursor.getLong(cursor.getColumnIndex("time"));
|
||||
String tweettext = cursor.getString(cursor.getColumnIndex("tweet"));
|
||||
@ -549,23 +555,30 @@ public class AppDatabase {
|
||||
int statusregister = cursor.getInt(cursor.getColumnIndex("statusregister"));
|
||||
boolean favorited = (statusregister & FAV_MASK) != 0;
|
||||
boolean retweeted = (statusregister & RTW_MASK) != 0;
|
||||
boolean sensitive = (statusregister & MEDIA_SENS_MASK) != 0;
|
||||
String[] medias = parseMedia(medialinks);
|
||||
Tweet.MediaType mediaType = Tweet.MediaType.NONE;
|
||||
if ((statusregister & MEDIA_IMAGE_MASK) != 0)
|
||||
if ((statusregister & MEDIA_IMAGE_MASK) != MEDIA_IMAGE_MASK)
|
||||
mediaType = Tweet.MediaType.IMAGE;
|
||||
else if ((statusregister & MEDIA_VIDEO_MASK) != 0)
|
||||
else if ((statusregister & MEDIA_VIDEO_MASK) != MEDIA_VIDEO_MASK)
|
||||
mediaType = Tweet.MediaType.VIDEO;
|
||||
else if ((statusregister & MEDIA_ANGIF_MASK) != 0)
|
||||
else if ((statusregister & MEDIA_ANGIF_MASK) != MEDIA_ANGIF_MASK)
|
||||
mediaType = Tweet.MediaType.GIF;
|
||||
TwitterUser user = getUser(cursor);
|
||||
Tweet embeddedTweet = null;
|
||||
if (retweetId > 1)
|
||||
embeddedTweet = getStatus(retweetId);
|
||||
return new Tweet(tweetId, retweet, favorit, user, tweettext, time, replyname, replyUserId, medias,
|
||||
mediaType, source, replyStatusId, embeddedTweet, retweeterId, retweeted, favorited, place, geo);
|
||||
mediaType, source, replyStatusId, embeddedTweet, retweeterId, retweeted, favorited, sensitive, place, geo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get user information from table
|
||||
*
|
||||
* @param userId Id of the user
|
||||
* @param db SQLITE DB
|
||||
* @return user instance
|
||||
*/
|
||||
@Nullable
|
||||
private TwitterUser getUser(long userId, SQLiteDatabase db) {
|
||||
final String[] ARGS = new String[]{Long.toString(userId)};
|
||||
@ -579,7 +592,12 @@ public class AppDatabase {
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get user information from database
|
||||
*
|
||||
* @param cursor cursor containing user data
|
||||
* @return user instance
|
||||
*/
|
||||
private TwitterUser getUser(Cursor cursor) {
|
||||
long userId = cursor.getLong(cursor.getColumnIndex("userID"));
|
||||
String username = cursor.getString(cursor.getColumnIndex("username"));
|
||||
@ -603,32 +621,38 @@ public class AppDatabase {
|
||||
isLocked, isReq, defaultImg, link, banner, createdAt, following, follower, tCount, fCount);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* store user information into database
|
||||
*
|
||||
* @param user user information
|
||||
* @param db SQLITE DB
|
||||
* @param mode SQLITE mode {@link SQLiteDatabase#CONFLICT_IGNORE} or {@link SQLiteDatabase#CONFLICT_REPLACE}
|
||||
*/
|
||||
private void storeUser(TwitterUser user, SQLiteDatabase db, int mode) {
|
||||
ContentValues userColumn = new ContentValues();
|
||||
int userRegister = getUserStatus(db, user.getId());
|
||||
int flags = getUserFlags(db, user.getId());
|
||||
if (user.isVerified())
|
||||
userRegister |= VER_MASK;
|
||||
flags |= VER_MASK;
|
||||
else
|
||||
userRegister &= ~VER_MASK;
|
||||
flags &= ~VER_MASK;
|
||||
if (user.isLocked())
|
||||
userRegister |= LCK_MASK;
|
||||
flags |= LCK_MASK;
|
||||
else
|
||||
userRegister &= ~LCK_MASK;
|
||||
flags &= ~LCK_MASK;
|
||||
if (user.followRequested())
|
||||
userRegister |= FRQ_MASK;
|
||||
flags |= FRQ_MASK;
|
||||
else
|
||||
userRegister &= ~FRQ_MASK;
|
||||
flags &= ~FRQ_MASK;
|
||||
if (user.hasDefaultProfileImage())
|
||||
userRegister |= DEF_IMG;
|
||||
flags |= DEF_IMG;
|
||||
else
|
||||
userRegister &= ~DEF_IMG;
|
||||
flags &= ~DEF_IMG;
|
||||
|
||||
userColumn.put("userID", user.getId());
|
||||
userColumn.put("username", user.getUsername());
|
||||
userColumn.put("scrname", user.getScreenname());
|
||||
userColumn.put("pbLink", user.getImageLink());
|
||||
userColumn.put("userregister", userRegister);
|
||||
userColumn.put("userregister", flags);
|
||||
userColumn.put("bio", user.getBio());
|
||||
userColumn.put("link", user.getLink());
|
||||
userColumn.put("location", user.getLocation());
|
||||
@ -643,6 +667,13 @@ public class AppDatabase {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* save tweet into database
|
||||
*
|
||||
* @param tweet Tweet information
|
||||
* @param statusRegister predefined statusregister or "0" if there isn't one
|
||||
* @param db SQLite database
|
||||
*/
|
||||
private void storeStatus(Tweet tweet, int statusRegister, SQLiteDatabase db) {
|
||||
ContentValues status = new ContentValues();
|
||||
TwitterUser user = tweet.getUser();
|
||||
@ -654,7 +685,7 @@ public class AppDatabase {
|
||||
rtId = rtStat.getId();
|
||||
}
|
||||
|
||||
statusRegister |= getTweetStatus(db, tweet.getId());
|
||||
statusRegister |= getTweetFlags(db, tweet.getId());
|
||||
if (tweet.favored()) {
|
||||
statusRegister |= FAV_MASK;
|
||||
} else {
|
||||
@ -665,6 +696,11 @@ public class AppDatabase {
|
||||
} else {
|
||||
statusRegister &= ~RTW_MASK;
|
||||
}
|
||||
if (tweet.containsSensitiveMedia()) {
|
||||
statusRegister |= MEDIA_SENS_MASK;
|
||||
} else {
|
||||
statusRegister &= ~MEDIA_SENS_MASK;
|
||||
}
|
||||
switch (tweet.getMediaType()) {
|
||||
case IMAGE:
|
||||
statusRegister |= MEDIA_IMAGE_MASK;
|
||||
@ -701,21 +737,37 @@ public class AppDatabase {
|
||||
db.insertWithOnConflict("tweet", null, status, CONFLICT_REPLACE);
|
||||
}
|
||||
|
||||
|
||||
private void storeFavorite(Tweet tweet, long ownerId, SQLiteDatabase db) {
|
||||
/**
|
||||
* Store Tweet into favorite table of a user
|
||||
*
|
||||
* @param tweetId ID of the favored tweet
|
||||
* @param ownerId ID of the favorite list owner
|
||||
* @param db SQLITE DB
|
||||
*/
|
||||
private void storeFavorite(long tweetId, long ownerId, SQLiteDatabase db) {
|
||||
ContentValues favTable = new ContentValues();
|
||||
favTable.put("tweetID", tweet.getId());
|
||||
favTable.put("tweetID", tweetId);
|
||||
favTable.put("ownerID", ownerId);
|
||||
db.insertWithOnConflict("favorit", null, favTable, CONFLICT_REPLACE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* clear old favorites from table
|
||||
*
|
||||
* @param db SQLITE DB
|
||||
* @param userId ID of the favorite list owner
|
||||
*/
|
||||
private void removeOldFavorites(SQLiteDatabase db, long userId) {
|
||||
final String[] delArgs = {Long.toString(userId)};
|
||||
db.delete("favorit", "ownerID=?", delArgs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* store direct message
|
||||
*
|
||||
* @param message direct message information
|
||||
* @param db SQLITE DB
|
||||
*/
|
||||
private void storeMessage(Message message, SQLiteDatabase db) {
|
||||
ContentValues messageColumn = new ContentValues();
|
||||
messageColumn.put("messageID", message.getId());
|
||||
@ -728,8 +780,14 @@ public class AppDatabase {
|
||||
db.insertWithOnConflict("message", null, messageColumn, CONFLICT_IGNORE);
|
||||
}
|
||||
|
||||
|
||||
private int getTweetStatus(SQLiteDatabase db, long tweetID) {
|
||||
/**
|
||||
* get statusregister of a tweet or "0" if tweet was not found
|
||||
*
|
||||
* @param db SQLITE DB
|
||||
* @param tweetID ID of the tweet
|
||||
* @return tweet flags
|
||||
*/
|
||||
private int getTweetFlags(SQLiteDatabase db, long tweetID) {
|
||||
final String[] ARGS = new String[]{Long.toString(tweetID)};
|
||||
final String QUERY = "SELECT statusregister FROM tweet WHERE tweetID=? LIMIT 1;";
|
||||
|
||||
@ -743,8 +801,14 @@ public class AppDatabase {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private int getUserStatus(SQLiteDatabase db, long userID) {
|
||||
/**
|
||||
* get flags of a twitter user or "0" if user was not found
|
||||
*
|
||||
* @param db SQLITE DB
|
||||
* @param userID ID of the user
|
||||
* @return user flags
|
||||
*/
|
||||
private int getUserFlags(SQLiteDatabase db, long userID) {
|
||||
final String[] ARGS = new String[]{Long.toString(userID)};
|
||||
final String QUERY = "SELECT userregister FROM user WHERE userID=? LIMIT 1;";
|
||||
|
||||
@ -776,25 +840,42 @@ public class AppDatabase {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get SQLite instance for reading database
|
||||
*
|
||||
* @return SQLite instance
|
||||
*/
|
||||
private synchronized SQLiteDatabase getDbRead() {
|
||||
return dataHelper.getDatabase();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GET SQLite instance for writing database
|
||||
*
|
||||
* @return SQLite instance
|
||||
*/
|
||||
private synchronized SQLiteDatabase getDbWrite() {
|
||||
SQLiteDatabase db = dataHelper.getDatabase();
|
||||
db.beginTransaction();
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Commit changes and close Database
|
||||
*
|
||||
* @param db SQLite database
|
||||
*/
|
||||
private synchronized void commit(SQLiteDatabase db) {
|
||||
db.setTransactionSuccessful();
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse string where media links are separated by ' ; '
|
||||
*
|
||||
* @param media tweet media link
|
||||
* @return array of media links
|
||||
*/
|
||||
private String[] parseMedia(String media) {
|
||||
int index;
|
||||
List<String> links = new LinkedList<>();
|
||||
@ -808,7 +889,12 @@ public class AppDatabase {
|
||||
return links.toArray(new String[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create string where media links are separated by ' ; '
|
||||
*
|
||||
* @param tweet tweet informations
|
||||
* @return String of media links
|
||||
*/
|
||||
private String getMediaLinks(Tweet tweet) {
|
||||
StringBuilder media = new StringBuilder();
|
||||
for (String link : tweet.getMediaLinks())
|
||||
|
@ -132,7 +132,7 @@
|
||||
<dimen name="tweetpopup_text_width">300dp</dimen>
|
||||
<dimen name="tweetpopup_text_height">200dp</dimen>
|
||||
<dimen name="tweetpopup_button_size">40dp</dimen>
|
||||
<dimen name="tweetpopup_button_margin">12dp</dimen>
|
||||
<dimen name="tweetpopup_button_margin">7dp</dimen>
|
||||
<dimen name="tweetpopup_location_progress_size">30dp</dimen>
|
||||
|
||||
<!--dimens of popup_dm.xml-->
|
||||
@ -141,7 +141,7 @@
|
||||
<dimen name="dmpopup_button_size">40dp</dimen>
|
||||
<dimen name="dmpopup_text_width">300dp</dimen>
|
||||
<dimen name="dmpopup_text_height">200dp</dimen>
|
||||
<dimen name="dmpopup_button_margin">12dp</dimen>
|
||||
<dimen name="dmpopup_button_margin">7dp</dimen>
|
||||
|
||||
<!--dimens of item_load.xml-->
|
||||
<dimen name="loaditem_button_size">36sp</dimen>
|
||||
|
Loading…
x
Reference in New Issue
Block a user