WIP +1
This commit is contained in:
parent
5f31ce23d0
commit
88bb4ddb8a
9 changed files with 172 additions and 352 deletions
|
@ -98,7 +98,13 @@ public class DBWrapper extends Wrapper {
|
|||
"CREATE TABLE IF NOT EXISTS queue_event (" +
|
||||
" queue_id INTEGER," +
|
||||
" event_id INTEGER" +
|
||||
");"
|
||||
");",
|
||||
|
||||
"CREATE INDEX IF NOT EXISTS queue_event__event_id_tag_id ON queue_event(queue_id, event_id);",
|
||||
|
||||
"CREATE INDEX IF NOT EXISTS queue_event__event_id ON queue_event(queue_id);",
|
||||
|
||||
"CREATE INDEX IF NOT EXISTS queue_event__tag_id ON queue_event(event_id);"
|
||||
};
|
||||
|
||||
private static String DB_PATH = "database.db";
|
||||
|
|
|
@ -32,6 +32,7 @@ public class EventImpl implements Event {
|
|||
|
||||
private final SQLiteDatabase db;
|
||||
private final int id;
|
||||
private Tag[] cachedTags;
|
||||
|
||||
protected EventImpl(SQLiteDatabase db, int id) {
|
||||
this.db = db;
|
||||
|
@ -46,8 +47,14 @@ public class EventImpl implements Event {
|
|||
@Override
|
||||
public long getTimestamp() {
|
||||
synchronized (this.db) {
|
||||
Cursor cursor = db.query("event", new String[] { "timestamp" }, "id = ?",
|
||||
new String[] { Integer.toString(this.getId()) }, null, null, null
|
||||
Cursor cursor = db.query(
|
||||
"event",
|
||||
new String[] { "timestamp" },
|
||||
"id = ?",
|
||||
new String[] { Integer.toString(this.getId()) },
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
if (Utils.findResult(cursor)) {
|
||||
|
@ -70,8 +77,14 @@ public class EventImpl implements Event {
|
|||
@Override
|
||||
public String getComment() {
|
||||
synchronized (this.db) {
|
||||
Cursor cursor = db.query("event", new String[] { "comment" }, "id = ?",
|
||||
new String[] { Integer.toString(this.getId()) }, null, null, null
|
||||
Cursor cursor = db.query(
|
||||
"event",
|
||||
new String[] { "comment" },
|
||||
"id = ?",
|
||||
new String[] { Integer.toString(this.getId()) },
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
if (Utils.findResult(cursor)) {
|
||||
|
@ -107,6 +120,8 @@ public class EventImpl implements Event {
|
|||
@Override
|
||||
public void addTag(Tag tag) {
|
||||
synchronized (this.db) {
|
||||
this.cachedTags = null;
|
||||
|
||||
if (tag == null) return;
|
||||
|
||||
if (this.hasTag(tag)) return;
|
||||
|
@ -125,6 +140,8 @@ public class EventImpl implements Event {
|
|||
@Override
|
||||
public void removeTag(Tag tag) {
|
||||
synchronized (this.db) {
|
||||
this.cachedTags = null;
|
||||
|
||||
if (tag == null) return;
|
||||
|
||||
if (!this.hasTag(tag)) return;
|
||||
|
@ -142,6 +159,8 @@ public class EventImpl implements Event {
|
|||
@Override
|
||||
public void removeTags() {
|
||||
synchronized (this.db) {
|
||||
this.cachedTags = null;
|
||||
|
||||
try {
|
||||
db.delete("event_tag", "event_id = ?", new String[] { Integer.toString(this.getId()) });
|
||||
} catch (SQLiteException e) {
|
||||
|
@ -153,8 +172,17 @@ public class EventImpl implements Event {
|
|||
@Override
|
||||
public Tag[] getTags() {
|
||||
synchronized (this.db) {
|
||||
Cursor cursor = db.query("event_tag", new String[] { "tag_id" }, "event_id = ?",
|
||||
new String[] { Integer.toString(this.getId()) }, null, null, "tag_id desc"
|
||||
if (this.cachedTags != null)
|
||||
return this.cachedTags;
|
||||
|
||||
Cursor cursor = db.query(
|
||||
"event_tag",
|
||||
new String[] { "tag_id" },
|
||||
"event_id = ?",
|
||||
new String[] { Integer.toString(this.getId()) },
|
||||
null,
|
||||
null,
|
||||
"tag_id desc"
|
||||
);
|
||||
|
||||
if (cursor == null) {
|
||||
|
@ -168,7 +196,7 @@ public class EventImpl implements Event {
|
|||
tags[index++] = new TagImpl(this.db, cursor.getInt(0));
|
||||
}
|
||||
|
||||
return tags;
|
||||
return this.cachedTags = tags;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,12 +72,7 @@ public class QueueImpl implements Queue {
|
|||
synchronized (this.db) {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put("name", name);
|
||||
db.update(
|
||||
"queue",
|
||||
cv,
|
||||
"id = ?",
|
||||
new String[] { Integer.toString(this.getId()) }
|
||||
);
|
||||
db.update("queue", cv, "id = ?", new String[] { Integer.toString(this.getId()) });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,10 +97,7 @@ public class QueueImpl implements Queue {
|
|||
|
||||
int index = 0;
|
||||
while (cursor.moveToNext()) {
|
||||
events[index++] = new EventImpl(
|
||||
this.db,
|
||||
cursor.getInt(0)
|
||||
);
|
||||
events[index++] = new EventImpl(this.db, cursor.getInt(0));
|
||||
}
|
||||
|
||||
return events;
|
||||
|
@ -125,8 +117,7 @@ public class QueueImpl implements Queue {
|
|||
null
|
||||
);
|
||||
|
||||
if (!Utils.findResult(cursor))
|
||||
return 0;
|
||||
if (!Utils.findResult(cursor)) return 0;
|
||||
|
||||
return cursor.getInt(0);
|
||||
}
|
||||
|
@ -154,11 +145,9 @@ public class QueueImpl implements Queue {
|
|||
@Override
|
||||
public void addEvent(Event event) {
|
||||
synchronized (this.db) {
|
||||
if (event == null)
|
||||
return;
|
||||
if (event == null) return;
|
||||
|
||||
if (this.hasEvent(event))
|
||||
return;
|
||||
if (this.hasEvent(event)) return;
|
||||
|
||||
try {
|
||||
ContentValues cv = new ContentValues();
|
||||
|
@ -174,11 +163,9 @@ public class QueueImpl implements Queue {
|
|||
@Override
|
||||
public void removeEvent(Event event) {
|
||||
synchronized (this.db) {
|
||||
if (event == null)
|
||||
return;
|
||||
if (event == null) return;
|
||||
|
||||
if (this.hasEvent(event))
|
||||
return;
|
||||
if (this.hasEvent(event)) return;
|
||||
|
||||
try {
|
||||
db.delete(
|
||||
|
@ -196,38 +183,7 @@ public class QueueImpl implements Queue {
|
|||
public TagStat[] getGlobalTags() {
|
||||
synchronized (this.db) {
|
||||
Cursor cursor = db.rawQuery(
|
||||
"select" +
|
||||
" tag_id,\n" +
|
||||
" count(*) as cnt\n" +
|
||||
"from (\n" +
|
||||
" select\n" +
|
||||
" event_id,\n" +
|
||||
" tag_id\n" +
|
||||
" from (\n" +
|
||||
" select\n" +
|
||||
" event_tag.event_id as event_id,\n" +
|
||||
" event_tag.tag_id as tag_id\n" +
|
||||
" from (\n" +
|
||||
" select\n" +
|
||||
" event_id\n" +
|
||||
" from\n" +
|
||||
" queue_event\n" +
|
||||
" where\n" +
|
||||
" queue_id = ?\n" +
|
||||
" ) as queue_event_temp\n" +
|
||||
" inner join\n" +
|
||||
" event_tag\n" +
|
||||
" on\n" +
|
||||
" (event_tag.event_id = queue_event_temp.event_id)\n" +
|
||||
" )\n" +
|
||||
" group by\n" +
|
||||
" event_id,\n" +
|
||||
" tag_id\n" +
|
||||
")\n" +
|
||||
"group by\n" +
|
||||
" tag_id\n" +
|
||||
"order by\n" +
|
||||
" cnt desc",
|
||||
"select" + " tag_id,\n" + " count(*) as cnt\n" + "from (\n" + " select\n" + " event_id,\n" + " tag_id\n" + " from (\n" + " select\n" + " event_tag.event_id as event_id,\n" + " event_tag.tag_id as tag_id\n" + " from (\n" + " select\n" + " event_id\n" + " from\n" + " queue_event\n" + " where\n" + " queue_id = ?\n" + " ) as queue_event_temp\n" + " inner join\n" + " event_tag\n" + " on\n" + " (event_tag.event_id = queue_event_temp.event_id)\n" + " )\n" + " group by\n" + " event_id,\n" + " tag_id\n" + ")\n" + "group by\n" + " tag_id\n" + "order by\n" + " cnt desc",
|
||||
new String[] { Integer.toString(this.getId()) }
|
||||
);
|
||||
|
||||
|
@ -242,10 +198,7 @@ public class QueueImpl implements Queue {
|
|||
TagStat tagStat = new TagStat();
|
||||
tags[index++] = tagStat;
|
||||
|
||||
tagStat.tag = new TagImpl(
|
||||
this.db,
|
||||
cursor.getInt(0)
|
||||
);
|
||||
tagStat.tag = new TagImpl(this.db, cursor.getInt(0));
|
||||
tagStat.count = cursor.getInt(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,26 +40,19 @@ public class QueueMakerImpl implements QueueMaker {
|
|||
public Queue getById(int id) {
|
||||
synchronized (this.db) {
|
||||
try {
|
||||
Cursor cursor = db.query(
|
||||
"queue",
|
||||
new String[] { "1" },
|
||||
"id = ?",
|
||||
new String[] { Integer.toString(id) },
|
||||
null,
|
||||
null,
|
||||
null
|
||||
Cursor cursor = db.query("queue",
|
||||
new String[] { "1" },
|
||||
"id = ?",
|
||||
new String[] { Integer.toString(id) },
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
if (Utils.findResult(cursor)) return new QueueImpl(
|
||||
this.db,
|
||||
id
|
||||
);
|
||||
if (Utils.findResult(cursor)) return new QueueImpl(this.db, id);
|
||||
|
||||
} catch (SQLiteException e) {
|
||||
Log.wtf(
|
||||
TAG,
|
||||
e
|
||||
);
|
||||
Log.wtf(TAG, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -71,24 +64,11 @@ public class QueueMakerImpl implements QueueMaker {
|
|||
synchronized (this.db) {
|
||||
try {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(
|
||||
"id",
|
||||
(Integer) null
|
||||
);
|
||||
long rowId = db.insertOrThrow(
|
||||
"queue",
|
||||
null,
|
||||
cv
|
||||
);
|
||||
return new QueueImpl(
|
||||
this.db,
|
||||
(int) rowId
|
||||
);
|
||||
cv.put("id", (Integer) null);
|
||||
long rowId = db.insertOrThrow("queue", null, cv);
|
||||
return new QueueImpl(this.db, (int) rowId);
|
||||
} catch (SQLiteException e) {
|
||||
Log.wtf(
|
||||
TAG,
|
||||
e
|
||||
);
|
||||
Log.wtf(TAG, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -98,15 +78,7 @@ public class QueueMakerImpl implements QueueMaker {
|
|||
@Override
|
||||
public Queue[] list() {
|
||||
synchronized (this.db) {
|
||||
Cursor cursor = db.query(
|
||||
"queue",
|
||||
new String[] { "id" },
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
Cursor cursor = db.query("queue", new String[] { "id" }, null, null, null, null, null);
|
||||
|
||||
if (cursor == null) {
|
||||
return new Queue[0];
|
||||
|
@ -116,10 +88,7 @@ public class QueueMakerImpl implements QueueMaker {
|
|||
|
||||
int index = 0;
|
||||
while (cursor.moveToNext()) {
|
||||
queues[index++] = new QueueImpl(
|
||||
this.db,
|
||||
cursor.getInt(0)
|
||||
);
|
||||
queues[index++] = new QueueImpl(this.db, cursor.getInt(0));
|
||||
}
|
||||
|
||||
return queues;
|
||||
|
@ -133,46 +102,25 @@ public class QueueMakerImpl implements QueueMaker {
|
|||
// Drop events
|
||||
try {
|
||||
for (Event event : queue.getEvents()) {
|
||||
db.delete(
|
||||
"event",
|
||||
"id = ?",
|
||||
new String[] { Integer.toString(event.getId()) }
|
||||
);
|
||||
db.delete("event", "id = ?", new String[] { Integer.toString(event.getId()) });
|
||||
}
|
||||
} catch (SQLiteException e) {
|
||||
Log.wtf(
|
||||
TAG,
|
||||
e
|
||||
);
|
||||
Log.wtf(TAG, e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Drop queue <-> event
|
||||
try {
|
||||
db.delete(
|
||||
"queue_event",
|
||||
"queue_id = ?",
|
||||
new String[] { Integer.toString(queue.getId()) }
|
||||
);
|
||||
db.delete("queue_event", "queue_id = ?", new String[] { Integer.toString(queue.getId()) });
|
||||
} catch (SQLiteException e) {
|
||||
Log.wtf(
|
||||
TAG,
|
||||
e
|
||||
);
|
||||
Log.wtf(TAG, e);
|
||||
}
|
||||
|
||||
// Drop queue
|
||||
try {
|
||||
db.delete(
|
||||
"queue",
|
||||
"id = ?",
|
||||
new String[] { Integer.toString(queue.getId()) }
|
||||
);
|
||||
db.delete("queue", "id = ?", new String[] { Integer.toString(queue.getId()) });
|
||||
} catch (SQLiteException e) {
|
||||
Log.wtf(
|
||||
TAG,
|
||||
e
|
||||
);
|
||||
Log.wtf(TAG, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,33 +94,21 @@ public class EventEditActivity extends AppCompatActivity {
|
|||
// Get Queue ID from Intent
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if (extras == null) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Missing Intent arguments (queue_id)"
|
||||
);
|
||||
Log.e(TAG, "Missing Intent arguments (queue_id)");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
int queue_id = extras.getInt(
|
||||
"queue_id",
|
||||
-1
|
||||
);
|
||||
int queue_id = extras.getInt("queue_id", -1);
|
||||
if (queue_id == -1) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Missing Intent arguments (queue_id)"
|
||||
);
|
||||
Log.e(TAG, "Missing Intent arguments (queue_id)");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
queue = Wrapper.getQueueMaker().getById(queue_id);
|
||||
if (queue == null) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Missing Intent arguments (queue_id)"
|
||||
);
|
||||
Log.e(TAG, "Missing Intent arguments (queue_id)");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
@ -131,10 +119,7 @@ public class EventEditActivity extends AppCompatActivity {
|
|||
// Get Event ID from Intent (optional)
|
||||
extras = getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
int event_id = extras.getInt(
|
||||
"event_id",
|
||||
-1
|
||||
);
|
||||
int event_id = extras.getInt("event_id", -1);
|
||||
if (event_id != -1) {
|
||||
this.event = Wrapper.getEventMaker().getById(event_id);
|
||||
this.eventContainer.timestamp = this.event.getTimestamp();
|
||||
|
@ -148,8 +133,7 @@ public class EventEditActivity extends AppCompatActivity {
|
|||
binding = ActivityEventEditBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
setSupportActionBar(binding.toolbar);
|
||||
getSupportActionBar().setTitle(
|
||||
getSupportActionBar().getTitle() + " / " + (event == null ? "Create" : "Edit") + " Event");
|
||||
getSupportActionBar().setTitle(getSupportActionBar().getTitle() + " / " + (event == null ? "Create" : "Edit") + " Event");
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
|
||||
|
@ -164,18 +148,15 @@ public class EventEditActivity extends AppCompatActivity {
|
|||
// Request focus on click
|
||||
this.binding.eventEditContent.eventEditContainerComment.setOnClickListener((View view) -> {
|
||||
this.binding.eventEditContent.eventEditComment.requestFocus();
|
||||
this.binding.eventEditContent.eventEditComment.setSelection(
|
||||
EventEditActivity.this.binding.eventEditContent.eventEditComment.getText().length());
|
||||
this.binding.eventEditContent.eventEditComment.setSelection(EventEditActivity.this.binding.eventEditContent.eventEditComment.getText().length());
|
||||
});
|
||||
|
||||
/* Timestamp Listeners */
|
||||
|
||||
binding.eventEditContent.eventEditContainerTimestamp.setOnClickListener((View view) -> {
|
||||
Date date;
|
||||
if (this.eventContainer.timestamp != 0)
|
||||
date = new Date(this.eventContainer.timestamp);
|
||||
else
|
||||
date = new Date();
|
||||
if (this.eventContainer.timestamp != 0) date = new Date(this.eventContainer.timestamp);
|
||||
else date = new Date();
|
||||
|
||||
DatePickerDialog datePickerDialog = new DatePickerDialog(
|
||||
view.getContext(),
|
||||
|
@ -184,16 +165,23 @@ public class EventEditActivity extends AppCompatActivity {
|
|||
view.getContext(),
|
||||
(TimePicker timePicker, int hour, int minute) -> {
|
||||
Date newDate = new Date();
|
||||
newDate.setYear(year - 1900);
|
||||
newDate.setMonth(month);
|
||||
newDate.setDate(day);
|
||||
newDate.setHours(hour);
|
||||
newDate.setMinutes(minute);
|
||||
newDate.setSeconds(0);
|
||||
newDate.setYear(
|
||||
year - 1900);
|
||||
newDate.setMonth(
|
||||
month);
|
||||
newDate.setDate(
|
||||
day);
|
||||
newDate.setHours(
|
||||
hour);
|
||||
newDate.setMinutes(
|
||||
minute);
|
||||
newDate.setSeconds(
|
||||
0);
|
||||
|
||||
this.eventContainer.timestamp = newDate.getTime();
|
||||
binding.eventEditContent.eventEditTimestamp.setText(
|
||||
Utils.formatTs(this.eventContainer.timestamp));
|
||||
Utils.formatTs(
|
||||
this.eventContainer.timestamp));
|
||||
},
|
||||
date.getHours(),
|
||||
date.getMinutes(),
|
||||
|
@ -210,16 +198,10 @@ public class EventEditActivity extends AppCompatActivity {
|
|||
|
||||
/* FAB Listeners */
|
||||
binding.fab.setOnLongClickListener((View view) -> {
|
||||
Snackbar.make(
|
||||
view,
|
||||
"Save Event",
|
||||
Snackbar.LENGTH_LONG
|
||||
)
|
||||
.setAnchorView(R.id.fab)
|
||||
.setAction(
|
||||
"Action",
|
||||
null
|
||||
).show();
|
||||
Snackbar.make(view, "Save Event", Snackbar.LENGTH_LONG).setAnchorView(R.id.fab).setAction(
|
||||
"Action",
|
||||
null
|
||||
).show();
|
||||
|
||||
return true;
|
||||
});
|
||||
|
@ -227,8 +209,7 @@ public class EventEditActivity extends AppCompatActivity {
|
|||
// Finalize values
|
||||
this.eventContainer.comment = this.binding.eventEditContent.eventEditComment.getText().toString().trim();
|
||||
|
||||
String[] tags = EventEditActivity.this.binding.eventEditContent.eventEditTags.getText().toString().split(
|
||||
",");
|
||||
String[] tags = EventEditActivity.this.binding.eventEditContent.eventEditTags.getText().toString().split(",");
|
||||
tags = Utils.orderedDeduplicateIgnoreCaseAndTrim(tags);
|
||||
this.eventContainer.tags.clear();
|
||||
for (String tag : tags) {
|
||||
|
@ -237,16 +218,12 @@ public class EventEditActivity extends AppCompatActivity {
|
|||
|
||||
// Fill event
|
||||
boolean hasEvent = this.event != null;
|
||||
if (this.event == null)
|
||||
this.event = Wrapper.getEventMaker().create();
|
||||
if (this.event == null) this.event = Wrapper.getEventMaker().create();
|
||||
|
||||
this.event.setTimestamp(this.eventContainer.timestamp);
|
||||
this.event.removeTags();
|
||||
for (String tag : this.eventContainer.tags) {
|
||||
this.event.addTag(Wrapper.getTagMaker().getOrCreateInQueue(
|
||||
this.queue,
|
||||
tag
|
||||
));
|
||||
this.event.addTag(Wrapper.getTagMaker().getOrCreateInQueue(this.queue, tag));
|
||||
}
|
||||
this.event.setComment(this.eventContainer.comment);
|
||||
|
||||
|
@ -270,32 +247,22 @@ public class EventEditActivity extends AppCompatActivity {
|
|||
this.binding.eventEditContent.eventEditTags.setThreshold(1);
|
||||
this.binding.eventEditContent.eventEditTags.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
|
||||
this.binding.eventEditContent.eventEditTags.setOnItemClickListener((parent, view, position, id) -> {
|
||||
String[] tags = EventEditActivity.this.binding.eventEditContent.eventEditTags.getText().toString().split(
|
||||
",");
|
||||
String[] tags = EventEditActivity.this.binding.eventEditContent.eventEditTags.getText().toString().split(",");
|
||||
tags = Utils.orderedDeduplicateIgnoreCaseAndTrim(tags);
|
||||
|
||||
EventEditActivity.this.binding.eventEditContent.eventEditTags.setText(String.join(
|
||||
", ",
|
||||
tags
|
||||
));
|
||||
EventEditActivity.this.binding.eventEditContent.eventEditTags.setSelection(
|
||||
EventEditActivity.this.binding.eventEditContent.eventEditTags.getText().length());
|
||||
EventEditActivity.this.binding.eventEditContent.eventEditTags.setText(String.join(", ", tags));
|
||||
EventEditActivity.this.binding.eventEditContent.eventEditTags.setSelection(EventEditActivity.this.binding.eventEditContent.eventEditTags.getText().length());
|
||||
});
|
||||
|
||||
// Request focus on click
|
||||
this.binding.eventEditContent.eventEditContainerTags.setOnClickListener((View view) -> {
|
||||
this.binding.eventEditContent.eventEditTags.requestFocus();
|
||||
this.binding.eventEditContent.eventEditTags.setSelection(
|
||||
EventEditActivity.this.binding.eventEditContent.eventEditTags.getText().length());
|
||||
this.binding.eventEditContent.eventEditTags.setSelection(EventEditActivity.this.binding.eventEditContent.eventEditTags.getText().length());
|
||||
});
|
||||
|
||||
// Fill
|
||||
this.binding.eventEditContent.eventEditTags.setText(String.join(
|
||||
", ",
|
||||
this.eventContainer.tags
|
||||
));
|
||||
this.binding.eventEditContent.eventEditTags.setSelection(
|
||||
EventEditActivity.this.binding.eventEditContent.eventEditTags.getText().length());
|
||||
this.binding.eventEditContent.eventEditTags.setText(String.join(", ", this.eventContainer.tags));
|
||||
this.binding.eventEditContent.eventEditTags.setSelection(EventEditActivity.this.binding.eventEditContent.eventEditTags.getText().length());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -63,33 +63,21 @@ public class EventListActivity extends AppCompatActivity {
|
|||
// Get Queue ID from Intent
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if (extras == null) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Missing Intent arguments (queue_id)"
|
||||
);
|
||||
Log.e(TAG, "Missing Intent arguments (queue_id)");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
int queue_id = extras.getInt(
|
||||
"queue_id",
|
||||
-1
|
||||
);
|
||||
int queue_id = extras.getInt("queue_id", -1);
|
||||
if (queue_id == -1) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Missing Intent arguments (queue_id)"
|
||||
);
|
||||
Log.e(TAG, "Missing Intent arguments (queue_id)");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
queue = Wrapper.getQueueMaker().getById(queue_id);
|
||||
if (queue == null) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Missing Intent arguments (queue_id)"
|
||||
);
|
||||
Log.e(TAG, "Missing Intent arguments (queue_id)");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
@ -128,30 +116,17 @@ public class EventListActivity extends AppCompatActivity {
|
|||
|
||||
/* FAB Listeners */
|
||||
binding.fab.setOnLongClickListener((View view) -> {
|
||||
Snackbar.make(
|
||||
view,
|
||||
"Create Event",
|
||||
Snackbar.LENGTH_LONG
|
||||
)
|
||||
.setAnchorView(R.id.fab)
|
||||
.setAction(
|
||||
"Action",
|
||||
null
|
||||
).show();
|
||||
Snackbar.make(view, "Create Event", Snackbar.LENGTH_LONG).setAnchorView(R.id.fab).setAction("Action",
|
||||
null
|
||||
).show();
|
||||
|
||||
return true;
|
||||
});
|
||||
binding.fab.setOnClickListener(view -> {
|
||||
Bundle extra = new Bundle();
|
||||
extra.putInt(
|
||||
"queue_id",
|
||||
this.queue.getId()
|
||||
);
|
||||
extra.putInt("queue_id", this.queue.getId());
|
||||
|
||||
Intent intent = new Intent(
|
||||
view.getContext(),
|
||||
EventEditActivity.class
|
||||
);
|
||||
Intent intent = new Intent(view.getContext(), EventEditActivity.class);
|
||||
intent.putExtras(extra);
|
||||
|
||||
view.getContext().startActivity(intent);
|
||||
|
|
|
@ -18,7 +18,10 @@ package art.pegasko.yeeemp.ui.activity;
|
|||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
|
@ -57,13 +60,7 @@ class EventRecyclerViewAdapter extends RecyclerView.Adapter<EventRecyclerViewAda
|
|||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||
View view = (
|
||||
LayoutInflater
|
||||
.from(viewGroup.getContext())
|
||||
.inflate(
|
||||
R.layout.event_list_item,
|
||||
viewGroup,
|
||||
false
|
||||
)
|
||||
LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.event_list_item, viewGroup, false)
|
||||
);
|
||||
|
||||
return new ViewHolder(view);
|
||||
|
@ -75,13 +72,11 @@ class EventRecyclerViewAdapter extends RecyclerView.Adapter<EventRecyclerViewAda
|
|||
Tag[] tags = this.events[position].getTags();
|
||||
for (Tag tag : tags) {
|
||||
TextView tagView = (TextView) (
|
||||
LayoutInflater
|
||||
.from(viewHolder.getBinding().getRoot().getContext())
|
||||
.inflate(
|
||||
R.layout.event_list_item_tag,
|
||||
null,
|
||||
false
|
||||
)
|
||||
LayoutInflater.from(viewHolder.getBinding().getRoot().getContext()).inflate(
|
||||
R.layout.event_list_item_tag,
|
||||
null,
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
tagView.setText(tag.getName());
|
||||
|
@ -100,33 +95,23 @@ class EventRecyclerViewAdapter extends RecyclerView.Adapter<EventRecyclerViewAda
|
|||
}
|
||||
|
||||
viewHolder.getBinding().eventListItemItem.setOnLongClickListener((View view) -> {
|
||||
PopupMenu popupMenu = new PopupMenu(
|
||||
view.getContext(),
|
||||
viewHolder.getBinding().eventListItemItem
|
||||
);
|
||||
popupMenu.getMenuInflater().inflate(
|
||||
R.menu.event_list_item_action_menu,
|
||||
popupMenu.getMenu()
|
||||
);
|
||||
PopupMenu popupMenu = new PopupMenu(view.getContext(), viewHolder.getBinding().eventListItemItem);
|
||||
popupMenu.getMenuInflater().inflate(R.menu.event_list_item_action_menu, popupMenu.getMenu());
|
||||
popupMenu.setOnMenuItemClickListener((MenuItem menuItem) -> {
|
||||
if (menuItem.getItemId() == R.id.event_list_item_action_menu_delete) {
|
||||
new AlertDialog.Builder(view.getContext())
|
||||
.setTitle("Delete event")
|
||||
.setMessage("Are you sure you want to delete this event?")
|
||||
.setPositiveButton(
|
||||
android.R.string.yes,
|
||||
(dialog, which) -> {
|
||||
Wrapper.getEventMaker().delete(events[position]);
|
||||
new AlertDialog.Builder(view.getContext()).setTitle("Delete event").setMessage(
|
||||
"Are you sure you want to delete this event?").setPositiveButton(
|
||||
android.R.string.yes,
|
||||
(dialog, which) -> {
|
||||
Wrapper.getEventMaker().delete(
|
||||
events[position]);
|
||||
|
||||
reloadItems();
|
||||
}
|
||||
)
|
||||
.setNegativeButton(
|
||||
android.R.string.no,
|
||||
null
|
||||
)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show();
|
||||
reloadItems();
|
||||
}
|
||||
).setNegativeButton(
|
||||
android.R.string.no,
|
||||
null
|
||||
).setIcon(android.R.drawable.ic_dialog_alert).show();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
@ -137,19 +122,10 @@ class EventRecyclerViewAdapter extends RecyclerView.Adapter<EventRecyclerViewAda
|
|||
});
|
||||
viewHolder.getBinding().eventListItemItem.setOnClickListener((View view) -> {
|
||||
Bundle extra = new Bundle();
|
||||
extra.putInt(
|
||||
"event_id",
|
||||
this.events[position].getId()
|
||||
);
|
||||
extra.putInt(
|
||||
"queue_id",
|
||||
this.queue.getId()
|
||||
);
|
||||
extra.putInt("event_id", this.events[position].getId());
|
||||
extra.putInt("queue_id", this.queue.getId());
|
||||
|
||||
Intent intent = new Intent(
|
||||
view.getContext(),
|
||||
EventEditActivity.class
|
||||
);
|
||||
Intent intent = new Intent(view.getContext(), EventEditActivity.class);
|
||||
intent.putExtras(extra);
|
||||
|
||||
view.getContext().startActivity(intent);
|
||||
|
@ -175,7 +151,12 @@ class EventRecyclerViewAdapter extends RecyclerView.Adapter<EventRecyclerViewAda
|
|||
}
|
||||
|
||||
public void reloadItems() {
|
||||
this.events = this.queue.getEvents();
|
||||
this.notifyDataSetChanged();
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
this.events = this.queue.getEvents();
|
||||
handler.post(() -> {
|
||||
this.notifyDataSetChanged();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,11 +68,7 @@ public class QueueListActivity extends AppCompatActivity {
|
|||
|
||||
/* FAB Listeners */
|
||||
binding.fab.setOnLongClickListener((View view) -> {
|
||||
Snackbar.make(
|
||||
view,
|
||||
"Create Queue",
|
||||
Snackbar.LENGTH_LONG
|
||||
).setAnchorView(R.id.fab).setAction(
|
||||
Snackbar.make(view, "Create Queue", Snackbar.LENGTH_LONG).setAnchorView(R.id.fab).setAction(
|
||||
"Action",
|
||||
null
|
||||
).show();
|
||||
|
|
|
@ -48,13 +48,7 @@ class QueueRecyclerViewAdapter extends RecyclerView.Adapter<QueueRecyclerViewAda
|
|||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||
View view = (
|
||||
LayoutInflater
|
||||
.from(viewGroup.getContext())
|
||||
.inflate(
|
||||
R.layout.queue_list_item,
|
||||
viewGroup,
|
||||
false
|
||||
)
|
||||
LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.queue_list_item, viewGroup, false)
|
||||
);
|
||||
|
||||
return new ViewHolder(view);
|
||||
|
@ -65,33 +59,20 @@ class QueueRecyclerViewAdapter extends RecyclerView.Adapter<QueueRecyclerViewAda
|
|||
viewHolder.getBinding().queueListItemTitle.setText(queues[position].getName());
|
||||
|
||||
viewHolder.getBinding().queueListItemItem.setOnLongClickListener((View view) -> {
|
||||
PopupMenu popupMenu = new PopupMenu(
|
||||
view.getContext(),
|
||||
viewHolder.getBinding().queueListItemItem
|
||||
);
|
||||
popupMenu.getMenuInflater().inflate(
|
||||
R.menu.queue_list_item_action_menu,
|
||||
popupMenu.getMenu()
|
||||
);
|
||||
PopupMenu popupMenu = new PopupMenu(view.getContext(), viewHolder.getBinding().queueListItemItem);
|
||||
popupMenu.getMenuInflater().inflate(R.menu.queue_list_item_action_menu, popupMenu.getMenu());
|
||||
popupMenu.setOnMenuItemClickListener((MenuItem menuItem) -> {
|
||||
if (menuItem.getItemId() == R.id.queue_list_item_action_menu_delete) {
|
||||
new AlertDialog.Builder(view.getContext())
|
||||
.setTitle("Delete queue")
|
||||
.setMessage("Are you sure you want to delete this queue?")
|
||||
.setPositiveButton(
|
||||
android.R.string.yes,
|
||||
(dialog, which) -> {
|
||||
Wrapper.getQueueMaker().delete(queues[position]);
|
||||
new AlertDialog.Builder(view.getContext()).setTitle("Delete queue").setMessage(
|
||||
"Are you sure you want to delete this queue?").setPositiveButton(
|
||||
android.R.string.yes,
|
||||
(dialog, which) -> {
|
||||
Wrapper.getQueueMaker().delete(
|
||||
queues[position]);
|
||||
|
||||
reloadItems();
|
||||
}
|
||||
)
|
||||
.setNegativeButton(
|
||||
android.R.string.no,
|
||||
null
|
||||
)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show();
|
||||
reloadItems();
|
||||
}
|
||||
).setNegativeButton(android.R.string.no, null).setIcon(android.R.drawable.ic_dialog_alert).show();
|
||||
} else if (menuItem.getItemId() == R.id.queue_list_item_action_menu_rename) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
|
||||
builder.setTitle("Title");
|
||||
|
@ -101,19 +82,13 @@ class QueueRecyclerViewAdapter extends RecyclerView.Adapter<QueueRecyclerViewAda
|
|||
input.setText(queues[position].getName());
|
||||
builder.setView(input);
|
||||
|
||||
builder.setPositiveButton(
|
||||
"OK",
|
||||
(dialog, which) -> {
|
||||
String name = input.getText().toString().trim();
|
||||
queues[position].setName(name);
|
||||
builder.setPositiveButton("OK", (dialog, which) -> {
|
||||
String name = input.getText().toString().trim();
|
||||
queues[position].setName(name);
|
||||
|
||||
reloadItems();
|
||||
}
|
||||
);
|
||||
builder.setNegativeButton(
|
||||
"Cancel",
|
||||
(dialog, which) -> dialog.cancel()
|
||||
);
|
||||
reloadItems();
|
||||
});
|
||||
builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel());
|
||||
|
||||
builder.show();
|
||||
}
|
||||
|
@ -126,15 +101,9 @@ class QueueRecyclerViewAdapter extends RecyclerView.Adapter<QueueRecyclerViewAda
|
|||
});
|
||||
viewHolder.getBinding().queueListItemItem.setOnClickListener((View view) -> {
|
||||
Bundle extra = new Bundle();
|
||||
extra.putInt(
|
||||
"queue_id",
|
||||
queues[position].getId()
|
||||
);
|
||||
extra.putInt("queue_id", queues[position].getId());
|
||||
|
||||
Intent intent = new Intent(
|
||||
view.getContext(),
|
||||
EventListActivity.class
|
||||
);
|
||||
Intent intent = new Intent(view.getContext(), EventListActivity.class);
|
||||
intent.putExtras(extra);
|
||||
|
||||
view.getContext().startActivity(intent);
|
||||
|
@ -143,10 +112,7 @@ class QueueRecyclerViewAdapter extends RecyclerView.Adapter<QueueRecyclerViewAda
|
|||
viewHolder.getBinding().queueListItemStats.setText(Integer.toString(queues[position].getEventCount()));
|
||||
|
||||
viewHolder.getBinding().queueListItemPlus.setOnClickListener((View view) -> {
|
||||
Intent intent = new Intent(
|
||||
view.getContext(),
|
||||
EventEditActivity.class
|
||||
);
|
||||
Intent intent = new Intent(view.getContext(), EventEditActivity.class);
|
||||
view.getContext().startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue