From f10fe0840b5aec3bf03a50436fe878759ccef765 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 8 Aug 2020 17:43:27 -0400 Subject: [PATCH] fix #39, url opener, and login; rmbr write changelog later --- app/build.gradle | 4 +- .../java/awais/instagrabber/MainHelper.java | 3 +- .../instagrabber/dialogs/SettingsDialog.java | 1 - .../models/enums/IntentModelType.java | 1 + .../awais/instagrabber/utils/Constants.java | 2 +- .../awais/instagrabber/utils/FlavorTown.java | 2 +- .../instagrabber/utils/UpdateChecker.java | 43 +++++-------------- .../java/awais/instagrabber/utils/Utils.java | 13 ++++-- 8 files changed, 28 insertions(+), 41 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 76c30794..71685fa4 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { minSdkVersion 16 targetSdkVersion 29 - versionCode 42 - versionName '17.6' + versionCode 43 + versionName '17.7' multiDexEnabled true diff --git a/app/src/main/java/awais/instagrabber/MainHelper.java b/app/src/main/java/awais/instagrabber/MainHelper.java index 8a979ef8..01603893 100755 --- a/app/src/main/java/awais/instagrabber/MainHelper.java +++ b/app/src/main/java/awais/instagrabber/MainHelper.java @@ -626,7 +626,8 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { .putExtra(Constants.EXTRAS_POST, new PostModel(modelText, false)), 9629); } else { main.addToStack(); - main.userQuery = modelType == IntentModelType.HASHTAG ? '#' + modelText : ("@"+modelText); + main.userQuery = modelType == IntentModelType.HASHTAG ? ('#' + modelText) : + (modelType == IntentModelType.LOCATION ? modelText : ('@'+modelText)); onRefresh(); } } diff --git a/app/src/main/java/awais/instagrabber/dialogs/SettingsDialog.java b/app/src/main/java/awais/instagrabber/dialogs/SettingsDialog.java index 54f4feb6..604ff987 100755 --- a/app/src/main/java/awais/instagrabber/dialogs/SettingsDialog.java +++ b/app/src/main/java/awais/instagrabber/dialogs/SettingsDialog.java @@ -185,7 +185,6 @@ public final class SettingsDialog extends BottomSheetDialogFragment implements V if (v == btnLogin) { startActivity(new Intent(v.getContext(), Login.class)); somethingChanged = true; - this.dismiss(); } else if (v == btnLogout) { Utils.setupCookies("LOGOUT"); settingsHelper.putString(Constants.COOKIE, ""); diff --git a/app/src/main/java/awais/instagrabber/models/enums/IntentModelType.java b/app/src/main/java/awais/instagrabber/models/enums/IntentModelType.java index 5d17b167..b9424a4f 100755 --- a/app/src/main/java/awais/instagrabber/models/enums/IntentModelType.java +++ b/app/src/main/java/awais/instagrabber/models/enums/IntentModelType.java @@ -5,4 +5,5 @@ public enum IntentModelType { USERNAME, POST, HASHTAG, + LOCATION } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/utils/Constants.java b/app/src/main/java/awais/instagrabber/utils/Constants.java index 595e964d..b51d2500 100755 --- a/app/src/main/java/awais/instagrabber/utils/Constants.java +++ b/app/src/main/java/awais/instagrabber/utils/Constants.java @@ -51,7 +51,7 @@ public final class Constants { "Instagram 152.0.0.25.117 Android (27/8.1.0; 320dpi; 720x1362; motorola; motorola one; deen_sprout; qcom; pt_BR; 234847224)"; public static final String I_USER_AGENT = "Instagram 152.0.0.25.117 Android (27/8.1.0; 320dpi; 720x1362; motorola; motorola one; deen_sprout; qcom; pt_BR; 234847224)"; - public static final String A_USER_AGENT = "InstaGrabber.AustinHuang.me / InstaGrabber@AustinHuang.me"; + public static final String A_USER_AGENT = "https://InstaGrabber.AustinHuang.me / mailto:InstaGrabber@AustinHuang.me"; // see https://github.com/dilame/instagram-private-api/blob/master/src/core/constants.ts public static final String SUPPORTED_CAPABILITIES = "[ { \"name\": \"SUPPORTED_SDK_VERSIONS\", \"value\":" + " \"13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0," + diff --git a/app/src/main/java/awais/instagrabber/utils/FlavorTown.java b/app/src/main/java/awais/instagrabber/utils/FlavorTown.java index f5a61259..70e35055 100755 --- a/app/src/main/java/awais/instagrabber/utils/FlavorTown.java +++ b/app/src/main/java/awais/instagrabber/utils/FlavorTown.java @@ -36,7 +36,7 @@ public final class FlavorTown { .setNegativeButton(R.string.action_github, (dialog, which) -> { try { context.startActivity(new Intent(Intent.ACTION_VIEW).setData( - Uri.parse("https://github.com/austinhuang0131/instagrabber/releases/tag/" + version))); + Uri.parse("https://github.com/austinhuang0131/instagrabber/releases/latest"))); } catch (final ActivityNotFoundException e) { // do nothing } diff --git a/app/src/main/java/awais/instagrabber/utils/UpdateChecker.java b/app/src/main/java/awais/instagrabber/utils/UpdateChecker.java index ceb28a31..0bde36bc 100755 --- a/app/src/main/java/awais/instagrabber/utils/UpdateChecker.java +++ b/app/src/main/java/awais/instagrabber/utils/UpdateChecker.java @@ -22,44 +22,23 @@ public final class UpdateChecker extends AsyncTask { @NonNull @Override protected Boolean doInBackground(final Void... voids) { - final String UPDATE_BASE_URL = "https://github.com/austinhuang0131/instagrabber/releases/tag/"; - final String versionName = BuildConfig.VERSION_NAME; - final int index = versionName.indexOf('.'); - try { - final int verMajor = Integer.parseInt(versionName.substring(0, index)); + version = ""; - version = "v" + (verMajor + 1) + ".0"; - - // check major version first - HttpURLConnection conn = (HttpURLConnection) new URL(UPDATE_BASE_URL + version).openConnection(); + HttpURLConnection conn = + (HttpURLConnection) new URL("https://github.com/austinhuang0131/instagrabber/releases/latest").openConnection(); conn.setUseCaches(false); - conn.setRequestMethod("HEAD"); + conn.setInstanceFollowRedirects(false); + conn.setRequestProperty("User-Agent", Constants.A_USER_AGENT); conn.connect(); final int responseCode = conn.getResponseCode(); - conn.disconnect(); - - if (responseCode == HttpURLConnection.HTTP_OK) return true; - else { - final String substring = versionName.substring(index + 1); - final int verMinor = Integer.parseInt(substring) + 1; - - for (int i = verMinor; i < 10; ++i) { - version = "v" + verMajor + '.' + i; - conn.disconnect(); - - conn = (HttpURLConnection) new URL(UPDATE_BASE_URL + version).openConnection(); - conn.setUseCaches(false); - conn.setRequestMethod("HEAD"); - conn.connect(); - - if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { - conn.disconnect(); - return true; - } - } + if (responseCode == HttpURLConnection.HTTP_MOVED_TEMP) { + version = conn.getHeaderField("Location").split("/v")[1]; + return Float.parseFloat(version) > Float.parseFloat(BuildConfig.VERSION_NAME); } + + conn.disconnect(); } catch (final Exception e) { if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); } @@ -70,6 +49,6 @@ public final class UpdateChecker extends AsyncTask { @Override protected void onPostExecute(final Boolean result) { if (result != null && result && fetchListener != null) - fetchListener.onResult(version); + fetchListener.onResult("v"+version); } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/utils/Utils.java b/app/src/main/java/awais/instagrabber/utils/Utils.java index 27a02fdd..74fbf7db 100755 --- a/app/src/main/java/awais/instagrabber/utils/Utils.java +++ b/app/src/main/java/awais/instagrabber/utils/Utils.java @@ -175,12 +175,18 @@ public final class Utils { clipString = clipString.substring((isHttps ? 22 : 21) + wwwDel); final char firstChar = clipString.charAt(0); - if ((firstChar == 'p' || firstChar == 'P') && clipString.charAt(1) == '/') { - clipString = clipString.substring(2); + if (clipString.startsWith("p/") || clipString.startsWith("reel/")) { + clipString = clipString.substring(clipString.startsWith("p/") ? 2 : 5); type = IntentModelType.POST; } else if (clipString.startsWith("explore/tags/")) { clipString = clipString.substring(13); type = IntentModelType.HASHTAG; + } else if (clipString.startsWith("explore/locations/")) { + clipString = clipString.substring(18); + type = IntentModelType.LOCATION; + } else if (clipString.startsWith("_u/")) { // usually exists in embeds + clipString = clipString.substring(3); + type = IntentModelType.USERNAME; } clipString = cleanString(clipString); @@ -195,7 +201,8 @@ public final class Utils { if (clipString.charAt(clipLen) == '/') clipString = clipString.substring(0, clipLen); - return new IntentModel(type, clipString); + if (!clipString.contains("/")) return new IntentModel(type, clipString); + else return null; } @NonNull