diff --git a/app/src/main/java/org/nuclearfog/twidda/DataBase/TweetDatabase.java b/app/src/main/java/org/nuclearfog/twidda/DataBase/TweetDatabase.java index 5b0bfd22..fc1d8db8 100644 --- a/app/src/main/java/org/nuclearfog/twidda/DataBase/TweetDatabase.java +++ b/app/src/main/java/org/nuclearfog/twidda/DataBase/TweetDatabase.java @@ -21,23 +21,25 @@ public class TweetDatabase { private List user,tweet,noRT,noFav,noAns,pbLink; private List userId,tweetId,timeMillis; private List stats; - private Context c; private int size = 0; private int mode = 0; - private long userid = 0; + private long CurrentId = 0; private SharedPreferences settings; /** * Store & Read Data - * @param stats Twitter Home + * @param stats Twitter Status + * @param context Current Activity's Context + * @param mode which type of data should be stored + * @param CurrentId current User ID + * @see #HOME_TL#FAV_TL#USER_TL */ - public TweetDatabase(List stats, Context c, int mode,long userid) { + public TweetDatabase(List stats, Context context, int mode,long CurrentId) { this.stats=stats; - this.c=c; - this.userid = userid; + this.CurrentId = CurrentId; this.mode=mode; - dataHelper = AppDatabase.getInstance(c); - settings = c.getSharedPreferences("settings", 0); + dataHelper = AppDatabase.getInstance(context); + settings = context.getSharedPreferences("settings", 0); initArray(); store(); load(); @@ -45,14 +47,15 @@ public class TweetDatabase { /** * Read Data - * @param c MainActivity Context + * @param context MainActivity Context + * @param mode which type of data should be loaded + * @param CurrentId current User's ID */ - public TweetDatabase(Context c, int mode, long userid) { - this.c=c; - this.userid=userid; + public TweetDatabase(Context context, int mode, long CurrentId) { + this.CurrentId=CurrentId; this.mode=mode; - dataHelper = AppDatabase.getInstance(c); - settings = c.getSharedPreferences("settings", 0); + dataHelper = AppDatabase.getInstance(context); + settings = context.getSharedPreferences("settings", 0); initArray(); load(); } @@ -65,7 +68,6 @@ public class TweetDatabase { ContentValues fav = new ContentValues(); for(int pos = 0; pos < stats.size(); pos++) { - Status stat = stats.get(pos); User usr = stat.getUser(); @@ -77,7 +79,7 @@ public class TweetDatabase { user.put("location",usr.getLocation()); user.put("link",usr.getURL()); - tweet.put("userID", usr.getId()); // this one does not work TODO + tweet.put("userID", usr.getId()); tweet.put("tweetID", stat.getId()); tweet.put("time", stat.getCreatedAt().getTime()); tweet.put("tweet", stat.getText()); @@ -86,8 +88,8 @@ public class TweetDatabase { tweet.put("answers", 0); home.put("tweetID", stat.getId()); - - fav.put("ownerID", userid); + fav.put("tweetID", stat.getId()); + fav.put("ownerID", CurrentId); db.insertWithOnConflict("user",null, user,SQLiteDatabase.CONFLICT_IGNORE); db.insertWithOnConflict("tweet",null, tweet,SQLiteDatabase.CONFLICT_IGNORE); @@ -97,7 +99,6 @@ public class TweetDatabase { db.insertWithOnConflict("timeline",null,home,SQLiteDatabase.CONFLICT_IGNORE); } else if(mode == FAV_TL) { - db.insertWithOnConflict("favorit",null,home,SQLiteDatabase.CONFLICT_IGNORE); db.insertWithOnConflict("favorit",null,fav,SQLiteDatabase.CONFLICT_IGNORE); } } @@ -119,10 +120,10 @@ public class TweetDatabase { SQL_GET_HOME = "SELECT * FROM favorit " + "INNER JOIN tweet ON favorit.tweetID = tweet.tweetID " + "INNER JOIN user ON tweet.userID=user.userID " + - /*"WHERE favorit.ownerID = "+userid+*/" ORDER BY tweet.time DESC"; + "WHERE favorit.ownerID = "+CurrentId+" ORDER BY tweet.time DESC"; } else if(mode==USER_TL) { SQL_GET_HOME = "SELECT * FROM user INNER JOIN tweet ON user.userID = tweet.userID " + - "WHERE user.userID = "+userid+" ORDER BY tweet.time DESC"; + "WHERE user.userID = "+CurrentId+" ORDER BY tweet.time DESC"; } Cursor cursor = db.rawQuery(SQL_GET_HOME,null); @@ -144,7 +145,7 @@ public class TweetDatabase { index = cursor.getColumnIndex("pbLink"); // image pbLink.add(cursor.getString(index) ); index = cursor.getColumnIndex("userID"); // UserID - userId.add(cursor.getLong(index) );long integ = cursor.getLong(index); + userId.add(cursor.getLong(index) ); index = cursor.getColumnIndex("tweetID"); // tweetID tweetId.add(cursor.getLong(index) ); size++; diff --git a/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileTweets.java b/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileTweets.java index ee573d59..0ce336d4 100644 --- a/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileTweets.java +++ b/app/src/main/java/org/nuclearfog/twidda/Engine/ProfileTweets.java @@ -34,6 +34,9 @@ public class ProfileTweets extends AsyncTask { profileFavorits = (ListView)((Profile)context).findViewById(R.id.hf_list); } + /** + * @param id UserID[0] Mode[1] + */ @Override protected Void doInBackground(Long... id) { try { @@ -42,7 +45,7 @@ public class ProfileTweets extends AsyncTask { if(id[1] == 0) { TweetDatabase hTweets = new TweetDatabase(twitter.getUserTimeline(userId), context,TweetDatabase.USER_TL,userId); homeTl = new TimelineAdapter(context,R.layout.tweet,hTweets); - } else if(id[1] == 1) { //FAVORITs + } else if(id[1] == 1) { TweetDatabase fTweets = new TweetDatabase(twitter.getFavorites(userId), context,TweetDatabase.FAV_TL,userId); homeFav = new TimelineAdapter(context,R.layout.tweet,fTweets); } diff --git a/app/src/main/java/org/nuclearfog/twidda/Window/Profile.java b/app/src/main/java/org/nuclearfog/twidda/Window/Profile.java index 03a2997b..e850d0e6 100644 --- a/app/src/main/java/org/nuclearfog/twidda/Window/Profile.java +++ b/app/src/main/java/org/nuclearfog/twidda/Window/Profile.java @@ -34,7 +34,7 @@ public class Profile extends AppCompatActivity { setSupportActionBar(tool); getSupportActionBar().setDisplayShowTitleEnabled(false); userId = getIntent().getExtras().getLong("userID"); - context = getApplicationContext(); + context = getApplicationContext();System.out.println(userId);//TODO homeTweets = (ListView)findViewById(R.id.ht_list); homeFavorits = (ListView)findViewById(R.id.hf_list); initElements();