From 6654c2c335781ded3ab49e84cbe241ef56c0e72a Mon Sep 17 00:00:00 2001 From: NudeDude Date: Thu, 22 Feb 2018 20:41:55 +0100 Subject: [PATCH] Bugfix --- app/src/main/AndroidManifest.xml | 1 - .../org/nuclearfog/twidda/MainActivity.java | 2 +- .../twidda/backend/ProfileAction.java | 5 +- .../nuclearfog/twidda/backend/ShowStatus.java | 6 +- .../twidda/window/SearchWindow.java | 2 +- .../nuclearfog/twidda/window/TweetPopup.java | 16 ++--- .../nuclearfog/twidda/window/UserProfile.java | 72 ++++++++++--------- app/src/main/res/drawable/tweet_icon.xml | 4 -- app/src/main/res/menu/home.xml | 5 +- app/src/main/res/menu/search.xml | 2 +- 10 files changed, 57 insertions(+), 58 deletions(-) delete mode 100644 app/src/main/res/drawable/tweet_icon.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 40151c0b..fefb14af 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,7 +11,6 @@ android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme" - android:screenOrientation="portrait" android:label="@string/app_name"> /** * @param context Context to Activity - * @param tool Actionbar * @see UserProfile */ - public ProfileAction(Context context, Toolbar tool) { + public ProfileAction(Context context) { this.context=context; - this.tool = tool; SharedPreferences settings = context.getSharedPreferences("settings", 0); imgEnabled = settings.getBoolean("image_load",false); } @@ -80,6 +78,7 @@ public class ProfileAction extends AsyncTask favoritsReload = (SwipeRefreshLayout)((UserProfile)context).findViewById(R.id.homefavorits); profileTweets = (ListView)((UserProfile)context).findViewById(R.id.ht_list); profileFavorits = (ListView)((UserProfile)context).findViewById(R.id.hf_list); + tool = (Toolbar) ((UserProfile)context).findViewById(R.id.profile_toolbar); } @Override diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/ShowStatus.java b/app/src/main/java/org/nuclearfog/twidda/backend/ShowStatus.java index 87d49e8b..e6f62903 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/ShowStatus.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/ShowStatus.java @@ -311,9 +311,9 @@ public class ShowStatus extends AsyncTask { marked = false; break; } - if(i == tweet.length()-1 && marked) { - sTweet.setSpan(new ForegroundColorSpan(highlight),start,tweet.length()-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - } + } + if(marked) { + sTweet.setSpan(new ForegroundColorSpan(highlight),start,tweet.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return sTweet; } diff --git a/app/src/main/java/org/nuclearfog/twidda/window/SearchWindow.java b/app/src/main/java/org/nuclearfog/twidda/window/SearchWindow.java index 9853f9fd..db7d26b0 100644 --- a/app/src/main/java/org/nuclearfog/twidda/window/SearchWindow.java +++ b/app/src/main/java/org/nuclearfog/twidda/window/SearchWindow.java @@ -83,7 +83,7 @@ public class SearchWindow extends AppCompatActivity implements AdapterView.OnIte Bundle b = new Bundle(); b.putLong("TweetID", -1); if(search.startsWith("#")) { - b.putString("Hashtag", search); + b.putString("Addition", search); } intent.putExtras(b); startActivity(intent); diff --git a/app/src/main/java/org/nuclearfog/twidda/window/TweetPopup.java b/app/src/main/java/org/nuclearfog/twidda/window/TweetPopup.java index c887e7af..baf18dc7 100644 --- a/app/src/main/java/org/nuclearfog/twidda/window/TweetPopup.java +++ b/app/src/main/java/org/nuclearfog/twidda/window/TweetPopup.java @@ -28,17 +28,17 @@ public class TweetPopup extends AppCompatActivity implements View.OnClickListene private ImageView tweetImg1,tweetImg2,tweetImg3,tweetImg4; private EditText tweetfield; - private long inReplyId; - private String imgPath, hashtag=""; + private long inReplyId =-1L; + private String imgPath, addition=""; @Override protected void onCreate(Bundle SavedInstance) { super.onCreate(SavedInstance); setContentView(R.layout.tweetwindow); - - inReplyId = getIntent().getExtras().getLong("TweetID"); - if(getIntent().hasExtra("Hashtag")) - hashtag = getIntent().getExtras().getString("Hashtag"); + if(getIntent().hasExtra("TweetID")) + inReplyId = getIntent().getExtras().getLong("TweetID"); + if(getIntent().hasExtra("Addition")) + addition = getIntent().getExtras().getString("Addition"); final int size = LinearLayout.LayoutParams.WRAP_CONTENT; getWindow().setLayout(size, size); @@ -59,7 +59,7 @@ public class TweetPopup extends AppCompatActivity implements View.OnClickListene LinearLayout root = (LinearLayout) findViewById(R.id.tweet_popup); ColorPreferences mColor = ColorPreferences.getInstance(this); root.setBackgroundColor(mColor.getColor(ColorPreferences.TWEET_COLOR)); - tweetfield.setText(hashtag); + tweetfield.setText(addition); } @@ -116,7 +116,7 @@ public class TweetPopup extends AppCompatActivity implements View.OnClickListene } private void showClosingMsg() { - if( !hashtag.equals(tweetfield.getText().toString()) ){ + if( !addition.equals(tweetfield.getText().toString()) ){ AlertDialog.Builder alerta = new AlertDialog.Builder(this); alerta.setMessage("Tweet verwerfen?"); alerta.setPositiveButton(R.string.yes_confirm, this); diff --git a/app/src/main/java/org/nuclearfog/twidda/window/UserProfile.java b/app/src/main/java/org/nuclearfog/twidda/window/UserProfile.java index 3fd011b7..bc8c7105 100644 --- a/app/src/main/java/org/nuclearfog/twidda/window/UserProfile.java +++ b/app/src/main/java/org/nuclearfog/twidda/window/UserProfile.java @@ -28,9 +28,9 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener, TabHost.OnTabChangeListener, AppBarLayout.OnOffsetChangedListener { + private ProfileAction mProfile, mTweets, mFavorits; private SwipeRefreshLayout homeReload, favoriteReload; private ListView homeTweets, homeFavorits; - private Toolbar tool; private long userId; private boolean home; private String currentTab = "tweets"; @@ -39,7 +39,7 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen protected void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); setContentView(R.layout.profile); - tool = (Toolbar) findViewById(R.id.profile_toolbar); + Toolbar tool = (Toolbar) findViewById(R.id.profile_toolbar); setSupportActionBar(tool); if(getSupportActionBar() != null) getSupportActionBar().setDisplayShowTitleEnabled(false); @@ -53,18 +53,7 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen homeReload = (SwipeRefreshLayout) findViewById(R.id.hometweets); favoriteReload = (SwipeRefreshLayout) findViewById(R.id.homefavorits); TabHost mTab = (TabHost)findViewById(R.id.profile_tab); - mTab.setup(); - // Tab #1 - TabHost.TabSpec tab1 = mTab.newTabSpec("tweets"); - tab1.setContent(R.id.hometweets); - tab1.setIndicator("",getResources().getDrawable(R.drawable.home)); - mTab.addTab(tab1); - // Tab #2 - TabHost.TabSpec tab2 = mTab.newTabSpec("favorites"); - tab2.setContent(R.id.homefavorits); - tab2.setIndicator("",getResources().getDrawable(R.drawable.favorite)); - mTab.addTab(tab2); - + setTabs(mTab); mTab.setOnTabChangedListener(this); txtFollowing.setOnClickListener(this); txtFollower.setOnClickListener(this); @@ -76,6 +65,14 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen getContent(); } + @Override + protected void onDestroy() { + mProfile.cancel(true); + mTweets.cancel(true); + mFavorits.cancel(true); + super.onDestroy(); + } + @Override public boolean onCreateOptionsMenu(Menu m) { getMenuInflater().inflate(R.menu.profile, m); @@ -89,28 +86,17 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen @Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent; - ProfileAction action = new ProfileAction(this, tool); + mProfile = new ProfileAction(this); switch(item.getItemId()) { case R.id.profile_tweet: intent = new Intent(this, TweetPopup.class); - Bundle b = new Bundle(); - if(home) { - b.putLong("TweetID", -1); - } else { - b.putLong("TweetID", userId); - } - intent.putExtras(b); startActivity(intent); return true; case R.id.profile_follow: - if(!home) { - action.execute(userId, ProfileAction.ACTION_FOLLOW); - } + mProfile.execute(userId, ProfileAction.ACTION_FOLLOW); return true; case R.id.profile_block: - if(!home) { - action.execute(userId, ProfileAction.ACTION_MUTE); - } + mProfile.execute(userId, ProfileAction.ACTION_MUTE); return true; default: return false; } @@ -164,13 +150,14 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen @Override public void onRefresh() { - ProfileAction tweets = new ProfileAction(this, tool); switch(currentTab) { case "tweets": - tweets.execute(userId, ProfileAction.GET_TWEETS,1L); + mTweets = new ProfileAction(this); + mTweets.execute(userId, ProfileAction.GET_TWEETS,1L); break; case "favorites": - tweets.execute(userId, ProfileAction.GET_FAVS,1L); + mFavorits = new ProfileAction(this); + mFavorits.execute(userId, ProfileAction.GET_FAVS,1L); break; } } @@ -194,21 +181,37 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen } } + private void setTabs(TabHost mTab) { + mTab.setup(); + // Tab #1 + TabHost.TabSpec tab1 = mTab.newTabSpec("tweets"); + tab1.setContent(R.id.hometweets); + tab1.setIndicator("",getResources().getDrawable(R.drawable.home)); + mTab.addTab(tab1); + // Tab #2 + TabHost.TabSpec tab2 = mTab.newTabSpec("favorites"); + tab2.setContent(R.id.homefavorits); + tab2.setIndicator("",getResources().getDrawable(R.drawable.favorite)); + mTab.addTab(tab2); + } + /** * Tab Content */ private void getContent() { TweetDatabase mTweet = new TweetDatabase(UserProfile.this, TweetDatabase.USER_TL, userId); TweetDatabase fTweet = new TweetDatabase(UserProfile.this, TweetDatabase.FAV_TL, userId); + mTweets = new ProfileAction(this); + mFavorits = new ProfileAction(this); if( mTweet.getSize() > 0 ) { homeTweets.setAdapter(new TimelineAdapter(UserProfile.this,mTweet)); }else { - new ProfileAction(this, tool).execute(userId, ProfileAction.GET_TWEETS,1L); + mTweets.execute(userId, ProfileAction.GET_TWEETS,1L); } if( fTweet.getSize() > 0 ) { homeFavorits.setAdapter(new TimelineAdapter(UserProfile.this,fTweet)); } else { - new ProfileAction(this, tool).execute(userId, ProfileAction.GET_FAVS,1L); + mFavorits.execute(userId, ProfileAction.GET_FAVS,1L); } } @@ -216,7 +219,8 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen * Profile Information */ private void initElements() { - new ProfileAction(this, tool).execute(userId, ProfileAction.GET_INFORMATION,1L); + mProfile = new ProfileAction(this); + mProfile.execute(userId, ProfileAction.GET_INFORMATION,1L); } /** diff --git a/app/src/main/res/drawable/tweet_icon.xml b/app/src/main/res/drawable/tweet_icon.xml deleted file mode 100644 index bc6585b5..00000000 --- a/app/src/main/res/drawable/tweet_icon.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/app/src/main/res/menu/home.xml b/app/src/main/res/menu/home.xml index 79d98a32..47f20507 100644 --- a/app/src/main/res/menu/home.xml +++ b/app/src/main/res/menu/home.xml @@ -1,10 +1,11 @@ - diff --git a/app/src/main/res/menu/search.xml b/app/src/main/res/menu/search.xml index 580447ca..aa08ed9f 100644 --- a/app/src/main/res/menu/search.xml +++ b/app/src/main/res/menu/search.xml @@ -4,7 +4,7 @@