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
577d80b182
commit
04657aa041
@ -0,0 +1,74 @@
|
||||
package org.nuclearfog.twidda.DataBase;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.engine.TweetDatabase;
|
||||
|
||||
|
||||
public class AppDatabase extends SQLiteOpenHelper
|
||||
{
|
||||
private static AppDatabase mData;
|
||||
private Context context;
|
||||
|
||||
private AppDatabase(Context context) {
|
||||
super(context, "twitter",null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
String uQuery = context.getString(R.string.user_table);
|
||||
String tQuery = context.getString(R.string.tweet_table);
|
||||
db.execSQL(uQuery);
|
||||
db.execSQL(tQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
if (oldVersion != newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + "user");
|
||||
db.execSQL("DROP TABLE IF EXISTS " + "tweet");
|
||||
onCreate(db);
|
||||
}
|
||||
}
|
||||
|
||||
public void commit(TweetDatabase mTweet) {
|
||||
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
|
||||
|
||||
db.endTransaction();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public TweetDatabase read(){
|
||||
TweetDatabase mTweet = new TweetDatabase();
|
||||
|
||||
|
||||
|
||||
return mTweet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Singleton Method
|
||||
* @param context Application Context
|
||||
* @return mData Object of this class
|
||||
*/
|
||||
public static synchronized AppDatabase getInstance(Context context) {
|
||||
if (mData == null) {
|
||||
mData = new AppDatabase(context.getApplicationContext());
|
||||
}
|
||||
return mData;
|
||||
}
|
||||
}
|
@ -3,36 +3,54 @@ package org.nuclearfog.twidda.engine;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import android.content.Context;
|
||||
import twitter4j.Status;
|
||||
|
||||
public class TweetDatabase {
|
||||
|
||||
private Context context;
|
||||
private Date now;
|
||||
private int size;
|
||||
|
||||
private Date now;
|
||||
private List<String> user,tweet,noRT,noFav,noAns,date;
|
||||
|
||||
/**
|
||||
* Daten speichern & aufrufen
|
||||
* @param context MainActivity Context
|
||||
* @param stats Twitter Home
|
||||
*/
|
||||
public TweetDatabase(Context context, List<Status> stats) {
|
||||
this.context=context;
|
||||
this.size = stats.size();
|
||||
public TweetDatabase(List<Status> stats) {
|
||||
initArray();
|
||||
fillArray(stats);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Manually Data using setData()
|
||||
*/
|
||||
public TweetDatabase() {
|
||||
initArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Data
|
||||
* @param usr Username
|
||||
* @param tw Tweet
|
||||
* @param rt Number Retweets
|
||||
* @param fav Number Favorites
|
||||
* @param time Tweet Time
|
||||
* @param ans Number Answers
|
||||
*/
|
||||
public void setData(String usr,String tw,String rt,String fav,String time,String ans) {
|
||||
user.add(usr);
|
||||
tweet.add(tw);
|
||||
noRT.add(rt);
|
||||
noFav.add(fav);
|
||||
noAns.add(ans);
|
||||
date.add(time);
|
||||
}
|
||||
|
||||
public String getUsername(int pos) {return user.get(pos);}
|
||||
public String getTweet(int pos){return tweet.get(pos);}
|
||||
public String getRetweet(int pos){return noRT.get(pos);}
|
||||
public String getFavorite(int pos){return noFav.get(pos);}
|
||||
public String getDate(int pos){return date.get(pos);}
|
||||
public String getAnswer(int pos){return "";/* TODO */}
|
||||
public int getSize(){return size;}
|
||||
public String getAnswer(int pos){return noAns.get(pos);}
|
||||
public int getSize(){return user.size();}
|
||||
|
||||
private String getTweetTime(Date time) {
|
||||
int tweetHour = now.getHours() - time.getHours();
|
||||
|
@ -50,7 +50,7 @@ public class TwitterEngine extends AsyncTask<Integer, Void, Void>
|
||||
try {
|
||||
switch(args[0]) {
|
||||
case (0): // Home Timeline
|
||||
TweetDatabase mTweets = new TweetDatabase(context,twitter.getHomeTimeline());
|
||||
TweetDatabase mTweets = new TweetDatabase(twitter.getHomeTimeline());
|
||||
timelineAdapter = new TimelineAdapter(context,R.layout.tweet,mTweets);
|
||||
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user