mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 22:57:29 +00:00
Disable DM if tab removed and do not add favs to more list if tab added
This commit is contained in:
parent
b9d75af03c
commit
2fed236f04
@ -116,6 +116,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
|||||||
private boolean isBackStackEmpty = false;
|
private boolean isBackStackEmpty = false;
|
||||||
private boolean isLoggedIn;
|
private boolean isLoggedIn;
|
||||||
private HideBottomViewOnScrollBehavior<BottomNavigationView> behavior;
|
private HideBottomViewOnScrollBehavior<BottomNavigationView> behavior;
|
||||||
|
private List<Tab> currentTabs;
|
||||||
|
|
||||||
private final ServiceConnection serviceConnection = new ServiceConnection() {
|
private final ServiceConnection serviceConnection = new ServiceConnection() {
|
||||||
@Override
|
@Override
|
||||||
@ -357,12 +358,14 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
|||||||
}
|
}
|
||||||
final List<SearchItem> result = new ArrayList<>();
|
final List<SearchItem> result = new ArrayList<>();
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
if (body.getList() != null) result.addAll(searchHash ? body.getList()
|
if (body.getList() != null) {
|
||||||
.stream()
|
result.addAll(searchHash ? body.getList()
|
||||||
.filter(i -> i.getUser() == null)
|
.stream()
|
||||||
.collect(Collectors.toList()) : body.getList());
|
.filter(i -> i.getUser() == null)
|
||||||
}
|
.collect(Collectors.toList())
|
||||||
else {
|
: body.getList());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (body.getUsers() != null && !searchHash) result.addAll(body.getUsers());
|
if (body.getUsers() != null && !searchHash) result.addAll(body.getUsers());
|
||||||
if (body.getHashtags() != null) result.addAll(body.getHashtags());
|
if (body.getHashtags() != null) result.addAll(body.getHashtags());
|
||||||
if (body.getPlaces() != null) result.addAll(body.getPlaces());
|
if (body.getPlaces() != null) result.addAll(body.getPlaces());
|
||||||
@ -431,7 +434,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
|||||||
}
|
}
|
||||||
prevSuggestionAsync = searchService.search(isLoggedIn,
|
prevSuggestionAsync = searchService.search(isLoggedIn,
|
||||||
searchUser || searchHash ? currentSearchQuery.substring(1)
|
searchUser || searchHash ? currentSearchQuery.substring(1)
|
||||||
: currentSearchQuery,
|
: currentSearchQuery,
|
||||||
searchUser ? "user" : (searchHash ? "hashtag" : "blended"));
|
searchUser ? "user" : (searchHash ? "hashtag" : "blended"));
|
||||||
suggestionAdapter.changeCursor(null);
|
suggestionAdapter.changeCursor(null);
|
||||||
prevSuggestionAsync.enqueue(cb);
|
prevSuggestionAsync.enqueue(cb);
|
||||||
@ -462,13 +465,13 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupBottomNavigationBar(final boolean setDefaultTabFromSettings) {
|
private void setupBottomNavigationBar(final boolean setDefaultTabFromSettings) {
|
||||||
final List<Tab> tabs = !isLoggedIn ? setupAnonBottomNav() : setupMainBottomNav();
|
currentTabs = !isLoggedIn ? setupAnonBottomNav() : setupMainBottomNav();
|
||||||
|
|
||||||
final List<Integer> mainNavList = tabs.stream()
|
final List<Integer> mainNavList = currentTabs.stream()
|
||||||
.map(Tab::getNavigationResId)
|
.map(Tab::getNavigationResId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (setDefaultTabFromSettings) {
|
if (setDefaultTabFromSettings) {
|
||||||
setSelectedTab(tabs);
|
setSelectedTab(currentTabs);
|
||||||
}
|
}
|
||||||
final LiveData<NavController> navControllerLiveData = setupWithNavController(
|
final LiveData<NavController> navControllerLiveData = setupWithNavController(
|
||||||
binding.bottomNavView,
|
binding.bottomNavView,
|
||||||
@ -875,4 +878,8 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
|||||||
public Toolbar getToolbar() {
|
public Toolbar getToolbar() {
|
||||||
return binding.toolbar;
|
return binding.toolbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Tab> getCurrentTabs() {
|
||||||
|
return currentTabs;
|
||||||
|
}
|
||||||
}
|
}
|
@ -92,7 +92,15 @@ public class TabOrderPreferenceDialogFragment extends DialogFragment {
|
|||||||
setSaveButtonState(newOrderTabs);
|
setSaveButtonState(newOrderTabs);
|
||||||
// submit these tab lists to adapter
|
// submit these tab lists to adapter
|
||||||
if (adapter == null) return;
|
if (adapter == null) return;
|
||||||
adapter.submitList(newOrderTabs, newOtherTabs, () -> list.postDelayed(() -> adapter.notifyDataSetChanged(), 500));
|
adapter.submitList(newOrderTabs, newOtherTabs, () -> list.postDelayed(() -> {
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
if (tab.getNavigationRootId() == R.id.direct_messages_nav_graph) {
|
||||||
|
final ConfirmDialogFragment dialogFragment = ConfirmDialogFragment.newInstance(
|
||||||
|
111, 0, R.string.dm_remove_warning, R.string.ok, 0, 0
|
||||||
|
);
|
||||||
|
dialogFragment.show(getChildFragmentManager(), "dm_warning_dialog");
|
||||||
|
}
|
||||||
|
}, 500));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSaveButtonState(final List<Tab> newOrderTabs) {
|
private void setSaveButtonState(final List<Tab> newOrderTabs) {
|
||||||
|
@ -307,6 +307,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
private AccountRepository accountRepository;
|
private AccountRepository accountRepository;
|
||||||
private FavoriteRepository favoriteRepository;
|
private FavoriteRepository favoriteRepository;
|
||||||
private AppStateViewModel appStateViewModel;
|
private AppStateViewModel appStateViewModel;
|
||||||
|
private boolean disableDm = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
@ -322,8 +323,10 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
mediaService = isLoggedIn ? MediaService.getInstance(null, null, 0) : null;
|
mediaService = isLoggedIn ? MediaService.getInstance(null, null, 0) : null;
|
||||||
userService = isLoggedIn ? UserService.getInstance() : null;
|
userService = isLoggedIn ? UserService.getInstance() : null;
|
||||||
graphQLService = isLoggedIn ? null : GraphQLService.getInstance();
|
graphQLService = isLoggedIn ? null : GraphQLService.getInstance();
|
||||||
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(getContext()));
|
final Context context = getContext();
|
||||||
favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(getContext()));
|
if (context == null) return;
|
||||||
|
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(context));
|
||||||
|
favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(context));
|
||||||
appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class);
|
appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
@ -578,6 +581,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
disableDm = fragmentActivity.getCurrentTabs()
|
||||||
|
.stream()
|
||||||
|
.noneMatch(tab -> tab.getNavigationRootId() == R.id.direct_messages_nav_graph);
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
final ProfileFragmentArgs fragmentArgs = ProfileFragmentArgs.fromBundle(getArguments());
|
final ProfileFragmentArgs fragmentArgs = ProfileFragmentArgs.fromBundle(getArguments());
|
||||||
username = fragmentArgs.getUsername();
|
username = fragmentArgs.getUsername();
|
||||||
@ -612,8 +618,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
username = profileModel.getUsername();
|
username = profileModel.getUsername();
|
||||||
setUsernameDelayed();
|
setUsernameDelayed();
|
||||||
setProfileDetails();
|
setProfileDetails();
|
||||||
}
|
} else if (isLoggedIn) {
|
||||||
else if (isLoggedIn) {
|
|
||||||
userService.getUsernameInfo(usernameTemp, new ServiceCallback<User>() {
|
userService.getUsernameInfo(usernameTemp, new ServiceCallback<User>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(final User user) {
|
public void onSuccess(final User user) {
|
||||||
@ -647,8 +652,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
} catch (final Throwable ignored) {}
|
} catch (final Throwable ignored) {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
graphQLService.fetchUser(usernameTemp, new ServiceCallback<User>() {
|
graphQLService.fetchUser(usernameTemp, new ServiceCallback<User>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(final User user) {
|
public void onSuccess(final User user) {
|
||||||
@ -939,7 +943,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
}
|
}
|
||||||
profileDetailsBinding.btnSaved.setVisibility(View.GONE);
|
profileDetailsBinding.btnSaved.setVisibility(View.GONE);
|
||||||
profileDetailsBinding.btnLiked.setVisibility(View.GONE);
|
profileDetailsBinding.btnLiked.setVisibility(View.GONE);
|
||||||
profileDetailsBinding.btnDM.setVisibility(View.VISIBLE);
|
profileDetailsBinding.btnDM.setVisibility(disableDm ? View.GONE : View.VISIBLE);
|
||||||
profileDetailsBinding.btnFollow.setVisibility(View.VISIBLE);
|
profileDetailsBinding.btnFollow.setVisibility(View.VISIBLE);
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
@ -1116,23 +1120,25 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
PostItemType.TAGGED);
|
PostItemType.TAGGED);
|
||||||
NavHostFragment.findNavController(this).navigate(action);
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
});
|
});
|
||||||
profileDetailsBinding.btnDM.setOnClickListener(v -> {
|
if (!disableDm) {
|
||||||
profileDetailsBinding.btnDM.setEnabled(false);
|
profileDetailsBinding.btnDM.setOnClickListener(v -> {
|
||||||
new CreateThreadAction(cookie, profileModel.getPk(), thread -> {
|
profileDetailsBinding.btnDM.setEnabled(false);
|
||||||
if (thread == null) {
|
new CreateThreadAction(cookie, profileModel.getPk(), thread -> {
|
||||||
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
if (thread == null) {
|
||||||
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
||||||
|
profileDetailsBinding.btnDM.setEnabled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final InboxManager inboxManager = DirectMessagesManager.getInstance().getInboxManager();
|
||||||
|
if (!inboxManager.containsThread(thread.getThreadId())) {
|
||||||
|
thread.setTemp(true);
|
||||||
|
inboxManager.addThread(thread, 0);
|
||||||
|
}
|
||||||
|
fragmentActivity.navigateToThread(thread.getThreadId(), profileModel.getUsername());
|
||||||
profileDetailsBinding.btnDM.setEnabled(true);
|
profileDetailsBinding.btnDM.setEnabled(true);
|
||||||
return;
|
}).execute();
|
||||||
}
|
});
|
||||||
final InboxManager inboxManager = DirectMessagesManager.getInstance().getInboxManager();
|
}
|
||||||
if (!inboxManager.containsThread(thread.getThreadId())) {
|
|
||||||
thread.setTemp(true);
|
|
||||||
inboxManager.addThread(thread, 0);
|
|
||||||
}
|
|
||||||
fragmentActivity.navigateToThread(thread.getThreadId(), profileModel.getUsername());
|
|
||||||
profileDetailsBinding.btnDM.setEnabled(true);
|
|
||||||
}).execute();
|
|
||||||
});
|
|
||||||
profileDetailsBinding.mainProfileImage.setOnClickListener(v -> {
|
profileDetailsBinding.mainProfileImage.setOnClickListener(v -> {
|
||||||
if (!hasStories) {
|
if (!hasStories) {
|
||||||
// show profile pic
|
// show profile pic
|
||||||
|
@ -2,7 +2,6 @@ package awais.instagrabber.fragments.settings;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
@ -13,6 +12,7 @@ import androidx.preference.SwitchPreferenceCompat;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import awais.instagrabber.R;
|
import awais.instagrabber.R;
|
||||||
|
import awais.instagrabber.dialogs.ConfirmDialogFragment;
|
||||||
import awais.instagrabber.dialogs.TabOrderPreferenceDialogFragment;
|
import awais.instagrabber.dialogs.TabOrderPreferenceDialogFragment;
|
||||||
import awais.instagrabber.utils.Constants;
|
import awais.instagrabber.utils.Constants;
|
||||||
import awais.instagrabber.utils.CookieUtils;
|
import awais.instagrabber.utils.CookieUtils;
|
||||||
@ -34,9 +34,10 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen
|
|||||||
}
|
}
|
||||||
screen.addPreference(getUpdateCheckPreference(context));
|
screen.addPreference(getUpdateCheckPreference(context));
|
||||||
screen.addPreference(getFlagSecurePreference(context));
|
screen.addPreference(getFlagSecurePreference(context));
|
||||||
final List<Preference> preferences = FlavorSettings.getInstance().getPreferences(context,
|
final List<Preference> preferences = FlavorSettings.getInstance()
|
||||||
getChildFragmentManager(),
|
.getPreferences(context,
|
||||||
SettingCategory.GENERAL);
|
getChildFragmentManager(),
|
||||||
|
SettingCategory.GENERAL);
|
||||||
if (preferences != null) {
|
if (preferences != null) {
|
||||||
for (final Preference preference : preferences) {
|
for (final Preference preference : preferences) {
|
||||||
screen.addPreference(preference);
|
screen.addPreference(preference);
|
||||||
@ -101,7 +102,15 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSave(final boolean orderHasChanged) {
|
public void onSave(final boolean orderHasChanged) {
|
||||||
Log.d("", "onSave: " + orderHasChanged);
|
if (!orderHasChanged) return;
|
||||||
|
final ConfirmDialogFragment dialogFragment = ConfirmDialogFragment.newInstance(
|
||||||
|
111,
|
||||||
|
0,
|
||||||
|
R.string.tab_order_start_next_launch,
|
||||||
|
R.string.ok,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
dialogFragment.show(getChildFragmentManager(), "tab_order_set_dialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||||||
import awais.instagrabber.BuildConfig;
|
import awais.instagrabber.BuildConfig;
|
||||||
import awais.instagrabber.R;
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.activities.Login;
|
import awais.instagrabber.activities.Login;
|
||||||
|
import awais.instagrabber.activities.MainActivity;
|
||||||
import awais.instagrabber.databinding.PrefAccountSwitcherBinding;
|
import awais.instagrabber.databinding.PrefAccountSwitcherBinding;
|
||||||
import awais.instagrabber.db.datasources.AccountDataSource;
|
import awais.instagrabber.db.datasources.AccountDataSource;
|
||||||
import awais.instagrabber.db.entities.Account;
|
import awais.instagrabber.db.entities.Account;
|
||||||
@ -157,13 +158,24 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
|
|||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
screen.addPreference(getPreference(R.string.title_favorites, R.drawable.ic_star_24, preference -> {
|
|
||||||
if (isSafeToNavigate(navController)) {
|
// Check if favorites has been added as a tab. And if so, do not add in this list
|
||||||
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToFavoritesFragment();
|
boolean showFavorites = true;
|
||||||
navController.navigate(navDirections);
|
final MainActivity activity = (MainActivity) getActivity();
|
||||||
}
|
if (activity != null && activity.getCurrentTabs() != null) {
|
||||||
return true;
|
showFavorites = activity.getCurrentTabs()
|
||||||
}));
|
.stream()
|
||||||
|
.noneMatch(tab -> tab.getNavigationRootId() == R.id.favorites_nav_graph);
|
||||||
|
}
|
||||||
|
if (showFavorites) {
|
||||||
|
screen.addPreference(getPreference(R.string.title_favorites, R.drawable.ic_star_24, preference -> {
|
||||||
|
if (isSafeToNavigate(navController)) {
|
||||||
|
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToFavoritesFragment();
|
||||||
|
navController.navigate(navDirections);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
screen.addPreference(getDivider(context));
|
screen.addPreference(getDivider(context));
|
||||||
screen.addPreference(getPreference(R.string.action_settings, R.drawable.ic_outline_settings_24, preference -> {
|
screen.addPreference(getPreference(R.string.action_settings, R.drawable.ic_outline_settings_24, preference -> {
|
||||||
|
@ -477,4 +477,6 @@
|
|||||||
<string name="crash_report_title">Select an email app to send crash logs</string>
|
<string name="crash_report_title">Select an email app to send crash logs</string>
|
||||||
<string name="tab_order">Screen order</string>
|
<string name="tab_order">Screen order</string>
|
||||||
<string name="other_tabs">Other tabs</string>
|
<string name="other_tabs">Other tabs</string>
|
||||||
|
<string name="tab_order_start_next_launch">The tab order will be reflected on next launch</string>
|
||||||
|
<string name="dm_remove_warning">If saved, all DM related features will be disabled on next launch</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user