Skip to content

Commit f863f71

Browse files
committed
🎨 Supports append text by shortcuts to the dailynote doc on Android siyuan-note/siyuan#14414
1 parent 7664b11 commit f863f71

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

app/src/main/java/org/b3log/siyuan/ShortcutActivity.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@
2222
import android.util.Log;
2323
import android.widget.Button;
2424
import android.widget.EditText;
25+
import android.widget.Toast;
2526

2627
import androidx.annotation.Nullable;
2728
import androidx.appcompat.app.AppCompatActivity;
2829

2930
import com.blankj.utilcode.util.StringUtils;
3031

32+
import org.apache.commons.io.FileUtils;
33+
34+
import java.io.File;
35+
3136
/**
3237
* 追加到日记的快捷方式.
3338
*
@@ -65,12 +70,23 @@ private void setupFullScreenInput() {
6570
final EditText input = findViewById(R.id.full_screen_input);
6671
input.requestFocus();
6772

68-
6973
final Button submitButton = findViewById(R.id.submit_button);
7074
submitButton.setOnClickListener(v -> {
71-
String userInput = input.getText().toString();
72-
Log.i("shortcut", "User input: " + userInput);
73-
// Handle the user input here
75+
final String userInput = input.getText().toString().trim();
76+
if (StringUtils.isEmpty(userInput)) {
77+
return;
78+
}
79+
80+
final long now = System.currentTimeMillis();
81+
final String dailynotesDir = getExternalFilesDir(null).getAbsolutePath() + "/home/shortcuts/ailynotes/";
82+
new File(dailynotesDir).mkdirs();
83+
final File f = new File(dailynotesDir, now + ".md");
84+
try {
85+
FileUtils.writeStringToFile(f, userInput, "UTF-8");
86+
} catch (final Exception e) {
87+
Log.e("shortcut", "Failed to write to file", e);
88+
Toast.makeText(this, "Failed to write to file [" + e.getMessage() + "]", Toast.LENGTH_LONG).show();
89+
}
7490

7591
finish();
7692
});

0 commit comments

Comments
 (0)