Commit bd9edb62 authored by Geoffrey Métais's avatar Geoffrey Métais

Network favorites edition

parent 1a75eedf
......@@ -20,4 +20,8 @@
android:id="@+id/network_remove_favorite"
android:title="@string/favorites_remove"
android:visible="false" />
<item
android:id="@+id/network_edit_favorite"
android:title="@string/favorites_edit"
android:visible="false" />
</menu>
\ No newline at end of file
......@@ -165,6 +165,7 @@
<string name="search_results">Search results</string>
<string name="favorites_add">Add to favorites</string>
<string name="favorites_remove">Remove from favorites</string>
<string name="favorites_edit">Edit</string>
<string name="favorite_added">Saved to favorites</string>
<string name="favorite_removed">Removed from favorites</string>
......
......@@ -396,9 +396,10 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
menu.findItem(R.id.directory_view_delete).setVisible(canWrite);
if (this instanceof NetworkBrowserFragment) {
MediaDatabase db = MediaDatabase.getInstance();
if (db.networkFavExists(mw.getUri()))
if (db.networkFavExists(mw.getUri())) {
menu.findItem(R.id.network_remove_favorite).setVisible(true);
else
menu.findItem(R.id.network_edit_favorite).setVisible(true);
} else
menu.findItem(R.id.network_add_favorite).setVisible(true);
}
} else {
......@@ -428,7 +429,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
if (! (mAdapter.getItem(position) instanceof MediaWrapper))
return super.onContextItemSelected(item);
final MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
MediaDatabase db;
switch (id){
case R.id.directory_view_play:
mw.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
......@@ -484,18 +484,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
// if (new File(mw.getLocation()+"/.nomedia").delete())
// updateLib();
// return true;
case R.id.network_add_favorite:
db = MediaDatabase.getInstance();
db.addNetworkFavItem(mw.getUri(), mw.getTitle());
if (isRootDirectory())
updateDisplay();
return true;
case R.id.network_remove_favorite:
db = MediaDatabase.getInstance();
db.deleteNetworkFav(mw.getUri());
if (isRootDirectory())
updateDisplay();
return true;
}
return false;
}
......
......@@ -35,6 +35,7 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
......@@ -103,6 +104,32 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
super.updateDisplay();
}
protected boolean handleContextItemSelected(MenuItem item, final int position) {
int id = item.getItemId();
if (! (mAdapter.getItem(position) instanceof MediaWrapper))
return super.onContextItemSelected(item);
final MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
MediaDatabase db;
switch (id){
case R.id.network_add_favorite:
db = MediaDatabase.getInstance();
db.addNetworkFavItem(mw.getUri(), mw.getTitle());
if (isRootDirectory())
updateDisplay();
return true;
case R.id.network_remove_favorite:
db = MediaDatabase.getInstance();
db.deleteNetworkFav(mw.getUri());
if (isRootDirectory())
updateDisplay();
return true;
case R.id.network_edit_favorite:
showAddServerDialog(mw);
return true;
}
return super.handleContextItemSelected(item, position);
}
@Override
protected void browseRoot() {
updateFavorites();
......@@ -130,7 +157,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
}
ArrayList<MediaWrapper> favs = MediaDatabase.getInstance().getAllNetworkFav();
int newSize = favs.size(), totalSize = mAdapter.getItemCount();
int newSize = favs.size();
if (newSize == 0 && mFavorites == 0)
return;
......@@ -207,13 +234,15 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
@Override
public void onClick(View v) {
if (v.getId() == R.id.fab_add_custom_dir){
showAddServerDialog();
showAddServerDialog(null);
}
}
public void showAddServerDialog() {
public void showAddServerDialog(MediaWrapper mw) {
FragmentManager fm = getFragmentManager();
NetworkServerDialog dialog = new NetworkServerDialog();
if (mw != null)
dialog.setServer(mw);
dialog.show(fm, "fragment_add_server");
}
......
......@@ -24,6 +24,7 @@ import android.widget.TextView;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.media.MediaDatabase;
import org.videolan.vlc.media.MediaWrapper;
public class NetworkServerDialog extends DialogFragment implements AdapterView.OnItemSelectedListener, TextWatcher, View.OnClickListener {
......@@ -43,6 +44,8 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
Spinner mSpinnerProtocol;
TextView mUrl, mPortTitle;
Button mCancel, mSave;
Uri mUri;
String mName;
public NetworkServerDialog() {}
......@@ -115,13 +118,30 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
return v;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mEditAddress.setText(mUri.getHost());
if (!TextUtils.isEmpty(mUri.getUserInfo()))
mEditUsername.setText(mUri.getUserInfo());
if (!TextUtils.isEmpty(mUri.getPath()))
mEditFolder.setText(mUri.getPath().substring(1));
if (!TextUtils.isEmpty(mName))
mEditServername.setText(mName);
int position = getProtocolSpinnerPosition(mUri.getScheme().toUpperCase());
mSpinnerProtocol.setSelection(position);
int port = mUri.getPort();
mEditPort.setText(port != -1 ? String.valueOf(port) : getPortForProtocol(position));
}
private void saveServer() {
String name = (TextUtils.isEmpty(mEditServername.getText().toString())) ?
mEditAddress.getText().toString() : mEditServername.getText().toString();
Uri uri = Uri.parse(mUrl.getText().toString());
MediaDatabase db = MediaDatabase.getInstance();
if (!db.networkFavExists(uri))
db.addNetworkFavItem(uri, name);
MediaDatabase db = MediaDatabase.getInstance();
if (mUri != null)
db.deleteNetworkFav(mUri);
db.addNetworkFavItem(uri, name);
}
private void updateUrl() {
......@@ -136,7 +156,9 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
sb.append(':').append(mEditPort.getText());
}
if (mEditFolder.isEnabled() && !TextUtils.isEmpty(mEditFolder.getText())) {
sb.append('/').append(mEditFolder.getText());
if (!mEditFolder.getText().toString().startsWith("/"))
sb.append('/');
sb.append(mEditFolder.getText());
}
mUrl.setText(sb.toString());
mSave.setEnabled(!TextUtils.isEmpty(mEditAddress.getText().toString()));
......@@ -156,37 +178,46 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
}
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
boolean portEnabled = true, userEnabled = true;
String port = null;
int addressHint = R.string.server_domain_hint;
private int getProtocolSpinnerPosition(String protocol) {
for (int i = 0; i < mProtocols.length; ++i) {
if (TextUtils.equals(mProtocols[i], protocol))
return i;
}
return -1;
}
private String getPortForProtocol(int position) {
switch (mProtocols[position]) {
case "FTP":
port = FTP_DEFAULT_PORT;
break;
return FTP_DEFAULT_PORT;
case "FTPS":
port = FTPS_DEFAULT_PORT;
break;
return FTPS_DEFAULT_PORT;
case "SFTP":
port = SFTP_DEFAULT_PORT;
break;
return SFTP_DEFAULT_PORT;
case "HTTP":
port = HTTP_DEFAULT_PORT;
break;
return HTTP_DEFAULT_PORT;
case "HTTPS":
port = HTTPS_DEFAULT_PORT;
break;
return HTTPS_DEFAULT_PORT;
default:
return "";
}
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
boolean portEnabled = true, userEnabled = true;
String port = getPortForProtocol(position);
int addressHint = R.string.server_domain_hint;
switch (mProtocols[position]) {
case "SMB":
addressHint = R.string.server_share_hint;
portEnabled = false;
port = "";
break;
case "NFS":
addressHint = R.string.server_share_hint;
userEnabled = false;
portEnabled = false;
port = "";
break;
}
mEditAddressLayout.setHint(getString(addressHint));
......@@ -224,4 +255,9 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
}
}
public void setServer(MediaWrapper mw) {
mUri = mw.getUri();
mName = mw.getTitle();
}
}
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