diff --git a/.all-contributorsrc b/.all-contributorsrc
index 04d554bf..c0f4f8aa 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -31,6 +31,16 @@
"question"
]
},
+ {
+ "login": "andersonvom",
+ "name": "Anderson Mesquita",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/69922?v=4",
+ "profile": "https://github.com/andersonvom",
+ "contributions": [
+ "code",
+ "bug"
+ ]
+ },
{
"login": "AwaisKing",
"name": "AWAiS",
@@ -47,16 +57,8 @@
"avatar_url": "https://avatars2.githubusercontent.com/u/42580385?v=4",
"profile": "https://stefannajdovski.com/",
"contributions": [
- "design"
- ]
- },
- {
- "login": "aypie",
- "name": "Alex Potterson",
- "avatar_url": "https://avatars3.githubusercontent.com/u/57075012?v=4",
- "profile": "http://aypie.design/",
- "contributions": [
- "design"
+ "design",
+ "translation"
]
},
{
@@ -97,7 +99,6 @@
"avatar_url": "https://avatars3.githubusercontent.com/u/13700948",
"profile": "https://github.com/Galang23",
"contributions": [
- "question",
"translation"
]
},
diff --git a/README.md b/README.md
index 5982211b..d904bba3 100755
--- a/README.md
+++ b/README.md
@@ -47,15 +47,15 @@ Prominent contributors are listed here in the [all-contributors](https://allcont
Austin Huang 💻 📖 💬 🌍 🤔 |
Ammar Githam 💻 🎨 🤔 🚧 💬 |
+ Anderson Mesquita 💻 🐛 |
AWAiS 💻 🤔 |
- Stefan Najdovski 🎨 |
- Alex Potterson 🎨 |
+ Stefan Najdovski 🎨 🌍 |
Kevin Thomas 💵 |
Shadowspear123 📝 🐛 🤔 💬 📓 |
Airikr 💬 🤔 |
- Galang23 💬 🌍 |
+ Galang23 🌍 |
farzadx 🌍 |
kernoeb 🌍 |
Ten_Lego 🌍 |
diff --git a/app/src/main/java/awais/instagrabber/dialogs/TimeSettingsDialog.java b/app/src/main/java/awais/instagrabber/dialogs/TimeSettingsDialog.java
index 9a371db2..9958e59c 100755
--- a/app/src/main/java/awais/instagrabber/dialogs/TimeSettingsDialog.java
+++ b/app/src/main/java/awais/instagrabber/dialogs/TimeSettingsDialog.java
@@ -34,15 +34,18 @@ public final class TimeSettingsDialog extends DialogFragment implements AdapterV
private boolean customDateTimeFormatEnabled;
private String customDateTimeFormat;
private String dateTimeSelection;
+ private final boolean swapDateTimeEnabled;
private final OnConfirmListener onConfirmListener;
public TimeSettingsDialog(final boolean customDateTimeFormatEnabled,
final String customDateTimeFormat,
final String dateTimeSelection,
+ final boolean swapDateTimeEnabled,
final OnConfirmListener onConfirmListener) {
this.customDateTimeFormatEnabled = customDateTimeFormatEnabled;
this.customDateTimeFormat = customDateTimeFormat;
this.dateTimeSelection = dateTimeSelection;
+ this.swapDateTimeEnabled = swapDateTimeEnabled;
this.onConfirmListener = onConfirmListener;
final Calendar instance = GregorianCalendar.getInstance();
instance.set(2020, 5, 22, 8, 17, 13);
@@ -55,6 +58,7 @@ public final class TimeSettingsDialog extends DialogFragment implements AdapterV
timeSettingsBinding.cbCustomFormat.setOnCheckedChangeListener(this);
timeSettingsBinding.cbCustomFormat.setChecked(customDateTimeFormatEnabled);
+ timeSettingsBinding.cbSwapTimeDate.setChecked(swapDateTimeEnabled);
timeSettingsBinding.etCustomFormat.setText(customDateTimeFormat);
final String[] dateTimeFormat = dateTimeSelection.split(";"); // output = time;separator;date
@@ -86,11 +90,12 @@ public final class TimeSettingsDialog extends DialogFragment implements AdapterV
final String timeStr = String.valueOf(timeSettingsBinding.spTimeFormat.getSelectedItem());
final String dateStr = String.valueOf(timeSettingsBinding.spDateFormat.getSelectedItem());
- final boolean isSwapTime = !timeSettingsBinding.cbSwapTimeDate.isChecked();
+ final boolean isSwapTime = timeSettingsBinding.cbSwapTimeDate.isChecked();
+ final boolean isBlankSeparator = timeSettingsBinding.spSeparator.getSelectedItemPosition() <= 0;
- selectedFormat = (isSwapTime ? timeStr : dateStr)
- + (TextUtils.isEmpty(sepStr) || timeSettingsBinding.spSeparator.getSelectedItemPosition() == 0 ? " " : " '" + sepStr + "' ")
- + (isSwapTime ? dateStr : timeStr);
+ selectedFormat = (isSwapTime ? dateStr : timeStr)
+ + (isBlankSeparator ? " " : " '" + sepStr + "' ")
+ + (isSwapTime ? timeStr : dateStr);
timeSettingsBinding.btnConfirm.setEnabled(true);
currentFormat = new SimpleDateFormat(selectedFormat, LocaleUtils.getCurrentLocale());
@@ -145,13 +150,15 @@ public final class TimeSettingsDialog extends DialogFragment implements AdapterV
if (v == timeSettingsBinding.btnConfirm) {
final Editable etCustomFormatText = timeSettingsBinding.etCustomFormat.getText();
if (onConfirmListener != null) {
- onConfirmListener.onConfirm(timeSettingsBinding.cbCustomFormat.isChecked(),
+ onConfirmListener.onConfirm(
+ timeSettingsBinding.cbCustomFormat.isChecked(),
etCustomFormatText == null ? null : etCustomFormatText.toString(),
timeSettingsBinding.spTimeFormat.getSelectedItemPosition(),
timeSettingsBinding.spSeparator.getSelectedItemPosition(),
timeSettingsBinding.spDateFormat.getSelectedItemPosition(),
selectedFormat,
- currentFormat);
+ currentFormat,
+ timeSettingsBinding.cbSwapTimeDate.isChecked());
}
dismiss();
} else if (v == timeSettingsBinding.btnInfo) {
@@ -166,7 +173,10 @@ public final class TimeSettingsDialog extends DialogFragment implements AdapterV
String formatSelection,
int spTimeFormatSelectedItemPosition,
int spSeparatorSelectedItemPosition,
- int spDateFormatSelectedItemPosition, final String selectedFormat, final SimpleDateFormat currentFormat);
+ int spDateFormatSelectedItemPosition,
+ final String selectedFormat,
+ final SimpleDateFormat currentFormat,
+ final boolean swapDateTime);
}
@Override
diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java
index 7e108b17..ba3abc9c 100644
--- a/app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java
+++ b/app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java
@@ -284,12 +284,15 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
settingsHelper.getBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED),
settingsHelper.getString(Constants.CUSTOM_DATE_TIME_FORMAT),
settingsHelper.getString(Constants.DATE_TIME_SELECTION),
+ settingsHelper.getBoolean(Constants.SWAP_DATE_TIME_FORMAT_ENABLED),
(isCustomFormat,
formatSelection,
spTimeFormatSelectedItemPosition,
spSeparatorSelectedItemPosition,
spDateFormatSelectedItemPosition,
- selectedFormat, currentFormat) -> {
+ selectedFormat,
+ currentFormat,
+ swapDateTime) -> {
if (isCustomFormat) {
settingsHelper.putString(Constants.CUSTOM_DATE_TIME_FORMAT, formatSelection);
} else {
@@ -300,6 +303,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
settingsHelper.putString(Constants.DATE_TIME_SELECTION, formatSelectionUpdated);
}
settingsHelper.putBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED, isCustomFormat);
+ settingsHelper.putBoolean(Constants.SWAP_DATE_TIME_FORMAT_ENABLED, swapDateTime);
Utils.datetimeParser = (SimpleDateFormat) currentFormat.clone();
preference.setSummary(Utils.datetimeParser.format(new Date()));
}
diff --git a/app/src/main/java/awais/instagrabber/utils/Constants.java b/app/src/main/java/awais/instagrabber/utils/Constants.java
index 8719d711..a6be1da5 100644
--- a/app/src/main/java/awais/instagrabber/utils/Constants.java
+++ b/app/src/main/java/awais/instagrabber/utils/Constants.java
@@ -19,6 +19,7 @@ public final class Constants {
public static final String AUTOLOAD_POSTS = "autoload_posts";
public static final String SHOW_FEED = "show_feed";
public static final String CUSTOM_DATE_TIME_FORMAT_ENABLED = "data_time_custom_enabled";
+ public static final String SWAP_DATE_TIME_FORMAT_ENABLED = "swap_date_time_enabled";
public static final String MARK_AS_SEEN = "mark_as_seen";
public static final String DM_MARK_AS_SEEN = "dm_mark_as_seen";
public static final String INSTADP = "instadp";
diff --git a/app/src/main/java/awais/instagrabber/utils/CookieUtils.java b/app/src/main/java/awais/instagrabber/utils/CookieUtils.java
index e3e4f800..17c43e2b 100644
--- a/app/src/main/java/awais/instagrabber/utils/CookieUtils.java
+++ b/app/src/main/java/awais/instagrabber/utils/CookieUtils.java
@@ -10,6 +10,10 @@ import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import awais.instagrabber.BuildConfig;
import awaisomereport.LogCollector;
@@ -54,99 +58,61 @@ public final class CookieUtils {
}
@Nullable
- public static String getUserIdFromCookie(final String cookie) {
- if (!TextUtils.isEmpty(cookie)) {
- final int uidIndex = cookie.indexOf("ds_user_id=");
- if (uidIndex > 0) {
- String uid = cookie.split("ds_user_id=")[1].split(";")[0];
- return !TextUtils.isEmpty(uid) ? uid : null;
- }
- }
- return null;
+ public static String getUserIdFromCookie(final String cookies) {
+ return getCookieValue(cookies, "ds_user_id");
}
- public static String getCsrfTokenFromCookie(final String cookie) {
- if (cookie == null) {
- return null;
+ @Nullable
+ public static String getCsrfTokenFromCookie(final String cookies) {
+ return getCookieValue(cookies, "csrftoken");
+ }
+
+ @Nullable
+ private static String getCookieValue(final String cookies, final String name) {
+ final Pattern pattern = Pattern.compile(name + "=(.+?);");
+ final Matcher matcher = pattern.matcher(cookies);
+ if (matcher.find()) {
+ return matcher.group(1);
}
- return cookie.split("csrftoken=")[1].split(";")[0];
+ return null;
}
@Nullable
public static String getCookie(@Nullable final String webViewUrl) {
- int lastLongestCookieLength = 0;
- String mainCookie = null;
+ final List domains = Arrays.asList(
+ "https://instagram.com",
+ "https://instagram.com/",
+ "http://instagram.com",
+ "http://instagram.com",
+ "https://www.instagram.com",
+ "https://www.instagram.com/",
+ "http://www.instagram.com",
+ "http://www.instagram.com/"
+ );
- String cookie;
if (!TextUtils.isEmpty(webViewUrl)) {
- cookie = COOKIE_MANAGER.getCookie(webViewUrl);
+ domains.add(0, webViewUrl);
+ }
+
+ return getLongestCookie(domains);
+ }
+
+ @Nullable
+ private static String getLongestCookie(final List domains) {
+ int longestLength = 0;
+ String longestCookie = null;
+
+ for (final String domain : domains) {
+ final String cookie = COOKIE_MANAGER.getCookie(domain);
if (cookie != null) {
- final int cookieLen = cookie.length();
- if (cookieLen > lastLongestCookieLength) {
- mainCookie = cookie;
- lastLongestCookieLength = cookieLen;
+ final int cookieLength = cookie.length();
+ if (cookieLength > longestLength) {
+ longestCookie = cookie;
+ longestLength = cookieLength;
}
}
}
- cookie = COOKIE_MANAGER.getCookie("https://instagram.com");
- if (cookie != null) {
- final int cookieLen = cookie.length();
- if (cookieLen > lastLongestCookieLength) {
- mainCookie = cookie;
- lastLongestCookieLength = cookieLen;
- }
- }
- cookie = COOKIE_MANAGER.getCookie("https://instagram.com/");
- if (cookie != null) {
- final int cookieLen = cookie.length();
- if (cookieLen > lastLongestCookieLength) {
- mainCookie = cookie;
- lastLongestCookieLength = cookieLen;
- }
- }
- cookie = COOKIE_MANAGER.getCookie("http://instagram.com");
- if (cookie != null) {
- final int cookieLen = cookie.length();
- if (cookieLen > lastLongestCookieLength) {
- mainCookie = cookie;
- lastLongestCookieLength = cookieLen;
- }
- }
- cookie = COOKIE_MANAGER.getCookie("http://instagram.com/");
- if (cookie != null) {
- final int cookieLen = cookie.length();
- if (cookieLen > lastLongestCookieLength) {
- mainCookie = cookie;
- lastLongestCookieLength = cookieLen;
- }
- }
- cookie = COOKIE_MANAGER.getCookie("https://www.instagram.com");
- if (cookie != null) {
- final int cookieLen = cookie.length();
- if (cookieLen > lastLongestCookieLength) {
- mainCookie = cookie;
- lastLongestCookieLength = cookieLen;
- }
- }
- cookie = COOKIE_MANAGER.getCookie("https://www.instagram.com/");
- if (cookie != null) {
- final int cookieLen = cookie.length();
- if (cookieLen > lastLongestCookieLength) {
- mainCookie = cookie;
- lastLongestCookieLength = cookieLen;
- }
- }
- cookie = COOKIE_MANAGER.getCookie("http://www.instagram.com");
- if (cookie != null) {
- final int cookieLen = cookie.length();
- if (cookieLen > lastLongestCookieLength) {
- mainCookie = cookie;
- lastLongestCookieLength = cookieLen;
- }
- }
- cookie = COOKIE_MANAGER.getCookie("http://www.instagram.com/");
- if (cookie != null && cookie.length() > lastLongestCookieLength) mainCookie = cookie;
- return mainCookie;
+ return longestCookie;
}
}
diff --git a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java
index a62dc9a8..aa39823e 100755
--- a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java
+++ b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java
@@ -34,6 +34,7 @@ import static awais.instagrabber.utils.Constants.PREV_INSTALL_VERSION;
import static awais.instagrabber.utils.Constants.SHOW_QUICK_ACCESS_DIALOG;
import static awais.instagrabber.utils.Constants.SKIPPED_VERSION;
import static awais.instagrabber.utils.Constants.STORY_VIEWER;
+import static awais.instagrabber.utils.Constants.SWAP_DATE_TIME_FORMAT_ENABLED;
public final class SettingsHelper {
private final SharedPreferences sharedPreferences;
@@ -118,7 +119,7 @@ public final class SettingsHelper {
@StringDef({DOWNLOAD_USER_FOLDER, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, SHOW_QUICK_ACCESS_DIALOG, MUTED_VIDEOS,
AUTOLOAD_POSTS, CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, DM_MARK_AS_SEEN, INSTADP,
- CHECK_ACTIVITY, CHECK_UPDATES})
+ CHECK_ACTIVITY, CHECK_UPDATES, SWAP_DATE_TIME_FORMAT_ENABLED})
public @interface BooleanSettings {}
@StringDef({PREV_INSTALL_VERSION})