Commit 3a66bbba authored by Mygod's avatar Mygod

Move share functionality to ProfilesFragment

parent 5898d291
<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="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>
...@@ -31,6 +31,16 @@ ...@@ -31,6 +31,16 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:maxLines="2" android:maxLines="2"
android:ellipsize="end"/> android:ellipsize="end"/>
<android.support.v7.widget.AppCompatImageView android:id="@+id/share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:layout_gravity="top"
app:srcCompat="@drawable/ic_social_share"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="Share"
android:focusable="true"
android:nextFocusLeft="@+id/container"/>
<android.support.v7.widget.AppCompatImageView android:id="@+id/edit" <android.support.v7.widget.AppCompatImageView android:id="@+id/edit"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -39,8 +49,7 @@ ...@@ -39,8 +49,7 @@
app:srcCompat="@drawable/ic_image_edit" app:srcCompat="@drawable/ic_image_edit"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="Edit" android:contentDescription="Edit"
android:focusable="true" android:focusable="true"/>
android:nextFocusLeft="@+id/container"/>
</LinearLayout> </LinearLayout>
<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"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="@string/share"
android:icon="@drawable/abc_ic_menu_share_mtrl_alpha"
android:alphabeticShortcut="s"
android:numericShortcut="1"
app:showAsAction="always">
<menu>
<item android:id="@+id/action_qr_code_nfc"
android:title="QR code/NFC"
android:alphabeticShortcut="q"
android:numericShortcut="1"/>
<item android:id="@+id/action_export"
android:title="@string/action_export"
android:alphabeticShortcut="e"
android:numericShortcut="2"/>
</menu>
</item>
<item android:id="@+id/action_delete" <item android:id="@+id/action_delete"
android:title="Delete" android:title="Delete"
android:icon="@drawable/ic_action_delete" android:icon="@drawable/ic_action_delete"
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_qr_code_nfc"
android:title="QR code/NFC"
android:alphabeticShortcut="q"
android:numericShortcut="1"/>
<item android:id="@+id/action_export"
android:title="@string/action_export"
android:alphabeticShortcut="e"
android:numericShortcut="2"/>
</menu>
...@@ -20,16 +20,16 @@ ...@@ -20,16 +20,16 @@
package com.github.shadowsocks package com.github.shadowsocks
import android.content.{DialogInterface, Intent, SharedPreferences}
import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.content._ import android.os.{Build, Bundle, UserManager}
import android.os._
import android.support.v14.preference.SwitchPreference import android.support.v14.preference.SwitchPreference
import android.support.v4.content.LocalBroadcastManager import android.support.v4.content.LocalBroadcastManager
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.support.v7.preference.Preference import android.support.v7.preference.Preference
import android.support.v7.widget.Toolbar.OnMenuItemClickListener import android.support.v7.widget.Toolbar.OnMenuItemClickListener
import android.view.MenuItem import android.view.MenuItem
import be.mygod.preference._ import be.mygod.preference.PreferenceFragment
import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.ShadowsocksApplication.app
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.preferences.KcpCliPreferenceDialogFragment import com.github.shadowsocks.preferences.KcpCliPreferenceDialogFragment
...@@ -37,7 +37,6 @@ import com.github.shadowsocks.utils.{Action, Key, Utils} ...@@ -37,7 +37,6 @@ import com.github.shadowsocks.utils.{Action, Key, Utils}
class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListener class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListener
with OnSharedPreferenceChangeListener { with OnSharedPreferenceChangeListener {
private lazy val clipboard = getActivity.getSystemService(Context.CLIPBOARD_SERVICE).asInstanceOf[ClipboardManager]
private var profile: Profile = _ private var profile: Profile = _
private var isProxyApps: SwitchPreference = _ private var isProxyApps: SwitchPreference = _
...@@ -83,12 +82,6 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe ...@@ -83,12 +82,6 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe
} }
override def onMenuItemClick(item: MenuItem): Boolean = item.getItemId match { override def onMenuItemClick(item: MenuItem): Boolean = item.getItemId match {
case R.id.action_qr_code_nfc =>
getFragmentManager.beginTransaction().add(new QRCodeDialog(profile.toString), "").commitAllowingStateLoss()
true
case R.id.action_export =>
clipboard.setPrimaryClip(ClipData.newPlainText(null, profile.toString))
true
case R.id.action_delete => case R.id.action_delete =>
new AlertDialog.Builder(getActivity) new AlertDialog.Builder(getActivity)
.setTitle("Confirm?") // TODO .setTitle("Confirm?") // TODO
......
...@@ -25,13 +25,13 @@ import java.util.GregorianCalendar ...@@ -25,13 +25,13 @@ import java.util.GregorianCalendar
import android.content._ import android.content._
import android.os.{Bundle, Handler} import android.os.{Bundle, Handler}
import android.support.v4.content.LocalBroadcastManager import android.support.v4.content.LocalBroadcastManager
import android.support.v7.widget.{DefaultItemAnimator, LinearLayoutManager, RecyclerView, Toolbar}
import android.support.v7.widget.RecyclerView.ViewHolder import android.support.v7.widget.RecyclerView.ViewHolder
import android.support.v7.widget.Toolbar.OnMenuItemClickListener
import android.support.v7.widget._
import android.support.v7.widget.helper.ItemTouchHelper import android.support.v7.widget.helper.ItemTouchHelper
import android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback import android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback
import android.view._ import android.view._
import android.widget.{LinearLayout, TextView, Toast} import android.view.View.OnLongClickListener
import android.widget.{LinearLayout, PopupMenu, TextView, Toast}
import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.ShadowsocksApplication.app
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.utils._ import com.github.shadowsocks.utils._
...@@ -41,9 +41,15 @@ import com.google.android.gms.ads.{AdRequest, AdSize, NativeExpressAdView} ...@@ -41,9 +41,15 @@ import com.google.android.gms.ads.{AdRequest, AdSize, NativeExpressAdView}
import scala.collection.mutable.ArrayBuffer import scala.collection.mutable.ArrayBuffer
import scala.util.Random import scala.util.Random
final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListener { final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickListener {
private val cardButtonLongClickListener: OnLongClickListener = view => {
Utils.positionToast(Toast.makeText(getActivity, view.getContentDescription, Toast.LENGTH_SHORT), view,
getActivity.getWindow, 0, Utils.dpToPx(getActivity, 8)).show()
true
}
private final class ProfileViewHolder(val view: View) extends RecyclerView.ViewHolder(view) private final class ProfileViewHolder(val view: View) extends RecyclerView.ViewHolder(view)
with View.OnClickListener { with View.OnClickListener with PopupMenu.OnMenuItemClickListener {
var item: Profile = _ var item: Profile = _
...@@ -59,11 +65,15 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -59,11 +65,15 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
{ {
val edit = itemView.findViewById(R.id.edit) val edit = itemView.findViewById(R.id.edit)
edit.setOnClickListener(_ => startConfig(item.id)) edit.setOnClickListener(_ => startConfig(item.id))
edit.setOnLongClickListener(_ => { edit.setOnLongClickListener(cardButtonLongClickListener)
Utils.positionToast(Toast.makeText(getActivity, edit.getContentDescription, Toast.LENGTH_SHORT), edit, val share = itemView.findViewById(R.id.share)
getActivity.getWindow, 0, Utils.dpToPx(getActivity, 8)).show() share.setOnClickListener(_ => {
true val popup = new PopupMenu(getActivity, share)
popup.getMenuInflater.inflate(R.menu.profile_share_popup, popup.getMenu)
popup.setOnMenuItemClickListener(this)
popup.show()
}) })
share.setOnLongClickListener(cardButtonLongClickListener)
} }
def updateText(txTotal: Long = 0, rxTotal: Long = 0) { def updateText(txTotal: Long = 0, rxTotal: Long = 0) {
...@@ -131,6 +141,16 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -131,6 +141,16 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
if (state == State.CONNECTED) activity.serviceLoad() if (state == State.CONNECTED) activity.serviceLoad()
} }
} }
override def onMenuItemClick(item: MenuItem): Boolean = item.getItemId match {
case R.id.action_qr_code_nfc =>
getFragmentManager.beginTransaction().add(new QRCodeDialog(item.toString), "").commitAllowingStateLoss()
true
case R.id.action_export =>
clipboard.setPrimaryClip(ClipData.newPlainText(null, item.toString))
true
case _ => false
}
} }
private class ProfilesAdapter extends RecyclerView.Adapter[ProfileViewHolder] { private class ProfilesAdapter extends RecyclerView.Adapter[ProfileViewHolder] {
......
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