Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.niedermann.owncloud.notes.android.activity;

import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
Expand All @@ -22,13 +24,14 @@
import java.util.concurrent.TimeUnit;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.android.fragment.CategoryDialogFragment;
import it.niedermann.owncloud.notes.model.DBNote;
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
import it.niedermann.owncloud.notes.util.ICallback;
import it.niedermann.owncloud.notes.util.MarkDownUtil;
import rx.Subscriber;

public class EditNoteActivity extends AppCompatActivity {
public class EditNoteActivity extends AppCompatActivity implements CategoryDialogFragment.CategoryDialogListener {

public static final String PARAM_NOTE = "note";
public static final String PARAM_ORIGINAL_NOTE = "original_note";
Expand Down Expand Up @@ -185,6 +188,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
db.toggleFavorite(note, null);
invalidateOptionsMenu();
return true;
case R.id.menu_category:
showCategorySelector();
return true;
case R.id.menu_preview:
saveData(null);
Intent previewIntent = new Intent(getApplicationContext(), NoteActivity.class);
Expand All @@ -211,6 +217,29 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

/**
* Opens a dialog in order to chose a category
*/
private void showCategorySelector() {
final String fragmentId = "fragment_category";
FragmentManager manager = getFragmentManager();
Fragment frag = manager.findFragmentByTag(fragmentId);
if(frag!=null) {
manager.beginTransaction().remove(frag).commit();
}
Bundle arguments = new Bundle();
arguments.putString(CategoryDialogFragment.PARAM_CATEGORY, note.getCategory());
CategoryDialogFragment categoryFragment = new CategoryDialogFragment();
categoryFragment.setArguments(arguments);
categoryFragment.show(manager, fragmentId);
}

@Override
public void onCategoryChosen(String category) {
note.setCategory(category);
autoSave();
}

/**
* Saves all changes and closes the Activity
*/
Expand Down Expand Up @@ -295,14 +324,6 @@ public void run() {
});
}
}, DELAY_AFTER_SYNC);

/* TODO Notify widgets

int widgetIDs[] = AppWidgetManager.getInstance(getApplication()).getAppWidgetIds(new ComponentName(getApplication(), SingleNoteWidget.class));

for (int id : widgetIDs) {
AppWidgetManager.getInstance(getApplication()).notifyAppWidgetViewDataChanged(id, R.layout.widget_single_note);
}*/
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package it.niedermann.owncloud.notes.android.fragment;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import it.niedermann.owncloud.notes.R;

/**
* This {@link DialogFragment} allows for the selection of a category.
* The calling Activity must implement the interface {@link CategoryDialogListener}.
*/
public class CategoryDialogFragment extends DialogFragment {

/**
* Interface that must be implemented by the calling Activity.
*/
public interface CategoryDialogListener {
/**
* This method is called after the user has chosen a category.
* @param category Name of the category which was chosen by the user.
*/
void onCategoryChosen(String category);
}

public static final String PARAM_CATEGORY = "category";

private EditText textCategory;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View dialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_change_category, null);
textCategory = (EditText) dialogView.findViewById(R.id.editCategory);
if(savedInstanceState==null) {
textCategory.setText(getArguments().getString(PARAM_CATEGORY));
}
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.change_category_title)
.setView(dialogView)
.setMessage(R.string.change_category_message)
.setCancelable(true)
.setPositiveButton(R.string.action_edit_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
CategoryDialogListener listener = (CategoryDialogListener) getActivity();
listener.onCategoryChosen(textCategory.getText().toString());
}
})
.setNegativeButton(R.string.action_edit_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.create();
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package it.niedermann.owncloud.notes.android.fragment.about;

import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import it.niedermann.owncloud.notes.BuildConfig;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.util.SupportUtil;

public class AboutFragmentCreditsTab extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_about_credits_tab, container, false);
String versionName;
try {
versionName = "v"+getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
versionName = "(error)";
}
SupportUtil.setHtml((TextView) v.findViewById(R.id.about_version), R.string.about_version, versionName);
SupportUtil.setHtml((TextView) v.findViewById(R.id.about_version), R.string.about_version, "v"+BuildConfig.VERSION_NAME);
SupportUtil.setHtml((TextView) v.findViewById(R.id.about_maintainer), R.string.about_maintainer);
SupportUtil.setHtml((TextView) v.findViewById(R.id.about_translators), R.string.about_translators_transifex, getString(R.string.url_translations));
return v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public void toggleFavorite(DBNote note, ICallback callback) {
* @return changed note if differs from database, otherwise the old note.
*/
public DBNote updateNoteAndSync(DBNote oldNote, String newContent, ICallback callback) {
debugPrintFullDB();
//debugPrintFullDB();
DBNote newNote;
if(newContent==null) {
newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED);
Expand All @@ -344,9 +344,10 @@ public DBNote updateNoteAndSync(DBNote oldNote, String newContent, ICallback cal
ContentValues values = new ContentValues();
values.put(key_status, newNote.getStatus().getTitle());
values.put(key_title, newNote.getTitle());
values.put(key_category, newNote.getCategory());
values.put(key_modified, newNote.getModified(DATE_FORMAT));
values.put(key_content, newNote.getContent());
int rows = db.update(table_notes, values, key_id + " = ? AND " + key_content + " != ?", new String[]{String.valueOf(newNote.getId()), newNote.getContent()});
int rows = db.update(table_notes, values, key_id + " = ? AND (" + key_content + " != ? OR " + key_category + " != ?)", new String[]{String.valueOf(newNote.getId()), newNote.getContent(), newNote.getCategory()});
// if data was changed, set new status and schedule sync (with callback); otherwise invoke callback directly.
if(rows > 0) {
if(callback!=null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.net.MalformedURLException;

import at.bitfire.cert4android.CustomCertManager;
import it.niedermann.owncloud.notes.BuildConfig;
import it.niedermann.owncloud.notes.model.CloudNote;
import it.niedermann.owncloud.notes.util.ServerResponse.NoteResponse;
import it.niedermann.owncloud.notes.util.ServerResponse.NotesResponse;
Expand Down Expand Up @@ -94,7 +95,8 @@ private NoteResponse putNote(CustomCertManager ccm, CloudNote note, String path,
JSONObject paramObject = new JSONObject();
paramObject.accumulate(JSON_CONTENT, note.getContent());
paramObject.accumulate(JSON_MODIFIED, note.getModified().getTimeInMillis()/1000);
paramObject.accumulate(JSON_FAVORITE, note.isFavorite());
paramObject.accumulate(JSON_FAVORITE, note.isFavorite());
paramObject.accumulate(JSON_CATEGORY, note.getCategory());
return new NoteResponse(requestServer(ccm, path, method, paramObject, null));
}

Expand Down Expand Up @@ -138,6 +140,7 @@ private ResponseData requestServer(CustomCertManager ccm, String target, String
con.setRequestProperty(
"Authorization",
"Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP));
con.setRequestProperty("User-Agent", "nextcloud-notes/" + BuildConfig.VERSION_NAME + " (Android)");
if(lastETag!=null && METHOD_GET.equals(method)) {
con.setRequestProperty("If-None-Match", lastETag);
}
Expand Down Expand Up @@ -177,4 +180,4 @@ private ResponseData requestServer(CustomCertManager ccm, String target, String
// return these header fields since they should only be saved after successful processing the result!
return new ResponseData(result.toString(), etag, lastModified);
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/layout/dialog_change_category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="?dialogPreferredPadding"
>

<EditText
android:id="@+id/editCategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
/>

</LinearLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/menu_note_list_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
android:title="@string/menu_favorite"
android:checkable="true"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_category"
android:orderInCategory="60"
android:title="@string/menu_change_category"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_preview"
android:icon="@drawable/ic_eye_white_24dp"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
<string name="menu_copy">Copy</string>
<string name="menu_edit">Edit</string>
<string name="menu_cancel">Cancel</string>
<string name="menu_change_category">Category</string>
<string name="menu_favorite">Favorite</string>
<string name="menu_preview">Preview</string>
<string name="menu_share">Share</string>
<string name="menu_about">About</string>

<string name="change_category_title">Chose category</string>
<string name="change_category_message">Please enter a category name</string>
<string name="copy">Copy</string>

<string name="listview_updated_today">Today</string>
Expand Down