Fix an offset issue
This commit is contained in:
parent
7020644b3d
commit
3dbfe33983
|
@ -27,6 +27,7 @@ import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -488,7 +489,9 @@ public class PinnedTimelineHelper {
|
||||||
// Set LongClick listener to each Tab
|
// Set LongClick listener to each Tab
|
||||||
int finalI = i;
|
int finalI = i;
|
||||||
tabStrip.getChildAt(i).setOnLongClickListener(v -> {
|
tabStrip.getChildAt(i).setOnLongClickListener(v -> {
|
||||||
|
|
||||||
int position = finalI - (BOTTOM_TIMELINE_COUNT - finalToRemove);
|
int position = finalI - (BOTTOM_TIMELINE_COUNT - finalToRemove);
|
||||||
|
Log.v(Helper.TAG, "position: " + position + " -> " + pinnedTimelineVisibleList.get(position).type);
|
||||||
switch (pinnedTimelineVisibleList.get(position).type) {
|
switch (pinnedTimelineVisibleList.get(position).type) {
|
||||||
case LIST:
|
case LIST:
|
||||||
|
|
||||||
|
@ -759,8 +762,14 @@ public class PinnedTimelineHelper {
|
||||||
int toRemove = itemToRemoveInBottomMenu(activity);
|
int toRemove = itemToRemoveInBottomMenu(activity);
|
||||||
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(activity, Helper.popupStyle()), view);
|
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(activity, Helper.popupStyle()), view);
|
||||||
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
|
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
|
||||||
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
|
boolean singleBar = sharedpreferences.getBoolean(activity.getString(R.string.SET_USE_SINGLE_TOPBAR), false);
|
||||||
|
if (singleBar) {
|
||||||
|
offSetPosition = position;
|
||||||
|
}
|
||||||
String tag;
|
String tag;
|
||||||
TagTimeline tagTimeline = pinned.pinnedTimelines.get(offSetPosition).tagTimeline;
|
TagTimeline tagTimeline = pinned.pinnedTimelines.get(offSetPosition).tagTimeline;
|
||||||
|
Log.v(Helper.TAG, "tagTimeline: " + tagTimeline);
|
||||||
if (tagTimeline == null)
|
if (tagTimeline == null)
|
||||||
return;
|
return;
|
||||||
if (tagTimeline.displayName != null)
|
if (tagTimeline.displayName != null)
|
||||||
|
@ -803,6 +812,7 @@ public class PinnedTimelineHelper {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
int finalOffSetPosition = offSetPosition;
|
||||||
popup.setOnMenuItemClickListener(item -> {
|
popup.setOnMenuItemClickListener(item -> {
|
||||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
||||||
item.setActionView(new View(activity));
|
item.setActionView(new View(activity));
|
||||||
|
@ -822,7 +832,7 @@ public class PinnedTimelineHelper {
|
||||||
if (itemId == R.id.action_show_media_only) {
|
if (itemId == R.id.action_show_media_only) {
|
||||||
mediaOnly[0] = !mediaOnly[0];
|
mediaOnly[0] = !mediaOnly[0];
|
||||||
tagTimeline.isART = mediaOnly[0];
|
tagTimeline.isART = mediaOnly[0];
|
||||||
pinned.pinnedTimelines.get(offSetPosition).tagTimeline = tagTimeline;
|
pinned.pinnedTimelines.get(finalOffSetPosition).tagTimeline = tagTimeline;
|
||||||
itemMediaOnly.setChecked(mediaOnly[0]);
|
itemMediaOnly.setChecked(mediaOnly[0]);
|
||||||
try {
|
try {
|
||||||
new Pinned(activity).updatePinned(pinned);
|
new Pinned(activity).updatePinned(pinned);
|
||||||
|
@ -832,7 +842,7 @@ public class PinnedTimelineHelper {
|
||||||
} else if (itemId == R.id.action_show_nsfw) {
|
} else if (itemId == R.id.action_show_nsfw) {
|
||||||
showNSFW[0] = !showNSFW[0];
|
showNSFW[0] = !showNSFW[0];
|
||||||
tagTimeline.isNSFW = showNSFW[0];
|
tagTimeline.isNSFW = showNSFW[0];
|
||||||
pinned.pinnedTimelines.get(offSetPosition).tagTimeline = tagTimeline;
|
pinned.pinnedTimelines.get(finalOffSetPosition).tagTimeline = tagTimeline;
|
||||||
itemShowNSFW.setChecked(showNSFW[0]);
|
itemShowNSFW.setChecked(showNSFW[0]);
|
||||||
try {
|
try {
|
||||||
new Pinned(activity).updatePinned(pinned);
|
new Pinned(activity).updatePinned(pinned);
|
||||||
|
@ -855,7 +865,7 @@ public class PinnedTimelineHelper {
|
||||||
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
||||||
String[] values = editText.getText().toString().trim().split("\\s+");
|
String[] values = editText.getText().toString().trim().split("\\s+");
|
||||||
tagTimeline.any = new ArrayList<>(Arrays.asList(values));
|
tagTimeline.any = new ArrayList<>(Arrays.asList(values));
|
||||||
pinned.pinnedTimelines.get(offSetPosition).tagTimeline = tagTimeline;
|
pinned.pinnedTimelines.get(finalOffSetPosition).tagTimeline = tagTimeline;
|
||||||
try {
|
try {
|
||||||
new Pinned(activity).updatePinned(pinned);
|
new Pinned(activity).updatePinned(pinned);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
@ -884,7 +894,7 @@ public class PinnedTimelineHelper {
|
||||||
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
||||||
String[] values = editTextAll.getText().toString().trim().split("\\s+");
|
String[] values = editTextAll.getText().toString().trim().split("\\s+");
|
||||||
tagTimeline.all = new ArrayList<>(Arrays.asList(values));
|
tagTimeline.all = new ArrayList<>(Arrays.asList(values));
|
||||||
pinned.pinnedTimelines.get(offSetPosition).tagTimeline = tagTimeline;
|
pinned.pinnedTimelines.get(finalOffSetPosition).tagTimeline = tagTimeline;
|
||||||
try {
|
try {
|
||||||
new Pinned(activity).updatePinned(pinned);
|
new Pinned(activity).updatePinned(pinned);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
@ -913,7 +923,7 @@ public class PinnedTimelineHelper {
|
||||||
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
||||||
String[] values = editTextNone.getText().toString().trim().split("\\s+");
|
String[] values = editTextNone.getText().toString().trim().split("\\s+");
|
||||||
tagTimeline.none = new ArrayList<>(Arrays.asList(values));
|
tagTimeline.none = new ArrayList<>(Arrays.asList(values));
|
||||||
pinned.pinnedTimelines.get(offSetPosition).tagTimeline = tagTimeline;
|
pinned.pinnedTimelines.get(finalOffSetPosition).tagTimeline = tagTimeline;
|
||||||
try {
|
try {
|
||||||
new Pinned(activity).updatePinned(pinned);
|
new Pinned(activity).updatePinned(pinned);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
@ -941,7 +951,7 @@ public class PinnedTimelineHelper {
|
||||||
if (values.trim().length() == 0)
|
if (values.trim().length() == 0)
|
||||||
values = tag;
|
values = tag;
|
||||||
tagTimeline.displayName = values;
|
tagTimeline.displayName = values;
|
||||||
pinned.pinnedTimelines.get(offSetPosition).tagTimeline = tagTimeline;
|
pinned.pinnedTimelines.get(finalOffSetPosition).tagTimeline = tagTimeline;
|
||||||
try {
|
try {
|
||||||
new Pinned(activity).updatePinned(pinned);
|
new Pinned(activity).updatePinned(pinned);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
@ -970,6 +980,11 @@ public class PinnedTimelineHelper {
|
||||||
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(activity, Helper.popupStyle()), view);
|
PopupMenu popup = new PopupMenu(new ContextThemeWrapper(activity, Helper.popupStyle()), view);
|
||||||
int toRemove = itemToRemoveInBottomMenu(activity);
|
int toRemove = itemToRemoveInBottomMenu(activity);
|
||||||
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
|
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
|
||||||
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
|
boolean singleBar = sharedpreferences.getBoolean(activity.getString(R.string.SET_USE_SINGLE_TOPBAR), false);
|
||||||
|
if (singleBar) {
|
||||||
|
offSetPosition = position;
|
||||||
|
}
|
||||||
RemoteInstance remoteInstance = pinned.pinnedTimelines.get(offSetPosition).remoteInstance;
|
RemoteInstance remoteInstance = pinned.pinnedTimelines.get(offSetPosition).remoteInstance;
|
||||||
if (remoteInstance == null)
|
if (remoteInstance == null)
|
||||||
return;
|
return;
|
||||||
|
@ -984,6 +999,7 @@ public class PinnedTimelineHelper {
|
||||||
|
|
||||||
MenuItem itemAll = popup.getMenu().add(0, 0, Menu.NONE, title);
|
MenuItem itemAll = popup.getMenu().add(0, 0, Menu.NONE, title);
|
||||||
|
|
||||||
|
int finalOffSetPosition = offSetPosition;
|
||||||
itemAll.setOnMenuItemClickListener(item -> {
|
itemAll.setOnMenuItemClickListener(item -> {
|
||||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
||||||
item.setActionView(new View(activity));
|
item.setActionView(new View(activity));
|
||||||
|
@ -1010,10 +1026,10 @@ public class PinnedTimelineHelper {
|
||||||
return false;
|
return false;
|
||||||
FragmentTransaction fragTransaction1 = activity.getSupportFragmentManager().beginTransaction();
|
FragmentTransaction fragTransaction1 = activity.getSupportFragmentManager().beginTransaction();
|
||||||
|
|
||||||
pinned.pinnedTimelines.get(offSetPosition).remoteInstance.filteredWith = null;
|
pinned.pinnedTimelines.get(finalOffSetPosition).remoteInstance.filteredWith = null;
|
||||||
remoteInstance.filteredWith = null;
|
remoteInstance.filteredWith = null;
|
||||||
currentFilter[0] = null;
|
currentFilter[0] = null;
|
||||||
pinned.pinnedTimelines.get(offSetPosition).remoteInstance = remoteInstance;
|
pinned.pinnedTimelines.get(finalOffSetPosition).remoteInstance = remoteInstance;
|
||||||
try {
|
try {
|
||||||
new Pinned(activity).updatePinned(pinned);
|
new Pinned(activity).updatePinned(pinned);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
@ -1021,7 +1037,7 @@ public class PinnedTimelineHelper {
|
||||||
}
|
}
|
||||||
fragTransaction1.detach(fragmentMastodonTimeline).commit();
|
fragTransaction1.detach(fragmentMastodonTimeline).commit();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned.pinnedTimelines.get(offSetPosition));
|
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned.pinnedTimelines.get(finalOffSetPosition));
|
||||||
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
|
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
|
||||||
fragmentMastodonTimeline.setArguments(bundle);
|
fragmentMastodonTimeline.setArguments(bundle);
|
||||||
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
|
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
|
||||||
|
@ -1043,6 +1059,7 @@ public class PinnedTimelineHelper {
|
||||||
title = tag;
|
title = tag;
|
||||||
}
|
}
|
||||||
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
|
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
|
||||||
|
int finalOffSetPosition1 = offSetPosition;
|
||||||
item.setOnMenuItemClickListener(item1 -> {
|
item.setOnMenuItemClickListener(item1 -> {
|
||||||
FragmentMastodonTimeline fragmentMastodonTimeline = null;
|
FragmentMastodonTimeline fragmentMastodonTimeline = null;
|
||||||
if (activityMainBinding.viewPager.getAdapter() != null) {
|
if (activityMainBinding.viewPager.getAdapter() != null) {
|
||||||
|
@ -1055,7 +1072,7 @@ public class PinnedTimelineHelper {
|
||||||
FragmentTransaction fragTransaction1 = activity.getSupportFragmentManager().beginTransaction();
|
FragmentTransaction fragTransaction1 = activity.getSupportFragmentManager().beginTransaction();
|
||||||
if (fragmentMastodonTimeline == null)
|
if (fragmentMastodonTimeline == null)
|
||||||
return false;
|
return false;
|
||||||
pinned.pinnedTimelines.get(offSetPosition).remoteInstance.filteredWith = tag;
|
pinned.pinnedTimelines.get(finalOffSetPosition1).remoteInstance.filteredWith = tag;
|
||||||
remoteInstance.filteredWith = tag;
|
remoteInstance.filteredWith = tag;
|
||||||
try {
|
try {
|
||||||
new Pinned(activity).updatePinned(pinned);
|
new Pinned(activity).updatePinned(pinned);
|
||||||
|
@ -1065,7 +1082,7 @@ public class PinnedTimelineHelper {
|
||||||
currentFilter[0] = remoteInstance.filteredWith;
|
currentFilter[0] = remoteInstance.filteredWith;
|
||||||
fragTransaction1.detach(fragmentMastodonTimeline).commit();
|
fragTransaction1.detach(fragmentMastodonTimeline).commit();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned.pinnedTimelines.get(offSetPosition));
|
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned.pinnedTimelines.get(finalOffSetPosition1));
|
||||||
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
|
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
|
||||||
fragmentMastodonTimeline.setArguments(bundle);
|
fragmentMastodonTimeline.setArguments(bundle);
|
||||||
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
|
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
|
||||||
|
@ -1122,6 +1139,7 @@ public class PinnedTimelineHelper {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
int finalOffSetPosition2 = offSetPosition;
|
||||||
popup.setOnDismissListener(menu -> {
|
popup.setOnDismissListener(menu -> {
|
||||||
if (changes[0]) {
|
if (changes[0]) {
|
||||||
FragmentMastodonTimeline fragmentMastodonTimeline = null;
|
FragmentMastodonTimeline fragmentMastodonTimeline = null;
|
||||||
|
@ -1137,7 +1155,7 @@ public class PinnedTimelineHelper {
|
||||||
return;
|
return;
|
||||||
fragTransaction1.detach(fragmentMastodonTimeline).commit();
|
fragTransaction1.detach(fragmentMastodonTimeline).commit();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned.pinnedTimelines.get(offSetPosition));
|
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned.pinnedTimelines.get(finalOffSetPosition2));
|
||||||
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
|
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
|
||||||
fragmentMastodonTimeline.setArguments(bundle);
|
fragmentMastodonTimeline.setArguments(bundle);
|
||||||
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
|
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
|
||||||
|
@ -1160,6 +1178,11 @@ public class PinnedTimelineHelper {
|
||||||
|
|
||||||
int toRemove = itemToRemoveInBottomMenu(activity);
|
int toRemove = itemToRemoveInBottomMenu(activity);
|
||||||
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
|
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
|
||||||
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
|
boolean singleBar = sharedpreferences.getBoolean(activity.getString(R.string.SET_USE_SINGLE_TOPBAR), false);
|
||||||
|
if (singleBar) {
|
||||||
|
offSetPosition = position;
|
||||||
|
}
|
||||||
RemoteInstance remoteInstance = pinned.pinnedTimelines.get(offSetPosition).remoteInstance;
|
RemoteInstance remoteInstance = pinned.pinnedTimelines.get(offSetPosition).remoteInstance;
|
||||||
if (remoteInstance == null)
|
if (remoteInstance == null)
|
||||||
return;
|
return;
|
||||||
|
@ -1174,8 +1197,9 @@ public class PinnedTimelineHelper {
|
||||||
editText.setText(accounts);
|
editText.setText(accounts);
|
||||||
editText.setSelection(editText.getText().toString().length());
|
editText.setSelection(editText.getText().toString().length());
|
||||||
}
|
}
|
||||||
|
int finalOffSetPosition = offSetPosition;
|
||||||
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
||||||
pinned.pinnedTimelines.get(offSetPosition).remoteInstance.host = editText.getText().toString().trim();
|
pinned.pinnedTimelines.get(finalOffSetPosition).remoteInstance.host = editText.getText().toString().trim();
|
||||||
try {
|
try {
|
||||||
new Pinned(activity).updatePinned(pinned);
|
new Pinned(activity).updatePinned(pinned);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
@ -1194,7 +1218,7 @@ public class PinnedTimelineHelper {
|
||||||
return;
|
return;
|
||||||
fragTransaction1.detach(fragmentMastodonTimeline).commit();
|
fragTransaction1.detach(fragmentMastodonTimeline).commit();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned.pinnedTimelines.get(offSetPosition));
|
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned.pinnedTimelines.get(finalOffSetPosition));
|
||||||
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
|
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
|
||||||
fragmentMastodonTimeline.setArguments(bundle);
|
fragmentMastodonTimeline.setArguments(bundle);
|
||||||
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
|
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
|
||||||
|
|
Loading…
Reference in New Issue