mirror of
https://github.com/leanote/leanote-android.git
synced 2025-10-15 06:40:58 +00:00
support generate random notes for debugging
This commit is contained in:
@@ -2,18 +2,39 @@ package org.houxg.leamonax.ui;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
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.BuildConfig;
|
||||||
import org.houxg.leamonax.R;
|
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.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnClick;
|
||||||
|
import rx.Observable;
|
||||||
|
import rx.Subscriber;
|
||||||
|
import rx.schedulers.Schedulers;
|
||||||
|
|
||||||
public class AboutActivity extends BaseActivity {
|
public class AboutActivity extends BaseActivity {
|
||||||
|
|
||||||
@BindView(R.id.tv_version)
|
@BindView(R.id.tv_version)
|
||||||
TextView mVersionTv;
|
TextView mVersionTv;
|
||||||
|
@BindView(R.id.ll_debug)
|
||||||
|
View mDebugPanel;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -23,5 +44,38 @@ public class AboutActivity extends BaseActivity {
|
|||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
mVersionTv.setText(BuildConfig.VERSION_NAME);
|
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<Void>() {
|
||||||
|
@Override
|
||||||
|
public void call(Subscriber<? super Void> subscriber) {
|
||||||
|
String userId = AccountService.getCurrent().getUserId();
|
||||||
|
SecureRandom random = new SecureRandom();
|
||||||
|
String notebookId = new ObjectId().toString();
|
||||||
|
List<Note> notes = new ArrayList<>(8000);
|
||||||
|
for (int i = 0; i < 5000; i++) {
|
||||||
|
Note note = TestUtils.randomNote(random, notebookId, userId);
|
||||||
|
notes.add(note);
|
||||||
|
}
|
||||||
|
ProcessModelTransaction<Note> processModelTransaction = new ProcessModelTransaction.Builder<>(
|
||||||
|
new ProcessModelTransaction.ProcessModel<Note>() {
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
52
app/src/main/java/org/houxg/leamonax/utils/TestUtils.java
Normal file
52
app/src/main/java/org/houxg/leamonax/utils/TestUtils.java
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
@@ -105,6 +105,28 @@
|
|||||||
|
|
||||||
<include layout="@layout/divider" />
|
<include layout="@layout/divider" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/ll_debug"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/ll_generate_random_note"
|
||||||
|
style="@style/SettingsPanel"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/SettingsSecondaryText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Generate random note" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<include layout="@layout/divider" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Reference in New Issue
Block a user