code cleanup, gradle update

This commit is contained in:
nuclearfog 2019-11-07 19:57:32 +01:00
parent 0cdd375513
commit c6c7b244f6
No known key found for this signature in database
GPG Key ID: ED35E22099354A64
8 changed files with 31 additions and 45 deletions

View File

@ -15,61 +15,46 @@ import twitter4j.TwitterException;
/**
* Background task for app login
*/
public class Registration extends AsyncTask<Void, Void, Boolean> {
public class Registration extends AsyncTask<String, Void, String> {
private WeakReference<LoginPage> 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();
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -40,19 +40,18 @@
<Button
android:id="@+id/edit_upload"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="@dimen/margin_upload_btn"
android:layout_marginStart="@dimen/margin_upload_btn"
android:paddingLeft="@dimen/button_padding"
android:paddingRight="@dimen/button_padding"
android:drawablePadding="@dimen/padding_drawable"
android:maxLines="2"
android:layout_marginLeft="@dimen/margin_upload_btn"
android:layout_weight="1"
android:background="@drawable/button"
android:maxLines="2"
android:paddingLeft="@dimen/editprofile_upload_button_padding"
android:paddingRight="@dimen/button_padding"
app:drawableLeftCompat="@drawable/upload"
app:drawableStartCompat="@drawable/upload"
style="@style/Widget.AppCompat.Button.Borderless" />
app:drawableStartCompat="@drawable/upload" />
</LinearLayout>

View File

@ -123,5 +123,5 @@
<string name="info_not_implemented">Diese Funktion wurde noch nicht hinzugefügt!</string>
<string name="error_cant_copy_clipboard">Link konnte nicht kopiert werden!</string>
<string name="info_gps_attached">GPS Position hinzugefügt</string>
<string name="info_get_location">starte GPS lokalisierung</string>
<string name="info_get_location">starte GPS lokalisierung...</string>
</resources>

View File

@ -50,4 +50,5 @@
<dimen name="preview_margin">10dp</dimen>
<dimen name="dm_item_button_height">20dp</dimen>
<dimen name="tweet_media_button_margin">5dp</dimen>
<dimen name="editprofile_upload_button_padding">12dp</dimen>
</resources>

View File

@ -124,5 +124,5 @@
<string name="info_not_implemented">This function is not implemented yet!</string>
<string name="error_cant_copy_clipboard">can\'t copy link to clipboard!</string>
<string name="info_gps_attached">GPS position added</string>
<string name="info_get_location">starting location</string>
<string name="info_get_location">starting location...</string>
</resources>

View File

@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:3.5.2'
}
}