feat: add community drawer menu
This commit is contained in:
@@ -31,6 +31,7 @@ import com.stardust.scriptdroid.ui.common.ScriptOperations;
|
||||
import com.stardust.scriptdroid.ui.doc.DocsFragment_;
|
||||
import com.stardust.scriptdroid.ui.floating.FloatyWindowManger;
|
||||
import com.stardust.scriptdroid.storage.file.StorageFileProvider;
|
||||
import com.stardust.scriptdroid.ui.main.community.CommunityFragment;
|
||||
import com.stardust.scriptdroid.ui.main.community.CommunityFragment_;
|
||||
import com.stardust.scriptdroid.ui.log.LogActivity_;
|
||||
import com.stardust.scriptdroid.ui.main.sample.SampleListFragment_;
|
||||
@@ -52,6 +53,7 @@ import org.androidannotations.annotations.Click;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -84,6 +86,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
checkPermissions();
|
||||
mVersionGuard = new VersionGuard(this);
|
||||
showAnnunciationIfNeeded();
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@AfterViews
|
||||
@@ -275,6 +278,11 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onLoadUrl(CommunityFragment.LoadUrl loadUrl) {
|
||||
mDrawerLayout.closeDrawer(Gravity.START);
|
||||
}
|
||||
|
||||
|
||||
private void setUpSearchMenuItem(MenuItem searchMenuItem) {
|
||||
mSearchViewItem = new SearchViewItem(this, searchMenuItem) {
|
||||
@@ -316,5 +324,9 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
||||
EventBus.getDefault().post(event);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import android.support.design.widget.FloatingActionButton;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.network.NodeBB;
|
||||
import com.stardust.scriptdroid.ui.main.QueryEvent;
|
||||
import com.stardust.scriptdroid.ui.main.ViewPagerFragment;
|
||||
import com.stardust.util.BackPressedHandler;
|
||||
@@ -25,6 +26,22 @@ import java.net.URLEncoder;
|
||||
@EFragment(R.layout.fragment_community)
|
||||
public class CommunityFragment extends ViewPagerFragment implements BackPressedHandler {
|
||||
|
||||
public static class LoadUrl {
|
||||
public final String url;
|
||||
|
||||
public LoadUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class VisibilityChange {
|
||||
public final boolean visible;
|
||||
|
||||
public VisibilityChange(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String POSTS_PAGE_PATTERN = "[\\S\\s]+/topic/[0-9]+/[\\S\\s]+";
|
||||
|
||||
@@ -93,6 +110,11 @@ public class CommunityFragment extends ViewPagerFragment implements BackPressedH
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void loadUrl(LoadUrl loadUrl) {
|
||||
mWebView.loadUrl(NodeBB.url(loadUrl.url));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void submitQuery(QueryEvent event) {
|
||||
if (!isShown() || event == QueryEvent.CLEAR) {
|
||||
@@ -114,4 +136,16 @@ public class CommunityFragment extends ViewPagerFragment implements BackPressedH
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageShow() {
|
||||
super.onPageShow();
|
||||
EventBus.getDefault().post(new VisibilityChange(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageHide() {
|
||||
super.onPageHide();
|
||||
EventBus.getDefault().post(new VisibilityChange(false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.stardust.scriptdroid.ui.main.drawer;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.main.community.CommunityFragment;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/12/10.
|
||||
*/
|
||||
|
||||
public class CommunityDrawerMenu {
|
||||
|
||||
|
||||
private List<DrawerMenuItem> mDrawerMenuItems = new ArrayList<>(Arrays.asList(
|
||||
new DrawerMenuGroup(R.string.text_community),
|
||||
new DrawerMenuItem(R.drawable.community_list, R.string.text_community_category, this::showCategories),
|
||||
new DrawerMenuItem(R.drawable.community_inbox, R.string.text_community_unread, this::showUnread),
|
||||
new DrawerMenuItem(R.drawable.community_time, R.string.text_community_recent, this::showRecent),
|
||||
new DrawerMenuItem(R.drawable.community_fire, R.string.text_community_popular, this::showPopular),
|
||||
new DrawerMenuItem(R.drawable.community_tags, R.string.text_community_tags, this::showTags)
|
||||
));
|
||||
|
||||
private boolean mShown = false;
|
||||
|
||||
public List<DrawerMenuItem> getItems() {
|
||||
return mDrawerMenuItems;
|
||||
}
|
||||
|
||||
public void showCommunityMenu(DrawerMenuAdapter adapter) {
|
||||
List<DrawerMenuItem> items = adapter.getDrawerMenuItems();
|
||||
if (items.get(0) == mDrawerMenuItems.get(0)) {
|
||||
return;
|
||||
}
|
||||
items.addAll(0, mDrawerMenuItems);
|
||||
adapter.notifyItemRangeInserted(0, mDrawerMenuItems.size());
|
||||
adapter.notifyItemChanged(mDrawerMenuItems.size());
|
||||
}
|
||||
|
||||
public void hideCommunityMenu(DrawerMenuAdapter adapter) {
|
||||
List<DrawerMenuItem> items = adapter.getDrawerMenuItems();
|
||||
if (items.isEmpty() || items.get(0) != mDrawerMenuItems.get(0)) {
|
||||
return;
|
||||
}
|
||||
items.subList(0, mDrawerMenuItems.size()).clear();
|
||||
adapter.notifyItemChanged(mDrawerMenuItems.size());
|
||||
adapter.notifyItemRangeRemoved(0, mDrawerMenuItems.size());
|
||||
}
|
||||
|
||||
private void showCategories(DrawerMenuItemViewHolder holder) {
|
||||
EventBus.getDefault().post(new CommunityFragment.LoadUrl("/categories"));
|
||||
}
|
||||
|
||||
private void showUnread(DrawerMenuItemViewHolder holder) {
|
||||
EventBus.getDefault().post(new CommunityFragment.LoadUrl("/unread"));
|
||||
|
||||
}
|
||||
|
||||
private void showRecent(DrawerMenuItemViewHolder holder) {
|
||||
EventBus.getDefault().post(new CommunityFragment.LoadUrl("/recent"));
|
||||
|
||||
}
|
||||
|
||||
private void showPopular(DrawerMenuItemViewHolder holder) {
|
||||
EventBus.getDefault().post(new CommunityFragment.LoadUrl("/popular"));
|
||||
|
||||
}
|
||||
|
||||
private void showTags(DrawerMenuItemViewHolder holder) {
|
||||
EventBus.getDefault().post(new CommunityFragment.LoadUrl("/tags"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import com.stardust.scriptdroid.network.api.UserApi;
|
||||
import com.stardust.scriptdroid.network.entity.user.User;
|
||||
import com.stardust.scriptdroid.network.entity.VersionInfo;
|
||||
import com.stardust.scriptdroid.tool.SimpleObserver;
|
||||
import com.stardust.scriptdroid.ui.main.community.CommunityFragment;
|
||||
import com.stardust.scriptdroid.ui.user.LoginActivity_;
|
||||
import com.stardust.scriptdroid.ui.settings.SettingsActivity;
|
||||
import com.stardust.scriptdroid.ui.update.UpdateInfoDialogBuilder;
|
||||
@@ -92,6 +93,7 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
|
||||
private DrawerMenuAdapter mDrawerMenuAdapter;
|
||||
private Disposable mConnectionStateDisposable;
|
||||
private CommunityDrawerMenu mCommunityDrawerMenu = new CommunityDrawerMenu();
|
||||
|
||||
|
||||
@Override
|
||||
@@ -356,6 +358,16 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
setChecked(mFloatingWindowItem, event.getCurrentState() != CircularMenu.STATE_CLOSED);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onCommunityPageVisibilityChange(CommunityFragment.VisibilityChange change) {
|
||||
if (change.visible) {
|
||||
mCommunityDrawerMenu.showCommunityMenu(mDrawerMenuAdapter);
|
||||
} else {
|
||||
mCommunityDrawerMenu.hideCommunityMenu(mDrawerMenuAdapter);
|
||||
}
|
||||
mDrawerMenu.scrollToPosition(0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
@@ -27,6 +27,10 @@ public class DrawerMenuAdapter extends RecyclerView.Adapter<BindableViewHolder<D
|
||||
mDrawerMenuItems = drawerMenuItems;
|
||||
}
|
||||
|
||||
public List<DrawerMenuItem> getDrawerMenuItems() {
|
||||
return mDrawerMenuItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindableViewHolder<DrawerMenuItem> onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == VIEW_TYPE_GROUP) {
|
||||
|
||||
BIN
app/src/main/res/drawable-xhdpi/community_fire.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/community_fire.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
BIN
app/src/main/res/drawable-xhdpi/community_inbox.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/community_inbox.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
BIN
app/src/main/res/drawable-xhdpi/community_list.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/community_list.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.5 KiB |
BIN
app/src/main/res/drawable-xhdpi/community_tags.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/community_tags.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
BIN
app/src/main/res/drawable-xhdpi/community_time.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/community_time.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
@@ -10,7 +10,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
<com.stardust.theme.widget.ThemeColorToolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
@@ -7,4 +7,5 @@
|
||||
<item name="package_name" type="id"/>
|
||||
<item name="class_name" type="id"/>
|
||||
<item name="open_launcher" type="id"/>
|
||||
<item name="accessibility_service" type="id"/>
|
||||
</resources>
|
||||
@@ -327,4 +327,9 @@
|
||||
<string name="text_device_not_rooted">设备没有root</string>
|
||||
<string name="prompt_device_not_rooted">监测到您的设备没有root, 录制脚本需要root权限, 是否继续?</string>
|
||||
<string name="text_device_rooted">仍要录制</string>
|
||||
<string name="text_community_category">版块</string>
|
||||
<string name="text_community_unread">未读</string>
|
||||
<string name="text_community_recent">最新</string>
|
||||
<string name="text_community_popular">热门</string>
|
||||
<string name="text_community_tags">话题</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user