Commit 3ce7f7e9 authored by Mygod's avatar Mygod

Add minidrawer for large screens

parents dfe469e1 da8a6599
...@@ -42,6 +42,7 @@ libraryDependencies ++= ...@@ -42,6 +42,7 @@ libraryDependencies ++=
"com.google.android.gms" % "play-services-analytics" % "10.0.1" :: "com.google.android.gms" % "play-services-analytics" % "10.0.1" ::
"com.google.android.gms" % "play-services-gcm" % "10.0.1" :: "com.google.android.gms" % "play-services-gcm" % "10.0.1" ::
"com.j256.ormlite" % "ormlite-android" % "5.0" :: "com.j256.ormlite" % "ormlite-android" % "5.0" ::
"com.mikepenz" % "crossfader" % "1.5.0" ::
"com.mikepenz" % "fastadapter" % "2.1.5" :: "com.mikepenz" % "fastadapter" % "2.1.5" ::
"com.mikepenz" % "iconics-core" % "2.8.2" :: "com.mikepenz" % "iconics-core" % "2.8.2" ::
"com.mikepenz" % "materialdrawer" % "5.8.1" :: "com.mikepenz" % "materialdrawer" % "5.8.1" ::
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_height="match_parent"
tools:ignore="UnknownIdInLayout" android:clipChildren="false"> tools:ignore="UnknownIdInLayout" android:clipChildren="false">
<android.support.design.widget.CoordinatorLayout android:id="@+id/content" <FrameLayout android:id="@+id/fragment_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_above="@+id/stat"/> android:layout_above="@+id/stat"/>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
app:bounded_width="480dp" app:bounded_width="@dimen/profile_item_max_width"
android:id="@+id/indicator"> android:id="@+id/indicator">
<LinearLayout android:layout_width="match_parent" <LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<dimen name="profile_item_max_width">480dp</dimen>
<!-- TODO: Remove when this issue is fixed: https://github.com/JorgeCastilloPrz/FABProgressCircle/issues/19 --> <!-- TODO: Remove when this issue is fixed: https://github.com/JorgeCastilloPrz/FABProgressCircle/issues/19 -->
<dimen name="fab_margin_top">-44dp</dimen> <dimen name="fab_margin_top">-44dp</dimen>
</resources> </resources>
...@@ -45,6 +45,9 @@ import com.github.shadowsocks.ShadowsocksApplication.app ...@@ -45,6 +45,9 @@ import com.github.shadowsocks.ShadowsocksApplication.app
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
import com.github.shadowsocks.utils.CloseUtils.autoDisconnect import com.github.shadowsocks.utils.CloseUtils.autoDisconnect
import com.github.shadowsocks.utils._ import com.github.shadowsocks.utils._
import com.mikepenz.crossfader.Crossfader
import com.mikepenz.crossfader.view.CrossFadeSlidingPaneLayout
import com.mikepenz.materialdrawer.interfaces.ICrossfader
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
import com.mikepenz.materialdrawer.{Drawer, DrawerBuilder} import com.mikepenz.materialdrawer.{Drawer, DrawerBuilder}
...@@ -67,6 +70,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -67,6 +70,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
private val handler = new Handler() private val handler = new Handler()
private var fab: FloatingActionButton = _ private var fab: FloatingActionButton = _
private var fabProgressCircle: FABProgressCircle = _ private var fabProgressCircle: FABProgressCircle = _
var crossfader: Crossfader[CrossFadeSlidingPaneLayout] = _
var drawer: Drawer = _ var drawer: Drawer = _
private var testCount: Int = _ private var testCount: Int = _
...@@ -142,7 +146,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -142,7 +146,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
rxText.setText(TrafficMonitor.formatTraffic(rxTotal)) rxText.setText(TrafficMonitor.formatTraffic(rxTotal))
txRateText.setText(TrafficMonitor.formatTraffic(txRate) + "/s") txRateText.setText(TrafficMonitor.formatTraffic(txRate) + "/s")
rxRateText.setText(TrafficMonitor.formatTraffic(rxRate) + "/s") rxRateText.setText(TrafficMonitor.formatTraffic(rxRate) + "/s")
val child = getFragmentManager.findFragmentById(R.id.content).asInstanceOf[ToolbarFragment] val child = getFragmentManager.findFragmentById(R.id.fragment_holder).asInstanceOf[ToolbarFragment]
if (state != State.STOPPING && child != null) child.onTrafficUpdated(txRate, rxRate, txTotal, rxTotal) if (state != State.STOPPING && child != null) child.onTrafficUpdated(txRate, rxRate, txTotal, rxTotal)
} }
...@@ -173,8 +177,9 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -173,8 +177,9 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
override def onCreate(savedInstanceState: Bundle) { override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.layout_main) setContentView(R.layout.layout_main)
drawer = new DrawerBuilder() val drawerBuilder = new DrawerBuilder()
.withActivity(this) .withActivity(this)
.withTranslucentStatusBar(true)
.withHeader(R.layout.layout_header) .withHeader(R.layout.layout_header)
.addDrawerItems( .addDrawerItems(
new PrimaryDrawerItem() new PrimaryDrawerItem()
...@@ -204,7 +209,21 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -204,7 +209,21 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
.withOnDrawerItemClickListener(this) .withOnDrawerItemClickListener(this)
.withActionBarDrawerToggle(true) .withActionBarDrawerToggle(true)
.withSavedInstance(savedInstanceState) .withSavedInstance(savedInstanceState)
val miniDrawerWidth = getResources.getDimension(R.dimen.material_mini_drawer_item)
if (getResources.getDisplayMetrics.widthPixels >=
getResources.getDimension(R.dimen.profile_item_max_width) + miniDrawerWidth) {
drawer = drawerBuilder.withGenerateMiniDrawer(true).buildView()
crossfader = new Crossfader[CrossFadeSlidingPaneLayout]()
crossfader.withContent(findViewById(android.R.id.content))
.withFirst(drawer.getSlider, getResources.getDimensionPixelSize(R.dimen.material_drawer_width))
.withSecond(drawer.getMiniDrawer.build(this), miniDrawerWidth.toInt)
.withSavedInstance(savedInstanceState)
.build() .build()
drawer.getMiniDrawer.withCrossFader(new ICrossfader { // a wrapper is needed
def isCrossfaded: Boolean = crossfader.isCrossFaded
def crossfade(): Unit = crossfader.crossFade()
})
} else drawer = drawerBuilder.build()
val header = drawer.getHeader val header = drawer.getHeader
val title = header.findViewById(R.id.drawer_title).asInstanceOf[TextView] val title = header.findViewById(R.id.drawer_title).asInstanceOf[TextView]
...@@ -318,7 +337,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -318,7 +337,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
private def displayFragment(fragment: ToolbarFragment) { private def displayFragment(fragment: ToolbarFragment) {
currentFragment = fragment currentFragment = fragment
getFragmentManager.beginTransaction().replace(R.id.content, fragment).commitAllowingStateLoss() getFragmentManager.beginTransaction().replace(R.id.fragment_holder, fragment).commitAllowingStateLoss()
drawer.closeDrawer() drawer.closeDrawer()
} }
...@@ -368,6 +387,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -368,6 +387,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
override def onSaveInstanceState(outState: Bundle) { override def onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
drawer.saveInstanceState(outState) drawer.saveInstanceState(outState)
if (crossfader != null) crossfader.saveInstanceState(outState)
} }
override def onDestroy() { override def onDestroy() {
......
...@@ -32,7 +32,7 @@ class ToolbarFragment extends Fragment { ...@@ -32,7 +32,7 @@ class ToolbarFragment extends Fragment {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
toolbar = view.findViewById(R.id.toolbar).asInstanceOf[Toolbar] toolbar = view.findViewById(R.id.toolbar).asInstanceOf[Toolbar]
val activity = getActivity.asInstanceOf[MainActivity] val activity = getActivity.asInstanceOf[MainActivity]
activity.drawer.setToolbar(activity, toolbar, true) if (activity.crossfader == null) activity.drawer.setToolbar(activity, toolbar, true)
} }
def onTrafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long): Unit = () def onTrafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long): Unit = ()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment