mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 13:26:59 +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 isLoggedIn;
|
||||
private HideBottomViewOnScrollBehavior<BottomNavigationView> behavior;
|
||||
private List<Tab> currentTabs;
|
||||
|
||||
private final ServiceConnection serviceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
@ -357,12 +358,14 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
||||
}
|
||||
final List<SearchItem> result = new ArrayList<>();
|
||||
if (isLoggedIn) {
|
||||
if (body.getList() != null) result.addAll(searchHash ? body.getList()
|
||||
.stream()
|
||||
.filter(i -> i.getUser() == null)
|
||||
.collect(Collectors.toList()) : body.getList());
|
||||
}
|
||||
else {
|
||||
if (body.getList() != null) {
|
||||
result.addAll(searchHash ? body.getList()
|
||||
.stream()
|
||||
.filter(i -> i.getUser() == null)
|
||||
.collect(Collectors.toList())
|
||||
: body.getList());
|
||||
}
|
||||
} else {
|
||||
if (body.getUsers() != null && !searchHash) result.addAll(body.getUsers());
|
||||
if (body.getHashtags() != null) result.addAll(body.getHashtags());
|
||||
if (body.getPlaces() != null) result.addAll(body.getPlaces());
|
||||
@ -431,7 +434,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
||||
}
|
||||
prevSuggestionAsync = searchService.search(isLoggedIn,
|
||||
searchUser || searchHash ? currentSearchQuery.substring(1)
|
||||
: currentSearchQuery,
|
||||
: currentSearchQuery,
|
||||
searchUser ? "user" : (searchHash ? "hashtag" : "blended"));
|
||||
suggestionAdapter.changeCursor(null);
|
||||
prevSuggestionAsync.enqueue(cb);
|
||||
@ -462,13 +465,13 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
||||
}
|
||||
|
||||
private void setupBottomNavigationBar(final boolean setDefaultTabFromSettings) {
|
||||
final List<Tab> tabs = !isLoggedIn ? setupAnonBottomNav() : setupMainBottomNav();
|
||||
currentTabs = !isLoggedIn ? setupAnonBottomNav() : setupMainBottomNav();
|
||||
|
||||
final List<Integer> mainNavList = tabs.stream()
|
||||
.map(Tab::getNavigationResId)
|
||||
.collect(Collectors.toList());
|
||||
final List<Integer> mainNavList = currentTabs.stream()
|
||||
.map(Tab::getNavigationResId)
|
||||
.collect(Collectors.toList());
|
||||
if (setDefaultTabFromSettings) {
|
||||
setSelectedTab(tabs);
|
||||
setSelectedTab(currentTabs);
|
||||
}
|
||||
final LiveData<NavController> navControllerLiveData = setupWithNavController(
|
||||
binding.bottomNavView,
|
||||
@ -875,4 +878,8 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
||||
public Toolbar getToolbar() {
|
||||
return binding.toolbar;
|
||||
}
|
||||
|
||||
public List<Tab> getCurrentTabs() {
|
||||
return currentTabs;
|
||||
}
|
||||
}
|
@ -92,7 +92,15 @@ public class TabOrderPreferenceDialogFragment extends DialogFragment {
|
||||
setSaveButtonState(newOrderTabs);
|
||||
// submit these tab lists to adapter
|
||||
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) {
|
||||
|
@ -307,6 +307,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
private AccountRepository accountRepository;
|
||||
private FavoriteRepository favoriteRepository;
|
||||
private AppStateViewModel appStateViewModel;
|
||||
private boolean disableDm = false;
|
||||
|
||||
@Override
|
||||
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;
|
||||
userService = isLoggedIn ? UserService.getInstance() : null;
|
||||
graphQLService = isLoggedIn ? null : GraphQLService.getInstance();
|
||||
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(getContext()));
|
||||
favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(getContext()));
|
||||
final Context context = getContext();
|
||||
if (context == null) return;
|
||||
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(context));
|
||||
favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(context));
|
||||
appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
@ -578,6 +581,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
}
|
||||
|
||||
private void init() {
|
||||
disableDm = fragmentActivity.getCurrentTabs()
|
||||
.stream()
|
||||
.noneMatch(tab -> tab.getNavigationRootId() == R.id.direct_messages_nav_graph);
|
||||
if (getArguments() != null) {
|
||||
final ProfileFragmentArgs fragmentArgs = ProfileFragmentArgs.fromBundle(getArguments());
|
||||
username = fragmentArgs.getUsername();
|
||||
@ -612,8 +618,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
username = profileModel.getUsername();
|
||||
setUsernameDelayed();
|
||||
setProfileDetails();
|
||||
}
|
||||
else if (isLoggedIn) {
|
||||
} else if (isLoggedIn) {
|
||||
userService.getUsernameInfo(usernameTemp, new ServiceCallback<User>() {
|
||||
@Override
|
||||
public void onSuccess(final User user) {
|
||||
@ -647,8 +652,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
} catch (final Throwable ignored) {}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
graphQLService.fetchUser(usernameTemp, new ServiceCallback<User>() {
|
||||
@Override
|
||||
public void onSuccess(final User user) {
|
||||
@ -939,7 +943,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
}
|
||||
profileDetailsBinding.btnSaved.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);
|
||||
final Context context = getContext();
|
||||
if (context == null) return;
|
||||
@ -1116,23 +1120,25 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
PostItemType.TAGGED);
|
||||
NavHostFragment.findNavController(this).navigate(action);
|
||||
});
|
||||
profileDetailsBinding.btnDM.setOnClickListener(v -> {
|
||||
profileDetailsBinding.btnDM.setEnabled(false);
|
||||
new CreateThreadAction(cookie, profileModel.getPk(), thread -> {
|
||||
if (thread == null) {
|
||||
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
||||
if (!disableDm) {
|
||||
profileDetailsBinding.btnDM.setOnClickListener(v -> {
|
||||
profileDetailsBinding.btnDM.setEnabled(false);
|
||||
new CreateThreadAction(cookie, profileModel.getPk(), thread -> {
|
||||
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);
|
||||
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);
|
||||
}).execute();
|
||||
});
|
||||
}).execute();
|
||||
});
|
||||
}
|
||||
profileDetailsBinding.mainProfileImage.setOnClickListener(v -> {
|
||||
if (!hasStories) {
|
||||
// show profile pic
|
||||
|
@ -2,7 +2,6 @@ package awais.instagrabber.fragments.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.ListPreference;
|
||||
@ -13,6 +12,7 @@ import androidx.preference.SwitchPreferenceCompat;
|
||||
import java.util.List;
|
||||
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.dialogs.ConfirmDialogFragment;
|
||||
import awais.instagrabber.dialogs.TabOrderPreferenceDialogFragment;
|
||||
import awais.instagrabber.utils.Constants;
|
||||
import awais.instagrabber.utils.CookieUtils;
|
||||
@ -34,9 +34,10 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen
|
||||
}
|
||||
screen.addPreference(getUpdateCheckPreference(context));
|
||||
screen.addPreference(getFlagSecurePreference(context));
|
||||
final List<Preference> preferences = FlavorSettings.getInstance().getPreferences(context,
|
||||
getChildFragmentManager(),
|
||||
SettingCategory.GENERAL);
|
||||
final List<Preference> preferences = FlavorSettings.getInstance()
|
||||
.getPreferences(context,
|
||||
getChildFragmentManager(),
|
||||
SettingCategory.GENERAL);
|
||||
if (preferences != null) {
|
||||
for (final Preference preference : preferences) {
|
||||
screen.addPreference(preference);
|
||||
@ -101,7 +102,15 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen
|
||||
|
||||
@Override
|
||||
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
|
||||
|
@ -27,6 +27,7 @@ import java.util.List;
|
||||
import awais.instagrabber.BuildConfig;
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.activities.Login;
|
||||
import awais.instagrabber.activities.MainActivity;
|
||||
import awais.instagrabber.databinding.PrefAccountSwitcherBinding;
|
||||
import awais.instagrabber.db.datasources.AccountDataSource;
|
||||
import awais.instagrabber.db.entities.Account;
|
||||
@ -157,13 +158,24 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
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;
|
||||
}));
|
||||
|
||||
// Check if favorites has been added as a tab. And if so, do not add in this list
|
||||
boolean showFavorites = true;
|
||||
final MainActivity activity = (MainActivity) getActivity();
|
||||
if (activity != null && activity.getCurrentTabs() != null) {
|
||||
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(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="tab_order">Screen order</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>
|
||||
|
Loading…
Reference in New Issue
Block a user