mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-28 03:25:18 +03:00
Use correct accountId to suggest categories
This commit is contained in:
parent
bde70bd27d
commit
25357d7a2e
2 changed files with 17 additions and 19 deletions
|
@ -362,6 +362,7 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
|
||||||
}
|
}
|
||||||
Bundle arguments = new Bundle();
|
Bundle arguments = new Bundle();
|
||||||
arguments.putString(CategoryDialogFragment.PARAM_CATEGORY, note.getCategory());
|
arguments.putString(CategoryDialogFragment.PARAM_CATEGORY, note.getCategory());
|
||||||
|
arguments.putLong(CategoryDialogFragment.PARAM_ACCOUNT_ID, note.getAccountId());
|
||||||
CategoryDialogFragment categoryFragment = new CategoryDialogFragment();
|
CategoryDialogFragment categoryFragment = new CategoryDialogFragment();
|
||||||
categoryFragment.setArguments(arguments);
|
categoryFragment.setArguments(arguments);
|
||||||
categoryFragment.setTargetFragment(this, 0);
|
categoryFragment.setTargetFragment(this, 0);
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -45,10 +44,14 @@ public class CategoryDialogFragment extends DialogFragment {
|
||||||
void onCategoryChosen(String category);
|
void onCategoryChosen(String category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String PARAM_ACCOUNT_ID = "account_id";
|
||||||
public static final String PARAM_CATEGORY = "category";
|
public static final String PARAM_CATEGORY = "category";
|
||||||
|
|
||||||
|
private long accountId;
|
||||||
|
|
||||||
@BindView(R.id.editCategory)
|
@BindView(R.id.editCategory)
|
||||||
AlwaysAutoCompleteTextView textCategory;
|
AlwaysAutoCompleteTextView textCategory;
|
||||||
|
|
||||||
private FolderArrayAdapter adapter;
|
private FolderArrayAdapter adapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,6 +60,7 @@ public class CategoryDialogFragment extends DialogFragment {
|
||||||
ButterKnife.bind(this, dialogView);
|
ButterKnife.bind(this, dialogView);
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
textCategory.setText(getArguments().getString(PARAM_CATEGORY));
|
textCategory.setText(getArguments().getString(PARAM_CATEGORY));
|
||||||
|
accountId = getArguments().getLong(PARAM_ACCOUNT_ID);
|
||||||
}
|
}
|
||||||
adapter = new FolderArrayAdapter(getActivity(), android.R.layout.simple_spinner_dropdown_item);
|
adapter = new FolderArrayAdapter(getActivity(), android.R.layout.simple_spinner_dropdown_item);
|
||||||
textCategory.setAdapter(adapter);
|
textCategory.setAdapter(adapter);
|
||||||
|
@ -65,24 +69,18 @@ public class CategoryDialogFragment extends DialogFragment {
|
||||||
.setTitle(R.string.change_category_title)
|
.setTitle(R.string.change_category_title)
|
||||||
.setView(dialogView)
|
.setView(dialogView)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(R.string.action_edit_save, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> {
|
||||||
@Override
|
CategoryDialogListener listener;
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
Fragment target = getTargetFragment();
|
||||||
CategoryDialogListener listener;
|
if (target instanceof CategoryDialogListener) {
|
||||||
Fragment target = getTargetFragment();
|
listener = (CategoryDialogListener) target;
|
||||||
if (target instanceof CategoryDialogListener) {
|
} else {
|
||||||
listener = (CategoryDialogListener) target;
|
listener = (CategoryDialogListener) getActivity();
|
||||||
} else {
|
|
||||||
listener = (CategoryDialogListener) getActivity();
|
|
||||||
}
|
|
||||||
listener.onCategoryChosen(textCategory.getText().toString());
|
|
||||||
}
|
}
|
||||||
|
listener.onCategoryChosen(textCategory.getText().toString());
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.simple_cancel, new DialogInterface.OnClickListener() {
|
.setNegativeButton(R.string.simple_cancel, (dialog, which) -> {
|
||||||
@Override
|
// do nothing
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
@ -102,8 +100,7 @@ public class CategoryDialogFragment extends DialogFragment {
|
||||||
@Override
|
@Override
|
||||||
protected List<String> doInBackground(Void... voids) {
|
protected List<String> doInBackground(Void... voids) {
|
||||||
NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper.getInstance(getActivity());
|
NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper.getInstance(getActivity());
|
||||||
// FIXME hardcoded accountId
|
List<NavigationAdapter.NavigationItem> items = db.getCategories(accountId);
|
||||||
List<NavigationAdapter.NavigationItem> items = db.getCategories(1);
|
|
||||||
List<String> categories = new ArrayList<>();
|
List<String> categories = new ArrayList<>();
|
||||||
for (NavigationAdapter.NavigationItem item : items) {
|
for (NavigationAdapter.NavigationItem item : items) {
|
||||||
if (!item.label.isEmpty()) {
|
if (!item.label.isEmpty()) {
|
||||||
|
|
Loading…
Reference in a new issue