From 2fd7414d1f6ad567d85a970db0a0dd5ffe3bd027 Mon Sep 17 00:00:00 2001 From: NudeDude Date: Sun, 31 Mar 2019 15:55:22 +0200 Subject: [PATCH] bug fix --- .../twidda/backend/StatusLoader.java | 232 ++++++++++-------- .../nuclearfog/twidda/window/TweetDetail.java | 26 +- app/src/main/res/layout/page_tweet.xml | 25 +- 3 files changed, 169 insertions(+), 114 deletions(-) diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java b/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java index 58e886e8..24592443 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java @@ -22,6 +22,7 @@ import org.nuclearfog.twidda.backend.items.Tweet; import org.nuclearfog.twidda.database.DatabaseAdapter; import org.nuclearfog.twidda.database.GlobalSettings; import org.nuclearfog.twidda.window.TweetDetail; +import org.nuclearfog.twidda.window.UserProfile; import java.lang.ref.WeakReference; import java.text.NumberFormat; @@ -56,61 +57,61 @@ public class StatusLoader extends AsyncTask { private Tweet tweet; private int highlight, font_color; private boolean toggleImg, toggleAns; + private long homeId; public StatusLoader(@NonNull TweetDetail context, Mode mode) { mTwitter = TwitterEngine.getInstance(context); GlobalSettings settings = GlobalSettings.getInstance(context); + RecyclerView replyList = context.findViewById(R.id.answer_list); + answerAdapter = (TimelineAdapter) replyList.getAdapter(); + database = new DatabaseAdapter(context); sdf = settings.getDateFormatter(); formatter = NumberFormat.getIntegerInstance(); font_color = settings.getFontColor(); highlight = settings.getHighlightColor(); toggleImg = settings.getImageLoad(); toggleAns = settings.getAnswerLoad(); + homeId = settings.getUserId(); ui = new WeakReference<>(context); answers = new ArrayList<>(); this.mode = mode; - RecyclerView replyList = context.findViewById(R.id.answer_list); - answerAdapter = (TimelineAdapter) replyList.getAdapter(); - database = new DatabaseAdapter(context); } @Override protected void onPreExecute() { if (ui.get() == null) return; - if (toggleAns) { + if (mode == Mode.LOAD && toggleAns) { SwipeRefreshLayout ansReload = ui.get().findViewById(R.id.answer_reload); ansReload.setRefreshing(true); } } /** - * @param data [0] TWEET ID , [1] Mode + * @param data [0] TWEET ID */ @Override protected Void doInBackground(Long... data) { final long TWEETID = data[0]; long sinceId = TWEETID; - try { switch (mode) { case LOAD: - case ANS: - if (database.containStatus(TWEETID) && answerAdapter.getItemCount() == 0) { - tweet = database.getStatus(TWEETID); + tweet = database.getStatus(TWEETID); + if(tweet != null) { answers = database.getAnswers(TWEETID); publishProgress(); } + case ANS: tweet = mTwitter.getStatus(TWEETID); - if (toggleAns || mode == Mode.ANS) { + if (mode == Mode.ANS || toggleAns) { if (answerAdapter.getItemCount() > 0) sinceId = answerAdapter.getItemId(0); answers = mTwitter.getAnswers(tweet.getUser().getScreenname(), TWEETID, sinceId); - } else { - answers = new ArrayList<>(); } publishProgress(); + if (database.containStatus(TWEETID)) { database.updateStatus(tweet); if (!answers.isEmpty()) @@ -126,6 +127,7 @@ public class StatusLoader extends AsyncTask { case RETWEET: tweet = mTwitter.retweet(TWEETID); publishProgress(); + database.updateStatus(tweet); if (!tweet.retweeted()) database.removeRetweet(TWEETID); @@ -155,12 +157,131 @@ public class StatusLoader extends AsyncTask { return null; } + + @Override + protected void onProgressUpdate(Void... v) { + if (ui.get() == null) return; + + if(mode == Mode.LOAD) { + TextView tweetText = ui.get().findViewById(R.id.tweet_detailed); + TextView date = ui.get().findViewById(R.id.timedetail); + TextView used_api = ui.get().findViewById(R.id.used_api); + View tweet_verify = ui.get().findViewById(R.id.tweet_verify); + View tweet_locked = ui.get().findViewById(R.id.tweet_locked); + + Spannable sTweet = Tagger.makeText(tweet.getTweet(), highlight, ui.get()); + tweetText.setMovementMethod(LinkMovementMethod.getInstance()); + tweetText.setText(sTweet); + tweetText.setTextColor(font_color); + date.setText(sdf.format(tweet.getTime())); + date.setTextColor(font_color); + used_api.setText(R.string.sent_from); + used_api.append(tweet.getSource()); + used_api.setTextColor(font_color); + + if (tweet.getUser().isVerified()) { + tweet_verify.setVisibility(View.VISIBLE); + } + if (tweet.getUser().isLocked()) { + tweet_locked.setVisibility(View.VISIBLE); + } + if (tweet.getMediaLinks() != null && tweet.getMediaLinks().length != 0) { + View mediaButton = ui.get().findViewById(R.id.image_attach); + mediaButton.setVisibility(View.VISIBLE); + if(!mediaButton.isClickable()) { + mediaButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ui.get().imageClick(tweet.getMediaLinks()); + } + }); + } + } + } + + TextView username = ui.get().findViewById(R.id.usernamedetail); + TextView scrName = ui.get().findViewById(R.id.scrnamedetail); + TextView replyName = ui.get().findViewById(R.id.answer_reference_detail); + TextView txtRet = ui.get().findViewById(R.id.no_rt_detail); + TextView txtFav = ui.get().findViewById(R.id.no_fav_detail); + TextView txtAns = ui.get().findViewById(R.id.no_ans_detail); + ImageView profile_img = ui.get().findViewById(R.id.profileimage_detail); + ImageView retweetButton = ui.get().findViewById(R.id.rt_button_detail); + ImageView favoriteButton = ui.get().findViewById(R.id.fav_button_detail); + + username.setText(tweet.getUser().getUsername()); + username.setTextColor(font_color); + scrName.setText(tweet.getUser().getScreenname()); + scrName.setTextColor(font_color); + + txtFav.setText(formatter.format(tweet.getFavorCount())); + txtRet.setText(formatter.format(tweet.getRetweetCount())); + txtAns.setText(formatter.format(answerAdapter.getItemCount() + answers.size())); + + if (tweet.getReplyId() > 1) { + String reply = ui.get().getString(R.string.answering); + reply += tweet.getReplyName(); + replyName.setText(reply); + replyName.setVisibility(View.VISIBLE); + if(!replyName.isClickable()) { + replyName.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(ui.get(), TweetDetail.class); + intent.putExtra("tweetID", tweet.getReplyId()); + intent.putExtra("userID", tweet.getReplyUserId()); + intent.putExtra("username", tweet.getReplyName()); + ui.get().startActivity(intent); + } + }); + } + } + + if(!profile_img.isClickable()) { + profile_img.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent profile = new Intent(ui.get(), UserProfile.class); + profile.putExtra("userID", tweet.getUser().getId()); + profile.putExtra("username", tweet.getUser().getUsername()); + ui.get().startActivity(profile); + } + }); + } + + if (toggleImg) { + Picasso.get().load(tweet.getUser().getImageLink() + "_bigger").into(profile_img); + } + if (tweet.retweeted()) { + retweetButton.setImageResource(R.drawable.retweet_enabled); + } else { + retweetButton.setImageResource(R.drawable.retweet); + } + if (tweet.favored()) { + favoriteButton.setImageResource(R.drawable.favorite_enabled); + } else { + favoriteButton.setImageResource(R.drawable.favorite); + } + if(tweet.getUser().getId() == homeId) { + ui.get().setOptionsmenu(); + } + if(!answers.isEmpty()) { + SwipeRefreshLayout ansReload = ui.get().findViewById(R.id.answer_reload); + ansReload.setRefreshing(false); + answerAdapter.setData(answers); + answerAdapter.notifyDataSetChanged(); + } + } + + @Override protected void onPostExecute(Void v) { if (ui.get() == null) return; - SwipeRefreshLayout ansReload = ui.get().findViewById(R.id.answer_reload); - ansReload.setRefreshing(false); + if(answers.isEmpty()) { + SwipeRefreshLayout ansReload = ui.get().findViewById(R.id.answer_reload); + ansReload.setRefreshing(false); + } if (!failure) { if (mode == Mode.DELETE) { @@ -178,89 +299,6 @@ public class StatusLoader extends AsyncTask { } - @Override - protected void onProgressUpdate(Void... v) { - if (ui.get() == null) return; - - TextView tweetText = ui.get().findViewById(R.id.tweet_detailed); - TextView username = ui.get().findViewById(R.id.usernamedetail); - TextView scrName = ui.get().findViewById(R.id.scrnamedetail); - TextView date = ui.get().findViewById(R.id.timedetail); - TextView replyName = ui.get().findViewById(R.id.answer_reference_detail); - TextView used_api = ui.get().findViewById(R.id.used_api); - TextView txtRet = ui.get().findViewById(R.id.no_rt_detail); - TextView txtFav = ui.get().findViewById(R.id.no_fav_detail); - TextView txtAns = ui.get().findViewById(R.id.no_ans_detail); - ImageView profile_img = ui.get().findViewById(R.id.profileimage_detail); - ImageView retweetButton = ui.get().findViewById(R.id.rt_button_detail); - ImageView favoriteButton = ui.get().findViewById(R.id.fav_button_detail); - View mediaButton = ui.get().findViewById(R.id.image_attach); - View tweet_verify = ui.get().findViewById(R.id.tweet_verify); - - Spannable sTweet = Tagger.makeText(tweet.getTweet(), highlight, ui.get()); - tweetText.setMovementMethod(LinkMovementMethod.getInstance()); - tweetText.setText(sTweet); - tweetText.setTextColor(font_color); - username.setText(tweet.getUser().getUsername()); - username.setTextColor(font_color); - scrName.setText(tweet.getUser().getScreenname()); - scrName.setTextColor(font_color); - date.setText(sdf.format(tweet.getTime())); - date.setTextColor(font_color); - used_api.setText(R.string.sent_from); - used_api.append(tweet.getSource()); - used_api.setTextColor(font_color); - - txtFav.setText(formatter.format(tweet.getFavorCount())); - txtRet.setText(formatter.format(tweet.getRetweetCount())); - txtAns.setText(formatter.format(answerAdapter.getItemCount() + answers.size())); - - if (tweet.getReplyId() > 1) { - String reply = ui.get().getString(R.string.answering); - reply += tweet.getReplyName(); - replyName.setText(reply); - replyName.setVisibility(View.VISIBLE); - replyName.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(ui.get(), TweetDetail.class); - intent.putExtra("tweetID", tweet.getReplyId()); - intent.putExtra("userID", tweet.getReplyUserId()); - intent.putExtra("username", tweet.getReplyName()); - ui.get().startActivity(intent); - } - }); - } - if (tweet.getMediaLinks() != null && tweet.getMediaLinks().length != 0) { - mediaButton.setVisibility(View.VISIBLE); - mediaButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - ui.get().imageClick(tweet.getMediaLinks()); - } - }); - } - if (tweet.getUser().isVerified()) { - tweet_verify.setVisibility(View.VISIBLE); - } - if (toggleImg) { - Picasso.get().load(tweet.getUser().getImageLink() + "_bigger").into(profile_img); - } - if (tweet.retweeted()) { - retweetButton.setImageResource(R.drawable.retweet_enabled); - } else { - retweetButton.setImageResource(R.drawable.retweet); - } - if (tweet.favored()) { - favoriteButton.setImageResource(R.drawable.favorite_enabled); - } else { - favoriteButton.setImageResource(R.drawable.favorite); - } - answerAdapter.setData(answers); - answerAdapter.notifyDataSetChanged(); - } - - @Override protected void onCancelled() { if (ui.get() == null) return; diff --git a/app/src/main/java/org/nuclearfog/twidda/window/TweetDetail.java b/app/src/main/java/org/nuclearfog/twidda/window/TweetDetail.java index 5c906066..677fcac5 100644 --- a/app/src/main/java/org/nuclearfog/twidda/window/TweetDetail.java +++ b/app/src/main/java/org/nuclearfog/twidda/window/TweetDetail.java @@ -57,7 +57,6 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, private ConnectivityManager mConnect; private String username = ""; private boolean isHome; - private long userID = 0; private long tweetID = 0; @@ -69,7 +68,6 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, Bundle param = getIntent().getExtras(); if (param != null) { tweetID = param.getLong("tweetID"); - userID = param.getLong("userID"); username = param.getString("username"); } @@ -79,7 +77,6 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, getSupportActionBar().setDisplayShowTitleEnabled(false); settings = GlobalSettings.getInstance(this); - isHome = userID == settings.getUserId(); mConnect = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); View root = findViewById(R.id.tweet_layout); @@ -87,7 +84,6 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, View favorite = findViewById(R.id.fav_button_detail); View txtRt = findViewById(R.id.no_rt_detail); View txtFav = findViewById(R.id.no_fav_detail); - View profile_img = findViewById(R.id.profileimage_detail); View answer = findViewById(R.id.answer_button); TextView tweetTxt = findViewById(R.id.tweet_detailed); answerReload = findViewById(R.id.answer_reload); @@ -102,7 +98,6 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, answerReload.setOnRefreshListener(this); txtFav.setOnClickListener(this); txtRt.setOnClickListener(this); - profile_img.setOnClickListener(this); answer.setOnClickListener(this); } @@ -140,9 +135,15 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, @Override public boolean onCreateOptionsMenu(Menu m) { getMenuInflater().inflate(R.menu.tweet, m); + return super.onCreateOptionsMenu(m); + } + + + @Override + public boolean onPrepareOptionsMenu(Menu m) { if (isHome) m.findItem(R.id.delete_tweet).setVisible(true); - return super.onCreateOptionsMenu(m); + return super.onPrepareOptionsMenu(m); } @@ -224,13 +225,6 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, startActivity(favorit); break; - case R.id.profileimage_detail: - Intent profile = new Intent(this, UserProfile.class); - profile.putExtra("userID", userID); - profile.putExtra("username", username); - startActivity(profile); - break; - case R.id.answer_button: Intent tweet = new Intent(this, TweetPopup.class); tweet.putExtra("TweetID", tweetID); @@ -274,4 +268,10 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, image.putExtra("link", mediaLinks); startActivity(image); } + + + public void setOptionsmenu() { + isHome = true; + invalidateOptionsMenu(); + } } \ No newline at end of file diff --git a/app/src/main/res/layout/page_tweet.xml b/app/src/main/res/layout/page_tweet.xml index 0a5ac809..ff73b9dc 100644 --- a/app/src/main/res/layout/page_tweet.xml +++ b/app/src/main/res/layout/page_tweet.xml @@ -82,11 +82,28 @@ android:singleLine="true" /> - + android:layout_height="match_parent" + android:orientation="horizontal"> + + + + +