From c6c7b244f6b65fe3717f768668e752dda557c568 Mon Sep 17 00:00:00 2001 From: nuclearfog Date: Thu, 7 Nov 2019 19:57:32 +0100 Subject: [PATCH] code cleanup, gradle update --- .../twidda/backend/Registration.java | 39 ++++++------------- .../twidda/backend/TwitterEngine.java | 1 - .../nuclearfog/twidda/window/LoginPage.java | 14 ++++--- app/src/main/res/layout/page_editprofile.xml | 15 ++++--- app/src/main/res/values-de-rDE/strings.xml | 2 +- app/src/main/res/values/dimens.xml | 1 + app/src/main/res/values/strings.xml | 2 +- build.gradle | 2 +- 8 files changed, 31 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/Registration.java b/app/src/main/java/org/nuclearfog/twidda/backend/Registration.java index f042687b..bfe15db8 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/Registration.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/Registration.java @@ -15,61 +15,46 @@ import twitter4j.TwitterException; /** * Background task for app login */ -public class Registration extends AsyncTask { +public class Registration extends AsyncTask { private WeakReference ui; private TwitterEngine mTwitter; private TwitterException twException; - private String redirectionURL, loginPin; - - - /** - * Get Twitter redirection URL - * - * @param context Activity Context - */ - public Registration(LoginPage context) { - this(context, null); - } - /** * Login to twitter with PIN * * @param context Activity Context - * @param loginPin PIN from twitter website */ - public Registration(LoginPage context, String loginPin) { + public Registration(LoginPage context) { ui = new WeakReference<>(context); mTwitter = TwitterEngine.getInstance(context); - this.loginPin = loginPin; } @Override - protected Boolean doInBackground(Void... v) { + protected String doInBackground(String... param) { try { - if (loginPin == null) - redirectionURL = mTwitter.request(); - else - mTwitter.initialize(loginPin); - return true; + if (param.length == 0) + return mTwitter.request(); + mTwitter.initialize(param[0]); + return ""; } catch (TwitterException twException) { this.twException = twException; } catch (Exception exception) { exception.printStackTrace(); } - return false; + return null; } @Override - protected void onPostExecute(Boolean success) { + protected void onPostExecute(String redirectionURL) { if (ui.get() != null) { - if (success) { - if (redirectionURL != null) { + if (redirectionURL != null) { + if (!redirectionURL.isEmpty()) { ui.get().connect(redirectionURL); - } else if (loginPin != null) { + } else { ui.get().setResult(Activity.RESULT_OK); ui.get().finish(); } diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java b/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java index 79026a92..100e605e 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java @@ -140,7 +140,6 @@ public class TwitterEngine { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); - builder.setTweetModeExtended(true); AccessToken token = new AccessToken(key1, key2); twitter = new TwitterFactory(builder.build()).getInstance(token); } diff --git a/app/src/main/java/org/nuclearfog/twidda/window/LoginPage.java b/app/src/main/java/org/nuclearfog/twidda/window/LoginPage.java index bd2b585f..be4d70cc 100644 --- a/app/src/main/java/org/nuclearfog/twidda/window/LoginPage.java +++ b/app/src/main/java/org/nuclearfog/twidda/window/LoginPage.java @@ -102,12 +102,14 @@ public class LoginPage extends AppCompatActivity implements OnClickListener { break; case R.id.verifier: - String twitterPin = pin.getText().toString(); - if (!twitterPin.trim().isEmpty()) { - registerAsync = new Registration(this, twitterPin); - registerAsync.execute(); - } else { - Toast.makeText(this, R.string.enter_pin, LENGTH_LONG).show(); + if (pin.getText() != null) { + String twitterPin = pin.getText().toString(); + if (!twitterPin.trim().isEmpty()) { + registerAsync = new Registration(this); + registerAsync.execute(twitterPin); + } else { + Toast.makeText(this, R.string.enter_pin, LENGTH_LONG).show(); + } } break; } diff --git a/app/src/main/res/layout/page_editprofile.xml b/app/src/main/res/layout/page_editprofile.xml index ad71911d..3b85fa2c 100644 --- a/app/src/main/res/layout/page_editprofile.xml +++ b/app/src/main/res/layout/page_editprofile.xml @@ -40,19 +40,18 @@