feat(instance-info): add options menu
This commit is contained in:
@@ -10,6 +10,9 @@ import android.os.Bundle;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewOutlineProvider;
|
||||
@@ -72,12 +75,10 @@ public class InstanceInfoFragment extends LoaderFragment {
|
||||
private CoverImageView cover;
|
||||
private TextView uri, description, readMore;
|
||||
|
||||
private Button timelineButton, pinButton, rulesButton, serversButton;
|
||||
|
||||
private View spaceBelowText;
|
||||
private final CoverOverlayGradientDrawable coverGradient=new CoverOverlayGradientDrawable();
|
||||
|
||||
private ScrollView textScrollView;
|
||||
private ScrollView scrollView, textScrollView;
|
||||
private float titleTransY;
|
||||
|
||||
private String accountID;
|
||||
@@ -127,13 +128,10 @@ public class InstanceInfoFragment extends LoaderFragment {
|
||||
public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
|
||||
View content=inflater.inflate(R.layout.fragment_instance_info, container, false);
|
||||
|
||||
scrollView=content.findViewById(R.id.scroll_view);
|
||||
cover=content.findViewById(R.id.cover);
|
||||
uri =content.findViewById(R.id.uri);
|
||||
description=content.findViewById(R.id.description);
|
||||
timelineButton=content.findViewById(R.id.timeline_btn);
|
||||
pinButton=content.findViewById(R.id.timeline_pin_btn);
|
||||
rulesButton=content.findViewById(R.id.rules_btn);
|
||||
serversButton=content.findViewById(R.id.servers_btn);
|
||||
list=content.findViewById(R.id.metadata);
|
||||
textScrollView=content.findViewById(R.id.text_scroll_view);
|
||||
readMore=content.findViewById(R.id.read_more);
|
||||
@@ -151,10 +149,6 @@ public class InstanceInfoFragment extends LoaderFragment {
|
||||
}
|
||||
});
|
||||
|
||||
timelineButton.setOnClickListener(this::onTimelineButtonClick);
|
||||
pinButton.setOnClickListener(this::onPinButtonClick);
|
||||
rulesButton.setOnClickListener(this::onRulesButtonClick);
|
||||
serversButton.setOnClickListener(this::onSeversButtonClick);
|
||||
cover.setOnClickListener(this::onCoverClick);
|
||||
readMore.setOnClickListener(this::onReadMoreClick);
|
||||
|
||||
@@ -327,14 +321,44 @@ public class InstanceInfoFragment extends LoaderFragment {
|
||||
toolbarTitleView.setTranslationY(titleTransY);
|
||||
toolbarSubtitleView.setTranslationY(titleTransY);
|
||||
}
|
||||
getToolbar().setOnClickListener(v->scrollToTop());
|
||||
getToolbar().setNavigationContentDescription(R.string.back);
|
||||
}
|
||||
|
||||
public void scrollToTop(){
|
||||
scrollView.smoothScrollTo(0, 0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
|
||||
inflater.inflate(R.menu.instance_info, menu);
|
||||
UiUtils.enableOptionsMenuIcons(getActivity(), menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item){
|
||||
int id=item.getItemId();
|
||||
if (id==R.id.open_timeline) {
|
||||
Bundle args=new Bundle();
|
||||
args.putString("account", accountID);
|
||||
args.putString("domain", instance.uri);
|
||||
Nav.go(getActivity(), CustomLocalTimelineFragment.class, args);
|
||||
}else if (id==R.id.rules) {
|
||||
Bundle args=new Bundle();
|
||||
args.putParcelable("instance", Parcels.wrap(instance));
|
||||
Nav.go(getActivity(), InstanceRulesFragment.class, args);
|
||||
} else if (id==R.id.moderated_servers) {
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean wantsLightStatusBar(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getToolbarResource(){
|
||||
return R.layout.profile_toolbar;
|
||||
@@ -344,32 +368,6 @@ public class InstanceInfoFragment extends LoaderFragment {
|
||||
bindHeaderView();
|
||||
}
|
||||
|
||||
private void onTimelineButtonClick(View view) {
|
||||
Bundle args=new Bundle();
|
||||
args.putString("account", accountID);
|
||||
args.putString("domain", instance.uri);
|
||||
Nav.go(getActivity(), CustomLocalTimelineFragment.class, args);
|
||||
}
|
||||
|
||||
private void onPinButtonClick(View view) {
|
||||
List<TimelineDefinition> timelines = GlobalUserPreferences.pinnedTimelines.get(accountID);
|
||||
if (timelines == null) {
|
||||
timelines = List.of(TimelineDefinition.HOME_TIMELINE);
|
||||
}
|
||||
timelines.add(TimelineDefinition.ofCustomLocalTimeline(instance.uri));
|
||||
GlobalUserPreferences.pinnedTimelines.put(accountID, timelines);
|
||||
GlobalUserPreferences.save();
|
||||
updatedTimelines = true;
|
||||
}
|
||||
|
||||
private void onRulesButtonClick(View view) {
|
||||
Bundle args=new Bundle();
|
||||
args.putParcelable("instance", Parcels.wrap(instance));
|
||||
Nav.go(getActivity(), InstanceRulesFragment.class, args);
|
||||
}
|
||||
private void onSeversButtonClick(View view) {
|
||||
}
|
||||
|
||||
|
||||
private void onCoverClick(View v){
|
||||
Drawable drawable=cover.getDrawable();
|
||||
|
||||
@@ -383,6 +383,9 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
||||
followersBtn.setOnClickListener(this::onFollowersOrFollowingClick);
|
||||
followingBtn.setOnClickListener(this::onFollowersOrFollowingClick);
|
||||
|
||||
|
||||
//this currently takes up the whole username
|
||||
//in the future it might need to be change to only the instance uri
|
||||
username.setOnClickListener(v -> {
|
||||
Bundle args=new Bundle();
|
||||
args.putString("account", accountID);
|
||||
|
||||
@@ -920,6 +920,8 @@ public class UiUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/// Add icons to the menu.
|
||||
/// Passing in items will be colored to be visible on the background.
|
||||
public static void enableOptionsMenuIcons(Context context, Menu menu, @IdRes int... asAction) {
|
||||
if(menu.getClass().getSimpleName().equals("MenuBuilder")){
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M4,4.5v15A2.5,2.5 0,0 0,6.5 22h13.25a0.75,0.75 0,0 0,0 -1.5L6.5,20.5a1,1 0,0 1,-1 -1h14.25a0.75,0.75 0,0 0,0.75 -0.75L20.5,4.5A2.5,2.5 0,0 0,18 2L6.5,2A2.5,2.5 0,0 0,4 4.5ZM11.5,11.75v-5a0.75,0.75 0,0 1,1.5 0v5a0.75,0.75 0,0 1,-1.5 0ZM13.25,14.5a1,1 0,1 1,-2 0,1 1,0 0,1 2,0Z"
|
||||
android:fillColor="@color/fluent_default_icon_tint"/>
|
||||
</vector>
|
||||
@@ -6,6 +6,7 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ScrollView
|
||||
android:id="@id/scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
@@ -96,90 +97,6 @@
|
||||
android:layout_below="@id/border_top"
|
||||
android:background="?colorBackgroundLightest"
|
||||
android:paddingTop="4dp" />
|
||||
|
||||
<org.joinmastodon.android.ui.views.AutoOrientationLinearLayout
|
||||
android:id="@+id/profile_counters"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/metadata"
|
||||
android:background="?colorBackgroundLightest"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/posts_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="36dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/timeline_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_weight="0"
|
||||
android:background="@drawable/bg_inline_button"
|
||||
android:elevation="0dp"
|
||||
android:ellipsize="middle"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:maxWidth="140dp"
|
||||
android:singleLine="true"
|
||||
android:stateListAnimator="@null"
|
||||
android:text="View local timeline"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/timeline_pin_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:backgroundTint="?colorBackgroundLightest"
|
||||
android:contentDescription="@string/mo_personal_note_confirm"
|
||||
android:drawableStart="@drawable/ic_fluent_pin_24_regular"
|
||||
android:paddingHorizontal="8dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/rules_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_weight="0"
|
||||
android:background="@drawable/bg_inline_button"
|
||||
android:elevation="0dp"
|
||||
android:ellipsize="middle"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:maxWidth="140dp"
|
||||
android:singleLine="true"
|
||||
android:stateListAnimator="@null"
|
||||
android:text="@string/instance_rules_title"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/servers_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_weight="0"
|
||||
android:background="@drawable/bg_inline_button"
|
||||
android:elevation="0dp"
|
||||
android:ellipsize="middle"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:maxWidth="140dp"
|
||||
android:singleLine="true"
|
||||
android:stateListAnimator="@null"
|
||||
android:text="Moderated servers"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="16sp" />
|
||||
|
||||
|
||||
</org.joinmastodon.android.ui.views.AutoOrientationLinearLayout>
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
||||
6
mastodon/src/main/res/menu/instance_info.xml
Normal file
6
mastodon/src/main/res/menu/instance_info.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/open_timeline" android:title="@string/mo_instance_info_open_timeline" android:icon="@drawable/ic_fluent_timeline_24_regular"/>
|
||||
<item android:id="@+id/rules" android:title="@string/instance_rules_title" android:icon="@drawable/ic_fluent_task_list_ltr_24_regular"/>
|
||||
<item android:id="@+id/moderated_servers" android:title="@string/mo_instance_info_moderated_servers" android:icon="@drawable/ic_fluent_book_exclamation_mark_24_filled"/>
|
||||
</menu>
|
||||
@@ -57,4 +57,7 @@
|
||||
<string name="mo_mention_reblogger_automatically">Automatically mention account who reblogged the post in replies</string>
|
||||
<string name="mo_confirm_unfollow_title">Unfollow Account</string>
|
||||
<string name="mo_confirm_unfollow">Confirm to unfollow %s</string>
|
||||
|
||||
<string name="mo_instance_info_open_timeline">Local timeline</string>
|
||||
<string name="mo_instance_info_moderated_servers">Moderated servers</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user