1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 05:16:58 +00:00

Merge branch 'master' into pr/170

This commit is contained in:
Austin Huang 2020-09-19 22:54:52 -04:00
commit f9f3d4620b
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
7 changed files with 86 additions and 103 deletions

View File

@ -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"
]
},

View File

@ -47,15 +47,15 @@ Prominent contributors are listed here in the [all-contributors](https://allcont
<tr>
<td align="center"><a href="https://austinhuang.me"><img src="https://avatars1.githubusercontent.com/u/16656689?s=100" width="100px;" alt=""/><br /><sub><b>Austin Huang</b></sub></a><br /><a href="https://github.com/austinhuang0131/instagrabber/commits?author=austinhuang0131" title="Code">💻</a> <a href="https://github.com/austinhuang0131/instagrabber/commits?author=austinhuang0131" title="Documentation">📖</a> <a href="#question-austinhuang0131" title="Answering Questions">💬</a> <a href="#translation-austinhuang0131" title="Translation">🌍</a> <a href="#ideas-austinhuang0131" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/ammargitham"><img src="https://avatars0.githubusercontent.com/u/8017365?s=100" width="100px;" alt=""/><br /><sub><b>Ammar Githam</b></sub></a><br /><a href="https://github.com/austinhuang0131/instagrabber/commits?author=ammargitham" title="Code">💻</a> <a href="#design-ammargitham" title="Design">🎨</a> <a href="#ideas-ammargitham" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-ammargitham" title="Maintenance">🚧</a> <a href="#question-ammargitham" title="Answering Questions">💬</a></td>
<td align="center"><a href="https://github.com/andersonvom"><img src="https://avatars3.githubusercontent.com/u/69922?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Anderson Mesquita</b></sub></a><br /><a href="https://github.com/austinhuang0131/instagrabber/commits?author=andersonvom" title="Code">💻</a> <a href="https://github.com/austinhuang0131/instagrabber/issues?q=author%3Aandersonvom" title="Bug reports">🐛</a></td>
<td align="center"><a href="http://rerolledgeek.blogspot.com/"><img src="https://avatars3.githubusercontent.com/u/5278488?s=100" width="100px;" alt=""/><br /><sub><b>AWAiS</b></sub></a><br /><a href="https://github.com/austinhuang0131/instagrabber/commits?author=AwaisKing" title="Code">💻</a> <a href="#ideas-AwaisKing" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://stefannajdovski.com/"><img src="https://avatars2.githubusercontent.com/u/42580385?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stefan Najdovski</b></sub></a><br /><a href="#design-snajdovski" title="Design">🎨</a></td>
<td align="center"><a href="http://aypie.design/"><img src="https://avatars3.githubusercontent.com/u/57075012?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alex Potterson</b></sub></a><br /><a href="#design-aypie" title="Design">🎨</a></td>
<td align="center"><a href="https://stefannajdovski.com/"><img src="https://avatars2.githubusercontent.com/u/42580385?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stefan Najdovski</b></sub></a><br /><a href="#design-snajdovski" title="Design">🎨</a> <a href="#translation-snajdovski" title="Translation">🌍</a></td>
<td align="center"><a href="http://kevinthomas.dev"><img src="https://avatars2.githubusercontent.com/u/15370181?s=100" width="100px;" alt=""/><br /><sub><b>Kevin Thomas</b></sub></a><br /><a href="#financial-KevinNThomas" title="Financial">💵</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/Shadowspear123"><img src="https://avatars1.githubusercontent.com/u/50462281?s=100" width="100px;" alt=""/><br /><sub><b>Shadowspear123</b></sub></a><br /><a href="#blog-Shadowspear123" title="Blogposts">📝</a> <a href="https://github.com/austinhuang0131/instagrabber/issues?q=author%3AShadowspear123" title="Bug reports">🐛</a> <a href="#ideas-Shadowspear123" title="Ideas, Planning, & Feedback">🤔</a> <a href="#question-Shadowspear123" title="Answering Questions">💬</a> <a href="#userTesting-Shadowspear123" title="User Testing">📓</a></td>
<td align="center"><a href="https://airikr.me/"><img src="https://avatars0.githubusercontent.com/u/53869451?s=100" width="100px;" alt=""/><br /><sub><b>Airikr</b></sub></a><br /><a href="#question-e-edgren" title="Answering Questions">💬</a> <a href="#ideas-e-edgren" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/Galang23"><img src="https://avatars3.githubusercontent.com/u/13700948?s=100" width="100px;" alt=""/><br /><sub><b>Galang23</b></sub></a><br /><a href="#question-Galang23" title="Answering Questions">💬</a> <a href="#translation-Galang23" title="Translation">🌍</a></td>
<td align="center"><a href="https://github.com/Galang23"><img src="https://avatars3.githubusercontent.com/u/13700948?s=100" width="100px;" alt=""/><br /><sub><b>Galang23</b></sub></a><br /><a href="#translation-Galang23" title="Translation">🌍</a></td>
<td align="center"><a href="https://github.com/farzadx"><img src="https://avatars2.githubusercontent.com/u/70059397?v=4?s=100" width="100px;" alt=""/><br /><sub><b>farzadx</b></sub></a><br /><a href="#translation-farzadx" title="Translation">🌍</a></td>
<td align="center"><a href="https://becauseofprog.fr/"><img src="https://avatars3.githubusercontent.com/u/24623168?s=100" width="100px;" alt=""/><br /><sub><b>kernoeb</b></sub></a><br /><a href="#translation-kernoeb" title="Translation">🌍</a></td>
<td align="center"><a href="https://github.com/Lego8486"><img src="https://avatars1.githubusercontent.com/u/47414485?s=100" width="100px;" alt=""/><br /><sub><b>Ten_Lego</b></sub></a><br /><a href="#translation-Lego8486" title="Translation">🌍</a></td>

View File

@ -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

View File

@ -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()));
}

View File

@ -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";

View File

@ -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;
}
public static String getUserIdFromCookie(final String cookies) {
return getCookieValue(cookies, "ds_user_id");
}
@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 null;
}
public static String getCsrfTokenFromCookie(final String cookie) {
if (cookie == null) {
return null;
@Nullable
public static String getCookie(@Nullable final String webViewUrl) {
final List<String> 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/"
);
if (!TextUtils.isEmpty(webViewUrl)) {
domains.add(0, webViewUrl);
}
return cookie.split("csrftoken=")[1].split(";")[0];
return getLongestCookie(domains);
}
@Nullable
public static String getCookie(@Nullable final String webViewUrl) {
int lastLongestCookieLength = 0;
String mainCookie = null;
private static String getLongestCookie(final List<String> domains) {
int longestLength = 0;
String longestCookie = null;
String cookie;
if (!TextUtils.isEmpty(webViewUrl)) {
cookie = COOKIE_MANAGER.getCookie(webViewUrl);
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;
}
}

View File

@ -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})