Consolidates the main header and removes the now-unneeded FloatingSearchView library. Closes #67

main
Vavassor 8 years ago
parent 2d74f078e0
commit 9d78808bf3
  1. 1
      app/build.gradle
  2. 109
      app/src/main/java/com/keylesspalace/tusky/MainActivity.java
  3. 13
      app/src/main/java/com/keylesspalace/tusky/entity/Account.java
  4. 10
      app/src/main/res/drawable/ic_menu_24dp.xml
  5. 58
      app/src/main/res/layout/activity_main.xml
  6. 1
      app/src/main/res/values/colors.xml
  7. 3
      app/src/main/res/values/dimens.xml
  8. 20
      app/src/main/res/values/styles.xml

@ -47,7 +47,6 @@ dependencies {
compile 'com.github.varunest:sparkbutton:1.0.5' compile 'com.github.varunest:sparkbutton:1.0.5'
compile 'com.github.chrisbanes:PhotoView:2.0.0' compile 'com.github.chrisbanes:PhotoView:2.0.0'
compile 'com.mikepenz:google-material-typeface:3.0.1.0.original@aar' compile 'com.mikepenz:google-material-typeface:3.0.1.0.original@aar'
compile 'com.github.arimorty:floatingsearchview:2.0.4'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.3' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.3'
compile 'com.jakewharton:butterknife:8.5.1' compile 'com.jakewharton:butterknife:8.5.1'
compile 'org.jsoup:jsoup:1.10.2' compile 'org.jsoup:jsoup:1.10.2'

@ -19,7 +19,6 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -31,18 +30,11 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import com.arlib.floatingsearchview.FloatingSearchView;
import com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter;
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.entity.Account;
import com.keylesspalace.tusky.pager.TimelinePagerAdapter; import com.keylesspalace.tusky.pager.TimelinePagerAdapter;
import com.keylesspalace.tusky.receiver.TimelineReceiver; import com.keylesspalace.tusky.receiver.TimelineReceiver;
@ -91,8 +83,8 @@ public class MainActivity extends BaseActivity {
private AccountHeader headerResult; private AccountHeader headerResult;
private Drawer drawer; private Drawer drawer;
@BindView(R.id.floating_search_view) FloatingSearchView searchView;
@BindView(R.id.floating_btn) FloatingActionButton floatingBtn; @BindView(R.id.floating_btn) FloatingActionButton floatingBtn;
@BindView(R.id.drawer_toggle) ImageButton drawerToggle;
@BindView(R.id.tab_layout) TabLayout tabLayout; @BindView(R.id.tab_layout) TabLayout tabLayout;
@BindView(R.id.pager) ViewPager viewPager; @BindView(R.id.pager) ViewPager viewPager;
@ -122,7 +114,15 @@ public class MainActivity extends BaseActivity {
}); });
setupDrawer(); setupDrawer();
setupSearchView();
// Setup the navigation drawer toggle button.
ThemeUtils.setDrawableTint(this, drawerToggle.getDrawable(), R.attr.toolbar_icon_tint);
drawerToggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawer.openDrawer();
}
});
/* Fetch user info while we're doing other things. This has to be after setting up the /* Fetch user info while we're doing other things. This has to be after setting up the
* drawer, though, because its callback touches the header in the drawer. */ * drawer, though, because its callback touches the header in the drawer. */
@ -376,93 +376,6 @@ public class MainActivity extends BaseActivity {
.show(); .show();
} }
private void setupSearchView() {
searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout());
// Setup content descriptions for the different elements in the search view.
final View leftAction = searchView.findViewById(R.id.left_action);
leftAction.setContentDescription(getString(R.string.action_open_drawer));
searchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
@Override
public void onFocus() {
leftAction.setContentDescription(getString(R.string.action_close));
}
@Override
public void onFocusCleared() {
leftAction.setContentDescription(getString(R.string.action_open_drawer));
}
});
View clearButton = searchView.findViewById(R.id.clear_btn);
clearButton.setContentDescription(getString(R.string.action_clear));
searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
@Override
public void onSearchTextChanged(String oldQuery, String newQuery) {
if (!oldQuery.equals("") && newQuery.equals("")) {
searchView.clearSuggestions();
return;
}
if (newQuery.length() < 3) {
return;
}
searchView.showProgress();
mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() {
@Override
public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
if (response.isSuccessful()) {
searchView.swapSuggestions(response.body());
searchView.hideProgress();
} else {
searchView.hideProgress();
}
}
@Override
public void onFailure(Call<List<Account>> call, Throwable t) {
searchView.hideProgress();
}
});
}
});
searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
@Override
public void onSuggestionClicked(SearchSuggestion searchSuggestion) {
Account accountSuggestion = (Account) searchSuggestion;
Intent intent = new Intent(MainActivity.this, AccountActivity.class);
intent.putExtra("id", accountSuggestion.id);
startActivity(intent);
}
@Override
public void onSearchAction(String currentQuery) {}
});
searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
@Override
public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) {
Account accountSuggestion = ((Account) item);
Picasso.with(MainActivity.this)
.load(accountSuggestion.avatar)
.placeholder(R.drawable.avatar_default)
.into(leftIcon);
String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username;
final SpannableStringBuilder str = new SpannableStringBuilder(searchStr);
str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(str);
textView.setMaxLines(1);
textView.setEllipsize(TextUtils.TruncateAt.END);
}
});
}
private void fetchUserInfo() { private void fetchUserInfo() {
SharedPreferences preferences = getPrivatePreferences(); SharedPreferences preferences = getPrivatePreferences();
final String domain = preferences.getString("domain", null); final String domain = preferences.getString("domain", null);

@ -16,14 +16,14 @@
package com.keylesspalace.tusky.entity; package com.keylesspalace.tusky.entity;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable;
import android.text.Spanned; import android.text.Spanned;
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.keylesspalace.tusky.util.HtmlUtils; import com.keylesspalace.tusky.util.HtmlUtils;
import com.keylesspalace.tusky.json.StringWithEmoji; import com.keylesspalace.tusky.json.StringWithEmoji;
public class Account implements SearchSuggestion { public class Account implements Parcelable {
public String id; public String id;
@SerializedName("username") @SerializedName("username")
@ -77,11 +77,6 @@ public class Account implements SearchSuggestion {
return displayName.value; return displayName.value;
} }
@Override
public String getBody() {
return username;
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
@ -103,9 +98,7 @@ public class Account implements SearchSuggestion {
dest.writeString(statusesCount); dest.writeString(statusesCount);
} }
public Account() { public Account() {}
}
protected Account(Parcel in) { protected Account(Parcel in) {
id = in.readString(); id = in.readString();

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#ffffff"
android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z" />
</vector>

@ -1,38 +1,44 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main" android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.keylesspalace.tusky.MainActivity"> tools:context="com.keylesspalace.tusky.MainActivity">
<LinearLayout <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ImageButton
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:id="@+id/drawer_toggle"
app:srcCompat="@drawable/ic_menu_24dp"
app:layout_anchor="@id/pager"
app:layout_anchorGravity="top|left"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
style="?attr/image_button_style"
android:background="?android:colorBackground"
android:contentDescription="@string/action_open_drawer" />
<android.support.design.widget.TabLayout <android.support.design.widget.TabLayout
android:id="@+id/tab_layout" android:id="@+id/tab_layout"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="?attr/actionBarSize"
android:background="?android:colorBackground" android:background="?android:colorBackground"
android:paddingTop="?attr/actionBarSize"
app:tabGravity="fill" app:tabGravity="fill"
app:tabMaxWidth="0dp" app:tabMaxWidth="0dp"
app:tabPaddingEnd="1dp" app:tabPaddingEnd="1dp"
app:tabPaddingStart="1dp" app:tabPaddingStart="1dp"
app:tabPaddingTop="4dp" app:tabPaddingTop="4dp"
app:tabTextAppearance="@style/TabLayoutTextStyle"> app:tabTextAppearance="@style/TabLayoutTextStyle"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/drawer_toggle">
<android.support.design.widget.TabItem <android.support.design.widget.TabItem
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -56,22 +62,14 @@
</android.support.design.widget.TabLayout> </android.support.design.widget.TabLayout>
</android.support.v4.view.ViewPager> <android.support.v4.view.ViewPager
android:id="@+id/pager"
</LinearLayout>
<com.arlib.floatingsearchview.FloatingSearchView
android:id="@+id/floating_search_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
app:floatingSearch_close_search_on_keyboard_dismiss="true" android:layout_below="@id/tab_layout"
app:floatingSearch_leftActionMode="showHamburger" android:layout_alignParentBottom="true"/>
app:floatingSearch_searchBarMarginLeft="6dp"
app:floatingSearch_searchBarMarginRight="6dp" </RelativeLayout>
app:floatingSearch_searchBarMarginTop="4dp"
app:floatingSearch_searchHint="@string/search"
app:floatingSearch_showSearchKey="false"
app:floatingSearch_suggestionsListAnimDuration="250" />
<View <View
android:id="@+id/tab_bottom_shadow" android:id="@+id/tab_bottom_shadow"

@ -3,6 +3,7 @@
<!--These colors are not affected by themes.--> <!--These colors are not affected by themes.-->
<color name="view_video_background">#000000</color> <color name="view_video_background">#000000</color>
<color name="toolbar_view_media">#8f000000</color> <color name="toolbar_view_media">#8f000000</color>
<color name="semi_transparent">#33000000</color>
<!--Dark Theme Colors--> <!--Dark Theme Colors-->
<color name="color_primary_dark">#4c5368</color> <color name="color_primary_dark">#4c5368</color>
<color name="color_primary_dark_dark">#363c4b</color> <!--Dark Dark--> <color name="color_primary_dark_dark">#363c4b</color> <!--Dark Dark-->

@ -1,6 +1,4 @@
<resources> <resources>
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>
<dimen name="status_display_name_right_padding">4dp</dimen> <dimen name="status_display_name_right_padding">4dp</dimen>
<dimen name="status_username_right_padding">4dp</dimen> <dimen name="status_username_right_padding">4dp</dimen>
<dimen name="status_avatar_padding">8dp</dimen> <dimen name="status_avatar_padding">8dp</dimen>
@ -21,4 +19,5 @@
<dimen name="account_avatar_margin">8dp</dimen> <dimen name="account_avatar_margin">8dp</dimen>
<dimen name="tab_page_margin">8dp</dimen> <dimen name="tab_page_margin">8dp</dimen>
<dimen name="status_left_line_margin">38dp</dimen> <dimen name="status_left_line_margin">38dp</dimen>
<dimen name="text_content_margin">16dp</dimen>
</resources> </resources>

@ -80,16 +80,6 @@
<item name="material_drawer_selected">@color/color_primary_dark</item> <item name="material_drawer_selected">@color/color_primary_dark</item>
<item name="material_drawer_selected_text">@color/text_color_primary_dark</item> <item name="material_drawer_selected_text">@color/text_color_primary_dark</item>
<item name="material_drawer_header_selection_text">@color/text_color_primary_dark</item> <item name="material_drawer_header_selection_text">@color/text_color_primary_dark</item>
<item name="floatingSearch_backgroundColor">@color/toolbar_background_dark</item>
<item name="floatingSearch_viewTextColor">@color/text_color_secondary_dark</item>
<item name="floatingSearch_hintTextColor">@color/text_color_tertiary_dark</item>
<item name="floatingSearch_dividerColor">@color/status_divider_dark</item>
<item name="floatingSearch_clearBtnColor">@color/toolbar_icon_dark</item>
<item name="floatingSearch_leftActionColor">@color/toolbar_icon_dark</item>
<item name="floatingSearch_menuItemIconColor">@color/toolbar_icon_dark</item>
<item name="floatingSearch_suggestionRightIconColor">@color/toolbar_icon_dark</item>
<item name="floatingSearch_actionMenuOverflowColor">@color/toolbar_icon_dark</item>
</style> </style>
<style name="AppTheme.ImageButton.Dark" parent="@style/Widget.AppCompat.Button.Borderless.Colored"> <style name="AppTheme.ImageButton.Dark" parent="@style/Widget.AppCompat.Button.Borderless.Colored">
@ -167,16 +157,6 @@
<item name="material_drawer_selected">@color/color_primary_light</item> <item name="material_drawer_selected">@color/color_primary_light</item>
<item name="material_drawer_selected_text">@color/text_color_primary_light</item> <item name="material_drawer_selected_text">@color/text_color_primary_light</item>
<item name="material_drawer_header_selection_text">@color/text_color_primary_dark</item> <!--Intentionally dark so it can be overlayed over the account's header image.--> <item name="material_drawer_header_selection_text">@color/text_color_primary_dark</item> <!--Intentionally dark so it can be overlayed over the account's header image.-->
<item name="floatingSearch_backgroundColor">@color/toolbar_background_light</item>
<item name="floatingSearch_viewTextColor">@color/text_color_secondary_light</item>
<item name="floatingSearch_hintTextColor">@color/text_color_tertiary_light</item>
<item name="floatingSearch_dividerColor">@color/status_divider_light</item>
<item name="floatingSearch_clearBtnColor">@color/toolbar_icon_light</item>
<item name="floatingSearch_leftActionColor">@color/toolbar_icon_light</item>
<item name="floatingSearch_menuItemIconColor">@color/toolbar_icon_light</item>
<item name="floatingSearch_suggestionRightIconColor">@color/toolbar_icon_light</item>
<item name="floatingSearch_actionMenuOverflowColor">@color/toolbar_icon_light</item>
</style> </style>
<style name="AppTheme.ImageButton.Light" parent="Widget.AppCompat.Button.Borderless.Colored"> <style name="AppTheme.ImageButton.Light" parent="Widget.AppCompat.Button.Borderless.Colored">

Loading…
Cancel
Save