mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-02-03 20:47:37 +01:00
Bugfix
Optimizations
This commit is contained in:
parent
4bd98e4fa4
commit
f4d9ab0a60
@ -67,12 +67,12 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
|
||||
switch (MODE) {
|
||||
case HOME:
|
||||
timelineAdapter = (TimelineAdapter) timelineList.getAdapter();
|
||||
if(timelineAdapter.getCount() == 0) {
|
||||
TweetDatabase mTweets = new TweetDatabase(mTwitter.getHome(page,id), context,TweetDatabase.HOME_TL,0);
|
||||
timelineAdapter = new TimelineAdapter(context,mTweets);
|
||||
} else {
|
||||
if(timelineAdapter != null && timelineAdapter.getCount() != 0) {
|
||||
id = timelineAdapter.getItemId(0);
|
||||
timelineAdapter.getData().add(mTwitter.getHome(page,id));
|
||||
} else {
|
||||
TweetDatabase mTweets = new TweetDatabase(mTwitter.getHome(page,id), context,TweetDatabase.HOME_TL,0);
|
||||
timelineAdapter = new TimelineAdapter(context,mTweets);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -82,12 +82,12 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
|
||||
|
||||
case MENT:
|
||||
mentionAdapter = (TimelineAdapter) mentionList.getAdapter();
|
||||
if(mentionAdapter.getCount() == 0) {
|
||||
TweetDatabase mention = new TweetDatabase(mTwitter.getMention(page,id), context,TweetDatabase.GET_MENT,0);
|
||||
mentionAdapter = new TimelineAdapter(context,mention);
|
||||
} else {
|
||||
if(mentionAdapter != null && mentionAdapter.getCount() != 0) {
|
||||
id = mentionAdapter.getItemId(0);
|
||||
mentionAdapter.getData().add(mTwitter.getMention(page,id));
|
||||
} else {
|
||||
TweetDatabase mention = new TweetDatabase(mTwitter.getMention(page,id), context,TweetDatabase.GET_MENT,0);
|
||||
mentionAdapter = new TimelineAdapter(context,mention);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -117,12 +117,12 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||
else if(MODE == GET_TWEETS)
|
||||
{
|
||||
homeTl = (TimelineAdapter) profileTweets.getAdapter();
|
||||
if(homeTl != null) {
|
||||
id = homeTl.getItemId(0);
|
||||
homeTl.getData().add(mTwitter.getUserTweets(userId,args[2],id));
|
||||
} else {
|
||||
if(homeTl == null || homeTl.getCount() == 0) {
|
||||
TweetDatabase hTweets = new TweetDatabase(mTwitter.getUserTweets(userId,args[2],id),context,TweetDatabase.USER_TL,userId);
|
||||
homeTl = new TimelineAdapter(context,hTweets);
|
||||
} else {
|
||||
id = homeTl.getItemId(0);
|
||||
homeTl.getData().add(mTwitter.getUserTweets(userId,args[2],id));
|
||||
}
|
||||
}
|
||||
else if(MODE == GET_FAVS)
|
||||
|
@ -12,9 +12,9 @@ public class AppDatabase extends SQLiteOpenHelper
|
||||
"location TEXT, link TEXT, verify INTEGER);";
|
||||
|
||||
private static final String tQuery = "CREATE TABLE IF NOT EXISTS tweet (" +
|
||||
"tweetID INTEGER PRIMARY KEY, userID INTEGER," +
|
||||
"tweetID INTEGER PRIMARY KEY, userID INTEGER, retweeter TEXT," +
|
||||
"time INTEGER, tweet TEXT, retweet INTEGER, favorite INTEGER," +
|
||||
"answers INTEGER, FOREIGN KEY (userID) REFERENCES user(userID));";
|
||||
"FOREIGN KEY (userID) REFERENCES user(userID));";
|
||||
|
||||
private static final String trQuery = "CREATE TABLE IF NOT EXISTS trend (" +
|
||||
"trendpos INTEGER PRIMARY KEY, trendname TEXT, trendlink TEXT);";
|
||||
|
@ -15,17 +15,16 @@ import twitter4j.Status;
|
||||
import twitter4j.User;
|
||||
|
||||
public class TweetDatabase {
|
||||
public static final int HOME_TL = 0; // GET HOME TIMELINE
|
||||
public static final int FAV_TL = 1; // GET FAVORITE TL
|
||||
public static final int USER_TL = 2; // GET USERS TWEET TL @userID
|
||||
public static final int GET_TWEET = 3; // GET TWEET @ userID
|
||||
public static final int GET_MENT = 4; // GET MENTION TL
|
||||
public static final int HOME_TL = 0;
|
||||
public static final int FAV_TL = 1;
|
||||
public static final int USER_TL = 2;
|
||||
public static final int GET_TWEET = 3;
|
||||
public static final int GET_MENT = 4;
|
||||
|
||||
private AppDatabase dataHelper;
|
||||
private List<String> user,scrname,tweet,pbLink;
|
||||
private List<String> user,scrname,tweet,pbLink,retweeter;
|
||||
private List<Long> userId,tweetId,timeMillis;
|
||||
private List<Integer> noRT,noFav,noAns, verify;
|
||||
private SharedPreferences settings;
|
||||
private List<Integer> noRT,noFav, verify;
|
||||
private boolean toggleImg;
|
||||
private int size = 0;
|
||||
private int mode = 0;
|
||||
@ -110,6 +109,15 @@ public class TweetDatabase {
|
||||
for(int pos = 0; pos < stats.size(); pos++) {
|
||||
Status stat = stats.get(pos);
|
||||
User usr = stat.getUser();
|
||||
Status rtStat = stat.getRetweetedStatus();
|
||||
|
||||
if(rtStat != null) {
|
||||
tweet.put("retweeter",usr.getScreenName());
|
||||
stat = rtStat;
|
||||
usr = rtStat.getUser();
|
||||
} else {
|
||||
tweet.put("retweeter","\0");
|
||||
}
|
||||
|
||||
user.put("userID",usr.getId());
|
||||
user.put("username", usr.getName());
|
||||
@ -126,7 +134,6 @@ public class TweetDatabase {
|
||||
tweet.put("tweet", stat.getText());
|
||||
tweet.put("retweet", stat.getRetweetCount());
|
||||
tweet.put("favorite", stat.getFavoriteCount());
|
||||
tweet.put("answers", 0);
|
||||
|
||||
home.put("tweetID", stat.getId());
|
||||
fav.put("tweetID", stat.getId());
|
||||
@ -182,28 +189,28 @@ public class TweetDatabase {
|
||||
|
||||
if(cursor.moveToFirst()) {
|
||||
do {
|
||||
index = cursor.getColumnIndex("time"); // time
|
||||
index = cursor.getColumnIndex("time");
|
||||
timeMillis.add(cursor.getLong(index));
|
||||
index = cursor.getColumnIndex("tweet"); // tweet
|
||||
index = cursor.getColumnIndex("tweet");
|
||||
tweet.add( cursor.getString(index));
|
||||
index = cursor.getColumnIndex("retweet"); // retweet
|
||||
index = cursor.getColumnIndex("retweet");
|
||||
noRT.add( cursor.getInt(index));
|
||||
index = cursor.getColumnIndex("favorite"); // fav
|
||||
index = cursor.getColumnIndex("favorite");
|
||||
noFav.add( cursor.getInt(index));
|
||||
index = cursor.getColumnIndex("answers"); // answers
|
||||
noAns.add(cursor.getInt(index));
|
||||
index = cursor.getColumnIndex("username"); // user
|
||||
index = cursor.getColumnIndex("username");
|
||||
user.add(cursor.getString(index));
|
||||
index = cursor.getColumnIndex("scrname"); // username
|
||||
index = cursor.getColumnIndex("scrname");
|
||||
scrname.add(cursor.getString(index));
|
||||
index = cursor.getColumnIndex("verify"); // VERIFIED
|
||||
index = cursor.getColumnIndex("verify");
|
||||
verify.add(cursor.getInt(index));
|
||||
index = cursor.getColumnIndex("pbLink"); // image
|
||||
index = cursor.getColumnIndex("pbLink");
|
||||
pbLink.add(cursor.getString(index));
|
||||
index = cursor.getColumnIndex("userID"); // UserID
|
||||
index = cursor.getColumnIndex("userID");
|
||||
userId.add(cursor.getLong(index));
|
||||
index = cursor.getColumnIndex("tweetID"); // tweetID
|
||||
index = cursor.getColumnIndex("tweetID");
|
||||
tweetId.add(cursor.getLong(index));
|
||||
index = cursor.getColumnIndex("retweeter");
|
||||
retweeter.add(cursor.getString(index));
|
||||
size++;
|
||||
} while(cursor.moveToNext() && size < limit);
|
||||
}
|
||||
@ -216,7 +223,6 @@ public class TweetDatabase {
|
||||
}
|
||||
public int getRetweet(int pos){return noRT.get(pos);}
|
||||
public int getFavorite(int pos){return noFav.get(pos);}
|
||||
public int getAnswer(int pos){return noAns.get(pos);}
|
||||
public long getUserID(int pos){return userId.get(pos);}
|
||||
public long getTweetId(int pos){return tweetId.get(pos);}
|
||||
public long getTime(int pos){return timeMillis.get(pos);}
|
||||
@ -227,6 +233,10 @@ public class TweetDatabase {
|
||||
public String getPbLink(int pos){return pbLink.get(pos);}
|
||||
public boolean loadImages(){return toggleImg;}
|
||||
public boolean isVerified(int pos){return verify.get(pos) == 1;}
|
||||
public String getRetweeter(int pos) {
|
||||
if(retweeter.get(pos).trim().isEmpty()) return "";
|
||||
else return " RT @"+retweeter.get(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Time to String
|
||||
@ -260,7 +270,7 @@ public class TweetDatabase {
|
||||
|
||||
private void initialize(Context c) {
|
||||
dataHelper = AppDatabase.getInstance(c);
|
||||
settings = c.getSharedPreferences("settings", 0);
|
||||
SharedPreferences settings = c.getSharedPreferences("settings", 0);
|
||||
limit = settings.getInt("limit", 200);
|
||||
toggleImg = settings.getBoolean("image_load", true);
|
||||
initArray();
|
||||
@ -268,13 +278,20 @@ public class TweetDatabase {
|
||||
|
||||
private void insert(List<Status> stats) {
|
||||
for(Status stat: stats) {
|
||||
Status rtStat = stat.getRetweetedStatus();
|
||||
User usr = stat.getUser();
|
||||
if(rtStat != null) {
|
||||
retweeter.add(usr.getScreenName());
|
||||
stat = rtStat;
|
||||
usr = rtStat.getUser();
|
||||
} else {
|
||||
retweeter.add(" ");
|
||||
}
|
||||
user.add(usr.getName());
|
||||
scrname.add('@'+usr.getScreenName());
|
||||
tweet.add(stat.getText());
|
||||
noRT.add(stat.getRetweetCount());
|
||||
noFav.add(stat.getFavoriteCount());
|
||||
noAns.add(0); // TODO
|
||||
userId.add(usr.getId());
|
||||
pbLink.add(usr.getMiniProfileImageURL());
|
||||
tweetId.add(stat.getId());
|
||||
@ -287,13 +304,20 @@ public class TweetDatabase {
|
||||
private void insertNew(List<Status> stats) {
|
||||
for(int index = stats.size()-1 ; index >=0 ; index--) {
|
||||
Status stat = stats.get(index);
|
||||
Status rtStat = stat.getRetweetedStatus();
|
||||
User usr = stat.getUser();
|
||||
if(rtStat != null) {
|
||||
retweeter.add(usr.getScreenName());
|
||||
stat = rtStat;
|
||||
usr = rtStat.getUser();
|
||||
} else {
|
||||
retweeter.add(0,"\0");
|
||||
}
|
||||
user.add(0,usr.getName());
|
||||
scrname.add(0,'@'+usr.getScreenName());
|
||||
tweet.add(0,stat.getText());
|
||||
noRT.add(0,stat.getRetweetCount());
|
||||
noFav.add(0,stat.getFavoriteCount());
|
||||
noAns.add(0,0); // TODO
|
||||
userId.add(0,usr.getId());
|
||||
pbLink.add(0,usr.getMiniProfileImageURL());
|
||||
tweetId.add(0,stat.getId());
|
||||
@ -309,11 +333,11 @@ public class TweetDatabase {
|
||||
tweet = new ArrayList<>();
|
||||
noRT = new ArrayList<>();
|
||||
noFav = new ArrayList<>();
|
||||
noAns = new ArrayList<>();
|
||||
userId = new ArrayList<>();
|
||||
pbLink = new ArrayList<>();
|
||||
tweetId = new ArrayList<>();
|
||||
verify = new ArrayList<>();
|
||||
retweeter = new ArrayList<>();
|
||||
timeMillis = new ArrayList<>();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
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;
|
||||
@ -71,13 +72,15 @@ public class TimelineAdapter extends ArrayAdapter implements View.OnClickListene
|
||||
((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)) {
|
||||
v.findViewById(R.id.list_verify).setVisibility(View.VISIBLE);
|
||||
verify.setVisibility(ImageView.VISIBLE);
|
||||
} else {
|
||||
v.findViewById(R.id.list_verify).setVisibility(View.INVISIBLE);
|
||||
verify.setVisibility(ImageView.INVISIBLE);
|
||||
}
|
||||
if(mTweets.loadImages()) {
|
||||
Picasso.with(context).load(mTweets.getPbLink(position)).into(pb);
|
||||
|
@ -190,5 +190,6 @@ public class AppSettings extends AppCompatActivity implements View.OnClickListen
|
||||
edit.putBoolean("image_load", imgEnabled);
|
||||
edit.apply();
|
||||
mColor.commit();
|
||||
Toast.makeText(getApplicationContext(), "Gespeichert", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/twitterBlau"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
|
@ -3,7 +3,6 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/twitterBlau"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
@ -21,18 +20,10 @@
|
||||
android:layout_height="match_parent"
|
||||
android:contentDescription="@string/profile_image" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/list_verify"
|
||||
android:layout_width="12dp"
|
||||
android:layout_height="12dp"
|
||||
android:layout_margin="5dp"
|
||||
android:contentDescription="@string/verify"
|
||||
android:visibility="invisible"
|
||||
app:srcCompat="@drawable/verify" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
@ -40,20 +31,31 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/list_verify"
|
||||
android:layout_width="12dp"
|
||||
android:layout_height="12dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_margin="2dp"
|
||||
android:background="@drawable/verify"
|
||||
android:contentDescription="@string/verify" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
android:layout_weight="1"
|
||||
android:singleLine="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_weight="1"
|
||||
android:gravity="end"
|
||||
android:textAlignment="gravity" />
|
||||
android:textAlignment="gravity"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
@ -85,6 +87,13 @@
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/retweeter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/retweet"
|
||||
android:layout_width="16dp"
|
||||
@ -96,7 +105,7 @@
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="5dp"
|
||||
android:ems="10" />
|
||||
android:textSize="12sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/favorite"
|
||||
@ -110,7 +119,7 @@
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="5dp"
|
||||
android:ems="10" />
|
||||
android:textSize="12sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -24,28 +24,27 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_margin="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rt_info"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_weight="1"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/answer_reference_detail"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="12sp"
|
||||
android:visibility="invisible" />
|
||||
</LinearLayout>
|
||||
@ -112,8 +111,8 @@
|
||||
|
||||
<Button
|
||||
android:id="@+id/image_attach"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:background="@drawable/preview"
|
||||
android:visibility="invisible" />
|
||||
|
||||
|
@ -29,9 +29,9 @@
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_margin="2dp"
|
||||
android:background="@drawable/verify"
|
||||
android:contentDescription="@string/verify"
|
||||
android:visibility="invisible"
|
||||
app:srcCompat="@drawable/verify" />
|
||||
android:visibility="invisible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/username_detail"
|
||||
@ -50,9 +50,9 @@
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_margin="2dp"
|
||||
android:background="@drawable/lock"
|
||||
android:contentDescription="@string/profile_locked"
|
||||
android:visibility="invisible"
|
||||
app:srcCompat="@drawable/lock" />
|
||||
android:visibility="invisible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/screenname_detail"
|
||||
|
Loading…
x
Reference in New Issue
Block a user