mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-12 17:57:29 +00:00
convert HighlightModel usages (as highlights) to Story
This commit is contained in:
parent
dbf0c66b41
commit
f7ce2eeea2
@ -9,20 +9,20 @@ import androidx.recyclerview.widget.ListAdapter;
|
||||
|
||||
import awais.instagrabber.adapters.viewholder.HighlightViewHolder;
|
||||
import awais.instagrabber.databinding.ItemHighlightBinding;
|
||||
import awais.instagrabber.models.HighlightModel;
|
||||
import awais.instagrabber.repositories.responses.stories.Story;
|
||||
|
||||
public final class HighlightsAdapter extends ListAdapter<HighlightModel, HighlightViewHolder> {
|
||||
public final class HighlightsAdapter extends ListAdapter<Story, HighlightViewHolder> {
|
||||
|
||||
private final OnHighlightClickListener clickListener;
|
||||
|
||||
private static final DiffUtil.ItemCallback<HighlightModel> diffCallback = new DiffUtil.ItemCallback<HighlightModel>() {
|
||||
private static final DiffUtil.ItemCallback<Story> diffCallback = new DiffUtil.ItemCallback<Story>() {
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull final HighlightModel oldItem, @NonNull final HighlightModel newItem) {
|
||||
public boolean areItemsTheSame(@NonNull final Story oldItem, @NonNull final Story newItem) {
|
||||
return oldItem.getId().equals(newItem.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(@NonNull final HighlightModel oldItem, @NonNull final HighlightModel newItem) {
|
||||
public boolean areContentsTheSame(@NonNull final Story oldItem, @NonNull final Story newItem) {
|
||||
return oldItem.getId().equals(newItem.getId());
|
||||
}
|
||||
};
|
||||
@ -42,7 +42,7 @@ public final class HighlightsAdapter extends ListAdapter<HighlightModel, Highlig
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final HighlightViewHolder holder, final int position) {
|
||||
final HighlightModel highlightModel = getItem(position);
|
||||
final Story highlightModel = getItem(position);
|
||||
if (clickListener != null) {
|
||||
holder.itemView.setOnClickListener(v -> clickListener.onHighlightClick(highlightModel, position));
|
||||
}
|
||||
@ -50,6 +50,6 @@ public final class HighlightsAdapter extends ListAdapter<HighlightModel, Highlig
|
||||
}
|
||||
|
||||
public interface OnHighlightClickListener {
|
||||
void onHighlightClick(final HighlightModel model, final int position);
|
||||
void onHighlightClick(final Story model, final int position);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package awais.instagrabber.adapters.viewholder;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import awais.instagrabber.databinding.ItemHighlightBinding;
|
||||
import awais.instagrabber.models.HighlightModel;
|
||||
import awais.instagrabber.repositories.responses.stories.Story;
|
||||
|
||||
public final class HighlightViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@ -14,10 +14,10 @@ public final class HighlightViewHolder extends RecyclerView.ViewHolder {
|
||||
this.binding = binding;
|
||||
}
|
||||
|
||||
public void bind(final HighlightModel model) {
|
||||
public void bind(final Story model) {
|
||||
if (model == null) return;
|
||||
binding.title.setText(model.getTitle());
|
||||
binding.icon.setImageURI(model.getThumbnailUrl());
|
||||
binding.icon.setImageURI(model.getCoverMedia().getCroppedImageVersion().getUrl());
|
||||
// binding.getRoot().setOnClickListener(v -> {
|
||||
// if (listener == null) return;
|
||||
// listener.onFeedStoryClick(model, position);
|
||||
|
@ -736,12 +736,12 @@ public class StoryViewerFragment extends Fragment {
|
||||
switch (type) {
|
||||
case HIGHLIGHT: {
|
||||
final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel;
|
||||
final List<HighlightModel> models = highlightsViewModel.getList().getValue();
|
||||
final List<Story> models = highlightsViewModel.getList().getValue();
|
||||
if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size() || currentFeedStoryIndex < 0) {
|
||||
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
final HighlightModel model = models.get(currentFeedStoryIndex);
|
||||
final Story model = models.get(currentFeedStoryIndex);
|
||||
currentStoryMediaId = model.getId();
|
||||
fetchOptions = StoryViewerOptions.forHighlight(model.getId());
|
||||
highlightTitle = model.getTitle();
|
||||
|
@ -73,7 +73,6 @@ import awais.instagrabber.fragments.UserSearchFragment;
|
||||
import awais.instagrabber.fragments.UserSearchFragmentDirections;
|
||||
import awais.instagrabber.managers.DirectMessagesManager;
|
||||
import awais.instagrabber.managers.InboxManager;
|
||||
import awais.instagrabber.models.HighlightModel;
|
||||
import awais.instagrabber.models.PostsLayoutPreferences;
|
||||
import awais.instagrabber.models.enums.FavoriteType;
|
||||
import awais.instagrabber.models.enums.PostItemType;
|
||||
@ -84,6 +83,7 @@ import awais.instagrabber.repositories.responses.Media;
|
||||
import awais.instagrabber.repositories.responses.User;
|
||||
import awais.instagrabber.repositories.responses.UserProfileContextLink;
|
||||
import awais.instagrabber.repositories.responses.directmessages.RankedRecipient;
|
||||
import awais.instagrabber.repositories.responses.stories.Story;
|
||||
import awais.instagrabber.utils.AppExecutors;
|
||||
import awais.instagrabber.utils.Constants;
|
||||
import awais.instagrabber.utils.CookieUtils;
|
||||
@ -1121,7 +1121,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
if (highlightModels != null) {
|
||||
profileDetailsBinding.highlightsList.setVisibility(View.VISIBLE);
|
||||
//noinspection unchecked
|
||||
highlightsViewModel.getList().postValue((List<HighlightModel>) highlightModels);
|
||||
highlightsViewModel.getList().postValue((List<Story>) highlightModels);
|
||||
} else {
|
||||
profileDetailsBinding.highlightsList.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ interface StoriesService {
|
||||
suspend fun getFeedStories(): ReelsTrayResponse
|
||||
|
||||
@GET("/api/v1/highlights/{uid}/highlights_tray/")
|
||||
suspend fun fetchHighlights(@Path("uid") uid: Long): String
|
||||
suspend fun fetchHighlights(@Path("uid") uid: Long): ReelsTrayResponse
|
||||
|
||||
@GET("/api/v1/archive/reel/day_shells/")
|
||||
suspend fun fetchArchive(@QueryMap queryParams: Map<String, String>): String
|
||||
|
@ -1,5 +0,0 @@
|
||||
package awais.instagrabber.repositories.responses
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
data class HdProfilePicUrlInfo(val url: String, private val width: Int, private val height: Int) : Serializable
|
@ -0,0 +1,5 @@
|
||||
package awais.instagrabber.repositories.responses
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
data class ImageUrl(val url: String, private val width: Int, private val height: Int) : Serializable
|
@ -27,7 +27,7 @@ data class User @JvmOverloads constructor(
|
||||
val externalUrl: String? = null,
|
||||
val usertagsCount: Long = 0,
|
||||
val publicEmail: String? = null,
|
||||
val hdProfilePicUrlInfo: HdProfilePicUrlInfo? = null,
|
||||
val hdProfilePicUrlInfo: ImageUrl? = null,
|
||||
val profileContext: String? = null, // "also followed by" your friends
|
||||
val profileContextLinksWithUserIds: List<UserProfileContextLink>? = null, // ^
|
||||
val socialContext: String? = null, // AYML
|
||||
|
@ -0,0 +1,5 @@
|
||||
package awais.instagrabber.repositories.responses.stories
|
||||
|
||||
import awais.instagrabber.repositories.responses.ImageUrl
|
||||
|
||||
data class CoverMedia(val croppedImageVersion: ImageUrl)
|
@ -1,19 +1,24 @@
|
||||
package awais.instagrabber.repositories.responses.stories
|
||||
|
||||
import java.io.Serializable
|
||||
import awais.instagrabber.repositories.responses.Media
|
||||
import awais.instagrabber.repositories.responses.User
|
||||
import awais.instagrabber.utils.TextUtils
|
||||
|
||||
data class Story(
|
||||
// universal
|
||||
val id: String?,
|
||||
val latestReelMedia: Long?, // = timestamp
|
||||
var seen: Long?,
|
||||
val user: User?,
|
||||
// for stories
|
||||
val mediaCount: Int?,
|
||||
val muted: Boolean?,
|
||||
val hasBestiesMedia: Boolean?,
|
||||
val mediaCount: Int?,
|
||||
val items: List<StoryMedia>?, // may be null
|
||||
// for highlights
|
||||
val coverMedia: CoverMedia?,
|
||||
val title: String?,
|
||||
// invented fields
|
||||
val broadcast: Broadcast? // does not naturally occur
|
||||
) : Serializable {
|
||||
val dateTime: String
|
||||
|
@ -5,12 +5,12 @@ import androidx.lifecycle.ViewModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import awais.instagrabber.models.HighlightModel;
|
||||
import awais.instagrabber.repositories.responses.stories.Story;
|
||||
|
||||
public class HighlightsViewModel extends ViewModel {
|
||||
private MutableLiveData<List<HighlightModel>> list;
|
||||
private MutableLiveData<List<Story>> list;
|
||||
|
||||
public MutableLiveData<List<HighlightModel>> getList() {
|
||||
public MutableLiveData<List<Story>> getList() {
|
||||
if (list == null) {
|
||||
list = new MutableLiveData<>();
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import awais.instagrabber.db.entities.Favorite
|
||||
import awais.instagrabber.db.repositories.AccountRepository
|
||||
import awais.instagrabber.db.repositories.FavoriteRepository
|
||||
import awais.instagrabber.managers.DirectMessagesManager
|
||||
import awais.instagrabber.models.HighlightModel
|
||||
import awais.instagrabber.models.Resource
|
||||
import awais.instagrabber.models.StoryModel
|
||||
import awais.instagrabber.models.enums.BroadcastItemType
|
||||
@ -16,6 +15,7 @@ import awais.instagrabber.models.enums.FavoriteType
|
||||
import awais.instagrabber.repositories.requests.StoryViewerOptions
|
||||
import awais.instagrabber.repositories.responses.User
|
||||
import awais.instagrabber.repositories.responses.directmessages.RankedRecipient
|
||||
import awais.instagrabber.repositories.responses.stories.Story
|
||||
import awais.instagrabber.utils.ControlledRunner
|
||||
import awais.instagrabber.utils.extensions.TAG
|
||||
import awais.instagrabber.webservices.*
|
||||
@ -119,9 +119,9 @@ class ProfileFragmentViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
private val highlightsFetchControlledRunner = ControlledRunner<List<HighlightModel>?>()
|
||||
val userHighlights: LiveData<Resource<List<HighlightModel>?>> = profile.switchMap { userResource ->
|
||||
liveData<Resource<List<HighlightModel>?>>(context = viewModelScope.coroutineContext + ioDispatcher) {
|
||||
private val highlightsFetchControlledRunner = ControlledRunner<List<Story>?>()
|
||||
val userHighlights: LiveData<Resource<List<Story>?>> = profile.switchMap { userResource ->
|
||||
liveData<Resource<List<Story>?>>(context = viewModelScope.coroutineContext + ioDispatcher) {
|
||||
// don't fetch if not logged in
|
||||
if (isLoggedIn.value != true) {
|
||||
emit(Resource.success(null))
|
||||
@ -165,7 +165,7 @@ class ProfileFragmentViewModel(
|
||||
StoryViewerOptions.forUser(fetchedUser.pk, fetchedUser.fullName)
|
||||
)
|
||||
|
||||
private suspend fun fetchUserHighlights(fetchedUser: User): List<HighlightModel> = storiesRepository.fetchHighlights(fetchedUser.pk)
|
||||
private suspend fun fetchUserHighlights(fetchedUser: User): List<Story> = storiesRepository.fetchHighlights(fetchedUser.pk)
|
||||
|
||||
private suspend fun checkAndInsertFavorite(fetchedUser: User) {
|
||||
try {
|
||||
|
@ -37,9 +37,11 @@ open class StoriesRepository(private val service: StoriesService) {
|
||||
broadcast.publishedTime,
|
||||
0L,
|
||||
broadcast.broadcastOwner,
|
||||
1,
|
||||
broadcast.muted,
|
||||
false, // unclear
|
||||
1,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
broadcast
|
||||
)
|
||||
@ -49,25 +51,9 @@ open class StoriesRepository(private val service: StoriesService) {
|
||||
return sort(result.toList())
|
||||
}
|
||||
|
||||
open suspend fun fetchHighlights(profileId: Long): List<HighlightModel> {
|
||||
open suspend fun fetchHighlights(profileId: Long): List<Story> {
|
||||
val response = service.fetchHighlights(profileId)
|
||||
val highlightsReel = JSONObject(response).getJSONArray("tray")
|
||||
val length = highlightsReel.length()
|
||||
val highlightModels: MutableList<HighlightModel> = ArrayList()
|
||||
for (i in 0 until length) {
|
||||
val highlightNode = highlightsReel.getJSONObject(i)
|
||||
highlightModels.add(
|
||||
HighlightModel(
|
||||
highlightNode.getString("title"),
|
||||
highlightNode.getString(Constants.EXTRAS_ID),
|
||||
highlightNode.getJSONObject("cover_media")
|
||||
.getJSONObject("cropped_image_version")
|
||||
.getString("url"),
|
||||
highlightNode.getLong("latest_reel_media"),
|
||||
highlightNode.getInt("media_count")
|
||||
)
|
||||
)
|
||||
}
|
||||
val highlightModels = response.tray ?: listOf()
|
||||
return highlightModels
|
||||
}
|
||||
|
||||
|
@ -11,13 +11,13 @@ import awais.instagrabber.db.entities.Favorite
|
||||
import awais.instagrabber.db.repositories.AccountRepository
|
||||
import awais.instagrabber.db.repositories.FavoriteRepository
|
||||
import awais.instagrabber.getOrAwaitValue
|
||||
import awais.instagrabber.models.HighlightModel
|
||||
import awais.instagrabber.models.Resource
|
||||
import awais.instagrabber.models.StoryModel
|
||||
import awais.instagrabber.models.enums.FavoriteType
|
||||
import awais.instagrabber.repositories.requests.StoryViewerOptions
|
||||
import awais.instagrabber.repositories.responses.FriendshipStatus
|
||||
import awais.instagrabber.repositories.responses.User
|
||||
import awais.instagrabber.repositories.responses.stories.Story
|
||||
import awais.instagrabber.webservices.*
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import org.json.JSONException
|
||||
@ -296,7 +296,7 @@ internal class ProfileFragmentViewModelTest {
|
||||
)
|
||||
)
|
||||
val testUserStories = listOf(StoryModel())
|
||||
val testUserHighlights = listOf(HighlightModel())
|
||||
val testUserHighlights = listOf(Story())
|
||||
val userRepository = object : UserRepository(UserServiceAdapter()) {
|
||||
override suspend fun getUsernameInfo(username: String): User = testPublicUser
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user