1
0
Fork 0
mirror of https://github.com/KokaKiwi/BarInsta synced 2026-03-05 20:11:36 +00:00

Merge remote-tracking branch 'origin/task/add-favourites' into task/add-favourites

This commit is contained in:
Ammar Githam 2020-09-21 03:53:27 +09:00
commit 80b0cfa87f
33 changed files with 342 additions and 294 deletions

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

@ -29,12 +29,13 @@ public class AboutFragment extends BasePreferencesFragment {
final PreferenceCategory thirdPartyCategory = new PreferenceCategory(context);
screen.addPreference(thirdPartyCategory);
thirdPartyCategory.setTitle(R.string.about_category_3pt);
thirdPartyCategory.setSummary(R.string.about_category_3pt_summary);
//thirdPartyCategory.setSummary(R.string.about_category_3pt_summary);
thirdPartyCategory.setIconSpaceReserved(false);
// alphabetical order!!!
thirdPartyCategory.addPreference(getExoPlayerPreference());
thirdPartyCategory.addPreference(getFrescoPreference());
thirdPartyCategory.addPreference(getJsoupPreference());
thirdPartyCategory.addPreference(getMDIPreference());
thirdPartyCategory.addPreference(getRetrofitPreference());
final PreferenceCategory licenseCategory = new PreferenceCategory(context);
@ -157,6 +158,22 @@ public class AboutFragment extends BasePreferencesFragment {
return preference;
}
private Preference getMDIPreference() {
final Context context = getContext();
if (context == null) return null;
final Preference preference = new Preference(context);
preference.setTitle("Material Design Icons");
preference.setSummary("Copyright (C) 2014 Austin Andrews & Google LLC. Apache Version 2.0.");
preference.setIconSpaceReserved(false);
preference.setOnPreferenceClickListener(p -> {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://materialdesignicons.com/"));
startActivity(intent);
return true;
});
return preference;
}
private Preference getLicensePreference() {
final Context context = getContext();
if (context == null) return null;

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