mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-22 12:56:02 +03:00
Merge branch 'master' into 354-password-protection
This commit is contained in:
commit
5782a49e66
31 changed files with 130 additions and 147 deletions
|
@ -30,10 +30,7 @@ public class AlwaysAutoCompleteTextView extends AppCompatAutoCompleteTextView {
|
|||
|
||||
@Override
|
||||
public void setThreshold(int threshold) {
|
||||
if (threshold < 0) {
|
||||
threshold = 0;
|
||||
}
|
||||
myThreshold = threshold;
|
||||
myThreshold = Math.max(threshold, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -71,7 +71,7 @@ public class MultiSelectedActionModeCallback implements Callback {
|
|||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_delete: {
|
||||
case R.id.menu_delete:
|
||||
try {
|
||||
SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context);
|
||||
List<DBNote> deletedNotes = new ArrayList<>();
|
||||
|
@ -106,13 +106,12 @@ public class MultiSelectedActionModeCallback implements Callback {
|
|||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case R.id.menu_move: {
|
||||
case R.id.menu_move:
|
||||
AccountChooserDialogFragment.newInstance().show(fragmentManager, NotesListViewActivity.class.getCanonicalName());
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -60,7 +60,7 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper {
|
|||
@Override
|
||||
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
switch (direction) {
|
||||
case ItemTouchHelper.LEFT: {
|
||||
case ItemTouchHelper.LEFT:
|
||||
final DBNote dbNoteWithoutContent = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
|
||||
final DBNote dbNote = db.getNote(dbNoteWithoutContent.getAccountId(), dbNoteWithoutContent.getId());
|
||||
db.deleteNoteAndSync(ssoAccount, dbNote.getId());
|
||||
|
@ -77,13 +77,13 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper {
|
|||
})
|
||||
.show();
|
||||
break;
|
||||
}
|
||||
case ItemTouchHelper.RIGHT: {
|
||||
final DBNote dbNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
|
||||
db.toggleFavorite(ssoAccount, dbNote, syncCallBack);
|
||||
case ItemTouchHelper.RIGHT:
|
||||
final DBNote adapterNote = (DBNote) adapter.getItem(viewHolder.getAdapterPosition());
|
||||
db.toggleFavorite(ssoAccount, adapterNote, syncCallBack);
|
||||
refreshLists.run();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//NoOp
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ public class EditNoteActivity extends LockedActivity implements BaseNoteFragment
|
|||
String category = null;
|
||||
boolean favorite = false;
|
||||
if (intent.hasExtra(PARAM_CATEGORY)) {
|
||||
Category categoryPreselection = (Category) intent.getSerializableExtra(PARAM_CATEGORY);
|
||||
Category categoryPreselection = (Category) Objects.requireNonNull(intent.getSerializableExtra(PARAM_CATEGORY));
|
||||
category = categoryPreselection.category;
|
||||
favorite = categoryPreselection.favorite != null ? categoryPreselection.favorite : false;
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ public class EditNoteActivity extends LockedActivity implements BaseNoteFragment
|
|||
String content = "";
|
||||
if (
|
||||
intent.hasExtra(Intent.EXTRA_TEXT) &&
|
||||
MIMETYPE_TEXT_PLAIN.equals(intent.getType()) &&
|
||||
MIMETYPE_TEXT_PLAIN.equals(intent.getType()) &&
|
||||
(Intent.ACTION_SEND.equals(intent.getAction()) ||
|
||||
INTENT_GOOGLE_ASSISTANT.equals(intent.getAction()))
|
||||
) {
|
||||
|
|
|
@ -11,6 +11,8 @@ import androidx.annotation.Nullable;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import it.niedermann.nextcloud.exception.ExceptionUtil;
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
|
||||
|
@ -18,8 +20,6 @@ import static it.niedermann.nextcloud.exception.ExceptionHandler.KEY_THROWABLE;
|
|||
|
||||
public class ExceptionActivity extends AppCompatActivity {
|
||||
|
||||
Throwable throwable;
|
||||
|
||||
private TextView stacktrace;
|
||||
|
||||
@SuppressLint("SetTextI18n") // only used for logging
|
||||
|
@ -38,7 +38,7 @@ public class ExceptionActivity extends AppCompatActivity {
|
|||
findViewById(R.id.close).setOnClickListener((v) -> close());
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
throwable = ((Throwable) getIntent().getSerializableExtra(KEY_THROWABLE));
|
||||
Throwable throwable = (Throwable) Objects.requireNonNull(getIntent().getSerializableExtra(KEY_THROWABLE));
|
||||
throwable.printStackTrace();
|
||||
toolbar.setTitle(getString(R.string.simple_error));
|
||||
message.setText(throwable.getMessage());
|
||||
|
@ -46,14 +46,14 @@ public class ExceptionActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
|
||||
void copyStacktraceToClipboard() {
|
||||
final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
private void copyStacktraceToClipboard() {
|
||||
final ClipboardManager clipboardManager = (ClipboardManager) Objects.requireNonNull(getSystemService(CLIPBOARD_SERVICE));
|
||||
ClipData clipData = ClipData.newPlainText(getString(R.string.simple_exception), "```\n" + this.stacktrace.getText() + "\n```");
|
||||
clipboardManager.setPrimaryClip(clipData);
|
||||
Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
void close() {
|
||||
private void close() {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,10 +35,11 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
|
|||
private int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
|
||||
|
||||
LocalAccount localAccount = null;
|
||||
private LocalAccount localAccount = null;
|
||||
|
||||
private NavigationAdapter adapterCategories;
|
||||
private NavigationAdapter.NavigationItem itemRecent, itemFavorites;
|
||||
private NavigationAdapter.NavigationItem itemRecent;
|
||||
private NavigationAdapter.NavigationItem itemFavorites;
|
||||
private NotesDatabase db = null;
|
||||
|
||||
@Override
|
||||
|
@ -144,7 +145,9 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
|
|||
}
|
||||
|
||||
Map<String, Integer> favorites = db.getFavoritesCount(localAccount.getId());
|
||||
//noinspection ConstantConditions
|
||||
int numFavorites = favorites.containsKey("1") ? favorites.get("1") : 0;
|
||||
//noinspection ConstantConditions
|
||||
int numNonFavorites = favorites.containsKey("0") ? favorites.get("0") : 0;
|
||||
itemFavorites.count = numFavorites;
|
||||
itemRecent.count = numFavorites + numNonFavorites;
|
||||
|
|
|
@ -106,7 +106,9 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
|
|||
|
||||
private ActionBarDrawerToggle drawerToggle;
|
||||
private NavigationAdapter adapterCategories;
|
||||
private NavigationItem itemRecent, itemFavorites, itemUncategorized;
|
||||
private NavigationItem itemRecent;
|
||||
private NavigationItem itemFavorites;
|
||||
private NavigationItem itemUncategorized;
|
||||
private Category navigationSelection = new Category(null, null);
|
||||
private String navigationOpen = "";
|
||||
private ActionMode mActionMode;
|
||||
|
@ -412,7 +414,9 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
|
|||
}
|
||||
|
||||
Map<String, Integer> favorites = db.getFavoritesCount(localAccount.getId());
|
||||
//noinspection ConstantConditions
|
||||
int numFavorites = favorites.containsKey("1") ? favorites.get("1") : 0;
|
||||
//noinspection ConstantConditions
|
||||
int numNonFavorites = favorites.containsKey("0") ? favorites.get("0") : 0;
|
||||
itemFavorites.count = numFavorites;
|
||||
itemRecent.count = numFavorites + numNonFavorites;
|
||||
|
@ -420,7 +424,8 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
|
|||
ArrayList<NavigationItem> items = new ArrayList<>();
|
||||
items.add(itemRecent);
|
||||
items.add(itemFavorites);
|
||||
NavigationItem lastPrimaryCategory = null, lastSecondaryCategory = null;
|
||||
NavigationItem lastPrimaryCategory = null;
|
||||
NavigationItem lastSecondaryCategory = null;
|
||||
for (NavigationItem item : categories) {
|
||||
int slashIndex = item.label.indexOf('/');
|
||||
String currentPrimaryCategory = slashIndex < 0 ? item.label : item.label.substring(0, slashIndex);
|
||||
|
|
|
@ -154,8 +154,8 @@ public class NoteListWidget extends AppWidgetProvider {
|
|||
} else {
|
||||
return category;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact
|
|||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
//NoOp
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -70,7 +70,7 @@ public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFa
|
|||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
//NoOp
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,7 +61,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
|
|||
protected NotesDatabase db;
|
||||
private NoteFragmentListener listener;
|
||||
|
||||
boolean isNew = true;
|
||||
protected boolean isNew = true;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -146,7 +146,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
|
|||
public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_note_fragment, menu);
|
||||
|
||||
if (isRequestPinShortcutSupported(requireActivity()) && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
if (isRequestPinShortcutSupported(requireActivity()) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
menu.add(Menu.NONE, MENU_ID_PIN, 110, R.string.pin_to_homescreen);
|
||||
}
|
||||
}
|
||||
|
@ -198,8 +198,8 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
|
|||
Intent shareIntent = new Intent();
|
||||
shareIntent.setAction(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, note.getTitle());
|
||||
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, note.getContent());
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT, note.getTitle());
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, note.getContent());
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
|
@ -211,7 +211,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
|
|||
|
||||
return false;
|
||||
case MENU_ID_PIN:
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
ShortcutManager shortcutManager = requireActivity().getSystemService(ShortcutManager.class);
|
||||
|
||||
if (shortcutManager != null) {
|
||||
|
@ -274,7 +274,8 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
|
|||
}
|
||||
}
|
||||
|
||||
float getFontSizeFromPreferences(SharedPreferences sp) {
|
||||
@SuppressWarnings("WeakerAccess") //PMD...
|
||||
protected float getFontSizeFromPreferences(SharedPreferences sp) {
|
||||
final String prefValueSmall = getString(R.string.pref_value_font_size_small);
|
||||
final String prefValueMedium = getString(R.string.pref_value_font_size_medium);
|
||||
// final String prefValueLarge = getString(R.string.pref_value_font_size_large);
|
||||
|
|
|
@ -48,25 +48,23 @@ public class CategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
CategoryViewHolder categoryViewHolder = (CategoryViewHolder) holder;
|
||||
|
||||
switch (category.id) {
|
||||
case addItemId: {
|
||||
case addItemId:
|
||||
Drawable wrapDrawable = DrawableCompat.wrap(context.getResources().getDrawable(category.icon));
|
||||
DrawableCompat.setTint(wrapDrawable, context.getResources().getColor(R.color.icon_color_default));
|
||||
categoryViewHolder.getIcon().setImageDrawable(wrapDrawable);
|
||||
categoryViewHolder.getCategoryWrapper().setOnClickListener((v) -> listener.onCategoryAdded());
|
||||
break;
|
||||
}
|
||||
case clearItemId: {
|
||||
case clearItemId:
|
||||
categoryViewHolder.getIcon().setImageDrawable(context.getResources().getDrawable(category.icon));
|
||||
categoryViewHolder.getCategoryWrapper().setOnClickListener((v) -> listener.onCategoryCleared());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
default:
|
||||
categoryViewHolder.getIcon().setImageDrawable(context.getResources().getDrawable(category.icon));
|
||||
categoryViewHolder.getCategoryWrapper().setOnClickListener((v) -> listener.onCategoryChosen(category.label));
|
||||
}
|
||||
break;
|
||||
}
|
||||
categoryViewHolder.getCategory().setText(NoteUtil.extendCategory(category.label));
|
||||
if (category.count > 0) {
|
||||
if (category.count != null && category.count > 0) {
|
||||
categoryViewHolder.getCount().setText(String.valueOf(category.count));
|
||||
} else {
|
||||
categoryViewHolder.getCount().setVisibility(View.GONE);
|
||||
|
|
|
@ -61,7 +61,7 @@ public class CategoryDialogFragment extends AppCompatDialogFragment {
|
|||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
if (requireArguments() != null && requireArguments().containsKey(PARAM_ACCOUNT_ID)) {
|
||||
if (getArguments() != null && requireArguments().containsKey(PARAM_ACCOUNT_ID)) {
|
||||
accountId = requireArguments().getLong(PARAM_ACCOUNT_ID);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Provide at least \"" + PARAM_ACCOUNT_ID + "\"");
|
||||
|
@ -151,7 +151,7 @@ public class CategoryDialogFragment extends AppCompatDialogFragment {
|
|||
super.onActivityCreated(savedInstanceState);
|
||||
if (editCategory.getText() == null || editCategory.getText().length() == 0) {
|
||||
editCategory.requestFocus();
|
||||
if (getDialog().getWindow() != null) {
|
||||
if (getDialog() != null && getDialog().getWindow() != null) {
|
||||
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
} else {
|
||||
Log.w(TAG, "can not set SOFT_INPUT_STATE_ALWAYAS_VISIBLE because getWindow() == null");
|
||||
|
|
|
@ -51,7 +51,8 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
|
|||
private FragmentNoteEditBinding binding;
|
||||
|
||||
private Handler handler;
|
||||
private boolean saveActive, unsavedEdit;
|
||||
private boolean saveActive;
|
||||
private boolean unsavedEdit;
|
||||
private final Runnable runAutoSave = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -94,7 +94,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup
|
||||
container, @Nullable Bundle savedInstanceState) {
|
||||
binding = FragmentNotePreviewBinding.inflate(inflater, container, false);
|
||||
return binding.getRoot();
|
||||
|
|
|
@ -87,7 +87,7 @@ public class NoteReadonlyFragment extends SearchableBaseNoteFragment {
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup
|
||||
container, @Nullable Bundle savedInstanceState) {
|
||||
binding = FragmentNotePreviewBinding.inflate(inflater, container, false);
|
||||
return binding.getRoot();
|
||||
|
|
|
@ -42,8 +42,8 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
|||
assert themePref != null;
|
||||
themePref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
Notes.setAppTheme(DarkModeSetting.valueOf((String) newValue));
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
getActivity().recreate();
|
||||
requireActivity().setResult(Activity.RESULT_OK);
|
||||
requireActivity().recreate();
|
||||
return true;
|
||||
});
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
|||
assert syncPref != null;
|
||||
syncPref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
Log.v(TAG, "syncPref: " + preference + " - newValue: " + newValue);
|
||||
SyncWorker.update(getContext(), newValue.toString());
|
||||
SyncWorker.update(requireContext(), newValue.toString());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -172,38 +172,30 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
|||
Layout layout = getLayout();
|
||||
if (layout == null) {
|
||||
Log.w(TAG, "getLayout() is null");
|
||||
return;
|
||||
}
|
||||
if (getContent() == null || getContent().isEmpty()) {
|
||||
Log.w(TAG, "getContent() returned " + getContent());
|
||||
return;
|
||||
}
|
||||
if (searchQuery == null || searchQuery.isEmpty()) {
|
||||
// No search term
|
||||
return;
|
||||
}
|
||||
if (currentOccurrence < 1) {
|
||||
} else if (getContent() == null || getContent().isEmpty()) {
|
||||
Log.w(TAG, "getContent is null or empty");
|
||||
} else if (currentOccurrence < 1) {
|
||||
// if currentOccurrence is lower than 1, jump to last occurrence
|
||||
currentOccurrence = occurrenceCount;
|
||||
jumpToOccurrence();
|
||||
return;
|
||||
}
|
||||
String currentContent = getContent().toLowerCase();
|
||||
int indexOfNewText = indexOfNth(currentContent, searchQuery.toLowerCase(), 0, currentOccurrence);
|
||||
if (indexOfNewText <= 0) {
|
||||
// Search term is not n times in text
|
||||
// Go back to first search result
|
||||
if (currentOccurrence != 1) {
|
||||
currentOccurrence = 1;
|
||||
jumpToOccurrence();
|
||||
} else if (searchQuery != null && !searchQuery.isEmpty()) {
|
||||
String currentContent = getContent().toLowerCase();
|
||||
int indexOfNewText = indexOfNth(currentContent, searchQuery.toLowerCase(), 0, currentOccurrence);
|
||||
if (indexOfNewText <= 0) {
|
||||
// Search term is not n times in text
|
||||
// Go back to first search result
|
||||
if (currentOccurrence != 1) {
|
||||
currentOccurrence = 1;
|
||||
jumpToOccurrence();
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
String textUntilFirstOccurrence = currentContent.substring(0, indexOfNewText);
|
||||
int numberLine = layout.getLineForOffset(textUntilFirstOccurrence.length());
|
||||
String textUntilFirstOccurrence = currentContent.substring(0, indexOfNewText);
|
||||
int numberLine = layout.getLineForOffset(textUntilFirstOccurrence.length());
|
||||
|
||||
if (numberLine >= 0) {
|
||||
getScrollView().smoothScrollTo(0, layout.getLineTop(numberLine));
|
||||
if (numberLine >= 0) {
|
||||
getScrollView().smoothScrollTo(0, layout.getLineTop(numberLine));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,20 +207,18 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
|||
int idx = input.indexOf(value, startIndex);
|
||||
if (idx == -1)
|
||||
return -1;
|
||||
return indexOfNth(input, value, idx + 1, --nth);
|
||||
return indexOfNth(input, value, idx + 1, nth - 1);
|
||||
}
|
||||
|
||||
private static int countOccurrences(String haystack, String needle) {
|
||||
if (haystack == null || haystack.isEmpty() || needle == null || needle.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
haystack = haystack.toLowerCase();
|
||||
needle = needle.toLowerCase();
|
||||
int lastIndex = 0;
|
||||
int count = 0;
|
||||
|
||||
while (lastIndex != -1) {
|
||||
lastIndex = haystack.indexOf(needle, lastIndex);
|
||||
lastIndex = haystack.toLowerCase().indexOf(needle.toLowerCase(), lastIndex);
|
||||
if (lastIndex != -1) {
|
||||
count++;
|
||||
lastIndex += needle.length();
|
||||
|
|
|
@ -16,7 +16,7 @@ import it.niedermann.owncloud.notes.util.SupportUtil;
|
|||
|
||||
public class AboutFragmentLicenseTab extends Fragment {
|
||||
|
||||
void openLicense() {
|
||||
private void openLicense() {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_license))));
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@ import it.niedermann.owncloud.notes.util.NoteUtil;
|
|||
* It can be directly generated from the JSON answer from the server.
|
||||
*/
|
||||
public class CloudNote implements Serializable {
|
||||
private long remoteId = 0;
|
||||
private long remoteId;
|
||||
private String title = "";
|
||||
private Calendar modified = null;
|
||||
private Calendar modified;
|
||||
private String content = "";
|
||||
private boolean favorite = false;
|
||||
private String category = "";
|
||||
|
@ -51,7 +51,6 @@ public class CloudNote implements Serializable {
|
|||
this.title = NoteUtil.removeMarkDown(title);
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public Calendar getModified() {
|
||||
return modified;
|
||||
}
|
||||
|
|
|
@ -57,9 +57,6 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.Vi
|
|||
@NonNull
|
||||
private final View view;
|
||||
|
||||
@NonNull
|
||||
private final ItemNavigationBinding binding;
|
||||
|
||||
@NonNull
|
||||
private final TextView name;
|
||||
@NonNull
|
||||
|
@ -72,7 +69,7 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.Vi
|
|||
ViewHolder(@NonNull View itemView, @NonNull final ClickListener clickListener) {
|
||||
super(itemView);
|
||||
view = itemView;
|
||||
binding = ItemNavigationBinding.bind(view);
|
||||
ItemNavigationBinding binding = ItemNavigationBinding.bind(view);
|
||||
this.name = binding.navigationItemLabel;
|
||||
this.count = binding.navigationItemCount;
|
||||
this.icon = binding.navigationItemIcon;
|
||||
|
@ -80,7 +77,7 @@ public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.Vi
|
|||
itemView.setOnClickListener(view -> clickListener.onItemClick(currentItem));
|
||||
}
|
||||
|
||||
void assignItem(@NonNull NavigationItem item) {
|
||||
private void assignItem(@NonNull NavigationItem item) {
|
||||
currentItem = item;
|
||||
boolean isSelected = item.id.equals(selectedItem);
|
||||
name.setText(NoteUtil.extendCategory(item.label));
|
||||
|
|
|
@ -32,6 +32,7 @@ abstract class AbstractNotesDatabase extends SQLiteOpenHelper {
|
|||
private static final String TAG = AbstractNotesDatabase.class.getSimpleName();
|
||||
|
||||
private static final int database_version = 11;
|
||||
@NonNull
|
||||
private final Context context;
|
||||
|
||||
protected static final String database_name = "OWNCLOUD_NOTES";
|
||||
|
@ -55,12 +56,13 @@ abstract class AbstractNotesDatabase extends SQLiteOpenHelper {
|
|||
protected static final String key_category = "CATEGORY";
|
||||
protected static final String key_etag = "ETAG";
|
||||
|
||||
protected AbstractNotesDatabase(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory) {
|
||||
protected AbstractNotesDatabase(@NonNull Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory) {
|
||||
super(context, name, factory, database_version);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public class LoadNotesListTask extends AsyncTask<Void, Void, List<Item>> {
|
|||
for (int i = 0; i < noteList.size(); i++) {
|
||||
DBNote currentNote = noteList.get(i);
|
||||
String timeslot = timeslotter.getTimeslot(currentNote);
|
||||
if(i > 0 && !timeslot.equals(lastTimeslot)) {
|
||||
if (i > 0 && !timeslot.equals(lastTimeslot)) {
|
||||
itemList.add(new SectionItem(timeslot));
|
||||
}
|
||||
itemList.add(colorTheNote(currentNote));
|
||||
|
@ -132,16 +132,16 @@ public class LoadNotesListTask extends AsyncTask<Void, Void, List<Item>> {
|
|||
int day = now.get(Calendar.DAY_OF_MONTH);
|
||||
int offsetWeekStart = (now.get(Calendar.DAY_OF_WEEK) - now.getFirstDayOfWeek() + 7) % 7;
|
||||
timeslots.add(new Timeslot(context.getResources().getString(R.string.listview_updated_today), month, day));
|
||||
timeslots.add(new Timeslot(context.getResources().getString(R.string.listview_updated_yesterday), month,day - 1));
|
||||
timeslots.add(new Timeslot(context.getResources().getString(R.string.listview_updated_this_week), month,day - offsetWeekStart));
|
||||
timeslots.add(new Timeslot(context.getResources().getString(R.string.listview_updated_last_week), month,day - offsetWeekStart - 7));
|
||||
timeslots.add(new Timeslot(context.getResources().getString(R.string.listview_updated_this_month), month,1));
|
||||
timeslots.add(new Timeslot(context.getResources().getString(R.string.listview_updated_yesterday), month, day - 1));
|
||||
timeslots.add(new Timeslot(context.getResources().getString(R.string.listview_updated_this_week), month, day - offsetWeekStart));
|
||||
timeslots.add(new Timeslot(context.getResources().getString(R.string.listview_updated_last_week), month, day - offsetWeekStart - 7));
|
||||
timeslots.add(new Timeslot(context.getResources().getString(R.string.listview_updated_this_month), month, 1));
|
||||
timeslots.add(new Timeslot(context.getResources().getString(R.string.listview_updated_last_month), month - 1, 1));
|
||||
lastYear = Calendar.getInstance();
|
||||
lastYear.set(now.get(Calendar.YEAR) - 1, 0, 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
String getTimeslot(DBNote note) {
|
||||
private String getTimeslot(DBNote note) {
|
||||
if (note.isFavorite()) {
|
||||
return "";
|
||||
}
|
||||
|
@ -160,8 +160,8 @@ public class LoadNotesListTask extends AsyncTask<Void, Void, List<Item>> {
|
|||
}
|
||||
|
||||
private class Timeslot {
|
||||
final String label;
|
||||
final Calendar time;
|
||||
private final String label;
|
||||
private final Calendar time;
|
||||
|
||||
Timeslot(String label, int month, int day) {
|
||||
this.label = label;
|
||||
|
|
|
@ -295,7 +295,7 @@ public class NoteServerSyncHelper {
|
|||
this.onlyLocalChanges = onlyLocalChanges;
|
||||
}
|
||||
|
||||
void addCallbacks(SingleSignOnAccount ssoAccount, List<ISyncCallback> callbacks) {
|
||||
private void addCallbacks(SingleSignOnAccount ssoAccount, List<ISyncCallback> callbacks) {
|
||||
this.callbacks.put(ssoAccount.name, callbacks);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class NotesDatabase extends AbstractNotesDatabase {
|
|||
|
||||
private final NoteServerSyncHelper serverSyncHelper;
|
||||
|
||||
private NotesDatabase(Context context) {
|
||||
private NotesDatabase(@NonNull Context context) {
|
||||
super(context, database_name, null);
|
||||
serverSyncHelper = NoteServerSyncHelper.getInstance(this);
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ public class NotesDatabase extends AbstractNotesDatabase {
|
|||
deleteNoteAndSync(ssoAccount, note.getId());
|
||||
|
||||
notifyNotesChanged();
|
||||
getNoteServerSyncHelper().scheduleSync(ssoAccount,true);
|
||||
getNoteServerSyncHelper().scheduleSync(ssoAccount, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -389,7 +389,7 @@ public class NotesDatabase extends AbstractNotesDatabase {
|
|||
table_notes,
|
||||
new String[]{key_category, "COUNT(*)"},
|
||||
key_status + " != ? AND " + key_account_id + " = ? AND " + key_category + " LIKE ? AND " + key_category + " != \"\"",
|
||||
new String[]{DBStatus.LOCAL_DELETED.getTitle(), String.valueOf(accountId), "%" + (search == null ? search : search.trim()) + "%"},
|
||||
new String[]{DBStatus.LOCAL_DELETED.getTitle(), String.valueOf(accountId), "%" + (search == null ? null : search.trim()) + "%"},
|
||||
key_category,
|
||||
null,
|
||||
key_category);
|
||||
|
@ -436,7 +436,7 @@ public class NotesDatabase extends AbstractNotesDatabase {
|
|||
if (callback != null) {
|
||||
serverSyncHelper.addCallbackPush(ssoAccount, callback);
|
||||
}
|
||||
serverSyncHelper.scheduleSync(ssoAccount,true);
|
||||
serverSyncHelper.scheduleSync(ssoAccount, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -538,7 +538,7 @@ public class NotesDatabase extends AbstractNotesDatabase {
|
|||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(key_status, DBStatus.LOCAL_DELETED.getTitle());
|
||||
int i = db.update(table_notes,
|
||||
db.update(table_notes,
|
||||
values,
|
||||
key_id + " = ?",
|
||||
new String[]{String.valueOf(id)});
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.nextcloud.android.sso.AccountImporter;
|
|||
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
|
||||
import com.nextcloud.android.sso.model.SingleSignOnAccount;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
|
@ -23,7 +24,7 @@ import it.niedermann.owncloud.notes.model.LocalAccount;
|
|||
|
||||
public class SyncWorker extends Worker {
|
||||
|
||||
private static final String TAG = SyncWorker.class.getCanonicalName();
|
||||
private static final String TAG = Objects.requireNonNull(SyncWorker.class.getCanonicalName());
|
||||
private static final String WORKER_TAG = "background_synchronization";
|
||||
|
||||
private static final Constraints constraints = new Constraints.Builder()
|
||||
|
|
|
@ -26,7 +26,7 @@ public class ClipboardUtil {
|
|||
try {
|
||||
clipboardURL = new URL(clipboardData.getItemAt(0).getText().toString()).toString();
|
||||
} catch (MalformedURLException e) {
|
||||
Log.d(TAG, "Clipboard does not contain a valid URL: " + clipboardURL);
|
||||
Log.d(TAG, "Clipboard does not contain a valid URL: " + clipboardData.getItemAt(0).getText().toString());
|
||||
}
|
||||
}
|
||||
return clipboardURL;
|
||||
|
|
|
@ -37,13 +37,14 @@ public class NoteUtil {
|
|||
public static String removeMarkDown(@Nullable String s) {
|
||||
if (s == null)
|
||||
return "";
|
||||
s = pLists.matcher(s).replaceAll("");
|
||||
s = pHeadings.matcher(s).replaceAll("$1");
|
||||
s = pHeadingLine.matcher(s).replaceAll("");
|
||||
s = pEmphasis.matcher(s).replaceAll("$2");
|
||||
s = pSpace1.matcher(s).replaceAll("");
|
||||
s = pSpace2.matcher(s).replaceAll("");
|
||||
return s;
|
||||
String result = s;
|
||||
result = pLists.matcher(result).replaceAll("");
|
||||
result = pHeadings.matcher(result).replaceAll("$1");
|
||||
result = pHeadingLine.matcher(result).replaceAll("");
|
||||
result = pEmphasis.matcher(result).replaceAll("$2");
|
||||
result = pSpace1.matcher(result).replaceAll("");
|
||||
result = pSpace2.matcher(result).replaceAll("");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,21 +79,15 @@ public abstract class NotesTextWatcher implements TextWatcher {
|
|||
// Find start of line
|
||||
int startOfLine = MarkDownUtil.getStartOfLine(s, start);
|
||||
String line = s.subSequence(startOfLine, start).toString();
|
||||
if (line.startsWith(codeBlock)) {
|
||||
// "start" is the direct sibling of the codeBlock
|
||||
if (start - startOfLine == codeBlock.length()) {
|
||||
if (!resetSelection) {
|
||||
resetSelectionTo = editText.getSelectionEnd();
|
||||
resetSelection = true;
|
||||
Log.v(TAG, "Entered a character directly behind a codeBlock - prepare selection reset to " + resetSelectionTo);
|
||||
}
|
||||
}
|
||||
} else if (s.subSequence(startOfLine, start + count).toString().startsWith(codeBlock)) {
|
||||
if (!resetSelection) {
|
||||
resetSelectionTo = editText.getSelectionEnd();
|
||||
resetSelection = true;
|
||||
Log.v(TAG, "One completed a ``-codeBlock with the third `-character - prepare selection reset to " + resetSelectionTo);
|
||||
}
|
||||
// "start" is the direct sibling of the codeBlock
|
||||
if (line.startsWith(codeBlock) && start - startOfLine == codeBlock.length() && !resetSelection) {
|
||||
resetSelectionTo = editText.getSelectionEnd();
|
||||
resetSelection = true;
|
||||
Log.v(TAG, "Entered a character directly behind a codeBlock - prepare selection reset to " + resetSelectionTo);
|
||||
} else if (s.subSequence(startOfLine, start + count).toString().startsWith(codeBlock) && !resetSelection) {
|
||||
resetSelectionTo = editText.getSelectionEnd();
|
||||
resetSelection = true;
|
||||
Log.v(TAG, "One completed a ``-codeBlock with the third `-character - prepare selection reset to " + resetSelectionTo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,16 +59,15 @@ public class ContextBasedFormattingCallback implements ActionMode.Callback {
|
|||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.checkbox: {
|
||||
case R.id.checkbox:
|
||||
insertCheckbox();
|
||||
return true;
|
||||
}
|
||||
case R.id.link: {
|
||||
case R.id.link:
|
||||
insertLink();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void insertCheckbox() {
|
||||
|
|
|
@ -62,7 +62,7 @@ public class ContextBasedRangeFormattingCallback implements ActionMode.Callback
|
|||
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.bold: {
|
||||
case R.id.bold:
|
||||
markdown = "**";
|
||||
if (hasAlreadyMarkdown(start, end, markdown)) {
|
||||
this.removeMarkdown(ssb, start, end, markdown);
|
||||
|
@ -72,8 +72,7 @@ public class ContextBasedRangeFormattingCallback implements ActionMode.Callback
|
|||
editText.setText(ssb);
|
||||
editText.setSelection(end + markdown.length() * 2);
|
||||
return true;
|
||||
}
|
||||
case R.id.italic: {
|
||||
case R.id.italic:
|
||||
markdown = "*";
|
||||
if (hasAlreadyMarkdown(start, end, markdown)) {
|
||||
this.removeMarkdown(ssb, start, end, markdown);
|
||||
|
@ -83,8 +82,7 @@ public class ContextBasedRangeFormattingCallback implements ActionMode.Callback
|
|||
editText.setText(ssb);
|
||||
editText.setSelection(end + markdown.length() * 2);
|
||||
return true;
|
||||
}
|
||||
case R.id.link: {
|
||||
case R.id.link:
|
||||
boolean textToFormatIsLink = TextUtils.indexOf(editText.getText().subSequence(start, end), "http") == 0;
|
||||
if (textToFormatIsLink) {
|
||||
ssb.insert(end, ")");
|
||||
|
@ -108,8 +106,7 @@ public class ContextBasedRangeFormattingCallback implements ActionMode.Callback
|
|||
editText.setSelection(end + 2); // after <end>](
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case android.R.id.cut: {
|
||||
case android.R.id.cut:
|
||||
// https://github.com/stefan-niedermann/nextcloud-notes/issues/604
|
||||
// https://github.com/stefan-niedermann/nextcloud-notes/issues/477
|
||||
try {
|
||||
|
@ -121,9 +118,9 @@ public class ContextBasedRangeFormattingCallback implements ActionMode.Callback
|
|||
editText.clearFocus();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -148,7 +145,6 @@ public class ContextBasedRangeFormattingCallback implements ActionMode.Callback
|
|||
ssb.insert(start, markdown);
|
||||
editText.getText().charAt(start);
|
||||
editText.getText().charAt(start + 1);
|
||||
end += markdown.length() * 2;
|
||||
ssb.setSpan(new StyleSpan(typeface), start, end, 1);
|
||||
ssb.setSpan(new StyleSpan(typeface), start, end + markdown.length() * 2, 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue