Removed useless code
[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.support.v7.app.AlertDialog;
22 import android.app.Dialog;
23 import android.content.DialogInterface;
24 import android.os.Bundle;
25 import android.support.v4.app.DialogFragment;
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.owncloud.android.R;
34 import com.owncloud.android.datamodel.OCFile;
35 import com.owncloud.android.ui.activity.FileActivity;
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 DialogFragment
44 implements DialogInterface.OnClickListener {
45
46 private static final String ARG_FILE = "FILE";
47
48 public static final String PASSWORD_FRAGMENT = "PASSWORD_FRAGMENT";
49
50 private OCFile mFile;
51
52 /**
53 * Public factory method to create new SharePasswordDialogFragment instances.
54 *
55 * @param file
56 * @return Dialog ready to show.
57 */
58 public static SharePasswordDialogFragment newInstance(OCFile file) {
59 SharePasswordDialogFragment frag = new SharePasswordDialogFragment();
60 Bundle args = new Bundle();
61 args.putParcelable(ARG_FILE, file);
62 frag.setArguments(args);
63 return frag;
64 }
65
66 @Override
67 public Dialog onCreateDialog(Bundle savedInstanceState) {
68 mFile = getArguments().getParcelable(ARG_FILE);
69
70 // Inflate the layout for the dialog
71 LayoutInflater inflater = getActivity().getLayoutInflater();
72 View v = inflater.inflate(R.layout.password_dialog, null);
73
74 // Setup layout
75 EditText inputText = ((EditText)v.findViewById(R.id.share_password));
76 inputText.setText("");
77 inputText.requestFocus();
78
79 // Build the dialog
80 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
81 builder.setView(v)
82 .setPositiveButton(R.string.common_ok, this)
83 .setNegativeButton(R.string.common_cancel, this)
84 .setTitle(R.string.share_link_password_title);
85 Dialog d = builder.create();
86 d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
87 return d;
88 }
89
90
91 @Override
92 public void onClick(DialogInterface dialog, int which) {
93 if (which == AlertDialog.BUTTON_POSITIVE) {
94 // Enable the flag "Share again"
95 ((FileActivity) getActivity()).setTryShareAgain(true);
96
97 String password =
98 ((TextView)(getDialog().findViewById(R.id.share_password)))
99 .getText().toString();
100
101 if (password.length() <= 0) {
102 Toast.makeText(
103 getActivity(),
104 R.string.share_link_empty_password,
105 Toast.LENGTH_LONG).show();
106 return;
107 }
108
109 // Share the file
110 ((FileActivity) getActivity()).getFileOperationsHelper().
111 setPasswordToShareViaLink(mFile, password);
112
113 } else {
114 // Disable the flag "Share again"
115 ((FileActivity) getActivity()).setTryShareAgain(false);
116 }
117 }
118 }