This commit is contained in:
NudeDude 2018-02-10 21:04:04 +01:00
parent 49cc4b24b9
commit 593b1eb842
7 changed files with 120 additions and 106 deletions

View File

@ -51,13 +51,16 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.mainpage);
con = getApplicationContext(); con = getApplicationContext();
settings = con.getSharedPreferences("settings", 0); settings = con.getSharedPreferences("settings", 0);
boolean login = settings.getBoolean("login", false); boolean login = settings.getBoolean("login", false);
if( !login ) { if( !login ) {
Intent i = new Intent(con,LoginPage.class); Intent i = new Intent(con,LoginPage.class);
startActivityForResult(i,1); startActivityForResult(i,1);
} else { login(); } } else {
login();
}
} }
@Override @Override
@ -125,11 +128,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
} }
} }
@Override
protected void onPause() {
super.onPause();
}
@Override @Override
protected void onResume(){ protected void onResume(){
super.onResume(); super.onResume();
@ -200,13 +198,13 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
MainPage homeView = new MainPage(MainActivity.this); MainPage homeView = new MainPage(MainActivity.this);
switch (currentTab) { switch (currentTab) {
case "timeline": case "timeline":
homeView.execute(0,1); homeView.execute(MainPage.HOME,1);
break; break;
case "trends": case "trends":
homeView.execute(1,1); homeView.execute(MainPage.TRND,1);
break; break;
case "mention": case "mention":
homeView.execute(2,1); homeView.execute(MainPage.MENT,1);
break; break;
} }
} }
@ -242,12 +240,10 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
} }
} }
/** /**
* Login Handle * Login Handle
*/ */
private void login() { private void login() {
setContentView(R.layout.mainpage);
timelineList = (ListView) findViewById(R.id.tl_list); timelineList = (ListView) findViewById(R.id.tl_list);
trendList = (ListView) findViewById(R.id.tr_list); trendList = (ListView) findViewById(R.id.tr_list);
mentionList = (ListView) findViewById(R.id.m_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); mentionReload = (SwipeRefreshLayout) findViewById(R.id.mention);
tabhost = (TabHost)findViewById(R.id.main_tabhost); tabhost = (TabHost)findViewById(R.id.main_tabhost);
toolbar = (Toolbar) findViewById(R.id.profile_toolbar); toolbar = (Toolbar) findViewById(R.id.profile_toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
if(getSupportActionBar() != null) if(getSupportActionBar() != null)
getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false);
@ -284,11 +281,12 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
timelineReload.setOnRefreshListener(this); timelineReload.setOnRefreshListener(this);
trendReload.setOnRefreshListener(this); trendReload.setOnRefreshListener(this);
mentionReload.setOnRefreshListener(this); mentionReload.setOnRefreshListener(this);
setTabContent(); setTabContent();
} }
/** /**
* Set Teb Content * Set Tab Content
*/ */
private void setTabContent() { private void setTabContent() {
TweetDatabase tweetDeck = new TweetDatabase(con,TweetDatabase.HOME_TL, 0L); TweetDatabase tweetDeck = new TweetDatabase(con,TweetDatabase.HOME_TL, 0L);

View File

@ -13,9 +13,13 @@ import android.widget.Toast;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; 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 TwitterEngine mTwitter;
private Context context; private Context context;
@ -51,12 +55,13 @@ public class MainPage extends AsyncTask<Integer, Void, Boolean> {
* @return success * @return success
*/ */
@Override @Override
protected Boolean doInBackground(Integer... args) { protected Integer doInBackground(Integer... args) {
int mode = args[0]; final int MODE = args[0];
int page = args[1]; int page = args[1];
long id = 1L; long id = 1L;
try { try {
if(mode == 0) { switch (MODE) {
case HOME:
timelineAdapter = (TimelineAdapter) timelineList.getAdapter(); timelineAdapter = (TimelineAdapter) timelineList.getAdapter();
if(timelineAdapter.getCount() == 0) { if(timelineAdapter.getCount() == 0) {
TweetDatabase mTweets = new TweetDatabase(mTwitter.getHome(page,id), context,TweetDatabase.HOME_TL,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); id = timelineAdapter.getItemId(0);
timelineAdapter.getData().add(mTwitter.getHome(page,id)); timelineAdapter.getData().add(mTwitter.getHome(page,id));
} }
} break;
else if(mode == 1) {
case TRND:
trendsAdapter = new TrendAdapter(context, new TrendDatabase(mTwitter.getTrends(),context)); trendsAdapter = new TrendAdapter(context, new TrendDatabase(mTwitter.getTrends(),context));
} break;
else if(mode == 2) {
case MENT:
mentionAdapter = (TimelineAdapter) mentionList.getAdapter(); mentionAdapter = (TimelineAdapter) mentionList.getAdapter();
if(mentionAdapter.getCount() == 0) { if(mentionAdapter.getCount() == 0) {
TweetDatabase mention = new TweetDatabase(mTwitter.getMention(page,id), context,TweetDatabase.GET_MENT,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); id = mentionAdapter.getItemId(0);
mentionAdapter.getData().add(mTwitter.getMention(page,id)); mentionAdapter.getData().add(mTwitter.getMention(page,id));
} }
break;
} }
} catch (TwitterException e) {
return false;
} catch (Exception e){ } catch (Exception e){
e.printStackTrace(); e.printStackTrace();
return false; return FAIL;
} }
return true; return MODE;
} }
@Override @Override
protected void onPostExecute(Boolean success) { protected void onPostExecute(Integer MODE) {
if(success) { switch(MODE) {
if(timelineAdapter != null) { case HOME:
if(timelineList.getAdapter().getCount() == 0)
timelineList.setAdapter(timelineAdapter);
else
timelineAdapter.notifyDataSetChanged();
timelineRefresh.setRefreshing(false); timelineRefresh.setRefreshing(false);
} else if(trendsAdapter != null) { if(timelineList.getAdapter().getCount() == 0) {
trendList.setAdapter(trendsAdapter); timelineList.setAdapter(timelineAdapter);
} else {
timelineAdapter.notifyDataSetChanged();
}
break;
case TRND:
trendRefresh.setRefreshing(false); trendRefresh.setRefreshing(false);
} else if(mentionAdapter != null) { trendList.setAdapter(trendsAdapter);
if(mentionList.getAdapter().getCount() == 0) break;
mentionList.setAdapter(mentionAdapter);
else case MENT:
mentionAdapter.notifyDataSetChanged();
mentionRefresh.setRefreshing(false); mentionRefresh.setRefreshing(false);
} if(mentionList.getAdapter().getCount() == 0) {
} else { mentionList.setAdapter(mentionAdapter);
Toast.makeText(context, context.getString(R.string.connection_failure), Toast.LENGTH_LONG).show(); } else {
mentionAdapter.notifyDataSetChanged();
}
break;
case FAIL:
default:
Toast.makeText(context, context.getString(R.string.connection_failure), Toast.LENGTH_LONG).show();
} }
} }
} }

View File

@ -3,15 +3,12 @@ package org.nuclearfog.twidda.backend;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.widget.Button;
import android.widget.Toast; import android.widget.Toast;
import org.nuclearfog.twidda.MainActivity;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.window.LoginPage; 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 Context context;
private String errMSG = "";
/** /**
* Register App for Account access * Register App for Account access
@ -25,11 +22,7 @@ public class RegisterAccount extends AsyncTask<String, Void, String> {
@Override @Override
protected void onPreExecute() { } protected Boolean doInBackground( String... twitterPin ) {
@Override
protected String doInBackground( String... twitterPin ) {
String pin = twitterPin[0]; String pin = twitterPin[0];
TwitterEngine mTwitter = TwitterEngine.getInstance(context); TwitterEngine mTwitter = TwitterEngine.getInstance(context);
try { try {
@ -37,22 +30,22 @@ public class RegisterAccount extends AsyncTask<String, Void, String> {
mTwitter.request(); mTwitter.request();
}else { }else {
mTwitter.initialize(pin); mTwitter.initialize(pin);
return "success"; return true;
} }
} catch ( Exception e ) { } catch ( Exception e ) {
return e.getMessage(); errMSG = e.getMessage();
} }
return " "; return false;
} }
@Override @Override
protected void onPostExecute(String msg) { protected void onPostExecute(Boolean success) {
if( msg.equals("success") ) { if(success) {
((LoginPage)context).setResult(Activity.RESULT_OK); ((LoginPage)context).setResult(Activity.RESULT_OK);
((LoginPage)context).finish(); ((LoginPage)context).finish();
} else if( !msg.trim().isEmpty() ) { } else if(errMSG.isEmpty()) {
Toast.makeText(context,"Fehler: "+msg,Toast.LENGTH_LONG).show(); Toast.makeText(context,"Fehler: "+errMSG,Toast.LENGTH_LONG).show();
} }
} }
} }

View File

@ -30,11 +30,13 @@ import org.nuclearfog.twidda.viewadapter.TimelineAdapter;
import org.nuclearfog.twidda.window.ColorPreferences; import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.window.TweetDetail; 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 RETWEET = 0;
public static final long FAVORITE = 1; public static final long FAVORITE = 1;
public static final long DELETE = 2; public static final long DELETE = 2;
public static final long LOAD_TWEET = 3;
private Context c; private Context c;
private ListView replyList; private ListView replyList;
@ -47,7 +49,7 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
private String ansStr, rtStr, favStr, repliedUsername, apiName; private String ansStr, rtStr, favStr, repliedUsername, apiName;
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private boolean retweeted, favorited, toggleImg, verified; private boolean retweeted, favorited, toggleImg, verified;
private int ansNo = 0; private int rt, fav, ansNo = 0;
private int highlight; private int highlight;
private long userReply, tweetReplyID; private long userReply, tweetReplyID;
private Bitmap profile_btm, tweet_btm; 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); txtAns = (TextView) ((TweetDetail)c).findViewById(R.id.no_ans_detail);
txtRet = (TextView) ((TweetDetail)c).findViewById(R.id.no_rt_detail); txtRet = (TextView) ((TweetDetail)c).findViewById(R.id.no_rt_detail);
txtFav = (TextView) ((TweetDetail)c).findViewById(R.id.no_fav_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); profile_img = (ImageView) ((TweetDetail)c).findViewById(R.id.profileimage_detail);
tweet_img = (ImageView) ((TweetDetail)c).findViewById(R.id.tweet_image); 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. * @returns false if Tweet is already loaded.
*/ */
@Override @Override
protected Boolean doInBackground(Long... id) { protected Long doInBackground(Long... data) {
long tweetID = id[0]; long tweetID = data[0];
long mode = data[1];
try { try {
twitter4j.Status currentTweet = mTwitter.getStatus(tweetID); twitter4j.Status currentTweet = mTwitter.getStatus(tweetID);
rtStr = Integer.toString(currentTweet.getRetweetCount()); rt = currentTweet.getRetweetCount();
favStr = Integer.toString(currentTweet.getFavoriteCount()); fav = currentTweet.getFavoriteCount();
userReply = currentTweet.getInReplyToUserId(); userReply = currentTweet.getInReplyToUserId();
tweetReplyID = currentTweet.getInReplyToStatusId(); tweetReplyID = currentTweet.getInReplyToStatusId();
verified = currentTweet.getUser().isVerified(); verified = currentTweet.getUser().isVerified();
retweeted = currentTweet.isRetweetedByMe(); retweeted = currentTweet.isRetweetedByMe();
favorited = currentTweet.isFavorited(); favorited = currentTweet.isFavorited();
if(id.length == 1) { if(mode == LOAD_TWEET) {
tweetStr = currentTweet.getText(); tweetStr = currentTweet.getText();
usernameStr = currentTweet.getUser().getName(); usernameStr = currentTweet.getUser().getName();
scrNameStr = '@'+currentTweet.getUser().getScreenName(); scrNameStr = '@'+currentTweet.getUser().getScreenName();
@ -115,40 +118,43 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
if(toggleImg) { if(toggleImg) {
setMedia(currentTweet); setMedia(currentTweet);
} }
return true;
} else { } else if(mode == RETWEET) {
long mode = id[1]; if(retweeted) {
if(mode==RETWEET) { mTwitter.retweet(tweetID, true);
if(retweeted) { retweeted = false;
mTwitter.retweet(tweetID, true); rt--;
// TODO del Retweet } else {
} else { mTwitter.retweet(tweetID, false);
mTwitter.retweet(tweetID, false); retweeted = true;
retweeted = true; rt++;
}
} 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);
} }
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) { } catch(Exception err) {
err.printStackTrace(); err.printStackTrace();
return false; return ERROR;
} }
return mode;
} }
@Override @Override
protected void onPostExecute(Boolean tweetLoaded) { protected void onPostExecute(Long mode) {
if(tweetLoaded) { if(mode == LOAD_TWEET) {
ansStr = Integer.toString(ansNo); ansStr = Integer.toString(ansNo);
rtStr = Integer.toString(rt);
favStr = Integer.toString(fav);
tweet.setText(highlight(tweetStr)); tweet.setText(highlight(tweetStr));
username.setText(usernameStr); username.setText(usernameStr);
scrName.setText(scrNameStr); scrName.setText(scrNameStr);
@ -169,23 +175,24 @@ public class ShowStatus extends AsyncTask<Long, Void, Boolean> {
profile_img.setImageBitmap(profile_btm); profile_img.setImageBitmap(profile_btm);
tweet_img.setImageBitmap(tweet_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(); setIcons();
txtRet.setText(rtStr); txtRet.setText(rtStr);
txtFav.setText(favStr); 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 { private void setMedia(twitter4j.Status tweet) throws Exception {

View File

@ -369,6 +369,9 @@ public class TwitterEngine {
public void retweet(long id, boolean active) throws TwitterException { public void retweet(long id, boolean active) throws TwitterException {
if(!active) { if(!active) {
twitter.retweetStatus(id); twitter.retweetStatus(id);
}//TODO remove Retweet
else {
deleteTweet(id);
} }
} }

View File

@ -10,7 +10,6 @@ import android.widget.Toast;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.RegisterAccount; import org.nuclearfog.twidda.backend.RegisterAccount;
public class LoginPage extends Activity implements View.OnClickListener { public class LoginPage extends Activity implements View.OnClickListener {
private EditText pin; private EditText pin;

View File

@ -157,6 +157,6 @@ public class TweetDetail extends AppCompatActivity implements View.OnClickListen
tweetaction.setBackgroundColor(backgroundColor); tweetaction.setBackgroundColor(backgroundColor);
answer_list.setBackgroundColor(backgroundColor); answer_list.setBackgroundColor(backgroundColor);
txtTw.setTextColor(fontColor); txtTw.setTextColor(fontColor);
new ShowStatus(this).execute(tweetID); new ShowStatus(this).execute(tweetID, ShowStatus.LOAD_TWEET);
} }
} }