Ammar Githam
4 years ago
11 changed files with 238 additions and 96 deletions
-
10app/src/main/java/awais/instagrabber/adapters/FeedStoriesAdapter.java
-
59app/src/main/java/awais/instagrabber/adapters/HighlightsAdapter.java
-
33app/src/main/java/awais/instagrabber/adapters/viewholder/FeedStoryViewHolder.java
-
28app/src/main/java/awais/instagrabber/adapters/viewholder/HighlightViewHolder.java
-
27app/src/main/java/awais/instagrabber/asyncs/HighlightsFetcher.java
-
80app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
-
45app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
-
19app/src/main/java/awais/instagrabber/fragments/main/viewmodels/HighlightsViewModel.java
-
8app/src/main/java/awais/instagrabber/models/HighlightModel.java
-
5app/src/main/res/layout/fragment_profile.xml
-
20app/src/main/res/navigation/profile_nav_graph.xml
@ -1,54 +1,55 @@ |
|||
package awais.instagrabber.adapters; |
|||
|
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.ViewGroup; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.recyclerview.widget.RecyclerView; |
|||
import androidx.recyclerview.widget.DiffUtil; |
|||
import androidx.recyclerview.widget.ListAdapter; |
|||
|
|||
import com.bumptech.glide.Glide; |
|||
|
|||
import awais.instagrabber.R; |
|||
import awais.instagrabber.adapters.viewholder.HighlightViewHolder; |
|||
import awais.instagrabber.databinding.ItemHighlightBinding; |
|||
import awais.instagrabber.models.HighlightModel; |
|||
|
|||
public final class HighlightsAdapter extends RecyclerView.Adapter<HighlightViewHolder> { |
|||
private final View.OnClickListener clickListener; |
|||
private LayoutInflater layoutInflater; |
|||
private HighlightModel[] highlightModels; |
|||
public final class HighlightsAdapter extends ListAdapter<HighlightModel, HighlightViewHolder> { |
|||
|
|||
private final OnHighlightClickListener clickListener; |
|||
|
|||
private static final DiffUtil.ItemCallback<HighlightModel> diffCallback = new DiffUtil.ItemCallback<HighlightModel>() { |
|||
@Override |
|||
public boolean areItemsTheSame(@NonNull final HighlightModel oldItem, @NonNull final HighlightModel newItem) { |
|||
return oldItem.getId().equals(newItem.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public boolean areContentsTheSame(@NonNull final HighlightModel oldItem, @NonNull final HighlightModel newItem) { |
|||
return oldItem.getId().equals(newItem.getId()); |
|||
} |
|||
}; |
|||
|
|||
public HighlightsAdapter(final HighlightModel[] highlightModels, final View.OnClickListener clickListener) { |
|||
this.highlightModels = highlightModels; |
|||
public HighlightsAdapter(final OnHighlightClickListener clickListener) { |
|||
super(diffCallback); |
|||
this.clickListener = clickListener; |
|||
} |
|||
|
|||
@NonNull |
|||
@Override |
|||
public HighlightViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) { |
|||
if (layoutInflater == null) layoutInflater = LayoutInflater.from(parent.getContext()); |
|||
// return new HighlightViewHolder(layoutInflater.inflate(R.layout.item_highlight, parent, false)); |
|||
return null; |
|||
final LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext()); |
|||
final ItemHighlightBinding binding = ItemHighlightBinding.inflate(layoutInflater, parent, false); |
|||
return new HighlightViewHolder(binding); |
|||
} |
|||
|
|||
@Override |
|||
public void onBindViewHolder(@NonNull final HighlightViewHolder holder, final int position) { |
|||
// final HighlightModel highlightModel = highlightModels[position]; |
|||
// if (highlightModel != null) { |
|||
// holder.itemView.setTag(highlightModel); |
|||
// holder.itemView.setOnClickListener(clickListener); |
|||
// holder.title.setText(highlightModel.getTitle()); |
|||
// Glide.with(holder.itemView).load(highlightModel.getThumbnailUrl()).into(holder.icon); |
|||
// } |
|||
final HighlightModel highlightModel = getItem(position); |
|||
if (clickListener != null) { |
|||
holder.itemView.setOnClickListener(v -> clickListener.onHighlightClick(highlightModel, position)); |
|||
} |
|||
holder.bind(highlightModel); |
|||
} |
|||
|
|||
public void setData(final HighlightModel[] highlightModels) { |
|||
this.highlightModels = highlightModels; |
|||
notifyDataSetChanged(); |
|||
} |
|||
|
|||
@Override |
|||
public int getItemCount() { |
|||
return highlightModels == null ? 0 : highlightModels.length; |
|||
public interface OnHighlightClickListener { |
|||
void onHighlightClick(final HighlightModel model, final int position); |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
package awais.instagrabber.adapters.viewholder; |
|||
|
|||
import androidx.recyclerview.widget.RecyclerView; |
|||
|
|||
import awais.instagrabber.adapters.FeedStoriesAdapter; |
|||
import awais.instagrabber.databinding.ItemHighlightBinding; |
|||
import awais.instagrabber.models.FeedStoryModel; |
|||
import awais.instagrabber.models.ProfileModel; |
|||
|
|||
public final class FeedStoryViewHolder extends RecyclerView.ViewHolder { |
|||
|
|||
private final ItemHighlightBinding binding; |
|||
|
|||
public FeedStoryViewHolder(final ItemHighlightBinding binding) { |
|||
super(binding.getRoot()); |
|||
this.binding = binding; |
|||
} |
|||
|
|||
public void bind(final FeedStoryModel model, |
|||
final int position, |
|||
final FeedStoriesAdapter.OnFeedStoryClickListener listener) { |
|||
if (model == null) return; |
|||
binding.getRoot().setOnClickListener(v -> { |
|||
if (listener == null) return; |
|||
listener.onFeedStoryClick(model, position); |
|||
}); |
|||
final ProfileModel profileModel = model.getProfileModel(); |
|||
binding.title.setText(profileModel.getUsername()); |
|||
binding.title.setAlpha(model.getFullyRead() ? 0.5F : 1.0F); |
|||
binding.icon.setImageURI(profileModel.getSdProfilePic()); |
|||
binding.icon.setAlpha(model.getFullyRead() ? 0.5F : 1.0F); |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
package awais.instagrabber.fragments.main.viewmodels; |
|||
|
|||
import androidx.lifecycle.MutableLiveData; |
|||
import androidx.lifecycle.ViewModel; |
|||
|
|||
import java.util.List; |
|||
|
|||
import awais.instagrabber.models.HighlightModel; |
|||
|
|||
public class HighlightsViewModel extends ViewModel { |
|||
private MutableLiveData<List<HighlightModel>> list; |
|||
|
|||
public MutableLiveData<List<HighlightModel>> getList() { |
|||
if (list == null) { |
|||
list = new MutableLiveData<>(); |
|||
} |
|||
return list; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue