Search in tabs - part 2 - Improve scroll with tabs

This commit is contained in:
stom79 2018-08-14 11:47:26 +02:00
parent 97ebcd4bda
commit c8f55fb04d
4 changed files with 36 additions and 27 deletions

View File

@ -122,6 +122,8 @@ import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_TARGETED_ACCOUNT;
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_KEYWORD;
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_TAG;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
@ -679,9 +681,7 @@ public abstract class BaseMainActivity extends BaseActivity
long sizeCache = Helper.cacheSize(getCacheDir());
float cacheSize = 0;
if( sizeCache > 0 ) {
if (sizeCache > 0) {
cacheSize = (float) sizeCache / 1000000.0f;
}
cacheSize = (float) sizeCache / 1000000.0f;
}
final float finalCacheSize = cacheSize;
builder.setMessage(getString(R.string.cache_message, String.format("%s %s", String.format(Locale.getDefault(), "%.2f", cacheSize), getString(R.string.cache_units))))
@ -1136,6 +1136,14 @@ public abstract class BaseMainActivity extends BaseActivity
}else if( extras.getInt(INTENT_ACTION) == BACKUP_INTENT){
Intent myIntent = new Intent(BaseMainActivity.this, OwnerStatusActivity.class);
startActivity(myIntent);
}else if(extras.getInt(INTENT_ACTION) == SEARCH_TAG){
String keyword = extras.getString(SEARCH_KEYWORD);
if( keyword != null){
for(int i = 0; i < tabLayout.getTabCount() ; i++ ){
if( tabLayout.getTabAt(i).getText() != null && tabLayout.getTabAt(i).getText().equals(keyword))
tabLayout.getTabAt(i).select();
}
}
}
}else if( Intent.ACTION_SEND.equals(action) && type != null ) {
if ("text/plain".equals(type)) {

View File

@ -17,6 +17,7 @@ package fr.gouv.etalab.mastodon.fragments;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
@ -45,6 +46,9 @@ import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.R;
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_KEYWORD;
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_TAG;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
@ -111,20 +115,12 @@ public class DisplaySearchFragment extends Fragment {
return;
}
new SearchDAO(context, db).insertSearch(keyword);
((BaseMainActivity)context).refreshSearchTab();
searches.add(keyword);
if( textviewNoAction.getVisibility() == View.VISIBLE)
textviewNoAction.setVisibility(View.GONE);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT){
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.black);
}else if(theme == Helper.THEME_DARK){
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.dark_text);
}else if(theme == Helper.THEME_BLACK) {
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.dark_text);
}
searchTootsListAdapter.notifyDataSetChanged();
if( getActivity() != null)
getActivity().recreate();
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(INTENT_ACTION, SEARCH_TAG);
intent.putExtra(SEARCH_KEYWORD, keyword);
startActivity(intent);
}
});
AlertDialog alertDialog = dialogBuilder.create();

View File

@ -209,7 +209,7 @@ public class Helper {
public static final String SHOULD_CONTINUE_STREAMING = "should_continue_streaming";
public static final String SHOULD_CONTINUE_STREAMING_FEDERATED = "should_continue_streaming_federated";
public static final String SHOULD_CONTINUE_STREAMING_LOCAL = "should_continue_streaming_local";
public static final String SEARCH_KEYWORD = "search_keyword";
public static final String CLIP_BOARD = "clipboard";
//Notifications
public static final int NOTIFICATION_INTENT = 1;
@ -218,6 +218,7 @@ public class Helper {
public static final int CHANGE_USER_INTENT = 4;
public static final int ADD_USER_INTENT = 5;
public static final int BACKUP_INTENT = 6;
public static final int SEARCH_TAG = 7;
//Settings
public static final String SET_TOOTS_PER_PAGE = "set_toots_per_page";
public static final String SET_ACCOUNTS_PER_PAGE = "set_accounts_per_page";
@ -2151,7 +2152,6 @@ public class Helper {
public static void addSearchTag(Context context, TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<String> searches = new SearchDAO(context, db).getAllSearch();
int countInitialTab = ((BaseMainActivity) context).countPage;
@ -2162,10 +2162,15 @@ public class Helper {
allTabCount -=1;
}
}
if( searches != null)
for(String search: searches){
if( searches != null) {
for (String search : searches) {
addTab(tableLayout, pagerAdapter, search);
}
if( searches.size() > 0 ){
tableLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tableLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}
}
}
private static void removeTab(TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter, int position) {

View File

@ -19,8 +19,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical">
>
<ImageView
android:id="@+id/tab_icon"
android:layout_centerInParent="true"
@ -29,18 +28,19 @@
android:layout_height="25dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tab_counter"
android:visibility="gone"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:id="@+id/tab_counter"
android:layout_alignRight="@+id/tab_icon"
android:layout_alignEnd="@+id/tab_icon"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:textSize="12sp"
android:textColor="@color/mastodonC1"
android:background="@drawable/shape_counter"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>