This commit is contained in:
NudeDude 2018-08-12 11:40:53 +02:00
parent f172153585
commit caee4813fe
14 changed files with 131 additions and 175 deletions

View File

@ -21,7 +21,6 @@ import android.widget.TabHost.TabSpec;
import org.nuclearfog.twidda.backend.GlobalSettings;
import org.nuclearfog.twidda.backend.MainPage;
import org.nuclearfog.twidda.backend.TwitterEngine;
import org.nuclearfog.twidda.backend.listitems.Tweet;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.viewadapter.TrendRecycler;
@ -53,9 +52,9 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainpage);
TwitterEngine mTwitter = TwitterEngine.getInstance(this);
settings = GlobalSettings.getInstance(this);
boolean login = mTwitter.loggedIn();
boolean login = settings.getLogin();
if( !login ) {
Intent i = new Intent(this, LoginPage.class);
@ -128,9 +127,7 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
@Override
public boolean onQueryTextSubmit(String s) {
Intent intent = new Intent(getApplicationContext(), SearchPage.class);
Bundle bundle = new Bundle();
bundle.putString("search", s);
intent.putExtras(bundle);
intent.putExtra("search", s);
startActivity(intent);
return false;
}
@ -148,18 +145,14 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
switch(item.getItemId()) {
case R.id.action_profile:
intent = new Intent(this, UserProfile.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",homeId);
bundle.putString("username", "");
intent.putExtras(bundle);
intent.putExtra("userID", homeId);
intent.putExtra("username", "");
startActivity(intent);
return true;
case R.id.action_tweet:
intent = new Intent(this, TweetPopup.class);
Bundle b = new Bundle();
b.putLong("TweetID", -1);
intent.putExtras(b);
intent.putExtra("TweetID", -1);
startActivity(intent);
return true;
@ -168,9 +161,11 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
intent = new Intent(this, AppSettings.class);
startActivity(intent);
return true;
}
default:
return false;
}
}
@Override
protected void onPause() {
@ -238,12 +233,14 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
tweet.setVisible(true);
setting.setVisible(false);
break;
case "trends":
profile.setVisible(false);
search.setVisible(true);
tweet.setVisible(false);
setting.setVisible(true);
break;
case "mention":
searchQuery.onActionViewCollapsed();
profile.setVisible(false);
@ -261,54 +258,46 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
if(!timelineReload.isRefreshing()) {
TimelineRecycler tlAdp = (TimelineRecycler) timelineList.getAdapter();
Tweet tweet = tlAdp.getData().get(position);
Intent intent = new Intent(this,TweetDetail.class);
Bundle bundle = new Bundle();
if(tweet.embedded != null) {
tweet = tweet.embedded;
}
bundle.putLong("tweetID",tweet.tweetID);
bundle.putLong("userID",tweet.user.userID);
bundle.putString("username", tweet.user.screenname);
intent.putExtras(bundle);
Intent intent = new Intent(this, TweetDetail.class);
intent.putExtra("tweetID", tweet.tweetID);
intent.putExtra("userID", tweet.user.userID);
intent.putExtra("username", tweet.user.screenname);
startActivity(intent);
}
break;
case R.id.tr_list:
if(!trendReload.isRefreshing()) {
TrendRecycler trend = (TrendRecycler) trendList.getAdapter();
String search = trend.getData().get(position).trend;
Intent intent = new Intent(this, SearchPage.class);
Bundle bundle = new Bundle();
if(search.startsWith("#")) {
bundle.putString("Addition", search);
bundle.putString("search", search);
intent.putExtra("Addition", search);
intent.putExtra("search", search);
} else {
search = '\"'+ search + '\"';
bundle.putString("search", search);
intent.putExtra("search", search);
}
intent.putExtras(bundle);
startActivity(intent);
}
break;
case R.id.m_list:
if(!mentionReload.isRefreshing()) {
TimelineRecycler tlAdp = (TimelineRecycler) mentionList.getAdapter();
Tweet tweet = tlAdp.getData().get(position);
Intent intent = new Intent(this,TweetDetail.class);
Bundle bundle = new Bundle();
if(tweet.embedded != null) {
tweet = tweet.embedded;
}
bundle.putLong("tweetID",tweet.tweetID);
bundle.putLong("userID",tweet.user.userID);
bundle.putString("username", tweet.user.screenname);
intent.putExtras(bundle);
Intent intent = new Intent(this, TweetDetail.class);
intent.putExtra("tweetID", tweet.tweetID);
intent.putExtra("userID", tweet.user.userID);
intent.putExtra("username", tweet.user.screenname);
startActivity(intent);
}
break;
@ -325,27 +314,27 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
trendList.setBackgroundColor(background);
mentionList.setBackgroundColor(background);
TimelineRecycler homeRc = (TimelineRecycler) timelineList.getAdapter();
TrendRecycler trendRc = (TrendRecycler) trendList.getAdapter();
TimelineRecycler mentRc = (TimelineRecycler) mentionList.getAdapter();
TimelineRecycler hAdapter = (TimelineRecycler) timelineList.getAdapter();
TrendRecycler tAdapter = (TrendRecycler) trendList.getAdapter();
TimelineRecycler mAdapter = (TimelineRecycler) mentionList.getAdapter();
if(homeRc == null || homeRc.getItemCount() == 0) {
if (hAdapter == null || hAdapter.getItemCount() == 0) {
new MainPage(this).execute(MainPage.H_LOAD,1);
} else {
homeRc.setColor(highlight,fontColor);
homeRc.notifyDataSetChanged();
hAdapter.setColor(highlight, fontColor);
hAdapter.notifyDataSetChanged();
}
if(mentRc == null || mentRc.getItemCount() == 0) {
new MainPage(this).execute(MainPage.M_LOAD,1);
} else {
mentRc.setColor(highlight,fontColor);
mentRc.notifyDataSetChanged();
}
if(trendRc == null || trendRc.getItemCount() == 0) {
if (tAdapter == null || tAdapter.getItemCount() == 0) {
new MainPage(this).execute(MainPage.T_LOAD,1);
} else {
trendRc.setColor(fontColor);
trendRc.notifyDataSetChanged();
tAdapter.setColor(fontColor);
tAdapter.notifyDataSetChanged();
}
if (mAdapter == null || mAdapter.getItemCount() == 0) {
new MainPage(this).execute(MainPage.M_LOAD, 1);
} else {
mAdapter.setColor(highlight, fontColor);
mAdapter.notifyDataSetChanged();
}
lastTab = tabhost.getCurrentView();
}

View File

@ -41,7 +41,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
private int highlight, font;
private boolean image;
private String errMsg = "E: Main Page, ";
private int retryAfter = 0;
private int returnCode = 0;
/**
* Main View
@ -158,10 +158,8 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
break;
}
} catch(TwitterException e) {
int errCode = e.getErrorCode();
if(errCode == 420) {
retryAfter = e.getRetryAfter();
} else {
returnCode = e.getErrorCode();
if (returnCode != 420) {
errMsg += e.getMessage();
}
return FAIL;
@ -203,7 +201,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
break;
case FAIL:
if (retryAfter > 0) {
if (returnCode == 420) {
Toast.makeText(connect, R.string.rate_limit_exceeded, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(connect, errMsg, Toast.LENGTH_LONG).show();

View File

@ -55,7 +55,7 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
private boolean isLocked = false;
private boolean blocked = false;
private String errMsg = "E: Profile Load, ";
private int retryAfter = 0;
private int returnCode = 0;
/**
* @param context Context to Activity
@ -186,11 +186,9 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
}
}
} catch (TwitterException err) {
int errCode = err.getErrorCode();
if(errCode == 420) {
retryAfter = err.getRetryAfter();
}
else if(errCode != 136) {
returnCode = err.getErrorCode();
if (returnCode != 136) {
errMsg += err.getMessage();
errorLog.add(errMsg);
}
@ -285,12 +283,14 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
else if(mode == FAILURE)
{
SwipeRefreshLayout tweetsReload = connect.findViewById(R.id.hometweets);
SwipeRefreshLayout favoritsReload = connect.findViewById(R.id.homefavorits);
SwipeRefreshLayout favoriteReload = connect.findViewById(R.id.homefavorits);
tweetsReload.setRefreshing(false);
favoritsReload.setRefreshing(false);
favoriteReload.setRefreshing(false);
if (retryAfter > 0) {
if (returnCode == 420) {
Toast.makeText(connect, R.string.rate_limit_exceeded, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(connect, errMsg, Toast.LENGTH_LONG).show();
}
}
if(!isHome && (mode==ACTION_FOLLOW||mode==ACTION_MUTE||mode==GET_INFORMATION)) {

View File

@ -58,6 +58,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
private long tweetReplyID, replyUserId;
private int rtCount, favCount;
private int highlight, font;
private int returnCode = 0;
private WeakReference<TweetDetail> ui;
@ -168,14 +169,10 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
}
}
catch(TwitterException e) {
int errCode = e.getErrorCode();
if(errCode == 144) {
database.removeStatus(tweetID); //TODO
errorMessage = "Tweet nicht gefunden!\nID:"+tweetID;
} else if(errCode == 420) {
int retry = e.getRetryAfter(); //TODO
errorMessage = "Rate limit erreicht!\n Weiter in "+retry+" Sekunden";
} else {
returnCode = e.getErrorCode();
if (returnCode == 144) {
database.removeStatus(tweetID);
} else if (returnCode != 136) {
errorMessage += e.getMessage();
}
return ERROR;
@ -302,7 +299,13 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
ui.get().finish();
}
else if(mode == ERROR) {
Toast.makeText(ui.get(),errorMessage,Toast.LENGTH_LONG).show();
if (returnCode == 420) {
Toast.makeText(ui.get(), R.string.rate_limit_exceeded, Toast.LENGTH_LONG).show();
} else if (returnCode == 144) {
Toast.makeText(ui.get(), R.string.tweet_not_found, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ui.get(), errorMessage, Toast.LENGTH_LONG).show();
}
SwipeRefreshLayout ansReload = connect.findViewById(R.id.answer_reload);
if(ansReload.isRefreshing()) {
ansReload.setRefreshing(false);

View File

@ -138,14 +138,6 @@ public class TwitterEngine {
load = settings.getRowLimit();
}
/**
* @return if Twitter4J is registered
*/
public boolean loggedIn() {
return login;
}
/**
* recall Keys from Shared-Preferences
* & initialize Twitter

View File

@ -30,7 +30,7 @@ public class TwitterSearch extends AsyncTask<String, Void, Boolean> {
private int highlight, font_color;
private boolean imageLoad;
private String errorMessage = "E: Twitter search, ";
private int retryAfter = 0;
private int returnCode = 0;
public TwitterSearch(Context context) {
ui = new WeakReference<>((SearchPage)context);
@ -83,10 +83,8 @@ public class TwitterSearch extends AsyncTask<String, Void, Boolean> {
return true;
} catch (TwitterException err) {
int errCode = err.getErrorCode();
if(errCode == 420) {
retryAfter = err.getRetryAfter();
} else {
returnCode = err.getErrorCode();
if (returnCode != 420) {
errorMessage += err.getMessage();
errorLog.add(errorMessage);
}
@ -104,11 +102,12 @@ public class TwitterSearch extends AsyncTask<String, Void, Boolean> {
if(connect == null)
return;
if (!success) {
if (retryAfter > 0)
if (returnCode == 420) {
Toast.makeText(connect, R.string.rate_limit_exceeded, Toast.LENGTH_LONG).show();
else
} else {
Toast.makeText(connect, errorMessage, Toast.LENGTH_LONG).show();
}
}
SwipeRefreshLayout tweetReload = connect.findViewById(R.id.searchtweets);
View circleLoad = connect.findViewById(R.id.search_progress);
circleLoad.setVisibility(View.INVISIBLE);

View File

@ -30,7 +30,7 @@ public class UserLists extends AsyncTask <Long, Void, Boolean> {
private ErrorLog errorLog;
private boolean imageLoad;
private String errorMessage = "E: Userlist, ";
private int retryAfter = 0;
private int returnCode = 0;
/**
*@see UserDetail
@ -72,10 +72,8 @@ public class UserLists extends AsyncTask <Long, Void, Boolean> {
return true;
}
catch(TwitterException err) {
int errCode = err.getErrorCode();
if(errCode == 420) {
retryAfter = err.getRetryAfter();
} else {
returnCode = err.getErrorCode();
if (returnCode != 420) {
errorMessage += err.getMessage();
errorLog.add(errorMessage);
}
@ -98,7 +96,7 @@ public class UserLists extends AsyncTask <Long, Void, Boolean> {
if(success) {
usrAdp.notifyDataSetChanged();
} else {
if (retryAfter > 0)
if (returnCode == 420)
Toast.makeText(ui.get(), R.string.rate_limit_exceeded, Toast.LENGTH_SHORT).show();
else
Toast.makeText(ui.get(), errorMessage, Toast.LENGTH_SHORT).show();

View File

@ -126,12 +126,10 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
switch(id) {
case R.id.search_tweet:
intent = new Intent(this, TweetPopup.class);
Bundle b = new Bundle();
b.putLong("TweetID", -1);
intent.putExtra("TweetID", -1);
if(search.startsWith("#")) {
b.putString("Addition", search);
intent.putExtra("Addition", search);
}
intent.putExtras(b);
startActivity(intent);
break;
}
@ -140,20 +138,17 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
@Override
public void onItemClick(View view, ViewGroup parent, int position) {
Intent intent;
switch(parent.getId()) {
case R.id.tweet_result:
if(!tweetReload.isRefreshing()) {
TimelineRecycler tlAdp = (TimelineRecycler) tweetSearch.getAdapter();
Tweet tweet = tlAdp.getData().get(position);
Intent intent = new Intent(this,TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweet.tweetID);
bundle.putLong("userID",tweet.user.userID);
bundle.putString("username", tweet.user.screenname);
intent.putExtras(bundle);
intent = new Intent(this, TweetDetail.class);
intent.putExtra("tweetID", tweet.tweetID);
intent.putExtra("userID", tweet.user.userID);
intent.putExtra("username", tweet.user.screenname);
startActivity(intent);
}
break;
@ -161,13 +156,10 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
UserRecycler uAdp = (UserRecycler) userSearch.getAdapter();
TwitterUser user = uAdp.getData().get(position);
Intent profile = new Intent(getApplicationContext(), UserProfile.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",user.userID);
bundle.putString("username", user.screenname);
profile.putExtras(bundle);
startActivity(profile);
intent = new Intent(getApplicationContext(), UserProfile.class);
intent.putExtra("userID", user.userID);
intent.putExtra("username", user.screenname);
startActivity(intent);
break;
}
}

View File

@ -143,7 +143,6 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener,
@Override
public void onClick(View v) {
Intent intent;
Bundle bundle = new Bundle();
StatusLoader mStat = new StatusLoader(this);
switch(v.getId()) {
case R.id.rt_button_detail:
@ -156,36 +155,30 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener,
case R.id.no_rt_detail:
intent = new Intent(this, UserDetail.class);
bundle.putLong("tweetID",tweetID);
bundle.putLong("mode",2L);
intent.putExtras(bundle);
intent.putExtra("tweetID", tweetID);
intent.putExtra("mode", 2L);
startActivity(intent);
break;
case R.id.no_fav_detail:
intent = new Intent(this, UserDetail.class);
bundle.putLong("tweetID",tweetID);
bundle.putLong("mode",3L);
intent.putExtras(bundle);
intent.putExtra("tweetID", tweetID);
intent.putExtra("mode", 3L);
startActivity(intent);
break;
case R.id.profileimage_detail:
Intent profile = new Intent(this, UserProfile.class);
Bundle b = new Bundle();
b.putLong("userID",userID);
b.putString("username", username);
profile.putExtras(b);
startActivity(profile);
intent = new Intent(this, UserProfile.class);
intent.putExtra("userID", userID);
intent.putExtra("username", username);
startActivity(intent);
break;
case R.id.answer_button:
Intent tweetPopup = new Intent(this, TweetPopup.class);
Bundle ext = new Bundle();
ext.putLong("TweetID", tweetID);
ext.putString("Addition", username);
tweetPopup.putExtras(ext);
startActivity(tweetPopup);
intent = new Intent(this, TweetPopup.class);
intent.putExtra("TweetID", tweetID);
intent.putExtra("Addition", username);
startActivity(intent);
break;
}
}
@ -202,13 +195,9 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener,
Tweet tweet = tlAdp.getData().get(position);
Intent intent = new Intent(this,TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweet.tweetID);
bundle.putLong("userID",tweet.user.userID);
bundle.putString("username", tweet.user.screenname);
intent.putExtras(bundle);
intent.putExtra("tweetID", tweet.tweetID);
intent.putExtra("userID", tweet.user.userID);
intent.putExtra("username", tweet.user.screenname);
startActivity(intent);
}

View File

@ -123,17 +123,16 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener,
break;
case R.id.image:
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int check = checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
if(check == PackageManager.PERMISSION_GRANTED) {
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 0);
}
else {
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},1);
}
} else {
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 0);
}
break;

View File

@ -78,30 +78,32 @@ public class UserDetail extends AppCompatActivity implements OnItemClicked {
TwitterUser user = uAdp.getData().get(position);
long userID = user.userID;
String username = user.screenname;
Intent intent = new Intent(getApplicationContext(), UserProfile.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",userID);
bundle.putString("username", username);
intent.putExtras(bundle);
Intent intent = new Intent(this, UserProfile.class);
intent.putExtra("userID", userID);
intent.putExtra("username", username);
startActivity(intent);
}
private void getUsers() {
uList = new UserLists(UserDetail.this);
if(getSupportActionBar() != null) {
String title = "";
if (mode == 0L) {
getSupportActionBar().setTitle(R.string.following);
title = getString(R.string.following);
uList.execute(userID, UserLists.FOLLOWING, -1L);
} else if (mode == 1L) {
getSupportActionBar().setTitle(R.string.follower);
title = getString(R.string.follower);
uList.execute(userID, UserLists.FOLLOWERS, -1L);
} else if (mode == 2L) {
getSupportActionBar().setTitle(R.string.retweet);
title = getString(R.string.retweet);
uList.execute(tweetID, UserLists.RETWEETER, -1L);
} else if (mode == 3L) {
getSupportActionBar().setTitle(R.string.favorite);
title = getString(R.string.favorite);
uList.execute(tweetID, UserLists.FAVORISER, -1L);
}
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(title);
}
}
}

View File

@ -133,11 +133,9 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
mProfile = new ProfileLoader(this);
switch(item.getItemId()) {
case R.id.profile_tweet:
Bundle extra = new Bundle();
intent = new Intent(this, TweetPopup.class);
if(!home)
extra.putString("Addition", username);
intent.putExtras(extra);
intent.putExtra("Addition", username);
startActivity(intent);
return true;
@ -197,18 +195,15 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
tlAdp = (TimelineRecycler) favoriteList.getAdapter();
}
Intent intent = new Intent(this,TweetDetail.class);
Bundle bundle = new Bundle();
Tweet tweet = tlAdp.getData().get(position);
if(tweet.embedded != null) {
tweet = tweet.embedded;
}
bundle.putLong("tweetID",tweet.tweetID);
bundle.putLong("userID",tweet.user.userID);
bundle.putString("username", tweet.user.screenname);
intent.putExtras(bundle);
Intent intent = new Intent(this, TweetDetail.class);
intent.putExtra("tweetID", tweet.tweetID);
intent.putExtra("userID", tweet.user.userID);
intent.putExtra("username", tweet.user.screenname);
startActivity(intent);
}
@ -265,10 +260,8 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
private void getConnection(long mode) {
Intent intent = new Intent(this, UserDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",userId);
bundle.putLong("mode",mode);
intent.putExtras(bundle);
intent.putExtra("userID", userId);
intent.putExtra("mode", mode);
startActivity(intent);
}
}

View File

@ -42,4 +42,5 @@
<string name="error">Fehler!</string>
<string name="tweet_delete">Tweet löschen</string>
<string name="get_tweetlink">Im Browser öffnen</string>
<string name="tweet_not_found">Tweet wurde nicht gefunden</string>
</resources>

View File

@ -50,4 +50,5 @@
<string name="error">Error!</string>
<string name="tweet_delete">Delete</string>
<string name="get_tweetlink">Open in Browser</string>
<string name="tweet_not_found">Tweet not found</string>
</resources>