mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Address review comments
This commit is contained in:
@@ -21,8 +21,8 @@ public class TestDataActivity extends BriarActivity {
|
||||
@Inject
|
||||
TestDataCreator testDataCreator;
|
||||
|
||||
private TextView[] textviews = new TextView[5];
|
||||
private SeekBar[] seekbars = new SeekBar[5];
|
||||
private TextView[] textViews = new TextView[5];
|
||||
private SeekBar[] seekBars = new SeekBar[5];
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
@@ -35,20 +35,20 @@ public class TestDataActivity extends BriarActivity {
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_test_data);
|
||||
textviews[0] = findViewById(R.id.textViewContactsSb);
|
||||
textviews[1] = findViewById(R.id.textViewMessagesSb);
|
||||
textviews[2] = findViewById(R.id.TextViewBlogPostsSb);
|
||||
textviews[3] = findViewById(R.id.TextViewForumsSb);
|
||||
textviews[4] = findViewById(R.id.TextViewForumMessagesSb);
|
||||
seekbars[0] = findViewById(R.id.seekBarContacts);
|
||||
seekbars[1] = findViewById(R.id.seekBarMessages);
|
||||
seekbars[2] = findViewById(R.id.seekBarBlogPosts);
|
||||
seekbars[3] = findViewById(R.id.seekBarForums);
|
||||
seekbars[4] = findViewById(R.id.seekBarForumMessages);
|
||||
textViews[0] = findViewById(R.id.textViewContactsSb);
|
||||
textViews[1] = findViewById(R.id.textViewMessagesSb);
|
||||
textViews[2] = findViewById(R.id.TextViewBlogPostsSb);
|
||||
textViews[3] = findViewById(R.id.TextViewForumsSb);
|
||||
textViews[4] = findViewById(R.id.TextViewForumMessagesSb);
|
||||
seekBars[0] = findViewById(R.id.seekBarContacts);
|
||||
seekBars[1] = findViewById(R.id.seekBarMessages);
|
||||
seekBars[2] = findViewById(R.id.seekBarBlogPosts);
|
||||
seekBars[3] = findViewById(R.id.seekBarForums);
|
||||
seekBars[4] = findViewById(R.id.seekBarForumMessages);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final TextView textView = textviews[i];
|
||||
seekbars[i].setOnSeekBarChangeListener(
|
||||
final TextView textView = textViews[i];
|
||||
seekBars[i].setOnSeekBarChangeListener(
|
||||
new OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar,
|
||||
@@ -75,9 +75,9 @@ public class TestDataActivity extends BriarActivity {
|
||||
}
|
||||
|
||||
private void createTestData() {
|
||||
testDataCreator.createTestData(seekbars[0].getProgress(),
|
||||
seekbars[1].getProgress(), seekbars[2].getProgress(),
|
||||
seekbars[3].getProgress(), seekbars[4].getProgress());
|
||||
testDataCreator.createTestData(seekBars[0].getProgress(),
|
||||
seekBars[1].getProgress(), seekBars[2].getProgress(),
|
||||
seekBars[3].getProgress(), seekBars[4].getProgress());
|
||||
Intent intent = new Intent(this, NavDrawerActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
|
||||
@@ -86,12 +86,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
private final Random random = new Random();
|
||||
private final Map<Contact, LocalAuthor> localAuthors = new HashMap<>();
|
||||
|
||||
private int numContacts = 20;
|
||||
private int numPrivateMsgs = 15;
|
||||
private int numBlogPosts = 30;
|
||||
private int numForums = 3;
|
||||
private int numForumPosts = 30;
|
||||
|
||||
@Inject
|
||||
TestDataCreatorImpl(AuthorFactory authorFactory, Clock clock,
|
||||
PrivateMessageFactory privateMessageFactory,
|
||||
@@ -119,20 +113,12 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
this.ioExecutor = ioExecutor;
|
||||
}
|
||||
|
||||
public void createTestData(int numContacts, int numPrivateMsgs, int numBlogPosts, int numForums,
|
||||
int numForumPosts){
|
||||
this.numContacts = numContacts;
|
||||
this.numPrivateMsgs = numPrivateMsgs;
|
||||
this.numBlogPosts = numBlogPosts;
|
||||
this.numForums = numForums;
|
||||
this.numForumPosts = numForumPosts;
|
||||
createTestData();
|
||||
}
|
||||
|
||||
public void createTestData() {
|
||||
public void createTestData(int numContacts, int numPrivateMsgs,
|
||||
int numBlogPosts, int numForums, int numForumPosts) {
|
||||
ioExecutor.execute(() -> {
|
||||
try {
|
||||
createTestDataOnDbExecutor();
|
||||
createTestDataOnDbExecutor(numContacts, numPrivateMsgs,
|
||||
numBlogPosts, numForums, numForumPosts);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, "Creating test data failed", e);
|
||||
@@ -140,19 +126,25 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
});
|
||||
}
|
||||
|
||||
public void createTestData() {
|
||||
createTestData(20, 15, 30, 3, 30);
|
||||
}
|
||||
|
||||
@IoExecutor
|
||||
private void createTestDataOnDbExecutor() throws DbException {
|
||||
List<Contact> contacts = createContacts();
|
||||
createPrivateMessages(contacts);
|
||||
createBlogPosts(contacts);
|
||||
List<Forum> forums = createForums(contacts);
|
||||
private void createTestDataOnDbExecutor(int numContacts, int numPrivateMsgs,
|
||||
int numBlogPosts, int numForums, int numForumPosts)
|
||||
throws DbException {
|
||||
List<Contact> contacts = createContacts(numContacts);
|
||||
createPrivateMessages(contacts, numPrivateMsgs);
|
||||
createBlogPosts(contacts, numBlogPosts);
|
||||
List<Forum> forums = createForums(contacts, numForums, numForumPosts);
|
||||
|
||||
for (Forum forum : forums) {
|
||||
createRandomForumPosts(forum, contacts);
|
||||
createRandomForumPosts(forum, contacts, numForumPosts);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Contact> createContacts() throws DbException {
|
||||
private List<Contact> createContacts(int numContacts) throws DbException {
|
||||
List<Contact> contacts = new ArrayList<>(numContacts);
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
for (int i = 0; i < numContacts; i++) {
|
||||
@@ -281,7 +273,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void createPrivateMessages(List<Contact> contacts)
|
||||
private void createPrivateMessages(List<Contact> contacts,
|
||||
int numPrivateMsgs)
|
||||
throws DbException {
|
||||
for (Contact contact : contacts) {
|
||||
Group group = messagingManager.getContactGroup(contact);
|
||||
@@ -323,7 +316,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
}
|
||||
|
||||
private void createBlogPosts(List<Contact> contacts)
|
||||
private void createBlogPosts(List<Contact> contacts, int numBlogPosts)
|
||||
throws DbException {
|
||||
for (int i = 0; i < numBlogPosts; i++) {
|
||||
Contact contact = contacts.get(random.nextInt(contacts.size()));
|
||||
@@ -349,7 +342,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
}
|
||||
|
||||
private List<Forum> createForums(List<Contact> contacts)
|
||||
private List<Forum> createForums(List<Contact> contacts, int numForums,
|
||||
int numForumPosts)
|
||||
throws DbException {
|
||||
List<Forum> forums = new ArrayList<>(numForums);
|
||||
for (int i = 0; i < numForums; i++) {
|
||||
@@ -377,7 +371,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
return forums;
|
||||
}
|
||||
|
||||
private void createRandomForumPosts(Forum forum, List<Contact> contacts)
|
||||
private void createRandomForumPosts(Forum forum, List<Contact> contacts,
|
||||
int numForumPosts)
|
||||
throws DbException {
|
||||
List<ForumPost> posts = new ArrayList<>();
|
||||
for (int i = 0; i < numForumPosts; i++) {
|
||||
|
||||
Reference in New Issue
Block a user