initial commit

This commit is contained in:
NudeDude 2017-12-03 19:51:28 +01:00
parent e999eb201c
commit 941bf1f30f
4 changed files with 67 additions and 35 deletions

View File

@ -1,3 +1,7 @@
<component name="ProjectDictionaryState"> <component name="ProjectDictionaryState">
<dictionary name="Sufian" /> <dictionary name="Sufian">
<words>
<w>sqlite</w>
</words>
</dictionary>
</component> </component>

View File

@ -11,7 +11,7 @@ public class AppDatabase extends SQLiteOpenHelper
private Context c; private Context c;
private AppDatabase(Context context) { private AppDatabase(Context context) {
super(context, "twitter",null, 1); super(context, "twitter.sqlite",null, 1);
c = context; c = context;
} }
@ -25,12 +25,10 @@ public class AppDatabase extends SQLiteOpenHelper
@Override @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion != newVersion) { db.execSQL("DROP TABLE IF EXISTS " + "user_table");
db.execSQL("DROP TABLE IF EXISTS " + "user"); db.execSQL("DROP TABLE IF EXISTS " + "tweet_table");
db.execSQL("DROP TABLE IF EXISTS " + "tweet");
onCreate(db); onCreate(db);
} }
}
/** /**
* Singleton Method * Singleton Method

View File

@ -12,10 +12,12 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import twitter4j.Status; import twitter4j.Status;
import twitter4j.User;
public class TweetDatabase { public class TweetDatabase {
private Date now; private Date now;
private List<String> user,tweet,noRT,noFav,noAns,date; private List<String> user,tweet,noRT,noFav,noAns,date, pbLink;
private List<Long> userId, tweetId;
private AppDatabase dataHelper; private AppDatabase dataHelper;
private List<Status> stats; private List<Status> stats;
private Context c; private Context c;
@ -42,7 +44,6 @@ public class TweetDatabase {
dataHelper = AppDatabase.getInstance(c); dataHelper = AppDatabase.getInstance(c);
load(); load();
this.c=c; this.c=c;
} }
private void store() { private void store() {
@ -51,36 +52,54 @@ public class TweetDatabase {
ContentValues tl = new ContentValues(); ContentValues tl = new ContentValues();
Status stat; Status stat;
for(int pos = 0;pos < stats.size(); pos++) User user;
{ for(int pos = 0;pos < stats.size(); pos++) {
stat = stats.get(pos); stat = stats.get(pos);
user = stat.getUser();
// USER // USER
usr.put("userID",stat.getUser().getId() ); usr.put("userID", getUserID(pos));
usr.put("username", stat.getUser().getScreenName()); usr.put("username", getUsername(pos));
usr.put("pbLink",stat.getUser().getProfileImageURL()); usr.put("pbLink", getPbImg(pos));
// TWEET // TWEET
tl.put("userID",stat.getUser().getId() ); tl.put("userID", getUserID(pos));
tl.put("tweetID", stat.getId()); tl.put("tweetID", getTweetId(pos));
tl.put("time", stat.getCreatedAt().toString()); tl.put("time", getDate(pos));
tl.put("tweet", stat.getText()); tl.put("tweet", getTweet(pos));
tl.put("retweet", stat.getRetweetCount()); tl.put("retweet", getRetweet(pos));
tl.put("favorite", stat.getFavoriteCount()); tl.put("favorite", getFavorite(pos));
tl.put("user", stat.getUser().getId());
} }
data.insert("user",null, usr); data.insert("user",null, usr);
data.insert("tweet",null, tl); data.insert("tweet",null, tl);
} }
private void load() { private void load() {
SQLiteDatabase data = dataHelper.getReadableDatabase(); SQLiteDatabase data = dataHelper.getReadableDatabase();//TODO
String col_name[]= new String[] {c.getString(R.string.table_column)};
//Cursor tw = data.query("tweet_table", col_name, ); //TODO String col_name[]= new String[]{"tweetID","time","tweet","retweet","favorite","answers","userID"};//
Cursor cursor = data.rawQuery("SELECT * FROM tweet_table",null);
while( cursor.moveToNext() ) {
int index;
index = cursor.getColumnIndex(col_name[1]); // time
date.add( cursor.getString(index) );
index = cursor.getColumnIndex(col_name[2]); // tweet
tweet.add( cursor.getString(index) );
index = cursor.getColumnIndex(col_name[3]); // retweet
noRT.add( cursor.getString(index) );
index = cursor.getColumnIndex(col_name[4]); // favorite
noFav.add( cursor.getString(index) );
index = cursor.getColumnIndex(col_name[5]); // answers
noAns.add( cursor.getString(index) );
}
data.close();
} }
/** /**
@ -101,12 +120,15 @@ public class TweetDatabase {
date.add(time); date.add(time);
} }
public long getUserID(int pos){return userId.get(pos);}
public String getUsername(int pos){return user.get(pos);} public String getUsername(int pos){return user.get(pos);}
public String getTweet(int pos){return tweet.get(pos);} public String getTweet(int pos){return tweet.get(pos);}
public String getRetweet(int pos){return noRT.get(pos);} public String getRetweet(int pos){return noRT.get(pos);}
public String getFavorite(int pos){return noFav.get(pos);} public String getFavorite(int pos){return noFav.get(pos);}
public String getDate(int pos){return date.get(pos);} public String getDate(int pos){return date.get(pos);}
public String getAnswer(int pos){return noAns.get(pos);} public String getAnswer(int pos){return noAns.get(pos);}
public String getPbImg (int pos){return pbLink.get(pos);}
public long getTweetId(int pos){return tweetId.get(pos);}
public int getSize(){return user.size();} public int getSize(){return user.size();}
private String getTweetTime(Date time) { private String getTweetTime(Date time) {
@ -129,12 +151,16 @@ public class TweetDatabase {
noFav = new ArrayList<>(); noFav = new ArrayList<>();
noAns = new ArrayList<>(); noAns = new ArrayList<>();
date = new ArrayList<>(); date = new ArrayList<>();
userId = new ArrayList<>();
pbLink = new ArrayList<>();
tweetId= new ArrayList<>();
} }
private void fillArray() { private void fillArray() {
Status stat; Status stat;
for(short pos = 0; pos < getSize(); pos++) { for(short pos = 0; pos < getSize(); pos++) {
stat = stats.get(pos); stat = stats.get(pos);
stat.getId();
tweet.add( stat.getText() ); tweet.add( stat.getText() );
noRT.add( Integer.toString(stat.getRetweetCount()) ); noRT.add( Integer.toString(stat.getRetweetCount()) );
noFav.add( Integer.toString(stat.getFavoriteCount()) ); noFav.add( Integer.toString(stat.getFavoriteCount()) );
@ -142,6 +168,9 @@ public class TweetDatabase {
String name = stat.getUser().getScreenName(); String name = stat.getUser().getScreenName();
String twUsr = stat.getUser().getName(); String twUsr = stat.getUser().getName();
user.add( name +" @"+twUsr ); user.add( name +" @"+twUsr );
userId.add(stat.getUser().getId());
pbLink.add(stat.getUser().getProfileImageURL());
tweetId.add(stat.getId());
} }
} }
} }

View File

@ -17,6 +17,7 @@
<string name="user_table"> <string name="user_table">
CREATE TABLE IF NOT EXISTS user ( CREATE TABLE IF NOT EXISTS user (
userID INTEGER NOT NULL PRIMARY KEY, userID INTEGER NOT NULL PRIMARY KEY,
scrname TEXT,
username TEXT, username TEXT,
pbLink TEXT ); pbLink TEXT );
</string> </string>
@ -24,8 +25,8 @@
<string name="tweet_table"> <string name="tweet_table">
CREATE TABLE IF NOT EXISTS tweet ( CREATE TABLE IF NOT EXISTS tweet (
tweetID INTEGER NOT NULL PRIMARY KEY, tweetID INTEGER NOT NULL PRIMARY KEY,
user INTEGER, userID INTEGER,
time TEXT, time DATE,
tweet TEXT, tweet TEXT,
retweet INTEGER, retweet INTEGER,
favorite INTEGER, favorite INTEGER,
@ -34,7 +35,7 @@
</string> </string>
<string name="table_column"> <string name="table_column">
{tweetID,user,time,tweet,retweet,favorite,answers} {"tweetID","time","tweet","retweet","favorite","answers","userID"}
</string> </string>
<string name="datei">timeline.db</string> <string name="datei">timeline.db</string>