Change bookmark addon icon
This commit is contained in:
parent
e31ba2084c
commit
f6070c78c0
|
@ -87,7 +87,7 @@ public class AddonDetailsFragment extends SharedElementFragment {
|
||||||
// Buttons
|
// Buttons
|
||||||
@InjectView(R.id.fab) ImageButton fabButton;
|
@InjectView(R.id.fab) ImageButton fabButton;
|
||||||
@InjectView(R.id.enable_disable) ImageButton enabledButton;
|
@InjectView(R.id.enable_disable) ImageButton enabledButton;
|
||||||
@InjectView(R.id.pin_unpin) ImageButton pinButton;
|
@InjectView(R.id.pin_unpin) ImageView pinButton;
|
||||||
|
|
||||||
// Detail views
|
// Detail views
|
||||||
@InjectView(R.id.media_panel) ScrollView mediaPanel;
|
@InjectView(R.id.media_panel) ScrollView mediaPanel;
|
||||||
|
@ -333,39 +333,40 @@ public class AddonDetailsFragment extends SharedElementFragment {
|
||||||
|
|
||||||
@OnClick(R.id.pin_unpin)
|
@OnClick(R.id.pin_unpin)
|
||||||
public void onPinClicked(View v) {
|
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 name = mediaTitle.getText().toString();
|
||||||
String path = addonId;
|
String path = addonId;
|
||||||
|
|
||||||
SharedPreferences prefs = getActivity().getSharedPreferences("addons", Context.MODE_PRIVATE);
|
SharedPreferences prefs = getActivity().getSharedPreferences("addons", Context.MODE_PRIVATE);
|
||||||
Set<String> bookmarked = new HashSet<>(prefs.getStringSet("bookmarked", Collections.<String>emptySet()));
|
Set<String> bookmarks = new HashSet<>(prefs.getStringSet("bookmarked", Collections.<String>emptySet()));
|
||||||
if (enable)
|
if (isBookmarked)
|
||||||
bookmarked.add(path);
|
bookmarks.add(path);
|
||||||
else
|
else
|
||||||
bookmarked.remove(path);
|
bookmarks.remove(path);
|
||||||
prefs
|
prefs.edit()
|
||||||
.edit()
|
.putStringSet("bookmarked", bookmarks)
|
||||||
.putStringSet("bookmarked", bookmarked)
|
.putString("name_" + path, name)
|
||||||
.putString("name_" + path, name)
|
.apply();
|
||||||
.commit();
|
Toast.makeText(getActivity(), isBookmarked? R.string.addon_pinned : R.string.addon_unpinned, Toast.LENGTH_SHORT).show();
|
||||||
Toast.makeText(getActivity(), enable? R.string.addon_pinned : R.string.addon_unpinned, Toast.LENGTH_SHORT).show();
|
setupPinButton(isBookmarked);
|
||||||
setupPinButton(enable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupPinButton(boolean enabled) {
|
private void setupPinButton(boolean bookmarked) {
|
||||||
// Enabled button
|
Resources.Theme theme = getActivity().getTheme();
|
||||||
if (enabled) {
|
TypedArray styledAttributes =
|
||||||
Resources.Theme theme = getActivity().getTheme();
|
theme.obtainStyledAttributes(new int[] {R.attr.defaultButtonColorFilter, R.attr.colorAccent});
|
||||||
TypedArray styledAttributes = theme.obtainStyledAttributes(new int[]{
|
Resources resources = getActivity().getResources();
|
||||||
R.attr.colorAccent});
|
// Bookmarked button
|
||||||
pinButton.setColorFilter(styledAttributes.getColor(0,
|
if (bookmarked) {
|
||||||
getActivity().getResources().getColor(R.color.accent_default)));
|
pinButton.setColorFilter(styledAttributes.getColor(styledAttributes.getIndex(1),
|
||||||
styledAttributes.recycle();
|
resources.getColor(R.color.accent_default)));
|
||||||
} else {
|
} 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);
|
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_width="@dimen/buttonbar_button_width"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
style="@style/Widget.Button.Borderless"
|
style="@style/Widget.Button.Borderless"
|
||||||
android:src="?attr/iconNew"
|
android:src="?attr/iconBookmark"
|
||||||
android:contentDescription="@string/enable_disable"/>
|
android:contentDescription="@string/enable_disable"/>
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/enable_disable"
|
android:id="@+id/enable_disable"
|
||||||
|
|
|
@ -105,4 +105,5 @@
|
||||||
<attr name="iconChevronRight" format="reference" />
|
<attr name="iconChevronRight" format="reference" />
|
||||||
|
|
||||||
<attr name="iconOpenInNew" format="reference" />
|
<attr name="iconOpenInNew" format="reference" />
|
||||||
|
<attr name="iconBookmark" format="reference" />
|
||||||
</resources>
|
</resources>
|
|
@ -141,6 +141,8 @@
|
||||||
<item name="iconSearchToolbar">@drawable/ic_search_white_24dp</item>
|
<item name="iconSearchToolbar">@drawable/ic_search_white_24dp</item>
|
||||||
|
|
||||||
<item name="iconOpenInNew">@drawable/ic_open_in_new_white_24dp</item>
|
<item name="iconOpenInNew">@drawable/ic_open_in_new_white_24dp</item>
|
||||||
|
|
||||||
|
<item name="iconBookmark">@drawable/ic_bookmark_24dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!-- Base Light theme. -->
|
<!-- Base Light theme. -->
|
||||||
|
@ -266,6 +268,8 @@
|
||||||
<item name="iconSearchToolbar">@drawable/ic_search_white_24dp</item>
|
<item name="iconSearchToolbar">@drawable/ic_search_white_24dp</item>
|
||||||
|
|
||||||
<item name="iconOpenInNew">@drawable/ic_open_in_new_black_24dp</item>
|
<item name="iconOpenInNew">@drawable/ic_open_in_new_black_24dp</item>
|
||||||
|
|
||||||
|
<item name="iconBookmark">@drawable/ic_bookmark_24dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!-- Blue Grey theme. -->
|
<!-- Blue Grey theme. -->
|
||||||
|
|
Loading…
Reference in New Issue