Browse Source

date is locale not post, also post settings title

renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
parent
commit
1568b42d0d
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 45
      app/src/main/java/awais/instagrabber/fragments/settings/LocalePreferencesFragment.java
  2. 45
      app/src/main/java/awais/instagrabber/fragments/settings/PostPreferencesFragment.java
  3. 2
      app/src/main/res/navigation/more_nav_graph.xml

45
app/src/main/java/awais/instagrabber/fragments/settings/LocalePreferencesFragment.java

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

45
app/src/main/java/awais/instagrabber/fragments/settings/PostPreferencesFragment.java

@ -7,13 +7,8 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreferenceCompat; import androidx.preference.SwitchPreferenceCompat;
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.Utils;
import static awais.instagrabber.utils.Utils.settingsHelper; import static awais.instagrabber.utils.Utils.settingsHelper;
@ -25,7 +20,6 @@ public class PostPreferencesFragment extends BasePreferencesFragment {
// generalCategory.addPreference(getAutoPlayVideosPreference(context)); // generalCategory.addPreference(getAutoPlayVideosPreference(context));
screen.addPreference(getAlwaysMuteVideosPreference(context)); screen.addPreference(getAlwaysMuteVideosPreference(context));
screen.addPreference(getShowCaptionPreference(context)); screen.addPreference(getShowCaptionPreference(context));
screen.addPreference(getPostTimeFormatPreference(context));
} }
private Preference getAutoPlayVideosPreference(@NonNull final Context context) { private Preference getAutoPlayVideosPreference(@NonNull final Context context) {
@ -52,43 +46,4 @@ public class PostPreferencesFragment extends BasePreferencesFragment {
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
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;
}
} }

2
app/src/main/res/navigation/more_nav_graph.xml

@ -148,5 +148,5 @@
<fragment <fragment
android:id="@+id/postPreferencesFragment" android:id="@+id/postPreferencesFragment"
android:name="awais.instagrabber.fragments.settings.PostPreferencesFragment" android:name="awais.instagrabber.fragments.settings.PostPreferencesFragment"
android:label="PostPreferencesFragment" />
android:label="@string/pref_category_post" />
</navigation> </navigation>
Loading…
Cancel
Save