forked from mirrors/Fedilab
Rename Nitter instances
This commit is contained in:
parent
8e93b2d2bc
commit
8c44f338da
5 changed files with 114 additions and 47 deletions
|
@ -27,6 +27,8 @@ public class RemoteInstance implements Serializable {
|
||||||
public String id;
|
public String id;
|
||||||
@SerializedName("host")
|
@SerializedName("host")
|
||||||
public String host;
|
public String host;
|
||||||
|
@SerializedName("displayName")
|
||||||
|
public String displayName;
|
||||||
@SerializedName("type")
|
@SerializedName("type")
|
||||||
public InstanceType type;
|
public InstanceType type;
|
||||||
@SerializedName("tags")
|
@SerializedName("tags")
|
||||||
|
|
|
@ -39,6 +39,7 @@ import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.widget.AppCompatTextView;
|
||||||
import androidx.appcompat.widget.PopupMenu;
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
@ -356,6 +357,10 @@ public class PinnedTimelineHelper {
|
||||||
name = pinnedTimeline.remoteInstance.host;
|
name = pinnedTimeline.remoteInstance.host;
|
||||||
if (pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
|
if (pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
|
||||||
String remoteInstance = sharedpreferences.getString(activity.getString(R.string.SET_NITTER_HOST), activity.getString(R.string.DEFAULT_NITTER_HOST)).toLowerCase();
|
String remoteInstance = sharedpreferences.getString(activity.getString(R.string.SET_NITTER_HOST), activity.getString(R.string.DEFAULT_NITTER_HOST)).toLowerCase();
|
||||||
|
//Custom name for Nitter instances
|
||||||
|
if (pinnedTimeline.remoteInstance.displayName != null && pinnedTimeline.remoteInstance.displayName.trim().length() > 0) {
|
||||||
|
name = pinnedTimeline.remoteInstance.displayName;
|
||||||
|
}
|
||||||
ident = "@R@" + remoteInstance;
|
ident = "@R@" + remoteInstance;
|
||||||
} else {
|
} else {
|
||||||
ident = "@R@" + pinnedTimeline.remoteInstance.host;
|
ident = "@R@" + pinnedTimeline.remoteInstance.host;
|
||||||
|
@ -521,7 +526,7 @@ public class PinnedTimelineHelper {
|
||||||
if (pinnedTimelineVisibleList.get(position).remoteInstance.type != RemoteInstance.InstanceType.NITTER) {
|
if (pinnedTimelineVisibleList.get(position).remoteInstance.type != RemoteInstance.InstanceType.NITTER) {
|
||||||
instanceClick(activity, finalPinned, v, activityMainBinding, finalI, activityMainBinding.tabLayout.getTabAt(finalI).getTag().toString());
|
instanceClick(activity, finalPinned, v, activityMainBinding, finalI, activityMainBinding.tabLayout.getTabAt(finalI).getTag().toString());
|
||||||
} else {
|
} else {
|
||||||
nitterClick(activity, finalPinned, activityMainBinding, finalI, activityMainBinding.tabLayout.getTabAt(finalI).getTag().toString());
|
nitterClick(activity, finalPinned, v, activityMainBinding, finalI, activityMainBinding.tabLayout.getTabAt(finalI).getTag().toString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HOME:
|
case HOME:
|
||||||
|
@ -979,6 +984,10 @@ public class PinnedTimelineHelper {
|
||||||
if (values.trim().length() == 0)
|
if (values.trim().length() == 0)
|
||||||
values = tag;
|
values = tag;
|
||||||
tagTimeline.displayName = values;
|
tagTimeline.displayName = values;
|
||||||
|
View titleView = view.findViewById(R.id.title);
|
||||||
|
if (titleView instanceof AppCompatTextView) {
|
||||||
|
((AppCompatTextView) titleView).setText(tagTimeline.displayName);
|
||||||
|
}
|
||||||
pinned.pinnedTimelines.get(finalOffSetPosition).tagTimeline = tagTimeline;
|
pinned.pinnedTimelines.get(finalOffSetPosition).tagTimeline = tagTimeline;
|
||||||
try {
|
try {
|
||||||
new Pinned(activity).updatePinned(pinned);
|
new Pinned(activity).updatePinned(pinned);
|
||||||
|
@ -1224,7 +1233,7 @@ public class PinnedTimelineHelper {
|
||||||
* @param pinned - {@link Pinned}
|
* @param pinned - {@link Pinned}
|
||||||
* @param position - int position of the tab
|
* @param position - int position of the tab
|
||||||
*/
|
*/
|
||||||
public static void nitterClick(BaseMainActivity activity, Pinned pinned, ActivityMainBinding activityMainBinding, int position, String slug) {
|
public static void nitterClick(BaseMainActivity activity, Pinned pinned, View view, ActivityMainBinding activityMainBinding, int position, String slug) {
|
||||||
|
|
||||||
int toRemove = itemToRemoveInBottomMenu(activity);
|
int toRemove = itemToRemoveInBottomMenu(activity);
|
||||||
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
|
int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove);
|
||||||
|
@ -1236,6 +1245,46 @@ public class PinnedTimelineHelper {
|
||||||
RemoteInstance remoteInstance = pinned.pinnedTimelines.get(offSetPosition).remoteInstance;
|
RemoteInstance remoteInstance = pinned.pinnedTimelines.get(offSetPosition).remoteInstance;
|
||||||
if (remoteInstance == null)
|
if (remoteInstance == null)
|
||||||
return;
|
return;
|
||||||
|
PopupMenu popup = new PopupMenu(activity, view);
|
||||||
|
popup.getMenuInflater()
|
||||||
|
.inflate(R.menu.option_nitter_timeline, popup.getMenu());
|
||||||
|
int finalOffSetPosition = offSetPosition;
|
||||||
|
popup.setOnMenuItemClickListener(item -> {
|
||||||
|
int itemId = item.getItemId();
|
||||||
|
if (itemId == R.id.action_displayname) {
|
||||||
|
AlertDialog.Builder dialogBuilder;
|
||||||
|
LayoutInflater inflater;
|
||||||
|
View dialogView;
|
||||||
|
AlertDialog alertDialog;
|
||||||
|
dialogBuilder = new AlertDialog.Builder(activity, Helper.dialogStyle());
|
||||||
|
inflater = activity.getLayoutInflater();
|
||||||
|
dialogView = inflater.inflate(R.layout.tags_name, new LinearLayout(activity), false);
|
||||||
|
dialogBuilder.setView(dialogView);
|
||||||
|
final EditText editTextName = dialogView.findViewById(R.id.column_name);
|
||||||
|
if (remoteInstance.displayName != null) {
|
||||||
|
editTextName.setText(remoteInstance.displayName);
|
||||||
|
editTextName.setSelection(editTextName.getText().toString().length());
|
||||||
|
}
|
||||||
|
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
||||||
|
String values = editTextName.getText().toString();
|
||||||
|
if (values.trim().length() == 0) {
|
||||||
|
values = remoteInstance.displayName;
|
||||||
|
}
|
||||||
|
remoteInstance.displayName = values;
|
||||||
|
View titleView = view.findViewById(R.id.title);
|
||||||
|
if (titleView instanceof AppCompatTextView) {
|
||||||
|
((AppCompatTextView) titleView).setText(remoteInstance.displayName);
|
||||||
|
}
|
||||||
|
pinned.pinnedTimelines.get(finalOffSetPosition).remoteInstance = remoteInstance;
|
||||||
|
try {
|
||||||
|
new Pinned(activity).updatePinned(pinned);
|
||||||
|
} catch (DBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alertDialog = dialogBuilder.create();
|
||||||
|
alertDialog.show();
|
||||||
|
} else if (itemId == R.id.action_nitter_manage_accounts) {
|
||||||
String accounts = remoteInstance.host;
|
String accounts = remoteInstance.host;
|
||||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, Helper.dialogStyle());
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, Helper.dialogStyle());
|
||||||
LayoutInflater inflater = activity.getLayoutInflater();
|
LayoutInflater inflater = activity.getLayoutInflater();
|
||||||
|
@ -1247,7 +1296,6 @@ 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(finalOffSetPosition).remoteInstance.host = editText.getText().toString().trim();
|
pinned.pinnedTimelines.get(finalOffSetPosition).remoteInstance.host = editText.getText().toString().trim();
|
||||||
try {
|
try {
|
||||||
|
@ -1285,6 +1333,10 @@ public class PinnedTimelineHelper {
|
||||||
AlertDialog alertDialog = dialogBuilder.create();
|
AlertDialog alertDialog = dialogBuilder.create();
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
popup.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
12
app/src/main/res/menu/option_nitter_timeline.xml
Normal file
12
app/src/main/res/menu/option_nitter_timeline.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_displayname"
|
||||||
|
android:title="@string/change_tag_column"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_nitter_manage_accounts"
|
||||||
|
android:title="@string/manage_accounts"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
</menu>
|
|
@ -2111,4 +2111,5 @@
|
||||||
<string name="mute_them_all">Mute them all</string>
|
<string name="mute_them_all">Mute them all</string>
|
||||||
<string name="import_data">Import data</string>
|
<string name="import_data">Import data</string>
|
||||||
<string name="group_reblogs">Group reblogs in home timeline</string>
|
<string name="group_reblogs">Group reblogs in home timeline</string>
|
||||||
|
<string name="manage_accounts">Manage accounts</string>
|
||||||
</resources>
|
</resources>
|
|
@ -1,5 +1,5 @@
|
||||||
Added:
|
Added:
|
||||||
|
- Rename Nitter timelines
|
||||||
|
|
||||||
Changed:
|
Changed:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue