1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*
This file is part of Subsonic.
Subsonic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Subsonic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2014 (C) Scott Jackson
*/
package github.daneren2005.dsub.fragments;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.adapter.SectionAdapter;
import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.domain.User;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.UserUtil;
import github.daneren2005.dsub.adapter.SettingsAdapter;
import github.daneren2005.dsub.view.UpdateView;
public class UserFragment extends SelectRecyclerFragment<User.Setting>{
private User user;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
Bundle args = getArguments();
user = (User) args.getSerializable(Constants.INTENT_EXTRA_NAME_ID);
pullToRefresh = false;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(super.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case R.id.menu_update_permissions:
UserUtil.updateSettings(context, user);
return true;
case R.id.menu_change_password:
UserUtil.changePassword(context, user);
return true;
case R.id.menu_change_email:
UserUtil.changeEmail(context, user);
return true;
}
return false;
}
@Override
public int getOptionsMenu() {
if(UserUtil.isCurrentAdmin() && ServerInfo.checkServerVersion(context, "1.10")) {
return R.menu.user;
} else if(UserUtil.isCurrentRole(User.SETTINGS)) {
return R.menu.user_user;
} else {
return R.menu.empty;
}
}
@Override
public SectionAdapter<User.Setting> getAdapter(List<User.Setting> objs) {
return SettingsAdapter.getSettingsAdapter(context, user, getImageLoader(), this);
}
@Override
public List<User.Setting> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
return user.getSettings();
}
@Override
public int getTitleResource() {
setTitle(user.getUsername());
return 0;
}
@Override
public void onItemClicked(UpdateView<User.Setting> updateView, User.Setting item) {
if(updateView.isCheckable()) {
boolean newValue = !item.getValue();
item.setValue(newValue);
updateView.setChecked(newValue);
}
}
@Override
public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<User.Setting> updateView, User.Setting item) {}
@Override
public boolean onContextItemSelected(MenuItem menuItem, UpdateView<User.Setting> updateView, User.Setting item) {
return false;
}
}
|