convert some to kotlin

This commit is contained in:
Austin Huang 2021-05-30 19:07:58 -04:00
parent 37b4817bd7
commit 972f71c480
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
10 changed files with 67 additions and 264 deletions

View File

@ -11,20 +11,19 @@ import androidx.recyclerview.widget.ListAdapter;
import awais.instagrabber.adapters.viewholder.TopicClusterViewHolder; import awais.instagrabber.adapters.viewholder.TopicClusterViewHolder;
import awais.instagrabber.databinding.ItemDiscoverTopicBinding; import awais.instagrabber.databinding.ItemDiscoverTopicBinding;
import awais.instagrabber.repositories.responses.saved.SavedCollection; import awais.instagrabber.repositories.responses.saved.SavedCollection;
import awais.instagrabber.utils.ResponseBodyUtils;
public class SavedCollectionsAdapter extends ListAdapter<SavedCollection, TopicClusterViewHolder> { public class SavedCollectionsAdapter extends ListAdapter<SavedCollection, TopicClusterViewHolder> {
private static final DiffUtil.ItemCallback<SavedCollection> DIFF_CALLBACK = new DiffUtil.ItemCallback<SavedCollection>() { private static final DiffUtil.ItemCallback<SavedCollection> DIFF_CALLBACK = new DiffUtil.ItemCallback<SavedCollection>() {
@Override @Override
public boolean areItemsTheSame(@NonNull final SavedCollection oldItem, @NonNull final SavedCollection newItem) { public boolean areItemsTheSame(@NonNull final SavedCollection oldItem, @NonNull final SavedCollection newItem) {
return oldItem.getId().equals(newItem.getId()); return oldItem.getCollectionId().equals(newItem.getCollectionId());
} }
@Override @Override
public boolean areContentsTheSame(@NonNull final SavedCollection oldItem, @NonNull final SavedCollection newItem) { public boolean areContentsTheSame(@NonNull final SavedCollection oldItem, @NonNull final SavedCollection newItem) {
if (oldItem.getCoverMedias() != null && newItem.getCoverMedias() != null if (oldItem.getCoverMediaList() != null && newItem.getCoverMediaList() != null
&& oldItem.getCoverMedias().size() == newItem.getCoverMedias().size()) { && oldItem.getCoverMediaList().size() == newItem.getCoverMediaList().size()) {
return oldItem.getCoverMedias().get(0).getId().equals(newItem.getCoverMedias().get(0).getId()); return oldItem.getCoverMediaList().get(0).getId().equals(newItem.getCoverMediaList().get(0).getId());
} }
else if (oldItem.getCoverMedia() != null && newItem.getCoverMedia() != null) { else if (oldItem.getCoverMedia() != null && newItem.getCoverMedia() != null) {
return oldItem.getCoverMedia().getId().equals(newItem.getCoverMedia().getId()); return oldItem.getCoverMedia().getId().equals(newItem.getCoverMedia().getId());

View File

@ -128,11 +128,11 @@ public class TopicClusterViewHolder extends RecyclerView.ViewHolder {
backgroundColor.get() backgroundColor.get()
)); ));
} }
// binding.title.setTransitionName("title-" + topicCluster.getId()); // binding.title.setTransitionName("title-" + topicCluster.getCollectionId());
binding.cover.setTransitionName("cover-" + topicCluster.getId()); binding.cover.setTransitionName("cover-" + topicCluster.getCollectionId());
final String thumbUrl = ResponseBodyUtils.getThumbUrl(topicCluster.getCoverMedias() == null final String thumbUrl = ResponseBodyUtils.getThumbUrl(topicCluster.getCoverMediaList() == null
? topicCluster.getCoverMedia() ? topicCluster.getCoverMedia()
: topicCluster.getCoverMedias().get(0)); : topicCluster.getCoverMediaList().get(0));
if (thumbUrl == null) { if (thumbUrl == null) {
binding.cover.setImageURI((String) null); binding.cover.setImageURI((String) null);
} else { } else {
@ -174,6 +174,6 @@ public class TopicClusterViewHolder extends RecyclerView.ViewHolder {
}, CallerThreadExecutor.getInstance()); }, CallerThreadExecutor.getInstance());
binding.cover.setImageRequest(imageRequest); binding.cover.setImageRequest(imageRequest);
} }
binding.title.setText(topicCluster.getTitle()); binding.title.setText(topicCluster.getCollectionName());
} }
} }

View File

@ -297,7 +297,7 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
.setTitle(R.string.delete_collection) .setTitle(R.string.delete_collection)
.setMessage(R.string.delete_collection_note) .setMessage(R.string.delete_collection_note)
.setPositiveButton(R.string.confirm, (d, w) -> collectionService.deleteCollection( .setPositiveButton(R.string.confirm, (d, w) -> collectionService.deleteCollection(
savedCollection.getId(), savedCollection.getCollectionId(),
new ServiceCallback<String>() { new ServiceCallback<String>() {
@Override @Override
public void onSuccess(final String result) { public void onSuccess(final String result) {
@ -325,7 +325,7 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
.setTitle(R.string.edit_collection) .setTitle(R.string.edit_collection)
.setView(input) .setView(input)
.setPositiveButton(R.string.confirm, (d, w) -> collectionService.editCollectionName( .setPositiveButton(R.string.confirm, (d, w) -> collectionService.editCollectionName(
savedCollection.getId(), savedCollection.getCollectionId(),
input.getText().toString(), input.getText().toString(),
new ServiceCallback<String>() { new ServiceCallback<String>() {
@Override @Override
@ -408,9 +408,9 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
if (savedCollection == null) { if (savedCollection == null) {
return; return;
} }
binding.cover.setTransitionName("collection-" + savedCollection.getId()); binding.cover.setTransitionName("collection-" + savedCollection.getCollectionId());
fragmentActivity.setToolbar(binding.toolbar); fragmentActivity.setToolbar(binding.toolbar);
binding.collapsingToolbarLayout.setTitle(savedCollection.getTitle()); binding.collapsingToolbarLayout.setTitle(savedCollection.getCollectionName());
final int collapsedTitleTextColor = ColorUtils.setAlphaComponent(titleColor, 0xFF); final int collapsedTitleTextColor = ColorUtils.setAlphaComponent(titleColor, 0xFF);
final int expandedTitleTextColor = ColorUtils.setAlphaComponent(titleColor, 0x99); final int expandedTitleTextColor = ColorUtils.setAlphaComponent(titleColor, 0x99);
binding.collapsingToolbarLayout.setExpandedTitleColor(expandedTitleTextColor); binding.collapsingToolbarLayout.setExpandedTitleColor(expandedTitleTextColor);
@ -442,9 +442,9 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
} }
private void setupCover() { private void setupCover() {
final String coverUrl = ResponseBodyUtils.getImageUrl(savedCollection.getCoverMedias() == null final String coverUrl = ResponseBodyUtils.getImageUrl(savedCollection.getCoverMediaList() == null
? savedCollection.getCoverMedia() ? savedCollection.getCoverMedia()
: savedCollection.getCoverMedias().get(0)); : savedCollection.getCoverMediaList().get(0));
final DraweeController controller = Fresco final DraweeController controller = Fresco
.newDraweeControllerBuilder() .newDraweeControllerBuilder()
.setOldController(binding.cover.getController()) .setOldController(binding.cover.getController())
@ -471,7 +471,7 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
private void setupPosts() { private void setupPosts() {
binding.posts.setViewModelStoreOwner(this) binding.posts.setViewModelStoreOwner(this)
.setLifeCycleOwner(this) .setLifeCycleOwner(this)
.setPostFetchService(new SavedPostFetchService(0, PostItemType.COLLECTION, true, savedCollection.getId())) .setPostFetchService(new SavedPostFetchService(0, PostItemType.COLLECTION, true, savedCollection.getCollectionId()))
.setLayoutPreferences(layoutPreferences) .setLayoutPreferences(layoutPreferences)
.addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState())
.setFeedItemCallback(feedItemCallback) .setFeedItemCallback(feedItemCallback)

View File

@ -145,12 +145,12 @@ public class SavedCollectionsFragment extends Fragment implements SwipeRefreshLa
final SavedCollectionsAdapter adapter = new SavedCollectionsAdapter((topicCluster, root, cover, title, titleColor, backgroundColor) -> { final SavedCollectionsAdapter adapter = new SavedCollectionsAdapter((topicCluster, root, cover, title, titleColor, backgroundColor) -> {
final NavController navController = NavHostFragment.findNavController(this); final NavController navController = NavHostFragment.findNavController(this);
if (isSaving) { if (isSaving) {
setNavControllerResult(navController, topicCluster.getId()); setNavControllerResult(navController, topicCluster.getCollectionId());
navController.navigateUp(); navController.navigateUp();
} else { } else {
try { try {
final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder() final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder()
.addSharedElement(cover, "collection-" + topicCluster.getId()); .addSharedElement(cover, "collection-" + topicCluster.getCollectionId());
final SavedCollectionsFragmentDirections.ActionSavedCollectionsFragmentToCollectionPostsFragment action = SavedCollectionsFragmentDirections final SavedCollectionsFragmentDirections.ActionSavedCollectionsFragmentToCollectionPostsFragment action = SavedCollectionsFragmentDirections
.actionSavedCollectionsFragmentToCollectionPostsFragment(topicCluster, titleColor, backgroundColor); .actionSavedCollectionsFragmentToCollectionPostsFragment(topicCluster, titleColor, backgroundColor);
navController.navigate(action, builder.build()); navController.navigate(action, builder.build());

View File

@ -1,29 +1,11 @@
package awais.instagrabber.repositories.responses.notification; package awais.instagrabber.repositories.responses.notification
import awais.instagrabber.models.enums.NotificationType; import awais.instagrabber.models.enums.NotificationType
import awais.instagrabber.models.enums.NotificationType.Companion.valueOfType
public class Notification { class Notification(val args: NotificationArgs,
private final NotificationArgs args; private val storyType: Int,
private final int storyType; val pk: String) {
private final String pk; val type: NotificationType?
get() = valueOfType(storyType)
public Notification(final NotificationArgs args,
final int storyType,
final String pk) {
this.args = args;
this.storyType = storyType;
this.pk = pk;
}
public NotificationArgs getArgs() {
return args;
}
public NotificationType getType() {
return NotificationType.valueOfType(storyType);
}
public String getPk() {
return pk;
}
} }

View File

@ -1,55 +1,9 @@
package awais.instagrabber.repositories.responses.notification; package awais.instagrabber.repositories.responses.notification
public class NotificationCounts { class NotificationCounts(val commentLikesCount: Int,
private final int commentLikes; val userTagsCount: Int,
private final int usertags; val likesCount: Int,
private final int likes; val commentsCount: Int,
private final int comments; val relationshipsCount: Int,
private final int relationships; val pOYCount: Int,
private final int photosOfYou; val requestsCount: Int)
private final int requests;
public NotificationCounts(final int commentLikes,
final int usertags,
final int likes,
final int comments,
final int relationships,
final int photosOfYou,
final int requests) {
this.commentLikes = commentLikes;
this.usertags = usertags;
this.likes = likes;
this.comments = comments;
this.relationships = relationships;
this.photosOfYou = photosOfYou;
this.requests = requests;
}
public int getRelationshipsCount() {
return relationships;
}
public int getUserTagsCount() {
return usertags;
}
public int getCommentsCount() {
return comments;
}
public int getCommentLikesCount() {
return commentLikes;
}
public int getLikesCount() {
return likes;
}
public int getPOYCount() {
return photosOfYou;
}
public int getRequestsCount() {
return requests;
}
}

View File

@ -1,19 +1,3 @@
package awais.instagrabber.repositories.responses.notification; package awais.instagrabber.repositories.responses.notification
public class NotificationImage { class NotificationImage(val id: String, val image: String)
private final String id;
private final String image;
public NotificationImage(final String id, final String image) {
this.id = id;
this.image = image;
}
public String getId() {
return id;
}
public String getImage() {
return image;
}
}

View File

@ -1,50 +1,12 @@
package awais.instagrabber.repositories.responses.saved; package awais.instagrabber.repositories.responses.saved
import java.util.List; class CollectionsListResponse // this.numResults = numResults;
(val isMoreAvailable: Boolean,
public class CollectionsListResponse { val nextMaxId: String,
private final boolean moreAvailable; val maxId: String,
private final String nextMaxId; val status: String, // final int numResults,
private final String maxId; // public int getNumResults() {
private final String status; // return numResults;
// private final int numResults; // }
private final List<SavedCollection> items; // private final int numResults;
val items: List<SavedCollection>)
public CollectionsListResponse(final boolean moreAvailable,
final String nextMaxId,
final String maxId,
final String status,
// final int numResults,
final List<SavedCollection> items) {
this.moreAvailable = moreAvailable;
this.nextMaxId = nextMaxId;
this.maxId = maxId;
this.status = status;
// this.numResults = numResults;
this.items = items;
}
public boolean isMoreAvailable() {
return moreAvailable;
}
public String getNextMaxId() {
return nextMaxId;
}
public String getMaxId() {
return maxId;
}
public String getStatus() {
return status;
}
// public int getNumResults() {
// return numResults;
// }
public List<SavedCollection> getItems() {
return items;
}
}

View File

@ -1,54 +1,12 @@
package awais.instagrabber.repositories.responses.saved; package awais.instagrabber.repositories.responses.saved
import java.io.Serializable; import awais.instagrabber.repositories.responses.Media
import java.util.List; import java.io.Serializable
import awais.instagrabber.repositories.responses.Media; class SavedCollection(val collectionId: String,
val collectionName: String,
public class SavedCollection implements Serializable { val collectionType: String,
private final String collectionId; val collectionMediaCount: Int,
private final String collectionName; // coverMedia or coverMediaList: only one is defined
private final String collectionType; val coverMedia: Media,
private final int collectionMediacount; val coverMediaList: List<Media>) : Serializable
private final Media coverMedia;
private final List<Media> coverMediaList;
public SavedCollection(final String collectionId,
final String collectionName,
final String collectionType,
final int collectionMediacount,
final Media coverMedia,
final List<Media> coverMediaList) {
this.collectionId = collectionId;
this.collectionName = collectionName;
this.collectionType = collectionType;
this.collectionMediacount = collectionMediacount;
this.coverMedia = coverMedia;
this.coverMediaList = coverMediaList;
}
public String getId() {
return collectionId;
}
public String getTitle() {
return collectionName;
}
public String getType() {
return collectionType;
}
public int getMediaCount() {
return collectionMediacount;
}
// check the list first, then the single
// i have no idea what condition is required
public Media getCoverMedia() { return coverMedia; }
public List<Media> getCoverMedias() {
return coverMediaList;
}
}

View File

@ -1,46 +1,10 @@
package awais.instagrabber.repositories.responses.search; package awais.instagrabber.repositories.responses.search
import java.util.List; class SearchResponse(// app
val list: List<SearchItem>,
public class SearchResponse {
// app
private final List<SearchItem> list;
// browser // browser
private final List<SearchItem> users; val users: List<SearchItem>,
private final List<SearchItem> places; val places: List<SearchItem>,
private final List<SearchItem> hashtags; val hashtags: List<SearchItem>,
// universal // universal
private final String status; val status: String)
public SearchResponse(final List<SearchItem> list,
final List<SearchItem> users,
final List<SearchItem> places,
final List<SearchItem> hashtags,
final String status) {
this.list = list;
this.users = users;
this.places = places;
this.hashtags = hashtags;
this.status = status;
}
public List<SearchItem> getList() {
return list;
}
public List<SearchItem> getUsers() {
return users;
}
public List<SearchItem> getPlaces() {
return places;
}
public List<SearchItem> getHashtags() {
return hashtags;
}
public String getStatus() {
return status;
}
}