use of net.iGap.module.FileListerDialog.OnFileSelectedListener in project iGap-Android by KianIranian-STDG.
the class FragmentChat method exportChat.
public void exportChat() {
RealmResults<RealmRoomMessage> realmRoomMessages = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoomMessage.class).equalTo("roomId", mRoomId).sort("createTime").findAll();
});
File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/iGap", "iGap Messages");
if (!root.exists()) {
root.mkdir();
}
FileListerDialog fileListerDialog = FileListerDialog.createFileListerDialog(G.fragmentActivity);
fileListerDialog.setDefaultDir(root);
fileListerDialog.setFileFilter(FileListerDialog.FILE_FILTER.DIRECTORY_ONLY);
fileListerDialog.show();
fileListerDialog.setOnFileSelectedListener(new OnFileSelectedListener() {
@Override
public void onFileSelected(File file, String path) {
final MaterialDialog[] dialog = new MaterialDialog[1];
if (realmRoomMessages.size() != 0 && chatType != CHANNEL) {
G.handler.post(new Runnable() {
@Override
public void run() {
dialog[0] = new MaterialDialog.Builder(G.currentActivity).title(R.string.export_chat).content(R.string.just_wait_en).progress(false, realmRoomMessages.size(), true).show();
}
});
try {
File filepath = new File(file, title + ".txt");
FileWriter writer = new FileWriter(filepath);
for (RealmRoomMessage export : realmRoomMessages) {
if (export.getMessageType().toString().equalsIgnoreCase("TEXT")) {
writer.append(RealmRegisteredInfo.getNameWithId(export.getUserId()) + " text message " + " : " + export.getMessage() + " date :" + HelperCalander.milladyDate(export.getCreateTime()) + "\n");
} else {
writer.append(RealmRegisteredInfo.getNameWithId(export.getUserId()) + " text message " + export.getMessage() + " : message in format " + export.getMessageType() + " date :" + HelperCalander.milladyDate(export.getCreateTime()) + "\n");
}
G.handler.post(new Runnable() {
@Override
public void run() {
dialog[0].incrementProgress(1);
}
});
}
writer.flush();
writer.close();
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
dialog[0].dismiss();
}
}, 500);
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
Aggregations