1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00

Merge branch 'master' into raniapl/development

This commit is contained in:
Ammar Githam 2021-05-19 19:55:14 +09:00
commit f501f68f98
39 changed files with 319 additions and 188 deletions

View File

@ -51,8 +51,6 @@
<data android:scheme="http" /> <data android:scheme="http" />
<data android:scheme="https" /> <data android:scheme="https" />
<data android:host="ig.me" />
<data android:host="www.ig.me" />
<data android:host="instagr.am" /> <data android:host="instagr.am" />
<data android:host="www.instagr.am" /> <data android:host="www.instagr.am" />
<data android:host="instagram.com" /> <data android:host="instagram.com" />
@ -60,6 +58,7 @@
<data android:pathPrefix="/" /> <data android:pathPrefix="/" />
<data android:pathPrefix="/p" /> <data android:pathPrefix="/p" />
<data android:pathPrefix="/explore/tags" /> <data android:pathPrefix="/explore/tags" />
<data android:pathPrefix="/explore/locations" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
@ -104,14 +103,6 @@
<data android:mimeType="text/plain" /> <data android:mimeType="text/plain" />
</intent-filter> </intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="ig.me" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity> </activity>
<activity <activity
android:name=".activities.Login" android:name=".activities.Login"

View File

@ -13,6 +13,7 @@ import java.net.CookieHandler;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.UUID; import java.util.UUID;
import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.LocaleUtils; import awais.instagrabber.utils.LocaleUtils;
import awais.instagrabber.utils.SettingsHelper; import awais.instagrabber.utils.SettingsHelper;
@ -82,9 +83,9 @@ public final class InstaGrabberApplication extends Application {
if (datetimeParser == null) if (datetimeParser == null)
datetimeParser = new SimpleDateFormat( datetimeParser = new SimpleDateFormat(
settingsHelper.getBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED) ? settingsHelper.getBoolean(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT_ENABLED) ?
settingsHelper.getString(Constants.CUSTOM_DATE_TIME_FORMAT) : settingsHelper.getString(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT) :
settingsHelper.getString(Constants.DATE_TIME_FORMAT), LocaleUtils.getCurrentLocale()); settingsHelper.getString(PreferenceKeys.DATE_TIME_FORMAT), LocaleUtils.getCurrentLocale());
if (TextUtils.isEmpty(settingsHelper.getString(Constants.DEVICE_UUID))) { if (TextUtils.isEmpty(settingsHelper.getString(Constants.DEVICE_UUID))) {
settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString()); settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString());

View File

@ -141,7 +141,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
instance = this; instance = this;
binding = ActivityMainBinding.inflate(getLayoutInflater()); binding = ActivityMainBinding.inflate(getLayoutInflater());
setupCookie(); setupCookie();
if (settingsHelper.getBoolean(Constants.FLAG_SECURE)) { if (settingsHelper.getBoolean(PreferenceKeys.FLAG_SECURE)) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
} }
setContentView(binding.getRoot()); setContentView(binding.getRoot());
@ -166,14 +166,14 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
setupBottomNavigationBar(true); setupBottomNavigationBar(true);
} }
if (!BuildConfig.isPre) { if (!BuildConfig.isPre) {
final boolean checkUpdates = settingsHelper.getBoolean(Constants.CHECK_UPDATES); final boolean checkUpdates = settingsHelper.getBoolean(PreferenceKeys.CHECK_UPDATES);
if (checkUpdates) FlavorTown.updateCheck(this); if (checkUpdates) FlavorTown.updateCheck(this);
} }
FlavorTown.changelogCheck(this); FlavorTown.changelogCheck(this);
new ViewModelProvider(this).get(AppStateViewModel.class); // Just initiate the App state here new ViewModelProvider(this).get(AppStateViewModel.class); // Just initiate the App state here
final Intent intent = getIntent(); final Intent intent = getIntent();
handleIntent(intent); handleIntent(intent);
if (isLoggedIn && settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) { if (isLoggedIn && settingsHelper.getBoolean(PreferenceKeys.CHECK_ACTIVITY)) {
bindActivityCheckerService(); bindActivityCheckerService();
} }
getSupportFragmentManager().addOnBackStackChangedListener(this); getSupportFragmentManager().addOnBackStackChangedListener(this);

View File

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.ListAdapter;
import awais.instagrabber.adapters.viewholder.TopicClusterViewHolder; import awais.instagrabber.adapters.viewholder.TopicClusterViewHolder;
import awais.instagrabber.databinding.ItemDiscoverTopicBinding; import awais.instagrabber.databinding.ItemDiscoverTopicBinding;
import awais.instagrabber.repositories.responses.discover.TopicCluster; import awais.instagrabber.repositories.responses.discover.TopicCluster;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.ResponseBodyUtils;
public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicClusterViewHolder> { public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicClusterViewHolder> {
@ -50,6 +51,8 @@ public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicCluste
} }
public interface OnTopicClickListener { public interface OnTopicClickListener {
void onTopicClick(TopicCluster topicCluster, View root, View cover, View title, int titleColor, int backgroundColor); void onTopicClick(TopicCluster topicCluster, View cover, int titleColor, int backgroundColor);
void onTopicLongClick(Media coverMedia);
} }
} }

View File

@ -1,26 +1,26 @@
package awais.instagrabber.adapters.viewholder; //package awais.instagrabber.adapters.viewholder;
//
import android.view.View; //import android.view.View;
import android.widget.ImageView; //import android.widget.ImageView;
//
import androidx.annotation.NonNull; //import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; //import androidx.recyclerview.widget.RecyclerView;
//
import com.facebook.drawee.view.SimpleDraweeView; //import com.facebook.drawee.view.SimpleDraweeView;
//
import awais.instagrabber.R; //import awais.instagrabber.R;
//
public final class DiscoverViewHolder extends RecyclerView.ViewHolder { //public final class DiscoverViewHolder extends RecyclerView.ViewHolder {
public final SimpleDraweeView postImage; // public final SimpleDraweeView postImage;
public final ImageView typeIcon; // public final ImageView typeIcon;
public final View selectedView; // public final View selectedView;
// public final View progressView; // // public final View progressView;
//
public DiscoverViewHolder(@NonNull final View itemView) { // public DiscoverViewHolder(@NonNull final View itemView) {
super(itemView); // super(itemView);
typeIcon = itemView.findViewById(R.id.typeIcon); // typeIcon = itemView.findViewById(R.id.typeIcon);
postImage = itemView.findViewById(R.id.postImage); // postImage = itemView.findViewById(R.id.postImage);
selectedView = itemView.findViewById(R.id.selectedView); // selectedView = itemView.findViewById(R.id.selectedView);
// progressView = itemView.findViewById(R.id.progressView); // // progressView = itemView.findViewById(R.id.progressView);
} // }
} //}

View File

@ -15,9 +15,9 @@ import awais.instagrabber.adapters.SliderItemsAdapter;
import awais.instagrabber.customviews.VideoPlayerCallbackAdapter; import awais.instagrabber.customviews.VideoPlayerCallbackAdapter;
import awais.instagrabber.customviews.VideoPlayerViewHelper; import awais.instagrabber.customviews.VideoPlayerViewHelper;
import awais.instagrabber.databinding.LayoutVideoPlayerWithThumbnailBinding; import awais.instagrabber.databinding.LayoutVideoPlayerWithThumbnailBinding;
import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.VideoVersion; import awais.instagrabber.repositories.responses.VideoVersion;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.NumberUtils; import awais.instagrabber.utils.NumberUtils;
import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
@ -55,7 +55,7 @@ public class SliderVideoViewHolder extends SliderItemViewHolder {
public void bind(@NonNull final Media media, public void bind(@NonNull final Media media,
final int position, final int position,
final SliderItemsAdapter.SliderCallback sliderCallback) { 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() { final VideoPlayerViewHelper.VideoPlayerCallback videoPlayerCallback = new VideoPlayerCallbackAdapter() {
@Override @Override

View File

@ -54,12 +54,14 @@ public class TopicClusterViewHolder extends RecyclerView.ViewHolder {
if (onTopicClickListener != null) { if (onTopicClickListener != null) {
itemView.setOnClickListener(v -> onTopicClickListener.onTopicClick( itemView.setOnClickListener(v -> onTopicClickListener.onTopicClick(
topicCluster, topicCluster,
binding.getRoot(),
binding.cover, binding.cover,
binding.title,
titleColor.get(), titleColor.get(),
backgroundColor.get() backgroundColor.get()
)); ));
itemView.setOnLongClickListener(v -> {
onTopicClickListener.onTopicLongClick(topicCluster.getCoverMedia());
return true;
});
} }
// binding.title.setTransitionName("title-" + topicCluster.getId()); // binding.title.setTransitionName("title-" + topicCluster.getId());
binding.cover.setTransitionName("cover-" + topicCluster.getId()); binding.cover.setTransitionName("cover-" + topicCluster.getId());

View File

@ -14,7 +14,7 @@ import java.util.HashSet;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.adapters.KeywordsFilterAdapter; import awais.instagrabber.adapters.KeywordsFilterAdapter;
import awais.instagrabber.utils.Constants; import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.utils.SettingsHelper; import awais.instagrabber.utils.SettingsHelper;
public class KeywordsFilterDialogViewHolder extends RecyclerView.ViewHolder { public class KeywordsFilterDialogViewHolder extends RecyclerView.ViewHolder {
@ -34,7 +34,7 @@ public class KeywordsFilterDialogViewHolder extends RecyclerView.ViewHolder {
final String s = items.get(position); final String s = items.get(position);
SettingsHelper settingsHelper = new SettingsHelper(context); SettingsHelper settingsHelper = new SettingsHelper(context);
items.remove(position); items.remove(position);
settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items)); settingsHelper.putStringSet(PreferenceKeys.KEYWORD_FILTERS, new HashSet<>(items));
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
final String message = context.getString(R.string.removed_keywords, s); final String message = context.getString(R.string.removed_keywords, s);
Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); Toast.makeText(context, message, Toast.LENGTH_SHORT).show();

View File

@ -18,9 +18,9 @@ import awais.instagrabber.adapters.FeedAdapterV2;
import awais.instagrabber.customviews.VideoPlayerCallbackAdapter; import awais.instagrabber.customviews.VideoPlayerCallbackAdapter;
import awais.instagrabber.customviews.VideoPlayerViewHelper; import awais.instagrabber.customviews.VideoPlayerViewHelper;
import awais.instagrabber.databinding.ItemFeedVideoBinding; import awais.instagrabber.databinding.ItemFeedVideoBinding;
import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.VideoVersion; import awais.instagrabber.repositories.responses.VideoVersion;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.NumberUtils; import awais.instagrabber.utils.NumberUtils;
import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
@ -65,7 +65,7 @@ public class FeedVideoViewHolder extends FeedItemViewHolder {
// Log.d(TAG, "Binding post: " + feedModel.getPostId()); // Log.d(TAG, "Binding post: " + feedModel.getPostId());
this.media = media; this.media = media;
binding.itemFeedBottom.tvVideoViews.setText(String.valueOf(media.getViewCount())); 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() { final VideoPlayerViewHelper.VideoPlayerCallback videoPlayerCallback = new VideoPlayerCallbackAdapter() {
@Override @Override

View File

@ -33,10 +33,10 @@ import awais.instagrabber.adapters.FeedAdapterV2;
import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration;
import awais.instagrabber.customviews.helpers.PostFetcher; import awais.instagrabber.customviews.helpers.PostFetcher;
import awais.instagrabber.customviews.helpers.RecyclerLazyLoaderAtEdge; import awais.instagrabber.customviews.helpers.RecyclerLazyLoaderAtEdge;
import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.PostsLayoutPreferences; import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.KeywordsFilterUtils; import awais.instagrabber.utils.KeywordsFilterUtils;
import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
@ -81,8 +81,8 @@ public class PostsRecyclerView extends RecyclerView {
} }
final List<Media> models = mediaViewModel.getList().getValue(); final List<Media> models = mediaViewModel.getList().getValue();
final List<Media> modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models); final List<Media> modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models);
if (settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)) { if (settingsHelper.getBoolean(PreferenceKeys.TOGGLE_KEYWORD_FILTER)) {
final ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS)); final ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(PreferenceKeys.KEYWORD_FILTERS));
modelsCopy.addAll(new KeywordsFilterUtils(items).filter(result)); modelsCopy.addAll(new KeywordsFilterUtils(items).filter(result));
} else { } else {
modelsCopy.addAll(result); modelsCopy.addAll(result);

View File

@ -29,7 +29,7 @@ import awais.instagrabber.utils.ExportImportUtils;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils; 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; import static awais.instagrabber.utils.DownloadUtils.PERMS;
public class CreateBackupDialogFragment extends DialogFragment { public class CreateBackupDialogFragment extends DialogFragment {

View File

@ -22,7 +22,7 @@ import java.util.HashSet;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.adapters.KeywordsFilterAdapter; import awais.instagrabber.adapters.KeywordsFilterAdapter;
import awais.instagrabber.databinding.DialogKeywordsFilterBinding; 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.SettingsHelper;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
@ -54,7 +54,7 @@ public final class KeywordsFilterDialog extends DialogFragment {
recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setLayoutManager(linearLayoutManager);
final SettingsHelper settingsHelper = new SettingsHelper(context); final SettingsHelper settingsHelper = new SettingsHelper(context);
final ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS)); final ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(PreferenceKeys.KEYWORD_FILTERS));
final KeywordsFilterAdapter adapter = new KeywordsFilterAdapter(context, items); final KeywordsFilterAdapter adapter = new KeywordsFilterAdapter(context, items);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
@ -68,7 +68,7 @@ public final class KeywordsFilterDialog extends DialogFragment {
return; return;
} }
items.add(s.toLowerCase()); items.add(s.toLowerCase());
settingsHelper.putStringSet(Constants.KEYWORD_FILTERS, new HashSet<>(items)); settingsHelper.putStringSet(PreferenceKeys.KEYWORD_FILTERS, new HashSet<>(items));
adapter.notifyItemInserted(items.size()); adapter.notifyItemInserted(items.size());
final String message = context.getString(R.string.added_keywords, s); final String message = context.getString(R.string.added_keywords, s);
Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); Toast.makeText(context, message, Toast.LENGTH_SHORT).show();

View File

@ -28,7 +28,7 @@ import awais.instagrabber.utils.PasswordUtils.IncorrectPasswordException;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils; 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; import static awais.instagrabber.utils.DownloadUtils.PERMS;
public class RestoreBackupDialogFragment extends DialogFragment { public class RestoreBackupDialogFragment extends DialogFragment {

View File

@ -114,6 +114,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
bundle.putSerializable(PostViewV2Fragment.ARG_MEDIA, feedModel); bundle.putSerializable(PostViewV2Fragment.ARG_MEDIA, feedModel);
try { try {
navController.navigate(R.id.action_global_post_view, bundle); navController.navigate(R.id.action_global_post_view, bundle);
alertDialog.dismiss();
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "onSuccess: ", e); Log.e(TAG, "onSuccess: ", e);
} }

View File

@ -82,6 +82,7 @@ import awais.instagrabber.databinding.DialogPostViewBinding;
import awais.instagrabber.databinding.LayoutPostViewBottomBinding; import awais.instagrabber.databinding.LayoutPostViewBottomBinding;
import awais.instagrabber.databinding.LayoutVideoPlayerWithThumbnailBinding; import awais.instagrabber.databinding.LayoutVideoPlayerWithThumbnailBinding;
import awais.instagrabber.dialogs.EditTextDialogFragment; import awais.instagrabber.dialogs.EditTextDialogFragment;
import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.models.Resource; import awais.instagrabber.models.Resource;
import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.Caption; 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.Media;
import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.VideoVersion; import awais.instagrabber.repositories.responses.VideoVersion;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.NullSafePair; import awais.instagrabber.utils.NullSafePair;
import awais.instagrabber.utils.NumberUtils; import awais.instagrabber.utils.NumberUtils;
@ -184,7 +184,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
// wasPaused = true; // wasPaused = true;
if (settingsHelper.getBoolean(Constants.PLAY_IN_BACKGROUND)) return; if (settingsHelper.getBoolean(PreferenceKeys.PLAY_IN_BACKGROUND)) return;
final Media media = viewModel.getMedia(); final Media media = viewModel.getMedia();
if (media == null) return; if (media == null) return;
switch (media.getMediaType()) { switch (media.getMediaType()) {
@ -1058,7 +1058,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
// gestureDetector.onTouchEvent(event); // gestureDetector.onTouchEvent(event);
// return true; // 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() { final VideoPlayerViewHelper.VideoPlayerCallback videoPlayerCallback = new VideoPlayerCallbackAdapter() {
@Override @Override
public void onThumbnailLoaded() { public void onThumbnailLoaded() {

View File

@ -74,6 +74,7 @@ import awais.instagrabber.asyncs.CreateThreadAction;
import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.customviews.helpers.SwipeGestureListener;
import awais.instagrabber.databinding.FragmentStoryViewerBinding; import awais.instagrabber.databinding.FragmentStoryViewerBinding;
import awais.instagrabber.fragments.main.ProfileFragmentDirections; import awais.instagrabber.fragments.main.ProfileFragmentDirections;
import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.interfaces.SwipeEvent; import awais.instagrabber.interfaces.SwipeEvent;
import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.FeedStoryModel;
import awais.instagrabber.models.HighlightModel; 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_THRESHOLD;
import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_VELOCITY_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; import static awais.instagrabber.utils.Utils.settingsHelper;
public class StoryViewerFragment extends Fragment { public class StoryViewerFragment extends Fragment {
@ -448,7 +449,10 @@ public class StoryViewerFragment extends Fragment {
binding.swipeUp.setOnClickListener(v -> { binding.swipeUp.setOnClickListener(v -> {
final Object tag = v.getTag(); final Object tag = v.getTag();
if (tag instanceof CharSequence) { if (tag instanceof CharSequence) {
Utils.openURL(context, tag.toString()); 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 -> { binding.viewStoryPost.setOnClickListener(v -> {
@ -468,6 +472,7 @@ public class StoryViewerFragment extends Fragment {
bundle.putSerializable(PostViewV2Fragment.ARG_MEDIA, feedModel); bundle.putSerializable(PostViewV2Fragment.ARG_MEDIA, feedModel);
try { try {
navController.navigate(R.id.action_global_post_view, bundle); navController.navigate(R.id.action_global_post_view, bundle);
alertDialog.dismiss();
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "openPostDialog: ", e); Log.e(TAG, "openPostDialog: ", e);
} }
@ -990,7 +995,7 @@ public class StoryViewerFragment extends Fragment {
if (context == null) return; if (context == null) return;
player = new SimpleExoPlayer.Builder(context).build(); player = new SimpleExoPlayer.Builder(context).build();
binding.playerView.setPlayer(player); 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 Uri uri = Uri.parse(url);
final MediaItem mediaItem = MediaItem.fromUri(uri); final MediaItem mediaItem = MediaItem.fromUri(uri);
@ -1091,7 +1096,7 @@ public class StoryViewerFragment extends Fragment {
if (context == null) return; if (context == null) return;
player = new SimpleExoPlayer.Builder(context).build(); player = new SimpleExoPlayer.Builder(context).build();
binding.playerView.setPlayer(player); 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 Uri uri = Uri.parse(url);
final MediaItem mediaItem = MediaItem.fromUri(uri); final MediaItem mediaItem = MediaItem.fromUri(uri);

View File

@ -101,6 +101,7 @@ import awais.instagrabber.dialogs.MediaPickerBottomDialogFragment;
import awais.instagrabber.fragments.PostViewV2Fragment; import awais.instagrabber.fragments.PostViewV2Fragment;
import awais.instagrabber.fragments.UserSearchFragment; import awais.instagrabber.fragments.UserSearchFragment;
import awais.instagrabber.fragments.UserSearchFragmentDirections; import awais.instagrabber.fragments.UserSearchFragmentDirections;
import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.models.Resource; import awais.instagrabber.models.Resource;
import awais.instagrabber.models.enums.DirectItemType; import awais.instagrabber.models.enums.DirectItemType;
import awais.instagrabber.models.enums.MediaItemType; 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.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.RankedRecipient; import awais.instagrabber.repositories.responses.directmessages.RankedRecipient;
import awais.instagrabber.utils.AppExecutors; import awais.instagrabber.utils.AppExecutors;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.DMUtils; import awais.instagrabber.utils.DMUtils;
import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.PermissionUtils; import awais.instagrabber.utils.PermissionUtils;
@ -356,7 +356,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
fragmentActivity = (MainActivity) requireActivity(); fragmentActivity = (MainActivity) requireActivity();
appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class); 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(); final Bundle arguments = getArguments();
if (arguments == null) return; if (arguments == null) return;
final DirectMessageThreadFragmentArgs fragmentArgs = DirectMessageThreadFragmentArgs.fromBundle(arguments); final DirectMessageThreadFragmentArgs fragmentArgs = DirectMessageThreadFragmentArgs.fromBundle(arguments);

View File

@ -5,24 +5,35 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.fragment.FragmentNavigator; import androidx.navigation.fragment.FragmentNavigator;
import androidx.navigation.fragment.NavHostFragment; import androidx.navigation.fragment.NavHostFragment;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; 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.activities.MainActivity;
import awais.instagrabber.adapters.DiscoverTopicsAdapter; import awais.instagrabber.adapters.DiscoverTopicsAdapter;
import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration;
import awais.instagrabber.databinding.FragmentDiscoverBinding; 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.repositories.responses.discover.TopicalExploreFeedResponse;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.TopicClusterViewModel; import awais.instagrabber.viewmodels.TopicClusterViewModel;
import awais.instagrabber.webservices.DiscoverService; import awais.instagrabber.webservices.DiscoverService;
import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
@ -34,12 +45,14 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
private TopicClusterViewModel topicClusterViewModel; private TopicClusterViewModel topicClusterViewModel;
private boolean shouldRefresh = true; private boolean shouldRefresh = true;
private DiscoverService discoverService; private DiscoverService discoverService;
private MediaService mediaService;
@Override @Override
public void onCreate(@Nullable final Bundle savedInstanceState) { public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
fragmentActivity = (MainActivity) requireActivity(); fragmentActivity = (MainActivity) requireActivity();
discoverService = DiscoverService.getInstance(); discoverService = DiscoverService.getInstance();
mediaService = MediaService.getInstance(null, null, 0);
} }
@Override @Override
@ -76,13 +89,47 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
public void setupTopics() { public void setupTopics() {
topicClusterViewModel = new ViewModelProvider(fragmentActivity).get(TopicClusterViewModel.class); topicClusterViewModel = new ViewModelProvider(fragmentActivity).get(TopicClusterViewModel.class);
binding.topicsRecyclerView.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(2))); binding.topicsRecyclerView.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(2)));
final DiscoverTopicsAdapter adapter = new DiscoverTopicsAdapter((topicCluster, root, cover, title, titleColor, backgroundColor) -> { 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() final FragmentNavigator.Extras.Builder builder = new FragmentNavigator.Extras.Builder()
.addSharedElement(cover, "cover-" + topicCluster.getId()); .addSharedElement(cover, "cover-" + topicCluster.getId());
final DiscoverFragmentDirections.ActionDiscoverFragmentToTopicPostsFragment action = DiscoverFragmentDirections final DiscoverFragmentDirections.ActionDiscoverFragmentToTopicPostsFragment action = DiscoverFragmentDirections
.actionDiscoverFragmentToTopicPostsFragment(topicCluster, titleColor, backgroundColor); .actionDiscoverFragmentToTopicPostsFragment(topicCluster, titleColor, backgroundColor);
NavHostFragment.findNavController(this).navigate(action, builder.build()); 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<Media>() {
@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); binding.topicsRecyclerView.setAdapter(adapter);
topicClusterViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList); topicClusterViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList);
} }
@ -93,8 +140,18 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
@Override @Override
public void onSuccess(final TopicalExploreFeedResponse result) { public void onSuccess(final TopicalExploreFeedResponse result) {
if (result == null) return; if (result == null) return;
topicClusterViewModel.getList().postValue(result.getClusters()); final List<TopicCluster> clusters = result.getClusters();
binding.swipeRefreshLayout.setRefreshing(false); 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 @Override

View File

@ -1,5 +1,6 @@
package awais.instagrabber.fragments.search; package awais.instagrabber.fragments.search;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
@ -7,6 +8,7 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -36,6 +38,9 @@ import awais.instagrabber.models.enums.FavoriteType;
import awais.instagrabber.repositories.responses.search.SearchItem; import awais.instagrabber.repositories.responses.search.SearchItem;
import awais.instagrabber.viewmodels.SearchFragmentViewModel; 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 { public class SearchFragment extends Fragment implements SearchCategoryFragment.OnSearchItemClickListener {
private static final String TAG = SearchFragment.class.getSimpleName(); private static final String TAG = SearchFragment.class.getSimpleName();
private static final String QUERY = "query"; private static final String QUERY = "query";
@ -119,9 +124,11 @@ public class SearchFragment extends Fragment implements SearchCategoryFragment.O
if (mainActivity != null) { if (mainActivity != null) {
mainActivity.showSearchView(); mainActivity.showSearchView();
} }
// if (searchInputLayout != null) { if (settingsHelper.getBoolean(PREF_SEARCH_FOCUS_KEYBOARD)) {
// searchInputLayout.requestFocus(); 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) { private void init(@Nullable final Bundle savedInstanceState) {
@ -147,7 +154,11 @@ public class SearchFragment extends Fragment implements SearchCategoryFragment.O
searchInput.setText(savedQuery); searchInput.setText(savedQuery);
triggerEmptyQuery = false; 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) { if (triggerEmptyQuery) {
viewModel.submitQuery(""); viewModel.submitQuery("");
} }

View File

@ -41,7 +41,7 @@ public abstract class BasePreferencesFragment extends PreferenceFragmentCompat i
if (!shouldRecreate) return; if (!shouldRecreate) return;
final MainActivity activity = (MainActivity) getActivity(); final MainActivity activity = (MainActivity) getActivity();
if (activity == null) return; if (activity == null) return;
if (key.equals(Constants.APP_LANGUAGE)) { if (key.equals(PreferenceKeys.APP_LANGUAGE)) {
LocaleUtils.setLocale(activity.getBaseContext()); LocaleUtils.setLocale(activity.getBaseContext());
} }
shouldRecreate = false; shouldRecreate = false;

View File

@ -20,7 +20,6 @@ import awais.instagrabber.customviews.helpers.TextWatcherAdapter;
import awais.instagrabber.databinding.PrefAutoRefreshDmFreqBinding; import awais.instagrabber.databinding.PrefAutoRefreshDmFreqBinding;
import awais.instagrabber.services.DMSyncAlarmReceiver; import awais.instagrabber.services.DMSyncAlarmReceiver;
import awais.instagrabber.services.DMSyncService; import awais.instagrabber.services.DMSyncService;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.Debouncer; import awais.instagrabber.utils.Debouncer;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
@ -43,7 +42,7 @@ public class DMPreferencesFragment extends BasePreferencesFragment {
private Preference getMarkDMSeenPreference(@NonNull final Context context) { private Preference getMarkDMSeenPreference(@NonNull final Context context) {
return PreferenceHelper.getSwitchPreference( return PreferenceHelper.getSwitchPreference(
context, 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,
R.string.dm_mark_as_seen_setting_summary, R.string.dm_mark_as_seen_setting_summary,
false, false,

View File

@ -14,12 +14,11 @@ import androidx.preference.SwitchPreferenceCompat;
import com.google.android.material.switchmaterial.SwitchMaterial; import com.google.android.material.switchmaterial.SwitchMaterial;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.DirectoryChooser; import awais.instagrabber.utils.DirectoryChooser;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import static awais.instagrabber.utils.Constants.FOLDER_PATH; import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_PATH;
import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO; import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_SAVE_TO;
import static awais.instagrabber.utils.Utils.settingsHelper; import static awais.instagrabber.utils.Utils.settingsHelper;
public class DownloadsPreferencesFragment extends BasePreferencesFragment { public class DownloadsPreferencesFragment extends BasePreferencesFragment {
@ -34,7 +33,7 @@ public class DownloadsPreferencesFragment extends BasePreferencesFragment {
private Preference getDownloadUserFolderPreference(@NonNull final Context context) { private Preference getDownloadUserFolderPreference(@NonNull final Context context) {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(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.setTitle(R.string.download_user_folder);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
return preference; return preference;
@ -52,7 +51,7 @@ public class DownloadsPreferencesFragment extends BasePreferencesFragment {
private Preference getPrependUsernameToFilenamePreference(@NonNull final Context context) { private Preference getPrependUsernameToFilenamePreference(@NonNull final Context context) {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(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.setTitle(R.string.download_prepend_username);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
return preference; return preference;
@ -66,7 +65,7 @@ public class DownloadsPreferencesFragment extends BasePreferencesFragment {
public SaveToCustomFolderPreference(final Context context, final OnSelectFolderButtonClickListener onSelectFolderButtonClickListener) { public SaveToCustomFolderPreference(final Context context, final OnSelectFolderButtonClickListener onSelectFolderButtonClickListener) {
super(context); super(context);
this.onSelectFolderButtonClickListener = onSelectFolderButtonClickListener; this.onSelectFolderButtonClickListener = onSelectFolderButtonClickListener;
key = Constants.FOLDER_SAVE_TO; key = PreferenceKeys.FOLDER_SAVE_TO;
setLayoutResource(R.layout.pref_custom_folder); setLayoutResource(R.layout.pref_custom_folder);
setKey(key); setKey(key);
setTitle(R.string.save_to_folder); setTitle(R.string.save_to_folder);

View File

@ -36,6 +36,7 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen
} }
screen.addPreference(getUpdateCheckPreference(context)); screen.addPreference(getUpdateCheckPreference(context));
screen.addPreference(getFlagSecurePreference(context)); screen.addPreference(getFlagSecurePreference(context));
screen.addPreference(getSearchFocusPreference(context));
final List<Preference> preferences = FlavorSettings.getInstance() final List<Preference> preferences = FlavorSettings.getInstance()
.getPreferences(context, .getPreferences(context,
getChildFragmentManager(), getChildFragmentManager(),
@ -82,7 +83,7 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen
private Preference getUpdateCheckPreference(@NonNull final Context context) { private Preference getUpdateCheckPreference(@NonNull final Context context) {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context);
preference.setKey(Constants.CHECK_UPDATES); preference.setKey(PreferenceKeys.CHECK_UPDATES);
preference.setTitle(R.string.update_check); preference.setTitle(R.string.update_check);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
return preference; return preference;
@ -91,7 +92,7 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen
private Preference getFlagSecurePreference(@NonNull final Context context) { private Preference getFlagSecurePreference(@NonNull final Context context) {
return PreferenceHelper.getSwitchPreference( return PreferenceHelper.getSwitchPreference(
context, context,
Constants.FLAG_SECURE, PreferenceKeys.FLAG_SECURE,
R.string.flag_secure, R.string.flag_secure,
-1, -1,
false, false,
@ -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 @Override
public void onSave(final boolean orderHasChanged) { public void onSave(final boolean orderHasChanged) {
if (!orderHasChanged) return; if (!orderHasChanged) return;

View File

@ -36,7 +36,7 @@ public class LocalePreferencesFragment extends BasePreferencesFragment {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
values[i] = String.valueOf(i); values[i] = String.valueOf(i);
} }
preference.setKey(Constants.APP_LANGUAGE); preference.setKey(PreferenceKeys.APP_LANGUAGE);
preference.setTitle(R.string.select_language); preference.setTitle(R.string.select_language);
preference.setDialogTitle(R.string.select_language); preference.setDialogTitle(R.string.select_language);
preference.setEntries(R.array.languages); preference.setEntries(R.array.languages);
@ -59,10 +59,10 @@ public class LocalePreferencesFragment extends BasePreferencesFragment {
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
preference.setOnPreferenceClickListener(preference1 -> { preference.setOnPreferenceClickListener(preference1 -> {
new TimeSettingsDialog( new TimeSettingsDialog(
settingsHelper.getBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED), settingsHelper.getBoolean(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT_ENABLED),
settingsHelper.getString(Constants.CUSTOM_DATE_TIME_FORMAT), settingsHelper.getString(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT),
settingsHelper.getString(Constants.DATE_TIME_SELECTION), settingsHelper.getString(PreferenceKeys.DATE_TIME_SELECTION),
settingsHelper.getBoolean(Constants.SWAP_DATE_TIME_FORMAT_ENABLED), settingsHelper.getBoolean(PreferenceKeys.SWAP_DATE_TIME_FORMAT_ENABLED),
(isCustomFormat, (isCustomFormat,
formatSelection, formatSelection,
spTimeFormatSelectedItemPosition, spTimeFormatSelectedItemPosition,
@ -72,16 +72,16 @@ public class LocalePreferencesFragment extends BasePreferencesFragment {
currentFormat, currentFormat,
swapDateTime) -> { swapDateTime) -> {
if (isCustomFormat) { if (isCustomFormat) {
settingsHelper.putString(Constants.CUSTOM_DATE_TIME_FORMAT, formatSelection); settingsHelper.putString(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT, formatSelection);
} else { } else {
final String formatSelectionUpdated = spTimeFormatSelectedItemPosition + ";" final String formatSelectionUpdated = spTimeFormatSelectedItemPosition + ";"
+ spSeparatorSelectedItemPosition + ';' + spSeparatorSelectedItemPosition + ';'
+ spDateFormatSelectedItemPosition; // time;separator;date + spDateFormatSelectedItemPosition; // time;separator;date
settingsHelper.putString(Constants.DATE_TIME_FORMAT, selectedFormat); settingsHelper.putString(PreferenceKeys.DATE_TIME_FORMAT, selectedFormat);
settingsHelper.putString(Constants.DATE_TIME_SELECTION, formatSelectionUpdated); settingsHelper.putString(PreferenceKeys.DATE_TIME_SELECTION, formatSelectionUpdated);
} }
settingsHelper.putBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED, isCustomFormat); settingsHelper.putBoolean(PreferenceKeys.CUSTOM_DATE_TIME_FORMAT_ENABLED, isCustomFormat);
settingsHelper.putBoolean(Constants.SWAP_DATE_TIME_FORMAT_ENABLED, swapDateTime); settingsHelper.putBoolean(PreferenceKeys.SWAP_DATE_TIME_FORMAT_ENABLED, swapDateTime);
Utils.datetimeParser = (SimpleDateFormat) currentFormat.clone(); Utils.datetimeParser = (SimpleDateFormat) currentFormat.clone();
preference.setSummary(Utils.datetimeParser.format(new Date())); preference.setSummary(Utils.datetimeParser.format(new Date()));
} }

View File

@ -7,7 +7,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.utils.Constants;
public class NotificationsPreferencesFragment extends BasePreferencesFragment { public class NotificationsPreferencesFragment extends BasePreferencesFragment {
@Override @Override
@ -21,7 +20,7 @@ public class NotificationsPreferencesFragment extends BasePreferencesFragment {
private Preference getActivityNotificationsPreference(@NonNull final Context context) { private Preference getActivityNotificationsPreference(@NonNull final Context context) {
return PreferenceHelper.getSwitchPreference( return PreferenceHelper.getSwitchPreference(
context, context,
Constants.CHECK_ACTIVITY, PreferenceKeys.CHECK_ACTIVITY,
R.string.activity_setting, R.string.activity_setting,
-1, -1,
false, false,

View File

@ -9,7 +9,6 @@ import androidx.preference.SwitchPreferenceCompat;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.dialogs.KeywordsFilterDialog; import awais.instagrabber.dialogs.KeywordsFilterDialog;
import awais.instagrabber.utils.Constants;
public class PostPreferencesFragment extends BasePreferencesFragment { public class PostPreferencesFragment extends BasePreferencesFragment {
@Override @Override
@ -34,7 +33,7 @@ public class PostPreferencesFragment extends BasePreferencesFragment {
private Preference getBackgroundPlayPreference(@NonNull final Context context) { private Preference getBackgroundPlayPreference(@NonNull final Context context) {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(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.setTitle(R.string.post_viewer_background_play);
preference.setSummary(R.string.post_viewer_background_play_summary); preference.setSummary(R.string.post_viewer_background_play_summary);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
@ -43,7 +42,7 @@ public class PostPreferencesFragment extends BasePreferencesFragment {
private Preference getAlwaysMuteVideosPreference(@NonNull final Context context) { private Preference getAlwaysMuteVideosPreference(@NonNull final Context context) {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(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.setTitle(R.string.post_viewer_muted_autoplay);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
return preference; return preference;
@ -51,7 +50,7 @@ public class PostPreferencesFragment extends BasePreferencesFragment {
private Preference getShowCaptionPreference(@NonNull final Context context) { private Preference getShowCaptionPreference(@NonNull final Context context) {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context);
preference.setKey(Constants.SHOW_CAPTIONS); preference.setKey(PreferenceKeys.SHOW_CAPTIONS);
preference.setDefaultValue(true); preference.setDefaultValue(true);
preference.setTitle(R.string.post_viewer_show_captions); preference.setTitle(R.string.post_viewer_show_captions);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
@ -60,7 +59,7 @@ public class PostPreferencesFragment extends BasePreferencesFragment {
private Preference getToggleKeywordFilterPreference(@NonNull final Context context) { private Preference getToggleKeywordFilterPreference(@NonNull final Context context) {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context); final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context);
preference.setKey(Constants.TOGGLE_KEYWORD_FILTER); preference.setKey(PreferenceKeys.TOGGLE_KEYWORD_FILTER);
preference.setDefaultValue(false); preference.setDefaultValue(false);
preference.setTitle(R.string.toggle_keyword_filter); preference.setTitle(R.string.toggle_keyword_filter);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);

View File

@ -1,6 +1,7 @@
package awais.instagrabber.fragments.settings; package awais.instagrabber.fragments.settings;
public final class PreferenceKeys { 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_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 = "enable_dm_auto_refresh";
public static final String PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT = "enable_dm_auto_refresh_freq_unit"; public static final String PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT = "enable_dm_auto_refresh_freq_unit";
@ -8,4 +9,32 @@ public final class PreferenceKeys {
public static final String PREF_ENABLE_SENTRY = "enable_sentry"; public static final String PREF_ENABLE_SENTRY = "enable_sentry";
public static final String PREF_TAB_ORDER = "tab_order"; 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_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";
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";
// 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";
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";
public static final String CHECK_ACTIVITY = "check_activity";
public static final String CHECK_UPDATES = "check_updates";
public static final String FLAG_SECURE = "flag_secure";
} }

View File

@ -9,7 +9,6 @@ import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreferenceCompat; import androidx.preference.SwitchPreferenceCompat;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.utils.Constants;
public class StoriesPreferencesFragment extends BasePreferencesFragment { public class StoriesPreferencesFragment extends BasePreferencesFragment {
@Override @Override
@ -29,7 +28,7 @@ public class StoriesPreferencesFragment extends BasePreferencesFragment {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
values[i] = String.valueOf(i); values[i] = String.valueOf(i);
} }
preference.setKey(Constants.STORY_SORT); preference.setKey(PreferenceKeys.STORY_SORT);
preference.setTitle(R.string.story_sort_setting); preference.setTitle(R.string.story_sort_setting);
preference.setDialogTitle(R.string.story_sort_setting); preference.setDialogTitle(R.string.story_sort_setting);
preference.setEntries(R.array.story_sorts); preference.setEntries(R.array.story_sorts);
@ -40,7 +39,7 @@ public class StoriesPreferencesFragment extends BasePreferencesFragment {
private Preference getHideMutedReelsPreference(@NonNull final Context context) { private Preference getHideMutedReelsPreference(@NonNull final Context context) {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(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.setTitle(R.string.hide_muted_reels_setting);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);
return preference; return preference;
@ -48,7 +47,7 @@ public class StoriesPreferencesFragment extends BasePreferencesFragment {
private Preference getMarkStoriesSeenPreference(@NonNull final Context context) { private Preference getMarkStoriesSeenPreference(@NonNull final Context context) {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(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.setTitle(R.string.mark_as_seen_setting);
preference.setSummary(R.string.mark_as_seen_setting_summary); preference.setSummary(R.string.mark_as_seen_setting_summary);
preference.setIconSpaceReserved(false); preference.setIconSpaceReserved(false);

View File

@ -29,7 +29,7 @@ public class ThemePreferencesFragment extends BasePreferencesFragment {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
values[i] = String.valueOf(i); values[i] = String.valueOf(i);
} }
preference.setKey(Constants.APP_THEME); preference.setKey(PreferenceKeys.APP_THEME);
preference.setTitle(R.string.theme_settings); preference.setTitle(R.string.theme_settings);
preference.setDialogTitle(R.string.theme_settings); preference.setDialogTitle(R.string.theme_settings);
preference.setEntries(R.array.theme_presets); preference.setEntries(R.array.theme_presets);

View File

@ -11,7 +11,7 @@ public class TopicCluster implements Serializable {
private final boolean canMute; private final boolean canMute;
private final boolean isMuted; private final boolean isMuted;
private final int rankedPosition; private final int rankedPosition;
private final Media coverMedia; private Media coverMedia;
public TopicCluster(final String id, public TopicCluster(final String id,
final String title, final String title,
@ -56,4 +56,8 @@ public class TopicCluster implements Serializable {
public Media getCoverMedia() { public Media getCoverMedia() {
return coverMedia; return coverMedia;
} }
public void setCoverMedia(final Media coverMedia) {
this.coverMedia = coverMedia;
}
} }

View File

@ -3,45 +3,13 @@ package awais.instagrabber.utils;
public final class Constants { public final class Constants {
public static final String CRASH_REPORT_EMAIL = "barinsta@austinhuang.me"; 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 // int prefs, do not export
public static final String PREV_INSTALL_VERSION = "prevVersion"; public static final String PREV_INSTALL_VERSION = "prevVersion";
public static final String BROWSER_UA_CODE = "browser_ua_code"; public static final String BROWSER_UA_CODE = "browser_ua_code";
public static final String APP_UA_CODE = "app_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 // never Export
public static final String COOKIE = "cookie"; 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 DEVICE_UUID = "device_uuid";
public static final String BROWSER_UA = "browser_ua"; public static final String BROWSER_UA = "browser_ua";
public static final String APP_UA = "app_ua"; public static final String APP_UA = "app_ua";

View File

@ -33,6 +33,7 @@ import java.util.UUID;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.Audio; 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.repositories.responses.VideoVersion;
import awais.instagrabber.workers.DownloadWorker; import awais.instagrabber.workers.DownloadWorker;
import static awais.instagrabber.utils.Constants.FOLDER_PATH; import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_PATH;
import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO; import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_SAVE_TO;
public final class DownloadUtils { public final class DownloadUtils {
private static final String TAG = "DownloadUtils"; private static final String TAG = "DownloadUtils";
@ -74,7 +75,7 @@ public final class DownloadUtils {
final boolean skipCreateDir) { final boolean skipCreateDir) {
File dir = getDownloadDir(); 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; final String finaleUsername = username.startsWith("@") ? username.substring(1) : username;
dir = new File(dir, finaleUsername); dir = new File(dir, finaleUsername);
} }
@ -277,7 +278,7 @@ public final class DownloadUtils {
: storyModel.getStoryUrl(); : storyModel.getStoryUrl();
final String baseFileName = storyModel.getStoryMediaId() + "_" final String baseFileName = storyModel.getStoryMediaId() + "_"
+ storyModel.getTimestamp() + DownloadUtils.getFileExtensionFromUrl(url); + 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() + "_" : ""; && storyModel.getUsername() != null ? storyModel.getUsername() + "_" : "";
final File saveFile = new File(downloadDir, final File saveFile = new File(downloadDir,
usernamePrepend + baseFileName); usernamePrepend + baseFileName);
@ -318,7 +319,7 @@ public final class DownloadUtils {
} }
if (!TextUtils.isEmpty(media.getCode())) { if (!TextUtils.isEmpty(media.getCode())) {
fileName = 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; fileName = mediaUser.getUsername() + "_" + fileName;
} }
} }
@ -344,7 +345,7 @@ public final class DownloadUtils {
} }
final Media child = sliderItems.get(i); final Media child = sliderItems.get(i);
final String url = getUrlOfType(child); 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); final File file = getDownloadChildSaveFile(downloadDir, media.getCode(), i + 1, url, usernamePrepend);
map.put(url, file.getAbsolutePath()); map.put(url, file.getAbsolutePath());
} }

View File

@ -9,6 +9,8 @@ import androidx.annotation.Nullable;
import java.util.Locale; import java.util.Locale;
import awais.instagrabber.fragments.settings.PreferenceKeys;
// taken from my app TESV Console Codes // taken from my app TESV Console Codes
public final class LocaleUtils { public final class LocaleUtils {
private static Locale defaultLocale, currentLocale; private static Locale defaultLocale, currentLocale;
@ -22,7 +24,7 @@ public final class LocaleUtils {
if (Utils.settingsHelper == null) if (Utils.settingsHelper == null)
Utils.settingsHelper = new SettingsHelper(baseContext); 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); final String lang = LocaleUtils.getCorrespondingLanguageCode(appLanguageSettings);
currentLocale = TextUtils.isEmpty(lang) ? defaultLocale : currentLocale = TextUtils.isEmpty(lang) ? defaultLocale :

View File

@ -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_ENABLE_SENTRY;
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_SHOWN_COUNT_TOOLTIP; 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.fragments.settings.PreferenceKeys.PREF_TAB_ORDER;
import static awais.instagrabber.utils.Constants.APP_LANGUAGE; import static awais.instagrabber.fragments.settings.PreferenceKeys.APP_LANGUAGE;
import static awais.instagrabber.utils.Constants.APP_THEME; 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;
import static awais.instagrabber.utils.Constants.APP_UA_CODE; 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;
import static awais.instagrabber.utils.Constants.BROWSER_UA_CODE; import static awais.instagrabber.utils.Constants.BROWSER_UA_CODE;
import static awais.instagrabber.utils.Constants.CHECK_ACTIVITY; import static awais.instagrabber.fragments.settings.PreferenceKeys.CHECK_ACTIVITY;
import static awais.instagrabber.utils.Constants.CHECK_UPDATES; import static awais.instagrabber.fragments.settings.PreferenceKeys.CHECK_UPDATES;
import static awais.instagrabber.utils.Constants.COOKIE; import static awais.instagrabber.utils.Constants.COOKIE;
import static awais.instagrabber.utils.Constants.CUSTOM_DATE_TIME_FORMAT; import static awais.instagrabber.fragments.settings.PreferenceKeys.CUSTOM_DATE_TIME_FORMAT;
import static awais.instagrabber.utils.Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED; import static awais.instagrabber.fragments.settings.PreferenceKeys.CUSTOM_DATE_TIME_FORMAT_ENABLED;
import static awais.instagrabber.utils.Constants.DATE_TIME_FORMAT; import static awais.instagrabber.fragments.settings.PreferenceKeys.DATE_TIME_FORMAT;
import static awais.instagrabber.utils.Constants.DATE_TIME_SELECTION; import static awais.instagrabber.fragments.settings.PreferenceKeys.DATE_TIME_SELECTION;
import static awais.instagrabber.utils.Constants.DEFAULT_TAB; import static awais.instagrabber.utils.Constants.DEFAULT_TAB;
import static awais.instagrabber.utils.Constants.DEVICE_UUID; import static awais.instagrabber.utils.Constants.DEVICE_UUID;
import static awais.instagrabber.utils.Constants.DM_MARK_AS_SEEN; import static awais.instagrabber.fragments.settings.PreferenceKeys.DM_MARK_AS_SEEN;
import static awais.instagrabber.utils.Constants.DOWNLOAD_PREPEND_USER_NAME; import static awais.instagrabber.fragments.settings.PreferenceKeys.DOWNLOAD_PREPEND_USER_NAME;
import static awais.instagrabber.utils.Constants.DOWNLOAD_USER_FOLDER; import static awais.instagrabber.fragments.settings.PreferenceKeys.DOWNLOAD_USER_FOLDER;
import static awais.instagrabber.utils.Constants.FLAG_SECURE; import static awais.instagrabber.fragments.settings.PreferenceKeys.FLAG_SECURE;
import static awais.instagrabber.utils.Constants.FOLDER_PATH; import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_PATH;
import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO; import static awais.instagrabber.fragments.settings.PreferenceKeys.FOLDER_SAVE_TO;
import static awais.instagrabber.utils.Constants.HIDE_MUTED_REELS; import static awais.instagrabber.fragments.settings.PreferenceKeys.HIDE_MUTED_REELS;
import static awais.instagrabber.utils.Constants.KEYWORD_FILTERS; import static awais.instagrabber.fragments.settings.PreferenceKeys.KEYWORD_FILTERS;
import static awais.instagrabber.utils.Constants.MARK_AS_SEEN; import static awais.instagrabber.fragments.settings.PreferenceKeys.MARK_AS_SEEN;
import static awais.instagrabber.utils.Constants.MUTED_VIDEOS; import static awais.instagrabber.fragments.settings.PreferenceKeys.MUTED_VIDEOS;
import static awais.instagrabber.utils.Constants.PLAY_IN_BACKGROUND; 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_DARK_THEME;
import static awais.instagrabber.utils.Constants.PREF_EMOJI_VARIANTS; import static awais.instagrabber.utils.Constants.PREF_EMOJI_VARIANTS;
import static awais.instagrabber.utils.Constants.PREF_HASHTAG_POSTS_LAYOUT; 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_TAGGED_POSTS_LAYOUT;
import static awais.instagrabber.utils.Constants.PREF_TOPIC_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.PREV_INSTALL_VERSION;
import static awais.instagrabber.utils.Constants.SHOW_CAPTIONS; import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_SEARCH_FOCUS_KEYBOARD;
import static awais.instagrabber.utils.Constants.SHOW_QUICK_ACCESS_DIALOG; import static awais.instagrabber.fragments.settings.PreferenceKeys.SHOW_CAPTIONS;
import static awais.instagrabber.utils.Constants.SKIPPED_VERSION; import static awais.instagrabber.utils.Constants.SKIPPED_VERSION;
import static awais.instagrabber.utils.Constants.STORY_SORT; import static awais.instagrabber.fragments.settings.PreferenceKeys.STORY_SORT;
import static awais.instagrabber.utils.Constants.SWAP_DATE_TIME_FORMAT_ENABLED; import static awais.instagrabber.fragments.settings.PreferenceKeys.SWAP_DATE_TIME_FORMAT_ENABLED;
import static awais.instagrabber.utils.Constants.TOGGLE_KEYWORD_FILTER; import static awais.instagrabber.fragments.settings.PreferenceKeys.TOGGLE_KEYWORD_FILTER;
public final class SettingsHelper { public final class SettingsHelper {
private final SharedPreferences sharedPreferences; private final SharedPreferences sharedPreferences;
@ -155,18 +155,18 @@ public final class SettingsHelper {
return sharedPreferences != null && sharedPreferences.contains(key); return sharedPreferences != null && sharedPreferences.contains(key);
} }
@StringDef( @StringDef({APP_LANGUAGE, APP_THEME, APP_UA, BROWSER_UA, COOKIE, FOLDER_PATH, DATE_TIME_FORMAT, DATE_TIME_SELECTION,
{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, 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_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, 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}) STORY_SORT, PREF_EMOJI_VARIANTS, PREF_REACTIONS, PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT, PREF_TAB_ORDER})
public @interface StringSettings {} 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, 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, 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 {} public @interface BooleanSettings {}
@StringDef({PREV_INSTALL_VERSION, BROWSER_UA_CODE, APP_UA_CODE, PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER}) @StringDef({PREV_INSTALL_VERSION, BROWSER_UA_CODE, APP_UA_CODE, PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER})

View File

@ -10,11 +10,13 @@ import android.util.Patterns;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.stream.Collectors;
public final class TextUtils { public final class TextUtils {
// extracted from String class // extracted from String class
@ -106,4 +108,15 @@ public final class TextUtils {
} }
return urls; 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;
}
} }

View File

@ -17,12 +17,12 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.FeedStoryModel;
import awais.instagrabber.models.HighlightModel; import awais.instagrabber.models.HighlightModel;
import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.StoryModel;
import awais.instagrabber.repositories.StoriesRepository; import awais.instagrabber.repositories.StoriesRepository;
import awais.instagrabber.repositories.requests.StoryViewerOptions; import awais.instagrabber.repositories.requests.StoryViewerOptions;
import awais.instagrabber.repositories.responses.FriendshipStatus;
import awais.instagrabber.repositories.responses.StoryStickerResponse; import awais.instagrabber.repositories.responses.StoryStickerResponse;
import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
@ -135,7 +135,7 @@ public class StoriesService extends BaseService {
final JSONArray feedStoriesReel = new JSONObject(body).getJSONArray("tray"); final JSONArray feedStoriesReel = new JSONObject(body).getJSONArray("tray");
for (int i = 0; i < feedStoriesReel.length(); ++i) { for (int i = 0; i < feedStoriesReel.length(); ++i) {
final JSONObject node = feedStoriesReel.getJSONObject(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"); final JSONObject userJson = node.getJSONObject(node.has("user") ? "user" : "owner");
try { try {
final User user = new User(userJson.getLong("pk"), final User user = new User(userJson.getLong("pk"),
@ -505,7 +505,7 @@ public class StoriesService extends BaseService {
final List<FeedStoryModel> listCopy = new ArrayList<>(list); final List<FeedStoryModel> listCopy = new ArrayList<>(list);
Collections.sort(listCopy, (o1, o2) -> { Collections.sort(listCopy, (o1, o2) -> {
int result; int result;
switch (Utils.settingsHelper.getString(Constants.STORY_SORT)) { switch (Utils.settingsHelper.getString(PreferenceKeys.STORY_SORT)) {
case "1": case "1":
result = Long.compare(o2.getTimestamp(), o1.getTimestamp()); result = Long.compare(o2.getTimestamp(), o1.getTimestamp());
break; break;

View File

@ -235,7 +235,7 @@
<string name="request_approve">Approve request</string> <string name="request_approve">Approve request</string>
<string name="request_reject">Reject request</string> <string name="request_reject">Reject request</string>
<string name="share_public_post">Share this public post to…</string> <string name="share_public_post">Share this public post to…</string>
<string name="share_private_post">This is a private post! Share to those who can view them!</string> <string name="share_private_post">This is a private post! Share to those who can view it.</string>
<string name="discover_empty">This category is somehow empty…</string> <string name="discover_empty">This category is somehow empty…</string>
<string name="update_available">An update is available! (%s)</string> <string name="update_available">An update is available! (%s)</string>
<string name="update_notice">Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub.</string> <string name="update_notice">Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub.</string>
@ -269,6 +269,7 @@
<string name="skip_update_checkbox">Do not show again until next update</string> <string name="skip_update_checkbox">Do not show again until next update</string>
<string name="version">Version</string> <string name="version">Version</string>
<string name="pref_start_screen">Start screen</string> <string name="pref_start_screen">Start screen</string>
<string name="pref_search_focus_keyboard" comment="basically bring up the keyboard immediately when someone does search">Show keyboard on search</string>
<string name="pref_category_general">General</string> <string name="pref_category_general">General</string>
<string name="pref_category_theme">Theme</string> <string name="pref_category_theme">Theme</string>
<string name="pref_category_downloads">Downloads</string> <string name="pref_category_downloads">Downloads</string>
@ -505,4 +506,5 @@
<string name="no_external_map_app">No Map app found!</string> <string name="no_external_map_app">No Map app found!</string>
<string name="click_to_show_full">Click to view full count</string> <string name="click_to_show_full">Click to view full count</string>
<string name="no_profile_pic_found">No profile pic found!</string> <string name="no_profile_pic_found">No profile pic found!</string>
<string name="swipe_up_confirmation">Are you sure you want to open this link?</string>
</resources> </resources>

View File

@ -0,0 +1,28 @@
// 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;
import org.junit.jupiter.api.Test;
import awais.instagrabber.models.IntentModel;
import awais.instagrabber.models.enums.IntentModelType;
class IntentUtilsTest {
@Test
void getIntentFromUrl() {
IntentModel intent = IntentUtils.parseUrl("https://instagr.am/austinhuang.me");
Assertions.assertEquals(new IntentModel(IntentModelType.USERNAME, "austinhuang.me"), intent);
intent = IntentUtils.parseUrl("https://www.instagr.am/_u/austinhuang.me");
Assertions.assertEquals(new IntentModel(IntentModelType.USERNAME, "austinhuang.me"), intent);
intent = IntentUtils.parseUrl("https://instagram.com/p/BmjKdkxjzO7/");
Assertions.assertEquals(new IntentModel(IntentModelType.POST, "BmjKdkxjzO7"), intent);
intent = IntentUtils.parseUrl("https://www.instagram.com/explore/tags/metrodemontreal/");
Assertions.assertEquals(new IntentModel(IntentModelType.HASHTAG, "metrodemontreal"), intent);
intent = IntentUtils.parseUrl("http://www.instagram.com/explore/locations/538444610/abcde");
Assertions.assertEquals(new IntentModel(IntentModelType.LOCATION, "538444610"), intent);
// todo: reel and igtv test cases that are sfw and preferably n i c e
}
}

View File

@ -1,10 +1,11 @@
package awais.instagrabber.utils; package awais.instagrabber.utils;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class TextUtilsTest { class TextUtilsTest {
@org.junit.jupiter.api.Test @Test
void testMillisToTimeString() { void testMillisToTimeString() {
String timeString = TextUtils.millisToTimeString(18000000); String timeString = TextUtils.millisToTimeString(18000000);
Assertions.assertEquals("05:00:00", timeString); Assertions.assertEquals("05:00:00", timeString);
@ -15,4 +16,12 @@ class TextUtilsTest {
timeString = TextUtils.millisToTimeString(300000, true); timeString = TextUtils.millisToTimeString(300000, true);
Assertions.assertEquals("00:05:00", timeString); 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);
}
} }