diff --git a/app/src/main/java/org/houxg/leamonax/ui/AboutActivity.java b/app/src/main/java/org/houxg/leamonax/ui/AboutActivity.java index 9c7c3b1..1da66c4 100644 --- a/app/src/main/java/org/houxg/leamonax/ui/AboutActivity.java +++ b/app/src/main/java/org/houxg/leamonax/ui/AboutActivity.java @@ -2,18 +2,39 @@ package org.houxg.leamonax.ui; import android.os.Bundle; import android.support.v7.widget.Toolbar; +import android.view.View; import android.widget.TextView; +import com.raizlabs.android.dbflow.config.FlowManager; +import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; +import com.raizlabs.android.dbflow.structure.database.transaction.Transaction; + +import org.bson.types.ObjectId; import org.houxg.leamonax.BuildConfig; import org.houxg.leamonax.R; +import org.houxg.leamonax.database.AppDataBase; +import org.houxg.leamonax.model.Note; +import org.houxg.leamonax.service.AccountService; +import org.houxg.leamonax.utils.TestUtils; + +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; +import rx.Observable; +import rx.Subscriber; +import rx.schedulers.Schedulers; public class AboutActivity extends BaseActivity { @BindView(R.id.tv_version) TextView mVersionTv; + @BindView(R.id.ll_debug) + View mDebugPanel; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -23,5 +44,38 @@ public class AboutActivity extends BaseActivity { ButterKnife.bind(this); mVersionTv.setText(BuildConfig.VERSION_NAME); + mDebugPanel.setVisibility(BuildConfig.DEBUG ? View.VISIBLE : View.GONE); } + + @OnClick(R.id.ll_generate_random_note) + void clickedVersion() { + Observable.create( + new Observable.OnSubscribe() { + @Override + public void call(Subscriber subscriber) { + String userId = AccountService.getCurrent().getUserId(); + SecureRandom random = new SecureRandom(); + String notebookId = new ObjectId().toString(); + List notes = new ArrayList<>(8000); + for (int i = 0; i < 5000; i++) { + Note note = TestUtils.randomNote(random, notebookId, userId); + notes.add(note); + } + ProcessModelTransaction processModelTransaction = new ProcessModelTransaction.Builder<>( + new ProcessModelTransaction.ProcessModel() { + @Override + public void processModel(Note note) { + note.save(); + } + }) + .addAll(notes) + .build(); + Transaction transaction = FlowManager.getDatabase(AppDataBase.class).beginTransactionAsync(processModelTransaction).build(); + transaction.execute(); + } + }).subscribeOn(Schedulers.io()) + .subscribe(); + } + + } diff --git a/app/src/main/java/org/houxg/leamonax/utils/TestUtils.java b/app/src/main/java/org/houxg/leamonax/utils/TestUtils.java new file mode 100644 index 0000000..a3bd4c7 --- /dev/null +++ b/app/src/main/java/org/houxg/leamonax/utils/TestUtils.java @@ -0,0 +1,52 @@ +package org.houxg.leamonax.utils; + + +import org.houxg.leamonax.model.Note; + +import java.security.SecureRandom; + +public class TestUtils { + + private static final char[] CHARS = "abcdefghijklmnopqrstuvwxyz".toCharArray(); + + public static Note randomNote(SecureRandom random, String notebookId, String userId) { + Note note = new Note(); + note.setTitle(randomSentence(random)); + note.setContent(randomParagraph(random)); + note.setUserId(userId); + note.setNoteBookId(notebookId); + return note; + } + + public static String randomWord(SecureRandom random) { + int len = random.nextInt(10) + 1; + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < len; i++) { + builder.append(CHARS[random.nextInt(CHARS.length)]); + } + return builder.toString(); + } + + public static String randomSentence(SecureRandom random) { + int len = random.nextInt(20) + 2; + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < len; i++) { + builder.append(randomWord(random)); + builder.append(' '); + } + builder.deleteCharAt(builder.length() - 1); + return builder.toString(); + } + + public static String randomParagraph(SecureRandom random) { + int len = random.nextInt(10) + 2; + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < len; i++) { + builder.append(randomSentence(random)); + builder.append(random.nextBoolean() ? ',' : "."); + builder.append(' '); + } + builder.deleteCharAt(builder.length() - 1); + return builder.toString(); + } +} diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 932fbfb..cecbfa5 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -105,6 +105,28 @@ + + + + + + + + + + + +