mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-31 19:34:55 +01:00
Bugfix
This commit is contained in:
parent
49cc4b24b9
commit
593b1eb842
@ -51,13 +51,16 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.mainpage);
|
||||
con = getApplicationContext();
|
||||
settings = con.getSharedPreferences("settings", 0);
|
||||
boolean login = settings.getBoolean("login", false);
|
||||
if( !login ) {
|
||||
Intent i = new Intent(con,LoginPage.class);
|
||||
startActivityForResult(i,1);
|
||||
} else { login(); }
|
||||
} else {
|
||||
login();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -125,11 +128,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume(){
|
||||
super.onResume();
|
||||
@ -200,13 +198,13 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||
MainPage homeView = new MainPage(MainActivity.this);
|
||||
switch (currentTab) {
|
||||
case "timeline":
|
||||
homeView.execute(0,1);
|
||||
homeView.execute(MainPage.HOME,1);
|
||||
break;
|
||||
case "trends":
|
||||
homeView.execute(1,1);
|
||||
homeView.execute(MainPage.TRND,1);
|
||||
break;
|
||||
case "mention":
|
||||
homeView.execute(2,1);
|
||||
homeView.execute(MainPage.MENT,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -242,12 +240,10 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Login Handle
|
||||
*/
|
||||
private void login() {
|
||||
setContentView(R.layout.mainpage);
|
||||
timelineList = (ListView) findViewById(R.id.tl_list);
|
||||
trendList = (ListView) findViewById(R.id.tr_list);
|
||||
mentionList = (ListView) findViewById(R.id.m_list);
|
||||
@ -256,6 +252,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||
mentionReload = (SwipeRefreshLayout) findViewById(R.id.mention);
|
||||
tabhost = (TabHost)findViewById(R.id.main_tabhost);
|
||||
toolbar = (Toolbar) findViewById(R.id.profile_toolbar);
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
if(getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
@ -284,11 +281,12 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||
timelineReload.setOnRefreshListener(this);
|
||||
trendReload.setOnRefreshListener(this);
|
||||
mentionReload.setOnRefreshListener(this);
|
||||
|
||||
setTabContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Teb Content
|
||||
* Set Tab Content
|
||||
*/
|
||||
private void setTabContent() {
|
||||
TweetDatabase tweetDeck = new TweetDatabase(con,TweetDatabase.HOME_TL, 0L);
|
||||
|
@ -13,9 +13,13 @@ import android.widget.Toast;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
public class MainPage extends AsyncTask<Integer, Void, Boolean> {
|
||||
public class MainPage extends AsyncTask<Integer, Void, Integer> {
|
||||
|
||||
public static final int HOME = 0;
|
||||
public static final int TRND = 1;
|
||||
public static final int MENT = 2;
|
||||
private static final int FAIL = -1;
|
||||
|
||||
private TwitterEngine mTwitter;
|
||||
private Context context;
|
||||
@ -51,12 +55,13 @@ public class MainPage extends AsyncTask<Integer, Void, Boolean> {
|
||||
* @return success
|
||||
*/
|
||||
@Override
|
||||
protected Boolean doInBackground(Integer... args) {
|
||||
int mode = args[0];
|
||||
protected Integer doInBackground(Integer... args) {
|
||||
final int MODE = args[0];
|
||||
int page = args[1];
|
||||
long id = 1L;
|
||||
try {
|
||||
if(mode == 0) {
|
||||
switch (MODE) {
|
||||
case HOME:
|
||||
timelineAdapter = (TimelineAdapter) timelineList.getAdapter();
|
||||
if(timelineAdapter.getCount() == 0) {
|
||||
TweetDatabase mTweets = new TweetDatabase(mTwitter.getHome(page,id), context,TweetDatabase.HOME_TL,0);
|
||||
@ -65,11 +70,13 @@ public class MainPage extends AsyncTask<Integer, Void, Boolean> {
|
||||
id = timelineAdapter.getItemId(0);
|
||||
timelineAdapter.getData().add(mTwitter.getHome(page,id));
|
||||
}
|
||||
}
|
||||
else if(mode == 1) {
|
||||
break;
|
||||
|
||||
case TRND:
|
||||
trendsAdapter = new TrendAdapter(context, new TrendDatabase(mTwitter.getTrends(),context));
|
||||
}
|
||||
else if(mode == 2) {
|
||||
break;
|
||||
|
||||
case MENT:
|
||||
mentionAdapter = (TimelineAdapter) mentionList.getAdapter();
|
||||
if(mentionAdapter.getCount() == 0) {
|
||||
TweetDatabase mention = new TweetDatabase(mTwitter.getMention(page,id), context,TweetDatabase.GET_MENT,0);
|
||||
@ -78,37 +85,44 @@ public class MainPage extends AsyncTask<Integer, Void, Boolean> {
|
||||
id = mentionAdapter.getItemId(0);
|
||||
mentionAdapter.getData().add(mTwitter.getMention(page,id));
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (TwitterException e) {
|
||||
return false;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
return FAIL;
|
||||
}
|
||||
return true;
|
||||
return MODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean success) {
|
||||
if(success) {
|
||||
if(timelineAdapter != null) {
|
||||
if(timelineList.getAdapter().getCount() == 0)
|
||||
timelineList.setAdapter(timelineAdapter);
|
||||
else
|
||||
timelineAdapter.notifyDataSetChanged();
|
||||
protected void onPostExecute(Integer MODE) {
|
||||
switch(MODE) {
|
||||
case HOME:
|
||||
timelineRefresh.setRefreshing(false);
|
||||
} else if(trendsAdapter != null) {
|
||||
trendList.setAdapter(trendsAdapter);
|
||||
if(timelineList.getAdapter().getCount() == 0) {
|
||||
timelineList.setAdapter(timelineAdapter);
|
||||
} else {
|
||||
timelineAdapter.notifyDataSetChanged();
|
||||
}
|
||||
break;
|
||||
|
||||
case TRND:
|
||||
trendRefresh.setRefreshing(false);
|
||||
} else if(mentionAdapter != null) {
|
||||
if(mentionList.getAdapter().getCount() == 0)
|
||||
mentionList.setAdapter(mentionAdapter);
|
||||
else
|
||||
mentionAdapter.notifyDataSetChanged();
|
||||
trendList.setAdapter(trendsAdapter);
|
||||
break;
|
||||
|
||||
case MENT:
|
||||
mentionRefresh.setRefreshing(false);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(context, context.getString(R.string.connection_failure), Toast.LENGTH_LONG).show();
|
||||
if(mentionList.getAdapter().getCount() == 0) {
|
||||
mentionList.setAdapter(mentionAdapter);
|
||||
} else {
|
||||
mentionAdapter.notifyDataSetChanged();
|
||||
}
|
||||
break;
|
||||
|
||||
case FAIL:
|
||||
default:
|
||||
Toast.makeText(context, context.getString(R.string.connection_failure), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
@ -3,15 +3,12 @@ package org.nuclearfog.twidda.backend;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.nuclearfog.twidda.MainActivity;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.window.LoginPage;
|
||||
|
||||
public class RegisterAccount extends AsyncTask<String, Void, String> {
|
||||
public class RegisterAccount extends AsyncTask<String, Void, Boolean> {
|
||||
private Context context;
|
||||
private String errMSG = "";
|
||||
|
||||
/**
|
||||
* Register App for Account access
|
||||
@ -25,11 +22,7 @@ public class RegisterAccount extends AsyncTask<String, Void, String> {
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() { }
|
||||
|
||||
|
||||
@Override
|
||||
protected String doInBackground( String... twitterPin ) {
|
||||
protected Boolean doInBackground( String... twitterPin ) {
|
||||
String pin = twitterPin[0];
|
||||
TwitterEngine mTwitter = TwitterEngine.getInstance(context);
|
||||
try {
|
||||
@ -37,22 +30,22 @@ public class RegisterAccount extends AsyncTask<String, Void, String> {
|
||||
mTwitter.request();
|
||||
}else {
|
||||
mTwitter.initialize(pin);
|
||||
return "success";
|
||||
return true;
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
return e.getMessage();
|
||||
errMSG = e.getMessage();
|
||||
}
|
||||
return " ";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String msg) {
|
||||
if( msg.equals("success") ) {
|
||||
protected void onPostExecute(Boolean success) {
|
||||
if(success) {
|
||||
((LoginPage)context).setResult(Activity.RESULT_OK);
|
||||
((LoginPage)context).finish();
|
||||
} else if( !msg.trim().isEmpty() ) {
|
||||
Toast.makeText(context,"Fehler: "+msg,Toast.LENGTH_LONG).show();
|
||||
} else if(errMSG.isEmpty()) {
|
||||
Toast.makeText(context,"Fehler: "+errMSG,Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
@ -30,11 +30,13 @@ 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> {
|
||||
public class ShowStatus extends AsyncTask<Long, Void, Long> {
|
||||
|
||||
private static final long ERROR = -1;
|
||||
public static final long RETWEET = 0;
|
||||
public static final long FAVORITE = 1;
|
||||
public static final long DELETE = 2;
|
||||
public static final long LOAD_TWEET = 3;
|
||||
|
||||
private Context c;
|
||||
private ListView replyList;
|
||||
@ -47,7 +49,7 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
|
||||
private String ansStr, rtStr, favStr, repliedUsername, apiName;
|
||||
private TwitterEngine mTwitter;
|
||||
private boolean retweeted, favorited, toggleImg, verified;
|
||||
private int ansNo = 0;
|
||||
private int rt, fav, ansNo = 0;
|
||||
private int highlight;
|
||||
private long userReply, tweetReplyID;
|
||||
private Bitmap profile_btm, tweet_btm;
|
||||
@ -72,7 +74,7 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
|
||||
txtAns = (TextView) ((TweetDetail)c).findViewById(R.id.no_ans_detail);
|
||||
txtRet = (TextView) ((TweetDetail)c).findViewById(R.id.no_rt_detail);
|
||||
txtFav = (TextView) ((TweetDetail)c).findViewById(R.id.no_fav_detail);
|
||||
used_api = (TextView) ((TweetDetail)c).findViewById(R.id.used_api);
|
||||
used_api = (TextView) ((TweetDetail)c).findViewById(R.id.used_api);
|
||||
|
||||
profile_img = (ImageView) ((TweetDetail)c).findViewById(R.id.profileimage_detail);
|
||||
tweet_img = (ImageView) ((TweetDetail)c).findViewById(R.id.tweet_image);
|
||||
@ -83,22 +85,23 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id [0] TWEET ID , [1] Mode
|
||||
* @param data [0] TWEET ID , [1] Mode
|
||||
* @returns false if Tweet is already loaded.
|
||||
*/
|
||||
@Override
|
||||
protected Boolean doInBackground(Long... id) {
|
||||
long tweetID = id[0];
|
||||
protected Long doInBackground(Long... data) {
|
||||
long tweetID = data[0];
|
||||
long mode = data[1];
|
||||
try {
|
||||
twitter4j.Status currentTweet = mTwitter.getStatus(tweetID);
|
||||
rtStr = Integer.toString(currentTweet.getRetweetCount());
|
||||
favStr = Integer.toString(currentTweet.getFavoriteCount());
|
||||
rt = currentTweet.getRetweetCount();
|
||||
fav = currentTweet.getFavoriteCount();
|
||||
userReply = currentTweet.getInReplyToUserId();
|
||||
tweetReplyID = currentTweet.getInReplyToStatusId();
|
||||
verified = currentTweet.getUser().isVerified();
|
||||
retweeted = currentTweet.isRetweetedByMe();
|
||||
favorited = currentTweet.isFavorited();
|
||||
if(id.length == 1) {
|
||||
if(mode == LOAD_TWEET) {
|
||||
tweetStr = currentTweet.getText();
|
||||
usernameStr = currentTweet.getUser().getName();
|
||||
scrNameStr = '@'+currentTweet.getUser().getScreenName();
|
||||
@ -115,40 +118,43 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
|
||||
if(toggleImg) {
|
||||
setMedia(currentTweet);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
long mode = id[1];
|
||||
if(mode==RETWEET) {
|
||||
if(retweeted) {
|
||||
mTwitter.retweet(tweetID, true);
|
||||
// TODO del Retweet
|
||||
} else {
|
||||
mTwitter.retweet(tweetID, false);
|
||||
retweeted = true;
|
||||
}
|
||||
} else if(mode==FAVORITE) {
|
||||
if(favorited) {
|
||||
mTwitter.favorite(tweetID, true);
|
||||
favorited = false;
|
||||
} else {
|
||||
mTwitter.favorite(tweetID, false);
|
||||
favorited = true;
|
||||
}
|
||||
} else if(mode==DELETE){
|
||||
mTwitter.deleteTweet(tweetID);
|
||||
|
||||
} else if(mode == RETWEET) {
|
||||
if(retweeted) {
|
||||
mTwitter.retweet(tweetID, true);
|
||||
retweeted = false;
|
||||
rt--;
|
||||
} else {
|
||||
mTwitter.retweet(tweetID, false);
|
||||
retweeted = true;
|
||||
rt++;
|
||||
}
|
||||
return false;
|
||||
} else if(mode == FAVORITE) {
|
||||
if(favorited) {
|
||||
mTwitter.favorite(tweetID, true);
|
||||
favorited = false;
|
||||
fav--;
|
||||
} else {
|
||||
mTwitter.favorite(tweetID, false);
|
||||
favorited = true;
|
||||
fav++;
|
||||
}
|
||||
} else if(mode == DELETE) {
|
||||
mTwitter.deleteTweet(tweetID);
|
||||
}
|
||||
} catch(Exception err) {
|
||||
err.printStackTrace();
|
||||
return false;
|
||||
return ERROR;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean tweetLoaded) {
|
||||
if(tweetLoaded) {
|
||||
protected void onPostExecute(Long mode) {
|
||||
if(mode == LOAD_TWEET) {
|
||||
ansStr = Integer.toString(ansNo);
|
||||
rtStr = Integer.toString(rt);
|
||||
favStr = Integer.toString(fav);
|
||||
tweet.setText(highlight(tweetStr));
|
||||
username.setText(usernameStr);
|
||||
scrName.setText(scrNameStr);
|
||||
@ -169,23 +175,24 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
|
||||
profile_img.setImageBitmap(profile_btm);
|
||||
tweet_img.setImageBitmap(tweet_btm);
|
||||
}
|
||||
replyName.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(c, TweetDetail.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong("tweetID",tweetReplyID);
|
||||
bundle.putLong("userID",userReply);
|
||||
intent.putExtras(bundle);
|
||||
c.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setIcons();
|
||||
txtRet.setText(rtStr);
|
||||
txtFav.setText(favStr);
|
||||
|
||||
replyName.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(c, TweetDetail.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong("tweetID",tweetReplyID);
|
||||
bundle.putLong("userID",userReply);
|
||||
intent.putExtras(bundle);
|
||||
c.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void setMedia(twitter4j.Status tweet) throws Exception {
|
||||
|
@ -369,6 +369,9 @@ public class TwitterEngine {
|
||||
public void retweet(long id, boolean active) throws TwitterException {
|
||||
if(!active) {
|
||||
twitter.retweetStatus(id);
|
||||
}//TODO remove Retweet
|
||||
else {
|
||||
deleteTweet(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ import android.widget.Toast;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.backend.RegisterAccount;
|
||||
|
||||
|
||||
public class LoginPage extends Activity implements View.OnClickListener {
|
||||
|
||||
private EditText pin;
|
||||
|
@ -157,6 +157,6 @@ public class TweetDetail extends AppCompatActivity implements View.OnClickListen
|
||||
tweetaction.setBackgroundColor(backgroundColor);
|
||||
answer_list.setBackgroundColor(backgroundColor);
|
||||
txtTw.setTextColor(fontColor);
|
||||
new ShowStatus(this).execute(tweetID);
|
||||
new ShowStatus(this).execute(tweetID, ShowStatus.LOAD_TWEET);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user