Change bookmark addon icon
This commit is contained in:
parent
e31ba2084c
commit
f6070c78c0
|
@ -87,7 +87,7 @@ public class AddonDetailsFragment extends SharedElementFragment {
|
|||
// Buttons
|
||||
@InjectView(R.id.fab) ImageButton fabButton;
|
||||
@InjectView(R.id.enable_disable) ImageButton enabledButton;
|
||||
@InjectView(R.id.pin_unpin) ImageButton pinButton;
|
||||
@InjectView(R.id.pin_unpin) ImageView pinButton;
|
||||
|
||||
// Detail views
|
||||
@InjectView(R.id.media_panel) ScrollView mediaPanel;
|
||||
|
@ -333,39 +333,40 @@ public class AddonDetailsFragment extends SharedElementFragment {
|
|||
|
||||
@OnClick(R.id.pin_unpin)
|
||||
public void onPinClicked(View v) {
|
||||
final boolean enable = (v.getTag() == null)? true : !(Boolean)v.getTag();
|
||||
final boolean isBookmarked = (v.getTag() == null)? true : !(Boolean)v.getTag();
|
||||
|
||||
String name = mediaTitle.getText().toString();
|
||||
String path = addonId;
|
||||
|
||||
SharedPreferences prefs = getActivity().getSharedPreferences("addons", Context.MODE_PRIVATE);
|
||||
Set<String> bookmarked = new HashSet<>(prefs.getStringSet("bookmarked", Collections.<String>emptySet()));
|
||||
if (enable)
|
||||
bookmarked.add(path);
|
||||
Set<String> bookmarks = new HashSet<>(prefs.getStringSet("bookmarked", Collections.<String>emptySet()));
|
||||
if (isBookmarked)
|
||||
bookmarks.add(path);
|
||||
else
|
||||
bookmarked.remove(path);
|
||||
prefs
|
||||
.edit()
|
||||
.putStringSet("bookmarked", bookmarked)
|
||||
.putString("name_" + path, name)
|
||||
.commit();
|
||||
Toast.makeText(getActivity(), enable? R.string.addon_pinned : R.string.addon_unpinned, Toast.LENGTH_SHORT).show();
|
||||
setupPinButton(enable);
|
||||
bookmarks.remove(path);
|
||||
prefs.edit()
|
||||
.putStringSet("bookmarked", bookmarks)
|
||||
.putString("name_" + path, name)
|
||||
.apply();
|
||||
Toast.makeText(getActivity(), isBookmarked? R.string.addon_pinned : R.string.addon_unpinned, Toast.LENGTH_SHORT).show();
|
||||
setupPinButton(isBookmarked);
|
||||
}
|
||||
|
||||
private void setupPinButton(boolean enabled) {
|
||||
// Enabled button
|
||||
if (enabled) {
|
||||
Resources.Theme theme = getActivity().getTheme();
|
||||
TypedArray styledAttributes = theme.obtainStyledAttributes(new int[]{
|
||||
R.attr.colorAccent});
|
||||
pinButton.setColorFilter(styledAttributes.getColor(0,
|
||||
getActivity().getResources().getColor(R.color.accent_default)));
|
||||
styledAttributes.recycle();
|
||||
private void setupPinButton(boolean bookmarked) {
|
||||
Resources.Theme theme = getActivity().getTheme();
|
||||
TypedArray styledAttributes =
|
||||
theme.obtainStyledAttributes(new int[] {R.attr.defaultButtonColorFilter, R.attr.colorAccent});
|
||||
Resources resources = getActivity().getResources();
|
||||
// Bookmarked button
|
||||
if (bookmarked) {
|
||||
pinButton.setColorFilter(styledAttributes.getColor(styledAttributes.getIndex(1),
|
||||
resources.getColor(R.color.accent_default)));
|
||||
} else {
|
||||
pinButton.clearColorFilter();
|
||||
pinButton.setColorFilter(styledAttributes.getColor(styledAttributes.getIndex(0),
|
||||
resources.getColor(R.color.white)));
|
||||
}
|
||||
pinButton.setTag(enabled);
|
||||
styledAttributes.recycle();
|
||||
pinButton.setTag(bookmarked);
|
||||
pinButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:alpha="1.00"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M17,3H7c-1.1,0 -1.99,0.9 -1.99,2L5,21l7,-3 7,3V5c0,-1.1 -0.9,-2 -2,-2z"/>
|
||||
</vector>
|
|
@ -103,7 +103,7 @@
|
|||
android:layout_width="@dimen/buttonbar_button_width"
|
||||
android:layout_height="match_parent"
|
||||
style="@style/Widget.Button.Borderless"
|
||||
android:src="?attr/iconNew"
|
||||
android:src="?attr/iconBookmark"
|
||||
android:contentDescription="@string/enable_disable"/>
|
||||
<ImageButton
|
||||
android:id="@+id/enable_disable"
|
||||
|
|
|
@ -105,4 +105,5 @@
|
|||
<attr name="iconChevronRight" format="reference" />
|
||||
|
||||
<attr name="iconOpenInNew" format="reference" />
|
||||
<attr name="iconBookmark" format="reference" />
|
||||
</resources>
|
|
@ -141,6 +141,8 @@
|
|||
<item name="iconSearchToolbar">@drawable/ic_search_white_24dp</item>
|
||||
|
||||
<item name="iconOpenInNew">@drawable/ic_open_in_new_white_24dp</item>
|
||||
|
||||
<item name="iconBookmark">@drawable/ic_bookmark_24dp</item>
|
||||
</style>
|
||||
|
||||
<!-- Base Light theme. -->
|
||||
|
@ -266,6 +268,8 @@
|
|||
<item name="iconSearchToolbar">@drawable/ic_search_white_24dp</item>
|
||||
|
||||
<item name="iconOpenInNew">@drawable/ic_open_in_new_black_24dp</item>
|
||||
|
||||
<item name="iconBookmark">@drawable/ic_bookmark_24dp</item>
|
||||
</style>
|
||||
|
||||
<!-- Blue Grey theme. -->
|
||||
|
|
Loading…
Reference in New Issue