mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-31 19:34:55 +01:00
added profile tablayout
This commit is contained in:
parent
34b87b1a6c
commit
181f991812
@ -12,7 +12,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import org.nuclearfog.twidda.adapter.HomeAdapter;
|
||||
import org.nuclearfog.twidda.adapter.HomeTabAdapter;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
import org.nuclearfog.twidda.window.AppSettings;
|
||||
import org.nuclearfog.twidda.window.LoginPage;
|
||||
@ -30,7 +30,7 @@ public class MainActivity extends AppCompatActivity implements TabLayout.OnTabSe
|
||||
private static final int[] icons = {R.drawable.home, R.drawable.hash, R.drawable.mention};
|
||||
|
||||
private GlobalSettings settings;
|
||||
private HomeAdapter adapter;
|
||||
private HomeTabAdapter adapter;
|
||||
private ViewPager pager;
|
||||
private int tabIndex = 0;
|
||||
|
||||
@ -51,7 +51,7 @@ public class MainActivity extends AppCompatActivity implements TabLayout.OnTabSe
|
||||
View root = findViewById(R.id.main_layout);
|
||||
root.setBackgroundColor(settings.getBackgroundColor());
|
||||
|
||||
adapter = new HomeAdapter(getSupportFragmentManager());
|
||||
adapter = new HomeTabAdapter(getSupportFragmentManager());
|
||||
pager.setOffscreenPageLimit(3);
|
||||
pager.setAdapter(adapter);
|
||||
tab.setupWithViewPager(pager);
|
||||
|
@ -11,7 +11,7 @@ import static org.nuclearfog.twidda.fragment.TweetListFragment.HOME;
|
||||
import static org.nuclearfog.twidda.fragment.TweetListFragment.MENT;
|
||||
|
||||
|
||||
public class HomeAdapter extends FragmentPagerAdapter {
|
||||
public class HomeTabAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private static final int COUNT = 3;
|
||||
private static final Bundle HOME_TL, MENT_TL;
|
||||
@ -25,7 +25,7 @@ public class HomeAdapter extends FragmentPagerAdapter {
|
||||
MENT_TL.putInt("mode", MENT);
|
||||
}
|
||||
|
||||
public HomeAdapter(FragmentManager fm) {
|
||||
public HomeTabAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
fragments = new Fragment[COUNT];
|
||||
fragments[0] = new TweetListFragment();
|
@ -3,8 +3,6 @@ package org.nuclearfog.twidda.backend;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
@ -14,11 +12,10 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.squareup.picasso.Picasso;
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
import org.nuclearfog.tag.Tagger;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.adapter.TweetAdapter;
|
||||
import org.nuclearfog.twidda.backend.items.Tweet;
|
||||
import org.nuclearfog.twidda.backend.items.TwitterUser;
|
||||
import org.nuclearfog.twidda.database.DatabaseAdapter;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
@ -29,37 +26,27 @@ import org.nuclearfog.twidda.window.UserProfile;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
|
||||
public class ProfileLoader extends AsyncTask<Long, Void, Void> {
|
||||
public class ProfileLoader extends AsyncTask<Long, Void, Boolean> {
|
||||
|
||||
public enum Mode {
|
||||
LDR_PROFILE,
|
||||
GET_TWEETS,
|
||||
GET_FAVORS,
|
||||
ACTION_FOLLOW,
|
||||
ACTION_BLOCK,
|
||||
ACTION_MUTE
|
||||
}
|
||||
|
||||
private final Mode mode;
|
||||
private boolean failure = false;
|
||||
|
||||
private TweetAdapter homeTl, homeFav;
|
||||
private WeakReference<UserProfile> ui;
|
||||
private SimpleDateFormat sdf;
|
||||
private TwitterEngine mTwitter;
|
||||
private TwitterException err;
|
||||
private TwitterUser user;
|
||||
private List<Tweet> tweets, favors;
|
||||
private NumberFormat formatter;
|
||||
private long homeId;
|
||||
private int highlight;
|
||||
@ -85,45 +72,20 @@ public class ProfileLoader extends AsyncTask<Long, Void, Void> {
|
||||
imgEnabled = settings.getImageLoad();
|
||||
homeId = settings.getUserId();
|
||||
highlight = settings.getHighlightColor();
|
||||
|
||||
this.mode = mode;
|
||||
tweets = new ArrayList<>();
|
||||
favors = new ArrayList<>();
|
||||
|
||||
RecyclerView profileTweets = context.findViewById(R.id.ht_list);
|
||||
RecyclerView profileFavors = context.findViewById(R.id.hf_list);
|
||||
homeTl = (TweetAdapter) profileTweets.getAdapter();
|
||||
homeFav = (TweetAdapter) profileFavors.getAdapter();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
if (ui.get() != null) {
|
||||
if (mode == Mode.LDR_PROFILE) {
|
||||
SwipeRefreshLayout homeReload = ui.get().findViewById(R.id.hometweets);
|
||||
SwipeRefreshLayout favReload = ui.get().findViewById(R.id.homefavorits);
|
||||
homeReload.setRefreshing(true);
|
||||
favReload.setRefreshing(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Long... args) {
|
||||
protected Boolean doInBackground(Long... args) {
|
||||
final long UID = args[0];
|
||||
long page = 1L;
|
||||
if (args.length > 2)
|
||||
page = args[2];
|
||||
|
||||
DatabaseAdapter db = new DatabaseAdapter(ui.get());
|
||||
isHome = homeId == UID;
|
||||
try {
|
||||
if (mode == Mode.LDR_PROFILE) {
|
||||
user = db.getUser(UID);
|
||||
if (user != null) {
|
||||
tweets = db.getUserTweets(UID);
|
||||
favors = db.getUserFavs(UID);
|
||||
publishProgress();
|
||||
}
|
||||
}
|
||||
@ -141,47 +103,6 @@ public class ProfileLoader extends AsyncTask<Long, Void, Void> {
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case LDR_PROFILE:
|
||||
if (!user.isLocked() || isFollowing || isHome) {
|
||||
if (tweets.isEmpty()) {
|
||||
tweets = mTwitter.getUserTweets(UID, 1, page);
|
||||
db.storeUserTweets(tweets);
|
||||
tweets.addAll(homeTl.getData());
|
||||
publishProgress();
|
||||
}
|
||||
if (favors.isEmpty()) {
|
||||
favors = mTwitter.getUserFavs(UID, 1, page);
|
||||
db.storeUserFavs(favors, UID);
|
||||
favors.addAll(homeFav.getData());
|
||||
publishProgress();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_TWEETS:
|
||||
if (!user.isLocked() || isFollowing || isHome) {
|
||||
long sinceId = 1;
|
||||
if (homeTl.getItemCount() > 0)
|
||||
sinceId = homeTl.getItemId(0);
|
||||
tweets = mTwitter.getUserTweets(UID, sinceId, page);
|
||||
db.storeUserTweets(tweets);
|
||||
tweets.addAll(homeTl.getData());
|
||||
publishProgress();
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_FAVORS:
|
||||
if (!user.isLocked() || isFollowing || isHome) {
|
||||
long sinceId = 1;
|
||||
if (homeFav.getItemCount() > 0)
|
||||
sinceId = homeFav.getItemId(0);
|
||||
favors = mTwitter.getUserFavs(UID, sinceId, page);
|
||||
db.storeUserFavs(favors, UID);
|
||||
favors.addAll(homeFav.getData());
|
||||
publishProgress();
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_FOLLOW:
|
||||
if (user.isLocked()) {
|
||||
if (isFollowing)
|
||||
@ -219,13 +140,13 @@ public class ProfileLoader extends AsyncTask<Long, Void, Void> {
|
||||
}
|
||||
} catch (TwitterException err) {
|
||||
this.err = err;
|
||||
failure = true;
|
||||
return false;
|
||||
} catch (Exception err) {
|
||||
if (err.getMessage() != null)
|
||||
Log.e("ProfileLoader", err.getMessage());
|
||||
failure = true;
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -233,19 +154,6 @@ public class ProfileLoader extends AsyncTask<Long, Void, Void> {
|
||||
protected void onProgressUpdate(Void... v) {
|
||||
if (ui.get() == null) return;
|
||||
|
||||
if (!tweets.isEmpty()) {
|
||||
SwipeRefreshLayout homeReload = ui.get().findViewById(R.id.hometweets);
|
||||
homeTl.setData(tweets);
|
||||
homeTl.notifyDataSetChanged();
|
||||
homeReload.setRefreshing(false);
|
||||
}
|
||||
if (!favors.isEmpty()) {
|
||||
SwipeRefreshLayout favReload = ui.get().findViewById(R.id.homefavorits);
|
||||
homeFav.setData(favors);
|
||||
homeFav.notifyDataSetChanged();
|
||||
favReload.setRefreshing(false);
|
||||
}
|
||||
|
||||
TextView txtUser = ui.get().findViewById(R.id.profile_username);
|
||||
TextView txtScrName = ui.get().findViewById(R.id.profile_screenname);
|
||||
TextView txtBio = ui.get().findViewById(R.id.bio);
|
||||
@ -341,49 +249,11 @@ public class ProfileLoader extends AsyncTask<Long, Void, Void> {
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(final Void v) {
|
||||
protected void onPostExecute(final Boolean success) {
|
||||
if (ui.get() == null) return;
|
||||
|
||||
if (failure) {
|
||||
SwipeRefreshLayout homeReload = ui.get().findViewById(R.id.hometweets);
|
||||
SwipeRefreshLayout favReload = ui.get().findViewById(R.id.homefavorits);
|
||||
if (homeReload.isRefreshing())
|
||||
homeReload.setRefreshing(false);
|
||||
if (favReload.isRefreshing())
|
||||
favReload.setRefreshing(false);
|
||||
|
||||
if (err != null) {
|
||||
boolean killActivity = ErrorHandler.printError(ui.get(), err);
|
||||
if (killActivity)
|
||||
ui.get().finish();
|
||||
}
|
||||
} else {
|
||||
if (success) {
|
||||
switch (mode) {
|
||||
case LDR_PROFILE:
|
||||
if (tweets.isEmpty()) {
|
||||
SwipeRefreshLayout homeReload = ui.get().findViewById(R.id.hometweets);
|
||||
homeReload.setRefreshing(false);
|
||||
}
|
||||
if (favors.isEmpty()) {
|
||||
SwipeRefreshLayout favReload = ui.get().findViewById(R.id.homefavorits);
|
||||
favReload.setRefreshing(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_TWEETS:
|
||||
if (tweets.isEmpty()) {
|
||||
SwipeRefreshLayout homeReload = ui.get().findViewById(R.id.hometweets);
|
||||
homeReload.setRefreshing(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_FAVORS:
|
||||
if (favors.isEmpty()) {
|
||||
SwipeRefreshLayout favReload = ui.get().findViewById(R.id.homefavorits);
|
||||
favReload.setRefreshing(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_FOLLOW:
|
||||
if (!user.isLocked())
|
||||
if (isFollowing)
|
||||
@ -410,31 +280,11 @@ public class ProfileLoader extends AsyncTask<Long, Void, Void> {
|
||||
ui.get().setConnection(isFollowing, isMuted, isBlocked, canDm, user.followRequested());
|
||||
ui.get().invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
if (ui.get() != null) {
|
||||
SwipeRefreshLayout homeReload, favReload;
|
||||
switch (mode) {
|
||||
case GET_TWEETS:
|
||||
homeReload = ui.get().findViewById(R.id.hometweets);
|
||||
homeReload.setRefreshing(false);
|
||||
break;
|
||||
|
||||
case GET_FAVORS:
|
||||
favReload = ui.get().findViewById(R.id.homefavorits);
|
||||
favReload.setRefreshing(false);
|
||||
break;
|
||||
|
||||
case LDR_PROFILE:
|
||||
homeReload = ui.get().findViewById(R.id.hometweets);
|
||||
favReload = ui.get().findViewById(R.id.homefavorits);
|
||||
homeReload.setRefreshing(false);
|
||||
favReload.setRefreshing(false);
|
||||
break;
|
||||
} else {
|
||||
if (err != null) {
|
||||
boolean killActivity = ErrorHandler.printError(ui.get(), err);
|
||||
if (killActivity)
|
||||
ui.get().finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,12 +48,23 @@ public class TweetListFragment extends Fragment implements OnRefreshListener, On
|
||||
private TweetAdapter adapter;
|
||||
private View root;
|
||||
|
||||
private long id;
|
||||
private int mode;
|
||||
private String search;
|
||||
private long id;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup parent, Bundle param) {
|
||||
super.onCreateView(inflater, parent, param);
|
||||
|
||||
Bundle b = getArguments();
|
||||
if(b != null && b.containsKey("mode")) {
|
||||
mode = b.getInt("mode");
|
||||
id = b.getLong("id", -1);
|
||||
search = b.getString("search", "");
|
||||
} else {
|
||||
throw new AssertionError("Bundle error!");
|
||||
}
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_list, parent, false);
|
||||
GlobalSettings settings = GlobalSettings.getInstance(getContext());
|
||||
|
||||
@ -67,7 +78,21 @@ public class TweetListFragment extends Fragment implements OnRefreshListener, On
|
||||
|
||||
RecyclerView list = v.findViewById(R.id.fragment_list);
|
||||
list.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
list.setHasFixedSize(true);
|
||||
|
||||
switch(mode) {
|
||||
default:
|
||||
case USER_TWEET:
|
||||
case USER_FAVOR:
|
||||
case TWEET_ANSR:
|
||||
list.setHasFixedSize(false);
|
||||
break;
|
||||
|
||||
case HOME:
|
||||
case MENT:
|
||||
case SEARCH:
|
||||
list.setHasFixedSize(true);
|
||||
break;
|
||||
}
|
||||
list.setAdapter(adapter);
|
||||
return v;
|
||||
}
|
||||
@ -76,12 +101,7 @@ public class TweetListFragment extends Fragment implements OnRefreshListener, On
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View v, Bundle param) {
|
||||
super.onViewCreated(v, param);
|
||||
Bundle b = getArguments();
|
||||
if(b != null) {
|
||||
mode = b.getInt("mode", -1);
|
||||
id = b.getLong("id", -1L);
|
||||
}
|
||||
root = v;
|
||||
root = v;
|
||||
}
|
||||
|
||||
|
||||
@ -150,22 +170,22 @@ public class TweetListFragment extends Fragment implements OnRefreshListener, On
|
||||
|
||||
case USER_TWEET:
|
||||
tweetTask = new TweetLoader(root, USR_TWEETS);
|
||||
tweetTask.execute();
|
||||
tweetTask.execute(id);
|
||||
break;
|
||||
|
||||
case USER_FAVOR:
|
||||
tweetTask = new TweetLoader(root, USR_FAVORS);
|
||||
tweetTask.execute();
|
||||
tweetTask.execute(id);
|
||||
break;
|
||||
|
||||
case TWEET_ANSR:
|
||||
tweetTask = new TweetLoader(root, TWEET_ANS);
|
||||
tweetTask.execute();
|
||||
tweetTask.execute(id);
|
||||
break;
|
||||
|
||||
case SEARCH:
|
||||
tweetTask = new TweetLoader(root, TWEET_SEARCH);
|
||||
tweetTask.execute();
|
||||
tweetTask.execute(search);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -180,7 +200,7 @@ public class TweetListFragment extends Fragment implements OnRefreshListener, On
|
||||
Tweet tweet = adapter.getData(pos);
|
||||
if (tweet.getEmbeddedTweet() != null)
|
||||
tweet = tweet.getEmbeddedTweet();
|
||||
Intent intent = new Intent(getContext(), TweetDetail.class);//,
|
||||
Intent intent = new Intent(getContext(), TweetDetail.class);
|
||||
intent.putExtra("tweetID", tweet.getId());
|
||||
intent.putExtra("username", tweet.getUser().getScreenname());
|
||||
startActivity(intent);
|
||||
|
@ -93,7 +93,6 @@ public class TweetLoader extends AsyncTask<Object, Void, Boolean> {
|
||||
publishProgress();
|
||||
break;
|
||||
|
||||
|
||||
case DB_TWEETS:
|
||||
tweets = db.getUserTweets((long)param[0]);
|
||||
if(!tweets.isEmpty())
|
||||
|
@ -3,36 +3,30 @@ package org.nuclearfog.twidda.window;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.design.widget.TabLayout.OnTabSelectedListener;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.AlertDialog.Builder;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
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.BuildConfig;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.adapter.OnItemClickListener;
|
||||
import org.nuclearfog.twidda.adapter.TweetAdapter;
|
||||
import org.nuclearfog.twidda.adapter.ProfileTabAdapter;
|
||||
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.backend.ProfileLoader.Mode.LDR_PROFILE;
|
||||
import static org.nuclearfog.twidda.window.TweetDetail.STAT_CHANGED;
|
||||
|
||||
/**
|
||||
@ -40,32 +34,32 @@ import static org.nuclearfog.twidda.window.TweetDetail.STAT_CHANGED;
|
||||
*
|
||||
* @see ProfileLoader
|
||||
*/
|
||||
public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
||||
OnTabChangeListener, OnItemClickListener, OnTagClickListener {
|
||||
public class UserProfile extends AppCompatActivity implements OnTagClickListener, OnTabSelectedListener {
|
||||
|
||||
private static final int TWEET = 1;
|
||||
|
||||
private ProfileLoader profileAsync;
|
||||
private GlobalSettings settings;
|
||||
private RecyclerView homeList, favoriteList;
|
||||
private TweetAdapter tweetAdapter, favAdapter;
|
||||
private SwipeRefreshLayout homeReload, favoriteReload;
|
||||
private View lastTab, tweetUnderline, favorUnderline;
|
||||
private TextView tweetCount, favorCount;
|
||||
private TabHost mTab;
|
||||
private NumberFormat formatter;
|
||||
private ViewPager pager;
|
||||
private View[] icons;
|
||||
|
||||
private boolean home, isFollowing, isBlocked, isMuted, canDm, requested;
|
||||
private String username;
|
||||
private long userId;
|
||||
private int tabIndex = 0;
|
||||
|
||||
private int tabIndex = 0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle b) {
|
||||
super.onCreate(b);
|
||||
setContentView(R.layout.page_profile);
|
||||
|
||||
TextView bioTxt = findViewById(R.id.bio);
|
||||
TextView lnkTxt = findViewById(R.id.links);
|
||||
View root = findViewById(R.id.user_view);
|
||||
TabLayout tab = findViewById(R.id.profile_tab);
|
||||
pager = findViewById(R.id.profile_pager);
|
||||
Toolbar tool = findViewById(R.id.profile_toolbar);
|
||||
|
||||
setSupportActionBar(tool);
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
@ -78,71 +72,40 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
||||
username = param.getString("username");
|
||||
}
|
||||
|
||||
TextView bioTxt = findViewById(R.id.bio);
|
||||
TextView lnkTxt = findViewById(R.id.links);
|
||||
View root = findViewById(R.id.user_view);
|
||||
homeList = findViewById(R.id.ht_list);
|
||||
homeReload = findViewById(R.id.hometweets);
|
||||
favoriteList = findViewById(R.id.hf_list);
|
||||
favoriteReload = findViewById(R.id.homefavorits);
|
||||
mTab = findViewById(R.id.profile_tab);
|
||||
|
||||
settings = GlobalSettings.getInstance(this);
|
||||
GlobalSettings 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());
|
||||
bioTxt.setMovementMethod(ScrollingMovementMethod.getInstance());
|
||||
lnkTxt.setMovementMethod(ScrollingMovementMethod.getInstance());
|
||||
bioTxt.setLinkTextColor(settings.getHighlightColor());
|
||||
lnkTxt.setLinkTextColor(settings.getHighlightColor());
|
||||
|
||||
icons = new View[2];
|
||||
LayoutInflater inflater = LayoutInflater.from(this);
|
||||
View tweetIndicator = inflater.inflate(R.layout.tab_tw, null);
|
||||
View favorIndicator = inflater.inflate(R.layout.tab_fa, null);
|
||||
tweetUnderline = tweetIndicator.findViewById(R.id.tweet_divider);
|
||||
favorUnderline = favorIndicator.findViewById(R.id.favor_divider);
|
||||
tweetCount = tweetIndicator.findViewById(R.id.profile_tweet_count);
|
||||
favorCount = favorIndicator.findViewById(R.id.profile_favor_count);
|
||||
homeReload.setProgressBackgroundColorSchemeColor(settings.getHighlightColor());
|
||||
favoriteReload.setProgressBackgroundColorSchemeColor(settings.getHighlightColor());
|
||||
icons[0] = inflater.inflate(R.layout.tab_tw, null);
|
||||
icons[1] = inflater.inflate(R.layout.tab_fa, null);
|
||||
|
||||
mTab.setup();
|
||||
TabHost.TabSpec tab1 = mTab.newTabSpec("tweets");
|
||||
tab1.setContent(R.id.hometweets);
|
||||
tab1.setIndicator(tweetIndicator);
|
||||
mTab.addTab(tab1);
|
||||
TabHost.TabSpec tab2 = mTab.newTabSpec("favors");
|
||||
tab2.setContent(R.id.homefavorits);
|
||||
tab2.setIndicator(favorIndicator);
|
||||
mTab.addTab(tab2);
|
||||
lastTab = mTab.getCurrentView();
|
||||
setIndicator();
|
||||
ProfileTabAdapter adapter = new ProfileTabAdapter(getSupportFragmentManager(), userId);
|
||||
pager.setOffscreenPageLimit(2);
|
||||
pager.setAdapter(adapter);
|
||||
tab.setupWithViewPager(pager);
|
||||
tab.addOnTabSelectedListener(this);
|
||||
|
||||
mTab.setOnTabChangedListener(this);
|
||||
homeReload.setOnRefreshListener(this);
|
||||
favoriteReload.setOnRefreshListener(this);
|
||||
for(int i = 0 ; i < icons.length ; i++) {
|
||||
TabLayout.Tab t = tab.getTabAt(i);
|
||||
if(t != null)
|
||||
t.setCustomView(icons[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
if (profileAsync == null) {
|
||||
tweetAdapter = new TweetAdapter(this);
|
||||
tweetAdapter.setColor(settings.getHighlightColor(), settings.getFontColor());
|
||||
tweetAdapter.toggleImage(settings.getImageLoad());
|
||||
homeList.setAdapter(tweetAdapter);
|
||||
|
||||
favAdapter = new TweetAdapter(this);
|
||||
favAdapter.setColor(settings.getHighlightColor(), settings.getFontColor());
|
||||
favAdapter.toggleImage(settings.getImageLoad());
|
||||
favoriteList.setAdapter(favAdapter);
|
||||
|
||||
profileAsync = new ProfileLoader(this, ProfileLoader.Mode.LDR_PROFILE);
|
||||
profileAsync.execute(userId, 0L);
|
||||
if(profileAsync == null) {
|
||||
profileAsync = new ProfileLoader(this, LDR_PROFILE);
|
||||
profileAsync.execute(userId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,9 +120,8 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int reqCode, int returnCode, Intent i) {
|
||||
if (reqCode == TWEET && returnCode == STAT_CHANGED) {
|
||||
if (reqCode == TWEET && returnCode == STAT_CHANGED)
|
||||
profileAsync = null;
|
||||
}
|
||||
super.onActivityResult(reqCode, returnCode, i);
|
||||
}
|
||||
|
||||
@ -292,56 +254,7 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
||||
if (tabIndex == 0) {
|
||||
super.onBackPressed();
|
||||
} else {
|
||||
mTab.setCurrentTab(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if (profileAsync != null && profileAsync.getStatus() == RUNNING)
|
||||
profileAsync.cancel(true);
|
||||
switch (tabIndex) {
|
||||
default:
|
||||
case 0:
|
||||
profileAsync = new ProfileLoader(this, ProfileLoader.Mode.GET_TWEETS);
|
||||
break;
|
||||
case 1:
|
||||
profileAsync = new ProfileLoader(this, ProfileLoader.Mode.GET_FAVORS);
|
||||
break;
|
||||
}
|
||||
profileAsync.execute(userId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onTabChanged(String tabId) {
|
||||
animate();
|
||||
tabIndex = mTab.getCurrentTab();
|
||||
setIndicator();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onItemClick(RecyclerView parent, int position) {
|
||||
switch (parent.getId()) {
|
||||
case R.id.ht_list:
|
||||
if (!homeReload.isRefreshing()) {
|
||||
Tweet tweet = tweetAdapter.getData(position);
|
||||
if (tweet.getEmbeddedTweet() != null)
|
||||
tweet = tweet.getEmbeddedTweet();
|
||||
openTweet(tweet.getId(), tweet.getUser().getScreenname());
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.hf_list:
|
||||
if (!favoriteReload.isRefreshing()) {
|
||||
Tweet tweet = favAdapter.getData(position);
|
||||
if (tweet.getEmbeddedTweet() != null)
|
||||
tweet = tweet.getEmbeddedTweet();
|
||||
openTweet(tweet.getId(), tweet.getUser().getScreenname());
|
||||
}
|
||||
break;
|
||||
pager.setCurrentItem(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -354,8 +267,25 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
tabIndex = tab.getPosition();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) { }
|
||||
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) { }
|
||||
|
||||
|
||||
public void setTweetCount(int tweets, int favors) {
|
||||
NumberFormat formatter = NumberFormat.getIntegerInstance();
|
||||
TextView tweetCount = icons[0].findViewById(R.id.profile_tweet_count);
|
||||
tweetCount.setText(formatter.format(tweets));
|
||||
TextView favorCount = icons[1].findViewById(R.id.profile_favor_count);
|
||||
favorCount.setText(formatter.format(favors));
|
||||
}
|
||||
|
||||
@ -367,57 +297,4 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
|
||||
this.canDm = canDm;
|
||||
this.requested = requested;
|
||||
}
|
||||
|
||||
|
||||
private void openTweet(long tweetId, String username) {
|
||||
Intent intent = new Intent(this, TweetDetail.class);
|
||||
intent.putExtra("tweetID", tweetId);
|
||||
intent.putExtra("username", username);
|
||||
startActivityForResult(intent, TWEET);
|
||||
}
|
||||
|
||||
|
||||
private void setIndicator() {
|
||||
switch (tabIndex) {
|
||||
case 0:
|
||||
tweetUnderline.setBackgroundColor(settings.getHighlightColor());
|
||||
favorUnderline.setBackgroundColor(0);
|
||||
favoriteList.smoothScrollToPosition(0);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
favorUnderline.setBackgroundColor(settings.getHighlightColor());
|
||||
tweetUnderline.setBackgroundColor(0);
|
||||
homeList.smoothScrollToPosition(0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void animate() {
|
||||
final int ANIM_DUR = 300;
|
||||
final float LEFT = -1.0f;
|
||||
final float RIGHT = 1.0f;
|
||||
final float NULL = 0.0f;
|
||||
final int DIMENS = Animation.RELATIVE_TO_PARENT;
|
||||
|
||||
View currentTab = mTab.getCurrentView();
|
||||
if (mTab.getCurrentTab() > tabIndex) {
|
||||
Animation lOut = new TranslateAnimation(DIMENS, NULL, DIMENS, LEFT, DIMENS, NULL, DIMENS, NULL);
|
||||
Animation rIn = new TranslateAnimation(DIMENS, RIGHT, DIMENS, NULL, DIMENS, NULL, DIMENS, NULL);
|
||||
lOut.setDuration(ANIM_DUR);
|
||||
rIn.setDuration(ANIM_DUR);
|
||||
lastTab.setAnimation(lOut);
|
||||
currentTab.setAnimation(rIn);
|
||||
} else {
|
||||
Animation lIn = new TranslateAnimation(DIMENS, LEFT, DIMENS, NULL, DIMENS, NULL, DIMENS, NULL);
|
||||
Animation rOut = new TranslateAnimation(DIMENS, NULL, DIMENS, RIGHT, DIMENS, NULL, DIMENS, NULL);
|
||||
lIn.setDuration(ANIM_DUR);
|
||||
rOut.setDuration(ANIM_DUR);
|
||||
lastTab.setAnimation(rOut);
|
||||
currentTab.setAnimation(lIn);
|
||||
}
|
||||
lastTab = mTab.getCurrentView();
|
||||
}
|
||||
}
|
@ -15,29 +15,7 @@
|
||||
android:id="@+id/home_tab"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:tabTextAppearance="@style/CustomTextAppearance">
|
||||
|
||||
<android.support.design.widget.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:icon="@drawable/home"
|
||||
android:layout="@layout/tab_home" />
|
||||
|
||||
<android.support.design.widget.TabItem
|
||||
android:id="@+id/tab_trend"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:icon="@drawable/hash"
|
||||
android:layout="@layout/tab_home" />
|
||||
|
||||
<android.support.design.widget.TabItem
|
||||
android:id="@+id/tab_mention"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:icon="@drawable/mention"
|
||||
android:layout="@layout/tab_home" />
|
||||
|
||||
</android.support.design.widget.TabLayout>
|
||||
app:tabTextAppearance="@style/CustomTextAppearance"/>
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/home_pager"
|
||||
|
@ -260,55 +260,22 @@
|
||||
android:fillViewport="true"
|
||||
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
|
||||
|
||||
<TabHost
|
||||
android:id="@+id/profile_tab"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/profile_tab"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TabWidget
|
||||
android:id="@android:id/tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/profile_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@android:id/tabcontent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/hometweets"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/ht_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/homefavorits"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/hf_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</TabHost>
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user