added set consumer key dialog

This commit is contained in:
Mariotaku Lee 2015-06-29 15:21:12 +08:00
parent aec4447c65
commit bbe75e1df4
6 changed files with 119 additions and 17 deletions

View File

@ -249,6 +249,7 @@ public interface SharedPreferenceConstants {
@Preference(type = STRING, hasDefault = true, defaultString = TwidereConstants.TWITTER_CONSUMER_SECRET)
String KEY_CONSUMER_SECRET = "consumer_secret";
String KEY_SETTINGS_WIZARD_COMPLETED = "settings_wizard_completed";
String KEY_CONSUMER_KEY_SECRET_SET = "consumer_key_secret_set";
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = true)
String KEY_CARD_ANIMATION = "card_animation";
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = true)

View File

@ -1038,22 +1038,6 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL
// mAccountActionProvider.setSelectedAccounts(mAccountsAdapter.getSelectedAccounts());
}
@TargetApi(Build.VERSION_CODES.KITKAT)
private boolean openDocument() {
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
final String[] mimeTypes = {"image/png", "image/jpeg", "image/gif"};
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivityForResult(intent, REQUEST_OPEN_DOCUMENT);
} catch (final ActivityNotFoundException e) {
return false;
}
return true;
}
private boolean pickImage() {
final Intent intent = ThemedImagePickerActivity.withThemed(this).pickImage().build();
startActivityForResult(intent, REQUEST_PICK_IMAGE);
@ -1375,6 +1359,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL
mSelection = new LongSparseArray<>();
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(activity,
SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE, SharedPreferenceConstants.class);
assert preferences != null;
mNameFirst = preferences.getBoolean(KEY_NAME_FIRST);
}

View File

@ -19,11 +19,11 @@
package org.mariotaku.twidere.activity.support;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
@ -42,6 +42,7 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
@ -85,10 +86,12 @@ import org.mariotaku.twidere.util.OAuthPasswordAuthenticator.AuthenticationExcep
import org.mariotaku.twidere.util.OAuthPasswordAuthenticator.AuthenticityTokenException;
import org.mariotaku.twidere.util.OAuthPasswordAuthenticator.WrongUserPassException;
import org.mariotaku.twidere.util.ParseUtils;
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.TwidereActionModeForChildListener;
import org.mariotaku.twidere.util.TwidereColorUtils;
import org.mariotaku.twidere.util.TwitterAPIFactory;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.support.ViewSupport;
import org.mariotaku.twidere.util.support.view.ViewOutlineProviderCompat;
import org.mariotaku.twidere.view.TintedStatusNativeActionModeAwareLayout;
@ -346,6 +349,15 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList
final ColorStateList color = ColorStateList.valueOf(resources.getColor(R.color.material_light_green));
ViewCompat.setBackgroundTintList(mSignInButton, color);
setSignInButton();
final String consumerKey = mPreferences.getString(KEY_CONSUMER_KEY, null);
final String consumerSecret = mPreferences.getString(KEY_CONSUMER_SECRET, null);
if (savedInstanceState == null && !mPreferences.getBoolean(KEY_CONSUMER_KEY_SECRET_SET, false)
&& !Utils.isCustomConsumerKeySecret(consumerKey, consumerSecret)) {
final SetConsumerKeySecretDialogFragment df = new SetConsumerKeySecretDialogFragment();
df.setCancelable(false);
df.show(getSupportFragmentManager(), "set_consumer_key_secret");
}
}
private void doLogin() {
@ -816,4 +828,38 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList
apiUrlFormat, false, noVersionSuffix);
}
}
public static class SetConsumerKeySecretDialogFragment extends BaseSupportDialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(R.layout.dialog_set_consumer_key_secret);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final EditText editConsumerKey = (EditText) ((Dialog) dialog).findViewById(R.id.consumer_key);
final EditText editConsumerSecret = (EditText) ((Dialog) dialog).findViewById(R.id.consumer_secret);
final SharedPreferences prefs = SharedPreferencesWrapper.getInstance(getActivity(), SHARED_PREFERENCES_NAME, MODE_PRIVATE);
final SharedPreferences.Editor editor = prefs.edit();
editor.putString(KEY_CONSUMER_KEY, ParseUtils.parseString(editConsumerKey.getText()));
editor.putString(KEY_CONSUMER_SECRET, ParseUtils.parseString(editConsumerSecret.getText()));
editor.apply();
}
});
final AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
final EditText editConsumerKey = (EditText) ((Dialog) dialog).findViewById(R.id.consumer_key);
final EditText editConsumerSecret = (EditText) ((Dialog) dialog).findViewById(R.id.consumer_secret);
final SharedPreferences prefs = SharedPreferencesWrapper.getInstance(getActivity(), SHARED_PREFERENCES_NAME, MODE_PRIVATE);
editConsumerKey.setText(prefs.getString(KEY_CONSUMER_KEY, null));
editConsumerSecret.setText(prefs.getString(KEY_CONSUMER_SECRET, null));
}
});
return dialog;
}
}
}

View File

@ -3839,6 +3839,12 @@ public final class Utils implements Constants {
textView.setText(text);
}
public static boolean isCustomConsumerKeySecret(String consumerKey, String consumerSecret) {
if (TextUtils.isEmpty(consumerKey) || TextUtils.isEmpty(consumerSecret)) return false;
return (!TWITTER_CONSUMER_KEY.equals(consumerKey) && !TWITTER_CONSUMER_SECRET.equals(consumerKey))
&& (!TWITTER_CONSUMER_KEY_LEGACY.equals(consumerKey) && !TWITTER_CONSUMER_SECRET_LEGACY.equals(consumerSecret));
}
static class UtilsL {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/element_spacing_normal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/set_consumer_key_secret_message"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="?android:textColorPrimary" />
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/consumer_key"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/consumer_key"
android:inputType="text|textVisiblePassword"
android:singleLine="true"
app:met_baseColor="?android:textColorPrimary"
app:met_floatingLabel="normal"
app:met_floatingLabelText="@string/consumer_key" />
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/consumer_secret"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/consumer_secret"
android:inputType="text|textVisiblePassword"
android:singleLine="true"
app:met_baseColor="?android:textColorPrimary"
app:met_floatingLabel="normal"
app:met_floatingLabelText="@string/consumer_secret" />
</LinearLayout>
</ScrollView>

View File

@ -769,4 +769,5 @@
<string name="this_month">This month</string>
<string name="media_preload">Media preload</string>
<string name="on_mobile_network">On mobile network</string>
<string name="set_consumer_key_secret_message">Twidere is reaching token limit, you will have to create an app at https://apps.twitter.com/ and paste consumer key and secret below.\nIf you continue using default key, you may not be able to sign in.</string>
</resources>