diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/SettingsWizardActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/SettingsWizardActivity.java index be43459da..0855661cb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/SettingsWizardActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/SettingsWizardActivity.java @@ -19,6 +19,7 @@ package org.mariotaku.twidere.activity; +import android.Manifest; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; @@ -31,11 +32,13 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; +import android.support.annotation.NonNull; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; @@ -336,11 +339,25 @@ public class SettingsWizardActivity extends Activity implements Constants { } @Override - public void gotoNextPage() { - // Try getting location, some custom rom will popup requirement dialog - Utils.getCachedLocation(getActivity()); + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.gotoNextPage(); } + + @Override + public void gotoNextPage() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + final String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE}; + requestPermissions(permissions, REQUEST_REQUEST_PERMISSIONS); + } else { + // Try getting location, some custom rom will popup requirement dialog + Utils.getCachedLocation(getActivity()); + super.gotoNextPage(); + } + } } public static class WizardPageTabsFragment extends BaseWizardPageFragment { diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java index f9c161bef..2fed306da 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ComposeActivity.java @@ -200,6 +200,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL private boolean mTextChanged; private SetProgressVisibleRunnable mSetProgressVisibleRunnable; private boolean mFragmentResumed; + private int mKeyMetaState; @Override public int getThemeColor() { @@ -311,12 +312,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL public void onClick(final View view) { switch (view.getId()) { case R.id.send: { - if (isQuotingProtectedStatus()) { - new RetweetProtectedStatusWarnFragment().show(getSupportFragmentManager(), - "retweet_protected_status_warning_message"); - } else { - updateStatus(); - } + confirmAndUpdateStatus(); break; } case R.id.account_selector_container: { @@ -335,6 +331,15 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL } } + private void confirmAndUpdateStatus() { + if (isQuotingProtectedStatus()) { + new RetweetProtectedStatusWarnFragment().show(getSupportFragmentManager(), + "retweet_protected_status_warning_message"); + } else { + updateStatus(); + } + } + @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { final Window window = getWindow(); @@ -717,12 +722,32 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL mTextChanged = false; } + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + final int keyCode = event.getKeyCode(); + if (KeyEvent.isModifierKey(keyCode)) { + final int action = event.getAction(); + if (action == MotionEvent.ACTION_DOWN) { + mKeyMetaState |= KeyboardShortcutsHandler.getMetaStateForKeyCode(keyCode); + } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { + mKeyMetaState &= ~KeyboardShortcutsHandler.getMetaStateForKeyCode(keyCode); + } + } + return super.dispatchKeyEvent(event); + } + private void setupEditText() { final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND); EditTextEnterHandler.attach(mEditText, new EnterListener() { @Override - public void onHitEnter() { - updateStatus(); + public boolean shouldCallListener() { + return mKeyMetaState == 0; + } + + @Override + public boolean onHitEnter() { + confirmAndUpdateStatus(); + return true; } }, sendByEnter); mEditText.addTextChangedListener(new TextWatcher() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java index 0f6651567..a2e924eea 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/QuickSearchBarActivity.java @@ -233,8 +233,14 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On EditTextEnterHandler.attach(mSearchQuery, new EnterListener() { @Override - public void onHitEnter() { + public boolean shouldCallListener() { + return true; + } + + @Override + public boolean onHitEnter() { doSearch(); + return true; } }, true); mSearchQuery.addTextChangedListener(new TextWatcher() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java index 6f0f436f2..f7363a4ee 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java @@ -654,11 +654,17 @@ public class MessagesConversationFragment extends BaseSupportFragment implements private void setupEditQuery() { final EditTextEnterHandler queryEnterHandler = EditTextEnterHandler.attach(mEditUserQuery, new EnterListener() { @Override - public void onHitEnter() { + public boolean shouldCallListener() { + return true; + } + + @Override + public boolean onHitEnter() { final ParcelableCredentials account = (ParcelableCredentials) mAccountSpinner.getSelectedItem(); - if (account == null) return; + if (account == null) return false; mEditText.setAccountId(account.account_id); searchUsers(account.account_id, ParseUtils.parseString(mEditUserQuery.getText()), false); + return true; } }, true); queryEnterHandler.addTextChangedListener(new TextWatcher() { @@ -701,8 +707,14 @@ public class MessagesConversationFragment extends BaseSupportFragment implements private void setupEditText() { EditTextEnterHandler.attach(mEditText, new EnterListener() { @Override - public void onHitEnter() { + public boolean shouldCallListener() { + return true; + } + + @Override + public boolean onHitEnter() { sendDirectMessage(); + return true; } }, mPreferences.getBoolean(KEY_QUICK_SEND, false)); mEditText.addTextChangedListener(new TextWatcher() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/RetweetQuoteDialogFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/RetweetQuoteDialogFragment.java index 8a4fc49e9..1fcd26104 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/RetweetQuoteDialogFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/RetweetQuoteDialogFragment.java @@ -130,12 +130,18 @@ public class RetweetQuoteDialogFragment extends BaseSupportDialogFragment implem final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND); final EditTextEnterHandler enterHandler = EditTextEnterHandler.attach(mEditComment, new EditTextEnterHandler.EnterListener() { @Override - public void onHitEnter() { + public boolean shouldCallListener() { + return true; + } + + @Override + public boolean onHitEnter() { final AsyncTwitterWrapper twitter = mTwitterWrapper; final ParcelableStatus status = getStatus(); - if (twitter == null || status == null) return; + if (twitter == null || status == null) return false; retweetOrQuote(twitter, status); dismiss(); + return true; } }, sendByEnter); enterHandler.addTextChangedListener(new TextWatcher() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/EditTextEnterHandler.java b/twidere/src/main/java/org/mariotaku/twidere/util/EditTextEnterHandler.java index e7a045a77..c16021eb4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/EditTextEnterHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/EditTextEnterHandler.java @@ -41,6 +41,7 @@ public class EditTextEnterHandler implements View.OnKeyListener, OnEditorActionL private EnterListener listener; private boolean enabled; private ArrayList textWatchers; + private boolean appendText; public EditTextEnterHandler(@Nullable EnterListener listener, boolean enabled) { this.listener = listener; @@ -64,27 +65,30 @@ public class EditTextEnterHandler implements View.OnKeyListener, OnEditorActionL @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { - if (textWatchers == null) return; - for (TextWatcher textWatcher : textWatchers) { - textWatcher.beforeTextChanged(s, start, count, after); + if (textWatchers != null) { + for (TextWatcher textWatcher : textWatchers) { + textWatcher.beforeTextChanged(s, start, count, after); + } } } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - if (textWatchers == null) return; - for (TextWatcher textWatcher : textWatchers) { - textWatcher.onTextChanged(s, start, before, count); + if (textWatchers != null) { + for (TextWatcher textWatcher : textWatchers) { + textWatcher.onTextChanged(s, start, before, count); + } } + appendText = count > before; } @Override public void afterTextChanged(final Editable s) { final int length = s.length(); - if (enabled && length > 0 && s.charAt(length - 1) == '\n') { - s.delete(length - 1, length); - if (listener != null) { - listener.onHitEnter(); + if (enabled && length > 0 && s.charAt(length - 1) == '\n' && appendText) { + if (shouldCallListener()) { + s.delete(length - 1, length); + dispatchHitEnter(); } } else if (textWatchers != null) { for (TextWatcher textWatcher : textWatchers) { @@ -97,10 +101,7 @@ public class EditTextEnterHandler implements View.OnKeyListener, OnEditorActionL public boolean onEditorAction(final TextView view, final int actionId, final KeyEvent event) { if (!enabled) return false; if (event != null && actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) { - if (listener != null) { - listener.onHitEnter(); - } - return true; + if (shouldCallListener()) return dispatchHitEnter(); } return false; } @@ -108,14 +109,19 @@ public class EditTextEnterHandler implements View.OnKeyListener, OnEditorActionL @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && enabled && event.getAction() == KeyEvent.ACTION_DOWN) { - if (listener != null) { - listener.onHitEnter(); - } - return true; + if (shouldCallListener()) return dispatchHitEnter(); } return false; } + private boolean dispatchHitEnter() { + return listener != null && listener.onHitEnter(); + } + + private boolean shouldCallListener() { + return listener != null && listener.shouldCallListener(); + } + public void setEnabled(boolean enabled) { this.enabled = enabled; } @@ -125,7 +131,9 @@ public class EditTextEnterHandler implements View.OnKeyListener, OnEditorActionL } public interface EnterListener { - void onHitEnter(); + boolean shouldCallListener(); + + boolean onHitEnter(); } } diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index dc24a007a..f87e14b6d 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -768,6 +768,8 @@ Dark theme Location permission Twidere needs location permission when you send tweet containing location. + Storage permission + Twidere needs storage permission when you access documents. Scrapyard Crop image Sent diff --git a/twidere/src/main/res/xml/settings_wizard_page_hints.xml b/twidere/src/main/res/xml/settings_wizard_page_hints.xml index 1b14c7cf8..17d483e77 100644 --- a/twidere/src/main/res/xml/settings_wizard_page_hints.xml +++ b/twidere/src/main/res/xml/settings_wizard_page_hints.xml @@ -1,27 +1,31 @@ - + android:title="@string/wizard_hint_title_location_requirement" /> + + android:title="@string/select_account" /> + android:title="@string/filters" /> + android:title="@string/rate_limit" /> \ No newline at end of file