Austin Huang
4 years ago
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
11 changed files with 208 additions and 262 deletions
-
2app/src/main/java/awais/instagrabber/activities/MainActivity.java
-
102app/src/main/java/awais/instagrabber/asyncs/HashtagFetcher.java
-
6app/src/main/java/awais/instagrabber/asyncs/HashtagPostFetchService.java
-
129app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java
-
35app/src/main/java/awais/instagrabber/models/HashtagModel.java
-
35app/src/main/java/awais/instagrabber/models/enums/FollowingType.java
-
3app/src/main/java/awais/instagrabber/repositories/GraphQLRepository.java
-
12app/src/main/java/awais/instagrabber/repositories/TagsRepository.java
-
45app/src/main/java/awais/instagrabber/repositories/responses/Hashtag.java
-
42app/src/main/java/awais/instagrabber/webservices/GraphQLService.java
-
41app/src/main/java/awais/instagrabber/webservices/TagsService.java
@ -1,102 +0,0 @@ |
|||||
package awais.instagrabber.asyncs; |
|
||||
|
|
||||
import android.os.AsyncTask; |
|
||||
import android.util.Log; |
|
||||
|
|
||||
import androidx.annotation.Nullable; |
|
||||
|
|
||||
import org.json.JSONArray; |
|
||||
import org.json.JSONObject; |
|
||||
|
|
||||
import java.io.BufferedReader; |
|
||||
import java.io.IOException; |
|
||||
import java.io.InputStream; |
|
||||
import java.io.InputStreamReader; |
|
||||
import java.net.HttpURLConnection; |
|
||||
import java.net.URL; |
|
||||
|
|
||||
import awais.instagrabber.BuildConfig; |
|
||||
import awais.instagrabber.interfaces.FetchListener; |
|
||||
import awais.instagrabber.models.HashtagModel; |
|
||||
import awais.instagrabber.utils.Constants; |
|
||||
import awais.instagrabber.utils.NetworkUtils; |
|
||||
//import awaisomereport.LogCollector; |
|
||||
|
|
||||
//import static awais.instagrabber.utils.Utils.logCollector; |
|
||||
|
|
||||
public final class HashtagFetcher extends AsyncTask<Void, Void, HashtagModel> { |
|
||||
private static final String TAG = "HashtagFetcher"; |
|
||||
|
|
||||
private final FetchListener<HashtagModel> fetchListener; |
|
||||
private final String hashtag; |
|
||||
|
|
||||
public HashtagFetcher(String hashtag, FetchListener<HashtagModel> fetchListener) { |
|
||||
this.hashtag = hashtag; |
|
||||
this.fetchListener = fetchListener; |
|
||||
} |
|
||||
|
|
||||
@Nullable |
|
||||
@Override |
|
||||
protected HashtagModel doInBackground(final Void... voids) { |
|
||||
HashtagModel result = null; |
|
||||
|
|
||||
try { |
|
||||
final HttpURLConnection conn = (HttpURLConnection) new URL("https://www.instagram.com/explore/tags/" + hashtag + "/?__a=1") |
|
||||
.openConnection(); |
|
||||
conn.setUseCaches(true); |
|
||||
conn.connect(); |
|
||||
|
|
||||
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
||||
final JSONObject user = new JSONObject(NetworkUtils.readFromConnection(conn)).getJSONObject("graphql") |
|
||||
.getJSONObject(Constants.EXTRAS_HASHTAG); |
|
||||
|
|
||||
final JSONObject timelineMedia = user.getJSONObject("edge_hashtag_to_media"); |
|
||||
if (timelineMedia.has("edges")) { |
|
||||
final JSONArray edges = timelineMedia.getJSONArray("edges"); |
|
||||
} |
|
||||
|
|
||||
result = new HashtagModel( |
|
||||
user.getString(Constants.EXTRAS_ID), |
|
||||
user.getString("name"), |
|
||||
user.getString("profile_pic_url"), |
|
||||
timelineMedia.getLong("count"), |
|
||||
user.optBoolean("is_following")); |
|
||||
} else { |
|
||||
BufferedReader bufferedReader = null; |
|
||||
try { |
|
||||
final InputStream responseInputStream = conn.getErrorStream(); |
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(responseInputStream)); |
|
||||
final StringBuilder builder = new StringBuilder(); |
|
||||
for (String line = bufferedReader.readLine(); line != null; line = bufferedReader.readLine()) { |
|
||||
if (builder.length() != 0) { |
|
||||
builder.append("\n"); |
|
||||
} |
|
||||
builder.append(line); |
|
||||
} |
|
||||
Log.d(TAG, "doInBackground: " + builder.toString()); |
|
||||
} finally { |
|
||||
if (bufferedReader != null) { |
|
||||
try { |
|
||||
bufferedReader.close(); |
|
||||
} catch (IOException ignored) { |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
conn.disconnect(); |
|
||||
} catch (final Exception e) { |
|
||||
// if (logCollector != null) |
|
||||
// logCollector.appendException(e, LogCollector.LogFile.ASYNC_HASHTAG_FETCHER, "doInBackground"); |
|
||||
if (BuildConfig.DEBUG) Log.e(TAG, "", e); |
|
||||
if (fetchListener != null) fetchListener.onFailure(e); |
|
||||
} |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected void onPostExecute(final HashtagModel result) { |
|
||||
if (fetchListener != null) fetchListener.onResult(result); |
|
||||
} |
|
||||
} |
|
@ -1,35 +0,0 @@ |
|||||
package awais.instagrabber.models; |
|
||||
|
|
||||
import java.io.Serializable; |
|
||||
|
|
||||
public final class HashtagModel implements Serializable { |
|
||||
private final boolean following; |
|
||||
private final long postCount; |
|
||||
private final String id; |
|
||||
private final String name; |
|
||||
private final String sdProfilePic; |
|
||||
|
|
||||
public HashtagModel(final String id, final String name, final String sdProfilePic, final long postCount, final boolean following) { |
|
||||
this.id = id; |
|
||||
this.name = name; |
|
||||
this.sdProfilePic = sdProfilePic; |
|
||||
this.postCount = postCount; |
|
||||
this.following = following; |
|
||||
} |
|
||||
|
|
||||
public String getId() { |
|
||||
return id; |
|
||||
} |
|
||||
|
|
||||
public String getName() { |
|
||||
return name; |
|
||||
} |
|
||||
|
|
||||
public String getSdProfilePic() { |
|
||||
return sdProfilePic; |
|
||||
} |
|
||||
|
|
||||
public Long getPostCount() { return postCount; } |
|
||||
|
|
||||
public boolean getFollowing() { return following; } |
|
||||
} |
|
@ -0,0 +1,35 @@ |
|||||
|
package awais.instagrabber.models.enums; |
||||
|
|
||||
|
import com.google.gson.annotations.SerializedName; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
public enum FollowingType implements Serializable { |
||||
|
@SerializedName("1") |
||||
|
FOLLOWING(1), |
||||
|
@SerializedName("0") |
||||
|
NOT_FOLLOWING(0); |
||||
|
|
||||
|
private final int id; |
||||
|
private static final Map<Integer, FollowingType> map = new HashMap<>(); |
||||
|
|
||||
|
static { |
||||
|
for (FollowingType type : FollowingType.values()) { |
||||
|
map.put(type.id, type); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
FollowingType(final int id) { |
||||
|
this.id = id; |
||||
|
} |
||||
|
|
||||
|
public int getId() { |
||||
|
return id; |
||||
|
} |
||||
|
|
||||
|
public static FollowingType valueOf(final int id) { |
||||
|
return map.get(id); |
||||
|
} |
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
package awais.instagrabber.repositories.responses; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
import awais.instagrabber.models.enums.FollowingType; |
||||
|
|
||||
|
public final class Hashtag implements Serializable { |
||||
|
private final FollowingType following; // 0 false 1 true |
||||
|
private final long mediaCount; |
||||
|
private final String id; |
||||
|
private final String name; |
||||
|
private final String profilePicUrl; // on app API this is always null (property exists) |
||||
|
|
||||
|
public Hashtag(final String id, |
||||
|
final String name, |
||||
|
final String profilePicUrl, |
||||
|
final long mediaCount, |
||||
|
final FollowingType following) { |
||||
|
this.id = id; |
||||
|
this.name = name; |
||||
|
this.profilePicUrl = profilePicUrl; |
||||
|
this.mediaCount = mediaCount; |
||||
|
this.following = following; |
||||
|
} |
||||
|
|
||||
|
public String getId() { |
||||
|
return id; |
||||
|
} |
||||
|
|
||||
|
public String getName() { |
||||
|
return name; |
||||
|
} |
||||
|
|
||||
|
public String getProfilePicUrl() { |
||||
|
return profilePicUrl; |
||||
|
} |
||||
|
|
||||
|
public Long getMediaCount() { |
||||
|
return mediaCount; |
||||
|
} |
||||
|
|
||||
|
public FollowingType getFollowing() { |
||||
|
return following; |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue