mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-31 19:34:55 +01:00
Added Picasso library
Minor Bugfixes Added Text Highlighting
This commit is contained in:
parent
623fca48a5
commit
f0e3740ca7
@ -7,6 +7,9 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
@ -27,6 +30,7 @@ import twitter4j.Twitter;
|
||||
import org.nuclearfog.twidda.database.TweetDatabase;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.viewadapter.TimelineAdapter;
|
||||
import org.nuclearfog.twidda.window.ColorPreferences;
|
||||
import org.nuclearfog.twidda.window.TweetDetail;
|
||||
|
||||
public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
|
||||
@ -47,6 +51,7 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
|
||||
private boolean retweeted, favorited, toggleImg, rtFlag = false;
|
||||
private SharedPreferences settings;
|
||||
private int load, ansNo = 0;
|
||||
private int highlight;
|
||||
private long userReply, tweetReplyID;
|
||||
private Bitmap profile_btm, tweet_btm;
|
||||
|
||||
@ -56,6 +61,7 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
|
||||
settings = c.getSharedPreferences("settings", 0);
|
||||
load = settings.getInt("preload", 10);
|
||||
toggleImg = settings.getBoolean("image_load", false);
|
||||
highlight = ColorPreferences.getInstance(c).getColor(ColorPreferences.HIGHLIGHTING);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@ -158,7 +164,7 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
|
||||
protected void onPostExecute(Boolean tweetLoaded) {
|
||||
if(tweetLoaded) {
|
||||
ansStr = Integer.toString(ansNo);
|
||||
tweet.setText(tweetStr);
|
||||
tweet.setText(highlight(tweetStr)); //TODO make abstract class
|
||||
username.setText(usernameStr);
|
||||
scrName.setText(scrNameStr);
|
||||
txtAns.setText(ansStr);
|
||||
@ -227,6 +233,39 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
|
||||
return output;
|
||||
}
|
||||
|
||||
private SpannableStringBuilder highlight(String tweet) {
|
||||
SpannableStringBuilder sTweet = new SpannableStringBuilder(tweet);
|
||||
int start = 0;
|
||||
boolean marked = false;
|
||||
for(int i = 0 ; i < tweet.length() ; i++) {
|
||||
char current = tweet.charAt(i);
|
||||
switch(current){
|
||||
case '@':
|
||||
start = i;
|
||||
marked = true;
|
||||
break;
|
||||
case '#':
|
||||
start = i;
|
||||
marked = true;
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
case ':':
|
||||
case ' ':
|
||||
case '.':
|
||||
case ',':
|
||||
if(marked)
|
||||
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
marked = false;
|
||||
break;
|
||||
}
|
||||
if(i == tweet.length()-1 && marked) {
|
||||
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
return sTweet;
|
||||
}
|
||||
|
||||
private void setIcons() {
|
||||
if(favorited) {
|
||||
favoriteButton.setBackgroundResource(R.drawable.favorite_enabled);
|
||||
|
@ -3,6 +3,9 @@ package org.nuclearfog.twidda.viewadapter;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -21,7 +24,7 @@ public class TimelineAdapter extends ArrayAdapter implements View.OnClickListene
|
||||
private TweetDatabase mTweets;
|
||||
private ViewGroup p;
|
||||
private LayoutInflater inf;
|
||||
private int textColor, background;
|
||||
private int textColor, background, highlight;
|
||||
private Context context;
|
||||
|
||||
public TimelineAdapter(Context context, TweetDatabase mTweets) {
|
||||
@ -32,6 +35,7 @@ public class TimelineAdapter extends ArrayAdapter implements View.OnClickListene
|
||||
ColorPreferences mColor = ColorPreferences.getInstance(context);
|
||||
textColor = mColor.getColor(ColorPreferences.FONT_COLOR);
|
||||
background = mColor.getColor(ColorPreferences.BACKGROUND);
|
||||
highlight = mColor.getColor(ColorPreferences.HIGHLIGHTING);
|
||||
}
|
||||
|
||||
public TweetDatabase getAdapter() {
|
||||
@ -58,7 +62,7 @@ public class TimelineAdapter extends ArrayAdapter implements View.OnClickListene
|
||||
|
||||
((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(mTweets.getTweet(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);
|
||||
@ -77,4 +81,37 @@ public class TimelineAdapter extends ArrayAdapter implements View.OnClickListene
|
||||
int position = parent.getPositionForView(v);
|
||||
parent.performItemClick(v,position,0);
|
||||
}
|
||||
|
||||
private SpannableStringBuilder highlight(String tweet) {
|
||||
SpannableStringBuilder sTweet = new SpannableStringBuilder(tweet);
|
||||
int start = 0;
|
||||
boolean marked = false;
|
||||
for(int i = 0 ; i < tweet.length() ; i++) {
|
||||
char current = tweet.charAt(i);
|
||||
switch(current){
|
||||
case '@':
|
||||
start = i;
|
||||
marked = true;
|
||||
break;
|
||||
case '#':
|
||||
start = i;
|
||||
marked = true;
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
case ':':
|
||||
case ' ':
|
||||
case '.':
|
||||
case ',':
|
||||
if(marked)
|
||||
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
marked = false;
|
||||
break;
|
||||
}
|
||||
if(i == tweet.length()-1 && marked) {
|
||||
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
return sTweet;
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@ public class AppSettings extends AppCompatActivity implements View.OnClickListen
|
||||
Button colorButton1 = (Button) findViewById(R.id.color_background);
|
||||
Button colorButton2 = (Button) findViewById(R.id.color_font);
|
||||
Button colorButton3 = (Button) findViewById(R.id.color_tweet);
|
||||
Button colorButton4 = (Button) findViewById(R.id.highlight_color);
|
||||
Button reduce = (Button) findViewById(R.id.less);
|
||||
Button enhance = (Button) findViewById(R.id.more);
|
||||
load_factor = (TextView)findViewById(R.id.number_row);
|
||||
@ -54,6 +55,7 @@ public class AppSettings extends AppCompatActivity implements View.OnClickListen
|
||||
colorButton1.setOnClickListener(this);
|
||||
colorButton2.setOnClickListener(this);
|
||||
colorButton3.setOnClickListener(this);
|
||||
colorButton4.setOnClickListener(this);
|
||||
toggleImg.setOnCheckedChangeListener(this);
|
||||
reduce.setOnClickListener(this);
|
||||
enhance.setOnClickListener(this);
|
||||
@ -61,9 +63,11 @@ public class AppSettings extends AppCompatActivity implements View.OnClickListen
|
||||
int color1 = mColor.getColor(ColorPreferences.BACKGROUND);
|
||||
int color2 = mColor.getColor(ColorPreferences.FONT_COLOR);
|
||||
int color3 = mColor.getColor(ColorPreferences.TWEET_COLOR);
|
||||
int color4 = mColor.getColor(ColorPreferences.HIGHLIGHTING);
|
||||
colorButton1.setBackgroundColor(color1);
|
||||
colorButton2.setBackgroundColor(color2);
|
||||
colorButton3.setBackgroundColor(color3);
|
||||
colorButton4.setBackgroundColor(color4);
|
||||
|
||||
toggleImg.setChecked(settings.getBoolean("image_load",false));
|
||||
|
||||
@ -113,6 +117,9 @@ public class AppSettings extends AppCompatActivity implements View.OnClickListen
|
||||
case R.id.color_tweet:
|
||||
mColor.setColor(ColorPreferences.TWEET_COLOR);
|
||||
break;
|
||||
case R.id.highlight_color:
|
||||
mColor.setColor(ColorPreferences.HIGHLIGHTING);
|
||||
break;
|
||||
case R.id.less:
|
||||
if(row > 10)
|
||||
row -= 10;
|
||||
|
@ -48,7 +48,7 @@ public class ColorPreferences implements OnColorChangedListener, DialogInterface
|
||||
break;
|
||||
case HIGHLIGHTING:
|
||||
highlight = newColor;
|
||||
|
||||
break;
|
||||
case TWEET_COLOR:
|
||||
tweet = newColor;
|
||||
break;
|
||||
@ -60,9 +60,11 @@ public class ColorPreferences implements OnColorChangedListener, DialogInterface
|
||||
Button colorButton1 = (Button)((AppSettings)context).findViewById(R.id.color_background);
|
||||
Button colorButton2 = (Button)((AppSettings)context).findViewById(R.id.color_font);
|
||||
Button colorButton3 = (Button)((AppSettings)context).findViewById(R.id.color_tweet);
|
||||
Button colorButton4 = (Button)((AppSettings)context).findViewById(R.id.highlight_color);
|
||||
colorButton1.setBackgroundColor(background);
|
||||
colorButton2.setBackgroundColor(font);
|
||||
colorButton3.setBackgroundColor(tweet);
|
||||
colorButton4.setBackgroundColor(highlight);
|
||||
}
|
||||
|
||||
public int getColor(final int Mode){
|
||||
@ -76,7 +78,7 @@ public class ColorPreferences implements OnColorChangedListener, DialogInterface
|
||||
case HIGHLIGHTING:
|
||||
return highlight;
|
||||
default:
|
||||
return -1;
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,21 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/highlight_color"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:text="@string/highlight" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -55,14 +70,14 @@
|
||||
android:id="@+id/number_row"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="10dp" />
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginStart="5dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/more"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:background="@drawable/plus" />
|
||||
|
||||
<Button
|
||||
@ -75,7 +90,7 @@
|
||||
android:id="@+id/toggleImg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:text="@string/image" />
|
||||
|
||||
</LinearLayout>
|
||||
@ -98,7 +113,7 @@
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:text="@string/woeid" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -35,4 +35,5 @@
|
||||
<string name="get_link">Link</string>
|
||||
<string name="delete_tweet">Löschen</string>
|
||||
<string name="refresh_dummy">Aktualisieren</string>
|
||||
<string name="highlight">Highlight</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user