tweet counting added for user profiles
This commit is contained in:
parent
187b8f4395
commit
b0a5288427
|
@ -5,7 +5,7 @@
|
|||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="/opt/gradle/gradle-4.10.2" />
|
||||
<option name="gradleHome" value="$USER_HOME$/Gradle/gradle-4.10.2" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
@ -13,7 +13,6 @@
|
|||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
|
|
@ -29,5 +29,10 @@
|
|||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
|
@ -147,8 +147,7 @@ public class TimelineAdapter extends Adapter<TimelineAdapter.ItemHolder> {
|
|||
return hours + " h";
|
||||
if (minutes > 0)
|
||||
return minutes + " m";
|
||||
else
|
||||
return seconds + " s";
|
||||
return seconds + " s";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -133,15 +133,15 @@ public class ProfileLoader extends AsyncTask<Long, Long, Long> {
|
|||
|
||||
if (MODE == ACTION_FOLLOW) {
|
||||
isFollowing = !isFollowing;
|
||||
mTwitter.followAction(UID, isFollowing);
|
||||
user = mTwitter.followAction(UID, isFollowing);
|
||||
publishProgress(GET_USER);
|
||||
} else if (MODE == ACTION_BLOCK) {
|
||||
isBlocked = !isBlocked;
|
||||
mTwitter.blockAction(UID, isBlocked);
|
||||
user = mTwitter.blockAction(UID, isBlocked);
|
||||
publishProgress(GET_USER);
|
||||
} else if (MODE == ACTION_MUTE) {
|
||||
isMuted = !isMuted;
|
||||
mTwitter.muteAction(UID, isMuted);
|
||||
user = mTwitter.muteAction(UID, isMuted);
|
||||
publishProgress(GET_USER);
|
||||
} else {
|
||||
if (!user.isLocked() || isFollowing) {
|
||||
|
@ -258,6 +258,8 @@ public class ProfileLoader extends AsyncTask<Long, Long, Long> {
|
|||
}
|
||||
});
|
||||
|
||||
ui.get().setTweetCount(user.getTweetCount(),user.getFavorCount());
|
||||
|
||||
} else if (MODE == GET_TWEETS) {
|
||||
homeTl.setData(tweets);
|
||||
homeTl.notifyDataSetChanged();
|
||||
|
|
|
@ -111,7 +111,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
|
|||
|
||||
} else if (MODE == FAVORITE) {
|
||||
tweet = mTwitter.favorite(TWEETID);
|
||||
if (tweet.favorized())
|
||||
if (tweet.favored())
|
||||
database.storeFavorite(TWEETID);
|
||||
else
|
||||
database.removeFavorite(TWEETID);
|
||||
|
@ -209,7 +209,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
|
|||
} else {
|
||||
retweetButton.setImageResource(R.drawable.retweet);
|
||||
}
|
||||
if (tweet.favorized()) {
|
||||
if (tweet.favored()) {
|
||||
favoriteButton.setImageResource(R.drawable.favorite_enabled);
|
||||
} else {
|
||||
favoriteButton.setImageResource(R.drawable.favorite);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.nuclearfog.twidda.backend;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.nuclearfog.twidda.BuildConfig;
|
||||
|
@ -289,14 +290,16 @@ public class TwitterEngine {
|
|||
*
|
||||
* @param userId User ID
|
||||
* @param action using action
|
||||
* @return updated user information
|
||||
* @throws TwitterException if Access is unavailable
|
||||
*/
|
||||
public void followAction(long userId, boolean action) throws TwitterException {
|
||||
if (action) {
|
||||
twitter.createFriendship(userId);
|
||||
} else {
|
||||
twitter.destroyFriendship(userId);
|
||||
}
|
||||
public TwitterUser followAction(long userId, boolean action) throws TwitterException {
|
||||
User user;
|
||||
if (action)
|
||||
user = twitter.createFriendship(userId);
|
||||
else
|
||||
user = twitter.destroyFriendship(userId);
|
||||
return getUser(user);
|
||||
}
|
||||
|
||||
|
||||
|
@ -305,14 +308,16 @@ public class TwitterEngine {
|
|||
*
|
||||
* @param userId User ID
|
||||
* @param action using action
|
||||
* @return updated user information
|
||||
* @throws TwitterException if Access is unavailable
|
||||
*/
|
||||
public void blockAction(long userId, boolean action) throws TwitterException {
|
||||
if (action) {
|
||||
twitter.createBlock(userId);
|
||||
} else {
|
||||
twitter.destroyBlock(userId);
|
||||
}
|
||||
public TwitterUser blockAction(long userId, boolean action) throws TwitterException {
|
||||
User user;
|
||||
if (action)
|
||||
user = twitter.createBlock(userId);
|
||||
else
|
||||
user = twitter.destroyBlock(userId);
|
||||
return getUser(user);
|
||||
}
|
||||
|
||||
|
||||
|
@ -321,14 +326,16 @@ public class TwitterEngine {
|
|||
*
|
||||
* @param userId User ID
|
||||
* @param action using action
|
||||
* @return updated user information
|
||||
* @throws TwitterException if Access is unavailable
|
||||
*/
|
||||
public void muteAction(long userId, boolean action) throws TwitterException {
|
||||
if (action) {
|
||||
twitter.createMute(userId);
|
||||
} else {
|
||||
twitter.destroyMute(userId);
|
||||
}
|
||||
public TwitterUser muteAction(long userId, boolean action) throws TwitterException {
|
||||
User user;
|
||||
if (action)
|
||||
user = twitter.createMute(userId);
|
||||
else
|
||||
user = twitter.destroyMute(userId);
|
||||
return getUser(user);
|
||||
}
|
||||
|
||||
|
||||
|
@ -374,7 +381,7 @@ public class TwitterEngine {
|
|||
mStatus.setInReplyToStatusId(reply);
|
||||
|
||||
if (path != null) {
|
||||
int count = path.length;
|
||||
final int count = path.length;
|
||||
long[] mIDs = new long[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
String current = path[i];
|
||||
|
@ -439,19 +446,17 @@ public class TwitterEngine {
|
|||
* @throws TwitterException if Access is unavailable
|
||||
*/
|
||||
public Tweet retweet(long tweetId) throws TwitterException {
|
||||
Tweet tweet = getStatus(tweetId);
|
||||
int retweet = tweet.getRetweetCount();
|
||||
Status tweet = twitter.showStatus(tweetId);
|
||||
|
||||
if (tweet.retweeted()) {
|
||||
deleteTweet(tweet.getMyRetweetId());
|
||||
retweet--;
|
||||
} else {
|
||||
twitter.retweetStatus(tweet.getId());
|
||||
retweet++;
|
||||
}
|
||||
return new Tweet(tweetId, retweet, tweet.getFavorCount(), tweet.getUser(), tweet.getText(),
|
||||
tweet.getTime(), tweet.getReplyName(), tweet.getReplyUserId(), tweet.getMediaLinks(), tweet.getSource(),
|
||||
tweet.getReplyId(), tweet.getEmbeddedTweet(), tweet.getMyRetweetId(), !tweet.retweeted(), tweet.favorized());
|
||||
if (tweet.isRetweeted())
|
||||
tweet = twitter.unRetweetStatus(tweet.getId());
|
||||
else
|
||||
tweet = twitter.retweetStatus(tweet.getId());
|
||||
|
||||
if(tweet.getRetweetedStatus() == null)
|
||||
return getTweet(tweet, null);
|
||||
else
|
||||
return getTweet(tweet, getTweet(tweet.getRetweetedStatus(), null));
|
||||
}
|
||||
|
||||
|
||||
|
@ -462,20 +467,18 @@ public class TwitterEngine {
|
|||
* @throws TwitterException if Access is unavailable
|
||||
*/
|
||||
public Tweet favorite(long tweetId) throws TwitterException {
|
||||
Tweet tweet = getStatus(tweetId);
|
||||
int favorite = tweet.getFavorCount();
|
||||
Status tweet = twitter.showStatus(tweetId);
|
||||
|
||||
if (tweet.favorized()) {
|
||||
twitter.destroyFavorite(tweet.getId());
|
||||
favorite--;
|
||||
} else {
|
||||
twitter.createFavorite(tweet.getId());
|
||||
favorite++;
|
||||
}
|
||||
return new Tweet(tweetId, tweet.getRetweetCount(), favorite, tweet.getUser(), tweet.getText(),
|
||||
tweet.getTime(), tweet.getReplyName(), tweet.getReplyUserId(), tweet.getMediaLinks(), tweet.getSource(),
|
||||
tweet.getReplyId(), tweet.getEmbeddedTweet(), tweet.getMyRetweetId(), tweet.retweeted(), !tweet.favorized());
|
||||
}
|
||||
if (tweet.isFavorited())
|
||||
tweet = twitter.destroyFavorite(tweet.getId());
|
||||
else
|
||||
tweet = twitter.createFavorite(tweet.getId());
|
||||
|
||||
if(tweet.getRetweetedStatus() == null)
|
||||
return getTweet(tweet, null);
|
||||
else
|
||||
return getTweet(tweet, getTweet(tweet.getRetweetedStatus(), null));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -601,15 +604,13 @@ public class TwitterEngine {
|
|||
* @param retweetedStat embedded Status
|
||||
* @return Tweet item
|
||||
*/
|
||||
private Tweet getTweet(Status status, Tweet retweetedStat) {
|
||||
private Tweet getTweet(@NonNull Status status, @Nullable Tweet retweetedStat) {
|
||||
TwitterUser user = getUser(status.getUser());
|
||||
int retweet, favorite;
|
||||
int retweet = status.getRetweetCount();
|
||||
int favorite = status.getFavoriteCount();
|
||||
if (retweetedStat != null) {
|
||||
retweet = retweetedStat.getRetweetCount();
|
||||
favorite = retweetedStat.getFavorCount();
|
||||
} else {
|
||||
retweet = status.getRetweetCount();
|
||||
favorite = status.getFavoriteCount();
|
||||
}
|
||||
String api = status.getSource();
|
||||
api = api.substring(api.indexOf('>') + 1);
|
||||
|
@ -627,12 +628,7 @@ public class TwitterEngine {
|
|||
* @return User item
|
||||
*/
|
||||
private TwitterUser getUser(User user) {
|
||||
String description = user.getDescription().replace('\n', ' ');
|
||||
String screenname = '@' + user.getScreenName();
|
||||
return new TwitterUser(user.getId(), user.getName(), screenname,
|
||||
user.getOriginalProfileImageURL(), description, user.getLocation(), user.isVerified(),
|
||||
user.isProtected(), user.getURL(), user.getProfileBannerURL(), user.getCreatedAt().getTime(),
|
||||
user.getFriendsCount(), user.getFollowersCount());
|
||||
return new TwitterUser(user);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,14 +21,14 @@ public class Tweet {
|
|||
private final int favoriteCount;
|
||||
|
||||
private final boolean retweeted;
|
||||
private final boolean favorized;
|
||||
private final boolean favored;
|
||||
|
||||
private final long retweetId;
|
||||
|
||||
|
||||
public Tweet(long tweetID, int retweetCount, int favoriteCount, TwitterUser user, String tweet, long time,
|
||||
String replyName, long replyUserId, String[] media, String source, long replyID,
|
||||
Tweet embedded, long retweetId, boolean retweeted, boolean favorized) {
|
||||
Tweet embedded, long retweetId, boolean retweeted, boolean favored) {
|
||||
this.tweetID = tweetID;
|
||||
this.user = user;
|
||||
this.retweetCount = retweetCount;
|
||||
|
@ -41,7 +41,7 @@ public class Tweet {
|
|||
this.media = media;
|
||||
this.source = source;
|
||||
this.retweeted = retweeted;
|
||||
this.favorized = favorized;
|
||||
this.favored = favored;
|
||||
this.retweetId = retweetId;
|
||||
this.replyUserId = replyUserId;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public class Tweet {
|
|||
/**
|
||||
* is tweet retweeted by me
|
||||
*
|
||||
* @return retweet status
|
||||
* @return if status is retweeted
|
||||
*/
|
||||
public boolean retweeted() {
|
||||
return retweeted;
|
||||
|
@ -176,10 +176,10 @@ public class Tweet {
|
|||
/**
|
||||
* is tweet favored by me
|
||||
*
|
||||
* @return favor status
|
||||
* @return if status is favored
|
||||
*/
|
||||
public boolean favorized() {
|
||||
return favorized;
|
||||
public boolean favored() {
|
||||
return favored;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package org.nuclearfog.twidda.backend.items;
|
||||
|
||||
import twitter4j.User;
|
||||
|
||||
public class TwitterUser {
|
||||
private final long userID;
|
||||
private final long created;
|
||||
|
@ -13,6 +15,9 @@ public class TwitterUser {
|
|||
private final int following;
|
||||
private final int follower;
|
||||
|
||||
private final int tweetCount;
|
||||
private final int favorCount;
|
||||
|
||||
private final String bio;
|
||||
private final String location;
|
||||
private final String link;
|
||||
|
@ -20,10 +25,27 @@ public class TwitterUser {
|
|||
private final String profileImg;
|
||||
private final String bannerImg;
|
||||
|
||||
public TwitterUser(User user) {
|
||||
userID = user.getId();
|
||||
username = user.getName();
|
||||
screenname = '@' + user.getScreenName();
|
||||
profileImg = user.getOriginalProfileImageURL();
|
||||
bio = user.getDescription().replace('\n', ' ');
|
||||
link = user.getURL();
|
||||
location = user.getLocation();
|
||||
bannerImg = user.getProfileBannerURL();
|
||||
isVerified = user.isVerified();
|
||||
isLocked = user.isProtected();
|
||||
created = user.getCreatedAt().getTime();
|
||||
following = user.getFriendsCount();
|
||||
follower = user.getFollowersCount();
|
||||
tweetCount = user.getStatusesCount();
|
||||
favorCount = user.getFavouritesCount();
|
||||
}
|
||||
|
||||
public TwitterUser(long userID, String username, String screenname, String profileImg,
|
||||
String bio, String location, boolean isVerified, boolean isLocked, String link,
|
||||
String bannerImg, long created, int following, int follower) {
|
||||
String bannerImg, long created, int following, int follower, int tweetCount, int favorCount) {
|
||||
this.userID = userID;
|
||||
this.username = username;
|
||||
this.screenname = screenname;
|
||||
|
@ -37,6 +59,8 @@ public class TwitterUser {
|
|||
this.created = created;
|
||||
this.following = following;
|
||||
this.follower = follower;
|
||||
this.tweetCount = tweetCount;
|
||||
this.favorCount = favorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,4 +180,22 @@ public class TwitterUser {
|
|||
return follower;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Tweet count of user
|
||||
*
|
||||
* @return tweet count
|
||||
*/
|
||||
public int getTweetCount() {
|
||||
return tweetCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* get count of favored tweets
|
||||
*
|
||||
* @return tweet count
|
||||
*/
|
||||
public int getFavorCount() {
|
||||
return favorCount;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,31 +6,31 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||
|
||||
public class AppDatabase extends SQLiteOpenHelper {
|
||||
private static final String userTable = "CREATE TABLE IF NOT EXISTS user (" +
|
||||
"userID INTEGER PRIMARY KEY, username VARCHAR(50),scrname VARCHAR(15)," +
|
||||
"userID INTEGER PRIMARY KEY,username VARCHAR(50),scrname VARCHAR(15)," +
|
||||
"pbLink TEXT,banner TEXT,bio TEXT,location TEXT,link TEXT,userregister INTEGER," +
|
||||
"createdAt INTEGER, following INTEGER, follower INTEGER);";
|
||||
"createdAt INTEGER,following INTEGER,follower INTEGER,tweetCount INTEGER,favorCount INTEGER);";
|
||||
|
||||
private static final String tweetTable = "CREATE TABLE IF NOT EXISTS tweet (" +
|
||||
"tweetID INTEGER PRIMARY KEY, userID INTEGER, retweetID INTEGER, replyID INTEGER, retweeterID INTEGER," +
|
||||
"replyname TEXT, replyUserID INTEGER, time INTEGER, tweet TEXT, media TEXT, retweet INTEGER, favorite INTEGER," +
|
||||
"statusregister INTEGER, source VARCHAR(32), FOREIGN KEY (userID) REFERENCES user(userID));";
|
||||
"tweetID INTEGER PRIMARY KEY,userID INTEGER,retweetID INTEGER,replyID INTEGER,retweeterID INTEGER," +
|
||||
"replyname TEXT,replyUserID INTEGER,time INTEGER,tweet TEXT,media TEXT,retweet INTEGER,favorite INTEGER," +
|
||||
"statusregister INTEGER,source VARCHAR(32),FOREIGN KEY (userID) REFERENCES user(userID));";
|
||||
|
||||
private static final String favoriteTable = "CREATE TABLE IF NOT EXISTS favorit (" +
|
||||
"ownerID INTEGER, tweetID INTEGER PRIMARY KEY," +
|
||||
"ownerID INTEGER,tweetID INTEGER PRIMARY KEY," +
|
||||
"FOREIGN KEY (ownerID) REFERENCES user(userID)," +
|
||||
"FOREIGN KEY (tweetID) REFERENCES tweet(tweetID));";
|
||||
|
||||
private static final String trendTable = "CREATE TABLE IF NOT EXISTS trend (" +
|
||||
"woeID INTEGER, trendpos INTEGER, trendname TEXT, trendlink TEXT);";
|
||||
"woeID INTEGER,trendpos INTEGER,trendname TEXT,trendlink TEXT);";
|
||||
|
||||
private static final String messageTable = "CREATE TABLE IF NOT EXISTS message (" +
|
||||
"messageID INTEGER PRIMARY KEY, time INTEGER, senderID INTEGER, receiverID INTEGER," +
|
||||
"messageID INTEGER PRIMARY KEY,time INTEGER,senderID INTEGER,receiverID INTEGER," +
|
||||
"message TEXT);";
|
||||
|
||||
private static AppDatabase mData;
|
||||
|
||||
private AppDatabase(Context context) {
|
||||
super(context, "database.db", null, 1);
|
||||
super(context, "database.db", null, 2);
|
||||
}
|
||||
|
||||
public static synchronized AppDatabase getInstance(Context context) {
|
||||
|
@ -54,5 +54,11 @@ public class AppDatabase extends SQLiteOpenHelper {
|
|||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
if(oldVersion == 1 && newVersion >= 2) {
|
||||
final String T_QUERY = "ALTER TABLE user ADD COLUMN tweetCount INTEGER DEFAULT 0;";
|
||||
db.execSQL(T_QUERY);
|
||||
final String F_QUERY = "ALTER TABLE user ADD COLUMN favorCount INTEGER DEFAULT 0;";
|
||||
db.execSQL(F_QUERY);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -343,7 +343,7 @@ public class DatabaseAdapter {
|
|||
register |= RTW_MASK;
|
||||
else
|
||||
register &= ~RTW_MASK;
|
||||
if (tweet.favorized())
|
||||
if (tweet.favored())
|
||||
register |= FAV_MASK;
|
||||
else
|
||||
register &= ~FAV_MASK;
|
||||
|
@ -561,11 +561,15 @@ public class DatabaseAdapter {
|
|||
int following = cursor.getInt(index);
|
||||
index = cursor.getColumnIndex("follower");
|
||||
int follower = cursor.getInt(index);
|
||||
index = cursor.getColumnIndex("tweetCount");
|
||||
int tCount = cursor.getInt(index);
|
||||
index = cursor.getColumnIndex("favorCount");
|
||||
int fCount = cursor.getInt(index);
|
||||
|
||||
boolean isVerified = (userRegister & VER_MASK) > 0;
|
||||
boolean isLocked = (userRegister & LCK_MASK) > 0;
|
||||
return new TwitterUser(userId, username, screenname, profileImg, bio,
|
||||
location, isVerified, isLocked, link, banner, createdAt, following, follower);
|
||||
return new TwitterUser(userId, username, screenname, profileImg, bio, location, isVerified,
|
||||
isLocked, link, banner, createdAt, following, follower, tCount, fCount);
|
||||
}
|
||||
|
||||
|
||||
|
@ -588,6 +592,9 @@ public class DatabaseAdapter {
|
|||
userColumn.put("createdAt", user.getCreatedAt());
|
||||
userColumn.put("following", user.getFollowing());
|
||||
userColumn.put("follower", user.getFollower());
|
||||
userColumn.put("tweetCount", user.getTweetCount());
|
||||
userColumn.put("favorCount", user.getFavorCount());
|
||||
|
||||
db.insertWithOnConflict("user", null, userColumn, mode);
|
||||
}
|
||||
|
||||
|
@ -604,7 +611,7 @@ public class DatabaseAdapter {
|
|||
}
|
||||
|
||||
statusRegister |= getStatRegister(db, tweet.getId());
|
||||
if (tweet.favorized()) {
|
||||
if (tweet.favored()) {
|
||||
statusRegister |= FAV_MASK;
|
||||
} else {
|
||||
statusRegister &= ~FAV_MASK;
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.nuclearfog.twidda.window;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
import android.support.v7.app.AlertDialog.Builder;
|
||||
|
@ -12,6 +11,7 @@ import android.support.v7.app.AppCompatDelegate;
|
|||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -19,6 +19,7 @@ import android.view.animation.Animation;
|
|||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TabHost.OnTabChangeListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.nuclearfog.tag.Tagger.OnTagClickListener;
|
||||
import org.nuclearfog.twidda.R;
|
||||
|
@ -28,6 +29,8 @@ import org.nuclearfog.twidda.backend.ProfileLoader;
|
|||
import org.nuclearfog.twidda.backend.items.Tweet;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import static android.os.AsyncTask.Status.RUNNING;
|
||||
import static org.nuclearfog.twidda.window.TweetDetail.TWEET_REMOVED;
|
||||
|
||||
|
@ -43,14 +46,15 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
|||
|
||||
private ProfileLoader mProfile;
|
||||
private GlobalSettings settings;
|
||||
private SwipeRefreshLayout homeReload, favoriteReload;
|
||||
private RecyclerView homeList, favoriteList;
|
||||
private SwipeRefreshLayout homeReload, favoriteReload;
|
||||
private View lastTab, tweetIndicator, favorIndicator;
|
||||
private TabHost mTab;
|
||||
private View lastTab;
|
||||
private NumberFormat formatter;
|
||||
private boolean home, isFollowing, isBlocked, isMuted, canDm;
|
||||
private long userId = 0;
|
||||
private String username;
|
||||
private long userId;
|
||||
private int tabIndex = 0;
|
||||
private String username = "";
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -64,6 +68,8 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
|||
userId = b.getLong("userID");
|
||||
if (b.containsKey("username"))
|
||||
username = b.getString("username");
|
||||
else
|
||||
username = "";
|
||||
}
|
||||
|
||||
Toolbar tool = findViewById(R.id.profile_toolbar);
|
||||
|
@ -80,19 +86,25 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
|||
|
||||
settings = GlobalSettings.getInstance(this);
|
||||
home = userId == settings.getUserId();
|
||||
formatter = NumberFormat.getIntegerInstance();
|
||||
|
||||
homeList.setLayoutManager(new LinearLayoutManager(this));
|
||||
favoriteList.setLayoutManager(new LinearLayoutManager(this));
|
||||
root.setBackgroundColor(settings.getBackgroundColor());
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(this);
|
||||
|
||||
tweetIndicator = inflater.inflate(R.layout.tab_tweets, null);
|
||||
favorIndicator = inflater.inflate(R.layout.tab_favors, null);
|
||||
|
||||
mTab.setup();
|
||||
TabHost.TabSpec tab1 = mTab.newTabSpec("tweets");
|
||||
tab1.setContent(R.id.hometweets);
|
||||
tab1.setIndicator("", ContextCompat.getDrawable(this, R.drawable.home));
|
||||
tab1.setIndicator(tweetIndicator);
|
||||
mTab.addTab(tab1);
|
||||
TabHost.TabSpec tab2 = mTab.newTabSpec("favorites");
|
||||
TabHost.TabSpec tab2 = mTab.newTabSpec("favors");
|
||||
tab2.setContent(R.id.homefavorits);
|
||||
tab2.setIndicator("", ContextCompat.getDrawable(this, R.drawable.favorite));
|
||||
tab2.setIndicator(favorIndicator);
|
||||
mTab.addTab(tab2);
|
||||
lastTab = mTab.getCurrentView();
|
||||
|
||||
|
@ -288,9 +300,14 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
|||
switch (tabIndex) {
|
||||
case 0:
|
||||
homeList.smoothScrollToPosition(0);
|
||||
favorIndicator.findViewById(R.id.favor_divider).setBackgroundResource(R.color.soylentgreen);
|
||||
tweetIndicator.findViewById(R.id.tweet_divider).setBackgroundResource(android.R.color.transparent);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
favoriteList.smoothScrollToPosition(0);
|
||||
tweetIndicator.findViewById(R.id.tweet_divider).setBackgroundResource(R.color.soylentgreen);
|
||||
favorIndicator.findViewById(R.id.favor_divider).setBackgroundResource(android.R.color.transparent);
|
||||
break;
|
||||
}
|
||||
tabIndex = mTab.getCurrentTab();
|
||||
|
@ -327,6 +344,14 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
|||
}
|
||||
|
||||
|
||||
public void setTweetCount(int tweets, int favors) {
|
||||
TextView tweetCount = tweetIndicator.findViewById(R.id.profile_tweet_count);
|
||||
TextView favorCount = favorIndicator.findViewById(R.id.profile_favor_count);
|
||||
tweetCount.setText(formatter.format(tweets));
|
||||
favorCount.setText(formatter.format(favors));
|
||||
}
|
||||
|
||||
|
||||
private void openTweet(long tweetId, long userId, String username) {
|
||||
Intent intent = new Intent(this, TweetDetail.class);
|
||||
intent.putExtra("tweetID", tweetId);
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:contentDescription="@string/profile_tweets"
|
||||
app:srcCompat="@drawable/favorite" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/profile_favor_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="10sp" />
|
||||
|
||||
<View
|
||||
android:id="@+id/favor_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:background="@android:color/transparent" />
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:contentDescription="@string/profile_tweets"
|
||||
app:srcCompat="@drawable/home" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/profile_tweet_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="10sp" />
|
||||
|
||||
<View
|
||||
android:id="@+id/tweet_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:background="@color/soylentgreen" />
|
||||
|
||||
</LinearLayout>
|
|
@ -94,4 +94,5 @@
|
|||
<string name="favorite_button">Favorit Button</string>
|
||||
<string name="close_dm">Direktnachricht schließen</string>
|
||||
<string name="user_not_found">Nutzer nicht gefunden!</string>
|
||||
<string name="profile_tweets">Profile tweets</string>
|
||||
</resources>
|
|
@ -102,4 +102,5 @@
|
|||
<string name="favorite_button">favorite button</string>
|
||||
<string name="close_dm">close direct message</string>
|
||||
<string name="user_not_found">user not found!</string>
|
||||
<string name="profile_tweets">Profile tweets</string>
|
||||
</resources>
|
Loading…
Reference in New Issue