mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-02-06 22:13:21 +01:00
database bugfix, fixed error handling
This commit is contained in:
parent
e6464b277f
commit
1c25c7006d
@ -52,6 +52,8 @@ public class AccountLoader extends AsyncTask<Account, Void, List<Account>> {
|
||||
if (fragment != null) {
|
||||
if (accounts != null) {
|
||||
fragment.onSuccess(accounts);
|
||||
} else {
|
||||
fragment.onError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +71,6 @@ public class ListLoader extends AsyncTask<Long, Void, UserLists> {
|
||||
}
|
||||
} catch (TwitterException twException) {
|
||||
this.twException = twException;
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -42,8 +42,6 @@ public class ListUpdater extends AsyncTask<Void, Void, UserList> {
|
||||
return twitter.createUserlist(update);
|
||||
} catch (TwitterException err) {
|
||||
this.err = err;
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -95,8 +95,6 @@ public class MessageLoader extends AsyncTask<Long, Void, Directmessages> {
|
||||
db.deleteMessage(messageId);
|
||||
removeMsgId = messageId;
|
||||
}
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -50,15 +50,13 @@ public class MessageUpdater extends AsyncTask<Void, Void, Boolean> {
|
||||
mediaId = twitter.uploadMedia(message.getMediaStream());
|
||||
message.getMediaStream().close();
|
||||
}
|
||||
// upload message and media ID if defined
|
||||
// upload message and media ID
|
||||
if (!isCancelled()) {
|
||||
twitter.sendDirectmessage(id, message.getText(), mediaId);
|
||||
}
|
||||
return true;
|
||||
} catch (TwitterException twException) {
|
||||
this.twException = twException;
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -58,8 +58,6 @@ public class TrendLoader extends AsyncTask<Integer, Void, List<Trend>> {
|
||||
return trends;
|
||||
} catch (TwitterException twException) {
|
||||
this.twException = twException;
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -137,8 +137,6 @@ public class TweetAction extends AsyncTask<TweetAction.Action, Tweet, TweetActio
|
||||
if (twException.getErrorType() == ErrorHandler.TwitterError.RESOURCE_NOT_FOUND) {
|
||||
db.removeStatus(tweetId);
|
||||
}
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -203,8 +203,6 @@ public class TweetLoader extends AsyncTask<Long, Void, List<Tweet>> {
|
||||
}
|
||||
} catch (TwitterException e) {
|
||||
this.twException = e;
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
return tweets;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.nuclearfog.twidda.backend.api.holder.MediaStream;
|
||||
import org.nuclearfog.twidda.backend.api.holder.TweetUpdate;
|
||||
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
@ -62,7 +63,7 @@ public class TweetUpdater extends AsyncTask<Void, Void, Boolean> {
|
||||
return true;
|
||||
} catch (TwitterException twException) {
|
||||
this.twException = twException;
|
||||
} catch (Exception err) {
|
||||
} catch (IOException err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
@ -63,8 +63,6 @@ public class UserExcludeLoader extends AsyncTask<String, Void, Void> {
|
||||
}
|
||||
} catch (TwitterException err) {
|
||||
this.err = err;
|
||||
} catch (Exception err) {
|
||||
// ignore
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1714,7 +1714,7 @@ public class Twitter {
|
||||
* @param params parameter to add to signature
|
||||
* @return header string
|
||||
*/
|
||||
private String buildHeader(String method, String endpoint, List<String> params) {
|
||||
private String buildHeader(String method, String endpoint, List<String> params) throws IOException {
|
||||
String timeStamp = StringTools.getTimestamp();
|
||||
String random = StringTools.getRandomString();
|
||||
String signkey = tokens.getConsumerSec() + "&";
|
||||
|
@ -4,10 +4,9 @@ import static org.nuclearfog.twidda.backend.api.Twitter.SIGNATURE_ALG;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
@ -250,7 +249,7 @@ public final class StringTools {
|
||||
* @param keyString key used to sign
|
||||
* @return key signature
|
||||
*/
|
||||
public static String sign(String method, String endpoint, String param, String keyString) {
|
||||
public static String sign(String method, String endpoint, String param, String keyString) throws IOException {
|
||||
String input = method + "&" + encode(endpoint) + "&" + encode(param);
|
||||
return encode(computeSignature(input, keyString));
|
||||
}
|
||||
@ -262,15 +261,14 @@ public final class StringTools {
|
||||
* @param keyString key used for sign
|
||||
* @return sign string
|
||||
*/
|
||||
public static String computeSignature(String baseString, String keyString) {
|
||||
public static String computeSignature(String baseString, String keyString) throws IOException {
|
||||
try {
|
||||
SecretKey secretKey = new SecretKeySpec(keyString.getBytes(), SIGNATURE_ALG);
|
||||
Mac mac = Mac.getInstance(SIGNATURE_ALG);
|
||||
mac.init(secretKey);
|
||||
return new String(Base64.encode(mac.doFinal(baseString.getBytes()), Base64.DEFAULT)).trim();
|
||||
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new IOException("error generating signature!");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
@ -98,7 +98,8 @@ public class DatabaseAdapter {
|
||||
+ MessageTable.SINCE + " INTEGER,"
|
||||
+ MessageTable.FROM + " INTEGER,"
|
||||
+ MessageTable.TO + " INTEGER,"
|
||||
+ MessageTable.MESSAGE + " TEXT);";
|
||||
+ MessageTable.MESSAGE + " TEXT,"
|
||||
+ MessageTable.MEDIA + " TEXT);";
|
||||
|
||||
/**
|
||||
* table for tweet register
|
||||
@ -108,6 +109,7 @@ public class DatabaseAdapter {
|
||||
+ TweetRegisterTable.OWNER + " INTEGER,"
|
||||
+ TweetRegisterTable.ID + " INTEGER,"
|
||||
+ TweetRegisterTable.REGISTER + " INTEGER,"
|
||||
+ TweetRegisterTable.RETWEETUSER + " INTEGER,"
|
||||
+ "FOREIGN KEY(" + TweetRegisterTable.ID + ")"
|
||||
+ "REFERENCES " + TweetTable.NAME + "(" + TweetTable.ID + "));";
|
||||
|
||||
@ -146,12 +148,6 @@ public class DatabaseAdapter {
|
||||
private static final String INDX_TWEET = "CREATE INDEX IF NOT EXISTS idx_tweet"
|
||||
+ " ON " + TweetTable.NAME + "(" + TweetTable.USER + ");";
|
||||
|
||||
/**
|
||||
* table index for trend table
|
||||
*/
|
||||
private static final String INDX_TREND = "CREATE INDEX IF NOT EXISTS idx_trend"
|
||||
+ " ON " + TrendTable.NAME + "(" + TrendTable.ID + ");";
|
||||
|
||||
/**
|
||||
* table index for tweet register
|
||||
*/
|
||||
@ -252,7 +248,6 @@ public class DatabaseAdapter {
|
||||
db.execSQL(TABLE_USER_REGISTER);
|
||||
// create index
|
||||
db.execSQL(INDX_TWEET);
|
||||
db.execSQL(INDX_TREND);
|
||||
db.execSQL(INDX_TWEET_REG);
|
||||
db.execSQL(INDX_USER_REG);
|
||||
if (db.getVersion() == 0) {
|
||||
|
@ -6,10 +6,12 @@ import static org.nuclearfog.twidda.dialog.ConfirmDialog.DialogType;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.adapter.AccountAdapter;
|
||||
import org.nuclearfog.twidda.adapter.AccountAdapter.OnAccountClickListener;
|
||||
import org.nuclearfog.twidda.backend.AccountLoader;
|
||||
@ -110,7 +112,7 @@ public class AccountFragment extends ListFragment implements OnAccountClickListe
|
||||
}
|
||||
|
||||
/**
|
||||
* called from {@link AccountLoader}
|
||||
* called from {@link AccountLoader} to set login information
|
||||
*
|
||||
* @param result login information
|
||||
*/
|
||||
@ -118,4 +120,11 @@ public class AccountFragment extends ListFragment implements OnAccountClickListe
|
||||
adapter.setData(result);
|
||||
setRefresh(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* called from {@link AccountLoader} when an error occurs
|
||||
*/
|
||||
public void onError() {
|
||||
Toast.makeText(requireContext(), R.string.error_login_information, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
@ -226,4 +226,5 @@
|
||||
<string name="toolbar_tweet_favoriter">Tweet favorisiert von</string>
|
||||
<string name="toolbar_tweet_liker">Tweet gelikt von</string>
|
||||
<string name="error_forbidden_api_access">Diese API unterstützt nicht diese Aktion!</string>
|
||||
<string name="error_login_information">Login Informationen konnten nicht geladen werden!</string>
|
||||
</resources>
|
@ -209,6 +209,7 @@
|
||||
<string name="error_twitter_search">Error, search query is too long or contains illegal characters!</string>
|
||||
<string name="error_not_defined">Not specified error!</string>
|
||||
<string name="error_forbidden_api_access">API does not support this operation!</string>
|
||||
<string name="error_login_information">could not load login information!</string>
|
||||
|
||||
<!-- menu icon strings -->
|
||||
<string name="menu_tweet">write Tweet</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user