Improves user search feature

This commit is contained in:
tom79 2017-08-02 12:17:43 +02:00
parent 37cffea2e0
commit 941b877f70
6 changed files with 81 additions and 34 deletions

View File

@ -46,6 +46,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
@ -120,8 +121,6 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAccountshInterface, OnRetrieveAttachmentInterface, OnPostStatusActionInterface {
private int charsInCw;
private int charsInToot;
private int maxChar;
private String visibility;
private final int PICK_IMAGE = 56556;
@ -147,6 +146,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
private long restored;
private TextView title;
private ImageView pp_actionBar;
private ProgressBar pp_progress;
private Toast mToast;
@ -173,11 +173,14 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
close_toot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(toot_content.getWindowToken(), 0);
finish();
}
});
title = (TextView) actionBar.getCustomView().findViewById(R.id.toolbar_title);
pp_actionBar = (ImageView) actionBar.getCustomView().findViewById(R.id.pp_actionBar);
pp_progress = (ProgressBar) actionBar.getCustomView().findViewById(R.id.pp_progress);
}
@ -285,8 +288,8 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
toot_content.setText( String.format("\n%s", sharedContent));
}
attachments = new ArrayList<>();
charsInCw = 0;
charsInToot = 0;
int charsInCw = 0;
int charsInToot = 0;
maxChar = 500;
//Register LocalBroadcast to receive selected accounts after search
@ -307,6 +310,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
toot_content.setSelection(toot_content.getText().length());
}
toot_show_accounts.setVisibility(View.GONE);
showKeyboard();
}
};
LocalBroadcastManager.getInstance(this).registerReceiver(search_validate, new IntentFilter(Helper.SEARCH_VALIDATE_ACCOUNT));
@ -321,6 +325,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
@Override
public void onClick(View v) {
toot_show_accounts.setVisibility(View.GONE);
showKeyboard();
}
});
@ -439,6 +444,10 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
Matcher m = sPattern.matcher(s.toString().substring(s.toString().length()- length, s.toString().length()));
if(m.matches()) {
String search = m.group(3);
if( pp_progress != null && pp_actionBar != null) {
pp_progress.setVisibility(View.VISIBLE);
pp_actionBar.setVisibility(View.GONE);
}
new RetrieveSearchAccountsAsyncTask(getApplicationContext(),search,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
toot_show_accounts.setVisibility(View.GONE);
@ -505,6 +514,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
restoreToot(restored);
}
changeColor();
}
@ -751,6 +761,14 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
LocalBroadcastManager.getInstance(this).unregisterReceiver(search_validate);
}
@Override
public void onBackPressed() {
if( toot_show_accounts.getVisibility() == View.VISIBLE) {
toot_show_accounts.setVisibility(View.GONE);
showKeyboard();
}else
super.onBackPressed();
}
@Override
public void onRetrieveAttachment(final Attachment attachment, Error error) {
loading_picture.setVisibility(View.GONE);
@ -933,6 +951,10 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
@Override
public void onRetrieveSearchAccounts(APIResponse apiResponse) {
if( pp_progress != null && pp_actionBar != null) {
pp_progress.setVisibility(View.GONE);
pp_actionBar.setVisibility(View.VISIBLE);
}
if( apiResponse.getError() != null){
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
@ -946,6 +968,8 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
toot_lv_accounts.setAdapter(accountsListAdapter);
accountsListAdapter.notifyDataSetChanged();
toot_show_accounts.setVisibility(View.VISIBLE);
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(toot_content.getWindowToken(), 0);
}
}
@ -1032,6 +1056,11 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
}
}
private void showKeyboard(){
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(toot_content.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
}
private void tootReply(){
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);

View File

@ -43,7 +43,7 @@ public class RetrieveSearchAccountsAsyncTask extends AsyncTask<Void, Void, Void>
@Override
protected Void doInBackground(Void... params) {
API api = new API(context);
apiResponse = api.searchAccounts(query);
apiResponse = api.searchAccounts(query, 10);
return null;
}

View File

@ -287,6 +287,7 @@ public class API {
return getStatus(accountId, false, false, max_id, null, tootPerPage);
}
/**
* Retrieves status for the account *synchronously*
*
@ -1137,12 +1138,16 @@ public class API {
* @param query String search
* @return APIResponse
*/
public APIResponse searchAccounts(String query) {
public APIResponse searchAccounts(String query, int count) {
RequestParams params = new RequestParams();
params.add("q", query);
//params.put("resolve","false");
params.add("limit", "4");
if( count < 5)
count = 5;
if( count > 40 )
count = 40;
params.add("limit", String.valueOf(count));
get("/accounts/search", params, new JsonHttpResponseHandler() {
@Override

View File

@ -16,6 +16,7 @@
see <http://www.gnu.org/licenses>.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -85,6 +86,29 @@
android:minLines="4"
android:layout_weight="1"
android:layout_height="0dp" />
<RelativeLayout
android:visibility="gone"
android:id="@+id/toot_show_accounts"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/toot_lv_accounts"
android:dividerHeight="0dp"
android:divider="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/toot_close_accounts"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
app:fabSize="mini"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/ic_close" />
</RelativeLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -111,35 +135,14 @@
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<RelativeLayout
android:visibility="gone"
android:id="@+id/toot_show_accounts"
android:maxHeight="300dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.FloatingActionButton
android:id="@+id/toot_close_accounts"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
app:fabSize="mini"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/ic_close" />
<ListView
android:id="@+id/toot_lv_accounts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<ImageButton
android:id="@+id/toot_picture"
android:padding="5dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_action_camera"
/>
tools:ignore="ContentDescription" />
<ImageButton
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
@ -148,7 +151,7 @@
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_action_globe"
/>
tools:ignore="ContentDescription" />
<Button
android:id="@+id/toot_cw"
android:padding="5dp"

View File

@ -20,7 +20,6 @@
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_marginTop="10dp"
style="?attr/cardStyle"
card_view:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
@ -31,6 +30,7 @@
android:id="@+id/account_container"
android:orientation="horizontal">
<ImageView
android:layout_margin="5dp"
android:layout_gravity="center"
android:id="@+id/account_pp"
android:layout_width="30dp"

View File

@ -23,7 +23,6 @@
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="?attr/popupOverlay">
<ImageView
android:id="@+id/close_toot"
android:src="@drawable/ic_close"
@ -32,7 +31,7 @@
android:gravity="center_vertical"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:contentDescription="" />
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/pp_actionBar"
android:layout_width="30dp"
@ -42,10 +41,21 @@
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
tools:ignore="ContentDescription" />
<ProgressBar
android:id="@+id/pp_progress"
android:visibility="gone"
android:indeterminate="true"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_width="30dp"
android:layout_height="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:textSize="14sp"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>