|
|
|
@ -2,7 +2,9 @@ package com.example.readtext;
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
import androidx.databinding.DataBindingUtil;
|
|
|
|
|
import androidx.databinding.ObservableBoolean;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.speech.tts.TextToSpeech;
|
|
|
|
@ -37,6 +39,8 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
|
|
|
|
|
private Intent intent;
|
|
|
|
|
private InPutDialog inPutDialog;
|
|
|
|
|
private ActivityMainBinding binding;
|
|
|
|
|
private ObservableBoolean state;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
@ -44,8 +48,10 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
|
|
|
|
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
|
|
|
|
|
intent = new Intent(this, ConfigActivity.class);
|
|
|
|
|
initAdapter();
|
|
|
|
|
|
|
|
|
|
inPutDialog=new InPutDialog(this);
|
|
|
|
|
state = new ObservableBoolean();
|
|
|
|
|
state.set(false);
|
|
|
|
|
binding.setState(state);
|
|
|
|
|
inPutDialog = new InPutDialog(this);
|
|
|
|
|
inPutDialog.setInPutDialogCall(this);
|
|
|
|
|
textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
|
|
|
|
|
@Override
|
|
|
|
@ -66,6 +72,7 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化加载器
|
|
|
|
|
private void initAdapter() {
|
|
|
|
|
adapter1 = new MainAdapter(this, new MyClickInterface() {
|
|
|
|
@ -74,9 +81,13 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
|
|
|
|
|
textToSpeech.speak(list1.get(index).getHanzi(), TextToSpeech.QUEUE_FLUSH, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
|
|
@Override
|
|
|
|
|
public void onClickUpdateCall(int index) {
|
|
|
|
|
|
|
|
|
|
ReadTextBeen readTextBeen = list1.get(index);
|
|
|
|
|
readTextBeen.delete();
|
|
|
|
|
list1.remove(index);
|
|
|
|
|
adapter1.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
adapter2 = new MainAdapter(this, new MyClickInterface() {
|
|
|
|
@ -85,9 +96,13 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
|
|
|
|
|
textToSpeech.speak(list2.get(index).getHanzi(), TextToSpeech.QUEUE_FLUSH, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
|
|
@Override
|
|
|
|
|
public void onClickUpdateCall(int index) {
|
|
|
|
|
|
|
|
|
|
ReadTextBeen readTextBeen = list2.get(index);
|
|
|
|
|
readTextBeen.delete();
|
|
|
|
|
list2.remove(index);
|
|
|
|
|
adapter2.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
adapter3 = new MainAdapter(this, new MyClickInterface() {
|
|
|
|
@ -96,9 +111,13 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
|
|
|
|
|
textToSpeech.speak(list3.get(index).getHanzi(), TextToSpeech.QUEUE_FLUSH, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
|
|
@Override
|
|
|
|
|
public void onClickUpdateCall(int index) {
|
|
|
|
|
|
|
|
|
|
ReadTextBeen readTextBeen = list3.get(index);
|
|
|
|
|
readTextBeen.delete();
|
|
|
|
|
list3.remove(index);
|
|
|
|
|
adapter3.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
adapter4 = new MainAdapter(this, new MyClickInterface() {
|
|
|
|
@ -107,9 +126,13 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
|
|
|
|
|
textToSpeech.speak(list4.get(index).getHanzi(), TextToSpeech.QUEUE_FLUSH, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
|
|
@Override
|
|
|
|
|
public void onClickUpdateCall(int index) {
|
|
|
|
|
|
|
|
|
|
ReadTextBeen readTextBeen = list4.get(index);
|
|
|
|
|
readTextBeen.delete();
|
|
|
|
|
list4.remove(index);
|
|
|
|
|
adapter4.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
binding.setAdapter1(adapter1);
|
|
|
|
@ -119,13 +142,14 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询和加载列表
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
list1 = LitePal.where("type =?","1").order("clickNum desc").find(ReadTextBeen.class);
|
|
|
|
|
list2 = LitePal.where("type =?","2").order("clickNum desc").find(ReadTextBeen.class);
|
|
|
|
|
list3 = LitePal.where("type =?","3").order("clickNum desc").find(ReadTextBeen.class);
|
|
|
|
|
list4 = LitePal.where("type =?","4").order("clickNum desc").find(ReadTextBeen.class);
|
|
|
|
|
list1 = LitePal.where("type =?", "1").order("clickNum desc").find(ReadTextBeen.class);
|
|
|
|
|
list2 = LitePal.where("type =?", "2").order("clickNum desc").find(ReadTextBeen.class);
|
|
|
|
|
list3 = LitePal.where("type =?", "3").order("clickNum desc").find(ReadTextBeen.class);
|
|
|
|
|
list4 = LitePal.where("type =?", "4").order("clickNum desc").find(ReadTextBeen.class);
|
|
|
|
|
|
|
|
|
|
adapter1.setList(list1);
|
|
|
|
|
adapter1.notifyDataSetChanged();
|
|
|
|
@ -135,24 +159,24 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
|
|
|
|
|
adapter3.notifyDataSetChanged();
|
|
|
|
|
adapter4.setList(list4);
|
|
|
|
|
adapter4.notifyDataSetChanged();
|
|
|
|
|
// if (list == null || list.isEmpty()) {
|
|
|
|
|
// startActivity(intent);
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// adapter.setList(list);
|
|
|
|
|
// adapter.notifyDataSetChanged();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 跳转到配置页面
|
|
|
|
|
// 设置
|
|
|
|
|
public void mainConfig(View view) {
|
|
|
|
|
// startActivity(intent);
|
|
|
|
|
boolean b = !state.get();
|
|
|
|
|
|
|
|
|
|
adapter1.setaBoolean(b);
|
|
|
|
|
adapter2.setaBoolean(b);
|
|
|
|
|
adapter3.setaBoolean(b);
|
|
|
|
|
adapter4.setaBoolean(b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state.set(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainAdd1(View view) {
|
|
|
|
|
|
|
|
|
|
inPutDialog.showAdd(1);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void mainAdd2(View view) {
|
|
|
|
@ -176,29 +200,43 @@ public class MainActivity extends AppCompatActivity implements InPutDialog.InPut
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加数据
|
|
|
|
|
@Override
|
|
|
|
|
public void inPutDialogReculi(String name, boolean b, int id, int type) {
|
|
|
|
|
|
|
|
|
|
ReadTextBeen readTextBeen=new ReadTextBeen();
|
|
|
|
|
ReadTextBeen readTextBeen = new ReadTextBeen();
|
|
|
|
|
readTextBeen.setHanzi(name);
|
|
|
|
|
String pinyinString ;
|
|
|
|
|
if (name.equals("睡觉")){
|
|
|
|
|
pinyinString="shui jiao";
|
|
|
|
|
}else {
|
|
|
|
|
pinyinString= PinyinHelper.convertToPinyinString("快乐音乐", " ", PinyinFormat.WITHOUT_TONE);
|
|
|
|
|
String pinyinString;
|
|
|
|
|
if (name.equals("睡觉")) {
|
|
|
|
|
pinyinString = "shui jiao";
|
|
|
|
|
} else {
|
|
|
|
|
pinyinString = PinyinHelper.convertToPinyinString(name, " ", PinyinFormat.WITHOUT_TONE);
|
|
|
|
|
}
|
|
|
|
|
readTextBeen.setPinyin(pinyinString);
|
|
|
|
|
readTextBeen.setType(type);
|
|
|
|
|
readTextBeen.setClickNum(0);
|
|
|
|
|
readTextBeen.save();
|
|
|
|
|
|
|
|
|
|
addBeen(type, readTextBeen);
|
|
|
|
|
inPutDialog.dismiss();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addBeen(int type){
|
|
|
|
|
|
|
|
|
|
private void addBeen(int type, ReadTextBeen readTextBeen) {
|
|
|
|
|
if (type == 1) {
|
|
|
|
|
list1.add(readTextBeen);
|
|
|
|
|
adapter1.setSelectedList(list1.size());
|
|
|
|
|
adapter1.notifyDataSetChanged();
|
|
|
|
|
} else if (type == 2) {
|
|
|
|
|
list2.add(readTextBeen);
|
|
|
|
|
adapter2.setSelectedList(list2.size());
|
|
|
|
|
adapter2.notifyDataSetChanged();
|
|
|
|
|
} else if (type == 3) {
|
|
|
|
|
list3.add(readTextBeen);
|
|
|
|
|
adapter3.setSelectedList(list3.size());
|
|
|
|
|
adapter3.notifyDataSetChanged();
|
|
|
|
|
} else if (type == 4) {
|
|
|
|
|
list4.add(readTextBeen);
|
|
|
|
|
adapter4.setSelectedList(list4.size());
|
|
|
|
|
adapter4.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|