Search in tabs - part 2 - Improve scroll with tabs
This commit is contained in:
parent
97ebcd4bda
commit
c8f55fb04d
|
@ -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.INTENT_TARGETED_ACCOUNT;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
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.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.THEME_BLACK;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
|
||||||
|
@ -679,9 +681,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
long sizeCache = Helper.cacheSize(getCacheDir());
|
long sizeCache = Helper.cacheSize(getCacheDir());
|
||||||
float cacheSize = 0;
|
float cacheSize = 0;
|
||||||
if( sizeCache > 0 ) {
|
if( sizeCache > 0 ) {
|
||||||
if (sizeCache > 0) {
|
cacheSize = (float) sizeCache / 1000000.0f;
|
||||||
cacheSize = (float) sizeCache / 1000000.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
final float finalCacheSize = cacheSize;
|
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))))
|
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){
|
}else if( extras.getInt(INTENT_ACTION) == BACKUP_INTENT){
|
||||||
Intent myIntent = new Intent(BaseMainActivity.this, OwnerStatusActivity.class);
|
Intent myIntent = new Intent(BaseMainActivity.this, OwnerStatusActivity.class);
|
||||||
startActivity(myIntent);
|
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 ) {
|
}else if( Intent.ACTION_SEND.equals(action) && type != null ) {
|
||||||
if ("text/plain".equals(type)) {
|
if ("text/plain".equals(type)) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ package fr.gouv.etalab.mastodon.fragments;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.Bundle;
|
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.sqlite.Sqlite;
|
||||||
import fr.gouv.etalab.mastodon.R;
|
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;
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,20 +115,12 @@ public class DisplaySearchFragment extends Fragment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new SearchDAO(context, db).insertSearch(keyword);
|
new SearchDAO(context, db).insertSearch(keyword);
|
||||||
((BaseMainActivity)context).refreshSearchTab();
|
if( getActivity() != null)
|
||||||
searches.add(keyword);
|
getActivity().recreate();
|
||||||
if( textviewNoAction.getVisibility() == View.VISIBLE)
|
Intent intent = new Intent(context, MainActivity.class);
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
intent.putExtra(INTENT_ACTION, SEARCH_TAG);
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
intent.putExtra(SEARCH_KEYWORD, keyword);
|
||||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
startActivity(intent);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AlertDialog alertDialog = dialogBuilder.create();
|
AlertDialog alertDialog = dialogBuilder.create();
|
||||||
|
|
|
@ -209,7 +209,7 @@ public class Helper {
|
||||||
public static final String SHOULD_CONTINUE_STREAMING = "should_continue_streaming";
|
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_FEDERATED = "should_continue_streaming_federated";
|
||||||
public static final String SHOULD_CONTINUE_STREAMING_LOCAL = "should_continue_streaming_local";
|
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";
|
public static final String CLIP_BOARD = "clipboard";
|
||||||
//Notifications
|
//Notifications
|
||||||
public static final int NOTIFICATION_INTENT = 1;
|
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 CHANGE_USER_INTENT = 4;
|
||||||
public static final int ADD_USER_INTENT = 5;
|
public static final int ADD_USER_INTENT = 5;
|
||||||
public static final int BACKUP_INTENT = 6;
|
public static final int BACKUP_INTENT = 6;
|
||||||
|
public static final int SEARCH_TAG = 7;
|
||||||
//Settings
|
//Settings
|
||||||
public static final String SET_TOOTS_PER_PAGE = "set_toots_per_page";
|
public static final String SET_TOOTS_PER_PAGE = "set_toots_per_page";
|
||||||
public static final String SET_ACCOUNTS_PER_PAGE = "set_accounts_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){
|
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();
|
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
List<String> searches = new SearchDAO(context, db).getAllSearch();
|
List<String> searches = new SearchDAO(context, db).getAllSearch();
|
||||||
int countInitialTab = ((BaseMainActivity) context).countPage;
|
int countInitialTab = ((BaseMainActivity) context).countPage;
|
||||||
|
@ -2162,10 +2162,15 @@ public class Helper {
|
||||||
allTabCount -=1;
|
allTabCount -=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( searches != null)
|
if( searches != null) {
|
||||||
for(String search: searches){
|
for (String search : searches) {
|
||||||
addTab(tableLayout, pagerAdapter, search);
|
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) {
|
private static void removeTab(TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter, int position) {
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
>
|
||||||
android:gravity="center_vertical">
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/tab_icon"
|
android:id="@+id/tab_icon"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
|
@ -29,18 +28,19 @@
|
||||||
android:layout_height="25dp"
|
android:layout_height="25dp"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription" />
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tab_counter"
|
|
||||||
android:visibility="gone"
|
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:paddingLeft="2dp"
|
||||||
android:paddingRight="2dp"
|
android:paddingRight="2dp"
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:textColor="@color/mastodonC1"
|
android:textColor="@color/mastodonC1"
|
||||||
android:background="@drawable/shape_counter"
|
android:background="@drawable/shape_counter"
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
Loading…
Reference in New Issue