mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-06 09:03:56 +02:00
Simplify FTS management
This commit is contained in:
@@ -46,10 +46,11 @@ import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import io.requery.android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private SwitchCompat swExternalSearch;
|
||||
private SwitchCompat swFts;
|
||||
private Button btnFtsReset;
|
||||
private TextView tvFtsIndexed;
|
||||
private SwitchCompat swEnglish;
|
||||
private SwitchCompat swWatchdog;
|
||||
@@ -93,7 +94,6 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
|
||||
swExternalSearch = view.findViewById(R.id.swExternalSearch);
|
||||
swFts = view.findViewById(R.id.swFts);
|
||||
btnFtsReset = view.findViewById(R.id.btnFtsReset);
|
||||
tvFtsIndexed = view.findViewById(R.id.tvFtsIndexed);
|
||||
swEnglish = view.findViewById(R.id.swEnglish);
|
||||
swWatchdog = view.findViewById(R.id.swWatchdog);
|
||||
@@ -137,33 +137,31 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("fts", checked).apply();
|
||||
|
||||
WorkerFts.init(getContext(), true);
|
||||
}
|
||||
});
|
||||
|
||||
btnFtsReset.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Bundle args = new Bundle();
|
||||
if (!checked) {
|
||||
Bundle args = new Bundle();
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
||||
DB db = DB.getInstance(context);
|
||||
db.message().resetFts();
|
||||
return null;
|
||||
}
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
SQLiteDatabase sdb = FtsDbHelper.getInstance(context);
|
||||
FtsDbHelper.delete(sdb);
|
||||
FtsDbHelper.optimize(sdb);
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Void data) {
|
||||
WorkerFts.init(getContext(), true);
|
||||
}
|
||||
DB db = DB.getInstance(context);
|
||||
db.message().resetFts();
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(FragmentOptionsMisc.this, args, "fts:reset");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(FragmentOptionsMisc.this, args, "fts:reset");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -246,12 +244,18 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
|
||||
DB db = DB.getInstance(getContext());
|
||||
db.message().liveFts().observe(getViewLifecycleOwner(), new Observer<TupleFtsStats>() {
|
||||
private TupleFtsStats last = null;
|
||||
|
||||
@Override
|
||||
public void onChanged(TupleFtsStats stats) {
|
||||
if (stats == null)
|
||||
tvFtsIndexed.setText(null);
|
||||
else
|
||||
tvFtsIndexed.setText(getString(R.string.title_advanced_fts_indexed, stats.fts, stats.total));
|
||||
else if (last == null || !last.equals(stats))
|
||||
tvFtsIndexed.setText(getString(R.string.title_advanced_fts_indexed,
|
||||
stats.fts,
|
||||
stats.total,
|
||||
Helper.humanReadableByteCount(FtsDbHelper.size(getContext()), true)));
|
||||
last = stats;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user