Added Clickable hashtags & usernames
This commit is contained in:
NudeDude 2018-03-19 20:41:38 +01:00
parent 30e69cdde6
commit f9ac7f6d7c
8 changed files with 54 additions and 17 deletions

View File

@ -242,9 +242,13 @@ public class MainActivity extends AppCompatActivity implements
String search = trend.getData().getTrendname(position);
Intent intent = new Intent(this, SearchPage.class);
Bundle bundle = new Bundle();
bundle.putString("search", search);
if(search.startsWith("#"))
if(search.startsWith("#")) {
bundle.putString("Addition", search);
bundle.putString("search", search);
} else {
search = '\"'+ search + '\"';
bundle.putString("search", search);
}
intent.putExtras(bundle);
startActivity(intent);
}

View File

@ -86,6 +86,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
trendsAdapter.getData().setTrends( mTwitter.getTrends(woeid) );
else
trendsAdapter = new TrendRecycler(new TrendDatabase(mTwitter.getTrends(woeid),ui.get()), ui.get());
trendsAdapter.setColor(font);
break;
case MENT:

View File

@ -9,9 +9,12 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
@ -31,6 +34,7 @@ import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.window.SearchPage;
import org.nuclearfog.twidda.window.TweetDetail;
import org.nuclearfog.twidda.backend.listitems.*;
import org.nuclearfog.twidda.window.UserProfile;
@ -173,7 +177,6 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
TweetDetail connect = ui.get();
if(connect == null)
return;
final Context c = connect;
TextView tweet = (TextView)connect.findViewById(R.id.tweet_detailed);
TextView username = (TextView)connect.findViewById(R.id.usernamedetail);
TextView scrName = (TextView)connect.findViewById(R.id.scrnamedetail);
@ -192,6 +195,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
Button mediabutton = (Button)connect.findViewById(R.id.image_attach);
if(mode == LOAD_TWEET) {
tweet.setMovementMethod(LinkMovementMethod.getInstance());
tweet.setText(highlight(tweetStr));
username.setText(usernameStr);
scrName.setText(scrNameStr);
@ -245,11 +249,11 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
txtAns.setText(ansStr);
}
else if(mode == DELETE) {
Toast.makeText(c, "Tweet gelöscht", Toast.LENGTH_LONG).show();
((TweetDetail)c).finish();
Toast.makeText(ui.get(), "Tweet gelöscht", Toast.LENGTH_LONG).show();
ui.get().finish();
}
else {
Toast.makeText(c, "Fehler beim Laden: "+errMSG, Toast.LENGTH_LONG).show();
Toast.makeText(ui.get(), "Fehler beim Laden: "+errMSG, Toast.LENGTH_LONG).show();
if(ansReload.isRefreshing()) {
ansReload.setRefreshing(false);
}
@ -272,8 +276,8 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
return output.toString();
}
private SpannableStringBuilder highlight(String tweet) {
SpannableStringBuilder sTweet = new SpannableStringBuilder(tweet);
private Spannable highlight(String tweet) {
Spannable sTweet = new SpannableStringBuilder(tweet);
int start = 0;
boolean marked = false;
for(int i = 0 ; i < tweet.length() ; i++) {
@ -296,19 +300,44 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
case '!':
case '?':
case '-':
if(marked) {
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
if(marked && start != i-1) {
sTweet = spanning(sTweet, start, i);
}
marked = false;
break;
}
}
if(marked) {
sTweet.setSpan(new ForegroundColorSpan(highlight),start,tweet.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
if(marked && start != tweet.length()-1) {
sTweet = spanning(sTweet, start, tweet.length());
}
return sTweet;
}
private Spannable spanning(Spannable sTweet, final int start, final int end) {
sTweet.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
TextView tv = (TextView) widget;
Spanned s = (Spanned) tv.getText();
String search = s.subSequence(start, end).toString();
Intent intent = new Intent(ui.get(), SearchPage.class);
Bundle bundle = new Bundle();
if(search.startsWith("#"))
bundle.putString("Addition", search);
bundle.putString("search", search);
intent.putExtras(bundle);
ui.get().startActivity(intent);
}
@Override
public void updateDrawState(TextPaint ds){
ds.setColor(highlight);
ds.setUnderlineText(false);
}
},start,end,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return sTweet;
}
private void setIcons(Button favoriteButton, Button retweetButton) {
if(favorited)
favoriteButton.setBackgroundResource(R.drawable.favorite_enabled);

View File

@ -36,7 +36,7 @@ import twitter4j.conf.ConfigurationBuilder;
public class TwitterEngine {
private final String TWITTER_CONSUMER_KEY = "1JwXJbVrvGWrc9SSKPnnEWslJ";
private final String TWITTER_CONSUMER_SECRET = "GET YOUR OWN!";
private final String TWITTER_CONSUMER_SECRET = "INSERT SECRET"; // TODO
private static TwitterEngine mTwitter;
private static long twitterID;

View File

@ -80,6 +80,7 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
public boolean onCreateOptionsMenu(Menu m) {
getMenuInflater().inflate(R.menu.search, m);
SearchView searchQuery = (SearchView)m.findItem(R.id.new_search).getActionView();
searchQuery.setQueryHint(search);
searchQuery.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {

View File

@ -97,13 +97,13 @@
android:id="@+id/load_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/load_factor" />
android:text="@string/load" />
<CheckBox
android:id="@+id/toggleImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginStart="10dp"
android:text="@string/image" />
</LinearLayout>

View File

@ -44,4 +44,5 @@
<string name="profile_locked">Privates Profil</string>
<string name="load_factor">Ladefaktor</string>
<string name="followback">Folgt dir</string>
<string name="load">Anzahl Tweets</string>
</resources>

View File

@ -3,8 +3,9 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/soylentgreen</item>
<item name="android:windowAnimationStyle">@style/TransactionPending</item>
<item name="android:colorBackground">@color/DarkBlue</item>
<item name="android:windowAnimationStyle">@style/TransactionPending</item>
<item name="android:statusBarColor">@android:color/black</item>
</style>
<style name="Transparency" parent="AppTheme">