-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gregor Santner
committed
Oct 26, 2016
1 parent
9d22e1f
commit b9f7b32
Showing
8 changed files
with
223 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
197 changes: 197 additions & 0 deletions
197
app/src/main/java/com/github/dfa/diaspora_android/fragment/AspectListFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
/* | ||
This file is part of the Diaspora for Android. | ||
Diaspora for Android is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Diaspora for Android is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with the Diaspora for Android. | ||
If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.github.dfa.diaspora_android.fragment; | ||
|
||
import android.content.Context; | ||
import android.graphics.PorterDuff; | ||
import android.os.Bundle; | ||
import android.support.v7.widget.AppCompatImageView; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.Menu; | ||
import android.view.MenuInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.RelativeLayout; | ||
import android.widget.TextView; | ||
|
||
import com.github.dfa.diaspora_android.App; | ||
import com.github.dfa.diaspora_android.R; | ||
import com.github.dfa.diaspora_android.activity.MainActivity; | ||
import com.github.dfa.diaspora_android.data.AppSettings; | ||
import com.github.dfa.diaspora_android.data.PodAspect; | ||
import com.github.dfa.diaspora_android.listener.OnSomethingClickListener; | ||
import com.github.dfa.diaspora_android.util.AppLog; | ||
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper; | ||
import com.github.dfa.diaspora_android.util.Helpers; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
|
||
/** | ||
* Fragment that shows a list of the Aspects | ||
*/ | ||
public class AspectListFragment extends ThemedFragment implements OnSomethingClickListener<Object> { | ||
|
||
public static final String TAG = "com.github.dfa.diaspora_android.AspectListFragment"; | ||
|
||
protected RecyclerView followedAspectsRecyclerView; | ||
protected App app; | ||
protected DiasporaUrlHelper urls; | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
AppLog.d(this, "onCreateView()"); | ||
return inflater.inflate(R.layout.recycler_list__fragment, container, false); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
followedAspectsRecyclerView = (RecyclerView) view.findViewById(R.id.fragment_list__recycler_view); | ||
app = (App) getActivity().getApplication(); | ||
AppSettings appSettings = app.getSettings(); | ||
urls = new DiasporaUrlHelper(appSettings); | ||
|
||
followedAspectsRecyclerView.setHasFixedSize(true); | ||
followedAspectsRecyclerView.setNestedScrollingEnabled(false); | ||
|
||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); | ||
followedAspectsRecyclerView.setLayoutManager(layoutManager); | ||
|
||
final FollowedTagsAdapter adapter = new FollowedTagsAdapter(appSettings, this); | ||
followedAspectsRecyclerView.setAdapter(adapter); | ||
|
||
//Set window title | ||
getActivity().setTitle(R.string.nav_aspects); | ||
} | ||
|
||
@Override | ||
public String getFragmentTag() { | ||
return TAG; | ||
} | ||
|
||
@Override | ||
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) { | ||
/* Nothing to do */ | ||
} | ||
|
||
@Override | ||
public boolean onBackPressed() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onSomethingClicked(Object null1, Integer null2, String aspectId) { | ||
((MainActivity) getActivity()).openDiasporaUrl(urls.getAspectUrl(aspectId)); | ||
} | ||
|
||
@Override | ||
protected void applyColorToViews() { | ||
followedAspectsRecyclerView.invalidate(); | ||
} | ||
|
||
public static class FollowedTagsAdapter extends RecyclerView.Adapter<FollowedTagsAdapter.ViewHolder> { | ||
private AppSettings appSettings; | ||
private PodAspect[] followedAspectList; | ||
private List<String> followedAspectFavsList; | ||
private OnSomethingClickListener<Object> aspectClickedListener; | ||
|
||
static class ViewHolder extends RecyclerView.ViewHolder { | ||
@BindView(R.id.recycler_view__list_item__text) | ||
public TextView title; | ||
@BindView(R.id.recycler_view__list_item__favourite) | ||
AppCompatImageView favouriteImage; | ||
@BindView(R.id.recycler_view__list_item__root) | ||
RelativeLayout root; | ||
|
||
ViewHolder(View v) { | ||
super(v); | ||
ButterKnife.bind(this, v); | ||
} | ||
} | ||
|
||
|
||
FollowedTagsAdapter(AppSettings appSettings, OnSomethingClickListener<Object> aspectClickedListener) { | ||
this.appSettings = appSettings; | ||
this.followedAspectList = appSettings.getAspects(); | ||
this.followedAspectFavsList = new ArrayList<>(Arrays.asList(appSettings.getAspectFavs())); | ||
this.aspectClickedListener = aspectClickedListener; | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return followedAspectList.length; | ||
} | ||
|
||
@Override | ||
public FollowedTagsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View v = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.recycler_view__list_item, parent, false); | ||
return new ViewHolder(v); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(final ViewHolder holder, final int position) { | ||
// Alternating colors | ||
final Context c = holder.root.getContext(); | ||
final String aspect = followedAspectList[position].name; | ||
holder.title.setText(aspect); | ||
if (position % 2 == 1) { | ||
holder.root.setBackgroundColor(Helpers.getColorFromRessource(c, R.color.md_grey_300)); | ||
} | ||
|
||
// Favourite (Star) Image | ||
applyFavouriteImage(holder.favouriteImage, isAspectFaved(aspect)); | ||
|
||
// Click on fav button | ||
holder.favouriteImage.setOnClickListener(new View.OnClickListener() { | ||
public void onClick(View v) { | ||
if (isAspectFaved(aspect)) { | ||
followedAspectFavsList.remove(followedAspectFavsList.indexOf(aspect)); | ||
} else { | ||
followedAspectFavsList.add(aspect); | ||
} | ||
appSettings.setFollowedTagsFavs(followedAspectFavsList); | ||
applyFavouriteImage(holder.favouriteImage, isAspectFaved(aspect)); | ||
} | ||
}); | ||
|
||
holder.root.setOnClickListener(new View.OnClickListener() { | ||
public void onClick(View v) { | ||
aspectClickedListener.onSomethingClicked(null, null, followedAspectList[position].id+""); | ||
} | ||
}); | ||
} | ||
|
||
private boolean isAspectFaved(String tag) { | ||
return followedAspectFavsList.contains(tag); | ||
} | ||
|
||
private void applyFavouriteImage(AppCompatImageView imageView, boolean isFaved) { | ||
imageView.setImageResource(isFaved ? R.drawable.ic_star_filled_48px : R.drawable.ic_star_border_black_48px); | ||
imageView.setColorFilter(isFaved ? appSettings.getAccentColor() : 0, PorterDuff.Mode.SRC_ATOP); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters