aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github/daneren2005/dsub/fragments
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/fragments')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java25
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/ChatFragment.java53
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java52
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/LyricsFragment.java1
4 files changed, 45 insertions, 86 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java
index 552712f7..dcd3d16a 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java
@@ -37,7 +37,6 @@ import github.daneren2005.dsub.adapter.UserAdapter;
import github.daneren2005.dsub.view.UpdateView;
public class AdminFragment extends SelectRecyclerFragment<User> {
- private static String TAG = AdminFragment.class.getSimpleName();
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@@ -45,10 +44,8 @@ public class AdminFragment extends SelectRecyclerFragment<User> {
return true;
}
- switch (item.getItemId()) {
- case R.id.menu_add_user:
- UserUtil.addNewUser(context, this, (objects.size() > 0) ? objects.get(0) : null);
- break;
+ if (item.getItemId() == R.id.menu_add_user) {
+ UserUtil.addNewUser(context, this, (objects.size() > 0) ? objects.get(0) : null);
}
return false;
@@ -65,18 +62,14 @@ public class AdminFragment extends SelectRecyclerFragment<User> {
@Override
public boolean onContextItemSelected(MenuItem menuItem, UpdateView<User> updateView, User user) {
- switch(menuItem.getItemId()) {
- case R.id.admin_change_email:
- UserUtil.changeEmail(context, user);
- break;
- case R.id.admin_change_password:
- UserUtil.changePassword(context, user);
- break;
- case R.id.admin_delete_user:
- UserUtil.deleteUser(context, user, adapter);
- break;
+ int id = menuItem.getItemId();
+ if (id == R.id.admin_change_email) {
+ UserUtil.changeEmail(context, user);
+ } else if (id == R.id.admin_change_password) {
+ UserUtil.changePassword(context, user);
+ } else if (id == R.id.admin_delete_user) {
+ UserUtil.deleteUser(context, user, adapter);
}
-
return true;
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/ChatFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/ChatFragment.java
index efdf0c7f..cec28722 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/ChatFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/ChatFragment.java
@@ -9,6 +9,8 @@ import java.util.Collections;
import java.util.List;
import android.os.Bundle;
import android.os.Handler;
+
+import androidx.annotation.NonNull;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.text.Editable;
import android.text.TextWatcher;
@@ -24,7 +26,6 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
-import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.ChatMessage;
import github.daneren2005.dsub.service.MusicService;
@@ -42,7 +43,6 @@ import java.util.concurrent.TimeUnit;
* @author Joshua Bahnsen
*/
public class ChatFragment extends SubsonicFragment {
- private static final String TAG = ChatFragment.class.getSimpleName();
private ListView chatListView;
private EditText messageEditText;
private ImageButton sendButton;
@@ -56,7 +56,7 @@ public class ChatFragment extends SubsonicFragment {
if(bundle != null) {
List<ChatMessage> abstractList = (List<ChatMessage>) bundle.getSerializable(Constants.FRAGMENT_LIST);
- messageList = new ArrayList<ChatMessage>(abstractList);
+ messageList = new ArrayList<>(abstractList);
}
}
@@ -73,12 +73,7 @@ public class ChatFragment extends SubsonicFragment {
messageEditText = (EditText) rootView.findViewById(R.id.chat_edittext);
sendButton = (ImageButton) rootView.findViewById(R.id.chat_send);
- sendButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- sendMessage();
- }
- });
+ sendButton.setOnClickListener(view -> sendMessage());
chatListView = (ListView) rootView.findViewById(R.id.chat_entries);
chatListView.setStackFromBottom(true);
@@ -99,21 +94,17 @@ public class ChatFragment extends SubsonicFragment {
}
});
- messageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
-
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if (actionId == EditorInfo.IME_ACTION_DONE || (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN)) {
- sendMessage();
- return true;
- }
-
- return false;
+ messageEditText.setOnEditorActionListener((v, actionId, event) -> {
+ if (actionId == EditorInfo.IME_ACTION_DONE || (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN)) {
+ sendMessage();
+ return true;
}
+
+ return false;
});
if(messageList == null) {
- messageList = new ArrayList<ChatMessage>();
+ messageList = new ArrayList<>();
refresh(true);
} else {
for (ChatMessage message : messageList) {
@@ -139,21 +130,13 @@ public class ChatFragment extends SubsonicFragment {
super.onStart();
final Handler handler = new Handler();
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- handler.post(new Runnable() {
- @Override
- public void run() {
- if(primaryFragment) {
- load(false);
- } else {
- invalidated = true;
- }
- }
- });
+ Runnable runnable = () -> handler.post(() -> {
+ if(primaryFragment) {
+ load(false);
+ } else {
+ invalidated = true;
}
- };
+ });
SharedPreferences prefs = Util.getPreferences(context);
long refreshRate = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_CHAT_REFRESH, "30"));
@@ -173,7 +156,7 @@ public class ChatFragment extends SubsonicFragment {
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater menuInflater) {
menuInflater.inflate(R.menu.abstract_top_menu, menu);
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java
index 4c37beec..49f31141 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java
@@ -15,7 +15,6 @@
package github.daneren2005.dsub.fragments;
-import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import androidx.recyclerview.widget.ItemTouchHelper;
@@ -69,17 +68,7 @@ public class DownloadFragment extends SelectRecyclerFragment<DownloadFile> imple
super.onStart();
final Handler handler = new Handler();
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- handler.post(new Runnable() {
- @Override
- public void run() {
- update();
- }
- });
- }
- };
+ Runnable runnable = () -> handler.post(this::update);
executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS);
@@ -105,11 +94,10 @@ public class DownloadFragment extends SelectRecyclerFragment<DownloadFile> imple
public List<DownloadFile> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
DownloadService downloadService = getDownloadService();
if(downloadService == null) {
- return new ArrayList<DownloadFile>();
+ return new ArrayList<>();
}
- List<DownloadFile> songList = new ArrayList<DownloadFile>();
- songList.addAll(downloadService.getBackgroundDownloads());
+ List<DownloadFile> songList = new ArrayList<>(downloadService.getBackgroundDownloads());
currentRevision = downloadService.getDownloadListUpdateRevision();
return songList;
}
@@ -147,26 +135,20 @@ public class DownloadFragment extends SelectRecyclerFragment<DownloadFile> imple
return true;
}
- switch (menuItem.getItemId()) {
- case R.id.menu_remove_all:
- Util.confirmDialog(context, R.string.download_menu_remove_all, "", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- new SilentBackgroundTask<Void>(context) {
- @Override
- protected Void doInBackground() throws Throwable {
- getDownloadService().clearBackground();
- return null;
- }
-
- @Override
- protected void done(Void result) {
- update();
- }
- }.execute();
- }
- });
- return true;
+ if (menuItem.getItemId() == R.id.menu_remove_all) {
+ Util.confirmDialog(context, R.string.download_menu_remove_all, "", (dialog, which) -> new SilentBackgroundTask<Void>(context) {
+ @Override
+ protected Void doInBackground() {
+ getDownloadService().clearBackground();
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ update();
+ }
+ }.execute());
+ return true;
}
return false;
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/LyricsFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/LyricsFragment.java
index 402bd257..50049656 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/LyricsFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/LyricsFragment.java
@@ -81,6 +81,7 @@ public final class LyricsFragment extends SubsonicFragment {
BackgroundTask<Lyrics> task = new TabBackgroundTask<Lyrics>(this) {
@Override
protected Lyrics doInBackground() throws Throwable {
+ assert getArguments() != null;
String artist = getArguments().getString(Constants.INTENT_EXTRA_NAME_ARTIST);
String title = getArguments().getString(Constants.INTENT_EXTRA_NAME_TITLE);
MusicService musicService = MusicServiceFactory.getMusicService(context);