Optimizations
changed to RecyclerView
This commit is contained in:
NudeDude 2018-03-05 23:22:19 +01:00
parent ec4bf33323
commit 902d89af5f
25 changed files with 622 additions and 520 deletions

View File

@ -5,10 +5,10 @@ android {
compileSdkVersion 27 compileSdkVersion 27
defaultConfig { defaultConfig {
applicationId "org.nuclearfog.twidda" applicationId "org.nuclearfog.twidda"
minSdkVersion 21 minSdkVersion 14
targetSdkVersion 21 targetSdkVersion 14
versionCode 1 versionCode 1
versionName '1.1' versionName '1.2'
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
} }
buildTypes { buildTypes {

View File

@ -6,13 +6,14 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity; 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.support.v7.widget.Toolbar;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TabHost; import android.widget.TabHost;
import android.widget.TabHost.TabSpec; import android.widget.TabHost.TabSpec;
@ -20,8 +21,9 @@ import org.nuclearfog.twidda.database.TrendDatabase;
import org.nuclearfog.twidda.database.TweetDatabase; import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.backend.Registration; import org.nuclearfog.twidda.backend.Registration;
import org.nuclearfog.twidda.backend.MainPage; import org.nuclearfog.twidda.backend.MainPage;
import org.nuclearfog.twidda.viewadapter.TimelineAdapter; import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.viewadapter.TrendAdapter; import org.nuclearfog.twidda.viewadapter.TrendRecycler;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.window.LoginPage; import org.nuclearfog.twidda.window.LoginPage;
import org.nuclearfog.twidda.window.SearchPage; import org.nuclearfog.twidda.window.SearchPage;
import org.nuclearfog.twidda.window.UserProfile; import org.nuclearfog.twidda.window.UserProfile;
@ -34,11 +36,12 @@ import org.nuclearfog.twidda.window.TweetPopup;
* @see Registration Registing App in Twitter * @see Registration Registing App in Twitter
* @see MainPage show Home Window * @see MainPage show Home Window
*/ */
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, public class MainActivity extends AppCompatActivity implements
SwipeRefreshLayout.OnRefreshListener, TabHost.OnTabChangeListener SwipeRefreshLayout.OnRefreshListener, TabHost.OnTabChangeListener,
TimelineRecycler.OnItemClicked, TrendRecycler.OnItemClicked
{ {
private SwipeRefreshLayout timelineReload,trendReload,mentionReload; private SwipeRefreshLayout timelineReload,trendReload,mentionReload;
private ListView timelineList, trendList,mentionList; private RecyclerView timelineList, trendList,mentionList;
private MenuItem profile, tweet, search, setting; private MenuItem profile, tweet, search, setting;
private SharedPreferences settings; private SharedPreferences settings;
private SearchView searchQuery; private SearchView searchQuery;
@ -47,6 +50,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
private TabHost tabhost; private TabHost tabhost;
private boolean settingFlag = false; private boolean settingFlag = false;
private String currentTab = "timeline"; private String currentTab = "timeline";
private int background, font_color;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -132,6 +136,9 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
protected void onResume(){ protected void onResume(){
super.onResume(); super.onResume();
if(settingFlag) { if(settingFlag) {
timelineList.setAdapter(null);
trendList.setAdapter(null);
mentionList.setAdapter(null);
setTabContent(); setTabContent();
settingFlag = false; settingFlag = false;
} }
@ -161,57 +168,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
} }
} }
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(parent.getId()) {
case R.id.tl_list:
if(!timelineReload.isRefreshing()) {
TimelineAdapter tlAdp = (TimelineAdapter) timelineList.getAdapter();
TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
String username = twDB.getScreenname(position);
Intent intent = new Intent(con, TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
bundle.putString("username",username);
intent.putExtras(bundle);
startActivity(intent);
}
break;
case R.id.tr_list:
if(!trendReload.isRefreshing()) {
TrendAdapter trend = (TrendAdapter) trendList.getAdapter();
String search = trend.getDatabase().getTrendname(position);
Intent intent = new Intent(con, SearchPage.class);
Bundle bundle = new Bundle();
bundle.putString("search", search);
if(search.startsWith("#")) {
bundle.putString("Addition", search);
}
intent.putExtras(bundle);
startActivity(intent);
}
break;
case R.id.m_list:
if(!mentionReload.isRefreshing()) {
TimelineAdapter tlAdp = (TimelineAdapter) mentionList.getAdapter();
TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
String username = twDB.getScreenname(position);
Intent intent = new Intent(con, TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
bundle.putString("username",username);
intent.putExtras(bundle);
startActivity(intent);
}
break;
}
}
@Override @Override
public void onRefresh() { public void onRefresh() {
@ -260,23 +217,79 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
} }
} }
@Override
public void onItemClick(View v, ViewGroup parent, int position) {
switch(parent.getId()) {
case R.id.tl_list:
if(!timelineReload.isRefreshing()) {
TimelineRecycler tlAdp = (TimelineRecycler) timelineList.getAdapter();
TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
String username = twDB.getScreenname(position);
Intent intent = new Intent(con, TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
bundle.putString("username",username);
intent.putExtras(bundle);
startActivity(intent);
}
break;
case R.id.tr_list:
if(!trendReload.isRefreshing()) {
TrendRecycler trend = (TrendRecycler) trendList.getAdapter();
String search = trend.getData().getTrendname(position);
Intent intent = new Intent(con, SearchPage.class);
Bundle bundle = new Bundle();
bundle.putString("search", search);
if(search.startsWith("#")) {
bundle.putString("Addition", search);
}
intent.putExtras(bundle);
startActivity(intent);
}
break;
case R.id.m_list:
if(!mentionReload.isRefreshing()) {
TimelineRecycler tlAdp = (TimelineRecycler) mentionList.getAdapter();
TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
String username = twDB.getScreenname(position);
Intent intent = new Intent(con, TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
bundle.putString("username",username);
intent.putExtras(bundle);
startActivity(intent);
}
break;
}
}
/** /**
* Login Handle * Login Handle
*/ */
private void login() { private void login() {
timelineList = (ListView) findViewById(R.id.tl_list); timelineList = (RecyclerView) findViewById(R.id.tl_list);
trendList = (ListView) findViewById(R.id.tr_list); trendList = (RecyclerView) findViewById(R.id.tr_list);
mentionList = (ListView) findViewById(R.id.m_list); mentionList = (RecyclerView) findViewById(R.id.m_list);
timelineReload = (SwipeRefreshLayout) findViewById(R.id.timeline); timelineReload = (SwipeRefreshLayout) findViewById(R.id.timeline);
trendReload = (SwipeRefreshLayout) findViewById(R.id.trends); trendReload = (SwipeRefreshLayout) findViewById(R.id.trends);
mentionReload = (SwipeRefreshLayout) findViewById(R.id.mention); mentionReload = (SwipeRefreshLayout) findViewById(R.id.mention);
tabhost = (TabHost)findViewById(R.id.main_tabhost); tabhost = (TabHost)findViewById(R.id.main_tabhost);
toolbar = (Toolbar) findViewById(R.id.profile_toolbar); toolbar = (Toolbar) findViewById(R.id.profile_toolbar);
timelineList.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
trendList.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
mentionList.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
timelineList.setHasFixedSize(true);
trendList.setHasFixedSize(true);
mentionList.setHasFixedSize(true);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
if(getSupportActionBar() != null) if(getSupportActionBar() != null)
getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false);
tabhost.setup(); tabhost.setup();
// Tab #1 // Tab #1
TabSpec tab1 = tabhost.newTabSpec("timeline"); TabSpec tab1 = tabhost.newTabSpec("timeline");
@ -295,9 +308,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
tabhost.addTab(tab3); tabhost.addTab(tab3);
tabhost.setOnTabChangedListener(this); tabhost.setOnTabChangedListener(this);
timelineList.setOnItemClickListener(this);
trendList.setOnItemClickListener(this);
mentionList.setOnItemClickListener(this);
timelineReload.setOnRefreshListener(this); timelineReload.setOnRefreshListener(this);
trendReload.setOnRefreshListener(this); trendReload.setOnRefreshListener(this);
mentionReload.setOnRefreshListener(this); mentionReload.setOnRefreshListener(this);
@ -312,15 +322,30 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
ColorPreferences mColor = ColorPreferences.getInstance(con);
background = mColor.getColor(ColorPreferences.BACKGROUND);
font_color = mColor.getColor(ColorPreferences.FONT_COLOR);
TimelineRecycler rlRc = (TimelineRecycler) timelineList.getAdapter();
TrendRecycler trendRc = (TrendRecycler) trendList.getAdapter();
TimelineRecycler mentRc = (TimelineRecycler) mentionList.getAdapter();
if(rlRc == null || rlRc.getItemCount() == 0) {
TweetDatabase tweetDeck = new TweetDatabase(con,TweetDatabase.HOME_TL, 0L); TweetDatabase tweetDeck = new TweetDatabase(con,TweetDatabase.HOME_TL, 0L);
TrendDatabase trendDeck = new TrendDatabase(con); rlRc = new TimelineRecycler(tweetDeck, MainActivity.this);
} if(mentRc == null || mentRc.getItemCount() == 0) {
TweetDatabase mentDeck = new TweetDatabase(con, TweetDatabase.GET_MENT, 0L); TweetDatabase mentDeck = new TweetDatabase(con, TweetDatabase.GET_MENT, 0L);
TimelineAdapter tlAdap = new TimelineAdapter(con,tweetDeck); mentRc = new TimelineRecycler(mentDeck, MainActivity.this);
TrendAdapter trendAdp = new TrendAdapter(con,trendDeck); } if(trendRc == null || trendRc.getItemCount() == 0) {
TimelineAdapter mentAdp = new TimelineAdapter(con, mentDeck); TrendDatabase trendDeck = new TrendDatabase(con);
timelineList.setAdapter(tlAdap); trendRc = new TrendRecycler(trendDeck, MainActivity.this);
trendList.setAdapter(trendAdp); }
mentionList.setAdapter(mentAdp); rlRc.setColor(background,font_color);
trendRc.setColor(background,font_color);
mentRc.setColor(background,font_color);
timelineList.setAdapter(rlRc);
trendList.setAdapter(trendRc);
mentionList.setAdapter(mentRc);
} }
}).run(); }).run();
} }

View File

@ -4,12 +4,12 @@ import org.nuclearfog.twidda.database.TrendDatabase;
import org.nuclearfog.twidda.database.TweetDatabase; import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.MainActivity; import org.nuclearfog.twidda.MainActivity;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.TimelineAdapter; import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.viewadapter.TrendAdapter; import org.nuclearfog.twidda.viewadapter.TrendRecycler;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ListView; import android.support.v7.widget.RecyclerView;
import android.widget.Toast; import android.widget.Toast;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -25,9 +25,9 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private Context context; private Context context;
private SwipeRefreshLayout timelineRefresh, trendRefresh, mentionRefresh; private SwipeRefreshLayout timelineRefresh, trendRefresh, mentionRefresh;
private ListView timelineList, trendList, mentionList; private RecyclerView timelineList, trendList, mentionList;
private TimelineAdapter timelineAdapter, mentionAdapter; private TimelineRecycler timelineAdapter, mentionAdapter;
private TrendAdapter trendsAdapter; private TrendRecycler trendsAdapter;
private int woeid; private int woeid;
/** /**
@ -45,13 +45,13 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
protected void onPreExecute() { protected void onPreExecute() {
// Timeline Tab // Timeline Tab
timelineRefresh = (SwipeRefreshLayout)((MainActivity)context).findViewById(R.id.timeline); timelineRefresh = (SwipeRefreshLayout)((MainActivity)context).findViewById(R.id.timeline);
timelineList = (ListView)((MainActivity)context).findViewById(R.id.tl_list); timelineList = (RecyclerView)((MainActivity)context).findViewById(R.id.tl_list);
// Trend Tab // Trend Tab
trendRefresh = (SwipeRefreshLayout)((MainActivity)context).findViewById(R.id.trends); trendRefresh = (SwipeRefreshLayout)((MainActivity)context).findViewById(R.id.trends);
trendList = (ListView)((MainActivity)context).findViewById(R.id.tr_list); trendList = (RecyclerView)((MainActivity)context).findViewById(R.id.tr_list);
// Mention Tab // Mention Tab
mentionRefresh = (SwipeRefreshLayout)((MainActivity)context).findViewById(R.id.mention); mentionRefresh = (SwipeRefreshLayout)((MainActivity)context).findViewById(R.id.mention);
mentionList = (ListView)((MainActivity)context).findViewById(R.id.m_list); mentionList = (RecyclerView)((MainActivity)context).findViewById(R.id.m_list);
} }
/** /**
@ -66,28 +66,28 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
try { try {
switch (MODE) { switch (MODE) {
case HOME: case HOME:
timelineAdapter = (TimelineAdapter) timelineList.getAdapter(); timelineAdapter = (TimelineRecycler) timelineList.getAdapter();
if(timelineAdapter != null && timelineAdapter.getCount() != 0) { if(timelineAdapter != null && timelineAdapter.getItemCount() != 0) {
id = timelineAdapter.getItemId(0); id = timelineAdapter.getItemId(0);
timelineAdapter.getData().insert(mTwitter.getHome(page,id),true); timelineAdapter.getData().insert(mTwitter.getHome(page,id),true);
} else { } else {
TweetDatabase mTweets = new TweetDatabase(mTwitter.getHome(page,id), context,TweetDatabase.HOME_TL,0); TweetDatabase mTweets = new TweetDatabase(mTwitter.getHome(page,id), context,TweetDatabase.HOME_TL,0);
timelineAdapter = new TimelineAdapter(context,mTweets); timelineAdapter = new TimelineRecycler(mTweets,(MainActivity)context);
} }
break; break;
case TRND: case TRND:
trendsAdapter = new TrendAdapter(context, new TrendDatabase(mTwitter.getTrends(woeid),context)); trendsAdapter = new TrendRecycler(new TrendDatabase(mTwitter.getTrends(woeid),context),(MainActivity)context);
break; break;
case MENT: case MENT:
mentionAdapter = (TimelineAdapter) mentionList.getAdapter(); mentionAdapter = (TimelineRecycler) mentionList.getAdapter();
if(mentionAdapter != null && mentionAdapter.getCount() != 0) { if(mentionAdapter != null && mentionAdapter.getItemCount() != 0) {
id = mentionAdapter.getItemId(0); id = mentionAdapter.getItemId(0);
mentionAdapter.getData().insert(mTwitter.getMention(page,id),true); mentionAdapter.getData().insert(mTwitter.getMention(page,id),true);
} else { } else {
TweetDatabase mention = new TweetDatabase(mTwitter.getMention(page,id), context,TweetDatabase.GET_MENT,0); TweetDatabase mention = new TweetDatabase(mTwitter.getMention(page,id), context,TweetDatabase.GET_MENT,0);
mentionAdapter = new TimelineAdapter(context,mention); mentionAdapter = new TimelineRecycler(mention,(MainActivity)context);
} }
break; break;
} }
@ -103,7 +103,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
switch(MODE) { switch(MODE) {
case HOME: case HOME:
timelineRefresh.setRefreshing(false); timelineRefresh.setRefreshing(false);
if(timelineList.getAdapter().getCount() == 0) { if(timelineList.getAdapter().getItemCount() == 0) {
timelineList.setAdapter(timelineAdapter); timelineList.setAdapter(timelineAdapter);
} else { } else {
timelineAdapter.notifyDataSetChanged(); timelineAdapter.notifyDataSetChanged();
@ -117,7 +117,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
case MENT: case MENT:
mentionRefresh.setRefreshing(false); mentionRefresh.setRefreshing(false);
if(mentionList.getAdapter().getCount() == 0) { if(mentionList.getAdapter().getItemCount() == 0) {
mentionList.setAdapter(mentionAdapter); mentionList.setAdapter(mentionAdapter);
} else { } else {
mentionAdapter.notifyDataSetChanged(); mentionAdapter.notifyDataSetChanged();

View File

@ -4,22 +4,21 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.TweetDatabase; import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.viewadapter.TimelineAdapter; import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.window.UserProfile; import org.nuclearfog.twidda.window.UserProfile;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import twitter4j.User; import twitter4j.User;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
public class ProfileLoader extends AsyncTask<Long,Void,Long> { public class ProfileLoader extends AsyncTask<Long,Void,Long> {
@ -35,9 +34,9 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
private TextView txtUser,txtScrName,txtBio,txtLocation,txtLink,txtFollowing,txtFollower,txtCreated; private TextView txtUser,txtScrName,txtBio,txtLocation,txtLink,txtFollowing,txtFollower,txtCreated;
private ImageView profile, banner, linkIcon, locationIcon, verifier, locked, followback; private ImageView profile, banner, linkIcon, locationIcon, verifier, locked, followback;
private SwipeRefreshLayout tweetsReload, favoritsReload; private SwipeRefreshLayout tweetsReload, favoritsReload;
private ListView profileTweets, profileFavorits; private RecyclerView profileTweets, profileFavorits;
private String imageLink, bannerLink, fullPbLink, link, dateString; private String imageLink, bannerLink, fullPbLink, link, dateString;
private TimelineAdapter homeTl, homeFav; private TimelineRecycler homeTl, homeFav;
private Context context; private Context context;
private Toolbar tool; private Toolbar tool;
private boolean isHome = false; private boolean isHome = false;
@ -77,8 +76,8 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
locationIcon = (ImageView)((UserProfile)context).findViewById(R.id.location_img); locationIcon = (ImageView)((UserProfile)context).findViewById(R.id.location_img);
tweetsReload = (SwipeRefreshLayout)((UserProfile)context).findViewById(R.id.hometweets); tweetsReload = (SwipeRefreshLayout)((UserProfile)context).findViewById(R.id.hometweets);
favoritsReload = (SwipeRefreshLayout)((UserProfile)context).findViewById(R.id.homefavorits); favoritsReload = (SwipeRefreshLayout)((UserProfile)context).findViewById(R.id.homefavorits);
profileTweets = (ListView)((UserProfile)context).findViewById(R.id.ht_list); profileTweets = (RecyclerView)((UserProfile)context).findViewById(R.id.ht_list);
profileFavorits = (ListView)((UserProfile)context).findViewById(R.id.hf_list); profileFavorits = (RecyclerView)((UserProfile)context).findViewById(R.id.hf_list);
tool = (Toolbar) ((UserProfile)context).findViewById(R.id.profile_toolbar); tool = (Toolbar) ((UserProfile)context).findViewById(R.id.profile_toolbar);
} }
@ -116,10 +115,10 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
} }
else if(MODE == GET_TWEETS) else if(MODE == GET_TWEETS)
{ {
homeTl = (TimelineAdapter) profileTweets.getAdapter(); homeTl = (TimelineRecycler) profileTweets.getAdapter();
if(homeTl == null || homeTl.getCount() == 0) { if(homeTl == null || homeTl.getItemCount() == 0) {
TweetDatabase hTweets = new TweetDatabase(mTwitter.getUserTweets(userId,args[2],id),context,TweetDatabase.USER_TL,userId); TweetDatabase hTweets = new TweetDatabase(mTwitter.getUserTweets(userId,args[2],id),context,TweetDatabase.USER_TL,userId);
homeTl = new TimelineAdapter(context,hTweets); homeTl = new TimelineRecycler(hTweets,(UserProfile)context);
} else { } else {
id = homeTl.getItemId(0); id = homeTl.getItemId(0);
homeTl.getData().insert(mTwitter.getUserTweets(userId,args[2],id),true); homeTl.getData().insert(mTwitter.getUserTweets(userId,args[2],id),true);
@ -127,13 +126,13 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
} }
else if(MODE == GET_FAVS) else if(MODE == GET_FAVS)
{ {
homeFav = (TimelineAdapter) profileFavorits.getAdapter(); homeFav = (TimelineRecycler) profileFavorits.getAdapter();
if(homeFav != null) { if(homeFav != null) {
id = homeFav.getItemId(0); id = homeFav.getItemId(0);
homeFav.getData().insert(mTwitter.getUserFavs(userId,args[2],id),true); homeFav.getData().insert(mTwitter.getUserFavs(userId,args[2],id),true);
} else { } else {
TweetDatabase fTweets = new TweetDatabase(mTwitter.getUserFavs(userId,args[2],id),context,TweetDatabase.FAV_TL,userId); TweetDatabase fTweets = new TweetDatabase(mTwitter.getUserFavs(userId,args[2],id),context,TweetDatabase.FAV_TL,userId);
homeFav = new TimelineAdapter(context,fTweets); homeFav = new TimelineRecycler(fTweets,(UserProfile)context);
} }
} }
else if(MODE == ACTION_FOLLOW) else if(MODE == ACTION_FOLLOW)

View File

@ -5,17 +5,15 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -31,10 +29,9 @@ import twitter4j.User;
import org.nuclearfog.twidda.database.TweetDatabase; import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.TimelineAdapter; import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.window.ColorPreferences; import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.window.TweetDetail; import org.nuclearfog.twidda.window.TweetDetail;
import org.nuclearfog.twidda.window.UserProfile;
public class StatusLoader extends AsyncTask<Long, Void, Long> { public class StatusLoader extends AsyncTask<Long, Void, Long> {
@ -48,8 +45,8 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
private Context c; private Context c;
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private List<twitter4j.Status> answers; private List<twitter4j.Status> answers;
private TimelineAdapter tlAdp; private TimelineRecycler tlAdp;
private ListView replyList; private RecyclerView replyList;
private TextView username,scrName,replyName,tweet,userRetweet; private TextView username,scrName,replyName,tweet,userRetweet;
private TextView used_api,txtAns,txtRet,txtFav,date; private TextView used_api,txtAns,txtRet,txtFav,date;
private ImageView profile_img,tweet_verify; private ImageView profile_img,tweet_verify;
@ -79,7 +76,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
replyList = (ListView) ((TweetDetail)c).findViewById(R.id.answer_list); replyList = (RecyclerView) ((TweetDetail)c).findViewById(R.id.answer_list);
tweet = (TextView) ((TweetDetail)c).findViewById(R.id.tweet_detailed); tweet = (TextView) ((TweetDetail)c).findViewById(R.id.tweet_detailed);
username = (TextView) ((TweetDetail)c).findViewById(R.id.usernamedetail); username = (TextView) ((TweetDetail)c).findViewById(R.id.usernamedetail);
scrName = (TextView) ((TweetDetail)c).findViewById(R.id.scrnamedetail); scrName = (TextView) ((TweetDetail)c).findViewById(R.id.scrnamedetail);
@ -173,7 +170,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
} }
else if(mode == LOAD_REPLY) { else if(mode == LOAD_REPLY) {
String replyname = user.getScreenName(); String replyname = user.getScreenName();
tlAdp = (TimelineAdapter) replyList.getAdapter(); tlAdp = (TimelineRecycler) replyList.getAdapter();
if(tlAdp != null) if(tlAdp != null)
tweetID = tlAdp.getItemId(0); tweetID = tlAdp.getItemId(0);
answers = mTwitter.getAnswers(replyname, tweetID); answers = mTwitter.getAnswers(replyname, tweetID);
@ -256,9 +253,9 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
setIcons(); setIcons();
} }
else if(mode == LOAD_REPLY) { else if(mode == LOAD_REPLY) {
if(tlAdp == null || tlAdp.getCount() == 0) { if(tlAdp == null || tlAdp.getItemCount() == 0) {
TweetDatabase tweetDatabase = new TweetDatabase(answers,c); TweetDatabase tweetDatabase = new TweetDatabase(answers,c);
tlAdp = new TimelineAdapter(c, tweetDatabase); tlAdp = new TimelineRecycler(tweetDatabase,(TweetDetail)c);
replyList.setAdapter(tlAdp); replyList.setAdapter(tlAdp);
} else { } else {
TweetDatabase twDb = tlAdp.getData(); TweetDatabase twDb = tlAdp.getData();
@ -266,7 +263,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
tlAdp.notifyDataSetChanged(); tlAdp.notifyDataSetChanged();
ansReload.setRefreshing(false); ansReload.setRefreshing(false);
} }
String ansStr = Integer.toString(tlAdp.getCount()); String ansStr = Integer.toString(tlAdp.getItemCount());
txtAns.setText(ansStr); txtAns.setText(ansStr);
} }
else if(mode == DELETE) { else if(mode == DELETE) {

View File

@ -3,35 +3,40 @@ package org.nuclearfog.twidda.backend;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import org.nuclearfog.twidda.database.TweetDatabase; import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.UserDatabase; import org.nuclearfog.twidda.database.UserDatabase;
import org.nuclearfog.twidda.viewadapter.TimelineAdapter; import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.viewadapter.UserAdapter; import org.nuclearfog.twidda.viewadapter.UserRecycler;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.window.SearchPage; import org.nuclearfog.twidda.window.SearchPage;
public class TwitterSearch extends AsyncTask<String, Void, Void> { public class TwitterSearch extends AsyncTask<String, Void, Void> {
private TimelineAdapter tlAdp; private TimelineRecycler tlRc;
private UserAdapter uAdp; private UserRecycler uAdp;
private SwipeRefreshLayout tweetReload; private SwipeRefreshLayout tweetReload;
private ListView tweetSearch, userSearch; private RecyclerView tweetSearch, userSearch;
private ProgressBar circleLoad; private ProgressBar circleLoad;
private Context context; private Context context;
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private int background, font_color;
public TwitterSearch(Context context) { public TwitterSearch(Context context) {
this.context=context; this.context=context;
ColorPreferences mcolor = ColorPreferences.getInstance(context);
background = mcolor.getColor(ColorPreferences.BACKGROUND);
font_color = mcolor.getColor(ColorPreferences.FONT_COLOR);
} }
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
tweetSearch = (ListView) ((SearchPage)context).findViewById(R.id.tweet_result); tweetSearch = (RecyclerView) ((SearchPage)context).findViewById(R.id.tweet_result);
userSearch = (ListView) ((SearchPage)context).findViewById(R.id.user_result); userSearch = (RecyclerView) ((SearchPage)context).findViewById(R.id.user_result);
tweetReload = (SwipeRefreshLayout) ((SearchPage)context).findViewById(R.id.searchtweets); tweetReload = (SwipeRefreshLayout) ((SearchPage)context).findViewById(R.id.searchtweets);
circleLoad = (ProgressBar) ((SearchPage)context).findViewById(R.id.search_progress); circleLoad = (ProgressBar) ((SearchPage)context).findViewById(R.id.search_progress);
mTwitter = TwitterEngine.getInstance(context); mTwitter = TwitterEngine.getInstance(context);
@ -42,14 +47,15 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
String get = search[0]; String get = search[0];
long id = 1L; long id = 1L;
try { try {
tlAdp = (TimelineAdapter) tweetSearch.getAdapter(); tlRc = (TimelineRecycler) tweetSearch.getAdapter();
if(tlAdp != null) { if(tlRc != null) {
id = tlAdp.getItemId(0); id = tlRc.getItemId(0);
tlAdp.getData().insert(mTwitter.searchTweets(get,id),false); tlRc.getData().insert(mTwitter.searchTweets(get,id),false);
} else { } else {
tlAdp = new TimelineAdapter(context, new TweetDatabase(mTwitter.searchTweets(get,id),context)); tlRc = new TimelineRecycler(new TweetDatabase(mTwitter.searchTweets(get,id),context),((SearchPage)context));
tlRc.setColor(background,font_color);
} }
uAdp = new UserAdapter(context, new UserDatabase(context, mTwitter.searchUsers(get))); uAdp = new UserRecycler(new UserDatabase(context, mTwitter.searchUsers(get)),((SearchPage)context));
} catch(Exception err){err.printStackTrace();} } catch(Exception err){err.printStackTrace();}
return null; return null;
} }
@ -58,9 +64,9 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
circleLoad.setVisibility(View.INVISIBLE); circleLoad.setVisibility(View.INVISIBLE);
if(tweetSearch.getAdapter() == null) if(tweetSearch.getAdapter() == null)
tweetSearch.setAdapter(tlAdp); tweetSearch.setAdapter(tlRc);
else else
tlAdp.notifyDataSetChanged(); tlRc.notifyDataSetChanged();
userSearch.setAdapter(uAdp); userSearch.setAdapter(uAdp);
tweetReload.setRefreshing(false); tweetReload.setRefreshing(false);
} }

View File

@ -2,14 +2,14 @@ package org.nuclearfog.twidda.backend;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Toast; import android.widget.Toast;
import org.nuclearfog.twidda.database.UserDatabase; import org.nuclearfog.twidda.database.UserDatabase;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.UserAdapter; import org.nuclearfog.twidda.viewadapter.UserRecycler;
import org.nuclearfog.twidda.window.UserDetail; import org.nuclearfog.twidda.window.UserDetail;
public class UserLists extends AsyncTask <Long, Void, Void> { public class UserLists extends AsyncTask <Long, Void, Void> {
@ -21,8 +21,8 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
private Context context; private Context context;
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private UserAdapter usrAdp; private UserRecycler usrAdp;
private ListView userList; private RecyclerView userList;
private ProgressBar uProgress; private ProgressBar uProgress;
private String errmsg; private String errmsg;
@ -36,7 +36,7 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
mTwitter = TwitterEngine.getInstance(context); mTwitter = TwitterEngine.getInstance(context);
userList = (ListView)((UserDetail)context).findViewById(R.id.userlist); userList = (RecyclerView) ((UserDetail)context).findViewById(R.id.userlist);
uProgress = (ProgressBar)((UserDetail)context).findViewById(R.id.user_progress); uProgress = (ProgressBar)((UserDetail)context).findViewById(R.id.user_progress);
} }
@ -46,10 +46,11 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
long mode = data[1]; long mode = data[1];
long cursor = data[2]; long cursor = data[2];
try { try {
usrAdp = (UserAdapter) userList.getAdapter(); usrAdp = (UserRecycler) userList.getAdapter();
if(mode == FOLLOWING) { if(mode == FOLLOWING) {
if(usrAdp == null) { if(usrAdp == null) {
usrAdp = new UserAdapter(context,new UserDatabase(context,mTwitter.getFollowing(id,cursor))); UserDatabase udb = new UserDatabase(context,mTwitter.getFollowing(id,cursor));
usrAdp = new UserRecycler(udb,(UserDetail)context);
} else { } else {
UserDatabase uDb = usrAdp.getData(); UserDatabase uDb = usrAdp.getData();
uDb.addLast(mTwitter.getFollowing(id,cursor)); uDb.addLast(mTwitter.getFollowing(id,cursor));
@ -58,7 +59,8 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
} }
else if(mode == FOLLOWERS) { else if(mode == FOLLOWERS) {
if(usrAdp == null) { if(usrAdp == null) {
usrAdp = new UserAdapter(context,new UserDatabase(context,mTwitter.getFollower(id,cursor))); UserDatabase udb = new UserDatabase(context,mTwitter.getFollower(id,cursor));
usrAdp = new UserRecycler(udb,(UserDetail)context);
} else { } else {
UserDatabase uDb = usrAdp.getData(); UserDatabase uDb = usrAdp.getData();
uDb.addLast(mTwitter.getFollower(id,cursor)); uDb.addLast(mTwitter.getFollower(id,cursor));
@ -67,14 +69,14 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
} }
else if(mode == RETWEETER) { else if(mode == RETWEETER) {
UserDatabase udb = new UserDatabase(context,mTwitter.getRetweeter(id,cursor)); UserDatabase udb = new UserDatabase(context,mTwitter.getRetweeter(id,cursor));
usrAdp = new UserAdapter(context,udb); usrAdp = new UserRecycler(udb,(UserDetail)context);
} }
else if(mode == FAVORISER) { else if(mode == FAVORISER) {
// GET FAV USERS TODO // GET FAV USERS TODO
} }
} }
catch(Exception err) { catch(Exception err) {
errmsg = err.getMessage(); errmsg = "Fehler: "+err.getMessage();
} }
return null; return null;
} }

View File

@ -38,7 +38,7 @@ public class TrendDatabase {
public String getTrendname(int pos){ return trendName.get(pos); } public String getTrendname(int pos){ return trendName.get(pos); }
public String getTrendlink(int pos){return trendLink.get(pos);} public String getTrendlink(int pos){return trendLink.get(pos);}
public int getTrendpos(int pos){ return trendpos.get(pos); } public String getTrendpos(int pos){ return Integer.toString(trendpos.get(pos))+"."; }
public int getSize(){ public int getSize(){
if(trendName != null) if(trendName != null)

View File

@ -5,6 +5,12 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import org.nuclearfog.twidda.window.ColorPreferences;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -175,6 +181,7 @@ public class TweetDatabase {
SQL_GET_HOME = "SELECT * FROM timeline " + SQL_GET_HOME = "SELECT * FROM timeline " +
"INNER JOIN tweet ON timeline.mTweetID = tweet.tweetID " + "INNER JOIN tweet ON timeline.mTweetID = tweet.tweetID " +
"INNER JOIN user ON tweet.userID=user.userID ORDER BY tweetID ASC"; "INNER JOIN user ON tweet.userID=user.userID ORDER BY tweetID ASC";
limit = 5;
} }
Cursor cursor = db.rawQuery(SQL_GET_HOME,null); Cursor cursor = db.rawQuery(SQL_GET_HOME,null);
@ -204,7 +211,7 @@ public class TweetDatabase {
index = cursor.getColumnIndex("retweeter"); index = cursor.getColumnIndex("retweeter");
retweeter.add(cursor.getString(index)); retweeter.add(cursor.getString(index));
size++; size++;
} while(cursor.moveToNext()); } while(cursor.moveToNext() && size < limit);
} }
cursor.close(); cursor.close();
db.close(); db.close();
@ -230,6 +237,48 @@ public class TweetDatabase {
else return " RT @"+retweeter.get(pos); else return " RT @"+retweeter.get(pos);
} }
public SpannableStringBuilder getHighlightedTweet(Context c, int pos) {
String tweet = getTweet(pos);
int highlight = ColorPreferences.getInstance(c).getColor(ColorPreferences.HIGHLIGHTING);
SpannableStringBuilder sTweet = new SpannableStringBuilder(tweet);
int start = 0;
boolean marked = false;
for(int i = 0 ; i < tweet.length() ; i++) {
char current = tweet.charAt(i);
switch(current){
case '@':
start = i;
marked = true;
break;
case '#':
start = i;
marked = true;
break;
case '\'':
case '\"':
case '\n':
case ')':
case '(':
case ':':
case ' ':
case '.':
case ',':
case '!':
case '?':
case '-':
if(marked)
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
marked = false;
break;
}
if(i == tweet.length()-1 && marked) {
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return sTweet;
}
/** /**
* Convert Time to String * Convert Time to String
* @param mills TweetDetail Time * @param mills TweetDetail Time

View File

@ -1,137 +0,0 @@
package org.nuclearfog.twidda.viewadapter;
import android.content.Context;
import android.media.Image;
import android.support.annotation.NonNull;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.database.TweetDatabase;
public class TimelineAdapter extends ArrayAdapter implements View.OnClickListener {
private TweetDatabase mTweets;
private ViewGroup p;
private LayoutInflater inf;
private int textColor, background, highlight;
private Context context;
public TimelineAdapter(Context context, TweetDatabase mTweets) {
super(context, R.layout.tweet);
this.mTweets = mTweets;
this.context = context;
inf = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ColorPreferences mColor = ColorPreferences.getInstance(context);
textColor = mColor.getColor(ColorPreferences.FONT_COLOR);
background = mColor.getColor(ColorPreferences.BACKGROUND);
highlight = mColor.getColor(ColorPreferences.HIGHLIGHTING);
}
/**
* Fetch & Update Data
* @return TweetDatabase instance
*/
public TweetDatabase getData() {
return mTweets;
}
@Override
public int getCount() {
return mTweets.getSize();
}
@Override
public long getItemId(int pos){
return mTweets.getTweetId(pos);
}
@NonNull
@Override
public View getView(int position, View v, @NonNull ViewGroup parent) {
p = parent;
if(v == null) {
v = inf.inflate(R.layout.tweet, parent,false);
v.setBackgroundColor(background);
v.setOnClickListener(this);
}
String retweetStr = Integer.toString(mTweets.getRetweet(position));
String favoriteStr = Integer.toString(mTweets.getFavorite(position));
((TextView) v.findViewById(R.id.username)).setText(mTweets.getUsername(position));
((TextView) v.findViewById(R.id.screenname)).setText(mTweets.getScreenname(position));
((TextView) v.findViewById(R.id.tweettext)).setText(highlight(mTweets.getTweet(position)));
((TextView) v.findViewById(R.id.retweet_number)).setText(retweetStr);
((TextView) v.findViewById(R.id.favorite_number)).setText(favoriteStr);
((TextView) v.findViewById(R.id.retweeter)).setText(mTweets.getRetweeter(position));
((TextView) v.findViewById(R.id.time)).setText(mTweets.getDate(position));
((TextView) v.findViewById(R.id.tweettext)).setTextColor(textColor);
ImageView pb = v.findViewById(R.id.tweetPb);
ImageView verify = v.findViewById(R.id.list_verify);
if(mTweets.isVerified(position)) {
verify.setVisibility(ImageView.VISIBLE);
} else {
verify.setVisibility(ImageView.GONE);
}
if(mTweets.loadImages()) {
Picasso.with(context).load(mTweets.getPbLink(position)).into(pb);
}
return v;
}
@Override
public void onClick(View v) {
ListView parent = ((ListView)p);
int position = parent.getPositionForView(v);
parent.performItemClick(v,position,0);
}
private SpannableStringBuilder highlight(String tweet) {
SpannableStringBuilder sTweet = new SpannableStringBuilder(tweet);
int start = 0;
boolean marked = false;
for(int i = 0 ; i < tweet.length() ; i++) {
char current = tweet.charAt(i);
switch(current){
case '@':
start = i;
marked = true;
break;
case '#':
start = i;
marked = true;
break;
case '\'':
case '\"':
case '\n':
case ')':
case '(':
case ':':
case ' ':
case '.':
case ',':
case '!':
case '?':
case '-':
if(marked)
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
marked = false;
break;
}
if(i == tweet.length()-1 && marked) {
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return sTweet;
}
}

View File

@ -0,0 +1,120 @@
package org.nuclearfog.twidda.viewadapter;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import com.squareup.picasso.Picasso;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.TweetDatabase;
public class TimelineRecycler extends Adapter<TimelineRecycler.ItemHolder> implements View.OnClickListener {
private TweetDatabase mTweets;
private ViewGroup parent;
private OnItemClicked mListener;
private int background = 0x00000000;
private int font_color = 0xFFFFFFFF;
/**
* @param mListener Item Click Listener
*/
public TimelineRecycler(TweetDatabase mTweets, OnItemClicked mListener) {
this.mListener = mListener;
this.mTweets = mTweets;
}
public void setColor(int background, int font_color) {
this.background = background;
this.font_color = font_color;
}
public TweetDatabase getData() {
return mTweets;
}
@Override
public int getItemCount(){
return mTweets.getSize();
}
@Override
public long getItemId(int pos){
return mTweets.getTweetId(pos);
}
@Override
public ItemHolder onCreateViewHolder(ViewGroup parent, int index) {
this.parent = parent;
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.tweet, parent,false);
v.setBackgroundColor(background);
v.setOnClickListener(this);
return new ItemHolder(v);
}
@Override
public void onBindViewHolder(ItemHolder vh, int index) {
vh.tweet.setTextColor(font_color);
vh.username.setText(mTweets.getUsername(index));
vh.screenname.setText(mTweets.getScreenname(index));
vh.tweet.setText(mTweets.getHighlightedTweet(parent.getContext(),index));
vh.retweet.setText(Integer.toString(mTweets.getRetweet(index)));
vh.favorite.setText(Integer.toString(mTweets.getFavorite(index)));
vh.retweeter.setText(mTweets.getRetweeter(index));
vh.time.setText(mTweets.getDate(index));
if(mTweets.loadImages()) {
Picasso.with(parent.getContext()).load(mTweets.getPbLink(index)).into(vh.profile);
}
if(mTweets.isVerified(index)) {
vh.verify.setVisibility(View.VISIBLE);
} else {
vh.verify.setVisibility(View.INVISIBLE);
}
}
@Override
public void onClick(View view) {
ViewGroup p = TimelineRecycler.this.parent;
RecyclerView rv = (RecyclerView) p;
int position = rv.getChildLayoutPosition(view);
mListener.onItemClick(view, p, position);
}
class ItemHolder extends ViewHolder {
public TextView username, screenname, tweet, retweet;
public TextView favorite, retweeter, time;
public ImageView profile, verify;
public ItemHolder(View v) {
super(v);
username = v.findViewById(R.id.username);
screenname = v.findViewById(R.id.screenname);
tweet = v.findViewById(R.id.tweettext);
retweet = v.findViewById(R.id.retweet_number);
favorite = v.findViewById(R.id.favorite_number);
retweeter = v.findViewById(R.id.retweeter);
time = v.findViewById(R.id.time);
profile = v.findViewById(R.id.tweetPb);
verify = v.findViewById(R.id.list_verify);
}
}
/**
* Custom Click Listener
*/
public interface OnItemClicked {
void onItemClick(View v, ViewGroup parent, int position);
}
}

View File

@ -1,53 +0,0 @@
package org.nuclearfog.twidda.viewadapter;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.database.TrendDatabase;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class TrendAdapter extends ArrayAdapter {
private TrendDatabase trend;
private LayoutInflater inf;
private int background, textColor;
public TrendAdapter(Context context, TrendDatabase trend) {
super(context, R.layout.trend);
inf = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ColorPreferences mcolor = ColorPreferences.getInstance(context);
textColor = mcolor.getColor(ColorPreferences.FONT_COLOR);
background = mcolor.getColor(ColorPreferences.BACKGROUND);
this.trend = trend;
}
public TrendDatabase getDatabase() {
return trend;
}
@Override
public int getCount() {
return trend.getSize();
}
@NonNull
@Override
public View getView(int position, View v, @NonNull ViewGroup parent) {
if(v == null) {
v = inf.inflate(R.layout.trend, parent,false);
v.setBackgroundColor(background);
}
String trendPos = Integer.toString( (position+1) ) +'.';
String trendName = trend.getTrendname(position);
((TextView) v.findViewById(R.id.trendpos)).setText(trendPos);
((TextView) v.findViewById(R.id.trendname)).setText(trendName);
((TextView) v.findViewById(R.id.trendpos)).setTextColor(textColor);
((TextView) v.findViewById(R.id.trendname)).setTextColor(textColor);
return v;
}
}

View File

@ -0,0 +1,81 @@
package org.nuclearfog.twidda.viewadapter;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.widget.TextView;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.TrendDatabase;
public class TrendRecycler extends RecyclerView.Adapter<TrendRecycler.ItemHolder>
implements View.OnClickListener {
private ViewGroup parent;
private TrendDatabase trend;
private OnItemClicked mListener;
private int background = 0x00000000;
private int font_color = 0xFFFFFFFF;
public TrendRecycler(TrendDatabase trend, OnItemClicked mListener) {
this.mListener = mListener;
this.trend = trend;
}
public TrendDatabase getData() { return trend; }
public void setColor(int background, int font_color) {
this.background = background;
this.font_color = font_color;
}
@Override
public int getItemCount(){
return trend.getSize();
}
@Override
public ItemHolder onCreateViewHolder(ViewGroup parent, int index) {
this.parent = parent;
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.trend, parent,false);
v.setBackgroundColor(background);
v.setOnClickListener(this);
return new ItemHolder(v);
}
@Override
public void onBindViewHolder(ItemHolder vh, int index) {
vh.pos.setText(trend.getTrendpos(index));
vh.pos.setTextColor(font_color);
vh.trends.setText(trend.getTrendname(index));
vh.trends.setTextColor(font_color);
}
@Override
public void onClick(View view) {
ViewGroup p = TrendRecycler.this.parent;
RecyclerView rv = (RecyclerView) p;
int position = rv.getChildLayoutPosition(view);
mListener.onItemClick(view, p, position);
}
class ItemHolder extends ViewHolder {
public TextView trends, pos;
public ItemHolder(View v) {
super(v);
pos = v.findViewById(R.id.trendpos);
trends = v.findViewById(R.id.trendname);
}
}
/**
* Custom Click Listener
*/
public interface OnItemClicked {
void onItemClick(View v, ViewGroup parent, int position);
}
}

View File

@ -1,84 +0,0 @@
package org.nuclearfog.twidda.viewadapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.database.UserDatabase;
import org.nuclearfog.twidda.R;
public class UserAdapter extends ArrayAdapter implements View.OnClickListener {
private UserDatabase userDatabase;
private ViewGroup p;
private LayoutInflater inf;
private int background;
private Context context;
public UserAdapter(Context context, UserDatabase userDatabase) {
super(context, R.layout.useritem);
this.userDatabase = userDatabase;
this.context = context;
inf = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ColorPreferences mColor = ColorPreferences.getInstance(context);
background = mColor.getColor(ColorPreferences.BACKGROUND);
}
public UserDatabase getData(){
return userDatabase;
}
@Override
public int getCount() {
return userDatabase.getSize();
}
@Override
public long getItemId(int position){
return userDatabase.getUserID(position);
}
@NonNull
@Override
public View getView(int position, View v, @NonNull ViewGroup parent) {
p = parent;
if(v == null) {
v = inf.inflate(R.layout.useritem, parent,false);
v.setBackgroundColor(background);
v.setOnClickListener(this);
}
((TextView)v.findViewById(R.id.username_detail)).setText(userDatabase.getUsername(position));
((TextView)v.findViewById(R.id.screenname_detail)).setText(userDatabase.getScreenname(position));
ImageView pb = v.findViewById(R.id.user_profileimg);
if(userDatabase.loadImages()) {
Picasso.with(context).load(userDatabase.getImageUrl(position)).into(pb);
}
if(userDatabase.isVerified(position)) {
v.findViewById(R.id.verified).setVisibility(View.VISIBLE);
} else {
v.findViewById(R.id.verified).setVisibility(View.INVISIBLE);
}
if(userDatabase.isLocked(position)) {
v.findViewById(R.id.locked_profile).setVisibility(View.VISIBLE);
} else {
v.findViewById(R.id.locked_profile).setVisibility(View.INVISIBLE);
}
return v;
}
@Override
public void onClick(View v) {
ListView parent = ((ListView)p);
int position = parent.getPositionForView(v);
parent.performItemClick(v,position,0);
}
}

View File

@ -0,0 +1,93 @@
package org.nuclearfog.twidda.viewadapter;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.UserDatabase;
public class UserRecycler extends RecyclerView.Adapter<UserRecycler.ItemHolder> implements View.OnClickListener {
private UserDatabase mUser;
private OnItemClicked mListener;
private ViewGroup parent;
public UserRecycler(UserDatabase mUser, OnItemClicked mListener) {
this.mListener = mListener;
this.mUser = mUser;
}
public UserDatabase getData(){return mUser; }
@Override
public int getItemCount(){
return mUser.getSize();
}
@Override
public long getItemId(int pos){
return mUser.getUserID(pos);
}
@Override
public ItemHolder onCreateViewHolder(ViewGroup parent, int index) {
this.parent = parent;
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.useritem, parent,false);
v.setOnClickListener(this);
return new ItemHolder(v);
}
@Override
public void onBindViewHolder(ItemHolder vh, int index) {
vh.screenname.setText(mUser.getScreenname(index));
vh.username.setText(mUser.getUsername(index));
if(mUser.loadImages()) {
Picasso.with(parent.getContext()).load(mUser.getImageUrl(index)).into(vh.profileImg);
}
if(mUser.isVerified(index)) {
vh.verifyIco.setVisibility(View.VISIBLE);
} else {
vh.verifyIco.setVisibility(View.INVISIBLE);
}
if(mUser.isLocked(index)) {
vh.lockIco.setVisibility(View.VISIBLE);
} else {
vh.lockIco.setVisibility(View.INVISIBLE);
}
}
@Override
public void onClick(View view) {
ViewGroup p = UserRecycler.this.parent;
RecyclerView rv = (RecyclerView) p;
int position = rv.getChildLayoutPosition(view);
mListener.onItemClick(view, p, position);
}
class ItemHolder extends ViewHolder {
ImageView profileImg, verifyIco, lockIco;
TextView username, screenname;
public ItemHolder(View v) {
super(v);
username = v.findViewById(R.id.username_detail);
screenname = v.findViewById(R.id.screenname_detail);
profileImg = v.findViewById(R.id.user_profileimg);
verifyIco = v.findViewById(R.id.verified);
lockIco = v.findViewById(R.id.locked_profile);
}
}
public interface OnItemClicked {
void onItemClick(View v, ViewGroup parent, int position);
}
}

View File

@ -4,31 +4,32 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TabHost; import android.widget.TabHost;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.TweetDatabase; import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.database.UserDatabase; import org.nuclearfog.twidda.database.UserDatabase;
import org.nuclearfog.twidda.viewadapter.TimelineAdapter; import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.viewadapter.UserAdapter;
import org.nuclearfog.twidda.backend.TwitterSearch; import org.nuclearfog.twidda.backend.TwitterSearch;
import org.nuclearfog.twidda.viewadapter.UserRecycler;
/** /**
* SearchPage Tweets and Users * SearchPage Tweets and Users
* @see TwitterSearch * @see TwitterSearch
*/ */
public class SearchPage extends AppCompatActivity implements AdapterView.OnItemClickListener, public class SearchPage extends AppCompatActivity implements UserRecycler.OnItemClicked,
SwipeRefreshLayout.OnRefreshListener, TabHost.OnTabChangeListener { SwipeRefreshLayout.OnRefreshListener, TabHost.OnTabChangeListener, TimelineRecycler.OnItemClicked {
private ListView tweetSearch, userSearch; private RecyclerView tweetSearch,userSearch;
private SwipeRefreshLayout tweetReload; private SwipeRefreshLayout tweetReload;
private TwitterSearch mSearch; private TwitterSearch mSearch;
private String search = ""; private String search = "";
@ -40,9 +41,12 @@ public class SearchPage extends AppCompatActivity implements AdapterView.OnItemC
getExtras(getIntent().getExtras()); getExtras(getIntent().getExtras());
Toolbar tool = (Toolbar) findViewById(R.id.search_toolbar); Toolbar tool = (Toolbar) findViewById(R.id.search_toolbar);
tweetSearch = (ListView) findViewById(R.id.tweet_result);
userSearch = (ListView) findViewById(R.id.user_result); tweetSearch = (RecyclerView) findViewById(R.id.tweet_result);
userSearch = (RecyclerView) findViewById(R.id.user_result);
tweetReload = (SwipeRefreshLayout) findViewById(R.id.searchtweets); tweetReload = (SwipeRefreshLayout) findViewById(R.id.searchtweets);
tweetSearch.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
userSearch.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
setSupportActionBar(tool); setSupportActionBar(tool);
if(getSupportActionBar() != null) if(getSupportActionBar() != null)
getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false);
@ -51,10 +55,7 @@ public class SearchPage extends AppCompatActivity implements AdapterView.OnItemC
setTabs(tabhost); setTabs(tabhost);
tabhost.setOnTabChangedListener(this); tabhost.setOnTabChangedListener(this);
tweetSearch.setOnItemClickListener(this);
userSearch.setOnItemClickListener(this);
tweetReload.setOnRefreshListener(this); tweetReload.setOnRefreshListener(this);
getContent(); getContent();
} }
@ -115,11 +116,11 @@ public class SearchPage extends AppCompatActivity implements AdapterView.OnItemC
} }
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(View view, ViewGroup parent, int position) {
switch(parent.getId()) { switch(parent.getId()) {
case R.id.tweet_result: case R.id.tweet_result:
if(!tweetReload.isRefreshing()) { if(!tweetReload.isRefreshing()) {
TimelineAdapter tlAdp = (TimelineAdapter) tweetSearch.getAdapter(); TimelineRecycler tlAdp = (TimelineRecycler) tweetSearch.getAdapter();
TweetDatabase twDB = tlAdp.getData(); TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position); long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position); long userID = twDB.getUserID(position);
@ -134,7 +135,7 @@ public class SearchPage extends AppCompatActivity implements AdapterView.OnItemC
} }
break; break;
case R.id.user_result: case R.id.user_result:
UserAdapter uAdp = (UserAdapter) userSearch.getAdapter(); UserRecycler uAdp = (UserRecycler) userSearch.getAdapter();
UserDatabase uDb = uAdp.getData(); UserDatabase uDb = uAdp.getData();
Intent profile = new Intent(getApplicationContext(), UserProfile.class); Intent profile = new Intent(getApplicationContext(), UserProfile.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -174,6 +175,7 @@ public class SearchPage extends AppCompatActivity implements AdapterView.OnItemC
mSearch.execute(search); mSearch.execute(search);
} }
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
private void getExtras(Bundle b) { private void getExtras(Bundle b) {
search = b.getString("search"); search = b.getString("search");

View File

@ -2,14 +2,16 @@ package org.nuclearfog.twidda.window;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
@ -18,21 +20,20 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import static android.content.DialogInterface.*; import static android.content.DialogInterface.*;
import org.nuclearfog.twidda.backend.ImagePopup;
import org.nuclearfog.twidda.backend.StatusLoader; import org.nuclearfog.twidda.backend.StatusLoader;
import org.nuclearfog.twidda.backend.TwitterEngine; import org.nuclearfog.twidda.backend.TwitterEngine;
import org.nuclearfog.twidda.database.TweetDatabase; import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.TimelineAdapter; import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
/** /**
* Detailed Tweet Window * Detailed Tweet Window
* @see StatusLoader * @see StatusLoader
*/ */
public class TweetDetail extends AppCompatActivity implements View.OnClickListener, public class TweetDetail extends AppCompatActivity implements View.OnClickListener,
AdapterView.OnItemClickListener, DialogInterface.OnClickListener, SwipeRefreshLayout.OnRefreshListener { TimelineRecycler.OnItemClicked, DialogInterface.OnClickListener, SwipeRefreshLayout.OnRefreshListener {
private ListView answer_list; private RecyclerView answer_list;
private long tweetID; private long tweetID;
private long userID; private long userID;
private StatusLoader mStat, mReply; private StatusLoader mStat, mReply;
@ -46,22 +47,20 @@ public class TweetDetail extends AppCompatActivity implements View.OnClickListen
boolean home = userID == TwitterEngine.getHomeId(); boolean home = userID == TwitterEngine.getHomeId();
answer_list = (ListView) findViewById(R.id.answer_list); answer_list = (RecyclerView) findViewById(R.id.answer_list);
Button answer = (Button) findViewById(R.id.answer_button); Button answer = (Button) findViewById(R.id.answer_button);
Button retweet = (Button) findViewById(R.id.rt_button_detail); Button retweet = (Button) findViewById(R.id.rt_button_detail);
Button favorite = (Button) findViewById(R.id.fav_button_detail); Button favorite = (Button) findViewById(R.id.fav_button_detail);
Button delete = (Button) findViewById(R.id.delete); Button delete = (Button) findViewById(R.id.delete);
ImageView pb =(ImageView) findViewById(R.id.profileimage_detail); ImageView pb =(ImageView) findViewById(R.id.profileimage_detail);
SwipeRefreshLayout answerReload = (SwipeRefreshLayout) findViewById(R.id.answer_reload); SwipeRefreshLayout answerReload = (SwipeRefreshLayout) findViewById(R.id.answer_reload);
TextView txtRt = (TextView) findViewById(R.id.no_rt_detail); TextView txtRt = (TextView) findViewById(R.id.no_rt_detail);
TextView txtFav = (TextView) findViewById(R.id.no_fav_detail); TextView txtFav = (TextView) findViewById(R.id.no_fav_detail);
TextView date = (TextView) findViewById(R.id.timedetail); TextView date = (TextView) findViewById(R.id.timedetail);
answer_list.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
if(home) { if(home) {
delete.setVisibility(View.VISIBLE); delete.setVisibility(View.VISIBLE);
} }
answer_list.setOnItemClickListener(this);
favorite.setOnClickListener(this); favorite.setOnClickListener(this);
retweet.setOnClickListener(this); retweet.setOnClickListener(this);
answerReload.setOnRefreshListener(this); answerReload.setOnRefreshListener(this);
@ -159,8 +158,8 @@ public class TweetDetail extends AppCompatActivity implements View.OnClickListen
} }
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(View view, ViewGroup parent, int position) {
TimelineAdapter tlAdp = (TimelineAdapter) answer_list.getAdapter(); TimelineRecycler tlAdp = (TimelineRecycler) answer_list.getAdapter();
TweetDatabase twDB = tlAdp.getData(); TweetDatabase twDB = tlAdp.getData();
long userID = twDB.getUserID(position); long userID = twDB.getUserID(position);
long tweetID = twDB.getTweetId(position); long tweetID = twDB.getTweetId(position);

View File

@ -3,27 +3,28 @@ package org.nuclearfog.twidda.window;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; 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.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.view.ViewGroup;
import android.widget.ListView;
import org.nuclearfog.twidda.backend.UserLists; import org.nuclearfog.twidda.backend.UserLists;
import org.nuclearfog.twidda.database.UserDatabase; import org.nuclearfog.twidda.database.UserDatabase;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.UserAdapter; import org.nuclearfog.twidda.viewadapter.UserRecycler;
/** /**
* Get Follow Connections from an User * Get Follow Connections from an User
* @see UserLists * @see UserLists
*/ */
public class UserDetail extends AppCompatActivity implements AdapterView.OnItemClickListener { public class UserDetail extends AppCompatActivity implements UserRecycler.OnItemClicked {
private long userID, tweetID; private long userID, tweetID;
private long mode; private long mode;
private ListView userListview; private RecyclerView userListview;
private UserLists uList; private UserLists uList;
@Override @Override
@ -32,10 +33,10 @@ public class UserDetail extends AppCompatActivity implements AdapterView.OnItemC
setContentView(R.layout.user); setContentView(R.layout.user);
getExtras(getIntent().getExtras()); getExtras(getIntent().getExtras());
userListview = (ListView) findViewById(R.id.userlist); userListview = (RecyclerView) findViewById(R.id.userlist);
userListview.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
Toolbar toolbar = (Toolbar) findViewById(R.id.user_toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.user_toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
userListview.setOnItemClickListener(this);
getUsers(); getUsers();
} }
@ -70,8 +71,8 @@ public class UserDetail extends AppCompatActivity implements AdapterView.OnItemC
} }
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(View view, ViewGroup parent, int position) {
UserAdapter uAdp = (UserAdapter) userListview.getAdapter(); UserRecycler uAdp = (UserRecycler) userListview.getAdapter();
UserDatabase uDB = uAdp.getData(); UserDatabase uDB = uAdp.getData();
long userID = uDB.getUserID(position); long userID = uDB.getUserID(position);
String username = uDB.getScreenname(position); String username = uDB.getScreenname(position);

View File

@ -5,31 +5,32 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity; 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.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TabHost; import android.widget.TabHost;
import android.widget.TextView; import android.widget.TextView;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.TweetDatabase; import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.backend.ProfileLoader; import org.nuclearfog.twidda.backend.ProfileLoader;
import org.nuclearfog.twidda.viewadapter.TimelineAdapter; import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
/** /**
* User Profile Class uses AsyncTask * User Profile Class uses AsyncTask
* @see ProfileLoader * @see ProfileLoader
*/ */
public class UserProfile extends AppCompatActivity implements View.OnClickListener, public class UserProfile extends AppCompatActivity implements View.OnClickListener,
AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener, SwipeRefreshLayout.OnRefreshListener, TabHost.OnTabChangeListener,
TabHost.OnTabChangeListener { TimelineRecycler.OnItemClicked {
private ProfileLoader mProfile, mTweets, mFavorits; private ProfileLoader mProfile, mTweets, mFavorits;
private SwipeRefreshLayout homeReload, favoriteReload; private SwipeRefreshLayout homeReload, favoriteReload;
private ListView homeTweets, homeFavorits; private RecyclerView homeTweets, homeFavorits;
private long userId; private long userId;
private boolean home; private boolean home;
private String username = ""; private String username = "";
@ -47,8 +48,10 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
SharedPreferences settings = getSharedPreferences("settings", 0); SharedPreferences settings = getSharedPreferences("settings", 0);
home = userId == settings.getLong("userID", -1); home = userId == settings.getLong("userID", -1);
homeTweets = (ListView)findViewById(R.id.ht_list); homeTweets = (RecyclerView) findViewById(R.id.ht_list);
homeFavorits = (ListView)findViewById(R.id.hf_list); homeFavorits = (RecyclerView)findViewById(R.id.hf_list);
homeTweets.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
homeFavorits.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
homeReload = (SwipeRefreshLayout) findViewById(R.id.hometweets); homeReload = (SwipeRefreshLayout) findViewById(R.id.hometweets);
favoriteReload = (SwipeRefreshLayout) findViewById(R.id.homefavorits); favoriteReload = (SwipeRefreshLayout) findViewById(R.id.homefavorits);
TextView txtFollowing = (TextView)findViewById(R.id.following); TextView txtFollowing = (TextView)findViewById(R.id.following);
@ -58,8 +61,6 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
mTab.setOnTabChangedListener(this); mTab.setOnTabChangedListener(this);
txtFollowing.setOnClickListener(this); txtFollowing.setOnClickListener(this);
txtFollower.setOnClickListener(this); txtFollower.setOnClickListener(this);
homeTweets.setOnItemClickListener(this);
homeFavorits.setOnItemClickListener(this);
homeReload.setOnRefreshListener(this); homeReload.setOnRefreshListener(this);
favoriteReload.setOnRefreshListener(this); favoriteReload.setOnRefreshListener(this);
@ -134,26 +135,6 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
} }
} }
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TimelineAdapter tlAdp;
if(parent.getId() == R.id.ht_list) {
tlAdp = (TimelineAdapter) homeTweets.getAdapter();
} else {
tlAdp = (TimelineAdapter) homeFavorits.getAdapter();
}
TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
String username = twDB.getScreenname(position);
Intent intent = new Intent(getApplicationContext(), TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
bundle.putString("username", username);
intent.putExtras(bundle);
startActivity(intent);
}
@Override @Override
public void onRefresh() { public void onRefresh() {
@ -176,6 +157,27 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
currentTab = tabId; currentTab = tabId;
} }
@Override
public void onItemClick(View v, ViewGroup parent, int position){
TimelineRecycler tlAdp;
if(parent.getId() == R.id.ht_list) {
tlAdp = (TimelineRecycler) homeTweets.getAdapter();
} else {
tlAdp = (TimelineRecycler) homeFavorits.getAdapter();
}
TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
String username = twDB.getScreenname(position);
Intent intent = new Intent(getApplicationContext(), TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
bundle.putString("username", username);
intent.putExtras(bundle);
startActivity(intent);
}
private void setTabs(TabHost mTab) { private void setTabs(TabHost mTab) {
mTab.setup(); mTab.setup();
// Tab #1 // Tab #1
@ -197,17 +199,26 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
new Thread( new Runnable() { new Thread( new Runnable() {
@Override @Override
public void run() { public void run() {
ColorPreferences mcolor = ColorPreferences.getInstance(getApplicationContext());
int background = mcolor.getColor(ColorPreferences.BACKGROUND);
int font_color = mcolor.getColor(ColorPreferences.FONT_COLOR);
TweetDatabase mTweet = new TweetDatabase(UserProfile.this, TweetDatabase.USER_TL, userId); TweetDatabase mTweet = new TweetDatabase(UserProfile.this, TweetDatabase.USER_TL, userId);
TweetDatabase fTweet = new TweetDatabase(UserProfile.this, TweetDatabase.FAV_TL, userId); TweetDatabase fTweet = new TweetDatabase(UserProfile.this, TweetDatabase.FAV_TL, userId);
mTweets = new ProfileLoader(UserProfile.this); mTweets = new ProfileLoader(UserProfile.this);
mFavorits = new ProfileLoader(UserProfile.this); mFavorits = new ProfileLoader(UserProfile.this);
if( mTweet.getSize() > 0 ) { if( mTweet.getSize() > 0 ) {
homeTweets.setAdapter(new TimelineAdapter(UserProfile.this,mTweet)); TimelineRecycler tlRc = new TimelineRecycler(mTweet,UserProfile.this);
}else { tlRc.setColor(background,font_color);
homeTweets.setAdapter(tlRc);
} else {
mTweets.execute(userId, ProfileLoader.GET_TWEETS,1L); mTweets.execute(userId, ProfileLoader.GET_TWEETS,1L);
} }
if( fTweet.getSize() > 0 ) { if( fTweet.getSize() > 0 ) {
homeFavorits.setAdapter(new TimelineAdapter(UserProfile.this,fTweet)); TimelineRecycler tlRc = new TimelineRecycler(fTweet,UserProfile.this);
tlRc.setColor(background,font_color);
homeFavorits.setAdapter(tlRc);
} else { } else {
mFavorits.execute(userId, ProfileLoader.GET_FAVS,1L); mFavorits.execute(userId, ProfileLoader.GET_FAVS,1L);
} }

View File

@ -7,7 +7,7 @@
<Button <Button
android:id="@+id/linkButton" android:id="@+id/linkButton"
android:layout_width="128dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="40dp" android:layout_marginBottom="40dp"
android:background="@android:color/darker_gray" android:background="@android:color/darker_gray"
@ -21,7 +21,7 @@
<EditText <EditText
android:id="@+id/pin" android:id="@+id/pin"
android:layout_width="96dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:hint="@string/pin" android:hint="@string/pin"
@ -30,16 +30,18 @@
<Button <Button
android:id="@+id/clipboard" android:id="@+id/clipboard"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="32dp" android:layout_height="32dp"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:background="@drawable/copy" /> android:background="@drawable/copy"
android:onClick="onClick" />
</LinearLayout> </LinearLayout>
<Button <Button
android:id="@+id/get" android:id="@+id/get"
android:layout_width="128dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="30dp" android:layout_margin="30dp"
android:background="@android:color/darker_gray" android:background="@android:color/darker_gray"

View File

@ -34,7 +34,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ListView <android.support.v7.widget.RecyclerView
android:id="@+id/tl_list" android:id="@+id/tl_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
@ -45,7 +45,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ListView <android.support.v7.widget.RecyclerView
android:id="@+id/tr_list" android:id="@+id/tr_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
@ -56,7 +56,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ListView <android.support.v7.widget.RecyclerView
android:id="@+id/m_list" android:id="@+id/m_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />

View File

@ -248,11 +248,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ListView <android.support.v7.widget.RecyclerView
android:id="@+id/ht_list" android:id="@+id/ht_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
android:nestedScrollingEnabled="true" />
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>
<android.support.v4.widget.SwipeRefreshLayout <android.support.v4.widget.SwipeRefreshLayout
@ -260,11 +259,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ListView <android.support.v7.widget.RecyclerView
android:id="@+id/hf_list" android:id="@+id/hf_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
android:nestedScrollingEnabled="true" />
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout> </FrameLayout>

View File

@ -35,22 +35,17 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ListView <android.support.v7.widget.RecyclerView
android:id="@+id/tweet_result" android:id="@+id/tweet_result"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent" />
</ListView>
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>
<ListView <android.support.v7.widget.RecyclerView
android:id="@+id/user_result" android:id="@+id/user_result"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"/>
</ListView>
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>

View File

@ -213,13 +213,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<ListView <android.support.v7.widget.RecyclerView
android:id="@+id/answer_list" android:id="@+id/answer_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:nestedScrollingEnabled="true"> android:nestedScrollingEnabled="true"/>
</ListView>
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>

View File

@ -21,12 +21,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" /> android:layout_gravity="center" />
<ListView <android.support.v7.widget.RecyclerView
android:id="@+id/userlist" android:id="@+id/userlist"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"/>
</ListView>
</FrameLayout> </FrameLayout>