bugfix, cleanup

This commit is contained in:
NudeDude 2018-08-14 00:22:18 +02:00
parent 037c5acb1d
commit 49269eb06d
6 changed files with 78 additions and 52 deletions

View File

@ -36,6 +36,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
private TimelineRecycler timelineAdapter, mentionAdapter;
private TrendRecycler trendsAdapter;
private DatabaseAdapter tweetDb;
private ErrorLog errorLog;
private int woeId;
private int highlight, font;
@ -51,6 +52,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
ui = new WeakReference<>((MainActivity)context);
mTwitter = TwitterEngine.getInstance(context);
GlobalSettings settings = GlobalSettings.getInstance(context);
tweetDb = new DatabaseAdapter(ui.get());
errorLog = new ErrorLog(context);
woeId = settings.getWoeId();
highlight = settings.getHighlightColor();
@ -89,7 +91,6 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
long id = 1L;
List<Tweet> tweets;
try {
DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get());
TrendDatabase trendDb = new TrendDatabase(ui.get());
switch (MODE) {
case HOME:

View File

@ -18,6 +18,8 @@ import org.nuclearfog.twidda.window.TweetPopup;
import java.lang.ref.WeakReference;
import twitter4j.TwitterException;
public class StatusUpload extends AsyncTask<Object, Void, Boolean> implements OnClickListener {
private WeakReference<TweetPopup> ui;
@ -81,7 +83,13 @@ public class StatusUpload extends AsyncTask<Object, Void, Boolean> implements On
mTwitter.sendStatus(tweet,id,path);
}
return true;
} catch(Exception err) {
} catch (TwitterException err) {
int returnCode = err.getErrorCode();
if (returnCode > 0) {
errorLog.add("E: Upload, " + err.getMessage());
}
return false;
} catch (Exception err) {
errorLog.add("E: Upload, " + err.getMessage());
return false;
}

View File

@ -156,14 +156,14 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener,
case R.id.no_rt_detail:
intent = new Intent(this, UserDetail.class);
intent.putExtra("tweetID", tweetID);
intent.putExtra("mode", 2L);
intent.putExtra("mode", 2);
startActivity(intent);
break;
case R.id.no_fav_detail:
intent = new Intent(this, UserDetail.class);
intent.putExtra("tweetID", tweetID);
intent.putExtra("mode", 3L);
intent.putExtra("mode", 3);
startActivity(intent);
break;

View File

@ -23,8 +23,7 @@ import org.nuclearfog.twidda.backend.StatusUpload;
import java.util.ArrayList;
import java.util.List;
public class TweetPopup extends AppCompatActivity implements OnClickListener,
DialogInterface.OnClickListener, StatusUpload.OnTweetSending {
public class TweetPopup extends AppCompatActivity implements OnClickListener, StatusUpload.OnTweetSending {
private StatusUpload sendTweet;
private View imageButton, previewBtn;
@ -77,33 +76,27 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener,
super.onActivityResult(reqCode,returnCode,i);
if(returnCode == RESULT_OK){
String[] mode = {MediaStore.Images.Media.DATA};
if(i.getData() == null)
return;
Cursor c = getContentResolver().query(i.getData(),mode,null,null,null);
if(c != null && c.moveToFirst()) {
if(imgIndex == 0) {
previewBtn.setVisibility(View.VISIBLE);
if (i.getData() != null) {
Cursor c = getContentResolver().query(i.getData(), mode, null, null, null);
if (c != null && c.moveToFirst()) {
if (imgIndex == 0) {
previewBtn.setVisibility(View.VISIBLE);
}
if (imgIndex < 4) {
int index = c.getColumnIndex(mode[0]);
mediaPath.add(c.getString(index));
String count = Integer.toString(++imgIndex);
imgCount.setText(count);
}
if (imgIndex == 4) {
imageButton.setVisibility(View.INVISIBLE);
}
c.close();
}
if(imgIndex < 4) {
int index = c.getColumnIndex(mode[0]);
mediaPath.add(c.getString(index));
String count = Integer.toString(++imgIndex);
imgCount.setText(count);
}
if(imgIndex == 4) {
imageButton.setVisibility(View.INVISIBLE);
}
c.close();
}
}
}
@Override
public void onClick(DialogInterface d, int id) {
if(sendTweet != null)
sendTweet.cancel(true);
finish();
}
@Override
public void onClick(View v) {
@ -139,11 +132,19 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener,
private void showClosingMsg() {
if( !addition.equals(tweet.getText().toString()) || imgIndex > 0) {
AlertDialog.Builder alerta = new AlertDialog.Builder(this);
alerta.setMessage(R.string.should_cancel_tweet);
alerta.setPositiveButton(R.string.yes_confirm,this);
alerta.setNegativeButton(R.string.no_confirm,null);
alerta.show();
AlertDialog.Builder closeDialog = new AlertDialog.Builder(this);
closeDialog.setMessage(R.string.should_cancel_tweet);
closeDialog.setNegativeButton(R.string.no_confirm, null);
closeDialog.setPositiveButton(R.string.yes_confirm, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (sendTweet != null && !sendTweet.isCancelled())
sendTweet.cancel(true);
finish();
}
});
closeDialog.show();
} else {
finish();
}

View File

@ -22,7 +22,7 @@ public class UserDetail extends AppCompatActivity implements OnItemClicked {
private RecyclerView userList;
private UserLists uList;
private long mode = -1;
private int mode = -1;
private long userID = 0;
private long tweetID = 0;
@ -32,7 +32,7 @@ public class UserDetail extends AppCompatActivity implements OnItemClicked {
b = getIntent().getExtras();
if (b != null) {
userID = b.getLong("userID");
mode = b.getLong("mode");
mode = b.getInt("mode");
if (b.containsKey("tweetID"))
tweetID = b.getLong("tweetID");
}
@ -49,6 +49,13 @@ public class UserDetail extends AppCompatActivity implements OnItemClicked {
getUsers();
}
@Override
protected void onDestroy() {
if (uList != null && !uList.isCancelled())
uList.cancel(true);
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu( Menu m ) {
getMenuInflater().inflate(R.menu.user, m);
@ -70,6 +77,7 @@ 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(this, UserProfile.class);
intent.putExtra("userID", userID);
intent.putExtra("username", username);
@ -78,24 +86,32 @@ public class UserDetail extends AppCompatActivity implements OnItemClicked {
private void getUsers() {
uList = new UserLists(UserDetail.this);
String title = "";
int titleId = 0;
if (mode == 0L) {
title = getString(R.string.following);
uList.execute(userID, UserLists.FOLLOWING, -1L);
} else if (mode == 1L) {
title = getString(R.string.follower);
uList.execute(userID, UserLists.FOLLOWERS, -1L);
} else if (mode == 2L) {
title = getString(R.string.retweet);
uList.execute(tweetID, UserLists.RETWEETER, -1L);
} else if (mode == 3L) {
title = getString(R.string.favorite);
uList.execute(tweetID, UserLists.FAVORISER, -1L);
switch (mode) {
case 0:
titleId = R.string.following;
uList.execute(userID, UserLists.FOLLOWING, -1L);
break;
case 1:
titleId = R.string.follower;
uList.execute(userID, UserLists.FOLLOWERS, -1L);
break;
case 2:
titleId = R.string.retweet;
uList.execute(tweetID, UserLists.RETWEETER, -1L);
break;
case 3:
titleId = R.string.favorite;
uList.execute(tweetID, UserLists.FAVORISER, -1L);
break;
}
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(title);
getSupportActionBar().setTitle(titleId);
}
}
}

View File

@ -155,10 +155,10 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
public void onClick(View v) {
switch(v.getId()) {
case R.id.following:
getConnection(0L);
getConnection(0);
break;
case R.id.follower:
getConnection(1L);
getConnection(1);
break;
}
}
@ -258,7 +258,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
}
private void getConnection(long mode) {
private void getConnection(int mode) {
Intent intent = new Intent(this, UserDetail.class);
intent.putExtra("userID", userId);
intent.putExtra("mode", mode);