Add tab popup window

This commit is contained in:
kyori19 2019-12-24 12:46:43 +09:00
parent 1d5101e5a5
commit 49d939f718
8 changed files with 128 additions and 6 deletions

View File

@ -15,6 +15,7 @@
package com.keylesspalace.tusky;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
@ -27,6 +28,7 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import androidx.annotation.Nullable;
@ -129,6 +131,7 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
private int notificationTabPosition;
private MainPagerAdapter adapter;
private List<TabData> tabs;
private final EmojiCompat.InitCallback emojiInitCallback = new EmojiCompat.InitCallback() {
@Override
@ -226,6 +229,13 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
viewPager.setOffscreenPageLimit(9);
}
PopupWindow popupWindow = new PopupWindow(this);
@SuppressLint("InflateParams")
View popupView = getLayoutInflater().inflate(R.layout.view_tab_action, null);
popupWindow.setContentView(popupView);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
@ -242,12 +252,34 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
@Override
public void onTabReselected(TabLayout.Tab tab) {
if (adapter != null) {
Fragment fragment = adapter.getFragment(tab.getPosition());
if (fragment instanceof ReselectableFragment) {
((ReselectableFragment) fragment).onReselect();
}
if (tabs.get(tab.getPosition()).getId().equals(TabDataKt.DIRECT)) {
popupView.findViewById(R.id.tab_reset).setVisibility(View.GONE);
popupView.findViewById(R.id.tab_text_reset).setVisibility(View.GONE);
}
popupView.findViewById(R.id.tab_jump_to_top)
.setOnClickListener(v -> {
if (adapter != null) {
Fragment fragment = adapter.getFragment(tab.getPosition());
if (fragment instanceof ReselectableFragment) {
((ReselectableFragment) fragment).onReselect();
}
}
popupWindow.dismiss();
});
popupView.findViewById(R.id.tab_reset)
.setOnClickListener(v -> {
if (adapter != null) {
Fragment fragment = adapter.getFragment(tab.getPosition());
if (fragment instanceof ReselectableFragment) {
((ReselectableFragment) fragment).onReset();
}
}
popupWindow.dismiss();
});
popupWindow.showAsDropDown(tab.view);
}
});
@ -543,7 +575,7 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
}
private void setupTabs(boolean selectNotificationTab) {
List<TabData> tabs = accountManager.getActiveAccount().getTabPreferences();
tabs = accountManager.getActiveAccount().getTabPreferences();
adapter = new MainPagerAdapter(tabs, this);
viewPager.setAdapter(adapter);

View File

@ -195,6 +195,17 @@ class ConversationsFragment : SFragment(), StatusActionListener, Injectable, Res
jumpToTop()
}
override fun onReset() {
viewModel.conversations.observe(this, Observer<PagedList<ConversationEntity>> {
adapter.submitList(it)
})
viewModel.networkState.observe(this, Observer {
adapter.setNetworkState(it)
})
viewModel.load()
}
override fun onVoteInPoll(position: Int, choices: MutableList<Int>) {
viewModel.voteInPoll(position, choices)
}

View File

@ -1258,4 +1258,9 @@ public class NotificationsFragment extends SFragment implements
public void onReselect() {
jumpToTop();
}
@Override
public void onReset() {
fullyRefresh();
}
}

View File

@ -1594,6 +1594,11 @@ public class TimelineFragment extends SFragment implements
jumpToTop();
}
@Override
public void onReset() {
fullyRefresh();
}
@Override
public void refreshContent() {
if (isAdded())

View File

@ -8,4 +8,5 @@ interface ReselectableFragment {
* Call this method when tab reselected
*/
fun onReselect()
fun onReset()
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M4,12l1.41,1.41L11,7.83V20h2V7.83l5.58,5.59L20,12l-8,-8 -8,8z"/>
</vector>

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageButton
android:id="@+id/tab_jump_to_top"
style="?attr/image_button_style"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_margin="4dp"
android:contentDescription="@string/action_tab_jump_to_top"
android:importantForAccessibility="no"
android:padding="4dp"
app:layout_constraintBottom_toTopOf="@id/tab_text_jump_to_top"
app:layout_constraintEnd_toStartOf="@id/tab_reset"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_arrow_upward" />
<TextView
android:id="@+id/tab_text_jump_to_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_tab_jump_to_top"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/tab_jump_to_top"
app:layout_constraintStart_toStartOf="@id/tab_jump_to_top"
app:layout_constraintTop_toBottomOf="@id/tab_jump_to_top" />
<ImageButton
android:id="@+id/tab_reset"
style="?attr/image_button_style"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_margin="4dp"
android:contentDescription="@string/action_tab_reset"
android:importantForAccessibility="no"
android:padding="4dp"
app:layout_constraintBottom_toTopOf="@id/tab_text_reset"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tab_jump_to_top"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_reject_24dp" />
<TextView
android:id="@+id/tab_text_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_tab_reset"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/tab_reset"
app:layout_constraintStart_toStartOf="@id/tab_reset"
app:layout_constraintTop_toBottomOf="@id/tab_reset" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -138,6 +138,8 @@
<string name="action_open_faved_by">Show favorites</string>
<string name="action_quote">Quote</string>
<string name="action_authorize">Authorize Now!</string>
<string name="action_tab_jump_to_top">Jump to top</string>
<string name="action_tab_reset">Reset tab</string>
<string name="title_hashtags_dialog">Hashtags</string>
<string name="title_mentions_dialog">Mentions</string>