Added 280 Char Support

Added Reply Refreshing
Bugfix
This commit is contained in:
NudeDude 2018-02-11 16:16:46 +01:00
parent 5c4862db71
commit 11c0b046e9
7 changed files with 185 additions and 104 deletions

View File

@ -24,7 +24,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -7,6 +7,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
@ -15,6 +16,7 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.InputStream;
import java.net.URL;
@ -37,26 +39,34 @@ public class ShowStatus extends AsyncTask<Long, Void, Long> {
public static final long FAVORITE = 1;
public static final long DELETE = 2;
public static final long LOAD_TWEET = 3;
public static final long LOAD_REPLY = 4;
private Context c;
private TwitterEngine mTwitter;
private ListView replyList;
private TextView username,scrName,replyName,tweet;
private TextView used_api,txtAns,txtRet,txtFav,date;
private Button retweetButton,favoriteButton;
private ImageView profile_img,tweet_img,tweet_verify;
private ImageView profile_img,tweet_verify;
private List<twitter4j.Status> answers;
private SwipeRefreshLayout ansReload;
private TimelineAdapter tlAdp;
private ImageView[] tweetImg;
private Bitmap[] tweet_btm;
private Bitmap profile_btm;
private String errMSG = "";
private String usernameStr, scrNameStr, tweetStr, dateString;
private String ansStr, rtStr, favStr, repliedUsername, apiName;
private TwitterEngine mTwitter;
private String repliedUsername, apiName;
private boolean retweeted, favorited, toggleImg, verified;
private int rt, fav, ansNo = 0;
private int highlight;
private long userReply, tweetReplyID;
private Bitmap profile_btm, tweet_btm;
public ShowStatus(Context c) {
mTwitter = TwitterEngine.getInstance(c);
answers = new ArrayList<>();
tweet_btm = new Bitmap[4];
tweetImg = new ImageView[4];
SharedPreferences settings = c.getSharedPreferences("settings", 0);
toggleImg = settings.getBoolean("image_load", false);
highlight = ColorPreferences.getInstance(c).getColor(ColorPreferences.HIGHLIGHTING);
@ -75,9 +85,13 @@ public class ShowStatus extends AsyncTask<Long, Void, Long> {
txtRet = (TextView) ((TweetDetail)c).findViewById(R.id.no_rt_detail);
txtFav = (TextView) ((TweetDetail)c).findViewById(R.id.no_fav_detail);
used_api = (TextView) ((TweetDetail)c).findViewById(R.id.used_api);
ansReload = (SwipeRefreshLayout) ((TweetDetail)c).findViewById(R.id.answer_reload);
profile_img = (ImageView) ((TweetDetail)c).findViewById(R.id.profileimage_detail);
tweet_img = (ImageView) ((TweetDetail)c).findViewById(R.id.tweet_image);
tweetImg[0] = (ImageView) ((TweetDetail)c).findViewById(R.id.tweet_image);
tweetImg[1] = (ImageView) ((TweetDetail)c).findViewById(R.id.tweet_image2);
tweetImg[2] = (ImageView) ((TweetDetail)c).findViewById(R.id.tweet_image3);
tweetImg[3] = (ImageView) ((TweetDetail)c).findViewById(R.id.tweet_image4);
tweet_verify =(ImageView)((TweetDetail)c).findViewById(R.id.tweet_verify);
retweetButton = (Button) ((TweetDetail)c).findViewById(R.id.rt_button_detail);
@ -94,32 +108,28 @@ public class ShowStatus extends AsyncTask<Long, Void, Long> {
long mode = data[1];
try {
twitter4j.Status currentTweet = mTwitter.getStatus(tweetID);
scrNameStr = '@'+currentTweet.getUser().getScreenName();
rt = currentTweet.getRetweetCount();
fav = currentTweet.getFavoriteCount();
retweeted = currentTweet.isRetweetedByMe();
favorited = currentTweet.isFavorited();
if(mode == LOAD_TWEET) {
userReply = currentTweet.getInReplyToUserId();
tweetReplyID = currentTweet.getInReplyToStatusId();
verified = currentTweet.getUser().isVerified();
retweeted = currentTweet.isRetweetedByMe();
favorited = currentTweet.isFavorited();
if(mode == LOAD_TWEET) {
tweetStr = currentTweet.getText();
usernameStr = currentTweet.getUser().getName();
scrNameStr = '@'+currentTweet.getUser().getScreenName();
apiName = formatString(currentTweet.getSource());
if(userReply > 0) {
repliedUsername = "Antwort an @"+currentTweet.getInReplyToScreenName();
}
dateString = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss").format(currentTweet.getCreatedAt());
answers = mTwitter.getAnswers(scrNameStr, tweetID);
ansNo = answers.size();
if(toggleImg) {
if(userReply > 0)
repliedUsername = "Antwort an @"+currentTweet.getInReplyToScreenName();
if(toggleImg)
setMedia(currentTweet);
}
} else if(mode == RETWEET) {
else if(mode == RETWEET) {
if(retweeted) {
mTwitter.retweet(tweetID, true);
retweeted = false;
@ -129,7 +139,8 @@ public class ShowStatus extends AsyncTask<Long, Void, Long> {
retweeted = true;
rt++;
}
} else if(mode == FAVORITE) {
}
else if(mode == FAVORITE) {
if(favorited) {
mTwitter.favorite(tweetID, true);
favorited = false;
@ -139,11 +150,19 @@ public class ShowStatus extends AsyncTask<Long, Void, Long> {
favorited = true;
fav++;
}
} else if(mode == DELETE) {
}
else if(mode == LOAD_REPLY) {
tlAdp = (TimelineAdapter) replyList.getAdapter();
if(tlAdp != null)
tweetID = tlAdp.getItemId(0);
answers = mTwitter.getAnswers(scrNameStr, tweetID);
ansNo = answers.size();
}
else if(mode == DELETE) {
mTwitter.deleteTweet(tweetID);
}
} catch(Exception err) {
err.printStackTrace();
errMSG = err.getMessage();
return ERROR;
}
return mode;
@ -152,15 +171,19 @@ public class ShowStatus extends AsyncTask<Long, Void, Long> {
@Override
protected void onPostExecute(Long mode) {
if(mode == LOAD_TWEET) {
ansStr = Integer.toString(ansNo);
rtStr = Integer.toString(rt);
favStr = Integer.toString(fav);
tweet.setText(highlight(tweetStr));
username.setText(usernameStr);
scrName.setText(scrNameStr);
txtAns.setText(ansStr);
date.setText(dateString);
used_api.setText(apiName);
String favStr = Integer.toString(fav);
String rtStr = Integer.toString(rt);
txtFav.setText(favStr);
txtRet.setText(rtStr);
txtAns.setText("0");
setIcons();
if(repliedUsername != null) {
replyName.setText(repliedUsername);
replyName.setVisibility(View.VISIBLE);
@ -168,13 +191,13 @@ public class ShowStatus extends AsyncTask<Long, Void, Long> {
if(verified) {
tweet_verify.setVisibility(View.VISIBLE);
}
TweetDatabase tweetDatabase = new TweetDatabase(answers,c);
TimelineAdapter tlAdp = new TimelineAdapter(c, tweetDatabase);
replyList.setAdapter(tlAdp);
if(toggleImg) {
profile_img.setImageBitmap(profile_btm);
tweet_img.setImageBitmap(tweet_btm);
for(int i = 0 ; i < 4 ; i++) {
tweetImg[i].setImageBitmap(tweet_btm[i]);
}
}
setIcons();
replyName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -187,12 +210,40 @@ public class ShowStatus extends AsyncTask<Long, Void, Long> {
}
});
}
setIcons();
else if(mode == RETWEET) {
String rtStr = Integer.toString(rt);
txtRet.setText(rtStr);
setIcons();
}
else if(mode == FAVORITE) {
String favStr = Integer.toString(fav);
txtFav.setText(favStr);
setIcons();
}
else if(mode == LOAD_REPLY) {
if(tlAdp == null || tlAdp.getCount() == 0) {
TweetDatabase tweetDatabase = new TweetDatabase(answers,c);
tlAdp = new TimelineAdapter(c, tweetDatabase);
replyList.setAdapter(tlAdp);
} else {
TweetDatabase twDb = tlAdp.getData();
twDb.addHot(answers);
tlAdp.notifyDataSetChanged();
ansReload.setRefreshing(false);
}
String ansStr = Integer.toString(ansNo);
txtAns.setText(ansStr);
}
else if(mode == DELETE) {
Toast.makeText(c, "Tweet gelöscht", Toast.LENGTH_LONG).show();
((TweetDetail)c).finish();
}
else {
Toast.makeText(c, "Fehler beim Laden: "+errMSG, Toast.LENGTH_LONG).show();
if(ansReload.isRefreshing()) {
ansReload.setRefreshing(false);
}
}
}
private void setMedia(twitter4j.Status tweet) throws Exception {
@ -201,10 +252,10 @@ public class ShowStatus extends AsyncTask<Long, Void, Long> {
InputStream iStream = new URL(pbLink).openStream();
profile_btm = BitmapFactory.decodeStream(iStream);
if( media.length > 0 ) {
InputStream mediaStream = new URL(media[0].getMediaURL()).openStream();
tweet_btm = BitmapFactory.decodeStream(mediaStream);
byte i = 0;
for(MediaEntity m : media) {
InputStream mediaStream = new URL(m.getMediaURL()).openStream();
tweet_btm[i++] = BitmapFactory.decodeStream(mediaStream);
}
}

View File

@ -350,6 +350,7 @@ public class TwitterEngine {
Query query = new Query("to:"+name+" since_id:"+id+" -filter:retweets");
query.setCount(load);
QueryResult result = twitter.search(query);
List<twitter4j.Status> stats = result.getTweets();

View File

@ -63,14 +63,12 @@ public class TimelineAdapter extends ArrayAdapter implements View.OnClickListene
v.setBackgroundColor(background);
v.setOnClickListener(this);
}
String answerStr = Integer.toString(mTweets.getAnswer(position));
String retweetStr = Integer.toString(mTweets.getRetweet(position));
String favoriteStr = Integer.toString(mTweets.getFavorite(position));
((TextView) v.findViewById(R.id.username)).setText(mTweets.getUsername(position));
((TextView) v.findViewById(R.id.screenname)).setText(mTweets.getScreenname(position));
((TextView) v.findViewById(R.id.tweettext)).setText(highlight(mTweets.getTweet(position)));
((TextView) v.findViewById(R.id.answer_number)).setText(answerStr);
((TextView) v.findViewById(R.id.retweet_number)).setText(retweetStr);
((TextView) v.findViewById(R.id.favorite_number)).setText(favoriteStr);
((TextView) v.findViewById(R.id.time)).setText(mTweets.getDate(position));

View File

@ -4,6 +4,8 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
@ -27,7 +29,7 @@ import static android.content.DialogInterface.BUTTON_POSITIVE;
* @see ShowStatus
*/
public class TweetDetail extends AppCompatActivity implements View.OnClickListener,
AdapterView.OnItemClickListener, DialogInterface.OnClickListener {
AdapterView.OnItemClickListener, DialogInterface.OnClickListener, SwipeRefreshLayout.OnRefreshListener {
private ListView answer_list;
private long tweetID;
@ -48,6 +50,7 @@ public class TweetDetail extends AppCompatActivity implements View.OnClickListen
Button favorite = (Button) findViewById(R.id.fav_button_detail);
Button delete = (Button) findViewById(R.id.delete);
ImageView pb = (ImageView) findViewById(R.id.profileimage_detail);
SwipeRefreshLayout answerReload = (SwipeRefreshLayout) findViewById(R.id.answer_reload);
TextView txtRt = (TextView) findViewById(R.id.no_rt_detail);
TextView txtFav = (TextView) findViewById(R.id.no_fav_detail);
@ -58,6 +61,7 @@ public class TweetDetail extends AppCompatActivity implements View.OnClickListen
answer_list.setOnItemClickListener(this);
favorite.setOnClickListener(this);
retweet.setOnClickListener(this);
answerReload.setOnRefreshListener(this);
answer.setOnClickListener(this);
txtFav.setOnClickListener(this);
txtRt.setOnClickListener(this);
@ -146,17 +150,23 @@ public class TweetDetail extends AppCompatActivity implements View.OnClickListen
startActivity(intent);
}
@Override
public void onRefresh() {
new ShowStatus(this).execute(tweetID, ShowStatus.LOAD_REPLY);
}
private void setContent() {
ColorPreferences mColor = ColorPreferences.getInstance(getApplicationContext());
int backgroundColor = mColor.getColor(ColorPreferences.BACKGROUND);
int fontColor = mColor.getColor(ColorPreferences.FONT_COLOR);
LinearLayout background = (LinearLayout) findViewById(R.id.tweet_detail);
CollapsingToolbarLayout cLayout = (CollapsingToolbarLayout) findViewById(R.id.tweet_detail);
LinearLayout tweetaction = (LinearLayout) findViewById(R.id.tweetbar);
TextView txtTw = (TextView) findViewById(R.id.tweet_detailed);
background.setBackgroundColor(backgroundColor);
cLayout.setBackgroundColor(backgroundColor);
tweetaction.setBackgroundColor(backgroundColor);
answer_list.setBackgroundColor(backgroundColor);
txtTw.setTextColor(fontColor);
new ShowStatus(this).execute(tweetID, ShowStatus.LOAD_TWEET);
new ShowStatus(this).execute(tweetID, ShowStatus.LOAD_REPLY);
}
}

View File

@ -10,23 +10,22 @@
android:id="@+id/user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/tweetPb"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:layout_width="38dp"
android:layout_height="match_parent"
android:contentDescription="@string/profile_image" />
<ImageView
android:id="@+id/list_verify"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginTop="8dp"
android:layout_margin="5dp"
android:contentDescription="@string/verify"
android:visibility="invisible"
app:srcCompat="@drawable/verify" />
@ -34,7 +33,6 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<LinearLayout
@ -81,25 +79,10 @@
android:layout_width="match_parent"
android:layout_height="16dp"
android:layout_marginBottom="5dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:addStatesFromChildren="false"
android:gravity="end"
android:orientation="horizontal">
<Button
android:id="@+id/answer"
android:layout_width="16dp"
android:layout_height="16dp"
android:background="@drawable/chat" />
<TextView
android:id="@+id/answer_number"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_marginStart="5dp"
android:ems="10" />
android:layout_marginStart="10dp"
android:addStatesFromChildren="false"
android:orientation="horizontal">
<Button
android:id="@+id/retweet"
@ -111,7 +94,6 @@
android:id="@+id/retweet_number"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_marginStart="5dp"
android:ems="10" />
@ -119,13 +101,13 @@
android:id="@+id/favorite"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginStart="10dp"
android:background="@drawable/favorite" />
<TextView
android:id="@+id/favorite_number"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_marginStart="5dp"
android:ems="10" />

View File

@ -14,6 +14,7 @@
android:fitsSystemWindows="false">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/tweet_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
@ -21,33 +22,28 @@
app:toolbarId="@+id/tweet_toolbar">
<LinearLayout
android:id="@+id/tweet_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/profileimage_detail"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_margin="5dp"
android:layout_width="56dp"
android:layout_height="56dp"
android:contentDescription="@string/profile_image" />
<ImageView
android:id="@+id/tweet_verify"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="8dp"
android:layout_margin="4dp"
android:contentDescription="@string/verify"
android:visibility="invisible"
app:srcCompat="@drawable/verify" />
@ -55,8 +51,6 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="vertical">
@ -68,9 +62,7 @@
<TextView
android:id="@+id/scrnamedetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp" />
android:layout_height="wrap_content" />
<TextView
android:id="@+id/timedetail"
@ -85,16 +77,12 @@
android:id="@+id/answer_reference_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:visibility="invisible" />
<TextView
android:id="@+id/tweet_detailed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:autoLink="web"
android:linksClickable="true"
android:textSize="24sp" />
@ -103,20 +91,61 @@
android:id="@+id/used_api"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:linksClickable="false"
android:textSize="12sp" />
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/tweet_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:contentDescription="@string/tweet_image"
app:srcCompat="@android:color/black" />
<ImageView
android:id="@+id/tweet_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:contentDescription="@string/tweet_image"
app:srcCompat="@android:color/black" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/tweet_image3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:contentDescription="@string/tweet_image"
app:srcCompat="@android:color/black" />
<ImageView
android:id="@+id/tweet_image4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:contentDescription="@string/tweet_image"
app:srcCompat="@android:color/black" />
</TableRow>
</TableLayout>
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
@ -194,11 +223,21 @@
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/answer_reload"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="@+id/answer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true" />
android:nestedScrollingEnabled="true">
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>