|
|
@ -57,6 +57,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Deque; |
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import awais.instagrabber.BuildConfig; |
|
|
@ -85,8 +86,8 @@ import awais.instagrabber.utils.TextUtils; |
|
|
|
import awais.instagrabber.utils.Utils; |
|
|
|
import awais.instagrabber.utils.emoji.EmojiParser; |
|
|
|
import awais.instagrabber.viewmodels.AppStateViewModel; |
|
|
|
import awais.instagrabber.webservices.RetrofitFactory; |
|
|
|
import awais.instagrabber.viewmodels.DirectInboxViewModel; |
|
|
|
import awais.instagrabber.webservices.RetrofitFactory; |
|
|
|
import awais.instagrabber.webservices.SearchService; |
|
|
|
import retrofit2.Call; |
|
|
|
import retrofit2.Callback; |
|
|
@ -137,9 +138,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage |
|
|
|
RetrofitFactory.setup(this); |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
binding = ActivityMainBinding.inflate(getLayoutInflater()); |
|
|
|
final String cookie = settingsHelper.getString(Constants.COOKIE); |
|
|
|
CookieUtils.setupCookies(cookie); |
|
|
|
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != 0; |
|
|
|
setupCookie(); |
|
|
|
if (settingsHelper.getBoolean(Constants.FLAG_SECURE)) |
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); |
|
|
|
setContentView(binding.getRoot()); |
|
|
@ -165,7 +164,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage |
|
|
|
new ViewModelProvider(this).get(AppStateViewModel.class); // Just initiate the App state here |
|
|
|
final Intent intent = getIntent(); |
|
|
|
handleIntent(intent); |
|
|
|
if (!TextUtils.isEmpty(cookie) && settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) { |
|
|
|
if (isLoggedIn && settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) { |
|
|
|
bindActivityCheckerService(); |
|
|
|
} |
|
|
|
getSupportFragmentManager().addOnBackStackChangedListener(this); |
|
|
@ -180,6 +179,26 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage |
|
|
|
initDmUnreadCount(); |
|
|
|
} |
|
|
|
|
|
|
|
private void setupCookie() { |
|
|
|
final String cookie = settingsHelper.getString(Constants.COOKIE); |
|
|
|
long userId = 0; |
|
|
|
String csrfToken = null; |
|
|
|
if (!TextUtils.isEmpty(cookie)) { |
|
|
|
userId = CookieUtils.getUserIdFromCookie(cookie); |
|
|
|
csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); |
|
|
|
} |
|
|
|
if (TextUtils.isEmpty(cookie) || userId == 0 || TextUtils.isEmpty(csrfToken)) { |
|
|
|
isLoggedIn = false; |
|
|
|
return; |
|
|
|
} |
|
|
|
final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID); |
|
|
|
if (TextUtils.isEmpty(deviceUuid)) { |
|
|
|
settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString()); |
|
|
|
} |
|
|
|
CookieUtils.setupCookies(cookie); |
|
|
|
isLoggedIn = true; |
|
|
|
} |
|
|
|
|
|
|
|
private void initDmService() { |
|
|
|
if (!isLoggedIn) return; |
|
|
|
final boolean enabled = settingsHelper.getBoolean(PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH); |
|
|
@ -916,9 +935,9 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage |
|
|
|
return currentTabs; |
|
|
|
} |
|
|
|
|
|
|
|
// public boolean isNavRootInCurrentTabs(@IdRes final int navRootId) { |
|
|
|
// return showBottomViewDestinations.stream().anyMatch(id -> id == navRootId); |
|
|
|
// } |
|
|
|
// public boolean isNavRootInCurrentTabs(@IdRes final int navRootId) { |
|
|
|
// return showBottomViewDestinations.stream().anyMatch(id -> id == navRootId); |
|
|
|
// } |
|
|
|
|
|
|
|
private void setNavBarDMUnreadCountBadge(final int unseenCount) { |
|
|
|
final BadgeDrawable badge = binding.bottomNavView.getOrCreateBadge(R.id.direct_messages_nav_graph); |
|
|
|