Optimizations
This commit is contained in:
NudeDude 2018-03-03 22:54:13 +01:00
parent 5dcc6f39ec
commit fc4c3d9d64
10 changed files with 58 additions and 44 deletions

View File

@ -69,7 +69,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
timelineAdapter = (TimelineAdapter) timelineList.getAdapter(); timelineAdapter = (TimelineAdapter) timelineList.getAdapter();
if(timelineAdapter != null && timelineAdapter.getCount() != 0) { if(timelineAdapter != null && timelineAdapter.getCount() != 0) {
id = timelineAdapter.getItemId(0); id = timelineAdapter.getItemId(0);
timelineAdapter.getData().add(mTwitter.getHome(page,id)); 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 TimelineAdapter(context,mTweets);
@ -84,7 +84,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
mentionAdapter = (TimelineAdapter) mentionList.getAdapter(); mentionAdapter = (TimelineAdapter) mentionList.getAdapter();
if(mentionAdapter != null && mentionAdapter.getCount() != 0) { if(mentionAdapter != null && mentionAdapter.getCount() != 0) {
id = mentionAdapter.getItemId(0); id = mentionAdapter.getItemId(0);
mentionAdapter.getData().add(mTwitter.getMention(page,id)); 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 TimelineAdapter(context,mention);

View File

@ -122,7 +122,7 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
homeTl = new TimelineAdapter(context,hTweets); homeTl = new TimelineAdapter(context,hTweets);
} else { } else {
id = homeTl.getItemId(0); id = homeTl.getItemId(0);
homeTl.getData().add(mTwitter.getUserTweets(userId,args[2],id)); homeTl.getData().insert(mTwitter.getUserTweets(userId,args[2],id),true);
} }
} }
else if(MODE == GET_FAVS) else if(MODE == GET_FAVS)
@ -130,7 +130,7 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
homeFav = (TimelineAdapter) profileFavorits.getAdapter(); homeFav = (TimelineAdapter) profileFavorits.getAdapter();
if(homeFav != null) { if(homeFav != null) {
id = homeFav.getItemId(0); id = homeFav.getItemId(0);
homeFav.getData().add(mTwitter.getUserFavs(userId,args[2],id)); 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 TimelineAdapter(context,fTweets);

View File

@ -262,7 +262,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
replyList.setAdapter(tlAdp); replyList.setAdapter(tlAdp);
} else { } else {
TweetDatabase twDb = tlAdp.getData(); TweetDatabase twDb = tlAdp.getData();
twDb.addHot(answers); twDb.insert(answers,false);
tlAdp.notifyDataSetChanged(); tlAdp.notifyDataSetChanged();
ansReload.setRefreshing(false); ansReload.setRefreshing(false);
} }

View File

@ -45,7 +45,7 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
tlAdp = (TimelineAdapter) tweetSearch.getAdapter(); tlAdp = (TimelineAdapter) tweetSearch.getAdapter();
if(tlAdp != null) { if(tlAdp != null) {
id = tlAdp.getItemId(0); id = tlAdp.getItemId(0);
tlAdp.getData().addHot(mTwitter.searchTweets(get,id)); tlAdp.getData().insert(mTwitter.searchTweets(get,id),false);
} else { } else {
tlAdp = new TimelineAdapter(context, new TweetDatabase(mTwitter.searchTweets(get,id),context)); tlAdp = new TimelineAdapter(context, new TweetDatabase(mTwitter.searchTweets(get,id),context));
} }

View File

@ -5,7 +5,6 @@ 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 java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -26,9 +25,9 @@ public class TweetDatabase {
private List<Long> userId,tweetId,timeMillis; private List<Long> userId,tweetId,timeMillis;
private List<Integer> noRT,noFav, verify; private List<Integer> noRT,noFav, verify;
private boolean toggleImg; private boolean toggleImg;
private int limit;
private int size = 0; private int size = 0;
private int mode = 0; private int mode = 0;
private int limit;
private long CurrentId = 0; private long CurrentId = 0;
/** /**
@ -67,24 +66,18 @@ public class TweetDatabase {
*/ */
public TweetDatabase(List<Status> stats, Context context) { public TweetDatabase(List<Status> stats, Context context) {
initialize(context); initialize(context);
insert(stats); add(stats);
} }
/** /**
* Add new Elements to the Lists and store into Database * Add new Elements to the List
* @param stats List of Tweets * @param stats List of Tweets
* @param store if True, data will be stored in SQL
*/ */
public void add(List<Status> stats) { public void insert(List<Status> stats, boolean store) {
store(stats); if(store)
insertNew(stats); store(stats);
} addFirst(stats);
/**
* Add new Elements without storing
* @param stats list of Tweets
*/
public void addHot(List<Status> stats) {
insertNew(stats);
} }
/** /**
@ -276,7 +269,7 @@ public class TweetDatabase {
initArray(); initArray();
} }
private void insert(List<Status> stats) { private void add(List<Status> stats) {
for(Status stat: stats) { for(Status stat: stats) {
Status rtStat = stat.getRetweetedStatus(); Status rtStat = stat.getRetweetedStatus();
User usr = stat.getUser(); User usr = stat.getUser();
@ -285,7 +278,7 @@ public class TweetDatabase {
stat = rtStat; stat = rtStat;
usr = rtStat.getUser(); usr = rtStat.getUser();
} else { } else {
retweeter.add(" "); retweeter.add("\0");
} }
user.add(usr.getName()); user.add(usr.getName());
scrname.add('@'+usr.getScreenName()); scrname.add('@'+usr.getScreenName());
@ -301,7 +294,7 @@ public class TweetDatabase {
} }
} }
private void insertNew(List<Status> stats) { private void addFirst(List<Status> stats) {
for(int index = stats.size()-1 ; index >=0 ; index--) { for(int index = stats.size()-1 ; index >=0 ; index--) {
Status stat = stats.get(index); Status stat = stats.get(index);
Status rtStat = stat.getRetweetedStatus(); Status rtStat = stat.getRetweetedStatus();

View File

@ -15,7 +15,8 @@
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"
android:text="@string/register_link" /> android:text="@string/register_link"
android:textSize="12sp" />
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -46,6 +47,7 @@
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"
android:text="@string/verifierbutton" /> android:text="@string/verifierbutton"
android:textSize="12sp" />
</LinearLayout> </LinearLayout>

View File

@ -72,9 +72,10 @@
<TextView <TextView
android:id="@+id/profile_username" android:id="@+id/profile_username"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="2dp" /> android:layout_marginBottom="2dp"
android:singleLine="true" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -94,9 +95,10 @@
<TextView <TextView
android:id="@+id/profile_screenname" android:id="@+id/profile_screenname"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="2dp" /> android:layout_marginBottom="2dp"
android:singleLine="true" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -166,7 +168,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:contentDescription="@string/location" android:contentDescription="@string/location"
android:visibility="invisible" android:visibility="gone"
app:srcCompat="@drawable/location" /> app:srcCompat="@drawable/location" />
<TextView <TextView
@ -181,7 +183,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:contentDescription="@string/link" android:contentDescription="@string/link"
android:visibility="invisible" android:visibility="gone"
app:srcCompat="@drawable/link" /> app:srcCompat="@drawable/link" />
<TextView <TextView
@ -199,6 +201,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"
android:singleLine="true"
android:textSize="12sp" /> android:textSize="12sp" />
</LinearLayout> </LinearLayout>

View File

@ -15,6 +15,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="5dp" android:layout_margin="5dp"
android:singleLine="true"
android:textSize="20sp" /> android:textSize="20sp" />
</LinearLayout> </LinearLayout>

View File

@ -62,7 +62,8 @@
<TextView <TextView
android:id="@+id/screenname" android:id="@+id/screenname"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:singleLine="true" />
</LinearLayout> </LinearLayout>

View File

@ -39,12 +39,14 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:singleLine="true"
android:textSize="12sp" /> android:textSize="12sp" />
<TextView <TextView
android:id="@+id/answer_reference_detail" android:id="@+id/answer_reference_detail"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="12sp" android:textSize="12sp"
android:visibility="invisible" /> android:visibility="invisible" />
</LinearLayout> </LinearLayout>
@ -84,12 +86,14 @@
<TextView <TextView
android:id="@+id/scrnamedetail" android:id="@+id/scrnamedetail"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:singleLine="true" />
<TextView <TextView
android:id="@+id/timedetail" android:id="@+id/timedetail"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:singleLine="true" />
</LinearLayout> </LinearLayout>
@ -108,6 +112,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:linksClickable="false" android:linksClickable="false"
android:singleLine="true"
android:textSize="12sp" /> android:textSize="12sp" />
<Button <Button
@ -151,11 +156,14 @@
<TextView <TextView
android:id="@+id/no_ans_detail" android:id="@+id/no_ans_detail"
android:layout_width="64dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="20dp" android:layout_marginEnd="5dp"
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:ems="10" /> android:layout_weight="1"
android:ems="10"
android:singleLine="true"
android:textSize="12sp" />
<Button <Button
android:id="@+id/rt_button_detail" android:id="@+id/rt_button_detail"
@ -165,11 +173,14 @@
<TextView <TextView
android:id="@+id/no_rt_detail" android:id="@+id/no_rt_detail"
android:layout_width="64dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="20dp" android:layout_marginEnd="5dp"
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:ems="10" /> android:layout_weight="1"
android:ems="10"
android:singleLine="true"
android:textSize="12sp" />
<Button <Button
android:id="@+id/fav_button_detail" android:id="@+id/fav_button_detail"
@ -179,16 +190,19 @@
<TextView <TextView
android:id="@+id/no_fav_detail" android:id="@+id/no_fav_detail"
android:layout_width="64dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:ems="10" /> android:layout_weight="1"
android:ems="10"
android:singleLine="true"
android:textSize="12sp" />
<Button <Button
android:id="@+id/delete" android:id="@+id/delete"
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_marginStart="10dp"
android:background="@drawable/cross" android:background="@drawable/cross"
android:visibility="invisible" /> android:visibility="invisible" />