|
@ -7,10 +7,15 @@ import androidx.preference.ListPreference; |
|
|
import androidx.preference.Preference; |
|
|
import androidx.preference.Preference; |
|
|
import androidx.preference.PreferenceScreen; |
|
|
import androidx.preference.PreferenceScreen; |
|
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
|
import awais.instagrabber.R; |
|
|
import awais.instagrabber.R; |
|
|
|
|
|
import awais.instagrabber.dialogs.TimeSettingsDialog; |
|
|
import awais.instagrabber.utils.Constants; |
|
|
import awais.instagrabber.utils.Constants; |
|
|
import awais.instagrabber.utils.LocaleUtils; |
|
|
import awais.instagrabber.utils.LocaleUtils; |
|
|
import awais.instagrabber.utils.UserAgentUtils; |
|
|
import awais.instagrabber.utils.UserAgentUtils; |
|
|
|
|
|
import awais.instagrabber.utils.Utils; |
|
|
|
|
|
|
|
|
import static awais.instagrabber.utils.Utils.settingsHelper; |
|
|
import static awais.instagrabber.utils.Utils.settingsHelper; |
|
|
|
|
|
|
|
@ -20,6 +25,7 @@ public class LocalePreferencesFragment extends BasePreferencesFragment { |
|
|
final Context context = getContext(); |
|
|
final Context context = getContext(); |
|
|
if (context == null) return; |
|
|
if (context == null) return; |
|
|
screen.addPreference(getLanguagePreference(context)); |
|
|
screen.addPreference(getLanguagePreference(context)); |
|
|
|
|
|
screen.addPreference(getPostTimeFormatPreference(context)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private Preference getLanguagePreference(@NonNull final Context context) { |
|
|
private Preference getLanguagePreference(@NonNull final Context context) { |
|
@ -45,4 +51,43 @@ public class LocalePreferencesFragment extends BasePreferencesFragment { |
|
|
}); |
|
|
}); |
|
|
return preference; |
|
|
return preference; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Preference getPostTimeFormatPreference(@NonNull final Context context) { |
|
|
|
|
|
final Preference preference = new Preference(context); |
|
|
|
|
|
preference.setTitle(R.string.time_settings); |
|
|
|
|
|
preference.setSummary(Utils.datetimeParser.format(new Date())); |
|
|
|
|
|
preference.setIconSpaceReserved(false); |
|
|
|
|
|
preference.setOnPreferenceClickListener(preference1 -> { |
|
|
|
|
|
new TimeSettingsDialog( |
|
|
|
|
|
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, |
|
|
|
|
|
swapDateTime) -> { |
|
|
|
|
|
if (isCustomFormat) { |
|
|
|
|
|
settingsHelper.putString(Constants.CUSTOM_DATE_TIME_FORMAT, formatSelection); |
|
|
|
|
|
} else { |
|
|
|
|
|
final String formatSelectionUpdated = spTimeFormatSelectedItemPosition + ";" |
|
|
|
|
|
+ spSeparatorSelectedItemPosition + ';' |
|
|
|
|
|
+ spDateFormatSelectedItemPosition; // time;separator;date |
|
|
|
|
|
settingsHelper.putString(Constants.DATE_TIME_FORMAT, selectedFormat); |
|
|
|
|
|
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())); |
|
|
|
|
|
} |
|
|
|
|
|
).show(getParentFragmentManager(), null); |
|
|
|
|
|
return true; |
|
|
|
|
|
}); |
|
|
|
|
|
return preference; |
|
|
|
|
|
} |
|
|
} |
|
|
} |