mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-01-07 00:20:08 +02:00
Allow to edit Nitter accounts with a long click on tabs
This commit is contained in:
parent
7e30ba8fb3
commit
564e0c682c
3 changed files with 73 additions and 4 deletions
|
@ -538,6 +538,9 @@ public class Helper {
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public static String dateDiff(Context context, Date date) {
|
public static String dateDiff(Context context, Date date) {
|
||||||
|
if (date == null) {
|
||||||
|
date = new Date();
|
||||||
|
}
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
long diff = now.getTime() - date.getTime();
|
long diff = now.getTime() - date.getTime();
|
||||||
long seconds = diff / 1000;
|
long seconds = diff / 1000;
|
||||||
|
|
|
@ -412,7 +412,8 @@ 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 -> {
|
||||||
switch (pinnedTimelineVisibleList.get(finalI - (BOTTOM_TIMELINE_COUNT - finalToRemove)).type) {
|
int position = finalI - (BOTTOM_TIMELINE_COUNT - finalToRemove);
|
||||||
|
switch (pinnedTimelineVisibleList.get(position).type) {
|
||||||
case LIST:
|
case LIST:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -420,12 +421,16 @@ public class PinnedTimelineHelper {
|
||||||
tagClick(activity, finalPinned, v, activityMainBinding, finalI);
|
tagClick(activity, finalPinned, v, activityMainBinding, finalI);
|
||||||
break;
|
break;
|
||||||
case REMOTE:
|
case REMOTE:
|
||||||
instanceClick(activity, finalPinned, v, activityMainBinding, finalI);
|
if (pinnedTimelineVisibleList.get(position).remoteInstance.type != RemoteInstance.InstanceType.NITTER) {
|
||||||
|
instanceClick(activity, finalPinned, v, activityMainBinding, finalI);
|
||||||
|
} else {
|
||||||
|
nitterClick(activity, finalPinned, activityMainBinding, finalI);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case HOME:
|
case HOME:
|
||||||
case LOCAL:
|
case LOCAL:
|
||||||
case PUBLIC:
|
case PUBLIC:
|
||||||
defaultClick(activity, pinnedTimelineVisibleList.get(finalI - (BOTTOM_TIMELINE_COUNT - finalToRemove)).type, v, activityMainBinding, finalI);
|
defaultClick(activity, pinnedTimelineVisibleList.get(position).type, v, activityMainBinding, finalI);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1042,4 +1047,62 @@ public class PinnedTimelineHelper {
|
||||||
|
|
||||||
popup.show();
|
popup.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manage long clicks on Nitter instances
|
||||||
|
*
|
||||||
|
* @param activity - BaseMainActivity activity
|
||||||
|
* @param pinned - {@link Pinned}
|
||||||
|
* @param position - int position of the tab
|
||||||
|
*/
|
||||||
|
public static void nitterClick(BaseMainActivity activity, Pinned pinned, ActivityMainBinding activityMainBinding, int position) {
|
||||||
|
|
||||||
|
int toRemove = itemToRemoveInBottomMenu(activity);
|
||||||
|
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
|
||||||
|
RemoteInstance remoteInstance = pinned.pinnedTimelines.get(offSetPosition).remoteInstance;
|
||||||
|
if (remoteInstance == null)
|
||||||
|
return;
|
||||||
|
String accounts = remoteInstance.host;
|
||||||
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, Helper.dialogStyle());
|
||||||
|
LayoutInflater inflater = activity.getLayoutInflater();
|
||||||
|
View dialogView = inflater.inflate(R.layout.tags_any, new LinearLayout(activity), false);
|
||||||
|
dialogBuilder.setView(dialogView);
|
||||||
|
final EditText editText = dialogView.findViewById(R.id.filter_any);
|
||||||
|
editText.setHint(R.string.list_of_twitter_accounts);
|
||||||
|
if (accounts != null) {
|
||||||
|
editText.setText(accounts);
|
||||||
|
editText.setSelection(editText.getText().toString().length());
|
||||||
|
}
|
||||||
|
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
||||||
|
pinned.pinnedTimelines.get(offSetPosition).remoteInstance.host = editText.getText().toString().trim();
|
||||||
|
try {
|
||||||
|
new Pinned(activity).updatePinned(pinned);
|
||||||
|
} catch (DBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
FragmentMastodonTimeline fragmentMastodonTimeline = null;
|
||||||
|
if (activityMainBinding.viewPager.getAdapter() != null) {
|
||||||
|
Fragment fragment = (Fragment) activityMainBinding.viewPager.getAdapter().instantiateItem(activityMainBinding.viewPager, activityMainBinding.tabLayout.getSelectedTabPosition());
|
||||||
|
if (fragment instanceof FragmentMastodonTimeline && fragment.isVisible()) {
|
||||||
|
fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment);
|
||||||
|
fragmentMastodonTimeline.refreshAllAdapters();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FragmentTransaction fragTransaction1 = activity.getSupportFragmentManager().beginTransaction();
|
||||||
|
if (fragmentMastodonTimeline == null)
|
||||||
|
return;
|
||||||
|
fragTransaction1.detach(fragmentMastodonTimeline).commit();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned.pinnedTimelines.get(offSetPosition));
|
||||||
|
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
|
||||||
|
fragmentMastodonTimeline.setArguments(bundle);
|
||||||
|
FragmentTransaction fragTransaction2 = activity.getSupportFragmentManager().beginTransaction();
|
||||||
|
fragTransaction2.attach(fragmentMastodonTimeline);
|
||||||
|
fragTransaction2.commit();
|
||||||
|
});
|
||||||
|
AlertDialog alertDialog = dialogBuilder.create();
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,13 +214,16 @@ public class TimelinesVM extends AndroidViewModel {
|
||||||
String accountsStr,
|
String accountsStr,
|
||||||
String max_position) {
|
String max_position) {
|
||||||
MastodonTimelinesService mastodonTimelinesService = initInstanceXMLOnly(instance);
|
MastodonTimelinesService mastodonTimelinesService = initInstanceXMLOnly(instance);
|
||||||
|
accountsStr = accountsStr.replaceAll("\\s", ",");
|
||||||
statusesMutableLiveData = new MutableLiveData<>();
|
statusesMutableLiveData = new MutableLiveData<>();
|
||||||
|
String finalAccountsStr = accountsStr;
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
Call<Nitter> publicTlCall = mastodonTimelinesService.getNitter(accountsStr, max_position);
|
Call<Nitter> publicTlCall = mastodonTimelinesService.getNitter(finalAccountsStr, max_position);
|
||||||
Statuses statuses = new Statuses();
|
Statuses statuses = new Statuses();
|
||||||
if (publicTlCall != null) {
|
if (publicTlCall != null) {
|
||||||
try {
|
try {
|
||||||
Response<Nitter> publicTlResponse = publicTlCall.execute();
|
Response<Nitter> publicTlResponse = publicTlCall.execute();
|
||||||
|
|
||||||
if (publicTlResponse.isSuccessful()) {
|
if (publicTlResponse.isSuccessful()) {
|
||||||
Nitter rssResponse = publicTlResponse.body();
|
Nitter rssResponse = publicTlResponse.body();
|
||||||
List<Status> statusList = new ArrayList<>();
|
List<Status> statusList = new ArrayList<>();
|
||||||
|
|
Loading…
Reference in a new issue