Merge branch 'develop' into share_password_support
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / SharePasswordDialogFragment.java
1 /**
2 * ownCloud Android client application
3 * @author masensio
4 * Copyright (C) 2015 ownCloud Inc.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19 package com.owncloud.android.ui.dialog;
20
21 import android.app.AlertDialog;
22 import android.app.Dialog;
23 import android.app.DialogFragment;
24 import android.content.DialogInterface;
25 import android.os.Bundle;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.view.WindowManager;
29 import android.widget.EditText;
30 import android.widget.TextView;
31 import android.widget.Toast;
32
33 import com.actionbarsherlock.app.SherlockDialogFragment;
34 import com.owncloud.android.R;
35 import com.owncloud.android.datamodel.OCFile;
36
37 /**
38 * Dialog to input the password for sharing a file/folder.
39 *
40 * Triggers the share when the password is introduced.
41 */
42
43 public class SharePasswordDialogFragment extends SherlockDialogFragment
44 implements DialogInterface.OnClickListener {
45
46 public static final String PASSWORD_FRAGMENT = "PASSWORD_FRAGMENT";
47
48 /**
49 * Public factory method to create new SharePasswordDialogFragment instances.
50 *
51 * @param file File to share
52 * @return Dialog ready to show.
53 */
54 public static SharePasswordDialogFragment newInstance(OCFile file) {
55 SharePasswordDialogFragment frag = new SharePasswordDialogFragment();
56 Bundle args = new Bundle();
57 frag.setArguments(args);
58 return frag;
59 }
60
61 @Override
62 public Dialog onCreateDialog(Bundle savedInstanceState) {
63 // Inflate the layout for the dialog
64 LayoutInflater inflater = getActivity().getLayoutInflater();
65 View v = inflater.inflate(R.layout.password_dialog, null);
66
67 // Setup layout
68 EditText inputText = ((EditText)v.findViewById(R.id.share_password));
69 inputText.setText("");
70 inputText.requestFocus();
71
72 // Build the dialog
73 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
74 builder.setView(v)
75 .setPositiveButton(R.string.common_ok, this)
76 .setNegativeButton(R.string.common_cancel, this)
77 .setTitle(R.string.share_link_password_title);
78 Dialog d = builder.create();
79 d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
80 return d;
81 }
82
83
84 @Override
85 public void onClick(DialogInterface dialog, int which) {
86 if (which == AlertDialog.BUTTON_POSITIVE) {
87 String password =
88 ((TextView)(getDialog().findViewById(R.id.share_password)))
89 .getText().toString();
90
91 if (password.length() <= 0) {
92 Toast.makeText(
93 getActivity(),
94 R.string.share_link_empty_password,
95 Toast.LENGTH_LONG).show();
96 return;
97 }
98
99 // TODO
100 // Share the file
101
102 }
103 }
104 }