Base 1.1
This commit is contained in:
parent
ce09df82fe
commit
bcef861c71
|
@ -0,0 +1,82 @@
|
|||
package org.nuclearfog.twidda.Backend;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.nuclearfog.twidda.DataBase.TweetDatabase;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.ViewAdapter.TimelineAdapter;
|
||||
import org.nuclearfog.twidda.Window.TweetDetail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import twitter4j.Query;
|
||||
import twitter4j.QueryResult;
|
||||
import twitter4j.Twitter;
|
||||
|
||||
|
||||
public class ShowStatus extends AsyncTask<Long, Void, Void> {
|
||||
|
||||
private Context c;
|
||||
private Twitter twitter;
|
||||
private ListView replyList;
|
||||
private TextView username,scrName, tweet;
|
||||
private ArrayList<twitter4j.Status> answers;
|
||||
private String usernameStr, scrNameStr, tweetStr;
|
||||
|
||||
public ShowStatus( Context c) {
|
||||
twitter = TwitterResource.getInstance(c).getTwitter();
|
||||
answers = new ArrayList<>();
|
||||
this.c=c;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
replyList = (ListView) ((TweetDetail)c).findViewById(R.id.answer_list);
|
||||
tweet = (TextView) ((TweetDetail)c).findViewById(R.id.tweet_detailed);
|
||||
username = (TextView) ((TweetDetail)c).findViewById(R.id.usernamedetail);
|
||||
scrName = (TextView) ((TweetDetail)c).findViewById(R.id.scrnamedetail);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id TWEET ID
|
||||
*/
|
||||
@Override
|
||||
protected Void doInBackground(Long... id) {
|
||||
long tweetID = id[0];
|
||||
try {
|
||||
twitter4j.Status currentTweet = twitter.showStatus(tweetID);
|
||||
tweetStr = currentTweet.getText();
|
||||
usernameStr = currentTweet.getUser().getName();
|
||||
scrNameStr = currentTweet.getUser().getScreenName();
|
||||
|
||||
Query query = new Query('@'+scrNameStr+" since_id:"+tweetID);
|
||||
query.setCount(10);//TODO
|
||||
QueryResult result= null;
|
||||
do {
|
||||
result = twitter.search(query);
|
||||
List<twitter4j.Status> stats = result.getTweets();
|
||||
|
||||
for(twitter4j.Status reply : stats) {
|
||||
if(reply.getInReplyToStatusId() == tweetID)
|
||||
answers.add(reply);
|
||||
}
|
||||
} while((query = result.nextQuery()) != null);
|
||||
} catch(Exception err){err.printStackTrace();}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
tweet.setText(tweetStr);
|
||||
username.setText(usernameStr);
|
||||
scrName.setText(scrNameStr);
|
||||
|
||||
TweetDatabase tweetDatabase = new TweetDatabase(answers,c);
|
||||
TimelineAdapter tlAdp = new TimelineAdapter(c, tweetDatabase);
|
||||
replyList.setAdapter(tlAdp);
|
||||
}
|
||||
}
|
|
@ -7,13 +7,14 @@ import android.view.View;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.nuclearfog.twidda.Backend.ShowStatus;
|
||||
import org.nuclearfog.twidda.DataBase.TweetDatabase;
|
||||
import org.nuclearfog.twidda.R;
|
||||
|
||||
public class TweetDetail extends AppCompatActivity {
|
||||
|
||||
private TweetDatabase mTweet;
|
||||
private TextView tweet, username;
|
||||
|
||||
private long tweetID;
|
||||
private long userID;
|
||||
|
||||
|
@ -23,8 +24,7 @@ public class TweetDetail extends AppCompatActivity {
|
|||
setContentView(R.layout.tweet_detail);
|
||||
tweetID = getIntent().getExtras().getLong("tweetID");
|
||||
userID = getIntent().getExtras().getLong("userID");
|
||||
tweet = (TextView) findViewById(R.id.tweetdetail);
|
||||
username = (TextView) findViewById(R.id.usernamedetail);
|
||||
|
||||
|
||||
ImageView pb = (ImageView) findViewById(R.id.profileimage_detail);
|
||||
pb.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -40,12 +40,14 @@ public class TweetDetail extends AppCompatActivity {
|
|||
setContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy(){
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void setContent() {
|
||||
mTweet = new TweetDatabase(getApplicationContext(),TweetDatabase.GET_TWEET,tweetID);
|
||||
String scrName = mTweet.getUsername(0)+" "+mTweet.getScreenname(0);
|
||||
tweet.setText(mTweet.getTweet(0));
|
||||
username.setText(scrName);
|
||||
ShowStatus set = new ShowStatus(this);
|
||||
set.execute(tweetID);
|
||||
|
||||
}
|
||||
}
|
|
@ -61,7 +61,8 @@ public class TwitterSearch extends AppCompatActivity {
|
|||
searchTL.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
//TODO
|
||||
int index = searchTL.getPositionForView(view);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -31,18 +31,24 @@
|
|||
android:id="@+id/usernamedetail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp" />
|
||||
android:layout_margin="2dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/scrnamedetail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="2dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timedetail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp" />
|
||||
android:layout_margin="2dp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tweetdetail"
|
||||
android:id="@+id/tweet_detailed"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
|
@ -114,11 +120,4 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/sendanswer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp"
|
||||
android:ems="10"
|
||||
android:inputType="textPersonName" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue