Austin Huang
4 years ago
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
16 changed files with 352 additions and 1 deletions
-
45app/src/main/java/awais/instagrabber/adapters/LikesAdapter.java
-
2app/src/main/java/awais/instagrabber/adapters/viewholder/FollowsViewHolder.java
-
118app/src/main/java/awais/instagrabber/fragments/LikesViewerFragment.java
-
7app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java
-
4app/src/main/java/awais/instagrabber/repositories/MediaRepository.java
-
47app/src/main/java/awais/instagrabber/webservices/MediaService.java
-
21app/src/main/res/layout/fragment_likes.xml
-
11app/src/main/res/navigation/direct_messages_nav_graph.xml
-
11app/src/main/res/navigation/discover_nav_graph.xml
-
11app/src/main/res/navigation/feed_nav_graph.xml
-
11app/src/main/res/navigation/hashtag_nav_graph.xml
-
40app/src/main/res/navigation/likes_nav_graph.xml
-
11app/src/main/res/navigation/location_nav_graph.xml
-
1app/src/main/res/navigation/more_nav_graph.xml
-
1app/src/main/res/navigation/notification_viewer_nav_graph.xml
-
12app/src/main/res/navigation/profile_nav_graph.xml
@ -0,0 +1,45 @@ |
|||
package awais.instagrabber.adapters; |
|||
|
|||
import android.util.Log; |
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.ViewGroup; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.recyclerview.widget.RecyclerView; |
|||
|
|||
import java.util.List; |
|||
|
|||
import awais.instagrabber.adapters.viewholder.FollowsViewHolder; |
|||
import awais.instagrabber.databinding.ItemFollowBinding; |
|||
import awais.instagrabber.models.ProfileModel; |
|||
|
|||
public final class LikesAdapter extends RecyclerView.Adapter<FollowsViewHolder> { |
|||
private final List<ProfileModel> profileModels; |
|||
private final View.OnClickListener onClickListener; |
|||
|
|||
public LikesAdapter(final List<ProfileModel> profileModels, |
|||
final View.OnClickListener onClickListener) { |
|||
this.profileModels = profileModels; |
|||
this.onClickListener = onClickListener; |
|||
} |
|||
|
|||
@NonNull |
|||
@Override |
|||
public FollowsViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) { |
|||
final LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext()); |
|||
final ItemFollowBinding binding = ItemFollowBinding.inflate(layoutInflater, parent, false); |
|||
return new FollowsViewHolder(binding); |
|||
} |
|||
|
|||
@Override |
|||
public void onBindViewHolder(@NonNull final FollowsViewHolder holder, final int position) { |
|||
final ProfileModel model = profileModels.get(position); |
|||
holder.bind(model, null, onClickListener); |
|||
} |
|||
|
|||
@Override |
|||
public int getItemCount() { |
|||
return profileModels.size(); |
|||
} |
|||
} |
@ -0,0 +1,118 @@ |
|||
package awais.instagrabber.fragments; |
|||
|
|||
import android.content.Context; |
|||
import android.content.res.Resources; |
|||
import android.os.AsyncTask; |
|||
import android.os.Bundle; |
|||
import android.util.Log; |
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.ViewGroup; |
|||
import android.widget.Toast; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.annotation.Nullable; |
|||
import androidx.appcompat.app.AppCompatActivity; |
|||
import androidx.appcompat.widget.LinearLayoutCompat; |
|||
import androidx.lifecycle.ViewModelProvider; |
|||
import androidx.navigation.NavDirections; |
|||
import androidx.navigation.fragment.NavHostFragment; |
|||
import androidx.recyclerview.widget.LinearLayoutManager; |
|||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
|||
|
|||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; |
|||
|
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
|
|||
import awais.instagrabber.BuildConfig; |
|||
import awais.instagrabber.R; |
|||
import awais.instagrabber.adapters.LikesAdapter; |
|||
import awais.instagrabber.databinding.FragmentLikesBinding; |
|||
import awais.instagrabber.models.ProfileModel; |
|||
import awais.instagrabber.utils.Constants; |
|||
import awais.instagrabber.utils.TextUtils; |
|||
import awais.instagrabber.utils.Utils; |
|||
import awais.instagrabber.webservices.MediaService; |
|||
import awais.instagrabber.webservices.ServiceCallback; |
|||
|
|||
public final class LikesViewerFragment extends BottomSheetDialogFragment implements SwipeRefreshLayout.OnRefreshListener { |
|||
private static final String TAG = "LikesViewerFragment"; |
|||
|
|||
private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); |
|||
|
|||
private LikesAdapter likesAdapter; |
|||
private FragmentLikesBinding binding; |
|||
private LinearLayoutManager layoutManager; |
|||
private Resources resources; |
|||
private AppCompatActivity fragmentActivity; |
|||
private LinearLayoutCompat root; |
|||
private MediaService mediaService; |
|||
private String postId; |
|||
|
|||
private final ServiceCallback<List<ProfileModel>> cb = new ServiceCallback<List<ProfileModel>>() { |
|||
@Override |
|||
public void onSuccess(final List<ProfileModel> result) { |
|||
final LikesAdapter likesAdapter = new LikesAdapter(result, v -> { |
|||
final Object tag = v.getTag(); |
|||
if (tag instanceof ProfileModel) { |
|||
ProfileModel model = (ProfileModel) tag; |
|||
final Bundle bundle = new Bundle(); |
|||
bundle.putString("username", "@" + model.getUsername()); |
|||
NavHostFragment.findNavController(LikesViewerFragment.this).navigate(R.id.action_global_profileFragment, bundle); |
|||
} |
|||
}); |
|||
binding.rvLikes.setAdapter(likesAdapter); |
|||
binding.rvLikes.setLayoutManager(new LinearLayoutManager(getContext())); |
|||
binding.swipeRefreshLayout.setRefreshing(false); |
|||
} |
|||
|
|||
@Override |
|||
public void onFailure(final Throwable t) { |
|||
Log.e(TAG, "Error", t); |
|||
try { |
|||
final Context context = getContext(); |
|||
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); |
|||
} |
|||
catch (Exception e) {} |
|||
} |
|||
}; |
|||
|
|||
@Override |
|||
public void onCreate(@Nullable final Bundle savedInstanceState) { |
|||
super.onCreate(savedInstanceState); |
|||
fragmentActivity = (AppCompatActivity) getActivity(); |
|||
mediaService = MediaService.getInstance(); |
|||
// setHasOptionsMenu(true); |
|||
} |
|||
|
|||
@NonNull |
|||
@Override |
|||
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { |
|||
binding = FragmentLikesBinding.inflate(getLayoutInflater()); |
|||
binding.swipeRefreshLayout.setEnabled(false); |
|||
binding.swipeRefreshLayout.setNestedScrollingEnabled(false); |
|||
root = binding.getRoot(); |
|||
return root; |
|||
} |
|||
|
|||
@Override |
|||
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { |
|||
init(); |
|||
} |
|||
|
|||
@Override |
|||
public void onRefresh() { |
|||
mediaService.fetchLikes(postId, cb); |
|||
} |
|||
|
|||
private void init() { |
|||
if (getArguments() == null) return; |
|||
final LikesViewerFragmentArgs fragmentArgs = LikesViewerFragmentArgs.fromBundle(getArguments()); |
|||
postId = fragmentArgs.getPostId(); |
|||
binding.swipeRefreshLayout.setOnRefreshListener(this); |
|||
binding.swipeRefreshLayout.setRefreshing(true); |
|||
resources = getResources(); |
|||
onRefresh(); |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
android:orientation="vertical"> |
|||
|
|||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout |
|||
android:id="@+id/swipeRefreshLayout" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="0dp" |
|||
android:layout_weight="1"> |
|||
|
|||
<androidx.recyclerview.widget.RecyclerView |
|||
android:id="@+id/rvLikes" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
android:clipToPadding="false" /> |
|||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> |
|||
</androidx.appcompat.widget.LinearLayoutCompat> |
@ -0,0 +1,40 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<navigation xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:id="@+id/likes_nav_graph" |
|||
app:startDestination="@id/likesViewerFragment"> |
|||
|
|||
<!--<include app:graph="@navigation/hashtag_nav_graph" />--> |
|||
|
|||
<!--<include app:graph="@navigation/profile_nav_graph" />--> |
|||
|
|||
<action |
|||
android:id="@+id/action_global_profileFragment" |
|||
app:destination="@id/profile_nav_graph"> |
|||
<argument |
|||
android:name="username" |
|||
app:argType="string" |
|||
app:nullable="true" /> |
|||
</action> |
|||
|
|||
<dialog |
|||
android:id="@+id/likesViewerFragment" |
|||
android:name="awais.instagrabber.fragments.LikesViewerFragment" |
|||
android:label="Comments" |
|||
tools:layout="@layout/fragment_likes"> |
|||
<argument |
|||
android:name="postId" |
|||
app:argType="string" |
|||
app:nullable="false" /> |
|||
</dialog> |
|||
|
|||
<action |
|||
android:id="@+id/action_global_likesViewerFragment" |
|||
app:destination="@id/likesViewerFragment"> |
|||
<argument |
|||
android:name="postId" |
|||
app:argType="string" |
|||
app:nullable="false" /> |
|||
</action> |
|||
</navigation> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue