Browse Source
retire LocationFetcher and enforce consistency
renovate/org.robolectric-robolectric-4.x
retire LocationFetcher and enforce consistency
renovate/org.robolectric-robolectric-4.x
Austin Huang
4 years ago
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
14 changed files with 187 additions and 344 deletions
-
5app/src/main/java/awais/instagrabber/activities/MainActivity.java
-
81app/src/main/java/awais/instagrabber/asyncs/LocationFetcher.java
-
10app/src/main/java/awais/instagrabber/asyncs/LocationPostFetchService.java
-
135app/src/main/java/awais/instagrabber/fragments/LocationFragment.java
-
56app/src/main/java/awais/instagrabber/models/LocationModel.java
-
51app/src/main/java/awais/instagrabber/models/SuggestionModel.java
-
3app/src/main/java/awais/instagrabber/repositories/GraphQLRepository.java
-
3app/src/main/java/awais/instagrabber/repositories/LocationRepository.java
-
18app/src/main/java/awais/instagrabber/repositories/responses/Location.java
-
15app/src/main/java/awais/instagrabber/repositories/responses/Place.java
-
3app/src/main/java/awais/instagrabber/repositories/responses/search/SearchItem.java
-
45app/src/main/java/awais/instagrabber/webservices/GraphQLService.java
-
50app/src/main/java/awais/instagrabber/webservices/LocationService.java
-
56app/src/main/res/layout/layout_location_details.xml
@ -1,81 +0,0 @@ |
|||
package awais.instagrabber.asyncs; |
|||
|
|||
import android.os.AsyncTask; |
|||
import android.util.Log; |
|||
|
|||
import androidx.annotation.Nullable; |
|||
|
|||
import org.json.JSONObject; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
|
|||
import awais.instagrabber.BuildConfig; |
|||
import awais.instagrabber.interfaces.FetchListener; |
|||
import awais.instagrabber.models.LocationModel; |
|||
import awais.instagrabber.utils.Constants; |
|||
import awais.instagrabber.utils.NetworkUtils; |
|||
//import awaisomereport.LogCollector; |
|||
|
|||
//import static awais.instagrabber.utils.Utils.logCollector; |
|||
|
|||
public final class LocationFetcher extends AsyncTask<Void, Void, LocationModel> { |
|||
private static final String TAG = "LocationFetcher"; |
|||
|
|||
private final FetchListener<LocationModel> fetchListener; |
|||
private final long id; |
|||
|
|||
public LocationFetcher(final long id, final FetchListener<LocationModel> fetchListener) { |
|||
// idSlug = id + "/" + slug UPDATE: slug can be ignored tbh |
|||
this.id = id; |
|||
this.fetchListener = fetchListener; |
|||
} |
|||
|
|||
@Nullable |
|||
@Override |
|||
protected LocationModel doInBackground(final Void... voids) { |
|||
LocationModel result = null; |
|||
|
|||
try { |
|||
final HttpURLConnection conn = (HttpURLConnection) new URL("https://www.instagram.com/explore/locations/" + id + "/?__a=1") |
|||
.openConnection(); |
|||
conn.setUseCaches(true); |
|||
conn.connect(); |
|||
|
|||
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|||
final JSONObject location = new JSONObject(NetworkUtils.readFromConnection(conn)).getJSONObject("graphql") |
|||
.getJSONObject(Constants.EXTRAS_LOCATION); |
|||
|
|||
final JSONObject timelineMedia = location.getJSONObject("edge_location_to_media"); |
|||
// if (timelineMedia.has("edges")) { |
|||
// final JSONArray edges = timelineMedia.getJSONArray("edges"); |
|||
// } |
|||
result = new LocationModel( |
|||
location.getLong(Constants.EXTRAS_ID), |
|||
location.getString("name"), |
|||
location.getString("blurb"), |
|||
location.getString("website"), |
|||
location.getString("profile_pic_url"), |
|||
timelineMedia.getLong("count"), |
|||
BigDecimal.valueOf(location.optDouble("lat", 0d)).toString(), |
|||
BigDecimal.valueOf(location.optDouble("lng", 0d)).toString() |
|||
); |
|||
} |
|||
|
|||
conn.disconnect(); |
|||
} catch (final Exception e) { |
|||
// if (logCollector != null) |
|||
// logCollector.appendException(e, LogCollector.LogFile.ASYNC_LOCATION_FETCHER, "doInBackground"); |
|||
if (BuildConfig.DEBUG) { |
|||
Log.e(TAG, "", e); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
protected void onPostExecute(final LocationModel result) { |
|||
if (fetchListener != null) fetchListener.onResult(result); |
|||
} |
|||
} |
@ -1,56 +0,0 @@ |
|||
package awais.instagrabber.models; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
public final class LocationModel implements Serializable { |
|||
private final long postCount; |
|||
private final long id; |
|||
private final String name; |
|||
private final String bio; |
|||
private final String url; |
|||
private final String sdProfilePic; |
|||
private final String lat; |
|||
private final String lng; |
|||
|
|||
public LocationModel(final long id, |
|||
final String name, |
|||
final String bio, |
|||
final String url, |
|||
final String sdProfilePic, |
|||
final long postCount, |
|||
final String lat, |
|||
final String lng) { |
|||
this.id = id; |
|||
this.name = name; |
|||
this.bio = bio; |
|||
this.url = url; |
|||
this.sdProfilePic = sdProfilePic; |
|||
this.postCount = postCount; |
|||
this.lat = lat; |
|||
this.lng = lng; |
|||
} |
|||
|
|||
public long getId() { |
|||
return id; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public String getBio() { |
|||
return bio; |
|||
} |
|||
|
|||
public String getUrl() { |
|||
return url; |
|||
} |
|||
|
|||
public String getGeo() { return "geo:" + lat + "," + lng + "?z=17&q=" + lat + "," + lng + "(" + name + ")"; } |
|||
|
|||
public String getSdProfilePic() { |
|||
return sdProfilePic; |
|||
} |
|||
|
|||
public Long getPostCount() { return postCount; } |
|||
} |
@ -1,51 +0,0 @@ |
|||
package awais.instagrabber.models; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
|
|||
import awais.instagrabber.models.enums.SuggestionType; |
|||
|
|||
public final class SuggestionModel implements Comparable<SuggestionModel> { |
|||
private final int position; |
|||
private final boolean isVerified; |
|||
private final String username, name, profilePic; |
|||
private final SuggestionType suggestionType; |
|||
|
|||
public SuggestionModel(final boolean isVerified, final String username, final String name, final String profilePic, |
|||
final SuggestionType suggestionType, final int position) { |
|||
this.isVerified = isVerified; |
|||
this.username = username; |
|||
this.name = name; |
|||
this.profilePic = profilePic; |
|||
this.suggestionType = suggestionType; |
|||
this.position = position; |
|||
} |
|||
|
|||
public boolean isVerified() { |
|||
return isVerified; |
|||
} |
|||
|
|||
public String getUsername() { |
|||
return username; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public String getProfilePic() { |
|||
return profilePic; |
|||
} |
|||
|
|||
public SuggestionType getSuggestionType() { |
|||
return suggestionType; |
|||
} |
|||
|
|||
public int getPosition() { |
|||
return position; |
|||
} |
|||
|
|||
@Override |
|||
public int compareTo(@NonNull final SuggestionModel model) { |
|||
return Integer.compare(getPosition(), model.getPosition()); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue