Browse Source

Merge pull request #68 from ammargitham/task/fix-videos-in-feed

Task/fix videos in feed
legacy
Austin Huang 4 years ago
committed by GitHub
parent
commit
ca0d89fdb6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      app/src/main/java/awais/instagrabber/MainHelper.java
  2. 12
      app/src/main/java/awais/instagrabber/activities/Main.java
  3. 6
      app/src/main/java/awais/instagrabber/adapters/FeedAdapter.java
  4. 257
      app/src/main/java/awais/instagrabber/customviews/helpers/VideoAwareRecyclerScroller.java
  5. 2
      app/src/main/java/awais/instagrabber/utils/FlavorTown.java
  6. 20
      app/src/main/java/awais/instagrabber/utils/Utils.java

23
app/src/main/java/awais/instagrabber/MainHelper.java

@ -85,6 +85,7 @@ import awaisomereport.LogCollector;
import static awais.instagrabber.utils.Constants.AUTOLOAD_POSTS;
import static awais.instagrabber.utils.Constants.BOTTOM_TOOLBAR;
import static awais.instagrabber.utils.Utils.logCollector;
import static awais.instagrabber.utils.Utils.settingsHelper;
public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
private static AsyncTask<?, ?, ?> currentlyExecuting;
@ -261,7 +262,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
private RecyclerLazyLoader feedLazyLoader, discoverLazyLoader;
private DiscoverAdapter discoverAdapter;
public SimpleExoPlayer currentFeedPlayer; // hack for remix drawer layout
private String cookie = Utils.settingsHelper.getString(Constants.COOKIE);
private String cookie = settingsHelper.getString(Constants.COOKIE);
public boolean isLoggedIn = !Utils.isEmpty(cookie) && Utils.getUserIdFromCookie(cookie) != null;
public MainHelper(@NonNull final Main main) {
@ -269,7 +270,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
this.main = main;
this.resources = main.getResources();
this.autoloadPosts = Utils.settingsHelper.getBoolean(AUTOLOAD_POSTS);
this.autoloadPosts = settingsHelper.getBoolean(AUTOLOAD_POSTS);
main.mainBinding.profileView.swipeRefreshLayout.setOnRefreshListener(this);
main.mainBinding.profileView.mainUrl.setMovementMethod(new LinkMovementMethod());
@ -279,7 +280,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
final ImageView iconProfile = (ImageView) iconSlider.getChildAt(1);
final ImageView iconDiscover = (ImageView) iconSlider.getChildAt(2);
final boolean isBottomToolbar = Utils.settingsHelper.getBoolean(BOTTOM_TOOLBAR);
final boolean isBottomToolbar = settingsHelper.getBoolean(BOTTOM_TOOLBAR);
isLoggedIn = !Utils.isEmpty(cookie);
if (!isLoggedIn) {
main.mainBinding.drawerLayout.removeView(main.mainBinding.feedView.feedLayout);
@ -362,8 +363,8 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
public void onDrawerOpened(@NonNull final View drawerView, @MouseDrawer.EdgeGravity final int gravity) {
if (gravity == GravityCompat.START || drawerView == main.mainBinding.feedView.feedLayout) {
if (currentFeedPlayer != null) {
currentFeedPlayer.setPlayWhenReady(true);
currentFeedPlayer.getPlaybackState();
final boolean shouldAutoplay = settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS);
currentFeedPlayer.setPlayWhenReady(shouldAutoplay);
}
} else {
// clear selection
@ -376,7 +377,6 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
if (gravity == GravityCompat.START || drawerView == main.mainBinding.feedView.feedLayout) {
if (currentFeedPlayer != null) {
currentFeedPlayer.setPlayWhenReady(false);
currentFeedPlayer.getPlaybackState();
}
} else {
// clear selection
@ -790,15 +790,15 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
main.mainBinding.profileView.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE);
final String profileId = profileModel.getId();
if (isLoggedIn || Utils.settingsHelper.getBoolean(Constants.STORIESIG)) {
if (isLoggedIn || settingsHelper.getBoolean(Constants.STORIESIG)) {
new iStoryStatusFetcher(profileId, profileModel.getUsername(), false, false,
(!isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG)), false,
(!isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG)), false,
result -> {
main.storyModels = result;
if (result != null && result.length > 0) main.mainBinding.profileView.mainProfileImage.setStoriesBorder();
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new HighlightsFetcher(profileId, (!isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG)), result -> {
new HighlightsFetcher(profileId, (!isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG)), result -> {
if (result != null && result.length > 0) {
main.mainBinding.profileView.highlightsList.setVisibility(View.VISIBLE);
main.highlightsAdapter.setData(result);
@ -1176,14 +1176,13 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
public void onPause() {
if (currentFeedPlayer != null) {
currentFeedPlayer.setPlayWhenReady(false);
currentFeedPlayer.getPlaybackState();
}
}
public void onResume() {
if (currentFeedPlayer != null) {
currentFeedPlayer.setPlayWhenReady(true);
currentFeedPlayer.getPlaybackState();
final boolean shouldAutoplay = settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS);
currentFeedPlayer.setPlayWhenReady(shouldAutoplay);
}
}

12
app/src/main/java/awais/instagrabber/activities/Main.java

@ -70,6 +70,7 @@ import static awais.instagrabber.utils.Utils.notificationManager;
import static awais.instagrabber.utils.Utils.settingsHelper;
public final class Main extends BaseLanguageActivity {
private static final int INITIAL_DELAY_MILLIS = 200;
public static FetchListener<String> scanHack;
public static ItemGetter itemGetter;
// -------- items --------
@ -117,6 +118,7 @@ public final class Main extends BaseLanguageActivity {
private Stack<String> queriesStack;
private DataBox.CookieModel cookieModel;
private Runnable runnable;
private Handler handler;
@Override
protected void onCreate(@Nullable final Bundle bundle) {
@ -257,7 +259,7 @@ public final class Main extends BaseLanguageActivity {
mainHelper.onIntent(getIntent());
final Handler handler = new Handler();
handler = new Handler();
runnable = () -> {
final GetActivityAsyncTask activityAsyncTask = new GetActivityAsyncTask(uid, cookie, result -> {
if (result == null) {
@ -305,7 +307,7 @@ public final class Main extends BaseLanguageActivity {
activityAsyncTask.execute();
handler.postDelayed(runnable, 60000);
};
handler.postDelayed(runnable, 200);
handler.postDelayed(runnable, INITIAL_DELAY_MILLIS);
}
private void downloadSelectedItems() {
@ -559,12 +561,18 @@ public final class Main extends BaseLanguageActivity {
@Override
protected void onPause() {
if (mainHelper != null) mainHelper.onPause();
if (handler != null && runnable != null) {
handler.removeCallbacks(runnable);
}
super.onPause();
}
@Override
protected void onResume() {
if (mainHelper != null) mainHelper.onResume();
if (handler != null && runnable != null) {
handler.postDelayed(runnable, INITIAL_DELAY_MILLIS);
}
super.onResume();
}

6
app/src/main/java/awais/instagrabber/adapters/FeedAdapter.java

@ -270,7 +270,11 @@ public final class FeedAdapter extends RecyclerView.Adapter<FeedItemViewHolder>
if (itemType == MediaItemType.MEDIA_TYPE_VIDEO) {
viewToChangeHeight = viewHolder.playerView;
final Player player = viewHolder.playerView.getPlayer();
if (player != null) {
final boolean shouldAutoplay = settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS);
player.setPlayWhenReady(shouldAutoplay);
}
viewHolder.videoViewsParent.setVisibility(View.VISIBLE);
viewHolder.videoViews.setText(String.valueOf(feedModel.getViewCount()));
} else {

257
app/src/main/java/awais/instagrabber/customviews/helpers/VideoAwareRecyclerScroller.java

@ -5,7 +5,6 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
@ -17,7 +16,10 @@ import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import java.util.List;
@ -30,18 +32,23 @@ import awais.instagrabber.utils.Utils;
import static awais.instagrabber.utils.Utils.settingsHelper;
// wasted around 3 hours to get this working, made from scrach, forgot to take a shower so i'm gonna go take a shower (time: May 11, 2020 @ 8:09:30 PM)
public class VideoAwareRecyclerScroller extends RecyclerView.OnScrollListener {
private static final String TAG = "VideoAwareRecScroll";
private static final Object LOCK = new Object();
private LinearLayoutManager layoutManager;
private View firstItemView, lastItemView;
private int videoPosShown = -1, lastVideoPos = -1, lastChangedVideoPos, lastStoppedVideoPos, lastPlayedVideoPos;
private boolean videoAttached = false;
private final List<FeedModel> feedModels;
////////////////////////////////////////////////////
private SimpleExoPlayer player;
private ImageView btnMute;
private CacheDataSourceFactory cacheDataSourceFactory;
private final List<FeedModel> feedModels;
private final Context context;
private final VideoChangeCallback videoChangeCallback;
private final DefaultDataSourceFactory dataSourceFactory;
private final View.OnClickListener commentClickListener = new View.OnClickListener() {
@Override
public void onClick(@NonNull final View v) {
@ -55,128 +62,135 @@ public class VideoAwareRecyclerScroller extends RecyclerView.OnScrollListener {
}
}
};
private final View.OnClickListener muteClickListener = v -> {
if (player == null) return;
final float intVol = player.getVolume() == 0f ? 1f : 0f;
player.setVolume(intVol);
if (btnMute != null) btnMute.setImageResource(intVol == 0f ? R.drawable.mute : R.drawable.vol);
if (btnMute != null)
btnMute.setImageResource(intVol == 0f ? R.drawable.mute : R.drawable.vol);
Utils.sessionVolumeFull = intVol == 1f;
};
private final VideoChangeCallback videoChangeCallback;
// private final ScrollerVideoCallback videoCallback;
// private View lastVideoHolder;
// private int videoState = -1;
public VideoAwareRecyclerScroller(final Context context, final List<FeedModel> feedModels,
final VideoChangeCallback videoChangeCallback) {
this.context = context;
this.feedModels = feedModels;
this.videoChangeCallback = videoChangeCallback;
dataSourceFactory = new DefaultDataSourceFactory(context, "instagram");
final SimpleCache simpleCache = Utils.getSimpleCacheInstance(context);
if (simpleCache != null) {
cacheDataSourceFactory = new CacheDataSourceFactory(simpleCache, dataSourceFactory);
}
}
@Override
public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) {
if (layoutManager == null) {
final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) this.layoutManager = (LinearLayoutManager) layoutManager;
if (layoutManager instanceof LinearLayoutManager)
this.layoutManager = (LinearLayoutManager) layoutManager;
}
if (feedModels.size() == 0 || layoutManager == null) {
return;
}
int firstVisibleItemPos = layoutManager.findFirstCompletelyVisibleItemPosition();
int lastVisibleItemPos = layoutManager.findLastCompletelyVisibleItemPosition();
if (feedModels.size() > 0 && layoutManager != null) {
int firstVisibleItemPos = layoutManager.findFirstCompletelyVisibleItemPosition();
int lastVisibleItemPos = layoutManager.findLastCompletelyVisibleItemPosition();
if (firstVisibleItemPos == -1 && lastVisibleItemPos == -1) {
firstVisibleItemPos = layoutManager.findFirstVisibleItemPosition();
lastVisibleItemPos = layoutManager.findLastVisibleItemPosition();
}
if (firstVisibleItemPos == -1 && lastVisibleItemPos == -1) {
firstVisibleItemPos = layoutManager.findFirstVisibleItemPosition();
lastVisibleItemPos = layoutManager.findLastVisibleItemPosition();
}
boolean processFirstItem = false, processLastItem = false;
View currView;
if (firstVisibleItemPos != -1) {
currView = layoutManager.findViewByPosition(firstVisibleItemPos);
if (currView != null && currView.getId() == R.id.videoHolder) {
firstItemView = currView;
processFirstItem = true;
}
boolean processFirstItem = false, processLastItem = false;
View currView;
if (firstVisibleItemPos != -1) {
currView = layoutManager.findViewByPosition(firstVisibleItemPos);
if (currView != null && currView.getId() == R.id.videoHolder) {
firstItemView = currView;
processFirstItem = true;
}
if (lastVisibleItemPos != -1) {
currView = layoutManager.findViewByPosition(lastVisibleItemPos);
if (currView != null && currView.getId() == R.id.videoHolder) {
lastItemView = currView;
processLastItem = true;
}
}
if (lastVisibleItemPos != -1) {
currView = layoutManager.findViewByPosition(lastVisibleItemPos);
if (currView != null && currView.getId() == R.id.videoHolder) {
lastItemView = currView;
processLastItem = true;
}
}
final Rect visibleItemRect = new Rect();
final Rect visibleItemRect = new Rect();
int firstVisibleItemHeight = 0, lastVisibleItemHeight = 0;
int firstVisibleItemHeight = 0, lastVisibleItemHeight = 0;
final boolean isFirstItemVideoHolder = firstItemView != null && firstItemView.getId() == R.id.videoHolder;
if (isFirstItemVideoHolder) {
firstItemView.getGlobalVisibleRect(visibleItemRect);
firstVisibleItemHeight = visibleItemRect.height();
}
final boolean isLastItemVideoHolder = lastItemView != null && lastItemView.getId() == R.id.videoHolder;
if (isLastItemVideoHolder) {
lastItemView.getGlobalVisibleRect(visibleItemRect);
lastVisibleItemHeight = visibleItemRect.height();
}
final boolean isFirstItemVideoHolder = firstItemView != null && firstItemView.getId() == R.id.videoHolder;
if (isFirstItemVideoHolder) {
firstItemView.getGlobalVisibleRect(visibleItemRect);
firstVisibleItemHeight = visibleItemRect.height();
}
final boolean isLastItemVideoHolder = lastItemView != null && lastItemView.getId() == R.id.videoHolder;
if (isLastItemVideoHolder) {
lastItemView.getGlobalVisibleRect(visibleItemRect);
lastVisibleItemHeight = visibleItemRect.height();
}
if (processFirstItem && firstVisibleItemHeight > lastVisibleItemHeight) videoPosShown = firstVisibleItemPos;
else if (processLastItem && lastVisibleItemHeight != 0) videoPosShown = lastVisibleItemPos;
if (processFirstItem && firstVisibleItemHeight > lastVisibleItemHeight)
videoPosShown = firstVisibleItemPos;
else if (processLastItem && lastVisibleItemHeight != 0) videoPosShown = lastVisibleItemPos;
if (firstItemView != lastItemView) {
final int mox = lastVisibleItemHeight - firstVisibleItemHeight;
if (processLastItem && lastVisibleItemHeight > firstVisibleItemHeight) videoPosShown = lastVisibleItemPos;
if ((processFirstItem || processLastItem) && mox >= 0) videoPosShown = lastVisibleItemPos;
if (firstItemView != lastItemView) {
final int mox = lastVisibleItemHeight - firstVisibleItemHeight;
if (processLastItem && lastVisibleItemHeight > firstVisibleItemHeight)
videoPosShown = lastVisibleItemPos;
if ((processFirstItem || processLastItem) && mox >= 0)
videoPosShown = lastVisibleItemPos;
}
if (lastChangedVideoPos != -1 && lastVideoPos != -1) {
currView = layoutManager.findViewByPosition(lastChangedVideoPos);
if (currView != null && currView.getId() == R.id.videoHolder &&
lastStoppedVideoPos != lastChangedVideoPos && lastPlayedVideoPos != lastChangedVideoPos) {
lastStoppedVideoPos = lastChangedVideoPos;
stopVideo(lastChangedVideoPos, recyclerView, currView);
}
if (lastChangedVideoPos != -1 && lastVideoPos != -1) {
currView = layoutManager.findViewByPosition(lastChangedVideoPos);
if (currView != null && currView.getId() == R.id.videoHolder &&
lastStoppedVideoPos != lastChangedVideoPos && lastPlayedVideoPos != lastChangedVideoPos) {
lastStoppedVideoPos = lastChangedVideoPos;
stopVideo(lastChangedVideoPos, recyclerView, currView);
}
currView = layoutManager.findViewByPosition(lastVideoPos);
if (currView != null && currView.getId() == R.id.videoHolder) {
final Rect rect = new Rect();
currView.getGlobalVisibleRect(rect);
currView = layoutManager.findViewByPosition(lastVideoPos);
if (currView != null && currView.getId() == R.id.videoHolder) {
final Rect rect = new Rect();
currView.getGlobalVisibleRect(rect);
final int holderTop = currView.getTop();
final int holderHeight = currView.getBottom() - holderTop;
final int halfHeight = holderHeight / 2;
//halfHeight -= halfHeight / 5;
if (rect.height() < halfHeight) {
if (lastStoppedVideoPos != lastVideoPos) {
lastStoppedVideoPos = lastVideoPos;
stopVideo(lastVideoPos, recyclerView, currView);
}
} else if (lastPlayedVideoPos != lastVideoPos) {
lastPlayedVideoPos = lastVideoPos;
playVideo(lastVideoPos, recyclerView, currView);
final int holderTop = currView.getTop();
final int holderHeight = currView.getBottom() - holderTop;
final int halfHeight = holderHeight / 2;
//halfHeight -= halfHeight / 5;
if (rect.height() < halfHeight) {
if (lastStoppedVideoPos != lastVideoPos) {
lastStoppedVideoPos = lastVideoPos;
stopVideo(lastVideoPos, recyclerView, currView);
}
} else if (lastPlayedVideoPos != lastVideoPos) {
lastPlayedVideoPos = lastVideoPos;
playVideo(lastVideoPos, recyclerView, currView);
}
if (lastChangedVideoPos != lastVideoPos) lastChangedVideoPos = lastVideoPos;
}
if (lastVideoPos != -1 && lastVideoPos != videoPosShown) {
if (videoAttached) {
//if ((currView = layoutManager.findViewByPosition(lastVideoPos)) != null && currView.getId() == R.id.videoHolder)
releaseVideo(lastVideoPos, recyclerView, null);
videoAttached = false;
}
if (lastChangedVideoPos != lastVideoPos) lastChangedVideoPos = lastVideoPos;
}
if (lastVideoPos != -1 && lastVideoPos != videoPosShown) {
if (videoAttached) {
//if ((currView = layoutManager.findViewByPosition(lastVideoPos)) != null && currView.getId() == R.id.videoHolder)
releaseVideo(lastVideoPos, recyclerView, null);
videoAttached = false;
}
if (videoPosShown != -1) {
lastVideoPos = videoPosShown;
if (!videoAttached) {
if ((currView = layoutManager.findViewByPosition(videoPosShown)) != null && currView.getId() == R.id.videoHolder)
attachVideo(videoPosShown, recyclerView, currView);
videoAttached = true;
}
}
if (videoPosShown != -1) {
lastVideoPos = videoPosShown;
if (!videoAttached) {
if ((currView = layoutManager.findViewByPosition(videoPosShown)) != null && currView.getId() == R.id.videoHolder)
attachVideo(videoPosShown, recyclerView, currView);
videoAttached = true;
}
}
}
@ -197,7 +211,11 @@ public class VideoAwareRecyclerScroller extends RecyclerView.OnScrollListener {
player = null;
}
player = new SimpleExoPlayer.Builder(context).build();
final boolean shouldAutoplay = settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS);
player = new SimpleExoPlayer.Builder(context)
.setUseLazyPreparation(!shouldAutoplay)
.build();
player.setPlayWhenReady(shouldAutoplay);
if (itemView != null) {
final Object tag = itemView.getTag();
@ -218,39 +236,26 @@ public class VideoAwareRecyclerScroller extends RecyclerView.OnScrollListener {
if (playerView == null) return;
playerView.setPlayer(player);
if (player != null) {
btnMute = itemView.findViewById(R.id.btnMute);
btnMute = itemView.findViewById(R.id.btnMute);
float vol = settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f;
if (vol == 0f && Utils.sessionVolumeFull) vol = 1f;
player.setVolume(vol);
if (btnMute != null) {
btnMute.setVisibility(View.VISIBLE);
btnMute.setImageResource(vol == 0f ? R.drawable.vol : R.drawable.mute);
btnMute.setOnClickListener(muteClickListener);
}
float vol = settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f;
if (vol == 0f && Utils.sessionVolumeFull) vol = 1f;
player.setVolume(vol);
player.setPlayWhenReady(settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS));
final ProgressiveMediaSource mediaSource = new ProgressiveMediaSource.Factory(new DefaultDataSourceFactory(context, "instagram"))
.createMediaSource(Uri.parse(feedModels.get(itemPos).getDisplayUrl()));
player.setRepeatMode(Player.REPEAT_MODE_ALL);
player.prepare(mediaSource);
player.setVolume(vol);
playerView.setOnClickListener(v -> {
if (player.getPlayWhenReady() == true) {
player.setPlayWhenReady(false);
player.getPlaybackState();
}
else {
player.setPlayWhenReady(true);
player.getPlaybackState();
}
});
if (btnMute != null) {
btnMute.setVisibility(View.VISIBLE);
btnMute.setImageResource(vol == 0f ? R.drawable.vol : R.drawable.mute);
btnMute.setOnClickListener(muteClickListener);
}
final DataSource.Factory factory = cacheDataSourceFactory != null ? cacheDataSourceFactory : dataSourceFactory;
final ProgressiveMediaSource.Factory sourceFactory = new ProgressiveMediaSource.Factory(factory);
final ProgressiveMediaSource mediaSource = sourceFactory.createMediaSource(Uri.parse(feedModels.get(itemPos).getDisplayUrl()));
player.setRepeatMode(Player.REPEAT_MODE_ALL);
player.prepare(mediaSource);
player.setVolume(vol);
playerView.setOnClickListener(v -> player.setPlayWhenReady(!player.getPlayWhenReady()));
}
if (videoChangeCallback != null) videoChangeCallback.playerChanged(itemPos, player);
@ -259,11 +264,11 @@ public class VideoAwareRecyclerScroller extends RecyclerView.OnScrollListener {
private void releaseVideo(final int itemPos, final RecyclerView recyclerView, final View itemView) {
// Log.d("AWAISKING_APP", "release: " + itemPos);
// if (player != null) {
// player.stop(true);
// player.release();
// }
// player = null;
// if (player != null) {
// player.stop(true);
// player.release();
// }
// player = null;
}
private void playVideo(final int itemPos, final RecyclerView recyclerView, final View itemView) {

2
app/src/main/java/awais/instagrabber/utils/FlavorTown.java

@ -29,7 +29,7 @@ public final class FlavorTown {
public static void updateCheck(@NonNull final Context context) {
Resources res = context.getResources();
new UpdateChecker(version -> {
if (version != BuildConfig.VERSION_NAME && !BuildConfig.DEBUG) {
if (!version.equals(BuildConfig.VERSION_NAME) && !BuildConfig.DEBUG) {
new AlertDialog.Builder(context)
.setTitle(res.getString(R.string.update_available, version))
.setMessage(R.string.update_notice)

20
app/src/main/java/awais/instagrabber/utils/Utils.java

@ -40,9 +40,12 @@ import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.internal.StringUtil;
import java.io.BufferedReader;
import java.io.File;
@ -105,6 +108,8 @@ import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO;
public final class Utils {
private static final String TAG = "Utils";
private static final int MAX_BYTES = 10 * 1024 * 1024;
public static LogCollector logCollector;
public static SettingsHelper settingsHelper;
public static DataBox dataBox;
@ -122,6 +127,7 @@ public final class Utils {
public static ClipboardManager clipboardManager;
public static DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
public static SimpleDateFormat datetimeParser;
public static SimpleCache simpleCache;
public static void setupCookies(final String cookieRaw) {
final CookieStore cookieStore = NET_COOKIE_MANAGER.getCookieStore();
@ -1400,4 +1406,16 @@ public final class Utils {
}
return builder.toString();
}
public static SimpleCache getSimpleCacheInstance(final Context context) {
if (context == null) {
return null;
}
final ExoDatabaseProvider exoDatabaseProvider = new ExoDatabaseProvider(context);
final File cacheDir = context.getCacheDir();
if (simpleCache == null && cacheDir != null) {
simpleCache = new SimpleCache(cacheDir, new LeastRecentlyUsedCacheEvictor(MAX_BYTES), exoDatabaseProvider);
}
return simpleCache;
}
}
Loading…
Cancel
Save