diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java index 27d5c939a..e1585bf3c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java @@ -24,6 +24,7 @@ import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.text.TextWatcher; +import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -74,6 +75,8 @@ public abstract class BaseLoginActivity extends AppCompatActivity { private static boolean client_id_for_webview = false; private String instance; private AutoCompleteTextView login_instance; + private EditText login_uid; + private EditText login_passwd; boolean isLoadingInstance = false; @Override @@ -94,8 +97,11 @@ public abstract class BaseLoginActivity extends AppCompatActivity { }else { changeDrawableColor(getApplicationContext(), R.drawable.mastodon_icon, R.color.mastodonC3); } - final Button connectionButton = (Button) findViewById(R.id.login_button); - login_instance = (AutoCompleteTextView) findViewById(R.id.login_instance); + final Button connectionButton = findViewById(R.id.login_button); + login_instance = findViewById(R.id.login_instance); + login_uid = findViewById(R.id.login_uid); + login_passwd = findViewById(R.id.login_passwd); + if( theme == Helper.THEME_LIGHT) { connectionButton.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white)); @@ -153,7 +159,7 @@ public abstract class BaseLoginActivity extends AppCompatActivity { connectionButton.setEnabled(false); - login_two_step = (TextView) findViewById(R.id.login_two_step); + login_two_step = findViewById(R.id.login_two_step); login_two_step.setVisibility(View.GONE); login_two_step.setPaintFlags(login_two_step.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); login_two_step.setOnClickListener(new View.OnClickListener() { @@ -181,7 +187,7 @@ public abstract class BaseLoginActivity extends AppCompatActivity { @Override protected void onResume(){ super.onResume(); - Button connectionButton = (Button) findViewById(R.id.login_button); + Button connectionButton = findViewById(R.id.login_button); if (login_instance.getText() != null && login_instance.getText().toString().length() > 0 && client_id_for_webview) { connectionButton.setEnabled(false); client_id_for_webview = false; @@ -190,7 +196,7 @@ public abstract class BaseLoginActivity extends AppCompatActivity { } private void retrievesClientId(){ - final Button connectionButton = (Button) findViewById(R.id.login_button); + final Button connectionButton = findViewById(R.id.login_button); try { instance = URLEncoder.encode(login_instance.getText().toString().trim(), "utf-8"); } catch (UnsupportedEncodingException e) { @@ -254,8 +260,6 @@ public abstract class BaseLoginActivity extends AppCompatActivity { requestParams.add(Helper.CLIENT_ID, sharedpreferences.getString(Helper.CLIENT_ID, null)); requestParams.add(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null)); requestParams.add("grant_type", "password"); - EditText login_uid = (EditText) findViewById(R.id.login_uid); - EditText login_passwd = (EditText) findViewById(R.id.login_passwd); requestParams.add("username",login_uid.getText().toString().trim()); requestParams.add("password",login_passwd.getText().toString().trim()); requestParams.add("scope"," read write follow"); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index ecf318e25..cc5ac4846 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -1213,37 +1213,39 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc toot_content.setThreshold(1); toot_content.setAdapter(accountsListAdapter); final String oldContent = toot_content.getText().toString(); - String[] searchA = oldContent.substring(0,currentCursorPosition).split("@"); - if( searchA.length > 0 ) { - final String search = searchA[searchA.length - 1]; - toot_content.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - Account account = accounts.get(position); - String deltaSearch = ""; - if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length()) - deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition); - else { - if (currentCursorPosition >= oldContent.length()) - deltaSearch = oldContent.substring(currentCursorPosition - searchLength, oldContent.length()); - } + if( oldContent.length() >= currentCursorPosition) { + String[] searchA = oldContent.substring(0, currentCursorPosition).split("@"); + if (searchA.length > 0) { + final String search = searchA[searchA.length - 1]; + toot_content.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Account account = accounts.get(position); + String deltaSearch = ""; + if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length()) + deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition); + else { + if (currentCursorPosition >= oldContent.length()) + deltaSearch = oldContent.substring(currentCursorPosition - searchLength, oldContent.length()); + } - if (!search.equals("")) - deltaSearch = deltaSearch.replace("@" + search, ""); - String newContent = oldContent.substring(0, currentCursorPosition - searchLength); - newContent += deltaSearch; - newContent += "@" + account.getAcct() + " "; - int newPosition = newContent.length(); - if (currentCursorPosition < oldContent.length() - 1) - newContent += oldContent.substring(currentCursorPosition, oldContent.length() - 1); - toot_content.setText(newContent); - toot_space_left.setText(String.valueOf(toot_content.length())); - toot_content.setSelection(newPosition); - AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, new ArrayList()); - toot_content.setThreshold(1); - toot_content.setAdapter(accountsListAdapter); - } - }); + if (!search.equals("")) + deltaSearch = deltaSearch.replace("@" + search, ""); + String newContent = oldContent.substring(0, currentCursorPosition - searchLength); + newContent += deltaSearch; + newContent += "@" + account.getAcct() + " "; + int newPosition = newContent.length(); + if (currentCursorPosition < oldContent.length() - 1) + newContent += oldContent.substring(currentCursorPosition, oldContent.length() - 1); + toot_content.setText(newContent); + toot_space_left.setText(String.valueOf(toot_content.length())); + toot_content.setSelection(newPosition); + AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, new ArrayList()); + toot_content.setThreshold(1); + toot_content.setAdapter(accountsListAdapter); + } + }); + } } } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java index 7ee1e1153..ebf21a47f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java @@ -767,40 +767,42 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio notifications.removeAll(notificationsToRemove); notificationsListAdapter.notifyDataSetChanged(); } - if (statusAction == API.StatusAction.REBLOG) { - for (Notification notification : notifications) { - if (notification.getStatus().getId().equals(targetedId)) { - notification.getStatus().setReblogs_count(notification.getStatus().getReblogs_count() + 1); - break; + if( targetedId != null ) { + if (statusAction == API.StatusAction.REBLOG) { + for (Notification notification : notifications) { + if (notification.getStatus() != null && notification.getStatus().getId().equals(targetedId)) { + notification.getStatus().setReblogs_count(notification.getStatus().getReblogs_count() + 1); + break; + } } - } - notificationsListAdapter.notifyDataSetChanged(); - } else if (statusAction == API.StatusAction.UNREBLOG) { - for (Notification notification : notifications) { - if (notification.getStatus().getId().equals(targetedId)) { - if (notification.getStatus().getReblogs_count() - 1 >= 0) - notification.getStatus().setReblogs_count(notification.getStatus().getReblogs_count() - 1); - break; + notificationsListAdapter.notifyDataSetChanged(); + } else if (statusAction == API.StatusAction.UNREBLOG) { + for (Notification notification : notifications) { + if (notification.getStatus() != null && notification.getStatus().getId().equals(targetedId)) { + if (notification.getStatus().getReblogs_count() - 1 >= 0) + notification.getStatus().setReblogs_count(notification.getStatus().getReblogs_count() - 1); + break; + } } - } - notificationsListAdapter.notifyDataSetChanged(); - } else if (statusAction == API.StatusAction.FAVOURITE) { - for (Notification notification : notifications) { - if (notification.getStatus().getId().equals(targetedId)) { - notification.getStatus().setFavourites_count(notification.getStatus().getFavourites_count() + 1); - break; + notificationsListAdapter.notifyDataSetChanged(); + } else if (statusAction == API.StatusAction.FAVOURITE) { + for (Notification notification : notifications) { + if (notification.getStatus() != null && notification.getStatus().getId().equals(targetedId)) { + notification.getStatus().setFavourites_count(notification.getStatus().getFavourites_count() + 1); + break; + } } - } - notificationsListAdapter.notifyDataSetChanged(); - } else if (statusAction == API.StatusAction.UNFAVOURITE) { - for (Notification notification : notifications) { - if (notification.getStatus().getId().equals(targetedId)) { - if (notification.getStatus().getFavourites_count() - 1 >= 0) - notification.getStatus().setFavourites_count(notification.getStatus().getFavourites_count() - 1); - break; + notificationsListAdapter.notifyDataSetChanged(); + } else if (statusAction == API.StatusAction.UNFAVOURITE) { + for (Notification notification : notifications) { + if (notification.getStatus() != null && notification.getStatus().getId().equals(targetedId)) { + if (notification.getStatus().getFavourites_count() - 1 >= 0) + notification.getStatus().setFavourites_count(notification.getStatus().getFavourites_count() - 1); + break; + } } + notificationsListAdapter.notifyDataSetChanged(); } - notificationsListAdapter.notifyDataSetChanged(); } } diff --git a/app/src/main/res/layout-sw600dp/activity_login.xml b/app/src/main/res/layout-sw600dp/activity_login.xml index c3cfd0bae..81eea3b4a 100644 --- a/app/src/main/res/layout-sw600dp/activity_login.xml +++ b/app/src/main/res/layout-sw600dp/activity_login.xml @@ -44,12 +44,15 @@ android:id="@+id/login_instance" android:layout_width="300dp" android:layout_height="wrap_content" + android:imeOptions="actionNext" + android:maxLines="1" android:inputType="textWebEmailAddress" android:hint="@string/instance_example" /> @@ -58,6 +61,7 @@ android:id = "@+id/login_passwd" android:inputType="textPassword" android:hint="@string/password" + android:maxLines="1" android:layout_width="match_parent" android:layout_height="wrap_content" />