Fix some Codacy issues

This commit is contained in:
stefan-niedermann 2019-12-29 11:22:56 +01:00
parent 4ff9198319
commit 8e93775dfe
9 changed files with 42 additions and 44 deletions

View file

@ -176,7 +176,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
shortcutManager.addDynamicShortcuts(newShortcuts);
}
}
}).run();
}).start();
}
@Override
@ -381,11 +381,11 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
adapterCategories.setSelectedItem(item.id);
// update current selection
if (itemRecent == item) {
if (itemRecent.equals(item)) {
navigationSelection = new Category(null, null);
} else if (itemFavorites == item) {
} else if (itemFavorites.equals(item)) {
navigationSelection = new Category(null, true);
} else if (itemUncategorized == item) {
} else if (itemUncategorized.equals(item)) {
navigationSelection = new Category("", null);
} else {
navigationSelection = new Category(item.label, null);
@ -531,16 +531,14 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
NavigationAdapter adapterMenu = new NavigationAdapter(new NavigationAdapter.ClickListener() {
@Override
public void onItemClick(NavigationAdapter.NavigationItem item) {
if (item == itemSettings) {
if (itemSettings.equals(item)) {
Intent settingsIntent = new Intent(getApplicationContext(), PreferencesActivity.class);
startActivityForResult(settingsIntent, server_settings);
} else if (item == itemAbout) {
} else if (itemAbout.equals(item)) {
Intent aboutIntent = new Intent(getApplicationContext(), AboutActivity.class);
startActivityForResult(aboutIntent, about);
} else if (item == itemTrashbin) {
if (localAccount != null) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(localAccount.getUrl() + "/index.php/apps/files/?dir=/&view=trashbin")));
}
} else if (itemTrashbin.equals(item) && localAccount != null) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(localAccount.getUrl() + "/index.php/apps/files/?dir=/&view=trashbin")));
}
}
@ -662,7 +660,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
LoadNotesListTask.NotesLoadedListener callback = (List<Item> notes, boolean showCategory) -> {
adapter.setShowCategory(showCategory);
adapter.setItemList(notes);
if(notes.size() > 0) {
if (notes.size() > 0) {
emptyContentView.setVisibility(View.GONE);
} else {
emptyContentView.setVisibility(View.VISIBLE);

View file

@ -147,7 +147,7 @@ public class NoteListWidget extends AppWidgetProvider {
case NoteListWidget.NLW_DISPLAY_STARRED:
return context.getString(R.string.label_favorites);
case NoteListWidget.NLW_DISPLAY_CATEGORY:
if (category.equals("")) {
if ("".equals(category)) {
return context.getString(R.string.action_uncategorized);
} else {
return category;

View file

@ -86,9 +86,9 @@ public class NoteListWidgetConfiguration extends AppCompatActivity {
public void onItemClick(NavigationAdapter.NavigationItem item) {
SharedPreferences.Editor sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
if (item == itemRecent) {
if (itemRecent.equals(item)) {
sp.putInt(NoteListWidget.WIDGET_MODE_KEY + appWidgetId, NoteListWidget.NLW_DISPLAY_ALL);
} else if (item == itemFavorites) {
} else if (itemFavorites.equals(item)) {
sp.putInt(NoteListWidget.WIDGET_MODE_KEY + appWidgetId, NoteListWidget.NLW_DISPLAY_STARRED);
} else {
String category = "";

View file

@ -20,19 +20,17 @@ import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFactory {
private final Context context;
private final int displayMode;
private final int appWidgetId;
private final boolean darkTheme;
private String category;
private final SharedPreferences sp;
private NoteSQLiteOpenHelper db;
private List<DBNote> dbNotes;
private long accountId;
NoteListWidgetFactory(Context context, Intent intent) {
this.context = context;
appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
sp = PreferenceManager.getDefaultSharedPreferences(this.context);
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this.context);
displayMode = sp.getInt(NoteListWidget.WIDGET_MODE_KEY + appWidgetId, -1);
darkTheme = sp.getBoolean(NoteListWidget.DARK_THEME_KEY + appWidgetId, false);
category = sp.getString(NoteListWidget.WIDGET_CATEGORY_KEY + appWidgetId, "");

View file

@ -48,12 +48,6 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
private static final String TAG = BaseNoteFragment.class.getSimpleName();
public interface NoteFragmentListener {
void close();
void onNoteUpdated(DBNote note);
}
private static final int MENU_ID_PIN = -1;
public static final String PARAM_NOTE_ID = "noteId";
public static final String PARAM_ACCOUNT_ID = "accountId";
@ -393,4 +387,10 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
db.setCategory(note, category, null);
listener.onNoteUpdated(note);
}
public interface NoteFragmentListener {
void close();
void onNoteUpdated(DBNote note);
}
}

View file

@ -145,10 +145,12 @@ public class NoteEditFragment extends BaseNoteFragment {
.subscribe(new Subscriber<CharSequence>() {
@Override
public void onCompleted() {
// Nothing to do here
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override

View file

@ -160,7 +160,8 @@ public class ItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@BindView(R.id.noteSwipeable)
public View noteSwipeable;
View noteSwipeFrame;
ImageView noteFavoriteLeft, noteDeleteRight;
ImageView noteFavoriteLeft;
ImageView noteDeleteRight;
TextView noteTitle;
@BindView(R.id.noteCategory)
TextView noteCategory;

View file

@ -44,21 +44,6 @@ public class NoteServerSyncHelper {
private static NoteServerSyncHelper instance;
/**
* Get (or create) instance from NoteServerSyncHelper.
* This has to be a singleton in order to realize correct registering and unregistering of
* the BroadcastReceiver, which listens on changes of network connectivity.
*
* @param dbHelper NoteSQLiteOpenHelper
* @return NoteServerSyncHelper
*/
public static synchronized NoteServerSyncHelper getInstance(NoteSQLiteOpenHelper dbHelper) {
if (instance == null) {
instance = new NoteServerSyncHelper(dbHelper);
}
return instance;
}
private NoteSQLiteOpenHelper dbHelper;
private Context appContext = null;
private LocalAccount localAccount;
@ -118,6 +103,21 @@ public class NoteServerSyncHelper {
updateNetworkStatus();
}
/**
* Get (or create) instance from NoteServerSyncHelper.
* This has to be a singleton in order to realize correct registering and unregistering of
* the BroadcastReceiver, which listens on changes of network connectivity.
*
* @param dbHelper NoteSQLiteOpenHelper
* @return NoteServerSyncHelper
*/
public static synchronized NoteServerSyncHelper getInstance(NoteSQLiteOpenHelper dbHelper) {
if (instance == null) {
instance = new NoteServerSyncHelper(dbHelper);
}
return instance;
}
public void updateAccount() throws NextcloudFilesAppAccountNotFoundException {
try {
this.localAccount = dbHelper.getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(appContext).name);

View file

@ -15,10 +15,6 @@ import it.niedermann.owncloud.notes.R;
*/
public class NoteUtil {
private NoteUtil() {
}
private static final Pattern pLists = Pattern.compile("^\\s*[*+-]\\s+", Pattern.MULTILINE);
private static final Pattern pHeadings = Pattern.compile("^#+\\s+(.*?)\\s*#*$", Pattern.MULTILINE);
private static final Pattern pHeadingLine = Pattern.compile("^(?:=*|-*)$", Pattern.MULTILINE);
@ -26,6 +22,9 @@ public class NoteUtil {
private static final Pattern pSpace1 = Pattern.compile("^\\s+", Pattern.MULTILINE);
private static final Pattern pSpace2 = Pattern.compile("\\s+$", Pattern.MULTILINE);
private NoteUtil() {
}
/**
* Strips all MarkDown from the given String