mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-02-09 08:38:38 +01:00
initial commit
This commit is contained in:
parent
97a0e3864c
commit
a40d769128
@ -17,16 +17,19 @@ public class AppDatabase extends SQLiteOpenHelper
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(SQLiteDatabase db) {
|
public void onCreate(SQLiteDatabase db) {
|
||||||
String uQuery = c.getString(R.string.user_table);
|
String uQuery = c.getString(R.string.user_table);
|
||||||
String tQuery = c.getString(R.string.tweet_table);
|
String tQuery = c.getString(R.string.tweet_table);
|
||||||
|
String trQuery = c.getString(R.string.trend_table);
|
||||||
db.execSQL(uQuery);
|
db.execSQL(uQuery);
|
||||||
db.execSQL(tQuery);
|
db.execSQL(tQuery);
|
||||||
|
db.execSQL(trQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int 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");
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + "trend");
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,96 @@
|
|||||||
|
package org.nuclearfog.twidda.engine;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import org.nuclearfog.twidda.DataBase.AppDatabase;
|
||||||
|
import org.nuclearfog.twidda.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import twitter4j.Trend;
|
||||||
|
import twitter4j.Trends;
|
||||||
|
|
||||||
|
public class TrendDatabase {
|
||||||
|
|
||||||
|
private AppDatabase dataHelper;
|
||||||
|
private List<String> trendName;
|
||||||
|
private List<String> trendLink;
|
||||||
|
private List<Integer> trendpos;
|
||||||
|
private Trends trends;
|
||||||
|
private int size = 0;
|
||||||
|
private Context c;
|
||||||
|
|
||||||
|
public TrendDatabase(Trends trends, Context c) {
|
||||||
|
this.trends = trends;
|
||||||
|
this.c=c;
|
||||||
|
init();
|
||||||
|
setup();
|
||||||
|
store();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TrendDatabase(Context c){
|
||||||
|
this.c = c;
|
||||||
|
init();
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTrendname(int pos){ return trendName.get(pos); }
|
||||||
|
public String getTrendlink(int pos){return trendLink.get(pos);}
|
||||||
|
public int getTrendpos(int pos){ return trendpos.get(pos); }
|
||||||
|
public int getSize(){
|
||||||
|
if(trendName != null)
|
||||||
|
return trendName.size();
|
||||||
|
else
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load(){
|
||||||
|
SQLiteDatabase data = dataHelper.getReadableDatabase();
|
||||||
|
String SQL_TREND = c.getString(R.string.SQL_TRENS);
|
||||||
|
Cursor cursor = data.rawQuery(SQL_TREND,null);
|
||||||
|
int index;
|
||||||
|
if(cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
index = cursor.getColumnIndex("trendpos"); // trendpos
|
||||||
|
trendpos.add(cursor.getInt(index));
|
||||||
|
index = cursor.getColumnIndex("trendname"); // trendname
|
||||||
|
trendName.add(cursor.getString(index));
|
||||||
|
index = cursor.getColumnIndex("trendlink"); // trendlink
|
||||||
|
trendLink.add(cursor.getString(index));
|
||||||
|
} while(cursor.moveToNext());
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
data.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void store(){
|
||||||
|
SQLiteDatabase data = dataHelper.getWritableDatabase();
|
||||||
|
ContentValues trend = new ContentValues();
|
||||||
|
for(int pos = 0; pos < getSize(); pos++) {
|
||||||
|
trend.put("trendpos", getTrendpos(pos));
|
||||||
|
trend.put("trendname", getTrendname(pos));
|
||||||
|
trend.put("trendlink", getTrendlink(pos));
|
||||||
|
data.insert("trend",null, trend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(){
|
||||||
|
dataHelper = AppDatabase.getInstance(c);
|
||||||
|
trendpos = new ArrayList<>();
|
||||||
|
trendName = new ArrayList<>();
|
||||||
|
trendLink = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup() {
|
||||||
|
for(Trend trend : trends.getTrends()) {
|
||||||
|
trendName.add(trend.getName());
|
||||||
|
trendLink.add(trend.getURL());
|
||||||
|
trendpos.add(++size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -58,8 +58,8 @@ public class TweetDatabase
|
|||||||
ContentValues tl = new ContentValues();
|
ContentValues tl = new ContentValues();
|
||||||
Status stat;
|
Status stat;
|
||||||
User user;
|
User user;
|
||||||
for(int pos = stats.size()-1 ;pos >=0; pos--) {
|
for(int pos = 0; pos < getSize(); pos++) {
|
||||||
// USER
|
// USER TODO UNIQUE
|
||||||
usr.put("userID", getUserID(pos));
|
usr.put("userID", getUserID(pos));
|
||||||
usr.put("username", getUsername(pos));
|
usr.put("username", getUsername(pos));
|
||||||
usr.put("pbLink", getPbImg(pos));
|
usr.put("pbLink", getPbImg(pos));
|
||||||
@ -77,32 +77,35 @@ public class TweetDatabase
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void load() {
|
private void load() {
|
||||||
SQLiteDatabase data = dataHelper.getReadableDatabase();//TODO
|
SQLiteDatabase data = dataHelper.getReadableDatabase();
|
||||||
int index;
|
int index;
|
||||||
String SQL_GET_HOME = c.getString(R.string.SQL_HOME_TL);
|
String SQL_GET_HOME = c.getString(R.string.SQL_HOME_TL);
|
||||||
Cursor cursor = data.rawQuery(SQL_GET_HOME,null);
|
Cursor cursor = data.rawQuery(SQL_GET_HOME,null);
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
while( cursor.moveToNext()) {
|
if(cursor.moveToFirst()) {
|
||||||
index = cursor.getColumnIndex("time"); // time
|
do {
|
||||||
newDate.add(longToDate(cursor.getLong(index)));
|
index = cursor.getColumnIndex("time"); // time
|
||||||
index = cursor.getColumnIndex("tweet"); // tweet
|
newDate.add(longToDate(cursor.getLong(index)));
|
||||||
tweet.add( cursor.getString(index) );
|
index = cursor.getColumnIndex("tweet"); // tweet
|
||||||
index = cursor.getColumnIndex("retweet"); // retweet
|
tweet.add( cursor.getString(index) );
|
||||||
noRT.add( cursor.getString(index) );
|
index = cursor.getColumnIndex("retweet"); // retweet
|
||||||
index = cursor.getColumnIndex("favorite"); // favorite
|
noRT.add( cursor.getString(index) );
|
||||||
noFav.add( cursor.getString(index) );
|
index = cursor.getColumnIndex("favorite"); // favorite
|
||||||
index = cursor.getColumnIndex("answers"); // answers
|
noFav.add( cursor.getString(index) );
|
||||||
noAns.add( cursor.getString(index) );
|
index = cursor.getColumnIndex("answers"); // answers
|
||||||
index = cursor.getColumnIndex("username"); // user
|
noAns.add( cursor.getString(index) );
|
||||||
user.add(cursor.getString(index) );
|
index = cursor.getColumnIndex("username"); // user
|
||||||
index = cursor.getColumnIndex("pbLink"); // image
|
user.add(cursor.getString(index) );
|
||||||
pbLink.add(cursor.getString(index) );
|
index = cursor.getColumnIndex("pbLink"); // image
|
||||||
index = cursor.getColumnIndex("userID"); // UserID
|
pbLink.add(cursor.getString(index) );
|
||||||
userId.add(cursor.getLong(index) );
|
index = cursor.getColumnIndex("userID"); // UserID
|
||||||
index = cursor.getColumnIndex("tweetID"); // tweetID
|
userId.add(cursor.getLong(index) );
|
||||||
tweetId.add(cursor.getLong(index) );
|
index = cursor.getColumnIndex("tweetID"); // tweetID
|
||||||
size++;
|
tweetId.add(cursor.getLong(index) );
|
||||||
|
size++;
|
||||||
|
} while(cursor.moveToNext());
|
||||||
}
|
}
|
||||||
|
cursor.close();
|
||||||
data.close();
|
data.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ import android.widget.Toast;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
import twitter4j.Trends;
|
|
||||||
import twitter4j.Twitter;
|
import twitter4j.Twitter;
|
||||||
import twitter4j.TwitterException;
|
import twitter4j.TwitterException;
|
||||||
import twitter4j.TwitterFactory;
|
import twitter4j.TwitterFactory;
|
||||||
@ -28,8 +27,8 @@ public class TwitterEngine extends AsyncTask<Integer, Void, Void>
|
|||||||
private static Twitter twitter;
|
private static Twitter twitter;
|
||||||
private Context context;
|
private Context context;
|
||||||
private ListView list;
|
private ListView list;
|
||||||
private static TimelineAdapter timelineAdapter;
|
private TimelineAdapter timelineAdapter;
|
||||||
private static TrendsAdapter trendsAdapter;
|
private TrendsAdapter trendsAdapter;
|
||||||
private SwipeRefreshLayout refresh;
|
private SwipeRefreshLayout refresh;
|
||||||
|
|
||||||
public TwitterEngine(Context context, ListView list) {
|
public TwitterEngine(Context context, ListView list) {
|
||||||
@ -59,8 +58,8 @@ public class TwitterEngine extends AsyncTask<Integer, Void, Void>
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case(1): // Trends
|
case(1): // Trends
|
||||||
Trends trend = twitter.getPlaceTrends(1);
|
TrendDatabase trend = new TrendDatabase(twitter.getPlaceTrends(23424829),context); //Germany by default
|
||||||
trendsAdapter = new TrendsAdapter(context,R.layout.tweet,trend.getTrends());
|
trendsAdapter = new TrendsAdapter(context,R.layout.tweet,trend);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case(2): // Mentions
|
case(2): // Mentions
|
||||||
@ -70,7 +69,10 @@ public class TwitterEngine extends AsyncTask<Integer, Void, Void>
|
|||||||
case(3): // Get TIMELINE
|
case(3): // Get TIMELINE
|
||||||
TweetDatabase tweetDeck = new TweetDatabase(context);
|
TweetDatabase tweetDeck = new TweetDatabase(context);
|
||||||
timelineAdapter = new TimelineAdapter(context,R.layout.tweet,tweetDeck);
|
timelineAdapter = new TimelineAdapter(context,R.layout.tweet,tweetDeck);
|
||||||
|
break;
|
||||||
|
case(4): // GET TRENDS
|
||||||
|
TrendDatabase trendDeck = new TrendDatabase(context);
|
||||||
|
trendsAdapter = new TrendsAdapter(context,R.layout.tweet,trendDeck);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (TwitterException e) {
|
} catch (TwitterException e) {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package org.nuclearfog.twidda.engine.ViewAdapter;
|
package org.nuclearfog.twidda.engine.ViewAdapter;
|
||||||
|
|
||||||
|
import org.nuclearfog.twidda.R;
|
||||||
|
import org.nuclearfog.twidda.engine.TrendDatabase;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -7,33 +10,25 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.nuclearfog.twidda.R;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import twitter4j.Location;
|
|
||||||
import twitter4j.ResponseList;
|
|
||||||
import twitter4j.Trend;
|
|
||||||
import twitter4j.Trends;
|
|
||||||
|
|
||||||
public class TrendsAdapter extends ArrayAdapter {
|
public class TrendsAdapter extends ArrayAdapter {
|
||||||
private Trend[] list;
|
private TrendDatabase trend;
|
||||||
private Context c;
|
private Context c;
|
||||||
|
|
||||||
public TrendsAdapter(Context c, int layout, Trend[] list) {
|
public TrendsAdapter(Context c, int layout, TrendDatabase trend) {
|
||||||
super(c, layout);
|
super(c, layout);
|
||||||
this.list = list;
|
this.trend = trend;
|
||||||
this.c = c;
|
this.c = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return list.length;
|
return trend.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
return list[position];
|
return trend.getTrendname(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,7 +38,7 @@ public class TrendsAdapter extends ArrayAdapter {
|
|||||||
LayoutInflater inf=(LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inf=(LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
v = inf.inflate(R.layout.trend, null);
|
v = inf.inflate(R.layout.trend, null);
|
||||||
}
|
}
|
||||||
String trendName = list[position].getName();
|
String trendName = trend.getTrendname(position);
|
||||||
((TextView) v.findViewById(R.id.trendname)).setText(trendName);
|
((TextView) v.findViewById(R.id.trendname)).setText(trendName);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
<string name="register_link">Link zur Anmeldung</string>
|
<string name="register_link">Link zur Anmeldung</string>
|
||||||
|
|
||||||
<!--Datenbank Konstanten -->
|
<!--Datenbank Konstanten -->
|
||||||
|
|
||||||
<string name="user_table">
|
<string name="user_table">
|
||||||
CREATE TABLE IF NOT EXISTS user (
|
CREATE TABLE IF NOT EXISTS user (
|
||||||
userID INTEGER PRIMARY KEY,
|
userID INTEGER PRIMARY KEY,
|
||||||
@ -32,12 +31,19 @@
|
|||||||
FOREIGN KEY (userID) REFERENCES user_table(userID) );
|
FOREIGN KEY (userID) REFERENCES user_table(userID) );
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<string name="trend_table">
|
||||||
|
CREATE TABLE IF NOT EXISTS trend (
|
||||||
|
trendpos INTEGER,
|
||||||
|
trendname TEXT,
|
||||||
|
trendlink TEXT );
|
||||||
|
</string>
|
||||||
|
|
||||||
<string name="SQL_HOME_TL">
|
<string name="SQL_HOME_TL">
|
||||||
"SELECT * FROM tweet INNER JOIN user ON user.userID = tweet.userID ORDER BY time DESC"
|
"SELECT * FROM tweet INNER JOIN user ON user.userID = tweet.userID ORDER BY time DESC"
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="table_column">
|
<string name="SQL_TRENS">
|
||||||
{"tweetID","time","tweet","retweet","favorite","answers","userID"}
|
"SELECT * FROM trend ORDER BY trendpos DESC"
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="datei">timeline.db</string>
|
<string name="datei">timeline.db</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user