Browse Source

Move StoriesService object to StoriesRepository constructor parameter.

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
3d69148d9b
  1. 2
      app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java
  2. 2
      app/src/main/java/awais/instagrabber/fragments/LocationFragment.java
  3. 2
      app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java
  4. 2
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
  5. 2
      app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java
  6. 2
      app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
  7. 100
      app/src/main/java/awais/instagrabber/webservices/StoriesRepository.kt

2
app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java

@ -298,7 +298,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
final String cookie = settingsHelper.getString(Constants.COOKIE);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
tagsService = isLoggedIn ? TagsService.getInstance() : null;
storiesRepository = isLoggedIn ? StoriesRepository.INSTANCE : null;
storiesRepository = isLoggedIn ? StoriesRepository.Companion.getInstance() : null;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
setHasOptionsMenu(true);
}

2
app/src/main/java/awais/instagrabber/fragments/LocationFragment.java

@ -291,7 +291,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
final String cookie = settingsHelper.getString(Constants.COOKIE);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
locationService = isLoggedIn ? LocationService.getInstance() : null;
storiesRepository = StoriesRepository.INSTANCE;
storiesRepository = StoriesRepository.Companion.getInstance();
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
setHasOptionsMenu(true);
}

2
app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java

@ -136,7 +136,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
context = getContext();
if (context == null) return;
setHasOptionsMenu(true);
storiesRepository = StoriesRepository.INSTANCE;
storiesRepository = StoriesRepository.Companion.getInstance();
}
@NonNull

2
app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java

@ -162,7 +162,7 @@ public class StoryViewerFragment extends Fragment {
userId = CookieUtils.getUserIdFromCookie(cookie);
deviceId = settingsHelper.getString(Constants.DEVICE_UUID);
fragmentActivity = (AppCompatActivity) requireActivity();
storiesRepository = StoriesRepository.INSTANCE;
storiesRepository = StoriesRepository.Companion.getInstance();
mediaService = MediaService.INSTANCE;
directMessagesService = DirectMessagesService.INSTANCE;
setHasOptionsMenu(true);

2
app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java

@ -276,7 +276,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fragmentActivity = (MainActivity) requireActivity();
storiesRepository = StoriesRepository.INSTANCE;
storiesRepository = StoriesRepository.Companion.getInstance();
setHasOptionsMenu(true);
}

2
app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java

@ -335,7 +335,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
fragmentActivity = (MainActivity) requireActivity();
friendshipRepository = isLoggedIn ? FriendshipRepository.Companion.getInstance() : null;
directMessagesService = isLoggedIn ? DirectMessagesService.INSTANCE : null;
storiesRepository = isLoggedIn ? StoriesRepository.INSTANCE : null;
storiesRepository = isLoggedIn ? StoriesRepository.Companion.getInstance() : null;
mediaService = isLoggedIn ? MediaService.INSTANCE : null;
userRepository = isLoggedIn ? UserRepository.Companion.getInstance() : null;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;

100
app/src/main/java/awais/instagrabber/webservices/StoriesRepository.kt

@ -19,8 +19,7 @@ import org.json.JSONArray
import org.json.JSONObject
import java.util.*
object StoriesRepository {
private val service: StoriesService = retrofit.create(StoriesService::class.java)
class StoriesRepository(private val service: StoriesService) {
suspend fun fetch(mediaId: Long): StoryModel {
val response = service.fetch(mediaId)
@ -41,7 +40,8 @@ object StoriesRepository {
if (node.optBoolean("hide_from_feed_unit") && Utils.settingsHelper.getBoolean(PreferenceKeys.HIDE_MUTED_REELS)) continue
val userJson = node.getJSONObject(if (node.has("user")) "user" else "owner")
try {
val user = User(userJson.getLong("pk"),
val user = User(
userJson.getLong("pk"),
userJson.getString("username"),
userJson.optString("full_name"),
userJson.optBoolean("is_private"),
@ -55,15 +55,18 @@ object StoriesRepository {
if (itemJson != null) {
firstStoryModel = ResponseBodyUtils.parseStoryItem(itemJson, false, null)
}
feedStoryModels.add(FeedStoryModel(
node.getString("id"),
user,
fullyRead,
timestamp,
firstStoryModel,
node.getInt("media_count"),
false,
node.optBoolean("has_besties_media")))
feedStoryModels.add(
FeedStoryModel(
node.getString("id"),
user,
fullyRead,
timestamp,
firstStoryModel,
node.getInt("media_count"),
false,
node.optBoolean("has_besties_media")
)
)
} catch (e: Exception) {
Log.e(TAG, "parseStoriesBody: ", e)
} // to cover promotional reels with non-long user pk's
@ -72,23 +75,26 @@ object StoriesRepository {
for (i in 0 until broadcasts.length()) {
val node = broadcasts.getJSONObject(i)
val userJson = node.getJSONObject("broadcast_owner")
val user = User(userJson.getLong("pk"),
val user = User(
userJson.getLong("pk"),
userJson.getString("username"),
userJson.optString("full_name"),
userJson.optBoolean("is_private"),
userJson.getString("profile_pic_url"),
userJson.optBoolean("is_verified")
)
feedStoryModels.add(FeedStoryModel(
node.getString("id"),
user,
false,
node.getLong("published_time"),
ResponseBodyUtils.parseBroadcastItem(node),
1,
isLive = true,
isBestie = false
))
feedStoryModels.add(
FeedStoryModel(
node.getString("id"),
user,
false,
node.getLong("published_time"),
ResponseBodyUtils.parseBroadcastItem(node),
1,
isLive = true,
isBestie = false
)
)
}
return sort(feedStoryModels)
}
@ -100,15 +106,17 @@ object StoriesRepository {
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")
))
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")
)
)
}
return highlightModels
}
@ -129,13 +137,15 @@ object StoriesRepository {
val highlightModels: MutableList<HighlightModel> = ArrayList()
for (i in 0 until length) {
val highlightNode = highlightsReel.getJSONObject(i)
highlightModels.add(HighlightModel(
null,
highlightNode.getString(Constants.EXTRAS_ID),
highlightNode.getJSONObject("cover_image_version").getString("url"),
highlightNode.getLong("latest_reel_media"),
highlightNode.getInt("media_count")
))
highlightModels.add(
HighlightModel(
null,
highlightNode.getString(Constants.EXTRAS_ID),
highlightNode.getJSONObject("cover_image_version").getString("url"),
highlightNode.getLong("latest_reel_media"),
highlightNode.getInt("media_count")
)
)
}
return ArchiveFetchResponse(highlightModels, data.getBoolean("more_available"), data.getString("max_id"))
}
@ -306,4 +316,16 @@ object StoriesRepository {
return hasNextPage
}
}
companion object {
@Volatile
private var INSTANCE: StoriesRepository? = null
fun getInstance(): StoriesRepository {
return INSTANCE ?: synchronized(this) {
val service: StoriesService = retrofit.create(StoriesService::class.java)
StoriesRepository(service).also { INSTANCE = it }
}
}
}
}
Loading…
Cancel
Save