From fdacd1b4210725500b8dd01f83a34b0fa07d1075 Mon Sep 17 00:00:00 2001 From: stamatiap Date: Fri, 30 Apr 2021 16:49:42 +0300 Subject: [PATCH 01/17] add alert dialog for swipe up link - issue #1101 --- .../fragments/StoryViewerFragment.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index a170a8a0..c6788dfa 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -3,6 +3,7 @@ package awais.instagrabber.fragments; import android.annotation.SuppressLint; import android.content.Context; import android.content.pm.PackageManager; +import android.content.DialogInterface; import android.graphics.drawable.Animatable; import android.net.Uri; import android.os.Bundle; @@ -442,10 +443,30 @@ public class StoryViewerFragment extends Fragment { } }); binding.swipeUp.setOnClickListener(v -> { - final Object tag = v.getTag(); - if (tag instanceof CharSequence) { - Utils.openURL(context, tag.toString()); - } + final Object tag = v.getTag(); + if (tag instanceof CharSequence) { + DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which){ + case DialogInterface.BUTTON_POSITIVE: + //Yes button clicked + Utils.openURL(context, tag.toString()); + break; + + case DialogInterface.BUTTON_NEGATIVE: + //No button clicked + dialog.dismiss(); + break; + } + } + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Are you sure you want to open this link?"); + builder.setMessage(tag.toString()).setPositiveButton("Yes", dialogClickListener) + .setNegativeButton("No", dialogClickListener).show(); + } }); binding.viewStoryPost.setOnClickListener(v -> { final Object tag = v.getTag(); From 1f61926108e25a955cbf5619861d06821c9af9a6 Mon Sep 17 00:00:00 2001 From: stamatiap Date: Sat, 1 May 2021 10:39:27 +0300 Subject: [PATCH 02/17] add default case to switch statement - issue #1101 --- .../awais/instagrabber/fragments/StoryViewerFragment.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index c6788dfa..9a02816f 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -458,6 +458,10 @@ public class StoryViewerFragment extends Fragment { //No button clicked dialog.dismiss(); break; + + default: + dialog.dismiss(); + break; } } }; From 13b747fc872ca9d706d24532ea698d33e2d82893 Mon Sep 17 00:00:00 2001 From: stamatiap Date: Mon, 10 May 2021 21:47:29 +0300 Subject: [PATCH 03/17] add string for swipe up link confirmation --- app/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8cc84a91..4253f02b 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -503,4 +503,5 @@ Recent Clear No Map app found! + Are you sure you want to open this link? From 38b7f29d449d13234bd66e3c9906b0b34b06c5b7 Mon Sep 17 00:00:00 2001 From: stamatiap Date: Mon, 10 May 2021 21:48:25 +0300 Subject: [PATCH 04/17] update alert dialog title --- .../java/awais/instagrabber/fragments/StoryViewerFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 9a02816f..55497989 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -467,7 +467,7 @@ public class StoryViewerFragment extends Fragment { }; AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle("Are you sure you want to open this link?"); + builder.setTitle(R.string.swipe_up_confirmation); builder.setMessage(tag.toString()).setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show(); } From 407f0680c1a662f56c8dd7879d5fc73fe0411df9 Mon Sep 17 00:00:00 2001 From: stamatiap Date: Sun, 16 May 2021 10:00:16 +0300 Subject: [PATCH 05/17] make changes in dialog --- .../fragments/StoryViewerFragment.java | 31 +++---------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 55497989..e40f445d 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -445,32 +445,11 @@ public class StoryViewerFragment extends Fragment { binding.swipeUp.setOnClickListener(v -> { final Object tag = v.getTag(); if (tag instanceof CharSequence) { - DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which){ - case DialogInterface.BUTTON_POSITIVE: - //Yes button clicked - Utils.openURL(context, tag.toString()); - break; - - case DialogInterface.BUTTON_NEGATIVE: - //No button clicked - dialog.dismiss(); - break; - - default: - dialog.dismiss(); - break; - } - } - }; - - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(R.string.swipe_up_confirmation); - builder.setMessage(tag.toString()).setPositiveButton("Yes", dialogClickListener) - .setNegativeButton("No", dialogClickListener).show(); - } + new AlertDialog.Builder(context) + .setTitle(R.string.swipe_up_confirmation) + .setMessage(tag.toString()).setPositiveButton(R.string.yes, (d, w) -> Utils.openURL(context, tag.toString())) + .setNegativeButton(R.string.no, (d, w) -> d.dismiss()).show(); + } }); binding.viewStoryPost.setOnClickListener(v -> { final Object tag = v.getTag(); From 85ac7478eb9e20d6f442c19ab940f064780adec9 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 14:48:23 -0400 Subject: [PATCH 06/17] fix string grammar --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8c59762e..676fe1da 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -235,7 +235,7 @@ Approve request Reject request Share this public post to… - This is a private post! Share to those who can view them! + This is a private post! Share to those who can view it. This category is somehow empty… An update is available! (%s) Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub. From ba0d51d0b62077698bf5e4288b1483dd27dbf98f Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 14:54:26 -0400 Subject: [PATCH 07/17] migrate preference keys --- .../instagrabber/InstaGrabberApplication.java | 7 +-- .../instagrabber/activities/MainActivity.java | 6 +-- .../viewholder/SliderVideoViewHolder.java | 4 +- .../KeywordsFilterDialogViewHolder.java | 4 +- .../viewholder/feed/FeedVideoViewHolder.java | 4 +- .../customviews/PostsRecyclerView.java | 6 +-- .../dialogs/CreateBackupDialogFragment.java | 2 +- .../dialogs/KeywordsFilterDialog.java | 6 +-- .../dialogs/RestoreBackupDialogFragment.java | 2 +- .../fragments/PostViewV2Fragment.java | 6 +-- .../fragments/StoryViewerFragment.java | 7 +-- .../DirectMessageThreadFragment.java | 4 +- .../settings/BasePreferencesFragment.java | 2 +- .../settings/DMPreferencesFragment.java | 3 +- .../DownloadsPreferencesFragment.java | 11 ++--- .../settings/GeneralPreferencesFragment.java | 4 +- .../settings/LocalePreferencesFragment.java | 20 ++++---- .../NotificationsPreferencesFragment.java | 3 +- .../settings/PostPreferencesFragment.java | 9 ++-- .../fragments/settings/PreferenceKeys.java | 32 +++++++++++++ .../settings/StoriesPreferencesFragment.java | 7 ++- .../settings/ThemePreferencesFragment.java | 2 +- .../awais/instagrabber/utils/Constants.java | 32 ------------- .../instagrabber/utils/DownloadUtils.java | 13 ++--- .../awais/instagrabber/utils/LocaleUtils.java | 4 +- .../instagrabber/utils/SettingsHelper.java | 48 +++++++++---------- .../webservices/StoriesService.java | 6 +-- 27 files changed, 127 insertions(+), 127 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/InstaGrabberApplication.java b/app/src/main/java/awais/instagrabber/InstaGrabberApplication.java index 4dcc9dde..8bdedbbd 100644 --- a/app/src/main/java/awais/instagrabber/InstaGrabberApplication.java +++ b/app/src/main/java/awais/instagrabber/InstaGrabberApplication.java @@ -13,6 +13,7 @@ import java.net.CookieHandler; import java.text.SimpleDateFormat; import java.util.UUID; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.LocaleUtils; import awais.instagrabber.utils.SettingsHelper; @@ -82,9 +83,9 @@ public final class InstaGrabberApplication extends Application { if (datetimeParser == null) datetimeParser = new SimpleDateFormat( - settingsHelper.getBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED) ? - settingsHelper.getString(Constants.CUSTOM_DATE_TIME_FORMAT) : - settingsHelper.getString(Constants.DATE_TIME_FORMAT), LocaleUtils.getCurrentLocale()); + settingsHelper.getBoolean(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT_ENABLED) ? + settingsHelper.getString(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT) : + settingsHelper.getString(PreferenceKeys.DATE_TIME_FORMAT), LocaleUtils.getCurrentLocale()); if (TextUtils.isEmpty(settingsHelper.getString(Constants.DEVICE_UUID))) { settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString()); diff --git a/app/src/main/java/awais/instagrabber/activities/MainActivity.java b/app/src/main/java/awais/instagrabber/activities/MainActivity.java index 00bc847d..8879b05c 100644 --- a/app/src/main/java/awais/instagrabber/activities/MainActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/MainActivity.java @@ -141,7 +141,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage instance = this; binding = ActivityMainBinding.inflate(getLayoutInflater()); setupCookie(); - if (settingsHelper.getBoolean(Constants.FLAG_SECURE)) { + if (settingsHelper.getBoolean(PreferenceKeys.FLAG_SECURE)) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); } setContentView(binding.getRoot()); @@ -166,14 +166,14 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage setupBottomNavigationBar(true); } if (!BuildConfig.isPre) { - final boolean checkUpdates = settingsHelper.getBoolean(Constants.CHECK_UPDATES); + final boolean checkUpdates = settingsHelper.getBoolean(PreferenceKeys.CHECK_UPDATES); if (checkUpdates) FlavorTown.updateCheck(this); } FlavorTown.changelogCheck(this); new ViewModelProvider(this).get(AppStateViewModel.class); // Just initiate the App state here final Intent intent = getIntent(); handleIntent(intent); - if (isLoggedIn && settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) { + if (isLoggedIn && settingsHelper.getBoolean(PreferenceKeys.CHECK_ACTIVITY)) { bindActivityCheckerService(); } getSupportFragmentManager().addOnBackStackChangedListener(this); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/SliderVideoViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/SliderVideoViewHolder.java index 3624d7ef..8f6226ef 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/SliderVideoViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/SliderVideoViewHolder.java @@ -15,9 +15,9 @@ import awais.instagrabber.adapters.SliderItemsAdapter; import awais.instagrabber.customviews.VideoPlayerCallbackAdapter; import awais.instagrabber.customviews.VideoPlayerViewHelper; import awais.instagrabber.databinding.LayoutVideoPlayerWithThumbnailBinding; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.VideoVersion; -import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.NumberUtils; import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.Utils; @@ -55,7 +55,7 @@ public class SliderVideoViewHolder extends SliderItemViewHolder { public void bind(@NonNull final Media media, final int position, final SliderItemsAdapter.SliderCallback sliderCallback) { - final float vol = settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f; + final float vol = settingsHelper.getBoolean(PreferenceKeys.MUTED_VIDEOS) ? 0f : 1f; final VideoPlayerViewHelper.VideoPlayerCallback videoPlayerCallback = new VideoPlayerCallbackAdapter() { @Override diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/dialogs/KeywordsFilterDialogViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/dialogs/KeywordsFilterDialogViewHolder.java index 65fe7b77..9930be59 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/dialogs/KeywordsFilterDialogViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/dialogs/KeywordsFilterDialogViewHolder.java @@ -14,7 +14,7 @@ import java.util.HashSet; import awais.instagrabber.R; import awais.instagrabber.adapters.KeywordsFilterAdapter; -import awais.instagrabber.utils.Constants; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.utils.SettingsHelper; public class KeywordsFilterDialogViewHolder extends RecyclerView.ViewHolder { @@ -34,7 +34,7 @@ public class KeywordsFilterDialogViewHolder extends RecyclerView.ViewHolder { final String s = items.get(position); SettingsHelper settingsHelper = new SettingsHelper(context); items.remove(position); - settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items)); + settingsHelper.putStringSet(PreferenceKeys.KEYWORD_FILTERS, new HashSet<>(items)); adapter.notifyDataSetChanged(); final String message = context.getString(R.string.removed_keywords, s); Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedVideoViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedVideoViewHolder.java index 3d56551b..e94af79b 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedVideoViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedVideoViewHolder.java @@ -18,9 +18,9 @@ import awais.instagrabber.adapters.FeedAdapterV2; import awais.instagrabber.customviews.VideoPlayerCallbackAdapter; import awais.instagrabber.customviews.VideoPlayerViewHelper; import awais.instagrabber.databinding.ItemFeedVideoBinding; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.VideoVersion; -import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.NumberUtils; import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.Utils; @@ -65,7 +65,7 @@ public class FeedVideoViewHolder extends FeedItemViewHolder { // Log.d(TAG, "Binding post: " + feedModel.getPostId()); this.media = media; binding.itemFeedBottom.tvVideoViews.setText(String.valueOf(media.getViewCount())); - final float vol = settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f; + final float vol = settingsHelper.getBoolean(PreferenceKeys.MUTED_VIDEOS) ? 0f : 1f; final VideoPlayerViewHelper.VideoPlayerCallback videoPlayerCallback = new VideoPlayerCallbackAdapter() { @Override diff --git a/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java b/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java index 2e008a18..ace25beb 100644 --- a/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java +++ b/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java @@ -33,10 +33,10 @@ import awais.instagrabber.adapters.FeedAdapterV2; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.customviews.helpers.PostFetcher; import awais.instagrabber.customviews.helpers.RecyclerLazyLoaderAtEdge; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.models.PostsLayoutPreferences; import awais.instagrabber.repositories.responses.Media; -import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.KeywordsFilterUtils; import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.Utils; @@ -81,8 +81,8 @@ public class PostsRecyclerView extends RecyclerView { } final List models = mediaViewModel.getList().getValue(); final List modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models); - if (settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)) { - final ArrayList items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS)); + if (settingsHelper.getBoolean(PreferenceKeys.TOGGLE_KEYWORD_FILTER)) { + final ArrayList items = new ArrayList<>(settingsHelper.getStringSet(PreferenceKeys.KEYWORD_FILTERS)); modelsCopy.addAll(new KeywordsFilterUtils(items).filter(result)); } else { modelsCopy.addAll(result); diff --git a/app/src/main/java/awais/instagrabber/dialogs/CreateBackupDialogFragment.java b/app/src/main/java/awais/instagrabber/dialogs/CreateBackupDialogFragment.java index f612b72c..68f895e0 100644 --- a/app/src/main/java/awais/instagrabber/dialogs/CreateBackupDialogFragment.java +++ b/app/src/main/java/awais/instagrabber/dialogs/CreateBackupDialogFragment.java @@ -29,7 +29,7 @@ import awais.instagrabber.utils.ExportImportUtils; import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.Utils; -import static awais.instagrabber.utils.Constants.FOLDER_PATH; +import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_PATH; import static awais.instagrabber.utils.DownloadUtils.PERMS; public class CreateBackupDialogFragment extends DialogFragment { diff --git a/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java b/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java index 2a4d8a04..5997371c 100644 --- a/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java +++ b/app/src/main/java/awais/instagrabber/dialogs/KeywordsFilterDialog.java @@ -22,7 +22,7 @@ import java.util.HashSet; import awais.instagrabber.R; import awais.instagrabber.adapters.KeywordsFilterAdapter; import awais.instagrabber.databinding.DialogKeywordsFilterBinding; -import awais.instagrabber.utils.Constants; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.utils.SettingsHelper; import awais.instagrabber.utils.Utils; @@ -54,7 +54,7 @@ public final class KeywordsFilterDialog extends DialogFragment { recyclerView.setLayoutManager(linearLayoutManager); final SettingsHelper settingsHelper = new SettingsHelper(context); - final ArrayList items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS)); + final ArrayList items = new ArrayList<>(settingsHelper.getStringSet(PreferenceKeys.KEYWORD_FILTERS)); final KeywordsFilterAdapter adapter = new KeywordsFilterAdapter(context, items); recyclerView.setAdapter(adapter); @@ -68,7 +68,7 @@ public final class KeywordsFilterDialog extends DialogFragment { return; } items.add(s.toLowerCase()); - settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items)); + settingsHelper.putStringSet(PreferenceKeys.KEYWORD_FILTERS, new HashSet<>(items)); adapter.notifyItemInserted(items.size()); final String message = context.getString(R.string.added_keywords, s); Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/awais/instagrabber/dialogs/RestoreBackupDialogFragment.java b/app/src/main/java/awais/instagrabber/dialogs/RestoreBackupDialogFragment.java index 7967b9e2..7ab5f0fd 100644 --- a/app/src/main/java/awais/instagrabber/dialogs/RestoreBackupDialogFragment.java +++ b/app/src/main/java/awais/instagrabber/dialogs/RestoreBackupDialogFragment.java @@ -28,7 +28,7 @@ import awais.instagrabber.utils.PasswordUtils.IncorrectPasswordException; import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.Utils; -import static awais.instagrabber.utils.Constants.FOLDER_PATH; +import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_PATH; import static awais.instagrabber.utils.DownloadUtils.PERMS; public class RestoreBackupDialogFragment extends DialogFragment { diff --git a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java index 35249824..001ce340 100644 --- a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java @@ -82,6 +82,7 @@ import awais.instagrabber.databinding.DialogPostViewBinding; import awais.instagrabber.databinding.LayoutPostViewBottomBinding; import awais.instagrabber.databinding.LayoutVideoPlayerWithThumbnailBinding; import awais.instagrabber.dialogs.EditTextDialogFragment; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.models.Resource; import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.repositories.responses.Caption; @@ -89,7 +90,6 @@ import awais.instagrabber.repositories.responses.Location; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.VideoVersion; -import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.NullSafePair; import awais.instagrabber.utils.NumberUtils; @@ -184,7 +184,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme public void onPause() { super.onPause(); // wasPaused = true; - if (settingsHelper.getBoolean(Constants.PLAY_IN_BACKGROUND)) return; + if (settingsHelper.getBoolean(PreferenceKeys.PLAY_IN_BACKGROUND)) return; final Media media = viewModel.getMedia(); if (media == null) return; switch (media.getMediaType()) { @@ -1058,7 +1058,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme // gestureDetector.onTouchEvent(event); // return true; // }); - final float vol = settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f; + final float vol = settingsHelper.getBoolean(PreferenceKeys.MUTED_VIDEOS) ? 0f : 1f; final VideoPlayerViewHelper.VideoPlayerCallback videoPlayerCallback = new VideoPlayerCallbackAdapter() { @Override public void onThumbnailLoaded() { diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 5cc6887b..c9a7f1d4 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -74,6 +74,7 @@ import awais.instagrabber.asyncs.CreateThreadAction; import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.databinding.FragmentStoryViewerBinding; import awais.instagrabber.fragments.main.ProfileFragmentDirections; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.interfaces.SwipeEvent; import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.HighlightModel; @@ -109,7 +110,7 @@ import retrofit2.Response; import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_THRESHOLD; import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_VELOCITY_THRESHOLD; -import static awais.instagrabber.utils.Constants.MARK_AS_SEEN; +import static awais.instagrabber.fragments.settings.PreferenceKeys.MARK_AS_SEEN; import static awais.instagrabber.utils.Utils.settingsHelper; public class StoryViewerFragment extends Fragment { @@ -990,7 +991,7 @@ public class StoryViewerFragment extends Fragment { if (context == null) return; player = new SimpleExoPlayer.Builder(context).build(); binding.playerView.setPlayer(player); - player.setPlayWhenReady(settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS)); + player.setPlayWhenReady(settingsHelper.getBoolean(PreferenceKeys.AUTOPLAY_VIDEOS)); final Uri uri = Uri.parse(url); final MediaItem mediaItem = MediaItem.fromUri(uri); @@ -1091,7 +1092,7 @@ public class StoryViewerFragment extends Fragment { if (context == null) return; player = new SimpleExoPlayer.Builder(context).build(); binding.playerView.setPlayer(player); - player.setPlayWhenReady(settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS)); + player.setPlayWhenReady(settingsHelper.getBoolean(PreferenceKeys.AUTOPLAY_VIDEOS)); final Uri uri = Uri.parse(url); final MediaItem mediaItem = MediaItem.fromUri(uri); diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java index eb97b60f..fe4343e7 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java @@ -101,6 +101,7 @@ import awais.instagrabber.dialogs.MediaPickerBottomDialogFragment; import awais.instagrabber.fragments.PostViewV2Fragment; import awais.instagrabber.fragments.UserSearchFragment; import awais.instagrabber.fragments.UserSearchFragmentDirections; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.models.Resource; import awais.instagrabber.models.enums.DirectItemType; import awais.instagrabber.models.enums.MediaItemType; @@ -114,7 +115,6 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItemVisual import awais.instagrabber.repositories.responses.directmessages.DirectThread; import awais.instagrabber.repositories.responses.directmessages.RankedRecipient; import awais.instagrabber.utils.AppExecutors; -import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.DMUtils; import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.PermissionUtils; @@ -356,7 +356,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact super.onCreate(savedInstanceState); fragmentActivity = (MainActivity) requireActivity(); appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class); - autoMarkAsSeen = Utils.settingsHelper.getBoolean(Constants.DM_MARK_AS_SEEN); + autoMarkAsSeen = Utils.settingsHelper.getBoolean(PreferenceKeys.DM_MARK_AS_SEEN); final Bundle arguments = getArguments(); if (arguments == null) return; final DirectMessageThreadFragmentArgs fragmentArgs = DirectMessageThreadFragmentArgs.fromBundle(arguments); diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/BasePreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/BasePreferencesFragment.java index caade8b7..3e7f304d 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/BasePreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/BasePreferencesFragment.java @@ -41,7 +41,7 @@ public abstract class BasePreferencesFragment extends PreferenceFragmentCompat i if (!shouldRecreate) return; final MainActivity activity = (MainActivity) getActivity(); if (activity == null) return; - if (key.equals(Constants.APP_LANGUAGE)) { + if (key.equals(PreferenceKeys.APP_LANGUAGE)) { LocaleUtils.setLocale(activity.getBaseContext()); } shouldRecreate = false; diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/DMPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/DMPreferencesFragment.java index 466e2490..2633bb78 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/DMPreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/DMPreferencesFragment.java @@ -20,7 +20,6 @@ import awais.instagrabber.customviews.helpers.TextWatcherAdapter; import awais.instagrabber.databinding.PrefAutoRefreshDmFreqBinding; import awais.instagrabber.services.DMSyncAlarmReceiver; import awais.instagrabber.services.DMSyncService; -import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Debouncer; import awais.instagrabber.utils.TextUtils; @@ -43,7 +42,7 @@ public class DMPreferencesFragment extends BasePreferencesFragment { private Preference getMarkDMSeenPreference(@NonNull final Context context) { return PreferenceHelper.getSwitchPreference( context, - Constants.DM_MARK_AS_SEEN, + PreferenceKeys.DM_MARK_AS_SEEN, R.string.dm_mark_as_seen_setting, R.string.dm_mark_as_seen_setting_summary, false, diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/DownloadsPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/DownloadsPreferencesFragment.java index 4e75a97f..6a18c69a 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/DownloadsPreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/DownloadsPreferencesFragment.java @@ -14,12 +14,11 @@ import androidx.preference.SwitchPreferenceCompat; import com.google.android.material.switchmaterial.SwitchMaterial; import awais.instagrabber.R; -import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.DirectoryChooser; import awais.instagrabber.utils.TextUtils; -import static awais.instagrabber.utils.Constants.FOLDER_PATH; -import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO; +import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_PATH; +import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_SAVE_TO; import static awais.instagrabber.utils.Utils.settingsHelper; public class DownloadsPreferencesFragment extends BasePreferencesFragment { @@ -34,7 +33,7 @@ public class DownloadsPreferencesFragment extends BasePreferencesFragment { private Preference getDownloadUserFolderPreference(@NonNull final Context context) { final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); - preference.setKey(Constants.DOWNLOAD_USER_FOLDER); + preference.setKey(PreferenceKeys.DOWNLOAD_USER_FOLDER); preference.setTitle(R.string.download_user_folder); preference.setIconSpaceReserved(false); return preference; @@ -52,7 +51,7 @@ public class DownloadsPreferencesFragment extends BasePreferencesFragment { private Preference getPrependUsernameToFilenamePreference(@NonNull final Context context) { final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); - preference.setKey(Constants.DOWNLOAD_PREPEND_USER_NAME); + preference.setKey(PreferenceKeys.DOWNLOAD_PREPEND_USER_NAME); preference.setTitle(R.string.download_prepend_username); preference.setIconSpaceReserved(false); return preference; @@ -66,7 +65,7 @@ public class DownloadsPreferencesFragment extends BasePreferencesFragment { public SaveToCustomFolderPreference(final Context context, final OnSelectFolderButtonClickListener onSelectFolderButtonClickListener) { super(context); this.onSelectFolderButtonClickListener = onSelectFolderButtonClickListener; - key = Constants.FOLDER_SAVE_TO; + key = PreferenceKeys.FOLDER_SAVE_TO; setLayoutResource(R.layout.pref_custom_folder); setKey(key); setTitle(R.string.save_to_folder); diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/GeneralPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/GeneralPreferencesFragment.java index 2eba325e..c14b2268 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/GeneralPreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/GeneralPreferencesFragment.java @@ -82,7 +82,7 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen private Preference getUpdateCheckPreference(@NonNull final Context context) { final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); - preference.setKey(Constants.CHECK_UPDATES); + preference.setKey(PreferenceKeys.CHECK_UPDATES); preference.setTitle(R.string.update_check); preference.setIconSpaceReserved(false); return preference; @@ -91,7 +91,7 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen private Preference getFlagSecurePreference(@NonNull final Context context) { return PreferenceHelper.getSwitchPreference( context, - Constants.FLAG_SECURE, + PreferenceKeys.FLAG_SECURE, R.string.flag_secure, -1, false, diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/LocalePreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/LocalePreferencesFragment.java index a02a8764..06fe32b2 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/LocalePreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/LocalePreferencesFragment.java @@ -36,7 +36,7 @@ public class LocalePreferencesFragment extends BasePreferencesFragment { for (int i = 0; i < length; i++) { values[i] = String.valueOf(i); } - preference.setKey(Constants.APP_LANGUAGE); + preference.setKey(PreferenceKeys.APP_LANGUAGE); preference.setTitle(R.string.select_language); preference.setDialogTitle(R.string.select_language); preference.setEntries(R.array.languages); @@ -59,10 +59,10 @@ public class LocalePreferencesFragment extends BasePreferencesFragment { 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), + settingsHelper.getBoolean(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT_ENABLED), + settingsHelper.getString(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT), + settingsHelper.getString(PreferenceKeys.DATE_TIME_SELECTION), + settingsHelper.getBoolean(PreferenceKeys.SWAP_DATE_TIME_FORMAT_ENABLED), (isCustomFormat, formatSelection, spTimeFormatSelectedItemPosition, @@ -72,16 +72,16 @@ public class LocalePreferencesFragment extends BasePreferencesFragment { currentFormat, swapDateTime) -> { if (isCustomFormat) { - settingsHelper.putString(Constants.CUSTOM_DATE_TIME_FORMAT, formatSelection); + settingsHelper.putString(PreferenceKeys.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.putString(PreferenceKeys.DATE_TIME_FORMAT, selectedFormat); + settingsHelper.putString(PreferenceKeys.DATE_TIME_SELECTION, formatSelectionUpdated); } - settingsHelper.putBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED, isCustomFormat); - settingsHelper.putBoolean(Constants.SWAP_DATE_TIME_FORMAT_ENABLED, swapDateTime); + settingsHelper.putBoolean(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT_ENABLED, isCustomFormat); + settingsHelper.putBoolean(PreferenceKeys.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/fragments/settings/NotificationsPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/NotificationsPreferencesFragment.java index 50d284e7..2a2dd499 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/NotificationsPreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/NotificationsPreferencesFragment.java @@ -7,7 +7,6 @@ import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import awais.instagrabber.R; -import awais.instagrabber.utils.Constants; public class NotificationsPreferencesFragment extends BasePreferencesFragment { @Override @@ -21,7 +20,7 @@ public class NotificationsPreferencesFragment extends BasePreferencesFragment { private Preference getActivityNotificationsPreference(@NonNull final Context context) { return PreferenceHelper.getSwitchPreference( context, - Constants.CHECK_ACTIVITY, + PreferenceKeys.CHECK_ACTIVITY, R.string.activity_setting, -1, false, diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/PostPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/PostPreferencesFragment.java index c79d009b..b1db2e40 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/PostPreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/PostPreferencesFragment.java @@ -9,7 +9,6 @@ import androidx.preference.SwitchPreferenceCompat; import awais.instagrabber.R; import awais.instagrabber.dialogs.KeywordsFilterDialog; -import awais.instagrabber.utils.Constants; public class PostPreferencesFragment extends BasePreferencesFragment { @Override @@ -34,7 +33,7 @@ public class PostPreferencesFragment extends BasePreferencesFragment { private Preference getBackgroundPlayPreference(@NonNull final Context context) { final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); - preference.setKey(Constants.PLAY_IN_BACKGROUND); + preference.setKey(PreferenceKeys.PLAY_IN_BACKGROUND); preference.setTitle(R.string.post_viewer_background_play); preference.setSummary(R.string.post_viewer_background_play_summary); preference.setIconSpaceReserved(false); @@ -43,7 +42,7 @@ public class PostPreferencesFragment extends BasePreferencesFragment { private Preference getAlwaysMuteVideosPreference(@NonNull final Context context) { final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); - preference.setKey(Constants.MUTED_VIDEOS); + preference.setKey(PreferenceKeys.MUTED_VIDEOS); preference.setTitle(R.string.post_viewer_muted_autoplay); preference.setIconSpaceReserved(false); return preference; @@ -51,7 +50,7 @@ public class PostPreferencesFragment extends BasePreferencesFragment { private Preference getShowCaptionPreference(@NonNull final Context context) { final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); - preference.setKey(Constants.SHOW_CAPTIONS); + preference.setKey(PreferenceKeys.SHOW_CAPTIONS); preference.setDefaultValue(true); preference.setTitle(R.string.post_viewer_show_captions); preference.setIconSpaceReserved(false); @@ -60,7 +59,7 @@ public class PostPreferencesFragment extends BasePreferencesFragment { private Preference getToggleKeywordFilterPreference(@NonNull final Context context) { final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); - preference.setKey(Constants.TOGGLE_KEYWORD_FILTER); + preference.setKey(PreferenceKeys.TOGGLE_KEYWORD_FILTER); preference.setDefaultValue(false); preference.setTitle(R.string.toggle_keyword_filter); preference.setIconSpaceReserved(false); diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.java b/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.java index dacf80f6..059e1069 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.java @@ -8,4 +8,36 @@ public final class PreferenceKeys { public static final String PREF_ENABLE_SENTRY = "enable_sentry"; public static final String PREF_TAB_ORDER = "tab_order"; public static final String PREF_SHOWN_COUNT_TOOLTIP = "shown_count_tooltip"; + // string prefs + public static final String FOLDER_PATH = "custom_path"; + public static final String DATE_TIME_FORMAT = "date_time_format"; + public static final String DATE_TIME_SELECTION = "date_time_selection"; + public static final String CUSTOM_DATE_TIME_FORMAT = "date_time_custom_format"; + public static final String APP_THEME = "app_theme_v19"; + public static final String APP_LANGUAGE = "app_language_v19"; + public static final String STORY_SORT = "story_sort"; + // set string prefs + public static final String KEYWORD_FILTERS = "keyword_filters"; + // boolean prefs + public static final String DOWNLOAD_USER_FOLDER = "download_user_folder"; + public static final String TOGGLE_KEYWORD_FILTER = "toggle_keyword_filter"; + public static final String DOWNLOAD_PREPEND_USER_NAME = "download_user_name"; + public static final String PLAY_IN_BACKGROUND = "play_in_background"; + // deprecated: public static final String BOTTOM_TOOLBAR = "bottom_toolbar"; + public static final String FOLDER_SAVE_TO = "saved_to"; + public static final String AUTOPLAY_VIDEOS = "autoplay_videos"; + public static final String MUTED_VIDEOS = "muted_videos"; + public static final String SHOW_CAPTIONS = "show_captions"; + 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 HIDE_MUTED_REELS = "hide_muted_reels"; + public static final String DM_MARK_AS_SEEN = "dm_mark_as_seen"; + // deprecated: public static final String INSTADP = "instadp"; + // deprecated: public static final String STORIESIG = "storiesig"; + // deprecated: public static final String STORY_VIEWER = "story_viewer"; + // deprecated: public static final String AMOLED_THEME = "amoled_theme"; + public static final String CHECK_ACTIVITY = "check_activity"; + public static final String CHECK_UPDATES = "check_updates"; + public static final String FLAG_SECURE = "flag_secure"; } diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/StoriesPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/StoriesPreferencesFragment.java index 0f3850ab..e027389d 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/StoriesPreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/StoriesPreferencesFragment.java @@ -9,7 +9,6 @@ import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreferenceCompat; import awais.instagrabber.R; -import awais.instagrabber.utils.Constants; public class StoriesPreferencesFragment extends BasePreferencesFragment { @Override @@ -29,7 +28,7 @@ public class StoriesPreferencesFragment extends BasePreferencesFragment { for (int i = 0; i < length; i++) { values[i] = String.valueOf(i); } - preference.setKey(Constants.STORY_SORT); + preference.setKey(PreferenceKeys.STORY_SORT); preference.setTitle(R.string.story_sort_setting); preference.setDialogTitle(R.string.story_sort_setting); preference.setEntries(R.array.story_sorts); @@ -40,7 +39,7 @@ public class StoriesPreferencesFragment extends BasePreferencesFragment { private Preference getHideMutedReelsPreference(@NonNull final Context context) { final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); - preference.setKey(Constants.HIDE_MUTED_REELS); + preference.setKey(PreferenceKeys.HIDE_MUTED_REELS); preference.setTitle(R.string.hide_muted_reels_setting); preference.setIconSpaceReserved(false); return preference; @@ -48,7 +47,7 @@ public class StoriesPreferencesFragment extends BasePreferencesFragment { private Preference getMarkStoriesSeenPreference(@NonNull final Context context) { final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); - preference.setKey(Constants.MARK_AS_SEEN); + preference.setKey(PreferenceKeys.MARK_AS_SEEN); preference.setTitle(R.string.mark_as_seen_setting); preference.setSummary(R.string.mark_as_seen_setting_summary); preference.setIconSpaceReserved(false); diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/ThemePreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/ThemePreferencesFragment.java index bf3aad9e..21435b0f 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/ThemePreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/ThemePreferencesFragment.java @@ -29,7 +29,7 @@ public class ThemePreferencesFragment extends BasePreferencesFragment { for (int i = 0; i < length; i++) { values[i] = String.valueOf(i); } - preference.setKey(Constants.APP_THEME); + preference.setKey(PreferenceKeys.APP_THEME); preference.setTitle(R.string.theme_settings); preference.setDialogTitle(R.string.theme_settings); preference.setEntries(R.array.theme_presets); diff --git a/app/src/main/java/awais/instagrabber/utils/Constants.java b/app/src/main/java/awais/instagrabber/utils/Constants.java index 9f79641e..53f89710 100644 --- a/app/src/main/java/awais/instagrabber/utils/Constants.java +++ b/app/src/main/java/awais/instagrabber/utils/Constants.java @@ -3,42 +3,10 @@ package awais.instagrabber.utils; public final class Constants { public static final String CRASH_REPORT_EMAIL = "barinsta@austinhuang.me"; - // string prefs - public static final String FOLDER_PATH = "custom_path"; - public static final String DATE_TIME_FORMAT = "date_time_format"; - public static final String DATE_TIME_SELECTION = "date_time_selection"; - public static final String CUSTOM_DATE_TIME_FORMAT = "date_time_custom_format"; - public static final String APP_THEME = "app_theme_v19"; - public static final String APP_LANGUAGE = "app_language_v19"; - public static final String STORY_SORT = "story_sort"; - // set string prefs - public static final String KEYWORD_FILTERS = "keyword_filters"; // int prefs, do not export public static final String PREV_INSTALL_VERSION = "prevVersion"; public static final String BROWSER_UA_CODE = "browser_ua_code"; public static final String APP_UA_CODE = "app_ua_code"; - // boolean prefs - public static final String DOWNLOAD_USER_FOLDER = "download_user_folder"; - public static final String TOGGLE_KEYWORD_FILTER = "toggle_keyword_filter"; - public static final String DOWNLOAD_PREPEND_USER_NAME = "download_user_name"; - public static final String PLAY_IN_BACKGROUND = "play_in_background"; - // deprecated: public static final String BOTTOM_TOOLBAR = "bottom_toolbar"; - public static final String FOLDER_SAVE_TO = "saved_to"; - public static final String AUTOPLAY_VIDEOS = "autoplay_videos"; - public static final String MUTED_VIDEOS = "muted_videos"; - public static final String SHOW_CAPTIONS = "show_captions"; - 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 HIDE_MUTED_REELS = "hide_muted_reels"; - public static final String DM_MARK_AS_SEEN = "dm_mark_as_seen"; - // deprecated: public static final String INSTADP = "instadp"; - // deprecated: public static final String STORIESIG = "storiesig"; - // deprecated: public static final String STORY_VIEWER = "story_viewer"; - // deprecated: public static final String AMOLED_THEME = "amoled_theme"; - public static final String CHECK_ACTIVITY = "check_activity"; - public static final String CHECK_UPDATES = "check_updates"; - public static final String FLAG_SECURE = "flag_secure"; // never Export public static final String COOKIE = "cookie"; public static final String SHOW_QUICK_ACCESS_DIALOG = "show_quick_dlg"; diff --git a/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java b/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java index 18bf59c7..be24dd48 100644 --- a/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java @@ -33,6 +33,7 @@ import java.util.UUID; import java.util.regex.Pattern; import awais.instagrabber.R; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.repositories.responses.Audio; @@ -41,8 +42,8 @@ import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.VideoVersion; import awais.instagrabber.workers.DownloadWorker; -import static awais.instagrabber.utils.Constants.FOLDER_PATH; -import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO; +import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_PATH; +import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_SAVE_TO; public final class DownloadUtils { private static final String TAG = "DownloadUtils"; @@ -74,7 +75,7 @@ public final class DownloadUtils { final boolean skipCreateDir) { File dir = getDownloadDir(); - if (Utils.settingsHelper.getBoolean(Constants.DOWNLOAD_USER_FOLDER) && !TextUtils.isEmpty(username)) { + if (Utils.settingsHelper.getBoolean(PreferenceKeys.DOWNLOAD_USER_FOLDER) && !TextUtils.isEmpty(username)) { final String finaleUsername = username.startsWith("@") ? username.substring(1) : username; dir = new File(dir, finaleUsername); } @@ -277,7 +278,7 @@ public final class DownloadUtils { : storyModel.getStoryUrl(); final String baseFileName = storyModel.getStoryMediaId() + "_" + storyModel.getTimestamp() + DownloadUtils.getFileExtensionFromUrl(url); - final String usernamePrepend = Utils.settingsHelper.getBoolean(Constants.DOWNLOAD_PREPEND_USER_NAME) + final String usernamePrepend = Utils.settingsHelper.getBoolean(PreferenceKeys.DOWNLOAD_PREPEND_USER_NAME) && storyModel.getUsername() != null ? storyModel.getUsername() + "_" : ""; final File saveFile = new File(downloadDir, usernamePrepend + baseFileName); @@ -318,7 +319,7 @@ public final class DownloadUtils { } if (!TextUtils.isEmpty(media.getCode())) { fileName = media.getCode(); - if (Utils.settingsHelper.getBoolean(Constants.DOWNLOAD_PREPEND_USER_NAME) && mediaUser != null) { + if (Utils.settingsHelper.getBoolean(PreferenceKeys.DOWNLOAD_PREPEND_USER_NAME) && mediaUser != null) { fileName = mediaUser.getUsername() + "_" + fileName; } } @@ -344,7 +345,7 @@ public final class DownloadUtils { } final Media child = sliderItems.get(i); final String url = getUrlOfType(child); - final String usernamePrepend = Utils.settingsHelper.getBoolean(Constants.DOWNLOAD_PREPEND_USER_NAME) && mediaUser != null ? mediaUser.getUsername() : ""; + final String usernamePrepend = Utils.settingsHelper.getBoolean(PreferenceKeys.DOWNLOAD_PREPEND_USER_NAME) && mediaUser != null ? mediaUser.getUsername() : ""; final File file = getDownloadChildSaveFile(downloadDir, media.getCode(), i + 1, url, usernamePrepend); map.put(url, file.getAbsolutePath()); } diff --git a/app/src/main/java/awais/instagrabber/utils/LocaleUtils.java b/app/src/main/java/awais/instagrabber/utils/LocaleUtils.java index 960bd8a6..bdf00582 100755 --- a/app/src/main/java/awais/instagrabber/utils/LocaleUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/LocaleUtils.java @@ -9,6 +9,8 @@ import androidx.annotation.Nullable; import java.util.Locale; +import awais.instagrabber.fragments.settings.PreferenceKeys; + // taken from my app TESV Console Codes public final class LocaleUtils { private static Locale defaultLocale, currentLocale; @@ -22,7 +24,7 @@ public final class LocaleUtils { if (Utils.settingsHelper == null) Utils.settingsHelper = new SettingsHelper(baseContext); - final String appLanguageSettings = Utils.settingsHelper.getString(Constants.APP_LANGUAGE); + final String appLanguageSettings = Utils.settingsHelper.getString(PreferenceKeys.APP_LANGUAGE); final String lang = LocaleUtils.getCorrespondingLanguageCode(appLanguageSettings); currentLocale = TextUtils.isEmpty(lang) ? defaultLocale : diff --git a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java index d98e6b37..8538b5c7 100755 --- a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java +++ b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java @@ -18,33 +18,33 @@ import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_ENABLE_D import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_ENABLE_SENTRY; import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_SHOWN_COUNT_TOOLTIP; import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_TAB_ORDER; -import static awais.instagrabber.utils.Constants.APP_LANGUAGE; -import static awais.instagrabber.utils.Constants.APP_THEME; +import static awais.instagrabber.fragments.settings.PreferenceKeys.APP_LANGUAGE; +import static awais.instagrabber.fragments.settings.PreferenceKeys.APP_THEME; import static awais.instagrabber.utils.Constants.APP_UA; import static awais.instagrabber.utils.Constants.APP_UA_CODE; -import static awais.instagrabber.utils.Constants.AUTOPLAY_VIDEOS; +import static awais.instagrabber.fragments.settings.PreferenceKeys.AUTOPLAY_VIDEOS; import static awais.instagrabber.utils.Constants.BROWSER_UA; import static awais.instagrabber.utils.Constants.BROWSER_UA_CODE; -import static awais.instagrabber.utils.Constants.CHECK_ACTIVITY; -import static awais.instagrabber.utils.Constants.CHECK_UPDATES; +import static awais.instagrabber.fragments.settings.PreferenceKeys.CHECK_ACTIVITY; +import static awais.instagrabber.fragments.settings.PreferenceKeys.CHECK_UPDATES; import static awais.instagrabber.utils.Constants.COOKIE; -import static awais.instagrabber.utils.Constants.CUSTOM_DATE_TIME_FORMAT; -import static awais.instagrabber.utils.Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED; -import static awais.instagrabber.utils.Constants.DATE_TIME_FORMAT; -import static awais.instagrabber.utils.Constants.DATE_TIME_SELECTION; +import static awais.instagrabber.fragments.settings.PreferenceKeys.CUSTOM_DATE_TIME_FORMAT; +import static awais.instagrabber.fragments.settings.PreferenceKeys.CUSTOM_DATE_TIME_FORMAT_ENABLED; +import static awais.instagrabber.fragments.settings.PreferenceKeys.DATE_TIME_FORMAT; +import static awais.instagrabber.fragments.settings.PreferenceKeys.DATE_TIME_SELECTION; import static awais.instagrabber.utils.Constants.DEFAULT_TAB; import static awais.instagrabber.utils.Constants.DEVICE_UUID; -import static awais.instagrabber.utils.Constants.DM_MARK_AS_SEEN; -import static awais.instagrabber.utils.Constants.DOWNLOAD_PREPEND_USER_NAME; -import static awais.instagrabber.utils.Constants.DOWNLOAD_USER_FOLDER; -import static awais.instagrabber.utils.Constants.FLAG_SECURE; -import static awais.instagrabber.utils.Constants.FOLDER_PATH; -import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO; -import static awais.instagrabber.utils.Constants.HIDE_MUTED_REELS; -import static awais.instagrabber.utils.Constants.KEYWORD_FILTERS; -import static awais.instagrabber.utils.Constants.MARK_AS_SEEN; -import static awais.instagrabber.utils.Constants.MUTED_VIDEOS; -import static awais.instagrabber.utils.Constants.PLAY_IN_BACKGROUND; +import static awais.instagrabber.fragments.settings.PreferenceKeys.DM_MARK_AS_SEEN; +import static awais.instagrabber.fragments.settings.PreferenceKeys.DOWNLOAD_PREPEND_USER_NAME; +import static awais.instagrabber.fragments.settings.PreferenceKeys.DOWNLOAD_USER_FOLDER; +import static awais.instagrabber.fragments.settings.PreferenceKeys.FLAG_SECURE; +import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_PATH; +import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_SAVE_TO; +import static awais.instagrabber.fragments.settings.PreferenceKeys.HIDE_MUTED_REELS; +import static awais.instagrabber.fragments.settings.PreferenceKeys.KEYWORD_FILTERS; +import static awais.instagrabber.fragments.settings.PreferenceKeys.MARK_AS_SEEN; +import static awais.instagrabber.fragments.settings.PreferenceKeys.MUTED_VIDEOS; +import static awais.instagrabber.fragments.settings.PreferenceKeys.PLAY_IN_BACKGROUND; import static awais.instagrabber.utils.Constants.PREF_DARK_THEME; import static awais.instagrabber.utils.Constants.PREF_EMOJI_VARIANTS; import static awais.instagrabber.utils.Constants.PREF_HASHTAG_POSTS_LAYOUT; @@ -58,12 +58,12 @@ import static awais.instagrabber.utils.Constants.PREF_SAVED_POSTS_LAYOUT; import static awais.instagrabber.utils.Constants.PREF_TAGGED_POSTS_LAYOUT; import static awais.instagrabber.utils.Constants.PREF_TOPIC_POSTS_LAYOUT; import static awais.instagrabber.utils.Constants.PREV_INSTALL_VERSION; -import static awais.instagrabber.utils.Constants.SHOW_CAPTIONS; +import static awais.instagrabber.fragments.settings.PreferenceKeys.SHOW_CAPTIONS; 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_SORT; -import static awais.instagrabber.utils.Constants.SWAP_DATE_TIME_FORMAT_ENABLED; -import static awais.instagrabber.utils.Constants.TOGGLE_KEYWORD_FILTER; +import static awais.instagrabber.fragments.settings.PreferenceKeys.STORY_SORT; +import static awais.instagrabber.fragments.settings.PreferenceKeys.SWAP_DATE_TIME_FORMAT_ENABLED; +import static awais.instagrabber.fragments.settings.PreferenceKeys.TOGGLE_KEYWORD_FILTER; public final class SettingsHelper { private final SharedPreferences sharedPreferences; diff --git a/app/src/main/java/awais/instagrabber/webservices/StoriesService.java b/app/src/main/java/awais/instagrabber/webservices/StoriesService.java index 96e9bc7d..9b6a2f49 100644 --- a/app/src/main/java/awais/instagrabber/webservices/StoriesService.java +++ b/app/src/main/java/awais/instagrabber/webservices/StoriesService.java @@ -17,12 +17,12 @@ import java.util.Map; import java.util.Objects; import java.util.UUID; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.HighlightModel; import awais.instagrabber.models.StoryModel; import awais.instagrabber.repositories.StoriesRepository; import awais.instagrabber.repositories.requests.StoryViewerOptions; -import awais.instagrabber.repositories.responses.FriendshipStatus; import awais.instagrabber.repositories.responses.StoryStickerResponse; import awais.instagrabber.repositories.responses.User; import awais.instagrabber.utils.Constants; @@ -135,7 +135,7 @@ public class StoriesService extends BaseService { final JSONArray feedStoriesReel = new JSONObject(body).getJSONArray("tray"); for (int i = 0; i < feedStoriesReel.length(); ++i) { final JSONObject node = feedStoriesReel.getJSONObject(i); - if (node.optBoolean("hide_from_feed_unit") && Utils.settingsHelper.getBoolean(Constants.HIDE_MUTED_REELS)) continue; + if (node.optBoolean("hide_from_feed_unit") && Utils.settingsHelper.getBoolean(PreferenceKeys.HIDE_MUTED_REELS)) continue; final JSONObject userJson = node.getJSONObject(node.has("user") ? "user" : "owner"); try { final User user = new User(userJson.getLong("pk"), @@ -505,7 +505,7 @@ public class StoriesService extends BaseService { final List listCopy = new ArrayList<>(list); Collections.sort(listCopy, (o1, o2) -> { int result; - switch (Utils.settingsHelper.getString(Constants.STORY_SORT)) { + switch (Utils.settingsHelper.getString(PreferenceKeys.STORY_SORT)) { case "1": result = Long.compare(o2.getTimestamp(), o1.getTimestamp()); break; From 256a2ae88d45f5e9d371a93258e614e7c1446818 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 15:48:28 -0400 Subject: [PATCH 08/17] option to show keyboard immediately on search, close #1261 --- .../fragments/search/SearchFragment.java | 19 +++++++++++++++---- .../settings/GeneralPreferencesFragment.java | 9 +++++++++ .../fragments/settings/PreferenceKeys.java | 9 +++------ .../awais/instagrabber/utils/Constants.java | 2 +- .../instagrabber/utils/SettingsHelper.java | 10 +++++----- app/src/main/res/values/strings.xml | 1 + 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/search/SearchFragment.java b/app/src/main/java/awais/instagrabber/fragments/search/SearchFragment.java index 8e31cb70..ab879a77 100644 --- a/app/src/main/java/awais/instagrabber/fragments/search/SearchFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/search/SearchFragment.java @@ -1,5 +1,6 @@ package awais.instagrabber.fragments.search; +import android.content.Context; import android.os.Bundle; import android.text.Editable; import android.text.TextUtils; @@ -7,6 +8,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import androidx.annotation.NonNull; @@ -36,6 +38,9 @@ import awais.instagrabber.models.enums.FavoriteType; import awais.instagrabber.repositories.responses.search.SearchItem; import awais.instagrabber.viewmodels.SearchFragmentViewModel; +import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_SEARCH_FOCUS_KEYBOARD; +import static awais.instagrabber.utils.Utils.settingsHelper; + public class SearchFragment extends Fragment implements SearchCategoryFragment.OnSearchItemClickListener { private static final String TAG = SearchFragment.class.getSimpleName(); private static final String QUERY = "query"; @@ -119,9 +124,11 @@ public class SearchFragment extends Fragment implements SearchCategoryFragment.O if (mainActivity != null) { mainActivity.showSearchView(); } - // if (searchInputLayout != null) { - // searchInputLayout.requestFocus(); - // } + if (settingsHelper.getBoolean(PREF_SEARCH_FOCUS_KEYBOARD)) { + searchInput.requestFocus(); + final InputMethodManager imm = (InputMethodManager) requireContext().getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) imm.showSoftInput(searchInput, InputMethodManager.SHOW_IMPLICIT); + } } private void init(@Nullable final Bundle savedInstanceState) { @@ -147,7 +154,11 @@ public class SearchFragment extends Fragment implements SearchCategoryFragment.O searchInput.setText(savedQuery); triggerEmptyQuery = false; } - // searchInput.requestFocus(); + if (settingsHelper.getBoolean(PREF_SEARCH_FOCUS_KEYBOARD)) { + searchInput.requestFocus(); + final InputMethodManager imm = (InputMethodManager) requireContext().getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) imm.showSoftInput(searchInput, InputMethodManager.SHOW_IMPLICIT); + } if (triggerEmptyQuery) { viewModel.submitQuery(""); } diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/GeneralPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/GeneralPreferencesFragment.java index c14b2268..e8403162 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/GeneralPreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/GeneralPreferencesFragment.java @@ -36,6 +36,7 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen } screen.addPreference(getUpdateCheckPreference(context)); screen.addPreference(getFlagSecurePreference(context)); + screen.addPreference(getSearchFocusPreference(context)); final List preferences = FlavorSettings.getInstance() .getPreferences(context, getChildFragmentManager(), @@ -101,6 +102,14 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen }); } + private Preference getSearchFocusPreference(@NonNull final Context context) { + final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); + preference.setKey(PreferenceKeys.PREF_SEARCH_FOCUS_KEYBOARD); + preference.setTitle(R.string.pref_search_focus_keyboard); + preference.setIconSpaceReserved(false); + return preference; + } + @Override public void onSave(final boolean orderHasChanged) { if (!orderHasChanged) return; diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.java b/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.java index 059e1069..878b9678 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/PreferenceKeys.java @@ -1,6 +1,7 @@ package awais.instagrabber.fragments.settings; public final class PreferenceKeys { + // new boolean prefs public static final String PREF_ENABLE_DM_NOTIFICATIONS = "enable_dm_notifications"; public static final String PREF_ENABLE_DM_AUTO_REFRESH = "enable_dm_auto_refresh"; public static final String PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT = "enable_dm_auto_refresh_freq_unit"; @@ -8,6 +9,7 @@ public final class PreferenceKeys { public static final String PREF_ENABLE_SENTRY = "enable_sentry"; public static final String PREF_TAB_ORDER = "tab_order"; public static final String PREF_SHOWN_COUNT_TOOLTIP = "shown_count_tooltip"; + public static final String PREF_SEARCH_FOCUS_KEYBOARD = "search_focus_keyboard"; // string prefs public static final String FOLDER_PATH = "custom_path"; public static final String DATE_TIME_FORMAT = "date_time_format"; @@ -18,12 +20,11 @@ public final class PreferenceKeys { public static final String STORY_SORT = "story_sort"; // set string prefs public static final String KEYWORD_FILTERS = "keyword_filters"; - // boolean prefs + // old boolean prefs public static final String DOWNLOAD_USER_FOLDER = "download_user_folder"; public static final String TOGGLE_KEYWORD_FILTER = "toggle_keyword_filter"; public static final String DOWNLOAD_PREPEND_USER_NAME = "download_user_name"; public static final String PLAY_IN_BACKGROUND = "play_in_background"; - // deprecated: public static final String BOTTOM_TOOLBAR = "bottom_toolbar"; public static final String FOLDER_SAVE_TO = "saved_to"; public static final String AUTOPLAY_VIDEOS = "autoplay_videos"; public static final String MUTED_VIDEOS = "muted_videos"; @@ -33,10 +34,6 @@ public final class PreferenceKeys { public static final String MARK_AS_SEEN = "mark_as_seen"; public static final String HIDE_MUTED_REELS = "hide_muted_reels"; public static final String DM_MARK_AS_SEEN = "dm_mark_as_seen"; - // deprecated: public static final String INSTADP = "instadp"; - // deprecated: public static final String STORIESIG = "storiesig"; - // deprecated: public static final String STORY_VIEWER = "story_viewer"; - // deprecated: public static final String AMOLED_THEME = "amoled_theme"; public static final String CHECK_ACTIVITY = "check_activity"; public static final String CHECK_UPDATES = "check_updates"; public static final String FLAG_SECURE = "flag_secure"; diff --git a/app/src/main/java/awais/instagrabber/utils/Constants.java b/app/src/main/java/awais/instagrabber/utils/Constants.java index 53f89710..357b4c24 100644 --- a/app/src/main/java/awais/instagrabber/utils/Constants.java +++ b/app/src/main/java/awais/instagrabber/utils/Constants.java @@ -9,7 +9,7 @@ public final class Constants { public static final String APP_UA_CODE = "app_ua_code"; // never Export public static final String COOKIE = "cookie"; - public static final String SHOW_QUICK_ACCESS_DIALOG = "show_quick_dlg"; + // deprecated: public static final String SHOW_QUICK_ACCESS_DIALOG = "show_quick_dlg"; public static final String DEVICE_UUID = "device_uuid"; public static final String BROWSER_UA = "browser_ua"; public static final String APP_UA = "app_ua"; diff --git a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java index 8538b5c7..74c69b9c 100755 --- a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java +++ b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java @@ -58,8 +58,8 @@ import static awais.instagrabber.utils.Constants.PREF_SAVED_POSTS_LAYOUT; import static awais.instagrabber.utils.Constants.PREF_TAGGED_POSTS_LAYOUT; import static awais.instagrabber.utils.Constants.PREF_TOPIC_POSTS_LAYOUT; import static awais.instagrabber.utils.Constants.PREV_INSTALL_VERSION; +import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_SEARCH_FOCUS_KEYBOARD; import static awais.instagrabber.fragments.settings.PreferenceKeys.SHOW_CAPTIONS; -import static awais.instagrabber.utils.Constants.SHOW_QUICK_ACCESS_DIALOG; import static awais.instagrabber.utils.Constants.SKIPPED_VERSION; import static awais.instagrabber.fragments.settings.PreferenceKeys.STORY_SORT; import static awais.instagrabber.fragments.settings.PreferenceKeys.SWAP_DATE_TIME_FORMAT_ENABLED; @@ -155,18 +155,18 @@ public final class SettingsHelper { return sharedPreferences != null && sharedPreferences.contains(key); } - @StringDef( - {APP_LANGUAGE, APP_THEME, APP_UA, BROWSER_UA, COOKIE, FOLDER_PATH, DATE_TIME_FORMAT, DATE_TIME_SELECTION, + @StringDef({APP_LANGUAGE, APP_THEME, APP_UA, BROWSER_UA, COOKIE, FOLDER_PATH, DATE_TIME_FORMAT, DATE_TIME_SELECTION, CUSTOM_DATE_TIME_FORMAT, DEVICE_UUID, SKIPPED_VERSION, DEFAULT_TAB, PREF_DARK_THEME, PREF_LIGHT_THEME, PREF_POSTS_LAYOUT, PREF_PROFILE_POSTS_LAYOUT, PREF_TOPIC_POSTS_LAYOUT, PREF_HASHTAG_POSTS_LAYOUT, PREF_LOCATION_POSTS_LAYOUT, PREF_LIKED_POSTS_LAYOUT, PREF_TAGGED_POSTS_LAYOUT, PREF_SAVED_POSTS_LAYOUT, STORY_SORT, PREF_EMOJI_VARIANTS, PREF_REACTIONS, PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT, PREF_TAB_ORDER}) public @interface StringSettings {} - @StringDef({DOWNLOAD_USER_FOLDER, DOWNLOAD_PREPEND_USER_NAME, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, SHOW_QUICK_ACCESS_DIALOG, MUTED_VIDEOS, + @StringDef({DOWNLOAD_USER_FOLDER, DOWNLOAD_PREPEND_USER_NAME, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, MUTED_VIDEOS, SHOW_CAPTIONS, CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, DM_MARK_AS_SEEN, CHECK_ACTIVITY, CHECK_UPDATES, SWAP_DATE_TIME_FORMAT_ENABLED, PREF_ENABLE_DM_NOTIFICATIONS, PREF_ENABLE_DM_AUTO_REFRESH, - FLAG_SECURE, TOGGLE_KEYWORD_FILTER, PREF_ENABLE_SENTRY, HIDE_MUTED_REELS, PLAY_IN_BACKGROUND, PREF_SHOWN_COUNT_TOOLTIP}) + FLAG_SECURE, TOGGLE_KEYWORD_FILTER, PREF_ENABLE_SENTRY, HIDE_MUTED_REELS, PLAY_IN_BACKGROUND, + PREF_SHOWN_COUNT_TOOLTIP, PREF_SEARCH_FOCUS_KEYBOARD}) public @interface BooleanSettings {} @StringDef({PREV_INSTALL_VERSION, BROWSER_UA_CODE, APP_UA_CODE, PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER}) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 676fe1da..193bd298 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -269,6 +269,7 @@ Do not show again until next update Version Start screen + Show keyboard on search General Theme Downloads From 4161c7bc4d0d1a3395c5ae9656c8e476cadd4b65 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 16:21:30 -0400 Subject: [PATCH 09/17] close #1271 --- .../fragments/main/DiscoverFragment.java | 16 +++++++++++++++- .../responses/discover/TopicCluster.java | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java index 8ec7444a..449b937e 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java @@ -15,10 +15,14 @@ import androidx.navigation.fragment.FragmentNavigator; import androidx.navigation.fragment.NavHostFragment; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import java.util.Collections; +import java.util.List; + import awais.instagrabber.activities.MainActivity; import awais.instagrabber.adapters.DiscoverTopicsAdapter; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.databinding.FragmentDiscoverBinding; +import awais.instagrabber.repositories.responses.discover.TopicCluster; import awais.instagrabber.repositories.responses.discover.TopicalExploreFeedResponse; import awais.instagrabber.utils.Utils; import awais.instagrabber.viewmodels.TopicClusterViewModel; @@ -93,8 +97,18 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR @Override public void onSuccess(final TopicalExploreFeedResponse result) { if (result == null) return; - topicClusterViewModel.getList().postValue(result.getClusters()); + final List clusters = result.getClusters(); binding.swipeRefreshLayout.setRefreshing(false); + if (clusters.size() == 1 && result.getItems().size() > 0) { + final TopicCluster cluster = clusters.get(0); + if (cluster.getCoverMedia() == null) + cluster.setCoverMedia(result.getItems().get(0).getMedia()); + topicClusterViewModel.getList().postValue(Collections.singletonList(cluster)); + return; + } + if (clusters.size() > 1 || result.getItems().size() == 0) { + topicClusterViewModel.getList().postValue(clusters); + } } @Override diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/discover/TopicCluster.java b/app/src/main/java/awais/instagrabber/repositories/responses/discover/TopicCluster.java index 610a4835..436b8ecf 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/discover/TopicCluster.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/discover/TopicCluster.java @@ -11,7 +11,7 @@ public class TopicCluster implements Serializable { private final boolean canMute; private final boolean isMuted; private final int rankedPosition; - private final Media coverMedia; + private Media coverMedia; public TopicCluster(final String id, final String title, @@ -56,4 +56,8 @@ public class TopicCluster implements Serializable { public Media getCoverMedia() { return coverMedia; } + + public void setCoverMedia(final Media coverMedia) { + this.coverMedia = coverMedia; + } } From f4d1575edb75ddce1e035912459a3d96a7243bef Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 16:24:37 -0400 Subject: [PATCH 10/17] close #1263 --- .../instagrabber/fragments/NotificationsViewerFragment.java | 1 + .../java/awais/instagrabber/fragments/StoryViewerFragment.java | 1 + 2 files changed, 2 insertions(+) diff --git a/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java index c443652b..c6ccff9f 100644 --- a/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java @@ -114,6 +114,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe bundle.putSerializable(PostViewV2Fragment.ARG_MEDIA, feedModel); try { navController.navigate(R.id.action_global_post_view, bundle); + alertDialog.dismiss(); } catch (Exception e) { Log.e(TAG, "onSuccess: ", e); } diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index c9a7f1d4..33626e0c 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -469,6 +469,7 @@ public class StoryViewerFragment extends Fragment { bundle.putSerializable(PostViewV2Fragment.ARG_MEDIA, feedModel); try { navController.navigate(R.id.action_global_post_view, bundle); + alertDialog.dismiss(); } catch (Exception e) { Log.e(TAG, "openPostDialog: ", e); } From d5e75d16c31974f18089de3f7ac79e721022803e Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 16:43:11 -0400 Subject: [PATCH 11/17] long-clicking a discover topic should now show cover post --- .../adapters/DiscoverTopicsAdapter.java | 5 +- .../viewholder/TopicClusterViewHolder.java | 6 +- .../fragments/main/DiscoverFragment.java | 57 ++++++++++++++++--- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/DiscoverTopicsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/DiscoverTopicsAdapter.java index 4623e230..a1547a0b 100644 --- a/app/src/main/java/awais/instagrabber/adapters/DiscoverTopicsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/DiscoverTopicsAdapter.java @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.ListAdapter; import awais.instagrabber.adapters.viewholder.TopicClusterViewHolder; import awais.instagrabber.databinding.ItemDiscoverTopicBinding; import awais.instagrabber.repositories.responses.discover.TopicCluster; +import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.utils.ResponseBodyUtils; public class DiscoverTopicsAdapter extends ListAdapter { @@ -50,6 +51,8 @@ public class DiscoverTopicsAdapter extends ListAdapter onTopicClickListener.onTopicClick( topicCluster, - binding.getRoot(), binding.cover, - binding.title, titleColor.get(), backgroundColor.get() )); + itemView.setOnLongClickListener(v -> { + onTopicClickListener.onTopicLongClick(topicCluster.getCoverMedia()); + return true; + }); } // binding.title.setTransitionName("title-" + topicCluster.getId()); binding.cover.setTransitionName("cover-" + topicCluster.getId()); diff --git a/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java index 449b937e..26ee6ce9 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java @@ -5,12 +5,15 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; +import androidx.navigation.NavController; import androidx.navigation.fragment.FragmentNavigator; import androidx.navigation.fragment.NavHostFragment; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; @@ -18,15 +21,19 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import java.util.Collections; import java.util.List; +import awais.instagrabber.R; import awais.instagrabber.activities.MainActivity; import awais.instagrabber.adapters.DiscoverTopicsAdapter; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.databinding.FragmentDiscoverBinding; +import awais.instagrabber.fragments.PostViewV2Fragment; +import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.discover.TopicCluster; import awais.instagrabber.repositories.responses.discover.TopicalExploreFeedResponse; import awais.instagrabber.utils.Utils; import awais.instagrabber.viewmodels.TopicClusterViewModel; import awais.instagrabber.webservices.DiscoverService; +import awais.instagrabber.webservices.MediaService; import awais.instagrabber.webservices.ServiceCallback; public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { @@ -38,12 +45,14 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR private TopicClusterViewModel topicClusterViewModel; private boolean shouldRefresh = true; private DiscoverService discoverService; + private MediaService mediaService; @Override public void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); fragmentActivity = (MainActivity) requireActivity(); discoverService = DiscoverService.getInstance(); + mediaService = MediaService.getInstance(null, null, 0); } @Override @@ -80,13 +89,47 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR public void setupTopics() { topicClusterViewModel = new ViewModelProvider(fragmentActivity).get(TopicClusterViewModel.class); binding.topicsRecyclerView.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(2))); - final DiscoverTopicsAdapter adapter = new DiscoverTopicsAdapter((topicCluster, root, cover, title, titleColor, backgroundColor) -> { - final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder() - .addSharedElement(cover, "cover-" + topicCluster.getId()); - final DiscoverFragmentDirections.ActionDiscoverFragmentToTopicPostsFragment action = DiscoverFragmentDirections - .actionDiscoverFragmentToTopicPostsFragment(topicCluster, titleColor, backgroundColor); - NavHostFragment.findNavController(this).navigate(action, builder.build()); - }); + final DiscoverTopicsAdapter.OnTopicClickListener otcl = new DiscoverTopicsAdapter.OnTopicClickListener() { + public void onTopicClick(final TopicCluster topicCluster, final View cover, final int titleColor, final int backgroundColor) { + final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder() + .addSharedElement(cover, "cover-" + topicCluster.getId()); + final DiscoverFragmentDirections.ActionDiscoverFragmentToTopicPostsFragment action = DiscoverFragmentDirections + .actionDiscoverFragmentToTopicPostsFragment(topicCluster, titleColor, backgroundColor); + NavHostFragment.findNavController(DiscoverFragment.this).navigate(action, builder.build()); + } + + public void onTopicLongClick(final Media coverMedia) { + final AlertDialog alertDialog = new AlertDialog.Builder(requireContext()) + .setCancelable(false) + .setView(R.layout.dialog_opening_post) + .create(); + alertDialog.show(); + mediaService.fetch(Long.valueOf(coverMedia.getPk()), new ServiceCallback() { + @Override + public void onSuccess(final Media feedModel) { + final NavController navController = NavHostFragment.findNavController(DiscoverFragment.this); + final Bundle bundle = new Bundle(); + bundle.putSerializable(PostViewV2Fragment.ARG_MEDIA, feedModel); + try { + navController.navigate(R.id.action_global_post_view, bundle); + alertDialog.dismiss(); + } catch (Exception e) { + Log.e(TAG, "onSuccess: ", e); + } + } + + @Override + public void onFailure(final Throwable t) { + alertDialog.dismiss(); + try { + Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + } + catch (Throwable e) {} + } + }); + } + }; + final DiscoverTopicsAdapter adapter = new DiscoverTopicsAdapter(otcl); binding.topicsRecyclerView.setAdapter(adapter); topicClusterViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList); } From 5c0598502a4e80bb6168b09e79073c9edb510647 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 16:43:22 -0400 Subject: [PATCH 12/17] comment out unused stuff --- .../viewholder/DiscoverViewHolder.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/DiscoverViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/DiscoverViewHolder.java index 1dbd28a0..94735486 100755 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/DiscoverViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/DiscoverViewHolder.java @@ -1,26 +1,26 @@ -package awais.instagrabber.adapters.viewholder; - -import android.view.View; -import android.widget.ImageView; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -import com.facebook.drawee.view.SimpleDraweeView; - -import awais.instagrabber.R; - -public final class DiscoverViewHolder extends RecyclerView.ViewHolder { - public final SimpleDraweeView postImage; - public final ImageView typeIcon; - public final View selectedView; - // public final View progressView; - - public DiscoverViewHolder(@NonNull final View itemView) { - super(itemView); - typeIcon = itemView.findViewById(R.id.typeIcon); - postImage = itemView.findViewById(R.id.postImage); - selectedView = itemView.findViewById(R.id.selectedView); - // progressView = itemView.findViewById(R.id.progressView); - } -} \ No newline at end of file +//package awais.instagrabber.adapters.viewholder; +// +//import android.view.View; +//import android.widget.ImageView; +// +//import androidx.annotation.NonNull; +//import androidx.recyclerview.widget.RecyclerView; +// +//import com.facebook.drawee.view.SimpleDraweeView; +// +//import awais.instagrabber.R; +// +//public final class DiscoverViewHolder extends RecyclerView.ViewHolder { +// public final SimpleDraweeView postImage; +// public final ImageView typeIcon; +// public final View selectedView; +// // public final View progressView; +// +// public DiscoverViewHolder(@NonNull final View itemView) { +// super(itemView); +// typeIcon = itemView.findViewById(R.id.typeIcon); +// postImage = itemView.findViewById(R.id.postImage); +// selectedView = itemView.findViewById(R.id.selectedView); +// // progressView = itemView.findViewById(R.id.progressView); +// } +//} \ No newline at end of file From 78caa4286afda97a675e274d4db18111d607fe75 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 17:14:28 -0400 Subject: [PATCH 13/17] fix indentations --- .../instagrabber/fragments/StoryViewerFragment.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 766c9837..0f0e9b9f 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -447,12 +447,12 @@ public class StoryViewerFragment extends Fragment { } }); binding.swipeUp.setOnClickListener(v -> { - final Object tag = v.getTag(); - if (tag instanceof CharSequence) { + final Object tag = v.getTag(); + if (tag instanceof CharSequence) { new AlertDialog.Builder(context) - .setTitle(R.string.swipe_up_confirmation) - .setMessage(tag.toString()).setPositiveButton(R.string.yes, (d, w) -> Utils.openURL(context, tag.toString())) - .setNegativeButton(R.string.no, (d, w) -> d.dismiss()).show(); + .setTitle(R.string.swipe_up_confirmation) + .setMessage(tag.toString()).setPositiveButton(R.string.yes, (d, w) -> Utils.openURL(context, tag.toString())) + .setNegativeButton(R.string.no, (d, w) -> d.dismiss()).show(); } }); binding.viewStoryPost.setOnClickListener(v -> { From f85daef6ea60cda06033d7180b1b847fa4a20cb3 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 17:15:09 -0400 Subject: [PATCH 14/17] remove redundant import --- .../java/awais/instagrabber/fragments/StoryViewerFragment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 0f0e9b9f..c3801ee0 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -3,7 +3,6 @@ package awais.instagrabber.fragments; import android.annotation.SuppressLint; import android.content.Context; import android.content.pm.PackageManager; -import android.content.DialogInterface; import android.graphics.drawable.Animatable; import android.net.Uri; import android.os.Bundle; From 65addf8c92f64c37479cd840afc7126491a14de8 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 18:09:40 -0400 Subject: [PATCH 15/17] intent test cases for #1201 --- app/src/main/AndroidManifest.xml | 11 +------- .../instagrabber/utils/IntentUtilsTest.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 app/src/test/java/awais/instagrabber/utils/IntentUtilsTest.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f90a4aea..d839e3d4 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -51,8 +51,6 @@ - - @@ -60,6 +58,7 @@ + - - - - - - - - Date: Tue, 18 May 2021 18:21:43 -0400 Subject: [PATCH 16/17] it doesn't even work... --- .../test/java/awais/instagrabber/utils/IntentUtilsTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/test/java/awais/instagrabber/utils/IntentUtilsTest.java b/app/src/test/java/awais/instagrabber/utils/IntentUtilsTest.java index bc5754fb..c9cbc6bb 100644 --- a/app/src/test/java/awais/instagrabber/utils/IntentUtilsTest.java +++ b/app/src/test/java/awais/instagrabber/utils/IntentUtilsTest.java @@ -1,3 +1,6 @@ +// java.lang.RuntimeException: Method parse in android.net.Uri not mocked. +// See http://g.co/androidstudio/not-mocked for details. + package awais.instagrabber.utils; import org.junit.jupiter.api.Assertions; From efb5818a65bea72866bb7b2c1491ace04d668091 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 18 May 2021 22:11:16 -0400 Subject: [PATCH 17/17] post shortcode converter --- .../java/awais/instagrabber/utils/TextUtils.java | 13 +++++++++++++ .../awais/instagrabber/utils/TextUtilsTest.java | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/awais/instagrabber/utils/TextUtils.java b/app/src/main/java/awais/instagrabber/utils/TextUtils.java index 448c2a90..5df3ac08 100644 --- a/app/src/main/java/awais/instagrabber/utils/TextUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/TextUtils.java @@ -10,11 +10,13 @@ import android.util.Patterns; import androidx.annotation.NonNull; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.regex.Matcher; +import java.util.stream.Collectors; public final class TextUtils { // extracted from String class @@ -106,4 +108,15 @@ public final class TextUtils { } return urls; } + + // https://github.com/notslang/instagram-id-to-url-segment + public static long shortcodeToId(final String shortcode) { + long result = 0L; + for (int i = 0; i < shortcode.length() && i < 11; i++){ + final char c = shortcode.charAt(i); + final int k = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".indexOf(c); + result = result * 64 + k; + } + return result; + } } diff --git a/app/src/test/java/awais/instagrabber/utils/TextUtilsTest.java b/app/src/test/java/awais/instagrabber/utils/TextUtilsTest.java index cf69eb07..00d3f71d 100644 --- a/app/src/test/java/awais/instagrabber/utils/TextUtilsTest.java +++ b/app/src/test/java/awais/instagrabber/utils/TextUtilsTest.java @@ -1,10 +1,11 @@ package awais.instagrabber.utils; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; class TextUtilsTest { - @org.junit.jupiter.api.Test + @Test void testMillisToTimeString() { String timeString = TextUtils.millisToTimeString(18000000); Assertions.assertEquals("05:00:00", timeString); @@ -15,4 +16,12 @@ class TextUtilsTest { timeString = TextUtils.millisToTimeString(300000, true); Assertions.assertEquals("00:05:00", timeString); } + + @Test + void testShortcodeConversion() { + long conversion = TextUtils.shortcodeToId("CA0YnOonSfS"); + Assertions.assertEquals(2320587956892280786L, conversion); + conversion = TextUtils.shortcodeToId("B_7n8mblwx6gv1ZaNvA5ZhAs2qslMnRiMMYW1c0"); + Assertions.assertEquals(2304611322577751162L, conversion); + } } \ No newline at end of file