Skip to content

Commit

Permalink
feat: manage data in clipboard / draft / collection
Browse files Browse the repository at this point in the history
  • Loading branch information
tumuyan authored and Bambooin committed Aug 18, 2022
1 parent 0058e89 commit 2055637
Show file tree
Hide file tree
Showing 19 changed files with 747 additions and 14 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>

<activity
android:name=".ui.main.LiquidKeyboardActivity"
android:parentActivityName=".ui.main.PrefMainActivity"
/>
<!-- All activities must be declared above <activity-alias> tag -->
</application>
</manifest>
11 changes: 9 additions & 2 deletions app/src/main/assets/rime/trime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ liquid_keyboard:
single_width: 60 #single类型的按键宽度
vertical_gap: 1 #纵向按键间隙
margin_x: 0.5 #左右按键间隙的1/2
keyboards: [emoji, math, ascii, cn, history, clipboard, draft, tabs, exit, candidate, list, ids , table, symbol, unit, new, jp, pinyin, grease, rusa, korea, lation, yinbiao, exit] #tab列表
keyboards: [emoji, math, ascii, cn, history, clipboard, collection, draft, tabs, exit, candidate, list, ids , table, symbol, unit, new, jp, pinyin, grease, rusa, korea, lation, yinbiao, yanwenzi, exit] #tab列表
exit:
name: 返回
type: NO_KEY
Expand All @@ -712,10 +712,13 @@ liquid_keyboard:
type: HISTORY
emoji:
type: SINGLE
keys: "🙂😂🤣😆🙃😅🙈🙉🙊☹😑😄🤐😨😱🌚🌝🤔❤💔🌹💣👌👍😣😥😮🙄😏😕😯😪😫😴😌🤑😉😋😎😍😘😚😛😜😝😒😓😔😲😷🤒😇🤓🤗🤕🙁😖😞😟😤😢😭😦😧😨😩😬😰😳😵😡😠☝✌🖕👎🙏🤘👏💪💋☘🍀🌸☕🍵🍺🍻🍦🍬🍚🍜🍲🍖🎂💤"
keys: "🙂😂🤣😆🙃😅🥺🙈🙉🙊☹😑😄🤐😨😱🌚🌝🤔❤💔🌹💣👌👍😣😥😮🙄😏😕😯😪😫😴😌🤑😉😋😎😍😘😚😛😜😝😒😓😔😲😷🤒😇🤓🤗🤕🙁😖😞😟😤😢😭😦😧😨😩😬😰😳😵😡😠☝✌🖕👎🙏🤘👏💪💋☘🍀🌸☕🍵🍺🍻🍦🍬🍚🍜🍲🍖🎂💤"
clipboard:
type: CLIPBOARD
name: 剪贴
collection:
type: COLLECTION
name: 收藏
draft:
type: DRAFT
name: 草稿
Expand Down Expand Up @@ -792,6 +795,10 @@ liquid_keyboard:
type: SINGLE
name: "音标"
keys: ["a:", "ɔ:", "ɜː", "i:", "u:", "ʌ", "ɒ", "ə", "ɪ", "ʊ", "e", "æ", "eɪ", "aɪ", "ɔɪ", "ɪə", "eə", "ʊə", "əʊ", "aʊ", "p", "t", "k", "f", "θ", "s", "b", "d", "g", "v", "ð", "z", "ʃ", "h", "ts", "tʃ", "j", "tr", "ʒ", "r", "dz", "dʒ", "dr", "w", "m", "n", "ŋ", "l"]
yanwenzi:
type: VAR_LENGTH
name: "颜文字"
keys: ["⎛⎝≥⏝⏝≤⎠⎞", "ɔ:", "ɜː", "i:", "u:", "ʌ", "ɒ", "ə", "ɪ", "ʊ", "e", "æ", "eɪ", "aɪ", "ɔɪ", "ɪə", "eə", "ʊə", "əʊ", "aʊ", "p", "t", "k", "f", "θ", "s", "b", "d", "g", "v", "ð", "z", "ʃ", "h", "ts", "tʃ", "j", "tr", "ʒ", "r", "dz", "dʒ", "dr", "w", "m", "n", "ŋ", "l"]

This comment has been minimized.

Copy link
@shitlime

shitlime Jul 28, 2023

Contributor

这个颜文字键盘内容不对吧

ascii:
type: SINGLE
name: 英文
Expand Down
92 changes: 92 additions & 0 deletions app/src/main/java/com/osfans/trime/data/db/CollectionDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.osfans.trime.data.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import androidx.annotation.NonNull;
import com.osfans.trime.ime.core.Trime;
import com.osfans.trime.ime.symbol.SimpleKeyBean;
import java.util.ArrayList;
import java.util.List;
import timber.log.Timber;

public class CollectionDao {

private DbHelper helper;
private static CollectionDao self;
private static String DB_NAME = "collection.db";

public static CollectionDao get() {
if (null == self) self = new CollectionDao();
return self;
}

public CollectionDao() {}

/** 插入新记录 * */
public void insert(@NonNull DbBean clipboardBean) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.execSQL(
"insert into t_data(text,html,type,time) values(?,?,?,?)",
new Object[] {
clipboardBean.getText(),
clipboardBean.getHtml(),
clipboardBean.getType(),
clipboardBean.getTime()
});
db.close();
}

/** 删除文字相同的剪贴板记录,插入新记录 * */
public void add(@NonNull DbBean clipboardBean) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.delete("t_data", "text=?", new String[] {clipboardBean.getText()});
db.execSQL(
"insert into t_data(text,html,type,time) values(?,?,?,?)",
new Object[] {
clipboardBean.getText(),
clipboardBean.getHtml(),
clipboardBean.getType(),
clipboardBean.getTime()
});
db.close();
}

/** 删除记录 * */
public void delete(@NonNull String str) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.delete("t_data", "text=?", new String[] {str});
db.close();
}

public void delete(@NonNull List<SimpleKeyBean> list) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
for (SimpleKeyBean bean : list) db.delete("t_data", "text=?", new String[] {bean.getText()});
db.close();
}

public List<SimpleKeyBean> getAllSimpleBean() {

List<SimpleKeyBean> list = new ArrayList<>();

String sql = "select text , html , type , time from t_data ORDER BY time DESC";

helper = new DbHelper(Trime.getService(), DB_NAME);

SQLiteDatabase db = helper.getWritableDatabase();
Cursor cursor = db.rawQuery(sql, null);
if (cursor != null) {
while (cursor.moveToNext()) {
DbBean v = new DbBean(cursor.getString(0));
list.add(v);
}
cursor.close();
}
db.close();
Timber.d("getAllSimpleBean() size=%s", list.size());
return list;
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/data/db/DbBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class DbBean extends SimpleKeyBean {
private long time;
private String text;
private final String html;
private int type;
private int type; // 0 text, 1 html

public long getTime() {
return time;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ClipboardDao {

private DbHelper helper;
private static ClipboardDao self;
private static String DB_NAME = "clipboard.db";

public static ClipboardDao get() {
if (null == self) self = new ClipboardDao();
Expand All @@ -25,7 +26,7 @@ public ClipboardDao() {}

/** 插入新记录 * */
public void insert(@NonNull DbBean clipboardBean) {
helper = new DbHelper(Trime.getService(), "clipboard.db");
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.execSQL(
"insert into t_data(text,html,type,time) values(?,?,?,?)",
Expand All @@ -40,7 +41,7 @@ public void insert(@NonNull DbBean clipboardBean) {

/** 删除文字相同的剪贴板记录,插入新记录 * */
public void add(@NonNull DbBean clipboardBean) {
helper = new DbHelper(Trime.getService(), "clipboard.db");
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.delete("t_data", "text=?", new String[] {clipboardBean.getText()});
db.execSQL(
Expand All @@ -56,12 +57,19 @@ public void add(@NonNull DbBean clipboardBean) {

/** 删除记录 * */
public void delete(@NonNull String str) {
helper = new DbHelper(Trime.getService(), "clipboard.db");
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.delete("t_data", "text=?", new String[] {str});
db.close();
}

public void delete(@NonNull List<SimpleKeyBean> list) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
for (SimpleKeyBean bean : list) db.delete("t_data", "text=?", new String[] {bean.getText()});
db.close();
}

public List<SimpleKeyBean> getAllSimpleBean(int size) {

List<SimpleKeyBean> list = new ArrayList<>();
Expand All @@ -70,7 +78,7 @@ public List<SimpleKeyBean> getAllSimpleBean(int size) {
String sql = "select text , html , type , time from t_data ORDER BY time DESC";
if (size > 0) sql = sql + " limit 0," + size;

helper = new DbHelper(Trime.getService(), "clipboard.db");
helper = new DbHelper(Trime.getService(), DB_NAME);

SQLiteDatabase db = helper.getWritableDatabase();
Cursor cursor = db.rawQuery(sql, null);
Expand Down
22 changes: 19 additions & 3 deletions app/src/main/java/com/osfans/trime/data/db/draft/DraftDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class DraftDao {

private SQLiteOpenHelper helper;
private static DraftDao self;
private static String DB_NAME = "draft.db";

public static DraftDao get() {
if (null == self) self = new DraftDao();
Expand All @@ -26,7 +27,7 @@ public DraftDao() {}

/** 插入新记录 * */
public void insert(@NonNull DbBean bean) {
helper = new DbHelper(Trime.getService(), "draft.db");
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.execSQL(
"insert into t_data(text,html,type,time) values(?,?,?,?)",
Expand All @@ -36,7 +37,7 @@ public void insert(@NonNull DbBean bean) {

/** 删除文字相同的记录,插入新记录 * */
public void add(@NonNull DbBean bean) {
helper = new DbHelper(Trime.getService(), "draft.db");
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.delete("t_data", "text=?", new String[] {bean.getText()});
db.execSQL(
Expand All @@ -45,6 +46,21 @@ public void add(@NonNull DbBean bean) {
db.close();
}

/** 删除记录 * */
public void delete(@NonNull String str) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.delete("t_data", "text=?", new String[] {str});
db.close();
}

public void delete(@NonNull List<SimpleKeyBean> list) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
for (SimpleKeyBean bean : list) db.delete("t_data", "text=?", new String[] {bean.getText()});
db.close();
}

public List<SimpleKeyBean> getAllSimpleBean(int size) {

List<SimpleKeyBean> list = new ArrayList<>();
Expand All @@ -53,7 +69,7 @@ public List<SimpleKeyBean> getAllSimpleBean(int size) {
String sql = "select text , html , type , time from t_data ORDER BY time DESC";
if (size > 0) sql = sql + " limit 0," + size;

helper = new DbHelper(Trime.getService(), "draft.db");
helper = new DbHelper(Trime.getService(), DB_NAME);

SQLiteDatabase db = helper.getWritableDatabase();
Cursor cursor = db.rawQuery(sql, null);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/ime/core/Trime.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.osfans.trime.core.Rime;
import com.osfans.trime.data.AppPrefs;
import com.osfans.trime.data.Config;
import com.osfans.trime.data.db.CollectionDao;
import com.osfans.trime.data.db.clipboard.ClipboardDao;
import com.osfans.trime.data.db.draft.DraftDao;
import com.osfans.trime.databinding.CompositionRootBinding;
Expand Down Expand Up @@ -237,9 +238,7 @@ public void run() {
};

@Synchronized
@NonNull
public static Trime getService() {
assert self != null;
return self;
}

Expand Down Expand Up @@ -391,6 +390,7 @@ public void onCreate() {
new LiquidKeyboard(
this, getImeConfig().getClipboardLimit(), getImeConfig().getDraftLimit());
clipBoardMonitor();
CollectionDao.get();
DraftDao.get();
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ enum class SymbolKeyboardType {
// 剪贴板(大段文本自动缩略,按键长度自适应。)
CLIPBOARD,

// 收藏的文本, 复用剪贴板
COLLECTION,

// 文本框编辑历史,即“草稿箱”
DRAFT,

Expand Down
Loading

0 comments on commit 2055637

Please sign in to comment.