mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 22:57:29 +00:00
custom folder + username folder
This commit is contained in:
parent
69a7d67734
commit
4fed608ffc
@ -46,16 +46,10 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
protected final DiscoverItemModel[] doInBackground(final Void... voids) {
|
protected final DiscoverItemModel[] doInBackground(final Void... voids) {
|
||||||
// to check if file exists
|
|
||||||
File customDir = null;
|
|
||||||
if (settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
|
|
||||||
final String customPath = settingsHelper.getString(FOLDER_PATH);
|
|
||||||
if (!Utils.isEmpty(customPath)) customDir = new File(customPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscoverItemModel[] result = null;
|
DiscoverItemModel[] result = null;
|
||||||
|
|
||||||
final ArrayList<DiscoverItemModel> discoverItemModels = fetchItems(customDir, null, maxId);
|
final ArrayList<DiscoverItemModel> discoverItemModels = fetchItems(null, maxId);
|
||||||
if (discoverItemModels != null) {
|
if (discoverItemModels != null) {
|
||||||
result = discoverItemModels.toArray(new DiscoverItemModel[0]);
|
result = discoverItemModels.toArray(new DiscoverItemModel[0]);
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
@ -67,8 +61,7 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<DiscoverItemModel> fetchItems(final File customDir,
|
private ArrayList<DiscoverItemModel> fetchItems(ArrayList<DiscoverItemModel> discoverItemModels, final String maxId) {
|
||||||
ArrayList<DiscoverItemModel> discoverItemModels, final String maxId) {
|
|
||||||
try {
|
try {
|
||||||
final String url = "https://www.instagram.com/explore/grid/?is_prefetch=false&omit_cover_media=true&module=explore_popular" +
|
final String url = "https://www.instagram.com/explore/grid/?is_prefetch=false&omit_cover_media=true&module=explore_popular" +
|
||||||
"&use_sectional_payload=false&cluster_id=explore_all%3A0&include_fixed_destinations=true" + maxId;
|
"&use_sectional_payload=false&cluster_id=explore_all%3A0&include_fixed_destinations=true" + maxId;
|
||||||
@ -99,8 +92,7 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
|
|||||||
if ("media_grid".equals(layoutType)) {
|
if ("media_grid".equals(layoutType)) {
|
||||||
final JSONArray medias = layoutContent.getJSONArray("medias");
|
final JSONArray medias = layoutContent.getJSONArray("medias");
|
||||||
for (int j = 0; j < medias.length(); ++j)
|
for (int j = 0; j < medias.length(); ++j)
|
||||||
discoverItemModels.add(makeDiscoverModel(customDir,
|
discoverItemModels.add(makeDiscoverModel(medias.getJSONObject(j).getJSONObject("media")));
|
||||||
medias.getJSONObject(j).getJSONObject("media")));
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
final boolean isOneSide = "one_by_two_left".equals(layoutType);
|
final boolean isOneSide = "one_by_two_left".equals(layoutType);
|
||||||
@ -108,14 +100,12 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
|
|||||||
|
|
||||||
final JSONObject layoutItem = layoutContent.getJSONObject(isOneSide ? "one_by_two_item" : "two_by_two_item");
|
final JSONObject layoutItem = layoutContent.getJSONObject(isOneSide ? "one_by_two_item" : "two_by_two_item");
|
||||||
if (layoutItem.has("media"))
|
if (layoutItem.has("media"))
|
||||||
discoverItemModels.add(makeDiscoverModel(customDir,
|
discoverItemModels.add(makeDiscoverModel(layoutItem.getJSONObject("media")));
|
||||||
layoutItem.getJSONObject("media")));
|
|
||||||
|
|
||||||
if (layoutContent.has("fill_items")) {
|
if (layoutContent.has("fill_items")) {
|
||||||
final JSONArray fillItems = layoutContent.getJSONArray("fill_items");
|
final JSONArray fillItems = layoutContent.getJSONArray("fill_items");
|
||||||
for (int j = 0; j < fillItems.length(); ++j)
|
for (int j = 0; j < fillItems.length(); ++j)
|
||||||
discoverItemModels.add(makeDiscoverModel(customDir,
|
discoverItemModels.add(makeDiscoverModel(fillItems.getJSONObject(j).getJSONObject("media")));
|
||||||
fillItems.getJSONObject(j).getJSONObject("media")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,8 +119,7 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
|
|||||||
if (this.isFirst) {
|
if (this.isFirst) {
|
||||||
final int size = discoverItemModels.size();
|
final int size = discoverItemModels.size();
|
||||||
if (size > 50) this.isFirst = false;
|
if (size > 50) this.isFirst = false;
|
||||||
discoverItemModels = fetchItems(customDir, discoverItemModels,
|
discoverItemModels = fetchItems(discoverItemModels, "&max_id=" + (lastId++));
|
||||||
"&max_id=" + (lastId++));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
urlConnection.disconnect();
|
urlConnection.disconnect();
|
||||||
@ -149,8 +138,7 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private DiscoverItemModel makeDiscoverModel(final File customDir,
|
private DiscoverItemModel makeDiscoverModel(@NonNull final JSONObject media) throws Exception {
|
||||||
@NonNull final JSONObject media) throws Exception {
|
|
||||||
final JSONObject user = media.getJSONObject(Constants.EXTRAS_USER);
|
final JSONObject user = media.getJSONObject(Constants.EXTRAS_USER);
|
||||||
final String username = user.getString(Constants.EXTRAS_USERNAME);
|
final String username = user.getString(Constants.EXTRAS_USERNAME);
|
||||||
// final ProfileModel userProfileModel = new ProfileModel(user.getBoolean("is_private"),
|
// final ProfileModel userProfileModel = new ProfileModel(user.getBoolean("is_private"),
|
||||||
@ -179,6 +167,14 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
|
|||||||
final File downloadDir = new File(Environment.getExternalStorageDirectory(), "Download" +
|
final File downloadDir = new File(Environment.getExternalStorageDirectory(), "Download" +
|
||||||
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
|
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
|
||||||
|
|
||||||
|
// to check if file exists
|
||||||
|
File customDir = null;
|
||||||
|
if (settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
|
||||||
|
final String customPath = settingsHelper.getString(FOLDER_PATH);
|
||||||
|
if (!Utils.isEmpty(customPath)) customDir = new File(customPath +
|
||||||
|
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
|
||||||
|
}
|
||||||
|
|
||||||
Utils.checkExistence(downloadDir, customDir, mediaType == MediaItemType.MEDIA_TYPE_SLIDER, model);
|
Utils.checkExistence(downloadDir, customDir, mediaType == MediaItemType.MEDIA_TYPE_SLIDER, model);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
|
@ -53,7 +53,8 @@ public final class PostFetcher extends AsyncTask<Void, Void, ViewerPostModel[]>
|
|||||||
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
|
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
|
||||||
File customDir = null;
|
File customDir = null;
|
||||||
if (Utils.settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
|
if (Utils.settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
|
||||||
final String customPath = Utils.settingsHelper.getString(FOLDER_PATH);
|
final String customPath = Utils.settingsHelper.getString(FOLDER_PATH +
|
||||||
|
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
|
||||||
if (!Utils.isEmpty(customPath)) customDir = new File(customPath);
|
if (!Utils.isEmpty(customPath)) customDir = new File(customPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,8 @@ public final class PostsFetcher extends AsyncTask<Void, Void, PostModel[]> {
|
|||||||
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
|
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
|
||||||
File customDir = null;
|
File customDir = null;
|
||||||
if (Utils.settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
|
if (Utils.settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
|
||||||
final String customPath = Utils.settingsHelper.getString(FOLDER_PATH);
|
final String customPath = Utils.settingsHelper.getString(FOLDER_PATH +
|
||||||
|
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
|
||||||
if (!Utils.isEmpty(customPath)) customDir = new File(customPath);
|
if (!Utils.isEmpty(customPath)) customDir = new File(customPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user