diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index 512e90b17..1a4177512 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -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)) { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplaySearchFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplaySearchFragment.java index b07813fee..d41550f31 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplaySearchFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplaySearchFragment.java @@ -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(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 042b22774..308f86a11 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -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 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) { diff --git a/app/src/main/res/layout/tab_badge.xml b/app/src/main/res/layout/tab_badge.xml index 58b49e521..509bac104 100644 --- a/app/src/main/res/layout/tab_badge.xml +++ b/app/src/main/res/layout/tab_badge.xml @@ -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"> + > \ No newline at end of file